@discourser/design-system 0.3.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -4
- package/dist/styles.css +5126 -0
- package/guidelines/Guidelines.md +92 -41
- package/guidelines/components/accordion.md +732 -0
- package/guidelines/components/avatar.md +1015 -0
- package/guidelines/components/badge.md +728 -0
- package/guidelines/components/button.md +75 -40
- package/guidelines/components/card.md +84 -25
- package/guidelines/components/checkbox.md +671 -0
- package/guidelines/components/dialog.md +619 -31
- package/guidelines/components/drawer.md +1616 -0
- package/guidelines/components/heading.md +576 -0
- package/guidelines/components/icon-button.md +92 -37
- package/guidelines/components/input-addon.md +685 -0
- package/guidelines/components/input-group.md +830 -0
- package/guidelines/components/input.md +92 -37
- package/guidelines/components/popover.md +1271 -0
- package/guidelines/components/progress.md +836 -0
- package/guidelines/components/radio-group.md +852 -0
- package/guidelines/components/select.md +1662 -0
- package/guidelines/components/skeleton.md +802 -0
- package/guidelines/components/slider.md +911 -0
- package/guidelines/components/spinner.md +783 -0
- package/guidelines/components/switch.md +105 -38
- package/guidelines/components/tabs.md +1488 -0
- package/guidelines/components/textarea.md +495 -0
- package/guidelines/components/toast.md +784 -0
- package/guidelines/components/tooltip.md +912 -0
- package/guidelines/design-tokens/colors.md +309 -72
- package/guidelines/design-tokens/elevation.md +615 -45
- package/guidelines/design-tokens/spacing.md +654 -74
- package/guidelines/design-tokens/typography.md +432 -50
- package/guidelines/overview-components.md +60 -8
- package/guidelines/overview-imports.md +314 -0
- package/guidelines/overview-patterns.md +3852 -0
- package/package.json +4 -2
|
@@ -2,6 +2,69 @@
|
|
|
2
2
|
|
|
3
3
|
**Purpose:** Toggle control for binary on/off states following Material Design 3 patterns.
|
|
4
4
|
|
|
5
|
+
## When to Use This Component
|
|
6
|
+
|
|
7
|
+
Use Switch when you need to **toggle a setting or preference** that takes effect immediately (no submit button required).
|
|
8
|
+
|
|
9
|
+
**Decision Tree:**
|
|
10
|
+
|
|
11
|
+
| Scenario | Use This | Why |
|
|
12
|
+
| --------------------------------------------------------------- | ---------- | ----------------------------------------------------- |
|
|
13
|
+
| Toggle setting with immediate effect (dark mode, notifications) | Switch ✅ | Visual metaphor for on/off, instant feedback |
|
|
14
|
+
| Selection that requires form submission | Checkbox | Part of form data, submitted together |
|
|
15
|
+
| Mutually exclusive choices (select one from many) | RadioGroup | Only one option can be selected |
|
|
16
|
+
| Action that triggers behavior (save, delete) | Button | Actions need explicit confirmation |
|
|
17
|
+
| Binary choice in a list or group | Checkbox | Better for lists where multiple items can be selected |
|
|
18
|
+
|
|
19
|
+
**Component Comparison:**
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
// ✅ Use Switch for immediate toggle settings
|
|
23
|
+
<Switch.Root checked={isDarkMode} onCheckedChange={({ checked }) => setDarkMode(checked)}>
|
|
24
|
+
<Switch.Label>Dark mode</Switch.Label>
|
|
25
|
+
<Switch.Control>
|
|
26
|
+
<Switch.Thumb />
|
|
27
|
+
</Switch.Control>
|
|
28
|
+
</Switch.Root>
|
|
29
|
+
|
|
30
|
+
// ❌ Don't use Switch for form selections - use Checkbox
|
|
31
|
+
<form onSubmit={handleSubmit}>
|
|
32
|
+
<Switch.Root name="terms">
|
|
33
|
+
<Switch.Label>I accept the terms</Switch.Label>
|
|
34
|
+
<Switch.Control><Switch.Thumb /></Switch.Control>
|
|
35
|
+
</Switch.Root>
|
|
36
|
+
<Button type="submit">Sign Up</Button>
|
|
37
|
+
</form> // Wrong - use Checkbox for form consent
|
|
38
|
+
|
|
39
|
+
<form onSubmit={handleSubmit}>
|
|
40
|
+
<Checkbox.Root name="terms">
|
|
41
|
+
<Checkbox.Label>I accept the terms</Checkbox.Label>
|
|
42
|
+
<Checkbox.Control>
|
|
43
|
+
<Checkbox.Indicator />
|
|
44
|
+
</Checkbox.Control>
|
|
45
|
+
</Checkbox.Root>
|
|
46
|
+
<Button type="submit">Sign Up</Button>
|
|
47
|
+
</form> // Correct
|
|
48
|
+
|
|
49
|
+
// ❌ Don't use Switch for actions - use Button
|
|
50
|
+
<Switch.Root onCheckedChange={deleteAccount}>
|
|
51
|
+
<Switch.Label>Delete account</Switch.Label>
|
|
52
|
+
<Switch.Control><Switch.Thumb /></Switch.Control>
|
|
53
|
+
</Switch.Root> // Wrong - destructive action needs confirmation
|
|
54
|
+
|
|
55
|
+
<Button variant="filled" onClick={() => setShowDeleteDialog(true)}>
|
|
56
|
+
Delete Account
|
|
57
|
+
</Button> // Correct
|
|
58
|
+
|
|
59
|
+
// ✅ Use Switch for settings that apply immediately
|
|
60
|
+
<Switch.Root checked={notificationsEnabled} onCheckedChange={toggleNotifications}>
|
|
61
|
+
<Switch.Label>Enable push notifications</Switch.Label>
|
|
62
|
+
<Switch.Control>
|
|
63
|
+
<Switch.Thumb />
|
|
64
|
+
</Switch.Control>
|
|
65
|
+
</Switch.Root>
|
|
66
|
+
```
|
|
67
|
+
|
|
5
68
|
## Import
|
|
6
69
|
|
|
7
70
|
```typescript
|
|
@@ -11,6 +74,7 @@ import { Switch } from '@discourser/design-system';
|
|
|
11
74
|
## Overview
|
|
12
75
|
|
|
13
76
|
The Switch component provides:
|
|
77
|
+
|
|
14
78
|
- Binary on/off toggle functionality
|
|
15
79
|
- Visual feedback for state changes
|
|
16
80
|
- Smooth animation between states
|
|
@@ -21,25 +85,25 @@ The Switch component provides:
|
|
|
21
85
|
## Sizes
|
|
22
86
|
|
|
23
87
|
| Size | Track Width | Track Height | Thumb Size (off) | Thumb Size (on) | Label Size |
|
|
24
|
-
|
|
25
|
-
| `sm` | 44px
|
|
26
|
-
| `md` | 52px
|
|
88
|
+
| ---- | ----------- | ------------ | ---------------- | --------------- | ---------- |
|
|
89
|
+
| `sm` | 44px | 24px | 12×12px | 16×16px | bodySmall |
|
|
90
|
+
| `md` | 52px | 32px | 16×16px | 24×24px | bodyMedium |
|
|
27
91
|
|
|
28
92
|
**Note:** The thumb (circle) grows larger when the switch is in the "on" state, following M3 specifications.
|
|
29
93
|
|
|
30
94
|
## Props
|
|
31
95
|
|
|
32
|
-
| Prop
|
|
33
|
-
|
|
34
|
-
| `label`
|
|
35
|
-
| `checked`
|
|
36
|
-
| `defaultChecked`
|
|
37
|
-
| `onCheckedChange` | `(details: { checked: boolean }) => void` | -
|
|
38
|
-
| `disabled`
|
|
39
|
-
| `name`
|
|
40
|
-
| `value`
|
|
41
|
-
| `required`
|
|
42
|
-
| `size`
|
|
96
|
+
| Prop | Type | Default | Description |
|
|
97
|
+
| ----------------- | ----------------------------------------- | ------- | ----------------------------------- |
|
|
98
|
+
| `label` | `string` | - | Label text displayed next to switch |
|
|
99
|
+
| `checked` | `boolean` | - | Controlled checked state |
|
|
100
|
+
| `defaultChecked` | `boolean` | - | Uncontrolled default checked state |
|
|
101
|
+
| `onCheckedChange` | `(details: { checked: boolean }) => void` | - | Callback when checked state changes |
|
|
102
|
+
| `disabled` | `boolean` | `false` | Disable switch interaction |
|
|
103
|
+
| `name` | `string` | - | Name attribute for form submission |
|
|
104
|
+
| `value` | `string` | - | Value attribute for form submission |
|
|
105
|
+
| `required` | `boolean` | `false` | Whether switch is required in form |
|
|
106
|
+
| `size` | `'sm' \| 'md'` | `'md'` | Switch size |
|
|
43
107
|
|
|
44
108
|
## Examples
|
|
45
109
|
|
|
@@ -283,30 +347,33 @@ The Switch component follows WCAG 2.1 Level AA standards:
|
|
|
283
347
|
|
|
284
348
|
## State Behaviors
|
|
285
349
|
|
|
286
|
-
| State
|
|
287
|
-
|
|
288
|
-
| **Unchecked** | Track: `surfaceContainerHighest` with `outline` border<br />Thumb: Small, `outline` color, left position | Off state
|
|
289
|
-
| **Checked**
|
|
290
|
-
| **Hover**
|
|
291
|
-
| **Focus**
|
|
292
|
-
| **Disabled**
|
|
293
|
-
| **Animation** | Smooth thumb transition (fast easing)
|
|
350
|
+
| State | Visual Change | Behavior |
|
|
351
|
+
| ------------- | -------------------------------------------------------------------------------------------------------- | ----------------------------------- |
|
|
352
|
+
| **Unchecked** | Track: `surfaceContainerHighest` with `outline` border<br />Thumb: Small, `outline` color, left position | Off state |
|
|
353
|
+
| **Checked** | Track: `primary` color<br />Thumb: Larger, `onPrimary` color, right position | On state |
|
|
354
|
+
| **Hover** | Subtle visual feedback | Interactive feedback |
|
|
355
|
+
| **Focus** | Focus indicator (handled by Ark UI) | Keyboard accessibility |
|
|
356
|
+
| **Disabled** | 38% opacity, greyed out | Cannot be toggled |
|
|
357
|
+
| **Animation** | Smooth thumb transition (fast easing) | Visual confirmation of state change |
|
|
294
358
|
|
|
295
359
|
## Visual States
|
|
296
360
|
|
|
297
361
|
### Unchecked (Off)
|
|
362
|
+
|
|
298
363
|
- Track background: `surfaceContainerHighest`
|
|
299
364
|
- Track border: 2px `outline`
|
|
300
365
|
- Thumb: Small (16×16px for md), `outline` color
|
|
301
366
|
- Thumb position: Left
|
|
302
367
|
|
|
303
368
|
### Checked (On)
|
|
369
|
+
|
|
304
370
|
- Track background: `primary`
|
|
305
371
|
- Track border: 2px `primary`
|
|
306
372
|
- Thumb: Large (24×24px for md), `onPrimary` color
|
|
307
373
|
- Thumb position: Right
|
|
308
374
|
|
|
309
375
|
### Disabled
|
|
376
|
+
|
|
310
377
|
- Track background: `surfaceVariant`
|
|
311
378
|
- Track border: `onSurface` (12% opacity)
|
|
312
379
|
- Thumb: `onSurface` (38% opacity)
|
|
@@ -353,15 +420,15 @@ const formik = useFormik({
|
|
|
353
420
|
|
|
354
421
|
## Use Cases
|
|
355
422
|
|
|
356
|
-
| Use Case
|
|
357
|
-
|
|
358
|
-
| Enable/disable feature
|
|
359
|
-
| On/off settings
|
|
360
|
-
| Binary preferences
|
|
361
|
-
| Show/hide sections
|
|
423
|
+
| Use Case | Recommendation |
|
|
424
|
+
| -------------------------- | -------------------- |
|
|
425
|
+
| Enable/disable feature | ✅ Perfect use case |
|
|
426
|
+
| On/off settings | ✅ Perfect use case |
|
|
427
|
+
| Binary preferences | ✅ Perfect use case |
|
|
428
|
+
| Show/hide sections | ✅ Good use case |
|
|
362
429
|
| Mutually exclusive options | ❌ Use radio buttons |
|
|
363
|
-
| Multiple selections
|
|
364
|
-
| Trigger actions
|
|
430
|
+
| Multiple selections | ❌ Use checkboxes |
|
|
431
|
+
| Trigger actions | ❌ Use buttons |
|
|
365
432
|
|
|
366
433
|
## Responsive Considerations
|
|
367
434
|
|
|
@@ -445,13 +512,13 @@ test('switch works with keyboard', async () => {
|
|
|
445
512
|
|
|
446
513
|
## When to Use Switch vs Checkbox
|
|
447
514
|
|
|
448
|
-
| Feature
|
|
449
|
-
|
|
450
|
-
| **Purpose**
|
|
451
|
-
| **Effect**
|
|
452
|
-
| **State**
|
|
453
|
-
| **Typical Use** | Settings, preferences | Forms, multi-select
|
|
454
|
-
| **Example**
|
|
455
|
-
| **Visual**
|
|
515
|
+
| Feature | Switch | Checkbox |
|
|
516
|
+
| --------------- | --------------------- | ----------------------- |
|
|
517
|
+
| **Purpose** | Toggle state (on/off) | Select option(s) |
|
|
518
|
+
| **Effect** | Immediate | Usually requires submit |
|
|
519
|
+
| **State** | Active/inactive | Selected/unselected |
|
|
520
|
+
| **Typical Use** | Settings, preferences | Forms, multi-select |
|
|
521
|
+
| **Example** | "Enable dark mode" | "I agree to terms" |
|
|
522
|
+
| **Visual** | Track + thumb | Box + checkmark |
|
|
456
523
|
|
|
457
524
|
**Rule of thumb**: Use Switch when the change takes effect immediately. Use Checkbox when part of a form that needs submission.
|