Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ToggleButton): story controls #2793

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions packages/components/button/stories/ToggleButton.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Icon } from '@contentful/f36-icon';
import * as icons from '@contentful/f36-icons';

import { ButtonGroup } from '../src';
import { ToggleButton } from '../src/ToggleButton';
import { ToggleButton, ToggleButtonProps } from '../src/ToggleButton';

export default {
title: 'Components/Button components/ToggleButton',
Expand All @@ -28,17 +28,17 @@ export default {
},
} as Meta;

export const Basic = ({ icon, children, isDisabled }) => {
export const Basic = ({ icon, children, ...rest }: ToggleButtonProps) => {
const [isActive, setIsActive] = useState(false);

return (
<ToggleButton
isDisabled={isDisabled}
isActive={isActive}
icon={icon && <Icon as={icons[icon]} />}
onToggle={() => {
setIsActive(!isActive);
}}
icon={icon && <Icon as={icons[icon]} />}
{...rest}
>
{children}
</ToggleButton>
Expand Down Expand Up @@ -119,21 +119,23 @@ export const GroupedWithOnlyOneActive = () => {
);
};

export const Overview = ({ icon, ...props }) => (
export const Overview = ({ icon, onToggle, ...rest }: ToggleButtonProps) => (
<>
<Flex flexDirection="column" marginBottom="spacingL">
<SectionHeading as="h3" marginBottom="spacingS">
Toggle variants
</SectionHeading>

<Stack marginBottom="spacingM" spacing="spacingXs">
<ToggleButton onToggle={props.onToggle}>Default</ToggleButton>
<ToggleButton onToggle={onToggle} {...rest}>
Default
</ToggleButton>

<ToggleButton isActive onToggle={props.onToggle}>
<ToggleButton isActive onToggle={onToggle} {...rest}>
Active
</ToggleButton>

<ToggleButton isDisabled onToggle={props.onToggle}>
<ToggleButton isDisabled onToggle={onToggle} {...rest}>
Disabled
</ToggleButton>
</Stack>
Expand All @@ -145,24 +147,27 @@ export const Overview = ({ icon, ...props }) => (

<Stack marginBottom="spacingM" spacing="spacingXs">
<ToggleButton
onToggle={props.onToggle}
onToggle={onToggle}
icon={icon && <Icon as={icons[icon]} />}
{...rest}
>
Default
</ToggleButton>

<ToggleButton
onToggle={props.onToggle}
onToggle={onToggle}
isActive
icon={icon && <Icon as={icons[icon]} />}
{...rest}
>
Active
</ToggleButton>

<ToggleButton
onToggle={props.onToggle}
onToggle={onToggle}
isDisabled
icon={icon && <Icon as={icons[icon]} />}
{...rest}
>
Disabled
</ToggleButton>
Expand Down
Loading