@pushwoosh/dumb-components 1.1.147 → 1.1.149
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/AccessForbidden/AccessForbidden.d.ts +3 -0
- package/AccessForbidden/AccessForbidden.js +3 -0
- package/Alert/Alert.d.ts +7 -0
- package/Alert/Alert.js +7 -0
- package/Alert/types.d.ts +6 -0
- package/ApplicationPreloader/ApplicationPreloader.d.ts +8 -0
- package/ApplicationPreloader/ApplicationPreloader.js +6 -0
- package/Badge/Badge.d.ts +6 -0
- package/Badge/Badge.js +6 -0
- package/Badge/types.d.ts +6 -0
- package/Banner/Banner.d.ts +7 -0
- package/Banner/Banner.js +7 -0
- package/Banner/types.d.ts +16 -0
- package/Button/Button.d.ts +19 -0
- package/Button/GhostButton.d.ts +1 -0
- package/Button/GhostButton.js +1 -0
- package/Button/RemoveButton.d.ts +6 -0
- package/Button/RemoveButton.js +6 -0
- package/Button/types.d.ts +21 -0
- package/Calendar/CalendarDropdown/CalendarDropdown.d.ts +12 -0
- package/Calendar/CalendarDropdown/CalendarDropdown.js +12 -0
- package/Calendar/CalendarDropdown/helpers.d.ts +4 -0
- package/Calendar/CalendarDropdown/helpers.js +4 -0
- package/Calendar/CalendarDropdown/types.d.ts +33 -0
- package/Calendar/CalendarSuperForm/CalendarSuperForm.d.ts +7 -0
- package/Calendar/CalendarSuperForm/CalendarSuperForm.js +10 -1
- package/Calendar/CalendarSuperForm/components/CalendarRangePicker/CalendarRangePicker.d.ts +1 -0
- package/Calendar/CalendarSuperForm/components/CalendarRangePicker/CalendarRangePicker.js +3 -2
- package/Calendar/CalendarSuperForm/types.d.ts +37 -9
- package/Calendar/helpers.d.ts +10 -0
- package/Calendar/helpers.js +10 -0
- package/Calendar/types.d.ts +16 -1
- package/CardMetric/CardMetric.d.ts +7 -0
- package/CardMetric/CardMetric.js +7 -0
- package/CardMetric/types.d.ts +13 -0
- package/Checkbox/Checkbox.d.ts +6 -0
- package/Checkbox/Checkbox.js +6 -0
- package/Checkbox/types.d.ts +13 -0
- package/Chip/Chip.d.ts +7 -0
- package/Chip/Chip.js +7 -0
- package/Chip/Chip.types.d.ts +9 -0
- package/CodeEditor/CodeEditor.d.ts +7 -0
- package/CodeEditor/CodeEditor.js +7 -0
- package/CodeEditor/languages/html.d.ts +1 -0
- package/CodeEditor/languages/html.js +1 -0
- package/CodeEditor/languages/json.d.ts +1 -0
- package/CodeEditor/languages/json.js +1 -0
- package/CodeEditor/languages/liquid.d.ts +1 -0
- package/CodeEditor/languages/liquid.js +1 -0
- package/CodeEditor/types.d.ts +11 -0
- package/CrashScreen/CrashScreen.d.ts +4 -0
- package/CrashScreen/CrashScreen.js +4 -0
- package/DateTimePicker/components/DatePicker/DatePicker.d.ts +5 -0
- package/DateTimePicker/components/DatePicker/DatePicker.js +5 -0
- package/DateTimePicker/components/DatePicker/types.d.ts +9 -0
- package/DateTimePicker/components/DatePickerField/DatePickerField.d.ts +5 -0
- package/DateTimePicker/components/DatePickerField/DatePickerField.js +5 -0
- package/DateTimePicker/components/DatePickerField/types.d.ts +9 -0
- package/DateTimePicker/components/DateTimePicker/DateTimePicker.d.ts +5 -0
- package/DateTimePicker/components/DateTimePicker/DateTimePicker.js +5 -0
- package/DateTimePicker/components/DateTimePicker/types.d.ts +6 -0
- package/DateTimePicker/components/DateTimePickerField/DateTimePickerField.d.ts +5 -0
- package/DateTimePicker/components/DateTimePickerField/DateTimePickerField.js +5 -0
- package/DateTimePicker/components/DateTimePickerField/types.d.ts +9 -0
- package/DateTimePicker/types.d.ts +5 -0
- package/Drawer/components/Drawer/Drawer.d.ts +11 -0
- package/Drawer/components/Drawer/Drawer.js +11 -0
- package/Drawer/components/Drawer/types.d.ts +9 -0
- package/Drawer/components/DrawerContent/styles.d.ts +3 -0
- package/Drawer/components/DrawerContent/styles.js +3 -0
- package/Drawer/components/DrawerDocs/DrawerDocs.d.ts +7 -0
- package/Drawer/components/DrawerDocs/DrawerDocs.js +7 -0
- package/Drawer/components/DrawerDocs/hooks.d.ts +4 -0
- package/Drawer/components/DrawerDocs/hooks.js +4 -0
- package/Drawer/components/DrawerDocs/types.d.ts +4 -0
- package/DropdownMenu/components/DropdownMenu/DropdownMenu.d.ts +12 -0
- package/DropdownMenu/components/DropdownMenu/DropdownMenu.js +12 -0
- package/DropdownMenu/components/DropdownMenu/types.d.ts +15 -0
- package/DropdownMenu/components/DropdownMenuButton/DropdownMenuButton.d.ts +8 -0
- package/DropdownMenu/components/DropdownMenuButton/DropdownMenuButton.js +8 -0
- package/DropdownMenu/components/DropdownMenuButton/types.d.ts +16 -0
- package/DropdownMenu/components/DropdownMenuItem/DropdownMenuItem.d.ts +7 -0
- package/DropdownMenu/components/DropdownMenuItem/DropdownMenuItem.js +7 -0
- package/DropdownMenu/components/DropdownMenuItem/types.d.ts +6 -0
- package/DropdownMenu/components/DropdownMenuSection/DropdownMenuSection.d.ts +8 -0
- package/DropdownMenu/components/DropdownMenuSection/DropdownMenuSection.js +8 -0
- package/DropdownMenu/components/DropdownMenuSection/types.d.ts +3 -0
- package/DropdownMenu/components/DropdownMenuSubmenu/DropdownMenuSubmenu.d.ts +9 -0
- package/DropdownMenu/components/DropdownMenuSubmenu/DropdownMenuSubmenu.js +9 -0
- package/DropdownMenu/components/DropdownMenuSubmenu/types.d.ts +5 -0
- package/EditableField/EditableField.d.ts +9 -0
- package/EditableField/EditableField.js +9 -0
- package/EditableField/types.d.ts +12 -0
- package/EmailTemplatePreview/EmailTemplatePreview.d.ts +7 -0
- package/EmailTemplatePreview/EmailTemplatePreview.js +7 -0
- package/EmailTemplatePreview/components/NoEmailTemplatePreview/NoEmailTemplatePreview.d.ts +4 -0
- package/EmailTemplatePreview/components/NoEmailTemplatePreview/NoEmailTemplatePreview.js +4 -0
- package/EmailTemplatePreview/helpers.d.ts +8 -0
- package/EmailTemplatePreview/helpers.js +8 -0
- package/EmailTemplatePreview/types.d.ts +7 -0
- package/EnhancedInput/EnhancedInput.d.ts +7 -0
- package/EnhancedInput/EnhancedInput.js +7 -0
- package/EnhancedInput/SearchInput.d.ts +6 -0
- package/EnhancedInput/SearchInput.js +6 -0
- package/EnhancedInput/types.d.ts +5 -0
- package/ExportResult/ExportResult.d.ts +7 -0
- package/ExportResult/ExportResult.js +7 -0
- package/ExportResult/types.d.ts +7 -0
- package/ExternalImagePreview/ExternalImagePreview.d.ts +7 -0
- package/ExternalImagePreview/ExternalImagePreview.js +7 -0
- package/ExternalImagePreview/types.d.ts +7 -0
- package/FieldBox/FieldBox.d.ts +9 -0
- package/FieldBox/FieldBox.js +9 -0
- package/FieldBox/types.d.ts +10 -0
- package/FrequencyCapping/FrequencyCappingEdit.d.ts +7 -0
- package/FrequencyCapping/FrequencyCappingEdit.js +7 -0
- package/FrequencyCapping/FrequencyCappingInApps.d.ts +7 -0
- package/FrequencyCapping/FrequencyCappingInApps.js +7 -0
- package/FrequencyCapping/FrequencyCappingReadonly.d.ts +3 -0
- package/FrequencyCapping/FrequencyCappingReadonly.js +3 -0
- package/FrequencyCapping/types.d.ts +37 -0
- package/FrequencyCapping/types.js +1 -0
- package/GetStartedPage/GetStartedPage.d.ts +7 -0
- package/GetStartedPage/GetStartedPage.js +7 -0
- package/GetStartedPage/types.d.ts +7 -0
- package/InputFile/InputFile.d.ts +7 -0
- package/InputFile/InputFile.js +7 -0
- package/InputFile/types.d.ts +18 -0
- package/Link/Link.d.ts +18 -0
- package/Link/types.d.ts +17 -0
- package/Modal/components/Modal/Modal.d.ts +11 -0
- package/Modal/components/Modal/Modal.js +11 -0
- package/Modal/components/Modal/types.d.ts +6 -0
- package/Modal/components/ModalConfirm/ModalConfirm.d.ts +8 -0
- package/Modal/components/ModalConfirm/ModalConfirm.js +8 -0
- package/Modal/components/ModalConfirm/ModalConfirmProvider.d.ts +7 -0
- package/Modal/components/ModalConfirm/ModalConfirmProvider.js +7 -0
- package/Modal/components/ModalConfirm/hooks.d.ts +8 -0
- package/Modal/components/ModalConfirm/hooks.js +8 -0
- package/Modal/components/ModalConfirm/types.d.ts +16 -0
- package/Modal/components/ModalContent/styles.d.ts +5 -0
- package/Modal/components/ModalContent/styles.js +5 -0
- package/Modal/components/ModalTitle/ModalTitle.d.ts +6 -0
- package/Modal/components/ModalTitle/ModalTitle.js +6 -0
- package/Modal/components/ModalTitle/types.d.ts +3 -0
- package/NotificationInbox/NotificationBar.d.ts +7 -0
- package/NotificationInbox/NotificationBar.js +7 -0
- package/NotificationInbox/NotificationBell.d.ts +7 -0
- package/NotificationInbox/NotificationBell.js +7 -0
- package/NotificationInbox/NotificationInbox.d.ts +7 -0
- package/NotificationInbox/NotificationInbox.js +7 -0
- package/NotificationInbox/types.d.ts +31 -0
- package/NumberPicker/NumberPicker.d.ts +7 -0
- package/NumberPicker/NumberPicker.js +7 -0
- package/NumberPicker/types.d.ts +12 -0
- package/PageHeader/components/AutosizeInput/AutosizeInput.d.ts +7 -0
- package/PageHeader/components/AutosizeInput/AutosizeInput.js +7 -0
- package/PageHeader/components/AutosizeInput/types.d.ts +7 -0
- package/PageHeader/components/PageHeader/PageHeader.d.ts +7 -0
- package/PageHeader/components/PageHeader/PageHeader.js +7 -0
- package/PageHeader/components/PageHeader/types.d.ts +13 -0
- package/PageHeader/components/PageHeaderEditable/PageHeaderEditable.d.ts +7 -0
- package/PageHeader/components/PageHeaderEditable/PageHeaderEditable.js +7 -0
- package/PageHeader/components/PageHeaderEditable/types.d.ts +19 -0
- package/Pagination/Pagination.d.ts +7 -0
- package/Pagination/Pagination.js +7 -0
- package/Pagination/types.d.ts +7 -0
- package/Popover/Popover.d.ts +10 -0
- package/Popover/Popover.js +10 -0
- package/Popover/styles.d.ts +1 -0
- package/Popover/styles.js +1 -0
- package/Popover/types.d.ts +9 -0
- package/ProgressBar/ProgressBar.d.ts +6 -0
- package/ProgressBar/ProgressBar.js +6 -0
- package/ProgressBar/types.d.ts +7 -0
- package/PushPreview/PushPreview.d.ts +7 -0
- package/PushPreview/PushPreview.js +7 -0
- package/PushPreview/types.d.ts +17 -0
- package/Radio/Radio.d.ts +7 -0
- package/Radio/Radio.js +7 -0
- package/Radio/types.d.ts +14 -0
- package/RadioCard/RadioCard.d.ts +7 -0
- package/RadioCard/RadioCard.js +7 -0
- package/RadioCard/types.d.ts +7 -0
- package/ReCaptcha/ReCaptcha.d.ts +8 -0
- package/ReCaptcha/ReCaptcha.js +8 -0
- package/ReCaptcha/helpers.d.ts +4 -0
- package/ReCaptcha/helpers.js +4 -0
- package/ReCaptcha/hooks.d.ts +4 -0
- package/ReCaptcha/hooks.js +4 -0
- package/ReCaptcha/types.d.ts +5 -0
- package/RichMessageEditor/RichMessageEditor.d.ts +8 -0
- package/RichMessageEditor/RichMessageEditor.js +8 -0
- package/RichMessageEditor/RichMessageEditor.types.d.ts +10 -0
- package/RichMessageEditor/RichMessageViewer.d.ts +10 -0
- package/RichMessageEditor/RichMessageViewer.js +7 -0
- package/RichMessageEditor/slate/types.d.ts +5 -0
- package/RichMessageEditor/types.d.ts +1 -0
- package/RichmediaPreview/RichmediaPreview.d.ts +7 -0
- package/RichmediaPreview/RichmediaPreview.js +7 -0
- package/RichmediaPreview/hooks.d.ts +4 -0
- package/RichmediaPreview/hooks.js +4 -0
- package/RichmediaPreview/types.d.ts +13 -0
- package/Select/Select.d.ts +22 -0
- package/Select/Select.js +22 -0
- package/Select/constants.d.ts +1 -0
- package/Select/constants.js +1 -0
- package/Select/types.d.ts +19 -0
- package/SendRate/SendRateEdit.d.ts +7 -0
- package/SendRate/SendRateEdit.js +7 -0
- package/SendRate/SendRateReadonly.d.ts +3 -0
- package/SendRate/SendRateReadonly.js +3 -0
- package/SendRate/types.d.ts +20 -0
- package/Skeleton/TextSkeleton.d.ts +6 -0
- package/Skeleton/TextSkeleton.js +6 -0
- package/Skeleton/styles.d.ts +2 -0
- package/Skeleton/styles.js +2 -0
- package/Skeleton/types.d.ts +11 -0
- package/SortButton/SortButton.d.ts +6 -0
- package/SortButton/SortButton.js +6 -0
- package/SortButton/types.d.ts +11 -0
- package/Spinner/Spinner.d.ts +6 -0
- package/Spinner/Spinner.js +6 -0
- package/Spinner/types.d.ts +4 -0
- package/StatisticCard/StatisticCard.d.ts +7 -0
- package/StatisticCard/StatisticCard.js +7 -0
- package/StatisticCard/types.d.ts +21 -0
- package/Switch/Switch.d.ts +6 -0
- package/Switch/Switch.js +6 -0
- package/Switch/types.d.ts +8 -0
- package/Tabs/components/Tab/Tab.d.ts +4 -0
- package/Tabs/components/Tab/Tab.js +4 -0
- package/Tabs/components/Tab/types.d.ts +6 -0
- package/Tabs/components/TabBar/TabBar.d.ts +3 -0
- package/Tabs/components/TabBar/TabBar.js +3 -0
- package/Tabs/components/TabBar/types.d.ts +2 -0
- package/Tabs/components/TabPanel/TabPanel.d.ts +4 -0
- package/Tabs/components/TabPanel/TabPanel.js +4 -0
- package/Tabs/components/TabPanel/types.d.ts +3 -0
- package/Tabs/components/Tabs/Tabs.d.ts +11 -0
- package/Tabs/components/Tabs/Tabs.js +11 -0
- package/Tabs/components/Tabs/types.d.ts +4 -0
- package/Tabs/types.d.ts +4 -0
- package/Toast/Toast.d.ts +5 -0
- package/Toast/Toast.js +5 -0
- package/Toast/ToastProvider.d.ts +7 -0
- package/Toast/ToastProvider.js +7 -0
- package/Toast/hooks.d.ts +8 -0
- package/Toast/hooks.js +8 -0
- package/Toast/types.d.ts +24 -0
- package/Tooltip/Tooltip.d.ts +7 -0
- package/Tooltip/Tooltip.js +7 -0
- package/Tooltip/TooltipTrigger.d.ts +13 -0
- package/Tooltip/TooltipTrigger.js +7 -0
- package/Tooltip/types.d.ts +12 -0
- package/hooks/useElementWidth.d.ts +4 -3
- package/hooks/useElementWidth.js +4 -3
- package/hooks/useLayer.d.ts +7 -0
- package/hooks/useLayer.js +7 -0
- package/hooks/useOnClickOutside.d.ts +7 -0
- package/hooks/useOnClickOutside.js +7 -0
- package/native/Input.d.ts +3 -0
- package/native/Input.js +1 -0
- package/native/NativeTimeInput.d.ts +1 -0
- package/native/NativeTimeInput.js +1 -0
- package/native/Select.d.ts +1 -0
- package/native/Select.js +1 -0
- package/native/Textarea.d.ts +1 -0
- package/native/Textarea.js +1 -0
- package/package.json +2 -3
- package/polyglot/react.d.ts +19 -0
- package/polyglot/react.js +19 -0
- package/polyglot/types.d.ts +4 -0
- package/shared/dropdownField/FieldInput.d.ts +1 -0
- package/shared/dropdownField/FieldInput.js +1 -0
- package/shared/dropdownField/FieldShell.d.ts +4 -0
- package/shared/dropdownField/FieldShell.js +4 -0
- package/shared/dropdownField/SuggestionsDropdown.d.ts +4 -0
- package/shared/dropdownField/SuggestionsDropdown.js +4 -0
- package/shared/dropdownField/constants.d.ts +1 -0
- package/shared/dropdownField/constants.js +1 -0
- package/shared/dropdownField/shared.d.ts +7 -0
- package/shared/dropdownField/shared.js +7 -0
- package/shared/dropdownField/types.d.ts +7 -0
- package/shared/dropdownField/useActiveIndex.d.ts +4 -0
- package/shared/dropdownField/useActiveIndex.js +4 -0
- package/shared/dropdownField/useAsyncItems.d.ts +4 -0
- package/shared/dropdownField/useAsyncItems.js +4 -0
- package/shared/dropdownField/useDebouncedValue.d.ts +1 -0
- package/shared/dropdownField/useDebouncedValue.js +1 -0
- package/shared/dropdownField/useDropdownItems.d.ts +4 -0
- package/shared/dropdownField/useDropdownItems.js +4 -0
- package/shared/dropdownField/useDropdownPosition.d.ts +4 -0
- package/shared/dropdownField/useDropdownPosition.js +4 -0
- package/shared/dropdownField/useFieldOpenEffects.d.ts +4 -0
- package/shared/dropdownField/useFieldOpenEffects.js +4 -0
- package/shared/dropdownField/useListNavigation.d.ts +5 -0
- package/shared/dropdownField/useListNavigation.js +5 -0
- package/Alert/ai-documentation.md +0 -132
- package/Badge/ai-documentation.md +0 -155
- package/Banner/ai-documentation.md +0 -285
- package/Button/ai-documentation.md +0 -247
- package/CardMetric/ai-documentation.md +0 -277
- package/Checkbox/ai-documentation.md +0 -231
- package/Chip/ai-documentation.md +0 -281
- package/CodeEditor/ai-documentation.md +0 -350
- package/DateTimePicker/ai-documentation.md +0 -400
- package/Drawer/ai-documentation.md +0 -417
- package/EnhancedInput/ai-documentation.md +0 -352
- package/InputFile/ai-documentation.md +0 -420
- package/Modal/ai-documentation.md +0 -285
- package/PageHeader/ai-documentation.md +0 -511
- package/Pagination/ai-documentation.md +0 -509
- package/Popover/ai-documentation.md +0 -625
- package/ProgressBar/ai-documentation.md +0 -533
- package/Radio/ai-documentation.md +0 -243
- package/Select/ai-documentation.md +0 -374
- package/Skeleton/ai-documentation.md +0 -574
- package/Spinner/ai-documentation.md +0 -607
- package/Switch/ai-documentation.md +0 -312
- package/Tabs/ai-documentation.md +0 -475
- package/Toast/ai-documentation.md +0 -220
- package/Tooltip/ai-documentation.md +0 -340
- package/ai-documentation.md +0 -124
- package/native/ai-documentation.md +0 -485
|
@@ -1,312 +0,0 @@
|
|
|
1
|
-
# Switch Component - @pushwoosh/dumb-components
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
|
|
5
|
-
- **Component Name**: Switch
|
|
6
|
-
- **Import Path**: `@pushwoosh/dumb-components`
|
|
7
|
-
- **Files**:
|
|
8
|
-
- `/src/Switch/Switch.tsx` - Main component implementation
|
|
9
|
-
- `/src/Switch/types.ts` - TypeScript type definitions
|
|
10
|
-
- `/src/Switch/styles.ts` - Styled components
|
|
11
|
-
- `/src/Switch/index.ts` - Component exports
|
|
12
|
-
- **Type**: Form Control
|
|
13
|
-
- **Description**: A toggle switch component that represents a boolean state. Features customizable label positioning, disabled state, and smooth visual transitions.
|
|
14
|
-
|
|
15
|
-
## TypeScript Interfaces
|
|
16
|
-
|
|
17
|
-
```typescript
|
|
18
|
-
export interface SwitchProps {
|
|
19
|
-
labelPosition?: 'left' | 'right';
|
|
20
|
-
enabled?: boolean;
|
|
21
|
-
isDisabled?: boolean;
|
|
22
|
-
children?: ReactNode;
|
|
23
|
-
onChange: () => void;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface AlignProps {
|
|
27
|
-
labelPosition?: string;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface ComponentProps {
|
|
31
|
-
enabled: boolean;
|
|
32
|
-
isDisabled?: boolean;
|
|
33
|
-
}
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
## Import & Usage
|
|
37
|
-
|
|
38
|
-
```typescript
|
|
39
|
-
import { Switch } from '@pushwoosh/dumb-components';
|
|
40
|
-
|
|
41
|
-
// Basic usage
|
|
42
|
-
function MyComponent() {
|
|
43
|
-
const [isEnabled, setIsEnabled] = useState(false);
|
|
44
|
-
|
|
45
|
-
return (
|
|
46
|
-
<Switch
|
|
47
|
-
enabled={isEnabled}
|
|
48
|
-
onChange={() => setIsEnabled(!isEnabled)}
|
|
49
|
-
>
|
|
50
|
-
Enable notifications
|
|
51
|
-
</Switch>
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// Left-aligned label
|
|
56
|
-
function LeftLabelSwitch() {
|
|
57
|
-
const [darkMode, setDarkMode] = useState(false);
|
|
58
|
-
|
|
59
|
-
return (
|
|
60
|
-
<Switch
|
|
61
|
-
enabled={darkMode}
|
|
62
|
-
labelPosition="left"
|
|
63
|
-
onChange={() => setDarkMode(!darkMode)}
|
|
64
|
-
>
|
|
65
|
-
Dark Mode
|
|
66
|
-
</Switch>
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
## Advanced Examples
|
|
72
|
-
|
|
73
|
-
```typescript
|
|
74
|
-
// Switch without label
|
|
75
|
-
function MinimalSwitch() {
|
|
76
|
-
const [enabled, setEnabled] = useState(false);
|
|
77
|
-
|
|
78
|
-
return (
|
|
79
|
-
<Switch
|
|
80
|
-
enabled={enabled}
|
|
81
|
-
onChange={() => setEnabled(!enabled)}
|
|
82
|
-
/>
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// Disabled switch
|
|
87
|
-
function DisabledSwitch() {
|
|
88
|
-
return (
|
|
89
|
-
<Switch
|
|
90
|
-
enabled={true}
|
|
91
|
-
isDisabled={true}
|
|
92
|
-
onChange={() => {}}
|
|
93
|
-
>
|
|
94
|
-
Read-only Setting
|
|
95
|
-
</Switch>
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// Form integration
|
|
100
|
-
function SettingsForm() {
|
|
101
|
-
const [settings, setSettings] = useState({
|
|
102
|
-
notifications: false,
|
|
103
|
-
darkMode: false,
|
|
104
|
-
autoSave: true,
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
const updateSetting = (key: string) => {
|
|
108
|
-
setSettings(prev => ({
|
|
109
|
-
...prev,
|
|
110
|
-
[key]: !prev[key as keyof typeof prev]
|
|
111
|
-
}));
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
return (
|
|
115
|
-
<div>
|
|
116
|
-
<h3>User Settings</h3>
|
|
117
|
-
|
|
118
|
-
<Switch
|
|
119
|
-
enabled={settings.notifications}
|
|
120
|
-
labelPosition="left"
|
|
121
|
-
onChange={() => updateSetting('notifications')}
|
|
122
|
-
>
|
|
123
|
-
Email Notifications
|
|
124
|
-
</Switch>
|
|
125
|
-
|
|
126
|
-
<Switch
|
|
127
|
-
enabled={settings.darkMode}
|
|
128
|
-
labelPosition="left"
|
|
129
|
-
onChange={() => updateSetting('darkMode')}
|
|
130
|
-
>
|
|
131
|
-
Dark Theme
|
|
132
|
-
</Switch>
|
|
133
|
-
|
|
134
|
-
<Switch
|
|
135
|
-
enabled={settings.autoSave}
|
|
136
|
-
labelPosition="left"
|
|
137
|
-
onChange={() => updateSetting('autoSave')}
|
|
138
|
-
>
|
|
139
|
-
Auto-save Documents
|
|
140
|
-
</Switch>
|
|
141
|
-
</div>
|
|
142
|
-
);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// Permission toggle
|
|
146
|
-
function PermissionToggle() {
|
|
147
|
-
const [permissions, setPermissions] = useState({
|
|
148
|
-
canEdit: false,
|
|
149
|
-
canDelete: false,
|
|
150
|
-
canShare: true,
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
return (
|
|
154
|
-
<div>
|
|
155
|
-
<h4>User Permissions</h4>
|
|
156
|
-
|
|
157
|
-
<Switch
|
|
158
|
-
enabled={permissions.canEdit}
|
|
159
|
-
onChange={() => setPermissions(prev => ({
|
|
160
|
-
...prev,
|
|
161
|
-
canEdit: !prev.canEdit
|
|
162
|
-
}))}
|
|
163
|
-
>
|
|
164
|
-
Can Edit Content
|
|
165
|
-
</Switch>
|
|
166
|
-
|
|
167
|
-
<Switch
|
|
168
|
-
enabled={permissions.canDelete}
|
|
169
|
-
isDisabled={!permissions.canEdit} // Dependent permission
|
|
170
|
-
onChange={() => setPermissions(prev => ({
|
|
171
|
-
...prev,
|
|
172
|
-
canDelete: !prev.canDelete
|
|
173
|
-
}))}
|
|
174
|
-
>
|
|
175
|
-
Can Delete Content
|
|
176
|
-
</Switch>
|
|
177
|
-
|
|
178
|
-
<Switch
|
|
179
|
-
enabled={permissions.canShare}
|
|
180
|
-
onChange={() => setPermissions(prev => ({
|
|
181
|
-
...prev,
|
|
182
|
-
canShare: !prev.canShare
|
|
183
|
-
}))}
|
|
184
|
-
>
|
|
185
|
-
Can Share Content
|
|
186
|
-
</Switch>
|
|
187
|
-
</div>
|
|
188
|
-
);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
// Async state management
|
|
192
|
-
function AsyncSwitch() {
|
|
193
|
-
const [enabled, setEnabled] = useState(false);
|
|
194
|
-
const [loading, setLoading] = useState(false);
|
|
195
|
-
|
|
196
|
-
const handleToggle = async () => {
|
|
197
|
-
setLoading(true);
|
|
198
|
-
try {
|
|
199
|
-
// Simulate API call
|
|
200
|
-
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
201
|
-
setEnabled(!enabled);
|
|
202
|
-
} finally {
|
|
203
|
-
setLoading(false);
|
|
204
|
-
}
|
|
205
|
-
};
|
|
206
|
-
|
|
207
|
-
return (
|
|
208
|
-
<Switch
|
|
209
|
-
enabled={enabled}
|
|
210
|
-
isDisabled={loading}
|
|
211
|
-
onChange={handleToggle}
|
|
212
|
-
>
|
|
213
|
-
{loading ? 'Updating...' : 'Feature Toggle'}
|
|
214
|
-
</Switch>
|
|
215
|
-
);
|
|
216
|
-
}
|
|
217
|
-
```
|
|
218
|
-
|
|
219
|
-
## Props Reference
|
|
220
|
-
|
|
221
|
-
| Prop | Type | Default | Required | Description |
|
|
222
|
-
|------|------|---------|----------|-------------|
|
|
223
|
-
| `labelPosition` | `'left' \| 'right'` | `'right'` | No | Position of the label relative to the switch |
|
|
224
|
-
| `enabled` | `boolean` | `false` | No | Whether the switch is in the enabled/on state |
|
|
225
|
-
| `isDisabled` | `boolean` | `false` | No | Whether the switch is disabled and non-interactive |
|
|
226
|
-
| `children` | `ReactNode` | `undefined` | No | Label content displayed next to the switch |
|
|
227
|
-
| `onChange` | `() => void` | - | Yes | Callback fired when the switch is toggled |
|
|
228
|
-
|
|
229
|
-
## AI Agent Guidelines
|
|
230
|
-
|
|
231
|
-
### Recommended Patterns
|
|
232
|
-
|
|
233
|
-
1. **State Management**: Use boolean state for switch values
|
|
234
|
-
```typescript
|
|
235
|
-
const [isEnabled, setIsEnabled] = useState(false);
|
|
236
|
-
|
|
237
|
-
<Switch
|
|
238
|
-
enabled={isEnabled}
|
|
239
|
-
onChange={() => setIsEnabled(!isEnabled)}
|
|
240
|
-
>
|
|
241
|
-
Setting Name
|
|
242
|
-
</Switch>
|
|
243
|
-
```
|
|
244
|
-
|
|
245
|
-
2. **Label Positioning**: Use consistent positioning within a form
|
|
246
|
-
```typescript
|
|
247
|
-
// Consistent left positioning for form layouts
|
|
248
|
-
<Switch labelPosition="left" enabled={setting1} onChange={toggle1}>Setting 1</Switch>
|
|
249
|
-
<Switch labelPosition="left" enabled={setting2} onChange={toggle2}>Setting 2</Switch>
|
|
250
|
-
```
|
|
251
|
-
|
|
252
|
-
3. **Form Integration**: Integrate with form state management
|
|
253
|
-
```typescript
|
|
254
|
-
const [formData, setFormData] = useState({ notifications: false });
|
|
255
|
-
|
|
256
|
-
const toggleNotifications = () => {
|
|
257
|
-
setFormData(prev => ({
|
|
258
|
-
...prev,
|
|
259
|
-
notifications: !prev.notifications
|
|
260
|
-
}));
|
|
261
|
-
};
|
|
262
|
-
```
|
|
263
|
-
|
|
264
|
-
### Common Mistakes to Avoid
|
|
265
|
-
|
|
266
|
-
1. **Missing onChange**: Always provide an `onChange` handler, even for disabled switches
|
|
267
|
-
2. **Inconsistent State**: Don't mix controlled and uncontrolled patterns
|
|
268
|
-
3. **Wrong Data Type**: The `enabled` prop expects a boolean, not a string
|
|
269
|
-
4. **Accessibility**: Don't forget to provide meaningful labels via `children`
|
|
270
|
-
|
|
271
|
-
### Integration Tips
|
|
272
|
-
|
|
273
|
-
1. **Accessibility**: The component automatically handles ARIA attributes and keyboard navigation
|
|
274
|
-
2. **Visual States**: The switch provides clear visual feedback for enabled/disabled states
|
|
275
|
-
3. **Performance**: Use React.memo() for switches in large lists to prevent unnecessary re-renders
|
|
276
|
-
4. **Form Libraries**: Works well with React Hook Form and Formik
|
|
277
|
-
```typescript
|
|
278
|
-
// React Hook Form integration
|
|
279
|
-
const { watch, setValue } = useForm();
|
|
280
|
-
const enabled = watch('featureEnabled');
|
|
281
|
-
|
|
282
|
-
<Switch
|
|
283
|
-
enabled={enabled}
|
|
284
|
-
onChange={() => setValue('featureEnabled', !enabled)}
|
|
285
|
-
>
|
|
286
|
-
Feature Toggle
|
|
287
|
-
</Switch>
|
|
288
|
-
```
|
|
289
|
-
|
|
290
|
-
5. **Async Operations**: Handle loading states by temporarily disabling the switch
|
|
291
|
-
```typescript
|
|
292
|
-
const [loading, setLoading] = useState(false);
|
|
293
|
-
|
|
294
|
-
<Switch
|
|
295
|
-
enabled={enabled}
|
|
296
|
-
isDisabled={loading}
|
|
297
|
-
onChange={async () => {
|
|
298
|
-
setLoading(true);
|
|
299
|
-
await saveSettings();
|
|
300
|
-
setLoading(false);
|
|
301
|
-
}}
|
|
302
|
-
>
|
|
303
|
-
{loading ? 'Saving...' : 'Auto Save'}
|
|
304
|
-
</Switch>
|
|
305
|
-
```
|
|
306
|
-
|
|
307
|
-
## Related Components
|
|
308
|
-
|
|
309
|
-
- **Radio**: For mutually exclusive options
|
|
310
|
-
- **Checkbox**: For multi-select scenarios
|
|
311
|
-
- **Button**: For action-based toggles
|
|
312
|
-
- **Select**: For multiple option selections
|