Skip to content

Commit 284accb

Browse files
committed
add files
1 parent 9a1e04e commit 284accb

File tree

11 files changed

+4232
-0
lines changed

11 files changed

+4232
-0
lines changed

.eslintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/lib
2+
/node_modules
3+
/@types

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
node_modules
2+
dist
3+
test
4+
npm-debug.log
5+
yarn-error.log
6+
.DS_Store
7+
coverage
8+
.cache
9+
.dev
10+
11+
12+

.npmignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
lib-cov
2+
*.seed
3+
*.log
4+
*.csv
5+
*.dat
6+
*.out
7+
*.pid
8+
*.gz
9+
10+
pids
11+
logs
12+
results
13+
14+
15+
npm-debug.log
16+
node_modules/*
17+
*.DS_Store

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
coverage
3+
dist

.prettierrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"tabWidth": 2,
3+
"useTabs": false,
4+
"printWidth": 120,
5+
"semi": false,
6+
"singleQuote": true,
7+
"trailingComma": "es5",
8+
}

@types/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import * as React from 'react'
2+
3+
export type UseIonHeaderParallxInput = {
4+
image: string
5+
expandedColor: string
6+
titleColor: string
7+
maximumHeight?: number
8+
}
9+
10+
export type UseIonHeaderParallxInputResult = {
11+
ref: React.MutableRefObject<HTMLElement | null>
12+
}

package.json

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"name": "ionic-react-header-parallax",
3+
"version": "0.0.0",
4+
"description": "A React Hook parallax effect for Ionic React <IonHeader> component",
5+
"author": {
6+
"name": "Ahmd Nouira",
7+
"email": "ahmnouira@gmail.comm"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "https://github.com/ahmnouira/ionic-react-header-parallax.git"
12+
},
13+
"keywords": [
14+
"ionic"
15+
],
16+
17+
"bugs": {
18+
"url": "https://github.com/ahmnouira/ionic-react-header-parallax.git/issues"
19+
},
20+
"main": "dist/index.js",
21+
"types": "@types/index.ts",
22+
"scripts": {
23+
"prepare": "yarn build",
24+
"build": "tsc",
25+
"test": "jest",
26+
"lint": "eslint src/**/*.ts",
27+
"eslint:fix": "eslint src/**/*.ts --fix",
28+
"format:fix": "prettier --write \"**/*.{ts,tsx,json}\"",
29+
"release": "auto shipit",
30+
"release:canary": "auto canary"
31+
},
32+
"license": "MIT",
33+
"devDependencies": {
34+
"@types/jest": "^27.0.1",
35+
"@types/react": "^17.0.18",
36+
"auto": "^10.31.0",
37+
"eslint": "^7.32.0",
38+
"jest": "^27.0.6",
39+
"prettier": "^2.3.2",
40+
"react": "^17.0.2",
41+
"typescript": "^4.3.5"
42+
}
43+
}

src/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './useIonHeaderParallax'

