snice 2.5.4 → 3.1.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 +501 -882
- package/bin/templates/base/src/components/counter-button.ts +13 -26
- package/bin/templates/base/src/controllers/counter-controller.ts +3 -3
- package/dist/components/accordion/snice-accordion-item.d.ts +4 -5
- package/dist/components/accordion/snice-accordion-item.js +37 -39
- package/dist/components/accordion/snice-accordion-item.js.map +1 -1
- package/dist/components/accordion/snice-accordion.d.ts +5 -11
- package/dist/components/accordion/snice-accordion.js +51 -52
- package/dist/components/accordion/snice-accordion.js.map +1 -1
- package/dist/components/alert/snice-alert.d.ts +2 -6
- package/dist/components/alert/snice-alert.js +41 -56
- package/dist/components/alert/snice-alert.js.map +1 -1
- package/dist/components/avatar/snice-avatar.d.ts +2 -6
- package/dist/components/avatar/snice-avatar.js +64 -71
- package/dist/components/avatar/snice-avatar.js.map +1 -1
- package/dist/components/badge/snice-badge.d.ts +2 -3
- package/dist/components/badge/snice-badge.js +22 -23
- package/dist/components/badge/snice-badge.js.map +1 -1
- package/dist/components/breadcrumbs/snice-breadcrumbs.d.ts +5 -12
- package/dist/components/breadcrumbs/snice-breadcrumbs.js +88 -89
- package/dist/components/breadcrumbs/snice-breadcrumbs.js.map +1 -1
- package/dist/components/button/snice-button.d.ts +3 -7
- package/dist/components/button/snice-button.js +37 -58
- package/dist/components/button/snice-button.js.map +1 -1
- package/dist/components/card/snice-card.d.ts +5 -8
- package/dist/components/card/snice-card.js +71 -56
- package/dist/components/card/snice-card.js.map +1 -1
- package/dist/components/checkbox/snice-checkbox.d.ts +4 -13
- package/dist/components/checkbox/snice-checkbox.js +66 -137
- package/dist/components/checkbox/snice-checkbox.js.map +1 -1
- package/dist/components/chip/snice-chip.d.ts +5 -11
- package/dist/components/chip/snice-chip.js +44 -47
- package/dist/components/chip/snice-chip.js.map +1 -1
- package/dist/components/date-picker/snice-date-picker.d.ts +11 -11
- package/dist/components/date-picker/snice-date-picker.js +134 -133
- package/dist/components/date-picker/snice-date-picker.js.map +1 -1
- package/dist/components/divider/snice-divider.d.ts +2 -4
- package/dist/components/divider/snice-divider.js +14 -22
- package/dist/components/divider/snice-divider.js.map +1 -1
- package/dist/components/drawer/snice-drawer.d.ts +4 -4
- package/dist/components/drawer/snice-drawer.js +25 -19
- package/dist/components/drawer/snice-drawer.js.map +1 -1
- package/dist/components/input/snice-input.d.ts +8 -6
- package/dist/components/input/snice-input.js +122 -105
- package/dist/components/input/snice-input.js.map +1 -1
- package/dist/components/layout/snice-layout-blog.d.ts +4 -4
- package/dist/components/layout/snice-layout-blog.js +21 -19
- package/dist/components/layout/snice-layout-blog.js.map +1 -1
- package/dist/components/layout/snice-layout-card.d.ts +2 -2
- package/dist/components/layout/snice-layout-card.js +16 -9
- package/dist/components/layout/snice-layout-card.js.map +1 -1
- package/dist/components/layout/snice-layout-centered.d.ts +2 -2
- package/dist/components/layout/snice-layout-centered.js +14 -7
- package/dist/components/layout/snice-layout-centered.js.map +1 -1
- package/dist/components/layout/snice-layout-dashboard.d.ts +5 -5
- package/dist/components/layout/snice-layout-dashboard.js +38 -30
- package/dist/components/layout/snice-layout-dashboard.js.map +1 -1
- package/dist/components/layout/snice-layout-fullscreen.d.ts +2 -2
- package/dist/components/layout/snice-layout-fullscreen.js +17 -10
- package/dist/components/layout/snice-layout-fullscreen.js.map +1 -1
- package/dist/components/layout/snice-layout-landing.d.ts +4 -4
- package/dist/components/layout/snice-layout-landing.js +21 -19
- package/dist/components/layout/snice-layout-landing.js.map +1 -1
- package/dist/components/layout/snice-layout-minimal.d.ts +2 -2
- package/dist/components/layout/snice-layout-minimal.js +17 -6
- package/dist/components/layout/snice-layout-minimal.js.map +1 -1
- package/dist/components/layout/snice-layout-sidebar.d.ts +5 -4
- package/dist/components/layout/snice-layout-sidebar.js +42 -20
- package/dist/components/layout/snice-layout-sidebar.js.map +1 -1
- package/dist/components/layout/snice-layout-split.d.ts +2 -2
- package/dist/components/layout/snice-layout-split.js +14 -7
- package/dist/components/layout/snice-layout-split.js.map +1 -1
- package/dist/components/layout/snice-layout.d.ts +4 -4
- package/dist/components/layout/snice-layout.js +16 -10
- package/dist/components/layout/snice-layout.js.map +1 -1
- package/dist/components/login/snice-login.d.ts +6 -11
- package/dist/components/login/snice-login.js +97 -71
- package/dist/components/login/snice-login.js.map +1 -1
- package/dist/components/modal/snice-modal.d.ts +5 -9
- package/dist/components/modal/snice-modal.js +47 -78
- package/dist/components/modal/snice-modal.js.map +1 -1
- package/dist/components/nav/snice-nav.d.ts +13 -7
- package/dist/components/nav/snice-nav.js +191 -100
- package/dist/components/nav/snice-nav.js.map +1 -1
- package/dist/components/nav/snice-nav.types.d.ts +3 -3
- package/dist/components/pagination/snice-pagination.d.ts +6 -7
- package/dist/components/pagination/snice-pagination.js +94 -81
- package/dist/components/pagination/snice-pagination.js.map +1 -1
- package/dist/components/progress/snice-progress.d.ts +2 -7
- package/dist/components/progress/snice-progress.js +41 -98
- package/dist/components/progress/snice-progress.js.map +1 -1
- package/dist/components/radio/snice-radio.d.ts +4 -4
- package/dist/components/radio/snice-radio.js +52 -44
- package/dist/components/radio/snice-radio.js.map +1 -1
- package/dist/components/select/snice-option.d.ts +2 -1
- package/dist/components/select/snice-option.js +12 -5
- package/dist/components/select/snice-option.js.map +1 -1
- package/dist/components/select/snice-select.d.ts +9 -21
- package/dist/components/select/snice-select.js +98 -170
- package/dist/components/select/snice-select.js.map +1 -1
- package/dist/components/skeleton/snice-skeleton.d.ts +2 -6
- package/dist/components/skeleton/snice-skeleton.js +18 -49
- package/dist/components/skeleton/snice-skeleton.js.map +1 -1
- package/dist/components/snice-cell-BLFVdxPp.js +4 -0
- package/dist/components/snice-cell-BLFVdxPp.js.map +1 -0
- package/dist/components/switch/snice-switch.d.ts +2 -2
- package/dist/components/switch/snice-switch.js +38 -26
- package/dist/components/switch/snice-switch.js.map +1 -1
- package/dist/components/table/snice-cell-actions.d.ts +24 -0
- package/dist/components/table/snice-cell-actions.js +149 -0
- package/dist/components/table/snice-cell-actions.js.map +1 -0
- package/dist/components/table/snice-cell-boolean.d.ts +2 -2
- package/dist/components/table/snice-cell-boolean.js +13 -7
- package/dist/components/table/snice-cell-boolean.js.map +1 -1
- package/dist/components/table/snice-cell-color.d.ts +18 -0
- package/dist/components/table/snice-cell-color.js +149 -0
- package/dist/components/table/snice-cell-color.js.map +1 -0
- package/dist/components/table/snice-cell-currency.d.ts +24 -0
- package/dist/components/table/snice-cell-currency.js +235 -0
- package/dist/components/table/snice-cell-currency.js.map +1 -0
- package/dist/components/table/snice-cell-date.d.ts +2 -2
- package/dist/components/table/snice-cell-date.js +14 -8
- package/dist/components/table/snice-cell-date.js.map +1 -1
- package/dist/components/table/snice-cell-duration.d.ts +2 -2
- package/dist/components/table/snice-cell-duration.js +12 -6
- package/dist/components/table/snice-cell-duration.js.map +1 -1
- package/dist/components/table/snice-cell-email.d.ts +15 -0
- package/dist/components/table/snice-cell-email.js +125 -0
- package/dist/components/table/snice-cell-email.js.map +1 -0
- package/dist/components/table/snice-cell-filesize.d.ts +2 -2
- package/dist/components/table/snice-cell-filesize.js +12 -6
- package/dist/components/table/snice-cell-filesize.js.map +1 -1
- package/dist/components/table/snice-cell-image.d.ts +20 -0
- package/dist/components/table/snice-cell-image.js +162 -0
- package/dist/components/table/snice-cell-image.js.map +1 -0
- package/dist/components/table/snice-cell-json.d.ts +20 -0
- package/dist/components/table/snice-cell-json.js +186 -0
- package/dist/components/table/snice-cell-json.js.map +1 -0
- package/dist/components/table/snice-cell-link.d.ts +17 -0
- package/dist/components/table/snice-cell-link.js +142 -0
- package/dist/components/table/snice-cell-link.js.map +1 -0
- package/dist/components/table/snice-cell-location.d.ts +19 -0
- package/dist/components/table/snice-cell-location.js +185 -0
- package/dist/components/table/snice-cell-location.js.map +1 -0
- package/dist/components/table/snice-cell-number.d.ts +2 -2
- package/dist/components/table/snice-cell-number.js +12 -6
- package/dist/components/table/snice-cell-number.js.map +1 -1
- package/dist/components/table/snice-cell-percentage.d.ts +22 -0
- package/dist/components/table/snice-cell-percentage.js +208 -0
- package/dist/components/table/snice-cell-percentage.js.map +1 -0
- package/dist/components/table/snice-cell-phone.d.ts +18 -0
- package/dist/components/table/snice-cell-phone.js +153 -0
- package/dist/components/table/snice-cell-phone.js.map +1 -0
- package/dist/components/table/snice-cell-progress.d.ts +2 -2
- package/dist/components/table/snice-cell-progress.js +12 -6
- package/dist/components/table/snice-cell-progress.js.map +1 -1
- package/dist/components/table/snice-cell-rating.d.ts +2 -2
- package/dist/components/table/snice-cell-rating.js +12 -6
- package/dist/components/table/snice-cell-rating.js.map +1 -1
- package/dist/components/table/snice-cell-sparkline.d.ts +2 -2
- package/dist/components/table/snice-cell-sparkline.js +13 -7
- package/dist/components/table/snice-cell-sparkline.js.map +1 -1
- package/dist/components/table/snice-cell-status.d.ts +17 -0
- package/dist/components/table/snice-cell-status.js +144 -0
- package/dist/components/table/snice-cell-status.js.map +1 -0
- package/dist/components/table/snice-cell-tag.d.ts +16 -0
- package/dist/components/table/snice-cell-tag.js +131 -0
- package/dist/components/table/snice-cell-tag.js.map +1 -0
- package/dist/components/table/snice-cell-text.d.ts +2 -2
- package/dist/components/table/snice-cell-text.js +14 -8
- package/dist/components/table/snice-cell-text.js.map +1 -1
- package/dist/components/table/snice-cell.d.ts +2 -2
- package/dist/components/table/snice-cell.js +12 -6
- package/dist/components/table/snice-cell.js.map +1 -1
- package/dist/components/table/snice-column.d.ts +1 -1
- package/dist/components/table/snice-column.js +6 -3
- package/dist/components/table/snice-column.js.map +1 -1
- package/dist/components/table/snice-header.d.ts +5 -5
- package/dist/components/table/snice-header.js +60 -50
- package/dist/components/table/snice-header.js.map +1 -1
- package/dist/components/table/snice-progress.d.ts +2 -2
- package/dist/components/table/snice-progress.js +18 -11
- package/dist/components/table/snice-progress.js.map +1 -1
- package/dist/components/table/snice-rating.d.ts +2 -2
- package/dist/components/table/snice-rating.js +15 -8
- package/dist/components/table/snice-rating.js.map +1 -1
- package/dist/components/table/snice-row.d.ts +17 -6
- package/dist/components/table/snice-row.js +95 -44
- package/dist/components/table/snice-row.js.map +1 -1
- package/dist/components/table/snice-table.d.ts +18 -10
- package/dist/components/table/snice-table.js +355 -173
- package/dist/components/table/snice-table.js.map +1 -1
- package/dist/components/table/snice-table.types.d.ts +101 -2
- package/dist/components/tabs/snice-tab-panel.d.ts +2 -2
- package/dist/components/tabs/snice-tab-panel.js +12 -6
- package/dist/components/tabs/snice-tab-panel.js.map +1 -1
- package/dist/components/tabs/snice-tab.d.ts +6 -5
- package/dist/components/tabs/snice-tab.js +36 -19
- package/dist/components/tabs/snice-tab.js.map +1 -1
- package/dist/components/tabs/snice-tabs.d.ts +5 -5
- package/dist/components/tabs/snice-tabs.js +38 -28
- package/dist/components/tabs/snice-tabs.js.map +1 -1
- package/dist/components/toast/snice-toast-container.d.ts +7 -7
- package/dist/components/toast/snice-toast-container.js +19 -12
- package/dist/components/toast/snice-toast-container.js.map +1 -1
- package/dist/components/toast/snice-toast.d.ts +3 -15
- package/dist/components/toast/snice-toast.js +49 -108
- package/dist/components/toast/snice-toast.js.map +1 -1
- package/dist/components/tooltip/snice-tooltip.d.ts +2 -2
- package/dist/components/tooltip/snice-tooltip.js +14 -7
- package/dist/components/tooltip/snice-tooltip.js.map +1 -1
- package/dist/context.d.ts +44 -0
- package/dist/element-ready.d.ts +40 -0
- package/dist/{types/element.d.ts → element.d.ts} +2 -8
- package/dist/{types/events.d.ts → events.d.ts} +0 -4
- package/dist/index.cjs +2589 -605
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +21 -0
- package/dist/index.esm.js +2568 -604
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +2589 -605
- package/dist/index.iife.js.map +1 -1
- package/dist/method-decorators.d.ts +121 -0
- package/dist/on.d.ts +59 -0
- package/dist/parts.d.ts +159 -0
- package/dist/render-debug.d.ts +27 -0
- package/dist/render-tracker.d.ts +14 -0
- package/dist/render.d.ts +96 -0
- package/dist/symbols.cjs +163 -0
- package/dist/symbols.cjs.map +1 -1
- package/dist/{types/symbols.d.ts → symbols.d.ts} +22 -0
- package/dist/symbols.esm.js +27 -3
- package/dist/symbols.esm.js.map +1 -1
- package/dist/template.d.ts +100 -0
- package/dist/transitions.cjs +219 -0
- package/dist/transitions.esm.js +2 -2
- package/dist/types/context.d.ts +48 -0
- package/dist/types/element-options.d.ts +26 -0
- package/dist/types/index.d.ts +25 -9
- package/dist/types/nav-context.d.ts +19 -0
- package/dist/types/{types/on-options.d.ts → on-options.d.ts} +2 -0
- package/dist/types/{types/placard.d.ts → placard.d.ts} +0 -1
- package/docs/ai/README.md +17 -0
- package/docs/ai/api.md +175 -0
- package/docs/ai/architecture.md +160 -0
- package/docs/ai/components/accordion.md +174 -0
- package/docs/ai/components/alert.md +77 -0
- package/docs/ai/components/avatar.md +61 -0
- package/docs/ai/components/badge.md +69 -0
- package/docs/ai/components/breadcrumbs.md +74 -0
- package/docs/ai/components/button.md +75 -0
- package/docs/ai/components/card.md +61 -0
- package/docs/ai/components/checkbox.md +74 -0
- package/docs/ai/components/chip.md +73 -0
- package/docs/ai/components/date-picker.md +75 -0
- package/docs/ai/components/divider.md +66 -0
- package/docs/ai/components/drawer.md +80 -0
- package/docs/ai/components/input.md +111 -0
- package/docs/ai/components/login.md +109 -0
- package/docs/ai/components/modal.md +67 -0
- package/docs/ai/components/nav.md +76 -0
- package/docs/ai/components/pagination.md +55 -0
- package/docs/ai/components/progress.md +72 -0
- package/docs/ai/components/radio.md +79 -0
- package/docs/ai/components/select.md +92 -0
- package/docs/ai/components/skeleton.md +57 -0
- package/docs/ai/components/switch.md +53 -0
- package/docs/ai/components/table.md +227 -0
- package/docs/ai/components/tabs.md +83 -0
- package/docs/ai/components/toast.md +140 -0
- package/docs/ai/components/tooltip.md +146 -0
- package/docs/ai/patterns.md +244 -0
- package/docs/components/accordion.md +558 -0
- package/docs/components/drawer.md +602 -0
- package/docs/components/modal.md +558 -0
- package/docs/components/nav.md +239 -0
- package/docs/components/pagination.md +289 -0
- package/docs/components/select.md +599 -0
- package/docs/components/switch.md +354 -0
- package/docs/components/tabs.md +546 -0
- package/docs/components/toast.md +506 -0
- package/docs/components/tooltip.md +523 -0
- package/docs/controllers.md +744 -0
- package/docs/elements.md +855 -0
- package/docs/events.md +807 -0
- package/docs/migration-v2-to-v3.md +569 -0
- package/docs/observe.md +588 -0
- package/docs/placards.md +401 -0
- package/docs/request-response.md +852 -0
- package/docs/routing.md +1186 -0
- package/package.json +10 -11
- package/dist/components/snice-cell-C9N6yGxQ.js +0 -4
- package/dist/components/snice-cell-C9N6yGxQ.js.map +0 -1
- package/dist/types/types/index.d.ts +0 -23
- /package/dist/{types/controller.d.ts → controller.d.ts} +0 -0
- /package/dist/{types/global.d.ts → global.d.ts} +0 -0
- /package/dist/{types/observe.d.ts → observe.d.ts} +0 -0
- /package/dist/{types/request-response.d.ts → request-response.d.ts} +0 -0
- /package/dist/{types/router.d.ts → router.d.ts} +0 -0
- /package/dist/{types/testing.d.ts → testing.d.ts} +0 -0
- /package/dist/{types/transitions.d.ts → transitions.d.ts} +0 -0
- /package/dist/types/{types/adopted-options.d.ts → adopted-options.d.ts} +0 -0
- /package/dist/types/{types/app-context.d.ts → app-context.d.ts} +0 -0
- /package/dist/types/{types/dispatch-options.d.ts → dispatch-options.d.ts} +0 -0
- /package/dist/types/{types/guard.d.ts → guard.d.ts} +0 -0
- /package/dist/types/{types/i-controller.d.ts → i-controller.d.ts} +0 -0
- /package/dist/types/{types/moved-options.d.ts → moved-options.d.ts} +0 -0
- /package/dist/types/{types/observe-options.d.ts → observe-options.d.ts} +0 -0
- /package/dist/types/{types/page-options.d.ts → page-options.d.ts} +0 -0
- /package/dist/types/{types/part-options.d.ts → part-options.d.ts} +0 -0
- /package/dist/types/{types/property-converter.d.ts → property-converter.d.ts} +0 -0
- /package/dist/types/{types/property-options.d.ts → property-options.d.ts} +0 -0
- /package/dist/types/{types/query-options.d.ts → query-options.d.ts} +0 -0
- /package/dist/types/{types/request-options.d.ts → request-options.d.ts} +0 -0
- /package/dist/types/{types/respond-options.d.ts → respond-options.d.ts} +0 -0
- /package/dist/types/{types/route-params.d.ts → route-params.d.ts} +0 -0
- /package/dist/types/{types/router-instance.d.ts → router-instance.d.ts} +0 -0
- /package/dist/types/{types/router-options.d.ts → router-options.d.ts} +0 -0
- /package/dist/types/{types/simple-array.d.ts → simple-array.d.ts} +0 -0
- /package/dist/types/{types/snice-element.d.ts → snice-element.d.ts} +0 -0
- /package/dist/types/{types/snice-global.d.ts → snice-global.d.ts} +0 -0
- /package/dist/types/{types/transition.d.ts → transition.d.ts} +0 -0
- /package/dist/{types/utils.d.ts → utils.d.ts} +0 -0
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
# Switch Component
|
|
2
|
+
|
|
3
|
+
The `<snice-switch>` component provides a toggle switch input for boolean selections, similar to iOS-style switches.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
- [Basic Usage](#basic-usage)
|
|
7
|
+
- [Properties](#properties)
|
|
8
|
+
- [Methods](#methods)
|
|
9
|
+
- [Events](#events)
|
|
10
|
+
- [Styling](#styling)
|
|
11
|
+
- [Examples](#examples)
|
|
12
|
+
|
|
13
|
+
## Basic Usage
|
|
14
|
+
|
|
15
|
+
```html
|
|
16
|
+
<snice-switch label="Enable notifications"></snice-switch>
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import 'snice/components/switch/snice-switch';
|
|
21
|
+
|
|
22
|
+
const switchEl = document.querySelector('snice-switch');
|
|
23
|
+
switchEl.addEventListener('@snice/switch-change', (e) => {
|
|
24
|
+
console.log('Switch is now:', e.detail.checked);
|
|
25
|
+
});
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Properties
|
|
29
|
+
|
|
30
|
+
| Property | Type | Default | Description |
|
|
31
|
+
|----------|------|---------|-------------|
|
|
32
|
+
| `checked` | `boolean` | `false` | Whether the switch is in the on position |
|
|
33
|
+
| `disabled` | `boolean` | `false` | Whether the switch is disabled |
|
|
34
|
+
| `required` | `boolean` | `false` | Whether the switch is required in a form |
|
|
35
|
+
| `invalid` | `boolean` | `false` | Whether to show invalid state styling |
|
|
36
|
+
| `size` | `'small' \| 'medium' \| 'large'` | `'medium'` | Size variant of the switch |
|
|
37
|
+
| `name` | `string` | `''` | Form field name |
|
|
38
|
+
| `value` | `string` | `'on'` | Form field value when checked |
|
|
39
|
+
| `label` | `string` | `''` | Label text displayed next to the switch |
|
|
40
|
+
| `labelOn` | `string` | `''` | Label shown on the switch when in on position |
|
|
41
|
+
| `labelOff` | `string` | `''` | Label shown on the switch when in off position |
|
|
42
|
+
|
|
43
|
+
## Methods
|
|
44
|
+
|
|
45
|
+
### `toggle(): void`
|
|
46
|
+
Toggle the switch state between on and off.
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
switchEl.toggle();
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### `focus(): void`
|
|
53
|
+
Give focus to the switch input.
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
switchEl.focus();
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### `blur(): void`
|
|
60
|
+
Remove focus from the switch input.
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
switchEl.blur();
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### `click(): void`
|
|
67
|
+
Programmatically click the switch.
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
switchEl.click();
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Events
|
|
74
|
+
|
|
75
|
+
### `@snice/switch-change`
|
|
76
|
+
Fired when the switch state changes.
|
|
77
|
+
|
|
78
|
+
**Event Detail:**
|
|
79
|
+
```typescript
|
|
80
|
+
{
|
|
81
|
+
checked: boolean; // New checked state
|
|
82
|
+
switch: SniceSwitchElement; // Reference to the switch element
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
**Usage:**
|
|
87
|
+
```typescript
|
|
88
|
+
switchEl.addEventListener('@snice/switch-change', (e) => {
|
|
89
|
+
const { checked } = e.detail;
|
|
90
|
+
console.log(`Switch is ${checked ? 'on' : 'off'}`);
|
|
91
|
+
});
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Styling
|
|
95
|
+
|
|
96
|
+
### Size Variants
|
|
97
|
+
|
|
98
|
+
```html
|
|
99
|
+
<!-- Small -->
|
|
100
|
+
<snice-switch size="small" label="Small switch"></snice-switch>
|
|
101
|
+
|
|
102
|
+
<!-- Medium (default) -->
|
|
103
|
+
<snice-switch size="medium" label="Medium switch"></snice-switch>
|
|
104
|
+
|
|
105
|
+
<!-- Large -->
|
|
106
|
+
<snice-switch size="large" label="Large switch"></snice-switch>
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### State Variants
|
|
110
|
+
|
|
111
|
+
```html
|
|
112
|
+
<!-- Checked -->
|
|
113
|
+
<snice-switch checked label="Enabled"></snice-switch>
|
|
114
|
+
|
|
115
|
+
<!-- Disabled -->
|
|
116
|
+
<snice-switch disabled label="Disabled"></snice-switch>
|
|
117
|
+
|
|
118
|
+
<!-- Invalid -->
|
|
119
|
+
<snice-switch invalid label="Invalid input"></snice-switch>
|
|
120
|
+
|
|
121
|
+
<!-- Required -->
|
|
122
|
+
<snice-switch required label="Required *"></snice-switch>
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Examples
|
|
126
|
+
|
|
127
|
+
### Basic Switch
|
|
128
|
+
|
|
129
|
+
```html
|
|
130
|
+
<snice-switch label="Enable feature"></snice-switch>
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### With On/Off Labels
|
|
134
|
+
|
|
135
|
+
```html
|
|
136
|
+
<snice-switch
|
|
137
|
+
label="Dark mode"
|
|
138
|
+
label-on="ON"
|
|
139
|
+
label-off="OFF">
|
|
140
|
+
</snice-switch>
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Form Integration
|
|
144
|
+
|
|
145
|
+
```html
|
|
146
|
+
<form id="settingsForm">
|
|
147
|
+
<snice-switch
|
|
148
|
+
name="notifications"
|
|
149
|
+
value="enabled"
|
|
150
|
+
label="Email notifications"
|
|
151
|
+
required>
|
|
152
|
+
</snice-switch>
|
|
153
|
+
|
|
154
|
+
<snice-switch
|
|
155
|
+
name="newsletter"
|
|
156
|
+
value="subscribed"
|
|
157
|
+
label="Subscribe to newsletter">
|
|
158
|
+
</snice-switch>
|
|
159
|
+
|
|
160
|
+
<button type="submit">Save Settings</button>
|
|
161
|
+
</form>
|
|
162
|
+
|
|
163
|
+
<script type="module">
|
|
164
|
+
import 'snice/components/switch/snice-switch';
|
|
165
|
+
|
|
166
|
+
const form = document.querySelector('#settingsForm');
|
|
167
|
+
|
|
168
|
+
form.addEventListener('submit', (e) => {
|
|
169
|
+
e.preventDefault();
|
|
170
|
+
|
|
171
|
+
const formData = new FormData(form);
|
|
172
|
+
const settings = Object.fromEntries(formData);
|
|
173
|
+
|
|
174
|
+
console.log('Settings:', settings);
|
|
175
|
+
// { notifications: 'enabled' } if checked
|
|
176
|
+
});
|
|
177
|
+
</script>
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### Programmatic Control
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
import type { SniceSwitchElement } from 'snice/components/switch/snice-switch.types';
|
|
184
|
+
|
|
185
|
+
const switchEl = document.querySelector<SniceSwitchElement>('snice-switch');
|
|
186
|
+
|
|
187
|
+
// Toggle programmatically
|
|
188
|
+
switchEl.toggle();
|
|
189
|
+
|
|
190
|
+
// Set specific state
|
|
191
|
+
switchEl.checked = true;
|
|
192
|
+
|
|
193
|
+
// Enable/disable
|
|
194
|
+
switchEl.disabled = true;
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### With Event Handling
|
|
198
|
+
|
|
199
|
+
```typescript
|
|
200
|
+
const switchEl = document.querySelector('snice-switch');
|
|
201
|
+
|
|
202
|
+
switchEl.addEventListener('@snice/switch-change', (e) => {
|
|
203
|
+
const { checked, switch: sw } = e.detail;
|
|
204
|
+
|
|
205
|
+
if (checked) {
|
|
206
|
+
console.log('Feature enabled');
|
|
207
|
+
enableFeature();
|
|
208
|
+
} else {
|
|
209
|
+
console.log('Feature disabled');
|
|
210
|
+
disableFeature();
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
function enableFeature() {
|
|
215
|
+
// Enable feature logic
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function disableFeature() {
|
|
219
|
+
// Disable feature logic
|
|
220
|
+
}
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### Validation Example
|
|
224
|
+
|
|
225
|
+
```html
|
|
226
|
+
<form id="termsForm">
|
|
227
|
+
<snice-switch
|
|
228
|
+
id="termsSwitch"
|
|
229
|
+
name="terms"
|
|
230
|
+
label="I agree to the terms and conditions"
|
|
231
|
+
required>
|
|
232
|
+
</snice-switch>
|
|
233
|
+
|
|
234
|
+
<button type="submit">Continue</button>
|
|
235
|
+
</form>
|
|
236
|
+
|
|
237
|
+
<script type="module">
|
|
238
|
+
import 'snice/components/switch/snice-switch';
|
|
239
|
+
|
|
240
|
+
const form = document.querySelector('#termsForm');
|
|
241
|
+
const termsSwitch = document.querySelector('#termsSwitch');
|
|
242
|
+
|
|
243
|
+
form.addEventListener('submit', (e) => {
|
|
244
|
+
e.preventDefault();
|
|
245
|
+
|
|
246
|
+
if (!termsSwitch.checked) {
|
|
247
|
+
termsSwitch.invalid = true;
|
|
248
|
+
alert('You must agree to the terms');
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
termsSwitch.invalid = false;
|
|
253
|
+
// Continue with form submission
|
|
254
|
+
});
|
|
255
|
+
</script>
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
### Multiple Switches
|
|
259
|
+
|
|
260
|
+
```html
|
|
261
|
+
<div class="settings-group">
|
|
262
|
+
<h3>Privacy Settings</h3>
|
|
263
|
+
|
|
264
|
+
<snice-switch
|
|
265
|
+
label="Public profile"
|
|
266
|
+
name="public_profile"
|
|
267
|
+
checked>
|
|
268
|
+
</snice-switch>
|
|
269
|
+
|
|
270
|
+
<snice-switch
|
|
271
|
+
label="Show email"
|
|
272
|
+
name="show_email">
|
|
273
|
+
</snice-switch>
|
|
274
|
+
|
|
275
|
+
<snice-switch
|
|
276
|
+
label="Show phone number"
|
|
277
|
+
name="show_phone">
|
|
278
|
+
</snice-switch>
|
|
279
|
+
|
|
280
|
+
<snice-switch
|
|
281
|
+
label="Allow messages from anyone"
|
|
282
|
+
name="allow_messages">
|
|
283
|
+
</snice-switch>
|
|
284
|
+
</div>
|
|
285
|
+
|
|
286
|
+
<style>
|
|
287
|
+
.settings-group {
|
|
288
|
+
display: flex;
|
|
289
|
+
flex-direction: column;
|
|
290
|
+
gap: 16px;
|
|
291
|
+
max-width: 400px;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
.settings-group snice-switch {
|
|
295
|
+
padding: 8px 0;
|
|
296
|
+
border-bottom: 1px solid #e5e7eb;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
.settings-group snice-switch:last-child {
|
|
300
|
+
border-bottom: none;
|
|
301
|
+
}
|
|
302
|
+
</style>
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
### Custom Styling with CSS Parts
|
|
306
|
+
|
|
307
|
+
```html
|
|
308
|
+
<style>
|
|
309
|
+
snice-switch::part(track) {
|
|
310
|
+
background: linear-gradient(to right, #667eea, #764ba2);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
snice-switch[checked]::part(track) {
|
|
314
|
+
background: linear-gradient(to right, #f093fb, #f5576c);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
snice-switch::part(thumb) {
|
|
318
|
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
snice-switch::part(label) {
|
|
322
|
+
font-weight: 600;
|
|
323
|
+
color: #1f2937;
|
|
324
|
+
}
|
|
325
|
+
</style>
|
|
326
|
+
|
|
327
|
+
<snice-switch label="Custom styled switch" checked></snice-switch>
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
## Accessibility
|
|
331
|
+
|
|
332
|
+
The switch component includes proper ARIA attributes:
|
|
333
|
+
|
|
334
|
+
- `role="switch"` on the input element
|
|
335
|
+
- `aria-checked` reflects the current state
|
|
336
|
+
- `aria-invalid` when invalid state is set
|
|
337
|
+
- Native `<input type="checkbox">` for form compatibility
|
|
338
|
+
- Keyboard accessible (Space/Enter to toggle)
|
|
339
|
+
- Focus visible state
|
|
340
|
+
|
|
341
|
+
## Form Behavior
|
|
342
|
+
|
|
343
|
+
The switch component works seamlessly with HTML forms:
|
|
344
|
+
|
|
345
|
+
- Acts like a checkbox input
|
|
346
|
+
- Only included in form data when checked
|
|
347
|
+
- Supports `name` and `value` attributes
|
|
348
|
+
- Supports `required` attribute for validation
|
|
349
|
+
- Compatible with FormData API
|
|
350
|
+
|
|
351
|
+
## Browser Support
|
|
352
|
+
|
|
353
|
+
- Modern browsers (Chrome, Firefox, Safari, Edge)
|
|
354
|
+
- Requires Custom Elements v1 and Shadow DOM support
|