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

feat(docs): update checkbox page to use new layout #611

Merged
merged 1 commit into from
Oct 7, 2021
Merged
Show file tree
Hide file tree
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
30 changes: 26 additions & 4 deletions packages/docs/PropTables/CheckboxPropTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,22 @@ const checkboxProps: Prop[] = [
},
{
name: 'description',
types: ['string', 'CheckboxDescription'],
types: [
'string',
<NextLink
key="checkbox-description"
href={{ hash: 'checkbox-description-prop-table', query: { props: 'checkbox-description' } }}
>
CheckboxDescription
</NextLink>,
],
description: (
<>
See <NextLink href="#checkbox-description-prop-table">below</NextLink> for usage.
See{' '}
<NextLink href={{ hash: 'checkbox-description-prop-table', query: { props: 'checkbox-description' } }}>
CheckboxDescription
</NextLink>{' '}
for usage.
</>
),
},
Expand All @@ -54,10 +66,20 @@ const checkboxDescriptionProps: Prop[] = [
},
{
name: 'link',
types: ['CheckboxDescriptionLink'],
types: (
<NextLink href={{ hash: 'checkbox-description-link-prop-table', query: { props: 'checkbox-description-link' } }}>
CheckboxDescriptionLink
</NextLink>
),
description: (
<>
See <NextLink href="#checkbox-description-link-prop-table">below</NextLink> for usage.
See{' '}
<NextLink
href={{ hash: 'checkbox-description-link-prop-table', query: { props: 'checkbox-description-link' } }}
>
CheckboxDescriptionLink
</NextLink>{' '}
for usage.
</>
),
},
Expand Down
246 changes: 144 additions & 102 deletions packages/docs/pages/checkbox.tsx
Original file line number Diff line number Diff line change
@@ -1,116 +1,158 @@
import { Checkbox, Form, FormGroup, H1, Panel, Text } from '@bigcommerce/big-design';
import React, { useState } from 'react';

import { Code, CodePreview, PageNavigation } from '../components';
import { Code, CodePreview, ContentRoutingTabs, List } from '../components';
import { CheckboxDescriptionLinkPropTable, CheckboxDescriptionPropTable, CheckboxPropTable } from '../PropTables';

