-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
102 additions
and
101 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
export default class WebUIToggle extends HTMLElement { | ||
private switch: HTMLButtonElement | null; | ||
|
||
constructor() { | ||
super(); | ||
this.switch = this.querySelector('[role="switch"]'); | ||
|
||
if (!this.switch) return; | ||
|
||
this.switch.addEventListener('click', this); | ||
} | ||
|
||
// Handle constructor() event listeners. | ||
handleEvent() { | ||
const isChecked = this.switch?.getAttribute('aria-checked') === 'true'; | ||
|
||
this.switch?.setAttribute( | ||
'aria-checked', | ||
Boolean(!isChecked).toString(), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,5 +16,4 @@ | |
@use 'slider'; | ||
@use 'tables'; | ||
@use 'tabs'; | ||
@use 'toggle'; | ||
@use 'video-player'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
@use 'webui-notify'; | ||
@use 'webui-prose'; | ||
@use 'webui-share'; | ||
@use 'webui-toggle'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
ui/stories/6. Web Components Or Custom Elements/WebUIToggle/WebUIToggle.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
export const WebUIToggleHtml = () => ` | ||
<webui-toggle> | ||
<button | ||
class="button" | ||
type="button" | ||
role="switch" | ||
aria-checked="false" | ||
aria-label="toggle / switch" | ||
> | ||
<span class="toggle__on" aria-hidden="true">on</span> | ||
<span class="toggle__off" aria-hidden="true">off</span> | ||
</button> | ||
</webui-toggle> | ||
`; | ||
|
||
export const WebUIToggleWithLabelHtml = () => ` | ||
<webui-toggle> | ||
<button | ||
class="button toggle--has-label" | ||
type="button" | ||
role="switch" | ||
aria-checked="false" | ||
> | ||
<span class="toggle__label">toggle / switch label</span> | ||
<span class="toggle__indicator"> | ||
<span class="toggle__on" aria-hidden="true">on</span> | ||
<span class="toggle__off" aria-hidden="true">off</span> | ||
</span> | ||
</button> | ||
<webui-toggle> | ||
`; |
11 changes: 6 additions & 5 deletions
11
ui/stories/5. Components/Toggle/Toggle.mdx → ...stom Elements/WebUIToggle/WebUIToggle.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
import { Meta, Canvas } from '@storybook/blocks'; | ||
import * as Toggle from './Toggle.stories'; | ||
import * as WebUIToggle from './WebUIToggle.stories'; | ||
|
||
<Meta of={Toggle} /> | ||
<Meta of={WebUIToggle} /> | ||
|
||
# Toggle button (or switch) | ||
# `<webui-toggle>` | ||
- Toggle button (or switch) | ||
|
||
## Accessibility considerations | ||
- See the [ARIA APG switch pattern](https://www.w3.org/WAI/ARIA/apg/patterns/switch/examples/switch-button/) and [Inclusive Components toggle](https://inclusive-components.design/toggle-button/) examples. | ||
|
||
## Toggle with no visible label | ||
<Canvas of={Toggle.Toggle} /> | ||
<Canvas of={WebUIToggle.WebUIToggle} /> | ||
|
||
## Toggle with visible label | ||
<Canvas of={Toggle.ToggleWithLabel} /> | ||
<Canvas of={WebUIToggle.WebUIToggleWithLabel} /> |
19 changes: 19 additions & 0 deletions
19
ui/stories/6. Web Components Or Custom Elements/WebUIToggle/WebUIToggle.stories.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { WebUIToggleHtml, WebUIToggleWithLabelHtml } from './WebUIToggle'; | ||
export default { | ||
title: 'Web Components Or Custom Elements/<webui-toggle>', | ||
parameters: { | ||
status: { | ||
type: 'stable', | ||
}, | ||
}, | ||
}; | ||
|
||
export const WebUIToggle = { | ||
render: () => WebUIToggleHtml(), | ||
}; | ||
WebUIToggle.storyName = '<webui-toggle>'; | ||
|
||
export const WebUIToggleWithLabel = { | ||
render: () => WebUIToggleWithLabelHtml(), | ||
}; | ||
WebUIToggleWithLabel.storyName = '<webui-toggle> With Visible Label'; |