Skip to content

Commit 9eb88ee

Browse files
committed
fix: remove unused variables
1 parent 783300f commit 9eb88ee

File tree

6 files changed

+34
-59
lines changed

6 files changed

+34
-59
lines changed

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"@types/react-router": "5.1.16",
1616
"@types/react-router-dom": "5.1.8",
1717
"babel-jest": "^26.6.0",
18-
"ionic-react-header-parallax": "^0.1.0",
18+
"ionic-react-header-parallax": "^0.1.1",
1919
"ionicons": "5.5.3",
2020
"react": "17.0.2",
2121
"react-dom": "17.0.2",

example/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5934,10 +5934,10 @@ internal-slot@^1.0.3:
59345934
has "^1.0.3"
59355935
side-channel "^1.0.4"
59365936

5937-
ionic-react-header-parallax@^0.1.0:
5938-
version "0.1.0"
5939-
resolved "https://registry.yarnpkg.com/ionic-react-header-parallax/-/ionic-react-header-parallax-0.1.0.tgz#d12edede7f0f2ef70eb283b0da3a416b766396d5"
5940-
integrity sha512-KiyCGeaBuVmDvQcQrWZvM6TNbaf5NOljsQXTzy/z/FwvtEiPJ/eV2gXSubaj8xnL0y76cU+KwnFJDUj9RtFOgA==
5937+
ionic-react-header-parallax@^0.1.1:
5938+
version "0.1.1"
5939+
resolved "https://registry.yarnpkg.com/ionic-react-header-parallax/-/ionic-react-header-parallax-0.1.1.tgz#13b0c3579ecc2aa84746345f05c686644edb3d11"
5940+
integrity sha512-pDUvPObUmFaGamFrFK3Vnz6eJ8PIFjaZwe3744rvxWNj5bdsSQXO8lwaJGdH4jKK5UCNd3dA+3OkSgUwXQVGyw==
59415941

59425942
ionicons@5.5.3, ionicons@^5.1.2, ionicons@^5.5.3:
59435943
version "5.5.3"

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ionic-react-header-parallax",
3-
"version": "0.1.1",
3+
"version": "0.1.0",
44
"description": "A React Hook parallax effect for Ionic React <IonHeader> component",
55
"author": {
66
"name": "Ahmd Nouira",
@@ -62,7 +62,7 @@
6262
"babel-jest": "26.6.0",
6363
"codecov": "3.8.3",
6464
"eslint": "7.32.0",
65-
"jest": "26.6.3",
65+
"jest": "26.6.0",
6666
"np": "7.5.0",
6767
"prettier": "2.3.2",
6868
"react": "^17.0.2",
@@ -75,5 +75,8 @@
7575
},
7676
"publishConfig": {
7777
"registry": "https://registry.npmjs.org"
78+
},
79+
"resolutions": {
80+
"jest": "26.6.0"
7881
}
7982
}

