Skip to content

Commit

Permalink
Add togglePosition prop to Toggle component (#1509)
Browse files Browse the repository at this point in the history
  • Loading branch information
felixhabib authored Jun 18, 2024
1 parent be8cab4 commit 16bc197
Show file tree
Hide file tree
Showing 7 changed files with 275 additions and 78 deletions.
17 changes: 17 additions & 0 deletions .changeset/few-planets-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
'braid-design-system': minor
---

---
updated:
- Toggle
---

**Toggle:** Add `togglePosition` prop

Introduces the `togglePosition` prop, enabling the toggle to either be `leading` or `trailing` its label text.

**EXAMPLE USAGE:**
```jsx
<Toggle togglePosition="trailing" label="Label" />
```
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,41 @@ const docs: ComponentDocs = {
</Stack>,
),
},
{
label: 'Toggle position',
description: (
<>
<Text>
By default, the position of the toggle relative to the label text
will be determined by its <Strong>align</Strong> prop.
</Text>
<Text>
This can be overridden by setting the{' '}
<Strong>togglePosition</Strong> prop to either{' '}
<Strong>leading</Strong> or <Strong>trailing</Strong>.
</Text>
</>
),
Example: ({ id, getState, toggleState }) =>
source(
<Stack space="large" dividers>
<Toggle
label="Leading"
id={`${id}_leading`}
on={getState('toggleLeading')}
onChange={() => toggleState('toggleLeading')}
togglePosition="leading"
/>
<Toggle
label="Trailing"
id={`${id}_trailing`}
on={getState('toggleTrailing')}
onChange={() => toggleState('toggleTrailing')}
togglePosition="trailing"
/>
</Stack>,
),
},
{
label: 'Sizes',
description: (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ export const galleryItems: GalleryComponent = {
/>,
),
},
{
label: 'Toggle Position: "leading" | "trailing"',
Example: ({ id, getState, toggleState }) =>
source(
<Toggle
togglePosition="trailing"
label="Trailing toggle"
id={id}
on={getState('toggle')}
onChange={() => toggleState('toggle')}
/>,
),
},
{
label: 'Toggle Alignment: "left" | "justify" | "right"',
Example: ({ id, getState, toggleState }) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const screenshots: ComponentScreenshot = {
),
},
{
label: 'Right aligned',
label: 'Right aligned with default toggle position',
Container: ({ children }) => (
<div style={{ maxWidth: '300px' }}>{children}</div>
),
Expand All @@ -47,7 +47,7 @@ export const screenshots: ComponentScreenshot = {
),
},
{
label: 'Justified',
label: 'Justified with default toggle position',
Container: ({ children }) => (
<div style={{ maxWidth: '300px' }}>{children}</div>
),
Expand Down Expand Up @@ -78,6 +78,102 @@ export const screenshots: ComponentScreenshot = {
</Box>
),
},
{
label: 'Left aligned with leading toggle position',
Container: ({ children }) => (
<div style={{ maxWidth: '300px' }}>{children}</div>
),
Example: ({ id, handler }) => (
<Toggle
on={true}
align="left"
togglePosition="leading"
label="Aligned left, leading toggle"
id={id}
onChange={handler}
/>
),
},
{
label: 'Left aligned with trailing toggle position',
Container: ({ children }) => (
<div style={{ maxWidth: '300px' }}>{children}</div>
),
Example: ({ id, handler }) => (
<Toggle
on={true}
align="left"
togglePosition="trailing"
label="Aligned left, trailing toggle"
id={id}
onChange={handler}
/>
),
},
{
label: 'Justified with leading toggle position',
Container: ({ children }) => (
<div style={{ maxWidth: '300px' }}>{children}</div>
),
Example: ({ id, handler }) => (
<Toggle
on={true}
align="justify"
togglePosition="leading"
label="Justified, leading toggle"
id={id}
onChange={handler}
/>
),
},
{
label: 'Justified with trailing toggle position',
Container: ({ children }) => (
<div style={{ maxWidth: '300px' }}>{children}</div>
),
Example: ({ id, handler }) => (
<Toggle
on={true}
align="justify"
togglePosition="trailing"
label="Justified, trailing toggle"
id={id}
onChange={handler}
/>
),
},
{
label: 'Right aligned with leading toggle position',
Container: ({ children }) => (
<div style={{ maxWidth: '300px' }}>{children}</div>
),
Example: ({ id, handler }) => (
<Toggle
on={true}
align="right"
togglePosition="leading"
label="Right aligned, leading toggle"
id={id}
onChange={handler}
/>
),
},
{
label: 'Right aligned with trailing toggle position',
Container: ({ children }) => (
<div style={{ maxWidth: '300px' }}>{children}</div>
),
Example: ({ id, handler }) => (
<Toggle
on={true}
align="right"
togglePosition="trailing"
label="Right aligned, trailing toggle"
id={id}
onChange={handler}
/>
),
},
{
label: 'With a long label',
Container: ({ children }) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ export const snippets: Snippets = [
name: 'Justified',
code: source(<Toggle label="Label" align="justify" />),
},
{
name: 'Trailing toggle position',
code: source(<Toggle label="Label" togglePosition="trailing" />),
},
];
Loading

0 comments on commit 16bc197

Please sign in to comment.