Skip to content

Commit 359d1d9

Browse files
authored
Add docs for POS > PWC > Switch component (#3659)
Fixes [#21064](shop/issues-retail#21064) ### Background Add documentation for the Switch component in the Point of Sale surface. ### Solution This PR adds comprehensive documentation for the `Switch` component in the Point of Sale surface, including: - Component description and usage guidelines - Property and event definitions - Default example showing basic usage with labels - Event handling example demonstrating how to respond to toggle changes - Accessibility best practices - Supporting screenshots for visual reference The documentation explains that the Switch component creates a toggle control for binary choices that take effect immediately, such as enabling notifications or toggling features. ### 🎩 - To be tophatted only by the App Platform Team, as the tophatting procedures for individual component additions are tricky at the moment ### Checklist - [x] I have 🎩'd these changes - [x] I have updated relevant documentation --- ![image.png](https://app.graphite.com/user-attachments/assets/944b18de-ed25-4431-b58e-572b7b8256d2.png) ![image.png](https://app.graphite.com/user-attachments/assets/18c53e93-c257-4183-85a4-db32bf39cabc.png) ![image.png](https://app.graphite.com/user-attachments/assets/a8a987fa-d2c7-46ef-8891-fb70703456e0.png)
2 parents 553f2c8 + 98277a8 commit 359d1d9

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)