src/useIonicHeaderParallax.spec.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react'
22
import { render } from '@testing-library/react/'
3-
import { useIonHeaderParallax } from './useIonicHeaderParallax'
3+
// import { useIonHeaderParallax } from './useIonicHeaderParallax'
44
import {
55
IonBackButton,
66
IonButton,
@@ -42,8 +42,9 @@ describe('IonHeaderParallax', () => {
4242
})
4343

4444
it('should render correctly', () => {
45+
4546
const Component = () => {
46-
useIonHeaderParallax({ image: 'https://picsum.photos/1080' })
47+
// useIonHeaderParallax({ image: 'https://picsum.photos/1080' })
4748
return Element
4849
}
4950
const { container } = render(<Component />)

src/useIonicHeaderParallax.ts

Lines changed: 13 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,21 @@ export function useIonHeaderParallax({
3636

3737
// ion-toolbar background
3838
const toolbarShadowRoot = toolbar.shadowRoot
39-
40-
if (!toolbarShadowRoot) return
41-
39+
if (!toolbarShadowRoot) throw new Error('No shadow')
4240
const toolbarBackground = toolbarShadowRoot.querySelector('.toolbar-background') as HTMLElement
4341

44-
if (!toolbarBackground) return
42+
if (!toolbarBackground) throw new Error('No .toolbar-background')
4543

4644
// ion-title
47-
const ionTitle = toolbar.querySelector('ion-title') as HTMLElement
45+
const ionTitle = toolbar.querySelector('ion-title')
4846

4947
// ion-buttons
5048
const barButtons = header.querySelector('ion-buttons') as HTMLElement
5149

5250
// ion-content
53-
const ionContent = parentElement.querySelector('ion-content') as HTMLElement
54-
if (!ionContent) throw new Error('Parallax an <ion-content> element on the page to work.')
55-
51+
const ionContent = parentElement.querySelector('ion-content')
52+
if (!ionContent) throw new Error('Parallax requires an <ion-content> element on the page to work.')
5653
const scrollContent = ionContent.shadowRoot?.querySelector('.inner-scroll') as HTMLElement
57-
5854
if (!scrollContent) {
5955
throw new Error('Parallax directive requires an <ion-content> element on the page to work.')
6056
}
@@ -71,6 +67,7 @@ export function useIonHeaderParallax({
7167

7268
if (overlayTitle) {
7369
overlayTitle.classList.add('parallax-title')
70+
7471
setTimeout(() => {
7572
if (overlayTitle.shadowRoot) {
7673
const toolbarTitle = overlayTitle.shadowRoot.querySelector('.toolbar-title') as HTMLElement
@@ -88,24 +85,19 @@ export function useIonHeaderParallax({
8885

8986
/*** initStyles ***/
9087
// still in init use JS DOM
91-
let headerHeight = scrollContent?.clientHeight
9288
setTicking(false)
9389

9490
// fetch styles
9591
maximumHeight = parseFloat(maximumHeight.toString())
9692
let headerMinHeight = toolbar.offsetHeight
9793

98-
let scrollContentPaddingTop = 0
99-
100-
if (scrollContent) {
101-
scrollContentPaddingTop = parseFloat(
102-
window.getComputedStyle(scrollContent as Element, null).paddingTop.replace('px', '')
103-
)
104-
}
105-
let originalToolbarBgColor = 'white'
94+
let scrollContentPaddingTop: number = parseFloat(
95+
window.getComputedStyle(scrollContent, null).paddingTop.replace('px', '')
96+
)
10697

107-
if (toolbarBackground) {
108-
originalToolbarBgColor = window.getComputedStyle(toolbarBackground as Element, null).backgroundColor
98+
const originalToolbarBgColor = window.getComputedStyle(toolbarBackground, null).backgroundColor
99+
if (!originalToolbarBgColor) {
100+
throw new Error('Error: toolbarBackround is null.')
109101
}
110102

111103
// header and title
@@ -139,9 +131,7 @@ export function useIonHeaderParallax({
139131
imageOverlay.style.backgroundPosition = 'center'
140132

141133
// .toolbar-background
142-
if (toolbarBackground) {
143-
toolbarBackground.style.backgroundColor = originalToolbarBgColor
144-
}
134+
toolbarBackground.style.backgroundColor = originalToolbarBgColor
145135

146136
// .bar-buttons
147137
if (barButtons) {
@@ -160,14 +150,6 @@ export function useIonHeaderParallax({
160150
scrollContent.style.paddingTop = `${maximumHeight + scrollContentPaddingTop - headerMinHeight}px`
161151
}
162152

163-
/** init events */
164-
window.addEventListener(
165-
'resize',
166-
() => {
167-
headerHeight = scrollContent.clientHeight
168-
},
169-
false
170-
)
171153

172154
if (scrollContent) {
173155
scrollContent.addEventListener('scroll', (_e) => {
@@ -176,15 +158,6 @@ export function useIonHeaderParallax({
176158
// to do
177159

178160
const scrollTop = scrollContent.scrollTop
179-
let translateAmt: number
180-
let scaleAmt: number
181-
if (scrollTop >= 0) {
182-
translateAmt = scrollTop / 2
183-
scaleAmt = 1
184-
} else {
185-
translateAmt = 0
186-
scaleAmt = scrollTop / headerHeight + 1
187-
}
188161

189162
// Parallax total progress
190163
headerMinHeight = toolbar.offsetHeight
@@ -195,8 +168,6 @@ export function useIonHeaderParallax({
195168
let targetHeight = maximumHeight - scrollTop
196169
targetHeight = Math.max(targetHeight, headerMinHeight)
197170

198-
header.style.transform = 'translate3d(0,' + translateAmt + 'px,0) scale(' + scaleAmt + ',' + scaleAmt + ')'
199-
200171
// .toolbar-background: change color
201172
imageOverlay.style.height = `${targetHeight}px`
202173
imageOverlay.style.opacity = `${progress}`

yarn.lock

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,7 @@
10741074
jest-util "^26.6.2"
10751075
slash "^3.0.0"
10761076

1077-
"@jest/core@^26.6.3":
1077+
"@jest/core@^26.6.0", "@jest/core@^26.6.3":
10781078
version "26.6.3"
10791079
resolved "https://registry.yarnpkg.com/@jest/core/-/core-26.6.3.tgz#7639fcb3833d748a4656ada54bde193051e45fad"
10801080
integrity sha512-xvV1kKbhfUqFVuZ8Cyo+JPpipAHHAV3kcDBftiduK8EICXmTFddryy3P7NfZt8Pv37rA9nEJBKCCkglCPt/Xjw==
@@ -3855,7 +3855,7 @@ jest-changed-files@^26.6.2:
38553855
execa "^4.0.0"
38563856
throat "^5.0.0"
38573857

3858-
jest-cli@^26.6.3:
3858+
jest-cli@^26.6.0:
38593859
version "26.6.3"
38603860
resolved "https://registry.yarnpkg.com/jest-cli/-/jest-cli-26.6.3.tgz#43117cfef24bc4cd691a174a8796a532e135e92a"
38613861
integrity sha512-GF9noBSa9t08pSyl3CY4frMrqp+aQXFGFkf5hEPbh/pIUFYWMK6ZLTfbmadxJVcJrdRoChlWQsA2VkJcDFK8hg==
@@ -4210,14 +4210,14 @@ jest-worker@^26.6.2:
42104210
merge-stream "^2.0.0"
42114211
supports-color "^7.0.0"
42124212

4213-
jest@26.6.3:
4214-
version "26.6.3"
4215-
resolved "https://registry.yarnpkg.com/jest/-/jest-26.6.3.tgz#40e8fdbe48f00dfa1f0ce8121ca74b88ac9148ef"
4216-
integrity sha512-lGS5PXGAzR4RF7V5+XObhqz2KZIDUA1yD0DG6pBVmy10eh0ZIXQImRuzocsI/N2XZ1GrLFwTS27In2i2jlpq1Q==
4213+
jest@26.6.0:
4214+
version "26.6.0"
4215+
resolved "https://registry.yarnpkg.com/jest/-/jest-26.6.0.tgz#546b25a1d8c888569dbbe93cae131748086a4a25"
4216+
integrity sha512-jxTmrvuecVISvKFFhOkjsWRZV7sFqdSUAd1ajOKY+/QE/aLBVstsJ/dX8GczLzwiT6ZEwwmZqtCUHLHHQVzcfA==
42174217
dependencies:
4218-
"@jest/core" "^26.6.3"
4218+
"@jest/core" "^26.6.0"
42194219
import-local "^3.0.2"
4220-
jest-cli "^26.6.3"
4220+
jest-cli "^26.6.0"
42214221

42224222
"js-tokens@^3.0.0 || ^4.0.0", js-tokens@^4.0.0:
42234223
version "4.0.0"

0 commit comments

Comments
 (0)