Skip to content

Commit 4d6e700

Browse files
committed
update Toggle documentation
1 parent bc50d83 commit 4d6e700

File tree

5 files changed

+53
-46
lines changed

5 files changed

+53
-46
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { ArgTypes } from '@storybook/react'
2+
import type { IToggleProps } from '..'
3+
4+
export const toggleArgTypes: Partial<ArgTypes<IToggleProps>> = {
5+
isOn: {
6+
type: 'boolean',
7+
},
8+
disabled: {
9+
type: 'boolean',
10+
defaultValue: false,
11+
},
12+
}

packages/core/src/Toggle/Toggle.stories.tsx

Lines changed: 35 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
/* eslint-disable react/no-unescaped-entities */
2-
import { ArgsTable, PRIMARY_STORY, Primary } from '@storybook/addon-docs'
2+
import { ArgsTable, PRIMARY_STORY, Primary, Story } from '@storybook/addon-docs'
33
import { Meta, StoryObj } from '@storybook/react'
4-
import {
5-
DoDont,
6-
Hero,
7-
LiveDemo,
8-
RelatedComponent,
9-
RelatedComponentContainer,
10-
Section,
11-
StoryHeading,
12-
StoryStage,
13-
TableOfContents,
14-
} from 'pcln-docs-utils'
154
import { Check as CheckIcon, Close as CloseIcon } from 'pcln-icons'
165
import React, { useState } from 'react'
6+
import type { IToggleProps } from '..'
177
import {
188
Box,
199
Button,
2010
Checkbox,
2111
ChoiceChip,
12+
DoDont,
2213
Flex,
23-
IToggleProps,
14+
Hero,
2415
Image,
2516
Label,
2617
Radio,
18+
RelatedComponent,
19+
RelatedComponentContainer,
20+
Section,
21+
StoryHeading,
22+
StoryStage,
23+
TableOfContents,
2724
Text,
2825
ThemeProvider,
2926
Toggle,
3027
} from '..'
3128

29+
import { toggleArgTypes } from './Toggle.stories.args'
30+
31+
import { linkTo } from '@storybook/addon-links'
3232
import alignmentImage from './Toggle.Image.Alignment.png'
3333
import heroImage from './Toggle.Image.Hero.png'
3434
import statesImage from './Toggle.Image.States.png'
@@ -43,15 +43,7 @@ export const Playground: ToggleStory = {
4343

4444
return <Toggle isOn={isOn} onToggle={onToggle} {...args} />
4545
},
46-
argTypes: {
47-
isOn: {
48-
type: 'boolean',
49-
},
50-
disabled: {
51-
type: 'boolean',
52-
defaultValue: false,
53-
},
54-
},
46+
argTypes: toggleArgTypes,
5547
}
5648

