Skip to content

Commit

Permalink
add files
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmnouira committed Aug 17, 2021
1 parent 9a1e04e commit 284accb
Show file tree
Hide file tree
Showing 11 changed files with 4,232 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/lib
/node_modules
/@types
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
node_modules
dist
test
npm-debug.log
yarn-error.log
.DS_Store
coverage
.cache
.dev



17 changes: 17 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz

pids
logs
results


npm-debug.log
node_modules/*
*.DS_Store
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
coverage
dist
8 changes: 8 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"tabWidth": 2,
"useTabs": false,
"printWidth": 120,
"semi": false,
"singleQuote": true,
"trailingComma": "es5",
}
12 changes: 12 additions & 0 deletions @types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import * as React from 'react'

export type UseIonHeaderParallxInput = {
image: string
expandedColor: string
titleColor: string
maximumHeight?: number
}

export type UseIonHeaderParallxInputResult = {
ref: React.MutableRefObject<HTMLElement | null>
}
43 changes: 43 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "ionic-react-header-parallax",
"version": "0.0.0",
"description": "A React Hook parallax effect for Ionic React <IonHeader> component",
"author": {
"name": "Ahmd Nouira",
"email": "ahmnouira@gmail.comm"
},
"repository": {
"type": "git",
"url": "https://github.com/ahmnouira/ionic-react-header-parallax.git"
},
"keywords": [
"ionic"
],

"bugs": {
"url": "https://github.com/ahmnouira/ionic-react-header-parallax.git/issues"
},
"main": "dist/index.js",
"types": "@types/index.ts",
"scripts": {
"prepare": "yarn build",
"build": "tsc",
"test": "jest",
"lint": "eslint src/**/*.ts",
"eslint:fix": "eslint src/**/*.ts --fix",
"format:fix": "prettier --write \"**/*.{ts,tsx,json}\"",
"release": "auto shipit",
"release:canary": "auto canary"
},
"license": "MIT",
"devDependencies": {
"@types/jest": "^27.0.1",
"@types/react": "^17.0.18",
"auto": "^10.31.0",
"eslint": "^7.32.0",
"jest": "^27.0.6",
"prettier": "^2.3.2",
"react": "^17.0.2",
"typescript": "^4.3.5"
}
}
1 change: 1 addition & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './useIonHeaderParallax'
129 changes: 129 additions & 0 deletions src/useIonHeaderParallax.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import * as React from 'react'

export type UseIonicHeaderParallxInput = {
image: string
expandedColor: string
titleColor: string
maximumHeight?: number
}

export type UseIonHeaderParallxInputResult = {
ref: React.MutableRefObject<HTMLElement | null>
}

export function UseIonHeaderParallxInputResult({}: UseIonicHeaderParallxInput): UseIonHeaderParallxInputResult {
const headerRef = React.useRef<HTMLElement>(null)

let header: HTMLElement
let toolbar: HTMLElement | null
let toolbarBackground: HTMLElement | null
let imageOverlay: HTMLElement
let colorOverlay: HTMLElement
let barButtons: HTMLElement | null
let scrollContent: HTMLElement | null
// let headerHeight: any
// let headerMinHeight: number
// let translateAmt: any
// let scaleAmt: any
// let scrollTop: any
// let lastScrollTop: any
// let ticking: any
// let originalToolbarBgColor: string
let overlayTitle: HTMLElement | null
let ionTitle: HTMLElement | null
// let overlayButtons: HTMLElement[]
// let scrollContentPaddingTop: number

React.useEffect(() => {
setTimeout(() => {
try {
initElements()
initStyles()
initEvents()
} catch (e) {
throw e
}
}, 100)
}, [])

const initElements = () => {
if (!(headerRef && headerRef.current)) throw new ReferenceError('Ref is required')

const parentElement = headerRef.current.parentElement

if (!parentElement) throw new Error('No parentElemnt')

header = headerRef.current

// check this
toolbar = header.querySelector('IonToolbar')

if (!toolbar) {
throw new Error('Parallax requires a <IonToolbar> or navbar element on the page to work.')
}

if (!toolbar.shadowRoot) {
throw new Error('Parallax requires a shadowRoot <IonToolbar>')
}

ionTitle = toolbar.querySelector('IonTitle')

toolbarBackground = toolbar.shadowRoot.querySelector('.toolbar-background')

console.log('toolbarBackground', toolbarBackground)

barButtons = header.querySelector('IonButtons')

const ionContent = parentElement.querySelector('ion-content')

if (!ionContent) throw new Error('Parallax directive requires an <IonContent> element on the page to work.')

if (!ionContent.shadowRoot) throw new Error('Parallax requires a shadowRoot <ion-content>')

scrollContent = ionContent.shadowRoot.querySelector('.inner-scroll')

if (!scrollContent) {
throw new Error('Parallax directive requires an <IonContent> element on the page to work.')
}

// Create image overlay
imageOverlay = document.createElement('div')
console.log('imageOverlay', imageOverlay)
imageOverlay.classList.add('image-overlay')

colorOverlay = document.createElement('div')

colorOverlay.classList.add('color-overlay')

colorOverlay.appendChild(imageOverlay)
header.appendChild(colorOverlay)

// Copy title and buttons
overlayTitle = ionTitle && (ionTitle.cloneNode(true) as HTMLElement)

if (!overlayTitle) throw new Error('')
overlayTitle.classList.add('parallax-title')

setTimeout(() => {
const toolbarTitle = overlayTitle?.shadowRoot?.querySelector('.toolbar-title') as HTMLElement
toolbarTitle.style.pointerEvents = 'unset'
})

if (overlayTitle) {
imageOverlay.appendChild(overlayTitle)
}
if (barButtons) {
imageOverlay.appendChild(barButtons)
}

console.log('finished')
}

const initStyles = () => {}

const initEvents = () => {}

return {
ref: headerRef,
}
}
74 changes: 74 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"compilerOptions": {
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "es6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
"lib": ["DOM"] /* Specify library files to be included in the compilation. */,
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
"declaration": true /* Generates corresponding '.d.ts' file. */,
"declarationMap": true /* Generates a sourcemap for each corresponding '.d.ts' file. */,
"sourceMap": true /* Generates corresponding '.map' file. */,
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "./dist" /* Redirect output structure to the directory. */,
// "rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
// "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
"noUnusedParameters": true,
"skipLibCheck": true,
"noImplicitAny": true,
"isolatedModules": true,
"noUnusedLocals": true,
"moduleResolution": "node",
"baseUrl": "./src",
"paths": {
"~*": ["./*"]
},
/* Strict Type-Checking Options */
"strict": true /* Enable all strict type-checking options. */,
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */

/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */

/* Module Resolution Options */
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */

/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */

/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
},
"include": ["src", "@types"],
"exclude": ["node_modules"]
}
Loading

0 comments on commit 284accb

Please sign in to comment.