diff --git a/src/@types/storybook-emotion-10-fixes.ts b/src/@types/storybook-emotion-10-fixes.ts index d5e6e1f4f..a07e67e30 100644 --- a/src/@types/storybook-emotion-10-fixes.ts +++ b/src/@types/storybook-emotion-10-fixes.ts @@ -13,9 +13,10 @@ export type Parameters = { [key: string]: any; }; -export type Story = { - (arg0: any): JSX.Element; +export type Story = { + (arg0: Args & T): JSX.Element; args?: Args; parameters?: Parameters; + argTypes?: Args; storyName?: string; }; diff --git a/src/core/components/radio/README.md b/src/core/components/radio/README.md index cc3318524..f4b881e67 100644 --- a/src/core/components/radio/README.md +++ b/src/core/components/radio/README.md @@ -10,101 +10,13 @@ $ yarn add @guardian/src-radio ## Use -```js -import { RadioGroup, Radio } from '@guardian/src-radio'; +### API -const Form = () => { - const [selected, setSelected] = useState(null); +See [storybook](https://guardian.github.io/source/?path=/docs/source-src-radio-radio--demo) - return ( -
- - - , - -
- ); -}; -``` - -## `RadioGroup` Props - -### `name` - -**`string`** - -Gets passed as the name attribute for each radio button - -### `label` - -**`string`** - -Appears as a legend at the top of the radio group - -### `hideLabel` - -**`boolean`** _= "false"_ - -Visually hides the label. - -### `supporting` - -**`string | JSX.Element` ** - -Additional text or component that appears below the label - -### `orientation` - -**`"vertical" | "horizontal"`** _= "vertical"_ - -The direction in which radio buttons are stacked - -### `error` - -**`string`** - -If passed, error styling should applies to this radio group. The string appears as an inline error message. - -## `Radio` Props - -### `label` - -**`ReactNode`** - -Appears to the right of the radio button. If a visible label is undesirable (e.g. for layout reasons) use `aria-label` instead. - -If label is omitted, supporting text will not appear either. - -### `supporting` - -**`ReactNode`** - -Additional text or a component that appears below the label - -### `checked` - -**`boolean`** - -Whether radio button is checked. This is necessary when using the [controlled approach](https://reactjs.org/docs/forms.html#controlled-components) to form state management. +### How to use -**Note:** if you pass the `checked` prop, you **must** also pass an `onChange` handler, or the field will be rendered as read-only. +For context and visual guides relating to usage see the [Source Design System website](https://theguardian.design/2a1e5182b/p/2891dd-radio-button/b/46940d). ## Supported themes diff --git a/src/core/components/radio/Radio.stories.tsx b/src/core/components/radio/Radio.stories.tsx new file mode 100644 index 000000000..7af4f80a6 --- /dev/null +++ b/src/core/components/radio/Radio.stories.tsx @@ -0,0 +1,124 @@ +import React from 'react'; +import { Radio } from './Radio'; +import type { RadioProps } from './Radio'; +import { radioBrand } from './index'; +import { ThemeProvider } from '@emotion/react'; +import type { Story } from '../../../@types/storybook-emotion-10-fixes'; +import { asPlayground, asChromaticStory } from '../../../lib/story-intents'; + +// These types are the right types, but don't work with Storybook v6 which uses Emotion v10 +// import type { Args, Story } from '@storybook/react'; + +export default { + title: 'Source/src-radio/Radio', + component: Radio, + argTypes: { + label: { + control: { + type: 'text', + }, + }, + supporting: { + control: { + type: 'text', + }, + }, + cssOverrides: { + control: null, + }, + }, + args: { + label: 'Red', + value: 'red', + supporting: '', + checked: true, + }, +}; + +const Template: Story = (args: RadioProps) => ; + +// ***************************************************************************** + +export const Playground = Template.bind({}); +asPlayground(Playground); + +// ***************************************************************************** + +export const DefaultLightTheme = Template.bind({}); +asChromaticStory(DefaultLightTheme); + +// ***************************************************************************** + +export const DefaultBrandTheme = (args: RadioProps) => ( + +