Skip to content
This repository has been archived by the owner on Sep 9, 2022. It is now read-only.

Commit

Permalink
fix: prevent initial fanfare on first render
Browse files Browse the repository at this point in the history
  • Loading branch information
Cecilia Woodward committed Aug 28, 2021
1 parent 7544ed5 commit 255e484
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 39 deletions.
14 changes: 7 additions & 7 deletions stories/Actions.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { Button } from './Button';

import { Actions, ActionsProps } from './Actions';
import { Icon } from './Icon';
import { Icon, IconType } from './Icon';

export default {
title: 'Components/Actions',
Expand All @@ -23,16 +23,16 @@ Simple.args = {
primary: (
<>
<Button>
<Icon icon='heart' />
<Icon icon={IconType.Heart} />
</Button>
<Button>
<Icon icon='delete' />
<Icon icon={IconType.Delete} />
</Button>
</>
),
secondary: (
<Button>
<Icon icon='share' />
<Icon icon={IconType.Share} />
</Button>
),
};
Expand All @@ -42,10 +42,10 @@ PrimaryOnly.args = {
primary: (
<>
<Button>
<Icon icon='heart' />
<Icon icon={IconType.Heart} />
</Button>
<Button>
<Icon icon='delete' />
<Icon icon={IconType.Delete} />
</Button>
</>
),
Expand All @@ -55,7 +55,7 @@ export const SecondaryOnly = Template.bind({});
SecondaryOnly.args = {
secondary: (
<Button>
<Icon icon='share' />
<Icon icon={IconType.Share} />
</Button>
),
};
14 changes: 7 additions & 7 deletions stories/Button.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';

import { Button, ButtonProps } from './Button';
import { Theme } from './constants';
import { Icon } from './Icon';
import { Icon, IconType } from './Icon';

export default {
title: 'Components/Button',
Expand Down Expand Up @@ -32,10 +32,10 @@ Secondary.args = {
theme: Theme.Secondary,
};

export const Accent = Template.bind({});
Accent.args = {
export const PrimaryAccent = Template.bind({});
PrimaryAccent.args = {
children: 'Button',
theme: Theme.Accent,
theme: Theme.PrimaryAccent,
};

export const Inverse = Template.bind({});
Expand All @@ -49,7 +49,7 @@ export const WithIcon = Template.bind({});
WithIcon.args = {
children: (
<>
<Icon icon='plus'/>
<Icon icon={IconType.Plus} />
<div>Test with lots of text</div>
</>
),
Expand All @@ -59,15 +59,15 @@ WithIcon.args = {
export const Twitter = Template.bind({});
Twitter.args = {
children: (
<Icon icon='twitter' />
<Icon icon={IconType.Twitter} />
),
theme: Theme.Twitter,
};

export const Facebook = Template.bind({});
Facebook.args = {
children: (
<Icon icon='facebook' />
<Icon icon={IconType.Facebook} />
),
theme: Theme.Secondary,
};
10 changes: 5 additions & 5 deletions stories/Card.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Button } from './Button';
import { Card, CardProps } from './Card';
import { Checkbox } from './Checkbox';
import { Layout } from './constants';
import { Icon } from './Icon';
import { Icon, IconType } from './Icon';
import { Input } from './Input';

export default {
Expand Down Expand Up @@ -39,13 +39,13 @@ Vertical.args = {
primary={(
<>
<Button inverse>
<Icon icon='delete' />
<Icon icon={IconType.Delete} />
</Button>
</>
)}
secondary={(
<Button inverse>
<Icon icon='share' />
<Icon icon={IconType.Share} />
</Button>
)}
/>
Expand All @@ -59,10 +59,10 @@ Horizontal.args = {
children: (
<>
<Button inverse>
<Icon icon='share'/>
<Icon icon={IconType.Share}/>
</Button>
<Button inverse>
<Icon icon='delete'/>
<Icon icon={IconType.Delete}/>
</Button>
</>
),
Expand Down
5 changes: 3 additions & 2 deletions stories/Checkbox.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import classNames from 'classnames';
import React, { useEffect, useState } from 'react';
import styles from './Checkbox.scss';
import { noop } from './utils/noop';
import { Checked } from './constants';

export interface CheckboxProps {
Expand All @@ -26,7 +27,7 @@ export function Checkbox({
checked = false,
className,
disabled = false,
onChange,
onChange = noop,
}: CheckboxProps): JSX.Element {
const [internallyChecked, setInternallyChecked] = useState<Checked>(Checked.Unchecked);

Expand All @@ -44,7 +45,7 @@ export function Checkbox({

const isChecked = [Checked.Unchecked, Checked.Indeterminate].includes(internallyChecked);
setInternallyChecked(isChecked ? Checked.Checked : Checked.Unchecked);
if (onChange) onChange(isChecked);
onChange(isChecked);
}

return (
Expand Down
1 change: 0 additions & 1 deletion stories/Favorite.scss
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@

&.checked > .fanfare {
animation: fanfare steps(27);
animation-duration: 1s;
}
}

Expand Down
12 changes: 9 additions & 3 deletions stories/Favorite.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ export default {

const Template = (args: FavoriteProps) => <Favorite {...args} />;

export const Simple = Template.bind({});
Simple.args = {
export const Unchecked = Template.bind({});
Unchecked.args = {
tooltip: 'This is an example',
}
};

export const Checked = Template.bind({});
Checked.args = {
checked: true,
tooltip: 'This is an example',
};
22 changes: 15 additions & 7 deletions stories/Favorite.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React, { useEffect, useState } from 'react';
import { Icon } from './Icon';
import classNames from 'classnames';
import { Icon, IconType } from './Icon';
import { Tooltip, getTooltipIdentifier } from './Tooltip';

import styles from './Favorite.scss';
import classNames from 'classnames';
import { noop } from './utils/noop';
import { Alignment } from './constants';

export interface FavoriteProps {
Expand All @@ -16,9 +17,10 @@ export interface FavoriteProps {
export function Favorite({
checked,
className,
onChange,
onChange = noop,
tooltip,
}: FavoriteProps): JSX.Element {
const [hasBeenClicked, setHasBeenClicked] = useState<boolean>(false);
const [tooltipId] = useState<string>(() => getTooltipIdentifier())
const [internallyChecked, setInternallyChecked] = useState<boolean>();

Expand All @@ -40,7 +42,8 @@ export function Favorite({

const updatedChecked = !internallyChecked;
setInternallyChecked(updatedChecked);
if (onChange) onChange(updatedChecked);
onChange(updatedChecked);
setHasBeenClicked(true);
}}
>
{tooltip && (
Expand All @@ -52,13 +55,18 @@ export function Favorite({
</Tooltip>
)}
<Icon
icon={'heart'}
icon={IconType.Heart}
/>
<Icon
className={styles.pseudoHover}
icon={'heart'}
icon={IconType.Heart}
/>
<div
className={styles.fanfare}
style={{
animationDuration: hasBeenClicked ? '1s' : '0s',
}}
/>
<div className={styles.fanfare} />
</div>
);
}
8 changes: 4 additions & 4 deletions stories/Grid.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ Vertical.args = {
children: (
<>
<Button>
<Icon icon='delete' />
<Icon icon={IconType.delete} />
</Button>
<Button>
<Icon icon='share' />
<Icon icon={IconType.share} />
</Button>
</>
),
Expand All @@ -39,10 +39,10 @@ Horizontal.args = {
children: (
<>
<Button>
<Icon icon='share'/>
<Icon icon={IconType.share}/>
</Button>
<Button>
<Icon icon='delete'/>
<Icon icon={IconType.delete}/>
</Button>
</>
),
Expand Down
5 changes: 3 additions & 2 deletions stories/Input.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import classNames from 'classnames';
import React, { useEffect, useState } from 'react';
import { Keys, UpdateOn } from './constants';
import { noop } from './utils/noop';
import styles from './Input.scss';

export interface InputProps {
Expand All @@ -11,7 +12,7 @@ export interface InputProps {
/**
* Invoked when the checkbox checked value is modified internally.
*/
onChange: (value: string) => void;
onChange?: (value: string) => void;
submitKeys?: Keys[];

updateOn?: UpdateOn;
Expand All @@ -21,7 +22,7 @@ export function Input({
className,
value,
placeholder,
onChange,
onChange = noop,
submitKeys = [Keys.Enter],
updateOn = UpdateOn.Blur,
}: InputProps): JSX.Element {
Expand Down
2 changes: 1 addition & 1 deletion stories/Tooltip.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default {
const Template = (args: TooltipProps) => (
<>
<Button data-tooltip='add'>
<Icon icon='plus' />
<Icon icon={IconType.plus} />
<Tooltip id='add' {...args}>
Create a List
</Tooltip>
Expand Down
2 changes: 2 additions & 0 deletions stories/utils/noop.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// eslint-disable-next-line @typescript-eslint/no-empty-function
export function noop(): void {}

0 comments on commit 255e484

Please sign in to comment.