mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-04-25 11:59:11 +00:00
feat: add basis of toggle atom
This commit is contained in:
parent
3172870aaf
commit
8b8f053525
4 changed files with 39 additions and 0 deletions
23
packages/design-system/atoms/toggle/Toggle.stories.tsx
Normal file
23
packages/design-system/atoms/toggle/Toggle.stories.tsx
Normal file
|
@ -0,0 +1,23 @@
|
|||
import * as React from 'react';
|
||||
import { Toggle } from './Toggle';
|
||||
export default {
|
||||
title: 'Atoms/Toggle',
|
||||
component: Toggle,
|
||||
};
|
||||
|
||||
export const toggle = (args) => <Toggle {...args}>Turn a cool thing on</Toggle>;
|
||||
export const interactive = (args) => {
|
||||
const [state, setState] = React.useState(true);
|
||||
return (
|
||||
<Toggle
|
||||
{...args}
|
||||
state={state}
|
||||
onChange={(val) => {
|
||||
setState(val);
|
||||
args.onChange(val);
|
||||
}}
|
||||
>
|
||||
Turn a cool thing on
|
||||
</Toggle>
|
||||
);
|
||||
};
|
0
packages/design-system/atoms/toggle/Toggle.styled.tsx
Normal file
0
packages/design-system/atoms/toggle/Toggle.styled.tsx
Normal file
15
packages/design-system/atoms/toggle/Toggle.tsx
Normal file
15
packages/design-system/atoms/toggle/Toggle.tsx
Normal file
|
@ -0,0 +1,15 @@
|
|||
type ToggleProps = {
|
||||
onChange?: (newState: boolean) => void;
|
||||
children: React.ReactNode;
|
||||
state: boolean;
|
||||
};
|
||||
|
||||
export const Toggle = (props: ToggleProps) => (
|
||||
<div
|
||||
onClick={() => {
|
||||
props.onChange?.(!props.state);
|
||||
}}
|
||||
>
|
||||
{props.children}:<div>{props.state ? 'on' : 'off'}!</div>
|
||||
</div>
|
||||
);
|
1
packages/design-system/atoms/toggle/index.ts
Normal file
1
packages/design-system/atoms/toggle/index.ts
Normal file
|
@ -0,0 +1 @@
|
|||
export * from './Toggle';
|
Loading…
Add table
Reference in a new issue