Skip to content

Commit

Permalink
chore: update checkbox docs (#333)
Browse files Browse the repository at this point in the history
  • Loading branch information
atomictangerine authored Feb 24, 2023
1 parent 8a9b8af commit 291549c
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 22 deletions.
105 changes: 84 additions & 21 deletions build.washingtonpost.com/docs/components/checkbox.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,9 @@ export default function Example() {
gap: "$100",
}}
>
<Checkbox
checked
variant="primary"
size="125"
label="Click checkbox to see focus"
/>
<Checkbox checked variant="primary" size="125">
Click checkbox to see focus
</Checkbox>
</Box>
);
}
Expand All @@ -222,13 +219,9 @@ export default function Example() {
gap: "$100",
}}
>
<Checkbox
checked
variant="primary"
size="125"
label="This is a required checkbox"
required
/>
<Checkbox checked variant="primary" size="125" required>
This is a required checkbox
</Checkbox>
</Box>
);
}
Expand Down Expand Up @@ -290,9 +283,10 @@ export default function Example() {
variant="primary"
isOutline
size="125"
label="Category"
id="cb1"
/>
>
Category
</Checkbox>
</Box>
<Box css={{ paddingLeft: "$100" }}>
<Box
Expand All @@ -304,9 +298,10 @@ export default function Example() {
variant="primary"
isOutline
size="125"
label="Option 1"
id="cb2"
/>
>
Option 1
</Checkbox>
</Box>
<Box
onClick={() => setCheck3(!Check3)}
Expand All @@ -322,9 +317,10 @@ export default function Example() {
variant="primary"
isOutline
size="125"
label="Option 2"
id="cb3"
/>
>
Option 2
</Checkbox>
</Box>
</Box>
</Box>
Expand Down Expand Up @@ -363,9 +359,76 @@ export default function Example() {
variant="primary"
isOutline
size="125"
label="Checkbox"
id="cb4"
/>
>
Checkbox
</Checkbox>
</Box>
</Box>
);
}
```

### Custom labels

You may want different styles applied to your labels.

```jsx withPreview isGuide="success"
export default function Example() {
const [Check1, setCheck1] = useState(false);
const [Check2, setCheck2] = useState(false);

const StyledLabel = styled("div", {
textDecoration: "line-through",
});

return (
<Box
css={{
display: "flex",
flexDirection: "column",
justifyContent: "center",
gap: "$100",
}}
>
<Box
onClick={() => setCheck1(!Check1)}
css={{
cursor: "pointer",
display: "flex",
marginTop: "$100",
gap: "$025",
}}
>
<Checkbox
checked={Check1}
variant="primary"
isOutline
size="125"
id="cb4"
>
<StyledLabel>This label is struck through</StyledLabel>
</Checkbox>
</Box>
<Box
onClick={() => setCheck2(!Check2)}
css={{
cursor: "pointer",
display: "flex",
marginTop: "$100",
gap: "$025",
}}
>
<Checkbox
checked={Check2}
variant="primary"
isOutline
size="125"
id="cb5"
>
This label has{" "}
<a href="https://www.washingtonpost.com"> a link to the homepage</a>
</Checkbox>
</Box>
</Box>
);
Expand Down
38 changes: 37 additions & 1 deletion ui/checkbox/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,42 @@
import { Checkbox } from "@washingtonpost/wpds-ui-kit";

function Component() {
return <Checkbox variant="primary" />;
return <Checkbox variant="primary">Checkbox label</Checkbox>;
}
```

### Checkbox Label

There are two ways you can pass in a label to the checkbox component:

- The label prop. This option only takes in a string.
- As a child. This allows you to style your label to your preference. You can include links, custom stylings, etc.

```jsx
import { Checkbox } from "@washingtonpost/wpds-ui-kit";

function Component() {
const StyledLabel = styled("div", {
textDecoration: "line-through",
});

return (
<Checkbox variant="primary">
<StyledLabel>This is the label</StyledLabel>
</Checkbox>
);
}
```

```jsx
import { Checkbox } from "@washingtonpost/wpds-ui-kit";

function Component() {
return (
<Checkbox variant="primary">
You can pass in links.{" "}
<a href="build.washingtonpost.com">Like this link to our docs site</a>
</Checkbox>
);
}
```
2 changes: 2 additions & 0 deletions ui/checkbox/src/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ interface CheckboxInterface extends CheckboxVariants {
value?: string;
id?: string;
label?: string;
/** The correspoding label to the checkbox. Allows you to pass in more than just text */
children?: React.ReactNode;
}

const StyledCheck = styled("span", {
Expand Down

2 comments on commit 291549c

@vercel
Copy link

@vercel vercel bot commented on 291549c Feb 24, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

wpds-ui-kit – ./build.washingtonpost.com

build.washingtonpost.com
wpds-ui-kit-git-main.preview.now.washingtonpost.com
wpds-ui-kit.preview.now.washingtonpost.com

@vercel
Copy link

@vercel vercel bot commented on 291549c Feb 24, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

wpds-ui-kit-storybook – ./

wpds-ui-kit-storybook-git-main.preview.now.washingtonpost.com
wpds-ui-kit-storybook.preview.now.washingtonpost.com

Please sign in to comment.