-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Timer): create component (#1130)
- Loading branch information
1 parent
c9ba728
commit 0b3253e
Showing
62 changed files
with
1,074 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import * as React from 'react'; | ||
import {Timer} from '../../..'; | ||
|
||
const TimerTest = (): JSX.Element => <Timer minTimeUnit="seconds" maxTimeUnit="hours" endTimestamp={0} />; | ||
|
||
export default TimerTest; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import {openSSRPage} from '../test-utils'; | ||
|
||
test('ssr timer', async () => { | ||
await openSSRPage({name: 'timer'}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+9.34 KB
(100%)
...ots__/private-skin-components-screenshot-test-tsx-components-in-blau-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+9.47 KB
(100%)
...e-skin-components-screenshot-test-tsx-components-in-blau-alternative-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+9.37 KB
(100%)
...ate-skin-components-screenshot-test-tsx-components-in-blau-dark-mode-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+9.2 KB
(100%)
...ivate-skin-components-screenshot-test-tsx-components-in-blau-inverse-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+9.22 KB
(100%)
...ponents-screenshot-test-tsx-components-in-blau-inverse-and-dark-mode-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+8.94 KB
(100%)
..._/private-skin-components-screenshot-test-tsx-components-in-movistar-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+8.88 KB
(100%)
...in-components-screenshot-test-tsx-components-in-movistar-alternative-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+9.08 KB
(100%)
...skin-components-screenshot-test-tsx-components-in-movistar-dark-mode-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+9.02 KB
(100%)
...e-skin-components-screenshot-test-tsx-components-in-movistar-inverse-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+9.06 KB
(100%)
...nts-screenshot-test-tsx-components-in-movistar-inverse-and-dark-mode-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+8.13 KB
(100%)
...hots__/private-skin-components-screenshot-test-tsx-components-in-o-2-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+8.07 KB
(100%)
...te-skin-components-screenshot-test-tsx-components-in-o-2-alternative-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+8.18 KB
(100%)
...vate-skin-components-screenshot-test-tsx-components-in-o-2-dark-mode-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+8.32 KB
(100%)
...rivate-skin-components-screenshot-test-tsx-components-in-o-2-inverse-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+7.98 KB
(100%)
...mponents-screenshot-test-tsx-components-in-o-2-inverse-and-dark-mode-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+9.15 KB
(100%)
...__/private-skin-components-screenshot-test-tsx-components-in-o-2-new-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+9.17 KB
(100%)
...kin-components-screenshot-test-tsx-components-in-o-2-new-alternative-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+9.58 KB
(100%)
...-skin-components-screenshot-test-tsx-components-in-o-2-new-dark-mode-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+9.19 KB
(100%)
...te-skin-components-screenshot-test-tsx-components-in-o-2-new-inverse-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+9.44 KB
(100%)
...ents-screenshot-test-tsx-components-in-o-2-new-inverse-and-dark-mode-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+8.9 KB
(100%)
...private-skin-components-screenshot-test-tsx-components-in-telefonica-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+8.99 KB
(100%)
...-components-screenshot-test-tsx-components-in-telefonica-alternative-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+9 KB
(100%)
...in-components-screenshot-test-tsx-components-in-telefonica-dark-mode-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+7.91 KB
(100%)
...skin-components-screenshot-test-tsx-components-in-telefonica-inverse-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+9 KB
(100%)
...s-screenshot-test-tsx-components-in-telefonica-inverse-and-dark-mode-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+9.33 KB
(100%)
...shots__/private-skin-components-screenshot-test-tsx-components-in-tu-1-snap.png
Oops, something went wrong.
Binary file modified
BIN
+9.12 KB
(100%)
...ate-skin-components-screenshot-test-tsx-components-in-tu-alternative-1-snap.png
Oops, something went wrong.
Binary file modified
BIN
+9.54 KB
(100%)
...ivate-skin-components-screenshot-test-tsx-components-in-tu-dark-mode-1-snap.png
Oops, something went wrong.
Binary file modified
BIN
+9.83 KB
(100%)
...private-skin-components-screenshot-test-tsx-components-in-tu-inverse-1-snap.png
Oops, something went wrong.
Binary file modified
BIN
+9.5 KB
(100%)
...omponents-screenshot-test-tsx-components-in-tu-inverse-and-dark-mode-1-snap.png
Oops, something went wrong.
Binary file modified
BIN
+9.53 KB
(100%)
..._/private-skin-components-screenshot-test-tsx-components-in-vivo-new-1-snap.png
Oops, something went wrong.
Binary file modified
BIN
+9.3 KB
(100%)
...in-components-screenshot-test-tsx-components-in-vivo-new-alternative-1-snap.png
Oops, something went wrong.
Binary file modified
BIN
+9.77 KB
(100%)
...skin-components-screenshot-test-tsx-components-in-vivo-new-dark-mode-1-snap.png
Oops, something went wrong.
Binary file modified
BIN
+9.93 KB
(100%)
...e-skin-components-screenshot-test-tsx-components-in-vivo-new-inverse-1-snap.png
Oops, something went wrong.
Binary file modified
BIN
+9.4 KB
(100%)
...nts-screenshot-test-tsx-components-in-vivo-new-inverse-and-dark-mode-1-snap.png
Oops, something went wrong.
Binary file added
BIN
+886 Bytes
...eenshot-test-tsx-text-timer-min-time-unit-minutes-max-time-unit-days-1-snap.png
Oops, something went wrong.
Binary file added
BIN
+886 Bytes
...eenshot-test-tsx-text-timer-min-time-unit-minutes-max-time-unit-days-2-snap.png
Oops, something went wrong.
Binary file added
BIN
+1.22 KB
...eenshot-test-tsx-text-timer-min-time-unit-seconds-max-time-unit-days-1-snap.png
Oops, something went wrong.
Binary file added
BIN
+1.22 KB
...enshot-test-tsx-text-timer-min-time-unit-seconds-max-time-unit-hours-1-snap.png
Oops, something went wrong.
Binary file added
BIN
+725 Bytes
...shot-test-tsx-text-timer-min-time-unit-seconds-max-time-unit-seconds-1-snap.png
Oops, something went wrong.
Binary file added
BIN
+4.47 KB
...__/__image_snapshots__/timer-screenshot-test-tsx-timer-boxed-desktop-1-snap.png
Oops, something went wrong.
Binary file added
BIN
+9.46 KB
...__image_snapshots__/timer-screenshot-test-tsx-timer-boxed-mobile-ios-1-snap.png
Oops, something went wrong.
Binary file added
BIN
+8.74 KB
...snapshots__/timer-screenshot-test-tsx-timer-boxed-with-big-font-size-1-snap.png
Oops, something went wrong.
Binary file added
BIN
+3.53 KB
...r-screenshot-test-tsx-timer-min-time-unit-minutes-max-time-unit-days-1-snap.png
Oops, something went wrong.
Binary file added
BIN
+3.53 KB
...r-screenshot-test-tsx-timer-min-time-unit-minutes-max-time-unit-days-2-snap.png
Oops, something went wrong.
Binary file added
BIN
+4.08 KB
...r-screenshot-test-tsx-timer-min-time-unit-seconds-max-time-unit-days-1-snap.png
Oops, something went wrong.
Binary file added
BIN
+3.57 KB
...-screenshot-test-tsx-timer-min-time-unit-seconds-max-time-unit-hours-1-snap.png
Oops, something went wrong.
Binary file added
BIN
+1.63 KB
...creenshot-test-tsx-timer-min-time-unit-seconds-max-time-unit-seconds-1-snap.png
Oops, something went wrong.
Binary file added
BIN
+27.7 KB
.../__image_snapshots__/timer-screenshot-test-tsx-timer-wraps-if-needed-1-snap.png
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import {openStoryPage, screen, setRootFontSize} from '../test-utils'; | ||
|
||
const DEVICE = ['DESKTOP', 'MOBILE_IOS'] as const; | ||
|
||
test.each` | ||
minTimeUnit | maxTimeUnit | ||
${'seconds'} | ${'hours'} | ||
${'minutes'} | ${'days'} | ||
${'seconds'} | ${'days'} | ||
${'minutes'} | ${'days'} | ||
${'seconds'} | ${'seconds'} | ||
`( | ||
'TextTimer - minTimeUnit = $minTimeUnit, maxTimeUnit = $maxTimeUnit', | ||
async ({minTimeUnit, maxTimeUnit}) => { | ||
await openStoryPage({ | ||
id: 'components-timer--text-timer-story', | ||
args: {minTimeUnit, maxTimeUnit}, | ||
}); | ||
|
||
const timer = await screen.findByTestId('timer'); | ||
|
||
const image = await timer.screenshot(); | ||
expect(image).toMatchImageSnapshot(); | ||
} | ||
); | ||
|
||
test.each` | ||
minTimeUnit | maxTimeUnit | ||
${'seconds'} | ${'hours'} | ||
${'minutes'} | ${'days'} | ||
${'seconds'} | ${'days'} | ||
${'minutes'} | ${'days'} | ||
${'seconds'} | ${'seconds'} | ||
`('Timer - minTimeUnit = $minTimeUnit, maxTimeUnit = $maxTimeUnit', async ({minTimeUnit, maxTimeUnit}) => { | ||
await openStoryPage({ | ||
id: 'components-timer--timer-story', | ||
args: {minTimeUnit, maxTimeUnit}, | ||
}); | ||
|
||
const timer = await screen.findByTestId('timer'); | ||
|
||
const image = await timer.screenshot(); | ||
expect(image).toMatchImageSnapshot(); | ||
}); | ||
|
||
test.each(DEVICE)('Timer - boxed (%s)', async (device) => { | ||
await openStoryPage({ | ||
id: 'components-timer--timer-story', | ||
device, | ||
args: {minTimeUnit: 'seconds', maxTimeUnit: 'days', boxed: true}, | ||
}); | ||
|
||
const timer = await screen.findByTestId('timer'); | ||
|
||
const image = await timer.screenshot(); | ||
expect(image).toMatchImageSnapshot(); | ||
}); | ||
|
||
test('Timer - boxed with big fontSize', async () => { | ||
await openStoryPage({ | ||
id: 'components-timer--timer-story', | ||
args: {minTimeUnit: 'seconds', maxTimeUnit: 'days', boxed: true}, | ||
}); | ||
|
||
await setRootFontSize(32); | ||
|
||
const timer = await screen.findByTestId('timer'); | ||
|
||
const image = await timer.screenshot(); | ||
expect(image).toMatchImageSnapshot(); | ||
}); | ||
|
||
test('Timer - wraps if needed', async () => { | ||
await openStoryPage({ | ||
id: 'components-timer--timer-story', | ||
args: {minTimeUnit: 'seconds', maxTimeUnit: 'days', boxed: true}, | ||
}); | ||
|
||
await setRootFontSize(72); | ||
|
||
const timer = await screen.findByTestId('timer'); | ||
|
||
const image = await timer.screenshot(); | ||
expect(image).toMatchImageSnapshot(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
import * as React from 'react'; | ||
import {ResponsiveLayout, Box, Text3, Timer, TextTimer, Stack, Title1, Text2} from '..'; | ||
import {isEqual} from '../utils/helpers'; | ||
|
||
import type {RemainingTime, TimeUnit} from '../timer'; | ||
import type {Variant} from '../theme-variant-context'; | ||
|
||
export default { | ||
title: 'Components/Timer', | ||
parameters: {fullScreen: true}, | ||
}; | ||
|
||
interface BaseArgs { | ||
themeVariant: Variant; | ||
minTimeUnit: TimeUnit; | ||
maxTimeUnit: TimeUnit; | ||
days: number; | ||
hours: number; | ||
minutes: number; | ||
seconds: number; | ||
} | ||
|
||
const SECOND = 1000; | ||
const MINUTE = SECOND * 60; | ||
const HOUR = MINUTE * 60; | ||
const DAY = HOUR * 24; | ||
|
||
const baseArgs: BaseArgs = { | ||
themeVariant: 'default', | ||
minTimeUnit: 'seconds', | ||
maxTimeUnit: 'hours', | ||
days: 1, | ||
hours: 0, | ||
minutes: 0, | ||
seconds: 0, | ||
}; | ||
|
||
const baseArgTypes = { | ||
themeVariant: { | ||
options: ['default', 'inverse', 'alternative'], | ||
control: {type: 'select'}, | ||
}, | ||
minTimeUnit: { | ||
options: ['undefined', 'seconds', 'minutes', 'hours', 'days'], | ||
control: {type: 'select'}, | ||
}, | ||
maxTimeUnit: { | ||
options: ['undefined', 'seconds', 'minutes', 'hours', 'days'], | ||
control: {type: 'select'}, | ||
}, | ||
}; | ||
|
||
type TextTimerArgs = BaseArgs & {labelType: 'none' | 'short' | 'long'}; | ||
|
||
export const TextTimerStory: StoryComponent<TextTimerArgs> = ({ | ||
labelType, | ||
themeVariant, | ||
minTimeUnit, | ||
maxTimeUnit, | ||
days, | ||
hours, | ||
minutes, | ||
seconds, | ||
}) => { | ||
const [remainingTime, setRemainingTime] = React.useState<RemainingTime>(); | ||
const [endTimestamp, setEndTimestamp] = React.useState( | ||
Date.now() + DAY * days + HOUR * hours + MINUTE * minutes + SECOND * seconds | ||
); | ||
|
||
React.useEffect(() => { | ||
setEndTimestamp(Date.now() + DAY * days + HOUR * hours + MINUTE * minutes + SECOND * seconds); | ||
}, [days, hours, minutes, seconds]); | ||
|
||
return ( | ||
<ResponsiveLayout fullWidth variant={themeVariant}> | ||
<Box padding={16}> | ||
<Stack space={16}> | ||
<Text3 regular> | ||
<TextTimer | ||
dataAttributes={{testid: 'timer'}} | ||
endTimestamp={endTimestamp} | ||
labelType={labelType} | ||
minTimeUnit={minTimeUnit} | ||
maxTimeUnit={maxTimeUnit} | ||
onProgress={(currentValue) => { | ||
if (!isEqual(currentValue, remainingTime)) { | ||
setRemainingTime(currentValue); | ||
} | ||
}} | ||
/> | ||
</Text3> | ||
<Stack space={8}> | ||
<Title1 as="h2">onProgress callback value</Title1> | ||
{remainingTime && ( | ||
<Text2 regular as="pre"> | ||
{JSON.stringify(remainingTime, null, 2)} | ||
</Text2> | ||
)} | ||
<div style={{width: '1ch', height: '1ch', border: '1px solid red'}} /> | ||
</Stack> | ||
</Stack> | ||
</Box> | ||
</ResponsiveLayout> | ||
); | ||
}; | ||
|
||
TextTimerStory.storyName = 'TextTimer'; | ||
TextTimerStory.args = { | ||
labelType: 'none', | ||
...baseArgs, | ||
}; | ||
TextTimerStory.argTypes = { | ||
...baseArgTypes, | ||
labelType: { | ||
options: ['none', 'short', 'long'], | ||
control: {type: 'select'}, | ||
}, | ||
}; | ||
|
||
type TimerArgs = BaseArgs & {boxed: boolean}; | ||
|
||
export const TimerStory: StoryComponent<TimerArgs> = ({ | ||
themeVariant, | ||
minTimeUnit, | ||
maxTimeUnit, | ||
days, | ||
hours, | ||
minutes, | ||
seconds, | ||
boxed, | ||
}) => { | ||
const [remainingTime, setRemainingTime] = React.useState<RemainingTime>(); | ||
const [endTimestamp, setEndTimestamp] = React.useState( | ||
Date.now() + DAY * days + HOUR * hours + MINUTE * minutes + SECOND * seconds | ||
); | ||
|
||
React.useEffect(() => { | ||
setEndTimestamp(Date.now() + DAY * days + HOUR * hours + MINUTE * minutes + SECOND * seconds); | ||
}, [days, hours, minutes, seconds]); | ||
|
||
return ( | ||
<ResponsiveLayout fullWidth variant={themeVariant}> | ||
<Box padding={16}> | ||
<Stack space={16}> | ||
<Timer | ||
dataAttributes={{testid: 'timer'}} | ||
endTimestamp={endTimestamp} | ||
minTimeUnit={minTimeUnit} | ||
maxTimeUnit={maxTimeUnit} | ||
boxed={boxed} | ||
onProgress={(currentValue) => { | ||
if (!isEqual(currentValue, remainingTime)) { | ||
setRemainingTime(currentValue); | ||
} | ||
}} | ||
/> | ||
|
||
<Stack space={8}> | ||
<Title1 as="h2">onProgress callback value</Title1> | ||
{remainingTime && ( | ||
<Text2 regular as="pre"> | ||
{JSON.stringify(remainingTime, null, 2)} | ||
</Text2> | ||
)} | ||
</Stack> | ||
</Stack> | ||
</Box> | ||
</ResponsiveLayout> | ||
); | ||
}; | ||
|
||
TimerStory.storyName = 'Timer'; | ||
TimerStory.args = { | ||
...baseArgs, | ||
boxed: false, | ||
}; | ||
TimerStory.argTypes = { | ||
...baseArgTypes, | ||
}; |
Oops, something went wrong.
0b3253e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deploy preview for mistica-web ready!
✅ Preview
https://mistica-9pxqr4sd5-flows-projects-65bb050e.vercel.app
Built with commit 0b3253e.
This pull request is being automatically deployed with vercel-action