Skip to content

Commit 98277a8

Browse files
prakashramancappslock
authored andcommitted
Add docs for POS > PWC > Switch component
1 parent 553f2c8 commit 98277a8

File tree

5 files changed

+81
-0
lines changed

5 files changed

+81
-0
lines changed
14.7 KB
Loading
7.75 KB
Loading
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import {ReferenceEntityTemplateSchema} from '@shopify/generate-docs';
2+
3+
const data: ReferenceEntityTemplateSchema = {
4+
name: 'Switch',
5+
description:
6+
'The `Switch` component creates a toggle control that allows merchants to turn an option on or off. Use switches for settings that take effect immediately, such as enabling notifications or toggling features.' +
7+
"\n\nSwitches provide clear visual feedback about the current state and are ideal for binary choices that don't require confirmation.",
8+
thumbnail: 'switch-thumbnail.png',
9+
isVisualComponent: true,
10+
type: '',
11+
definitions: [
12+
{
13+
title: 'Properties',
14+
description:
15+
'Configure the following properties on the `Switch` component.',
16+
type: 'Switch',
17+
},
18+
{
19+
title: 'Events',
20+
description:
21+
'The `Switch` component provides event callbacks for handling user interactions. Learn more about [handling events](/docs/api/polaris/using-polaris-web-components#handling-events).',
22+
type: 'SwitchEvents',
23+
},
24+
],
25+
category: 'Polaris web components',
26+
subCategory: 'Forms',
27+
defaultExample: {
28+
image: 'switch-default.png',
29+
description:
30+
'Toggle settings on or off using a `Switch` component. This example shows a basic switch with a label.',
31+
codeblock: {
32+
title: 'Create a toggle switch',
33+
tabs: [
34+
{
35+
code: './examples/default.html',
36+
language: 'html',
37+
},
38+
],
39+
},
40+
},
41+
subSections: [
42+
{
43+
type: 'Generic',
44+
anchorLink: 'accessibility',
45+
title: 'Accessibility',
46+
sectionContent: `
47+
- **Provide descriptive labels:** Use the \`label\` prop to clearly describe what the switch controls.
48+
- **Use accessibility labels when needed:** If the visual label doesn't provide enough context, use the \`accessibilityLabel\` prop to provide additional information for screen readers.
49+
- **Indicate disabled state:** When a switch is disabled, ensure the reason is communicated to users through surrounding context or helper text.
50+
`,
51+
},
52+
],
53+
related: [],
54+
examples: {
55+
description: 'Learn how to handle switch change events.',
56+
examples: [
57+
{
58+
description:
59+
'Subscribe to the `onChange` event to respond when merchants toggle the switch. This example shows how to handle state changes and capture the checked value in real time, enabling dynamic behavior based on the switch state.',
60+
codeblock: {
61+
title: 'Handle switch change events',
62+
tabs: [
63+
{
64+
code: './examples/event-handling.html',
65+
language: 'html',
66+
},
67+
],
68+
},
69+
},
70+
],
71+
},
72+
};
73+
74+
export default data;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<s-switch label="Option 1" />
2+
<s-switch label="Option 2" defaultChecked />
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<s-switch
2+
label="Enable email notifications"
3+
defaultChecked
4+
onChange={(event) => console.log('Switch toggled:', event.currentTarget.checked)}
5+
/>

0 commit comments

Comments
 (0)