const CheckboxPage = () => {
const items = [
{
id: 'examples',
title: 'Examples',
render: () => (
<>
<Panel>
<Text>
Checkboxes are a stylized <Code>input[type="checkbox"]</Code> with controllable checked/unchecked states.
</Text>
<CodePreview>
{/* jsx-to-string:start */}
{function Example() {
const [checked, setChecked] = useState(false);
const handleChange = () => setChecked(!checked);
return (
<>
<H1>Checkbox</H1>

return (
<Form>
<FormGroup>
<Checkbox label={checked ? 'Checked' : 'Unchecked'} checked={checked} onChange={handleChange} />
<Checkbox label="Disabled" disabled={true} />
</FormGroup>
</Form>
);
}}
{/* jsx-to-string:end */}
</CodePreview>
</Panel>
<Panel header="Indeterminate">
<Text>
Checkboxes support <Code primary>isIndeterminate</Code> passed as a prop to show a combined state of
partially selected checkboxes.
</Text>
<Panel header="Overview" headerId="overview">
<Text>Checkboxes let users toggle settings on and off within a form.</Text>
<Text bold>When to use it:</Text>
<List>
<List.Item>Use checkboxes when users can make toggle one or more items in a form.</List.Item>
</List>
Comment on lines +14 to +17
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In hindsight, we probably should have make a component for this 🤔 (just a comment, no action needed)

</Panel>

<CodePreview>
{/* jsx-to-string:start */}
<Form>
<FormGroup>
<Checkbox label="Indeterminate" isIndeterminate />
</FormGroup>
</Form>
{/* jsx-to-string:end */}
</CodePreview>
</Panel>
<Panel header="Description">
<Text>
Checkboxes support <Code primary>description</Code> passed as a prop, which contains a text and an
optional link.
</Text>
<CodePreview>
{/* jsx-to-string:start */}
{function Example() {
const [checkedA, setChangeA] = useState(false);
const [checkedB, setChangeB] = useState(false);
const handleChangeA = () => setChangeA(!checkedA);
const handleChangeB = () => setChangeB(!checkedB);
<Panel header="Implementation" headerId="implementation">
<ContentRoutingTabs
id="implementation"
routes={[
{
id: 'basic',
title: 'Basic',
render: () => (
<>
<Text>
Checkboxes are a stylized <Code>input[type="checkbox"]</Code> with controllable checked/unchecked
states.
</Text>

return (
<Form>
<FormGroup>
<Checkbox
onChange={handleChangeA}
checked={checkedA}
label="Checkbox with description and link"
description={{
text: 'I am a CheckboxDescription.',
link: {
text: 'Learn more',
href: 'http://www.bigcommerce.com',
},
}}
/>
<Checkbox
onChange={handleChangeB}
checked={checkedB}
label="Checkbox with description"
description="I am a string description."
/>
</FormGroup>
</Form>
);
}}
{/* jsx-to-string:end */}
</CodePreview>
</Panel>
</>
),
},
{
id: 'props',
title: 'Props',
render: () => (
<>
<CheckboxPropTable />
<CheckboxDescriptionPropTable />
<CheckboxDescriptionLinkPropTable />
</>
),
},
];
<CodePreview>
{/* jsx-to-string:start */}
{function Example() {
const [checked, setChecked] = useState(false);
const handleChange = () => setChecked(!checked);

return (
<>
<H1>Checkbox</H1>
return (
<Form>
<FormGroup>
<Checkbox
label={checked ? 'Checked' : 'Unchecked'}
checked={checked}
onChange={handleChange}
/>
<Checkbox label="Disabled" disabled={true} />
</FormGroup>
</Form>
);
}}
{/* jsx-to-string:end */}
</CodePreview>
</>
),
},
{
id: 'indeterminate',
title: 'Indeterminate',
render: () => (
<>
<Text>
Checkboxes support <Code primary>isIndeterminate</Code> passed as a prop to show a combined state of
partially selected checkboxes.
</Text>

<CodePreview>
{/* jsx-to-string:start */}
<Form>
<FormGroup>
<Checkbox label="Indeterminate" isIndeterminate />
</FormGroup>
</Form>
{/* jsx-to-string:end */}
</CodePreview>
</>
),
},
{
id: 'description',
title: 'Description',
render: () => (
<>
<Text>
Checkboxes support <Code primary>description</Code> passed as a prop, which contains a text and an
optional link.
</Text>

<CodePreview>
{/* jsx-to-string:start */}
{function Example() {
const [checkedA, setChangeA] = useState(false);
const [checkedB, setChangeB] = useState(false);
const handleChangeA = () => setChangeA(!checkedA);
const handleChangeB = () => setChangeB(!checkedB);

return (
<Form>
<FormGroup>
<Checkbox
onChange={handleChangeA}
checked={checkedA}
label="Checkbox with description and link"
description={{
text: 'I am a CheckboxDescription.',
link: {
text: 'Learn more',
href: 'http://www.bigcommerce.com',
},
}}
/>
<Checkbox
onChange={handleChangeB}
checked={checkedB}
label="Checkbox with description"
description="I am a string description."
/>
</FormGroup>
</Form>
);
}}
{/* jsx-to-string:end */}
</CodePreview>
</>
),
},
]}
/>
</Panel>

<PageNavigation items={items} />
<Panel header="Props" headerId="props">
<ContentRoutingTabs
id="props"
routes={[
{
id: 'checkbox',
title: 'Checkbox',
render: () => <CheckboxPropTable renderPanel={false} />,
},
{
id: 'checkbox-description',
title: 'CheckboxDescription',
render: () => <CheckboxDescriptionPropTable id="checkbox-description-prop-table" renderPanel={false} />,
},
{
id: 'checkbox-description-link',
title: 'CheckboxDescriptionLink',
render: () => (
<CheckboxDescriptionLinkPropTable id="checkbox-description-link-prop-table" renderPanel={false} />
),
},
]}
/>
</Panel>
</>
);
};
Expand Down