src/useIonHeaderParallax.ts

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
import * as React from 'react'
2+
3+
export type UseIonicHeaderParallxInput = {
4+
image: string
5+
expandedColor: string
6+
titleColor: string
7+
maximumHeight?: number
8+
}
9+
10+
export type UseIonHeaderParallxInputResult = {
11+
ref: React.MutableRefObject<HTMLElement | null>
12+
}
13+
14+
export function UseIonHeaderParallxInputResult({}: UseIonicHeaderParallxInput): UseIonHeaderParallxInputResult {
15+
const headerRef = React.useRef<HTMLElement>(null)
16+
17+
let header: HTMLElement
18+
let toolbar: HTMLElement | null
19+
let toolbarBackground: HTMLElement | null
20+
let imageOverlay: HTMLElement
21+
let colorOverlay: HTMLElement
22+
let barButtons: HTMLElement | null
23+
let scrollContent: HTMLElement | null
24+
// let headerHeight: any
25+
// let headerMinHeight: number
26+
// let translateAmt: any
27+
// let scaleAmt: any
28+
// let scrollTop: any
29+
// let lastScrollTop: any
30+
// let ticking: any
31+
// let originalToolbarBgColor: string
32+
let overlayTitle: HTMLElement | null
33+
let ionTitle: HTMLElement | null
34+
// let overlayButtons: HTMLElement[]
35+
// let scrollContentPaddingTop: number
36+
37+
React.useEffect(() => {
38+
setTimeout(() => {
39+
try {
40+
initElements()
41+
initStyles()
42+
initEvents()
43+
} catch (e) {
44+
throw e
45+
}
46+
}, 100)
47+
}, [])
48+
49+
const initElements = () => {
50+
if (!(headerRef && headerRef.current)) throw new ReferenceError('Ref is required')
51+
52+
const parentElement = headerRef.current.parentElement
53+
54+
if (!parentElement) throw new Error('No parentElemnt')
55+
56+
header = headerRef.current
57+
58+
// check this
59+
toolbar = header.querySelector('IonToolbar')
60+
61+
if (!toolbar) {
62+
throw new Error('Parallax requires a <IonToolbar> or navbar element on the page to work.')
63+
}
64+
65+
if (!toolbar.shadowRoot) {
66+
throw new Error('Parallax requires a shadowRoot <IonToolbar>')
67+
}
68+
69+
ionTitle = toolbar.querySelector('IonTitle')
70+
71+
toolbarBackground = toolbar.shadowRoot.querySelector('.toolbar-background')
72+
73+
console.log('toolbarBackground', toolbarBackground)
74+
75+
barButtons = header.querySelector('IonButtons')
76+
77+
const ionContent = parentElement.querySelector('ion-content')
78+
79+
if (!ionContent) throw new Error('Parallax directive requires an <IonContent> element on the page to work.')
80+
81+
if (!ionContent.shadowRoot) throw new Error('Parallax requires a shadowRoot <ion-content>')
82+
83+
scrollContent = ionContent.shadowRoot.querySelector('.inner-scroll')
84+
85+
if (!scrollContent) {
86+
throw new Error('Parallax directive requires an <IonContent> element on the page to work.')
87+
}
88+
89+
// Create image overlay
90+
imageOverlay = document.createElement('div')
91+
console.log('imageOverlay', imageOverlay)
92+
imageOverlay.classList.add('image-overlay')
93+
94+
colorOverlay = document.createElement('div')
95+
96+
colorOverlay.classList.add('color-overlay')
97+
98+
colorOverlay.appendChild(imageOverlay)
99+
header.appendChild(colorOverlay)
100+
101+
// Copy title and buttons
102+
overlayTitle = ionTitle && (ionTitle.cloneNode(true) as HTMLElement)
103+
104+
if (!overlayTitle) throw new Error('')
105+
overlayTitle.classList.add('parallax-title')
106+
107+
setTimeout(() => {
108+
const toolbarTitle = overlayTitle?.shadowRoot?.querySelector('.toolbar-title') as HTMLElement
109+
toolbarTitle.style.pointerEvents = 'unset'
110+
})
111+
112+
if (overlayTitle) {
113+
imageOverlay.appendChild(overlayTitle)
114+
}
115+
if (barButtons) {
116+
imageOverlay.appendChild(barButtons)
117+
}
118+
119+
console.log('finished')
120+
}
121+
122+
const initStyles = () => {}
123+
124+
const initEvents = () => {}
125+
126+
return {
127+
ref: headerRef,
128+
}
129+
}

tsconfig.json

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{
2+
"compilerOptions": {
3+
/* Basic Options */
4+
// "incremental": true, /* Enable incremental compilation */
5+
"target": "es6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */,
6+
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
7+
"lib": ["DOM"] /* Specify library files to be included in the compilation. */,
8+
// "allowJs": true, /* Allow javascript files to be compiled. */
9+
// "checkJs": true, /* Report errors in .js files. */
10+
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
11+
"declaration": true /* Generates corresponding '.d.ts' file. */,
12+
"declarationMap": true /* Generates a sourcemap for each corresponding '.d.ts' file. */,
13+
"sourceMap": true /* Generates corresponding '.map' file. */,
14+
// "outFile": "./", /* Concatenate and emit output to single file. */
15+
"outDir": "./dist" /* Redirect output structure to the directory. */,
16+
// "rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
17+
// "composite": true, /* Enable project compilation */
18+
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
19+
// "removeComments": true, /* Do not emit comments to output. */
20+
// "noEmit": true, /* Do not emit outputs. */
21+
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
22+
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
23+
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
24+
"noUnusedParameters": true,
25+
"skipLibCheck": true,
26+
"noImplicitAny": true,
27+
"isolatedModules": true,
28+
"noUnusedLocals": true,
29+
"moduleResolution": "node",
30+
"baseUrl": "./src",
31+
"paths": {
32+
"~*": ["./*"]
33+
},
34+
/* Strict Type-Checking Options */
35+
"strict": true /* Enable all strict type-checking options. */,
36+
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
37+
// "strictNullChecks": true, /* Enable strict null checks. */
38+
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
39+
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
40+
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
41+
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
42+
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
43+
44+
/* Additional Checks */
45+
// "noUnusedLocals": true, /* Report errors on unused locals. */
46+
// "noUnusedParameters": true, /* Report errors on unused parameters. */
47+
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
48+
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
49+
50+
/* Module Resolution Options */
51+
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
52+
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
53+
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
54+
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
55+
// "typeRoots": [], /* List of folders to include type definitions from. */
56+
// "types": [], /* Type declaration files to be included in compilation. */
57+
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
58+
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
59+
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
60+
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
61+
62+
/* Source Map Options */
63+
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
64+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
65+
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
66+
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
67+
68+
/* Experimental Options */
69+
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
70+
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
71+
},
72+
"include": ["src", "@types"],
73+
"exclude": ["node_modules"]
74+
}

0 commit comments

Comments
 (0)