5749
export const Sizes: ToggleStory = {
@@ -104,9 +96,9 @@ const meta: Meta<typeof Toggle> = {
10496
page: () => (
10597
<ThemeProvider>
10698
<Hero name='Toggle' img={heroImage}>
107-
Buttons allow users to trigger an action or event with a single click. For example, you can use a
108-
button for allowing the functionality of submitting a form, opening a dialog, canceling an action,
109-
or performing a delete operation.
99+
A toggle allows users to independently control binary options (a single state that is either on or
100+
off), such as a setting. When a toggle is interacted with, it should take immediate effect and its
101+
appearance should clearly indicate when it's in the activated or deactivated state.
110102
</Hero>
111103

112104
<TableOfContents
@@ -116,8 +108,8 @@ const meta: Meta<typeof Toggle> = {
116108
<Section heading='Overview'>
117109
<Text textStyle='paragraph'>
118110
A toggle allows users to independently control binary options (a single state that is either on
119-
or off), such as a setting. When a toggle is interacted with, it should take immediately effect
120-
and it's appearance should clearly indicate when it's activated or deactivated state.
111+
or off), such as a setting. When a toggle is interacted with, it should take immediate effect
112+
and and its appearance should indicate whether it's activated or deactivated.
121113
</Text>
122114
</Section>
123115

@@ -135,23 +127,24 @@ const meta: Meta<typeof Toggle> = {
135127
<Section heading='Examples'>
136128
<StoryHeading storyName='Sizes' storyTitle={meta.title} />
137129
<Text textStyle='paragraph'>
138-
Toggles support two toggle sizes that consists of a base size, and a small size. These sizes
139-
allow for hierarchy, emphasis, larger/smaller touch targets, and flexibility.
130+
Toggles support two sizes, <code>base</code> and <code>small</code>. These sizes allow for
131+
hierarchy, emphasis, larger/smaller touch targets, and flexibility.
140132
</Text>
141-
<LiveDemo code={Sizes} />
133+
<Story name='Sizes' />
142134

143-
<StoryHeading storyName='With Icon' storyTitle={meta.title} />
135+
<StoryHeading storyName='WithIcon' storyTitle={meta.title} />
144136
<Text textStyle='paragraph'>
145-
Toggles support two toggle sizes that consists of a base size, and a small size. These sizes
146-
allow for hierarchy, emphasis, larger/smaller touch targets, and flexibility.
137+
Toggles support two sizes, <code>base</code> and <code>small</code>. These sizes allow for
138+
hierarchy, emphasis, larger/smaller touch targets, and flexibility.
147139
</Text>
148-
<LiveDemo code={WithIcon} />
140+
<Story name='With Icon' />
149141
</Section>
150142

151143
<Section heading='Usage'>
152144
<Text.p textStyle='paragraph'>
153-
Toggles should be used to adjust a setting, or if each item in a set can be independently
154-
controlled. They’re used to control binary options, such as on/off or true/false.
145+
Toggles can contain an optional icon that can be used to visually emphasize the selected state.
146+
The icon's meaning should clearly indicate to help the user understand whether the toggle is
147+
switched on or off.
155148
</Text.p>
156149
<Box p={3} my={3} borderRadius='xl' bg='primary.light'>
157150
<Image src={usageImage} />
@@ -179,7 +172,7 @@ const meta: Meta<typeof Toggle> = {
179172
}
180173
doText='have a toggle with context or an inline label (short and direct) to describe the option that the toggle controls'
181174
dontExample={<Toggle />}
182-
dontText="have a toggle on it's own without any context or an inline label that leaves the user wondering that it controls"
175+
dontText='have a toggle on its own without any context or an inline label that leaves the user wondering what it controls'
183176
/>
184177
<DoDont
185178
doExample={
@@ -204,7 +197,7 @@ const meta: Meta<typeof Toggle> = {
204197
</Label>
205198
</Flex>
206199
}
207-
dontText='use toggle if an item is opposing options, especially those that can be independently controlled'
200+
dontText='use toggle if an item has opposing options, especially those that can be independently controlled'
208201
/>
209202
<DoDont
210203
doExample={
@@ -213,7 +206,7 @@ const meta: Meta<typeof Toggle> = {
213206
<Toggle isOn />
214207
</Flex>
215208
}
216-
doText='use toggle to a setting that would take immediate and noticeable effect'
209+
doText='use toggle to change a setting that would take immediate and noticeable effect'
217210
dontExample={
218211
<Flex alignItems='center' style={{ gap: 8 }}>
219212
<Label>Show Savings</Label>
@@ -247,18 +240,18 @@ const meta: Meta<typeof Toggle> = {
247240

248241
<Section heading='Related Components'>
249242
<RelatedComponentContainer>
250-
<RelatedComponent name='Radio'>
243+
<RelatedComponent name='Radio' onClick={linkTo('Radio')}>
251244
<Box>
252245
<Label nowrap>
253246
<Radio />
254247
Radio
255248
</Label>
256249
</Box>
257250
</RelatedComponent>
258-
<RelatedComponent name='ChoiceChip' linkTo='core-chip-ChoiceChip'>
251+
<RelatedComponent name='ChoiceChip' onClick={linkTo('core-chip-ChoiceChip')}>
259252
<ChoiceChip>Choice Chip</ChoiceChip>
260253
</RelatedComponent>
261-
<RelatedComponent name='CheckBox'>
254+
<RelatedComponent name='CheckBox' onClick={linkTo('Checkbox')}>
262255
<Box>
263256
<Label nowrap>
264257
<Checkbox />

packages/core/src/Toggle/Toggle.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import React from 'react'
21
import PropTypes from 'prop-types'
2+
import React from 'react'
33
import styled from 'styled-components'
4-
import { Box, Absolute, Input, getPaletteColor } from '..'
4+
import { Absolute, Box, Input, getPaletteColor } from '..'
55

66
const alphaColor = (color: string, props) => `${getPaletteColor(color)(props)}4C`
77

packages/core/src/Toggle/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
export { IToggleProps, default as Toggle } from './Toggle'
1+
export { default as Toggle } from './Toggle'
2+
export type { IToggleProps } from './Toggle'

packages/core/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ export { Text } from './Text'
5858
export { TextArea } from './TextArea'
5959
export { Toast } from './Toast'
6060
export { ToastProvider } from './ToastProvider'
61-
export { IToggleProps, Toggle } from './Toggle'
61+
export { Toggle } from './Toggle'
62+
export type { IToggleProps } from './Toggle'
6263
export { ToggleBadge } from './ToggleBadge'
6364
export { Tooltip } from './Tooltip'
6465
export { Truncate } from './Truncate'

0 commit comments

Comments
 (0)