@delightui/components 0.1.105 → 0.1.107
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 +104 -1
- package/dist/cjs/components/molecules/Modal/DemoModal.d.ts +8 -0
- package/dist/cjs/components/molecules/Modal/ModalContext/ModalContext.d.ts +41 -0
- package/dist/cjs/components/molecules/Modal/ModalContext/ModalContext.types.d.ts +87 -0
- package/dist/cjs/components/molecules/Modal/ModalContext/index.d.ts +3 -0
- package/dist/cjs/components/molecules/Modal/ModalContext/useModal.d.ts +34 -0
- package/dist/cjs/components/molecules/Modal/index.d.ts +2 -0
- package/dist/cjs/components/molecules/index.d.ts +2 -0
- package/dist/cjs/library.css +19 -6
- package/dist/cjs/library.js +3 -3
- package/dist/cjs/library.js.map +1 -1
- package/dist/esm/components/molecules/Modal/DemoModal.d.ts +8 -0
- package/dist/esm/components/molecules/Modal/ModalContext/ModalContext.d.ts +41 -0
- package/dist/esm/components/molecules/Modal/ModalContext/ModalContext.types.d.ts +87 -0
- package/dist/esm/components/molecules/Modal/ModalContext/index.d.ts +3 -0
- package/dist/esm/components/molecules/Modal/ModalContext/useModal.d.ts +34 -0
- package/dist/esm/components/molecules/Modal/index.d.ts +2 -0
- package/dist/esm/components/molecules/index.d.ts +2 -0
- package/dist/esm/library.css +19 -6
- package/dist/esm/library.js +3 -3
- package/dist/esm/library.js.map +1 -1
- package/dist/index.d.ts +108 -2
- package/docs/README.md +264 -0
- package/docs/components/atoms/ActionImage.md +119 -0
- package/docs/components/atoms/Button.md +197 -0
- package/docs/components/atoms/Checkbox.md +299 -0
- package/docs/components/atoms/CheckboxItem.md +314 -0
- package/docs/components/atoms/Chip.md +380 -0
- package/docs/components/atoms/CustomToggle.md +270 -0
- package/docs/components/atoms/Icon.md +365 -0
- package/docs/components/atoms/IconButton.md +407 -0
- package/docs/components/atoms/Image.md +448 -0
- package/docs/components/atoms/Input.md +430 -0
- package/docs/components/atoms/ListItem.md +502 -0
- package/docs/components/atoms/Password.md +472 -0
- package/docs/components/atoms/RadioButton.md +614 -0
- package/docs/components/atoms/RadioButtonItem.md +588 -0
- package/docs/components/atoms/ResponsiveComponent.md +612 -0
- package/docs/components/atoms/SelectListItem.md +609 -0
- package/docs/components/atoms/Slider.md +605 -0
- package/docs/components/atoms/Spinner.md +605 -0
- package/docs/components/atoms/Text.md +463 -0
- package/docs/components/atoms/TextArea.md +670 -0
- package/docs/components/atoms/ToastNotification.md +668 -0
- package/docs/components/atoms/Toggle.md +737 -0
- package/docs/components/atoms/ToggleButton.md +751 -0
- package/docs/components/atoms/Tooltip.md +391 -0
- package/docs/components/molecules/Accordion.md +440 -0
- package/docs/components/molecules/AccordionGroup.md +547 -0
- package/docs/components/molecules/ActionCard.md +546 -0
- package/docs/components/molecules/Breadcrumb.md +403 -0
- package/docs/components/molecules/Breadcrumbs.md +485 -0
- package/docs/components/molecules/ButtonGroup.md +383 -0
- package/docs/components/molecules/Card.md +298 -0
- package/docs/components/molecules/ChipInput.md +646 -0
- package/docs/components/molecules/ContextMenu.md +768 -0
- package/docs/components/molecules/CustomTimeSelector.md +116 -0
- package/docs/components/molecules/DatePicker.md +516 -0
- package/docs/components/molecules/DateTimeSelector.md +166 -0
- package/docs/components/molecules/FormField.md +312 -0
- package/docs/components/molecules/Grid.md +577 -0
- package/docs/components/molecules/GridItem.md +834 -0
- package/docs/components/molecules/GridList.md +244 -0
- package/docs/components/molecules/List.md +485 -0
- package/docs/components/molecules/Modal.md +470 -0
- package/docs/components/molecules/ModalFooter.md +702 -0
- package/docs/components/molecules/ModalHeader.md +756 -0
- package/docs/components/molecules/ModalProvider.md +205 -0
- package/docs/components/molecules/Nav.md +530 -0
- package/docs/components/molecules/NavItem.md +572 -0
- package/docs/components/molecules/NavLink.md +499 -0
- package/docs/components/molecules/Option.md +521 -0
- package/docs/components/molecules/Pagination.md +592 -0
- package/docs/components/molecules/PaginationNumberField.md +722 -0
- package/docs/components/molecules/Popover.md +516 -0
- package/docs/components/molecules/ProgressBar.md +624 -0
- package/docs/components/molecules/RadioGroup.md +831 -0
- package/docs/components/molecules/RepeaterList.md +185 -0
- package/docs/components/molecules/Select.md +402 -0
- package/docs/components/molecules/SortableTrigger.md +82 -0
- package/docs/components/molecules/useModal.md +379 -0
- package/docs/components/organisms/Dropzone.md +346 -0
- package/docs/components/organisms/DropzoneClear.md +135 -0
- package/docs/components/organisms/DropzoneContent.md +216 -0
- package/docs/components/organisms/DropzoneFilename.md +191 -0
- package/docs/components/organisms/DropzoneSupportedFormats.md +184 -0
- package/docs/components/organisms/DropzoneTrigger.md +209 -0
- package/docs/components/organisms/Form.md +533 -0
- package/docs/components/organisms/SlideOutPanel.md +662 -0
- package/docs/components/organisms/TabContent.md +902 -0
- package/docs/components/organisms/TabItem.md +1091 -0
- package/docs/components/organisms/Table.md +611 -0
- package/docs/components/organisms/TableBody.md +679 -0
- package/docs/components/organisms/TableCell.md +482 -0
- package/docs/components/organisms/TableHeader.md +513 -0
- package/docs/components/organisms/TableHeaderCell.md +661 -0
- package/docs/components/organisms/TableRow.md +715 -0
- package/docs/components/organisms/Tabs.md +1330 -0
- package/docs/components/utils/ConditionalView.md +568 -0
- package/docs/components/utils/RenderStateView.md +726 -0
- package/docs/components/utils/WrapTextNodes.md +614 -0
- package/package.json +3 -2
|
@@ -0,0 +1,737 @@
|
|
|
1
|
+
# Toggle
|
|
2
|
+
|
|
3
|
+
A toggle switch component that allows users to switch between two states (on/off, enabled/disabled). It provides a visual alternative to checkboxes for boolean inputs and includes flexible label positioning options. The component integrates seamlessly with forms and supports both controlled and uncontrolled usage patterns.
|
|
4
|
+
|
|
5
|
+
## Aliases
|
|
6
|
+
|
|
7
|
+
- Toggle
|
|
8
|
+
- Switch
|
|
9
|
+
- ToggleSwitch
|
|
10
|
+
|
|
11
|
+
## Props Breakdown
|
|
12
|
+
|
|
13
|
+
**Extends:** `InputHTMLAttributes<HTMLInputElement>` (excluding `type`, `value`, `checked`) + `ControlledFormComponentProps<boolean>`
|
|
14
|
+
|
|
15
|
+
| Prop | Type | Default | Required | Description |
|
|
16
|
+
|------|------|---------|----------|-------------|
|
|
17
|
+
| `children` | `ReactNode` | `undefined` | No | The label of the toggle |
|
|
18
|
+
| `labelAlignment` | `'Left' \| 'Right'` | `'Left'` | No | Alignment of the label |
|
|
19
|
+
| `initialValue` | `boolean` | `undefined` | No | The initial value for the field |
|
|
20
|
+
| `checked` | `boolean` | `undefined` | No | The initial value for the field |
|
|
21
|
+
| `value` | `boolean` | `undefined` | No | The current value of the form field |
|
|
22
|
+
| `onValueChange` | `(value: boolean) => void` | `undefined` | No | Callback function that is called when the field value changes |
|
|
23
|
+
| `disabled` | `boolean` | `false` | No | Whether the form field is disabled and cannot be interacted with |
|
|
24
|
+
| `required` | `boolean` | `false` | No | Whether the form field must have a value |
|
|
25
|
+
| `invalid` | `boolean` | `false` | No | Whether the form field's current value is invalid |
|
|
26
|
+
| `id` | `string` | `undefined` | No | Id for the form field |
|
|
27
|
+
| `name` | `string` | `undefined` | No | Name attribute for the toggle |
|
|
28
|
+
|
|
29
|
+
Plus all standard HTML input attributes (onChange, onFocus, onBlur, aria-*, data-*, etc.).
|
|
30
|
+
|
|
31
|
+
## Examples
|
|
32
|
+
|
|
33
|
+
### Basic Toggle
|
|
34
|
+
|
|
35
|
+
```tsx
|
|
36
|
+
import { Toggle } from '@delightui/components';
|
|
37
|
+
|
|
38
|
+
function BasicToggleExample() {
|
|
39
|
+
const [isEnabled, setIsEnabled] = useState(false);
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<div>
|
|
43
|
+
<p>Status: {isEnabled ? 'Enabled' : 'Disabled'}</p>
|
|
44
|
+
<Toggle
|
|
45
|
+
value={isEnabled}
|
|
46
|
+
onValueChange={setIsEnabled}
|
|
47
|
+
>
|
|
48
|
+
Enable notifications
|
|
49
|
+
</Toggle>
|
|
50
|
+
</div>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Label Alignment
|
|
56
|
+
|
|
57
|
+
```tsx
|
|
58
|
+
import { Toggle } from '@delightui/components';
|
|
59
|
+
|
|
60
|
+
function LabelAlignmentExample() {
|
|
61
|
+
const [leftToggle, setLeftToggle] = useState(false);
|
|
62
|
+
const [rightToggle, setRightToggle] = useState(true);
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: '16px' }}>
|
|
66
|
+
<Toggle
|
|
67
|
+
value={leftToggle}
|
|
68
|
+
onValueChange={setLeftToggle}
|
|
69
|
+
labelAlignment="Left"
|
|
70
|
+
>
|
|
71
|
+
Label on the left
|
|
72
|
+
</Toggle>
|
|
73
|
+
|
|
74
|
+
<Toggle
|
|
75
|
+
value={rightToggle}
|
|
76
|
+
onValueChange={setRightToggle}
|
|
77
|
+
labelAlignment="Right"
|
|
78
|
+
>
|
|
79
|
+
Label on the right
|
|
80
|
+
</Toggle>
|
|
81
|
+
</div>
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Form Integration
|
|
87
|
+
|
|
88
|
+
```tsx
|
|
89
|
+
import { Form, FormField, Toggle, Button } from '@delightui/components';
|
|
90
|
+
|
|
91
|
+
function ToggleFormExample() {
|
|
92
|
+
const handleSubmit = (data: any) => {
|
|
93
|
+
console.log('Form submitted:', data);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
return (
|
|
97
|
+
<Form onSubmit={handleSubmit}>
|
|
98
|
+
<FormField
|
|
99
|
+
name="emailNotifications"
|
|
100
|
+
label="Email Notifications"
|
|
101
|
+
>
|
|
102
|
+
<Toggle initialValue={true}>
|
|
103
|
+
Receive email notifications
|
|
104
|
+
</Toggle>
|
|
105
|
+
</FormField>
|
|
106
|
+
|
|
107
|
+
<FormField
|
|
108
|
+
name="smsNotifications"
|
|
109
|
+
label="SMS Notifications"
|
|
110
|
+
>
|
|
111
|
+
<Toggle initialValue={false}>
|
|
112
|
+
Receive SMS notifications
|
|
113
|
+
</Toggle>
|
|
114
|
+
</FormField>
|
|
115
|
+
|
|
116
|
+
<FormField
|
|
117
|
+
name="marketing"
|
|
118
|
+
label="Marketing Communications"
|
|
119
|
+
>
|
|
120
|
+
<Toggle initialValue={false}>
|
|
121
|
+
Receive marketing emails
|
|
122
|
+
</Toggle>
|
|
123
|
+
</FormField>
|
|
124
|
+
|
|
125
|
+
<FormField
|
|
126
|
+
name="twoFactor"
|
|
127
|
+
label="Security"
|
|
128
|
+
required
|
|
129
|
+
>
|
|
130
|
+
<Toggle initialValue={true}>
|
|
131
|
+
Enable two-factor authentication
|
|
132
|
+
</Toggle>
|
|
133
|
+
</FormField>
|
|
134
|
+
|
|
135
|
+
<Button type="submit">
|
|
136
|
+
Save Preferences
|
|
137
|
+
</Button>
|
|
138
|
+
</Form>
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Settings Panel
|
|
144
|
+
|
|
145
|
+
```tsx
|
|
146
|
+
import { Toggle, Text } from '@delightui/components';
|
|
147
|
+
|
|
148
|
+
function SettingsPanelExample() {
|
|
149
|
+
const [settings, setSettings] = useState({
|
|
150
|
+
darkMode: false,
|
|
151
|
+
notifications: true,
|
|
152
|
+
autoSave: true,
|
|
153
|
+
soundEffects: false,
|
|
154
|
+
analytics: false
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
const updateSetting = (key: string, value: boolean) => {
|
|
158
|
+
setSettings(prev => ({ ...prev, [key]: value }));
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
return (
|
|
162
|
+
<div style={{
|
|
163
|
+
border: '1px solid #ccc',
|
|
164
|
+
borderRadius: '8px',
|
|
165
|
+
padding: '20px',
|
|
166
|
+
maxWidth: '400px'
|
|
167
|
+
}}>
|
|
168
|
+
<Text weight="bold" size="large" style={{ marginBottom: '20px' }}>
|
|
169
|
+
Application Settings
|
|
170
|
+
</Text>
|
|
171
|
+
|
|
172
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: '20px' }}>
|
|
173
|
+
<div>
|
|
174
|
+
<Toggle
|
|
175
|
+
value={settings.darkMode}
|
|
176
|
+
onValueChange={(value) => updateSetting('darkMode', value)}
|
|
177
|
+
>
|
|
178
|
+
Dark Mode
|
|
179
|
+
</Toggle>
|
|
180
|
+
<Text size="small" color="secondary" style={{ marginTop: '4px', marginLeft: '28px' }}>
|
|
181
|
+
Switch to dark theme for better viewing in low light
|
|
182
|
+
</Text>
|
|
183
|
+
</div>
|
|
184
|
+
|
|
185
|
+
<div>
|
|
186
|
+
<Toggle
|
|
187
|
+
value={settings.notifications}
|
|
188
|
+
onValueChange={(value) => updateSetting('notifications', value)}
|
|
189
|
+
>
|
|
190
|
+
Push Notifications
|
|
191
|
+
</Toggle>
|
|
192
|
+
<Text size="small" color="secondary" style={{ marginTop: '4px', marginLeft: '28px' }}>
|
|
193
|
+
Receive notifications about important updates
|
|
194
|
+
</Text>
|
|
195
|
+
</div>
|
|
196
|
+
|
|
197
|
+
<div>
|
|
198
|
+
<Toggle
|
|
199
|
+
value={settings.autoSave}
|
|
200
|
+
onValueChange={(value) => updateSetting('autoSave', value)}
|
|
201
|
+
>
|
|
202
|
+
Auto-save
|
|
203
|
+
</Toggle>
|
|
204
|
+
<Text size="small" color="secondary" style={{ marginTop: '4px', marginLeft: '28px' }}>
|
|
205
|
+
Automatically save your work every 5 minutes
|
|
206
|
+
</Text>
|
|
207
|
+
</div>
|
|
208
|
+
|
|
209
|
+
<div>
|
|
210
|
+
<Toggle
|
|
211
|
+
value={settings.soundEffects}
|
|
212
|
+
onValueChange={(value) => updateSetting('soundEffects', value)}
|
|
213
|
+
>
|
|
214
|
+
Sound Effects
|
|
215
|
+
</Toggle>
|
|
216
|
+
<Text size="small" color="secondary" style={{ marginTop: '4px', marginLeft: '28px' }}>
|
|
217
|
+
Play sounds for notifications and interactions
|
|
218
|
+
</Text>
|
|
219
|
+
</div>
|
|
220
|
+
|
|
221
|
+
<div>
|
|
222
|
+
<Toggle
|
|
223
|
+
value={settings.analytics}
|
|
224
|
+
onValueChange={(value) => updateSetting('analytics', value)}
|
|
225
|
+
>
|
|
226
|
+
Analytics
|
|
227
|
+
</Toggle>
|
|
228
|
+
<Text size="small" color="secondary" style={{ marginTop: '4px', marginLeft: '28px' }}>
|
|
229
|
+
Help improve our service by sharing usage data
|
|
230
|
+
</Text>
|
|
231
|
+
</div>
|
|
232
|
+
</div>
|
|
233
|
+
</div>
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### Feature Toggles
|
|
239
|
+
|
|
240
|
+
```tsx
|
|
241
|
+
import { Toggle, Text, Button } from '@delightui/components';
|
|
242
|
+
|
|
243
|
+
function FeatureTogglesExample() {
|
|
244
|
+
const [features, setFeatures] = useState({
|
|
245
|
+
betaFeatures: false,
|
|
246
|
+
experimentalUI: false,
|
|
247
|
+
advancedMode: false,
|
|
248
|
+
debugMode: false
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
const [showWarning, setShowWarning] = useState(false);
|
|
252
|
+
|
|
253
|
+
const updateFeature = (key: string, value: boolean) => {
|
|
254
|
+
if (key === 'debugMode' && value) {
|
|
255
|
+
setShowWarning(true);
|
|
256
|
+
} else {
|
|
257
|
+
setShowWarning(false);
|
|
258
|
+
}
|
|
259
|
+
setFeatures(prev => ({ ...prev, [key]: value }));
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
return (
|
|
263
|
+
<div style={{ maxWidth: '500px' }}>
|
|
264
|
+
<Text weight="bold" size="large" style={{ marginBottom: '16px' }}>
|
|
265
|
+
Feature Toggles
|
|
266
|
+
</Text>
|
|
267
|
+
|
|
268
|
+
<Text size="small" color="secondary" style={{ marginBottom: '20px' }}>
|
|
269
|
+
Enable or disable experimental features. Some features may be unstable.
|
|
270
|
+
</Text>
|
|
271
|
+
|
|
272
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: '20px' }}>
|
|
273
|
+
<div style={{
|
|
274
|
+
padding: '16px',
|
|
275
|
+
border: '1px solid #e0e0e0',
|
|
276
|
+
borderRadius: '8px',
|
|
277
|
+
backgroundColor: features.betaFeatures ? '#f0f8ff' : '#f9f9f9'
|
|
278
|
+
}}>
|
|
279
|
+
<Toggle
|
|
280
|
+
value={features.betaFeatures}
|
|
281
|
+
onValueChange={(value) => updateFeature('betaFeatures', value)}
|
|
282
|
+
>
|
|
283
|
+
<Text weight="medium">Beta Features</Text>
|
|
284
|
+
</Toggle>
|
|
285
|
+
<Text size="small" color="secondary" style={{ marginTop: '8px', marginLeft: '28px' }}>
|
|
286
|
+
Access to features currently in beta testing
|
|
287
|
+
</Text>
|
|
288
|
+
</div>
|
|
289
|
+
|
|
290
|
+
<div style={{
|
|
291
|
+
padding: '16px',
|
|
292
|
+
border: '1px solid #e0e0e0',
|
|
293
|
+
borderRadius: '8px',
|
|
294
|
+
backgroundColor: features.experimentalUI ? '#fff8e1' : '#f9f9f9'
|
|
295
|
+
}}>
|
|
296
|
+
<Toggle
|
|
297
|
+
value={features.experimentalUI}
|
|
298
|
+
onValueChange={(value) => updateFeature('experimentalUI', value)}
|
|
299
|
+
>
|
|
300
|
+
<Text weight="medium">Experimental UI</Text>
|
|
301
|
+
</Toggle>
|
|
302
|
+
<Text size="small" color="secondary" style={{ marginTop: '8px', marginLeft: '28px' }}>
|
|
303
|
+
Try out new user interface designs and layouts
|
|
304
|
+
</Text>
|
|
305
|
+
</div>
|
|
306
|
+
|
|
307
|
+
<div style={{
|
|
308
|
+
padding: '16px',
|
|
309
|
+
border: '1px solid #e0e0e0',
|
|
310
|
+
borderRadius: '8px',
|
|
311
|
+
backgroundColor: features.advancedMode ? '#e8f5e8' : '#f9f9f9'
|
|
312
|
+
}}>
|
|
313
|
+
<Toggle
|
|
314
|
+
value={features.advancedMode}
|
|
315
|
+
onValueChange={(value) => updateFeature('advancedMode', value)}
|
|
316
|
+
>
|
|
317
|
+
<Text weight="medium">Advanced Mode</Text>
|
|
318
|
+
</Toggle>
|
|
319
|
+
<Text size="small" color="secondary" style={{ marginTop: '8px', marginLeft: '28px' }}>
|
|
320
|
+
Show advanced options and configuration settings
|
|
321
|
+
</Text>
|
|
322
|
+
</div>
|
|
323
|
+
|
|
324
|
+
<div style={{
|
|
325
|
+
padding: '16px',
|
|
326
|
+
border: '1px solid #ffcdd2',
|
|
327
|
+
borderRadius: '8px',
|
|
328
|
+
backgroundColor: features.debugMode ? '#ffebee' : '#f9f9f9'
|
|
329
|
+
}}>
|
|
330
|
+
<Toggle
|
|
331
|
+
value={features.debugMode}
|
|
332
|
+
onValueChange={(value) => updateFeature('debugMode', value)}
|
|
333
|
+
>
|
|
334
|
+
<Text weight="medium" color={features.debugMode ? 'error' : 'default'}>
|
|
335
|
+
Debug Mode
|
|
336
|
+
</Text>
|
|
337
|
+
</Toggle>
|
|
338
|
+
<Text size="small" color="secondary" style={{ marginTop: '8px', marginLeft: '28px' }}>
|
|
339
|
+
Enable debugging tools and verbose logging
|
|
340
|
+
</Text>
|
|
341
|
+
|
|
342
|
+
{showWarning && (
|
|
343
|
+
<div style={{
|
|
344
|
+
marginTop: '12px',
|
|
345
|
+
padding: '8px 12px',
|
|
346
|
+
backgroundColor: '#fff3cd',
|
|
347
|
+
border: '1px solid #ffeaa7',
|
|
348
|
+
borderRadius: '4px'
|
|
349
|
+
}}>
|
|
350
|
+
<Text size="small" color="warning" weight="medium">
|
|
351
|
+
Warning: Debug mode may impact performance and expose sensitive information.
|
|
352
|
+
</Text>
|
|
353
|
+
</div>
|
|
354
|
+
)}
|
|
355
|
+
</div>
|
|
356
|
+
</div>
|
|
357
|
+
|
|
358
|
+
<div style={{ marginTop: '24px', textAlign: 'center' }}>
|
|
359
|
+
<Button onClick={() => console.log('Settings saved:', features)}>
|
|
360
|
+
Save Settings
|
|
361
|
+
</Button>
|
|
362
|
+
</div>
|
|
363
|
+
</div>
|
|
364
|
+
);
|
|
365
|
+
}
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
### Disabled Toggles
|
|
369
|
+
|
|
370
|
+
```tsx
|
|
371
|
+
import { Toggle, Text } from '@delightui/components';
|
|
372
|
+
|
|
373
|
+
function DisabledTogglesExample() {
|
|
374
|
+
return (
|
|
375
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: '16px' }}>
|
|
376
|
+
<Text weight="bold" style={{ marginBottom: '8px' }}>
|
|
377
|
+
Toggle States
|
|
378
|
+
</Text>
|
|
379
|
+
|
|
380
|
+
<Toggle value={false}>
|
|
381
|
+
Normal toggle (off)
|
|
382
|
+
</Toggle>
|
|
383
|
+
|
|
384
|
+
<Toggle value={true}>
|
|
385
|
+
Normal toggle (on)
|
|
386
|
+
</Toggle>
|
|
387
|
+
|
|
388
|
+
<Toggle value={false} disabled>
|
|
389
|
+
Disabled toggle (off)
|
|
390
|
+
</Toggle>
|
|
391
|
+
|
|
392
|
+
<Toggle value={true} disabled>
|
|
393
|
+
Disabled toggle (on)
|
|
394
|
+
</Toggle>
|
|
395
|
+
</div>
|
|
396
|
+
);
|
|
397
|
+
}
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
### Privacy Settings
|
|
401
|
+
|
|
402
|
+
```tsx
|
|
403
|
+
import { Toggle, Text, Button } from '@delightui/components';
|
|
404
|
+
|
|
405
|
+
function PrivacySettingsExample() {
|
|
406
|
+
const [privacy, setPrivacy] = useState({
|
|
407
|
+
profileVisibility: true,
|
|
408
|
+
showEmail: false,
|
|
409
|
+
showPhone: false,
|
|
410
|
+
allowMessages: true,
|
|
411
|
+
shareData: false,
|
|
412
|
+
trackingCookies: false
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
const updatePrivacy = (key: string, value: boolean) => {
|
|
416
|
+
setPrivacy(prev => ({ ...prev, [key]: value }));
|
|
417
|
+
};
|
|
418
|
+
|
|
419
|
+
const getPrivacyScore = () => {
|
|
420
|
+
const enabledCount = Object.values(privacy).filter(Boolean).length;
|
|
421
|
+
const totalCount = Object.keys(privacy).length;
|
|
422
|
+
return Math.round(((totalCount - enabledCount) / totalCount) * 100);
|
|
423
|
+
};
|
|
424
|
+
|
|
425
|
+
const privacyScore = getPrivacyScore();
|
|
426
|
+
|
|
427
|
+
return (
|
|
428
|
+
<div style={{ maxWidth: '600px' }}>
|
|
429
|
+
<div style={{
|
|
430
|
+
display: 'flex',
|
|
431
|
+
justifyContent: 'space-between',
|
|
432
|
+
alignItems: 'center',
|
|
433
|
+
marginBottom: '20px'
|
|
434
|
+
}}>
|
|
435
|
+
<Text weight="bold" size="large">
|
|
436
|
+
Privacy Settings
|
|
437
|
+
</Text>
|
|
438
|
+
<div style={{
|
|
439
|
+
padding: '8px 16px',
|
|
440
|
+
borderRadius: '20px',
|
|
441
|
+
backgroundColor: privacyScore > 60 ? '#d4edda' : privacyScore > 30 ? '#fff3cd' : '#f8d7da'
|
|
442
|
+
}}>
|
|
443
|
+
<Text size="small" weight="bold">
|
|
444
|
+
Privacy Score: {privacyScore}%
|
|
445
|
+
</Text>
|
|
446
|
+
</div>
|
|
447
|
+
</div>
|
|
448
|
+
|
|
449
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: '20px' }}>
|
|
450
|
+
<div>
|
|
451
|
+
<Toggle
|
|
452
|
+
value={privacy.profileVisibility}
|
|
453
|
+
onValueChange={(value) => updatePrivacy('profileVisibility', value)}
|
|
454
|
+
labelAlignment="Right"
|
|
455
|
+
>
|
|
456
|
+
<div>
|
|
457
|
+
<Text weight="medium">Public Profile</Text>
|
|
458
|
+
<Text size="small" color="secondary" style={{ display: 'block', marginTop: '2px' }}>
|
|
459
|
+
Make your profile visible to other users
|
|
460
|
+
</Text>
|
|
461
|
+
</div>
|
|
462
|
+
</Toggle>
|
|
463
|
+
</div>
|
|
464
|
+
|
|
465
|
+
<div>
|
|
466
|
+
<Toggle
|
|
467
|
+
value={privacy.showEmail}
|
|
468
|
+
onValueChange={(value) => updatePrivacy('showEmail', value)}
|
|
469
|
+
labelAlignment="Right"
|
|
470
|
+
>
|
|
471
|
+
<div>
|
|
472
|
+
<Text weight="medium">Show Email Address</Text>
|
|
473
|
+
<Text size="small" color="secondary" style={{ display: 'block', marginTop: '2px' }}>
|
|
474
|
+
Display your email on your public profile
|
|
475
|
+
</Text>
|
|
476
|
+
</div>
|
|
477
|
+
</Toggle>
|
|
478
|
+
</div>
|
|
479
|
+
|
|
480
|
+
<div>
|
|
481
|
+
<Toggle
|
|
482
|
+
value={privacy.showPhone}
|
|
483
|
+
onValueChange={(value) => updatePrivacy('showPhone', value)}
|
|
484
|
+
labelAlignment="Right"
|
|
485
|
+
>
|
|
486
|
+
<div>
|
|
487
|
+
<Text weight="medium">Show Phone Number</Text>
|
|
488
|
+
<Text size="small" color="secondary" style={{ display: 'block', marginTop: '2px' }}>
|
|
489
|
+
Display your phone number on your public profile
|
|
490
|
+
</Text>
|
|
491
|
+
</div>
|
|
492
|
+
</Toggle>
|
|
493
|
+
</div>
|
|
494
|
+
|
|
495
|
+
<div>
|
|
496
|
+
<Toggle
|
|
497
|
+
value={privacy.allowMessages}
|
|
498
|
+
onValueChange={(value) => updatePrivacy('allowMessages', value)}
|
|
499
|
+
labelAlignment="Right"
|
|
500
|
+
>
|
|
501
|
+
<div>
|
|
502
|
+
<Text weight="medium">Allow Direct Messages</Text>
|
|
503
|
+
<Text size="small" color="secondary" style={{ display: 'block', marginTop: '2px' }}>
|
|
504
|
+
Let other users send you direct messages
|
|
505
|
+
</Text>
|
|
506
|
+
</div>
|
|
507
|
+
</Toggle>
|
|
508
|
+
</div>
|
|
509
|
+
|
|
510
|
+
<div>
|
|
511
|
+
<Toggle
|
|
512
|
+
value={privacy.shareData}
|
|
513
|
+
onValueChange={(value) => updatePrivacy('shareData', value)}
|
|
514
|
+
labelAlignment="Right"
|
|
515
|
+
>
|
|
516
|
+
<div>
|
|
517
|
+
<Text weight="medium">Data Sharing</Text>
|
|
518
|
+
<Text size="small" color="secondary" style={{ display: 'block', marginTop: '2px' }}>
|
|
519
|
+
Share anonymized usage data for product improvement
|
|
520
|
+
</Text>
|
|
521
|
+
</div>
|
|
522
|
+
</Toggle>
|
|
523
|
+
</div>
|
|
524
|
+
|
|
525
|
+
<div>
|
|
526
|
+
<Toggle
|
|
527
|
+
value={privacy.trackingCookies}
|
|
528
|
+
onValueChange={(value) => updatePrivacy('trackingCookies', value)}
|
|
529
|
+
labelAlignment="Right"
|
|
530
|
+
>
|
|
531
|
+
<div>
|
|
532
|
+
<Text weight="medium">Tracking Cookies</Text>
|
|
533
|
+
<Text size="small" color="secondary" style={{ display: 'block', marginTop: '2px' }}>
|
|
534
|
+
Allow tracking cookies for personalized advertising
|
|
535
|
+
</Text>
|
|
536
|
+
</div>
|
|
537
|
+
</Toggle>
|
|
538
|
+
</div>
|
|
539
|
+
</div>
|
|
540
|
+
|
|
541
|
+
<div style={{
|
|
542
|
+
marginTop: '24px',
|
|
543
|
+
padding: '16px',
|
|
544
|
+
backgroundColor: '#f8f9fa',
|
|
545
|
+
borderRadius: '8px'
|
|
546
|
+
}}>
|
|
547
|
+
<Text size="small" color="secondary">
|
|
548
|
+
Your privacy score reflects how much personal information you're sharing.
|
|
549
|
+
Higher scores indicate better privacy protection.
|
|
550
|
+
</Text>
|
|
551
|
+
</div>
|
|
552
|
+
|
|
553
|
+
<div style={{ marginTop: '20px', textAlign: 'center' }}>
|
|
554
|
+
<Button onClick={() => console.log('Privacy settings saved:', privacy)}>
|
|
555
|
+
Save Privacy Settings
|
|
556
|
+
</Button>
|
|
557
|
+
</div>
|
|
558
|
+
</div>
|
|
559
|
+
);
|
|
560
|
+
}
|
|
561
|
+
```
|
|
562
|
+
|
|
563
|
+
### Permissions Toggle
|
|
564
|
+
|
|
565
|
+
```tsx
|
|
566
|
+
import { Toggle, Text, Icon } from '@delightui/components';
|
|
567
|
+
|
|
568
|
+
function PermissionsToggleExample() {
|
|
569
|
+
const [permissions, setPermissions] = useState({
|
|
570
|
+
camera: false,
|
|
571
|
+
microphone: false,
|
|
572
|
+
location: false,
|
|
573
|
+
notifications: true,
|
|
574
|
+
storage: true
|
|
575
|
+
});
|
|
576
|
+
|
|
577
|
+
const updatePermission = (key: string, value: boolean) => {
|
|
578
|
+
setPermissions(prev => ({ ...prev, [key]: value }));
|
|
579
|
+
};
|
|
580
|
+
|
|
581
|
+
const permissionInfo = {
|
|
582
|
+
camera: {
|
|
583
|
+
icon: 'SearchFilled',
|
|
584
|
+
title: 'Camera Access',
|
|
585
|
+
description: 'Allow access to camera for photos and video calls'
|
|
586
|
+
},
|
|
587
|
+
microphone: {
|
|
588
|
+
icon: 'SearchFilled',
|
|
589
|
+
title: 'Microphone Access',
|
|
590
|
+
description: 'Allow access to microphone for voice recording'
|
|
591
|
+
},
|
|
592
|
+
location: {
|
|
593
|
+
icon: 'InfoFilled',
|
|
594
|
+
title: 'Location Services',
|
|
595
|
+
description: 'Allow access to your location for personalized content'
|
|
596
|
+
},
|
|
597
|
+
notifications: {
|
|
598
|
+
icon: 'InfoFilled',
|
|
599
|
+
title: 'Notifications',
|
|
600
|
+
description: 'Show notifications for important updates'
|
|
601
|
+
},
|
|
602
|
+
storage: {
|
|
603
|
+
icon: 'AddFilled',
|
|
604
|
+
title: 'Storage Access',
|
|
605
|
+
description: 'Allow access to device storage for file uploads'
|
|
606
|
+
}
|
|
607
|
+
};
|
|
608
|
+
|
|
609
|
+
return (
|
|
610
|
+
<div style={{ maxWidth: '500px' }}>
|
|
611
|
+
<Text weight="bold" size="large" style={{ marginBottom: '16px' }}>
|
|
612
|
+
App Permissions
|
|
613
|
+
</Text>
|
|
614
|
+
|
|
615
|
+
<Text size="small" color="secondary" style={{ marginBottom: '24px' }}>
|
|
616
|
+
Control which features of your device this app can access.
|
|
617
|
+
</Text>
|
|
618
|
+
|
|
619
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: '16px' }}>
|
|
620
|
+
{Object.entries(permissions).map(([key, value]) => {
|
|
621
|
+
const info = permissionInfo[key as keyof typeof permissionInfo];
|
|
622
|
+
|
|
623
|
+
return (
|
|
624
|
+
<div
|
|
625
|
+
key={key}
|
|
626
|
+
style={{
|
|
627
|
+
display: 'flex',
|
|
628
|
+
alignItems: 'flex-start',
|
|
629
|
+
gap: '12px',
|
|
630
|
+
padding: '16px',
|
|
631
|
+
border: '1px solid #e0e0e0',
|
|
632
|
+
borderRadius: '8px',
|
|
633
|
+
backgroundColor: value ? '#f0f8ff' : '#ffffff'
|
|
634
|
+
}}
|
|
635
|
+
>
|
|
636
|
+
<Icon name={info.icon} style={{ marginTop: '4px', color: value ? '#007bff' : '#6c757d' }} />
|
|
637
|
+
|
|
638
|
+
<div style={{ flex: 1 }}>
|
|
639
|
+
<Text weight="medium" style={{ marginBottom: '4px' }}>
|
|
640
|
+
{info.title}
|
|
641
|
+
</Text>
|
|
642
|
+
<Text size="small" color="secondary" style={{ marginBottom: '8px' }}>
|
|
643
|
+
{info.description}
|
|
644
|
+
</Text>
|
|
645
|
+
</div>
|
|
646
|
+
|
|
647
|
+
<Toggle
|
|
648
|
+
value={value}
|
|
649
|
+
onValueChange={(newValue) => updatePermission(key, newValue)}
|
|
650
|
+
/>
|
|
651
|
+
</div>
|
|
652
|
+
);
|
|
653
|
+
})}
|
|
654
|
+
</div>
|
|
655
|
+
|
|
656
|
+
<div style={{
|
|
657
|
+
marginTop: '20px',
|
|
658
|
+
padding: '12px',
|
|
659
|
+
backgroundColor: '#e9ecef',
|
|
660
|
+
borderRadius: '8px'
|
|
661
|
+
}}>
|
|
662
|
+
<Text size="small" color="secondary">
|
|
663
|
+
You can change these permissions at any time in your device settings.
|
|
664
|
+
</Text>
|
|
665
|
+
</div>
|
|
666
|
+
</div>
|
|
667
|
+
);
|
|
668
|
+
}
|
|
669
|
+
```
|
|
670
|
+
|
|
671
|
+
### Controlled vs Uncontrolled
|
|
672
|
+
|
|
673
|
+
```tsx
|
|
674
|
+
import { Toggle, Button, Text } from '@delightui/components';
|
|
675
|
+
|
|
676
|
+
function ControlledVsUncontrolledExample() {
|
|
677
|
+
const [controlledValue, setControlledValue] = useState(false);
|
|
678
|
+
|
|
679
|
+
return (
|
|
680
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: '24px' }}>
|
|
681
|
+
<div>
|
|
682
|
+
<Text weight="bold" style={{ marginBottom: '12px' }}>
|
|
683
|
+
Controlled Toggle
|
|
684
|
+
</Text>
|
|
685
|
+
<Text size="small" color="secondary" style={{ marginBottom: '12px' }}>
|
|
686
|
+
Value is controlled by React state
|
|
687
|
+
</Text>
|
|
688
|
+
|
|
689
|
+
<Toggle
|
|
690
|
+
value={controlledValue}
|
|
691
|
+
onValueChange={setControlledValue}
|
|
692
|
+
>
|
|
693
|
+
Controlled toggle (value: {controlledValue.toString()})
|
|
694
|
+
</Toggle>
|
|
695
|
+
|
|
696
|
+
<Button
|
|
697
|
+
size="Small"
|
|
698
|
+
type="Outlined"
|
|
699
|
+
onClick={() => setControlledValue(!controlledValue)}
|
|
700
|
+
style={{ marginTop: '8px' }}
|
|
701
|
+
>
|
|
702
|
+
Toggle Programmatically
|
|
703
|
+
</Button>
|
|
704
|
+
</div>
|
|
705
|
+
|
|
706
|
+
<div>
|
|
707
|
+
<Text weight="bold" style={{ marginBottom: '12px' }}>
|
|
708
|
+
Uncontrolled Toggle
|
|
709
|
+
</Text>
|
|
710
|
+
<Text size="small" color="secondary" style={{ marginBottom: '12px' }}>
|
|
711
|
+
Value is managed internally by the component
|
|
712
|
+
</Text>
|
|
713
|
+
|
|
714
|
+
<Toggle
|
|
715
|
+
initialValue={true}
|
|
716
|
+
onValueChange={(value) => console.log('Uncontrolled value changed:', value)}
|
|
717
|
+
>
|
|
718
|
+
Uncontrolled toggle with initial value
|
|
719
|
+
</Toggle>
|
|
720
|
+
</div>
|
|
721
|
+
|
|
722
|
+
<div>
|
|
723
|
+
<Text weight="bold" style={{ marginBottom: '12px' }}>
|
|
724
|
+
Invalid State Example
|
|
725
|
+
</Text>
|
|
726
|
+
|
|
727
|
+
<Toggle
|
|
728
|
+
value={true}
|
|
729
|
+
invalid
|
|
730
|
+
>
|
|
731
|
+
Toggle with validation error
|
|
732
|
+
</Toggle>
|
|
733
|
+
</div>
|
|
734
|
+
</div>
|
|
735
|
+
);
|
|
736
|
+
}
|
|
737
|
+
```
|