@vev/silke 1.1.6 → 1.1.7
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/CHANGELOG.md +8 -0
- package/dist/index.js +35 -35
- package/dist/index.js.LEGAL.txt +12 -12
- package/dist/styles.css +4416 -4020
- package/dist/types/components/index.d.ts +3 -2
- package/dist/types/components/silke-button/silke-dropdown-button.d.ts +8 -13
- package/dist/types/components/silke-card/silke-card-grid.d.ts +33 -1
- package/dist/types/components/silke-command-text-field/image-utils.d.ts +20 -0
- package/dist/types/components/silke-command-text-field/index.d.ts +4 -0
- package/dist/types/components/silke-command-text-field/silke-command-parser.d.ts +3 -0
- package/dist/types/components/silke-command-text-field/silke-command-parser.spec.d.ts +1 -0
- package/dist/types/components/silke-command-text-field/silke-command-text-field.d.ts +46 -0
- package/dist/types/components/silke-command-text-field/utils.d.ts +61 -0
- package/dist/types/components/silke-command-text-field/utils.spec.d.ts +1 -0
- package/dist/types/components/silke-form-schema/silke-schema-fields.d.ts +1 -0
- package/dist/types/components/silke-image/silke-image.d.ts +2 -1
- package/dist/types/components/silke-list/index.d.ts +1 -0
- package/dist/types/components/silke-list/silke-list-item.d.ts +24 -6
- package/dist/types/components/silke-list/silke-list.d.ts +9 -9
- package/dist/types/components/silke-list/types.d.ts +19 -0
- package/dist/types/components/silke-list/utils.d.ts +3 -0
- package/dist/types/components/silke-navigation-link/silke-navigation-link.d.ts +1 -0
- package/dist/types/components/silke-overflow-menu/silke-overflow-menu.d.ts +6 -1
- package/dist/types/components/silke-popover-native/silke-popover-native.d.ts +3 -1
- package/dist/types/components/silke-shortcut-button/index.d.ts +1 -0
- package/dist/types/components/silke-shortcut-button/silke-shortcut-button.d.ts +15 -0
- package/dist/types/components/silke-tag/silke-tag.d.ts +1 -1
- package/dist/types/icons.d.ts +30 -0
- package/jest.config.js +2 -3
- package/package.json +7 -2
- package/src/_variables.scss +125 -129
- package/src/components/index.ts +3 -2
- package/src/components/silke-action-box/silke-action-box.scss +2 -3
- package/src/components/silke-alert-banner/silke-alert-banner.scss +9 -10
- package/src/components/silke-autocomplete-field/autocomplete-item.tsx +2 -2
- package/src/components/silke-autocomplete-field/silke-autocomplete-field.scss +18 -12
- package/src/components/silke-autocomplete-field/silke-autocomplete-popup-native.tsx +3 -2
- package/src/components/silke-autocomplete-field/silke-autocomplete-popup.tsx +63 -44
- package/src/components/silke-box/silke-box.mdx +321 -21
- package/src/components/silke-box/silke-box.scss +5 -5
- package/src/components/silke-breadcrumbs/silke-breadcrumb.mdx +147 -9
- package/src/components/silke-breadcrumbs/silke-breadcrumb.scss +3 -3
- package/src/components/silke-button/silke-big-button.scss +1 -1
- package/src/components/silke-button/silke-button.scss +24 -15
- package/src/components/silke-button/silke-dropdown-button.mdx +67 -0
- package/src/components/silke-button/silke-dropdown-button.tsx +40 -122
- package/src/components/silke-card/silke-card-grid.tsx +5 -3
- package/src/components/silke-card/silke-card.scss +8 -7
- package/src/components/silke-card/silke-card.tsx +7 -1
- package/src/components/silke-checkbox/silke-checkbox.mdx +139 -14
- package/src/components/silke-checkbox/silke-checkbox.scss +11 -11
- package/src/components/silke-color-picker/color-picker.scss +8 -8
- package/src/components/silke-color-swatches/silke-color-swatches.mdx +130 -0
- package/src/components/silke-command-text-field/image-utils.ts +71 -0
- package/src/components/silke-command-text-field/index.ts +12 -0
- package/src/components/silke-command-text-field/silke-command-parser.spec.ts +89 -0
- package/src/components/silke-command-text-field/silke-command-parser.ts +47 -0
- package/src/components/silke-command-text-field/silke-command-text-field.mdx +301 -0
- package/src/components/silke-command-text-field/silke-command-text-field.module.scss +119 -0
- package/src/components/silke-command-text-field/silke-command-text-field.tsx +665 -0
- package/src/components/silke-command-text-field/utils.spec.ts +366 -0
- package/src/components/silke-command-text-field/utils.ts +287 -0
- package/src/components/silke-conditions-input/silke-conditions-input.scss +4 -4
- package/src/components/silke-content-column/silke-content-column.scss +1 -1
- package/src/components/silke-context-menu/silke-context-menu.scss +3 -4
- package/src/components/silke-context-menu/silke-context-menu.tsx +1 -1
- package/src/components/silke-css-number-field/silke-css-number-field.scss +14 -12
- package/src/components/silke-divider/silke-divider.mdx +154 -32
- package/src/components/silke-divider/silke-divider.scss +3 -2
- package/src/components/silke-drawer/silke-drawer.scss +6 -2
- package/src/components/silke-form/silke-form.mdx +254 -27
- package/src/components/silke-form-schema/fields/array-field-inline.tsx +1 -0
- package/src/components/silke-form-schema/fields/array-field-modal.tsx +1 -0
- package/src/components/silke-form-schema/fields/styles.scss +34 -35
- package/src/components/silke-form-schema/silke-schema-fields.tsx +4 -3
- package/src/components/silke-gradient-picker/silke-gradient-picker.module.scss +2 -2
- package/src/components/silke-icon/silke-icon.mdx +212 -8
- package/src/components/silke-icon/silke-icon.scss +10 -2
- package/src/components/silke-icon/silke-icon.tsx +1 -0
- package/src/components/silke-icon/silke-stacked-icon.scss +42 -45
- package/src/components/silke-icon-browser/silke-icon-browser.mdx +143 -0
- package/src/components/silke-image/silke-image-color-backdrop.scss +6 -6
- package/src/components/silke-image/silke-image.mdx +189 -41
- package/src/components/silke-image/silke-image.scss +3 -3
- package/src/components/silke-image/silke-image.tsx +14 -1
- package/src/components/silke-link/silke-link.scss +3 -5
- package/src/components/silke-list/index.ts +1 -0
- package/src/components/silke-list/silke-list-item.mdx +83 -0
- package/src/components/silke-list/silke-list-item.scss +119 -0
- package/src/components/silke-list/silke-list-item.tsx +137 -12
- package/src/components/silke-list/silke-list.mdx +108 -13
- package/src/components/silke-list/silke-list.scss +8 -15
- package/src/components/silke-list/silke-list.tsx +63 -9
- package/src/components/silke-list/types.ts +22 -0
- package/src/components/silke-list/utils.ts +24 -0
- package/src/components/silke-loader/silke-loader.mdx +139 -5
- package/src/components/silke-loader/silke-loader.scss +1 -1
- package/src/components/silke-modal/silke-modal.scss +9 -9
- package/src/components/silke-navigation-link/silke-navigation-link.mdx +27 -2
- package/src/components/silke-navigation-link/silke-navigation-link.scss +34 -40
- package/src/components/silke-navigation-link/silke-navigation-link.tsx +7 -6
- package/src/components/silke-overflow-menu/silke-overflow-menu.mdx +228 -31
- package/src/components/silke-overflow-menu/silke-overflow-menu.scss +8 -8
- package/src/components/silke-overflow-menu/silke-overflow-menu.tsx +14 -8
- package/src/components/silke-popover/silke-popover.scss +5 -5
- package/src/components/silke-popover-native/silke-popover-native.scss +93 -78
- package/src/components/silke-popover-native/silke-popover-native.tsx +4 -0
- package/src/components/silke-popover-native/use-popover-positioning.ts +1 -3
- package/src/components/silke-progress-indicator/silke-progress-indicator.scss +1 -1
- package/src/components/silke-radio-button/silke-radio-button.scss +18 -11
- package/src/components/silke-search-field/silke-search-field.mdx +161 -7
- package/src/components/silke-shortcut-button/index.ts +1 -0
- package/src/components/silke-shortcut-button/silke-shortcut-button.mdx +89 -0
- package/src/components/silke-shortcut-button/silke-shortcut-button.scss +145 -0
- package/src/components/silke-shortcut-button/silke-shortcut-button.tsx +55 -0
- package/src/components/silke-skeleton/silke-skeleton.mdx +109 -0
- package/src/components/silke-skeleton/silke-skeleton.scss +1 -1
- package/src/components/silke-slider/silke-slider.module.scss +19 -19
- package/src/components/silke-sortable-list/silke-nested-sortable-list.scss +3 -3
- package/src/components/silke-sortable-list/silke-sortable-list.scss +4 -5
- package/src/components/silke-table/silke-table.scss +1 -1
- package/src/components/silke-tabs/silke-tabs.scss +3 -3
- package/src/components/silke-tag/silke-tag.mdx +179 -43
- package/src/components/silke-tag/silke-tag.scss +49 -12
- package/src/components/silke-tag/silke-tag.tsx +17 -7
- package/src/components/silke-text/silke-text.scss +6 -4
- package/src/components/silke-text/silke-title.scss +7 -14
- package/src/components/silke-text-field/silke-text-field.scss +9 -9
- package/src/components/silke-text-field/silke-text-field.tsx +1 -1
- package/src/components/silke-tile/silke-tile.scss +7 -3
- package/src/components/silke-toast-notification/silke-toast-notification.scss +4 -5
- package/src/components/silke-toggle/silke-toggle.mdx +163 -33
- package/src/components/silke-toggle/silke-toggle.scss +4 -4
- package/src/components/silke-toolbar/silke-toolbar.scss +1 -1
- package/src/components/silke-tooltip/silke-shortcuts.tsx +3 -3
- package/src/components/silke-tooltip/silke-tooltip.scss +11 -16
- package/src/components/silke-variables-wrapper/silke-variables-wrapper.scss +9 -7
- package/src/components/silke-virtual/silke-virtual.mdx +161 -0
- package/src/components/silke-virtual/silke-virtual.scss +8 -8
- package/src/icons.tsx +43 -1
- package/src/styles/core.scss +42 -45
- package/src/styles/math.scss +66 -66
- package/tsconfig.build.json +2 -6
- package/tsconfig.build.tsbuildinfo +1 -1
- package/tsconfig.json +3 -14
- package/dist/types/components/silke-action-list/index.d.ts +0 -1
- package/dist/types/components/silke-action-list/silke-action-list.d.ts +0 -11
- package/dist/types/components/silke-list-card/index.d.ts +0 -1
- package/dist/types/components/silke-list-card/silke-list-card.d.ts +0 -14
- package/src/components/silke-action-list/index.ts +0 -1
- package/src/components/silke-action-list/silke-action-list.mdx +0 -48
- package/src/components/silke-action-list/silke-action-list.scss +0 -21
- package/src/components/silke-action-list/silke-action-list.tsx +0 -85
- package/src/components/silke-list-card/index.ts +0 -1
- package/src/components/silke-list-card/silke-list-card.mdx +0 -46
- package/src/components/silke-list-card/silke-list-card.scss +0 -57
- package/src/components/silke-list-card/silke-list-card.tsx +0 -63
|
@@ -1,51 +1,181 @@
|
|
|
1
|
-
#
|
|
1
|
+
# SilkeToggle
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A switch component for toggling boolean values on and off. Use toggles for settings that take effect immediately without requiring a save action.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **On/Off states**: Clear visual feedback for boolean values
|
|
8
|
+
- **Label support**: Display label and help text
|
|
9
|
+
- **Size variants**: Normal and small sizes
|
|
10
|
+
- **Form integration**: Works with SilkeForm
|
|
11
|
+
- **Invert mode**: Flip the visual state
|
|
12
|
+
- **Validation**: Built-in required validation
|
|
13
|
+
|
|
14
|
+
## Basic Usage
|
|
15
|
+
|
|
16
|
+
```js
|
|
17
|
+
const [enabled, setEnabled] = React.useState(false);
|
|
18
|
+
|
|
19
|
+
<SilkeToggle value={enabled} onChange={setEnabled} />;
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## With Label
|
|
23
|
+
|
|
24
|
+
```js
|
|
25
|
+
const [enabled, setEnabled] = React.useState(true);
|
|
26
|
+
|
|
27
|
+
<SilkeToggle label="Enable notifications" value={enabled} onChange={setEnabled} />;
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## With Help Text
|
|
31
|
+
|
|
32
|
+
Provide additional context with the `help` prop:
|
|
4
33
|
|
|
5
34
|
```js
|
|
6
|
-
const [
|
|
7
|
-
|
|
35
|
+
const [enabled, setEnabled] = React.useState(false);
|
|
36
|
+
|
|
37
|
+
<SilkeToggle
|
|
38
|
+
label="Dark mode"
|
|
39
|
+
help="Enable dark theme for the application"
|
|
40
|
+
value={enabled}
|
|
41
|
+
onChange={setEnabled}
|
|
42
|
+
/>;
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## States
|
|
8
46
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
47
|
+
```js
|
|
48
|
+
const [on, setOn] = React.useState(true);
|
|
49
|
+
const [off, setOff] = React.useState(false);
|
|
50
|
+
|
|
51
|
+
<SilkeBox column gap="s">
|
|
52
|
+
<SilkeToggle label="Toggle ON" value={on} onChange={setOn} />
|
|
53
|
+
<SilkeToggle label="Toggle OFF" value={off} onChange={setOff} />
|
|
54
|
+
</SilkeBox>;
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Size Variants
|
|
58
|
+
|
|
59
|
+
Use `small` for a compact toggle:
|
|
60
|
+
|
|
61
|
+
```js
|
|
62
|
+
const [normal, setNormal] = React.useState(true);
|
|
63
|
+
const [small, setSmall] = React.useState(true);
|
|
64
|
+
|
|
65
|
+
<SilkeBox column gap="m">
|
|
66
|
+
<SilkeToggle label="Normal size toggle" value={normal} onChange={setNormal} />
|
|
67
|
+
<SilkeToggle small label="Small size toggle" value={small} onChange={setSmall} />
|
|
68
|
+
</SilkeBox>;
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Disabled State
|
|
72
|
+
|
|
73
|
+
```js
|
|
74
|
+
<SilkeBox column gap="s">
|
|
75
|
+
<SilkeToggle disabled label="Disabled (ON)" value={true} onChange={() => {}} />
|
|
76
|
+
<SilkeToggle disabled label="Disabled (OFF)" value={false} onChange={() => {}} />
|
|
77
|
+
<SilkeToggle disabled small label="Disabled small (ON)" value={true} onChange={() => {}} />
|
|
78
|
+
<SilkeToggle disabled small label="Disabled small (OFF)" value={false} onChange={() => {}} />
|
|
79
|
+
</SilkeBox>
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Required Validation
|
|
83
|
+
|
|
84
|
+
Show error when required toggle is off:
|
|
85
|
+
|
|
86
|
+
```js
|
|
87
|
+
const [agreed, setAgreed] = React.useState(false);
|
|
88
|
+
|
|
89
|
+
<SilkeBox column gap="s">
|
|
90
|
+
<SilkeToggle required label="I agree to the terms" value={agreed} onChange={setAgreed} />
|
|
91
|
+
<SilkeText size="s" color={agreed ? 'success-50' : 'error-50'}>
|
|
92
|
+
{agreed ? 'Thank you for agreeing' : 'You must agree to continue'}
|
|
93
|
+
</SilkeText>
|
|
94
|
+
</SilkeBox>;
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Inverted Mode
|
|
98
|
+
|
|
99
|
+
Use `invert` to flip the visual state (toggle appears ON when value is false):
|
|
100
|
+
|
|
101
|
+
```js
|
|
102
|
+
const [disabled, setDisabled] = React.useState(false);
|
|
103
|
+
|
|
104
|
+
<SilkeBox column gap="s">
|
|
105
|
+
<SilkeToggle invert label="Disable feature" help="When on, this feature is disabled" value={disabled} onChange={setDisabled} />
|
|
106
|
+
<SilkeText size="s">Feature is: {disabled ? 'DISABLED' : 'ENABLED'}</SilkeText>
|
|
107
|
+
</SilkeBox>;
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Form Integration
|
|
111
|
+
|
|
112
|
+
Use within SilkeForm:
|
|
113
|
+
|
|
114
|
+
```js
|
|
115
|
+
const [settings, setSettings] = React.useState({
|
|
116
|
+
notifications: true,
|
|
117
|
+
autoSave: false,
|
|
118
|
+
darkMode: false,
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
<SilkeForm value={settings} onChange={setSettings}>
|
|
122
|
+
<SilkeBox column gap="m">
|
|
123
|
+
<SilkeToggle name="notifications" label="Push notifications" />
|
|
124
|
+
<SilkeToggle name="autoSave" label="Auto-save" help="Automatically save changes" />
|
|
125
|
+
<SilkeToggle name="darkMode" label="Dark mode" />
|
|
12
126
|
</SilkeBox>
|
|
13
|
-
|
|
14
|
-
<SilkeToggle small label="Tiny toggle, tiny text" value={checked} onChange={setChecked} />
|
|
15
|
-
</>;
|
|
127
|
+
</SilkeForm>;
|
|
16
128
|
```
|
|
17
129
|
|
|
18
|
-
##
|
|
130
|
+
## Settings Panel Example
|
|
19
131
|
|
|
20
132
|
```js
|
|
21
|
-
const [
|
|
133
|
+
const [settings, setSettings] = React.useState({
|
|
134
|
+
emailNotifications: true,
|
|
135
|
+
smsNotifications: false,
|
|
136
|
+
marketingEmails: false,
|
|
137
|
+
twoFactor: true,
|
|
138
|
+
});
|
|
22
139
|
|
|
23
|
-
|
|
24
|
-
<
|
|
140
|
+
<SilkeBox column gap="m" style={{ maxWidth: 400 }}>
|
|
141
|
+
<SilkeText kind="title" size="s">Notification Settings</SilkeText>
|
|
142
|
+
<SilkeToggle
|
|
143
|
+
label="Email notifications"
|
|
144
|
+
help="Receive updates via email"
|
|
145
|
+
value={settings.emailNotifications}
|
|
146
|
+
onChange={(v) => setSettings({ ...settings, emailNotifications: v })}
|
|
147
|
+
/>
|
|
25
148
|
<SilkeToggle
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
onChange={setChecked}
|
|
149
|
+
label="SMS notifications"
|
|
150
|
+
help="Receive updates via text message"
|
|
151
|
+
value={settings.smsNotifications}
|
|
152
|
+
onChange={(v) => setSettings({ ...settings, smsNotifications: v })}
|
|
31
153
|
/>
|
|
32
|
-
<
|
|
154
|
+
<SilkeDivider space="s" />
|
|
155
|
+
<SilkeText kind="title" size="s">Security</SilkeText>
|
|
33
156
|
<SilkeToggle
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
onChange={setChecked}
|
|
157
|
+
label="Two-factor authentication"
|
|
158
|
+
help="Require code when signing in"
|
|
159
|
+
value={settings.twoFactor}
|
|
160
|
+
onChange={(v) => setSettings({ ...settings, twoFactor: v })}
|
|
39
161
|
/>
|
|
40
|
-
|
|
162
|
+
</SilkeBox>;
|
|
41
163
|
```
|
|
42
164
|
|
|
43
|
-
##
|
|
165
|
+
## Props
|
|
44
166
|
|
|
45
|
-
|
|
46
|
-
|
|
167
|
+
| Prop | Type | Default | Description |
|
|
168
|
+
| ---------- | -------------------------- | ------- | ---------------------------------------- |
|
|
169
|
+
| `value` | `boolean` | - | Current toggle state |
|
|
170
|
+
| `onChange` | `(value: boolean) => void` | - | Called when toggle is switched |
|
|
171
|
+
| `label` | `string` | - | Label text |
|
|
172
|
+
| `help` | `React.ReactNode` | - | Help text displayed below label |
|
|
173
|
+
| `name` | `string` | - | Field name for form integration |
|
|
174
|
+
| `small` | `boolean` | `false` | Use smaller toggle size |
|
|
175
|
+
| `disabled` | `boolean` | `false` | Disable the toggle |
|
|
176
|
+
| `readOnly` | `boolean` | `false` | Prevent changes |
|
|
177
|
+
| `required` | `boolean` | `false` | Mark as required (shows error if false) |
|
|
178
|
+
| `invert` | `boolean` | `false` | Invert visual state (ON when false) |
|
|
179
|
+
| `error` | `string` | - | Error message to display |
|
|
47
180
|
|
|
48
|
-
|
|
49
|
-
<SilkeToggle value={checked} onChange={setChecked} />
|
|
50
|
-
</>;
|
|
51
|
-
```
|
|
181
|
+
Also accepts standard HTML input attributes and form field props.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
@use
|
|
2
|
-
@use
|
|
1
|
+
@use '../../variables' as *;
|
|
2
|
+
@use 'sass:math';
|
|
3
3
|
|
|
4
4
|
$bg-off: var(--color-neutral-30);
|
|
5
5
|
$bg-on: var(--color-accent-30);
|
|
@@ -43,7 +43,7 @@ $bg-on: var(--color-accent-30);
|
|
|
43
43
|
transition: background-color 100ms ease;
|
|
44
44
|
|
|
45
45
|
&::after {
|
|
46
|
-
content:
|
|
46
|
+
content: '';
|
|
47
47
|
display: block;
|
|
48
48
|
width: calc(50% - #{$space-xxs});
|
|
49
49
|
height: 100%;
|
|
@@ -64,7 +64,7 @@ $bg-on: var(--color-accent-30);
|
|
|
64
64
|
.disabled {
|
|
65
65
|
cursor: not-allowed;
|
|
66
66
|
pointer-events: none;
|
|
67
|
-
|
|
67
|
+
|
|
68
68
|
.switch {
|
|
69
69
|
background: var(--color-neutral-30);
|
|
70
70
|
}
|
|
@@ -33,11 +33,11 @@ export const SilkeShortcuts = ({
|
|
|
33
33
|
{Keyboard.getFormatted(s).map((keys, i) =>
|
|
34
34
|
keys
|
|
35
35
|
.split(' ')
|
|
36
|
-
.map((f) =>
|
|
36
|
+
.map((f, index) =>
|
|
37
37
|
isShortcutIcon(f) ? (
|
|
38
|
-
<SilkeIcon icon={f as IconSymbol} key={i} />
|
|
38
|
+
<SilkeIcon icon={f as IconSymbol} key={i + index} />
|
|
39
39
|
) : (
|
|
40
|
-
<span key={i}>{f}</span>
|
|
40
|
+
<span key={i + index}>{f}</span>
|
|
41
41
|
),
|
|
42
42
|
),
|
|
43
43
|
)}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
@use
|
|
1
|
+
@use '../../variables' as *;
|
|
2
2
|
|
|
3
|
-
$border-color: rgba(
|
|
4
|
-
var(--color-neutral-60-rgb),
|
|
5
|
-
var(--opacity-level-light)
|
|
6
|
-
);
|
|
3
|
+
$border-color: rgba(var(--color-neutral-60-rgb), var(--opacity-level-light));
|
|
7
4
|
.root {
|
|
8
5
|
position: relative;
|
|
9
6
|
filter: var(--shadow-level-4);
|
|
@@ -52,7 +49,7 @@ $border-color: rgba(
|
|
|
52
49
|
.definitionTooltip:not(.noBorder) {
|
|
53
50
|
border-bottom: 1px dotted var(--color-accent-40);
|
|
54
51
|
|
|
55
|
-
&:hover{
|
|
52
|
+
&:hover {
|
|
56
53
|
border-bottom-style: solid;
|
|
57
54
|
}
|
|
58
55
|
}
|
|
@@ -69,34 +66,32 @@ $border-color: rgba(
|
|
|
69
66
|
line-height: 14px;
|
|
70
67
|
font-weight: 300;
|
|
71
68
|
}
|
|
72
|
-
|
|
73
69
|
}
|
|
74
70
|
|
|
75
|
-
|
|
76
|
-
.tiny{
|
|
71
|
+
.tiny {
|
|
77
72
|
width: 192px;
|
|
78
|
-
.img{
|
|
73
|
+
.img {
|
|
79
74
|
aspect-ratio: 192/120;
|
|
80
75
|
}
|
|
81
76
|
}
|
|
82
77
|
|
|
83
|
-
.small{
|
|
78
|
+
.small {
|
|
84
79
|
width: 256px;
|
|
85
|
-
.img{
|
|
80
|
+
.img {
|
|
86
81
|
aspect-ratio: 256/160;
|
|
87
82
|
}
|
|
88
83
|
}
|
|
89
84
|
|
|
90
|
-
.base{
|
|
85
|
+
.base {
|
|
91
86
|
width: 320px;
|
|
92
|
-
.img{
|
|
87
|
+
.img {
|
|
93
88
|
aspect-ratio: 320/200;
|
|
94
89
|
}
|
|
95
90
|
}
|
|
96
91
|
|
|
97
|
-
.large{
|
|
92
|
+
.large {
|
|
98
93
|
width: 384px;
|
|
99
|
-
.img{
|
|
94
|
+
.img {
|
|
100
95
|
aspect-ratio: 384/240;
|
|
101
96
|
}
|
|
102
97
|
}
|
|
@@ -7,18 +7,18 @@
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
// Style border of wrapped children when open
|
|
10
|
-
&[data-open=
|
|
10
|
+
&[data-open='true'] *::after {
|
|
11
11
|
--current-border-color: var(--color-support-tertiary-40) !important;
|
|
12
12
|
--text-field-border-color: var(--color-support-tertiary-40) !important;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
// Style border of children when hovered
|
|
16
|
-
&[data-is-variable=
|
|
16
|
+
&[data-is-variable='true']:hover *::after {
|
|
17
17
|
--current-border-color: var(--color-support-tertiary-40) !important;
|
|
18
18
|
--text-field-border-color: var(--color-support-tertiary-40) !important;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
&[data-full-width=
|
|
21
|
+
&[data-full-width='true'] {
|
|
22
22
|
width: 100%;
|
|
23
23
|
}
|
|
24
24
|
}
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
|
|
36
36
|
&:after,
|
|
37
37
|
&:before {
|
|
38
|
-
content:
|
|
38
|
+
content: '';
|
|
39
39
|
position: absolute;
|
|
40
40
|
width: 12px;
|
|
41
41
|
height: 12px;
|
|
@@ -51,7 +51,9 @@
|
|
|
51
51
|
&:before {
|
|
52
52
|
transform: scale(0);
|
|
53
53
|
transform-origin: center center;
|
|
54
|
-
transition:
|
|
54
|
+
transition:
|
|
55
|
+
opacity 0.2s ease,
|
|
56
|
+
transform 0.2s ease;
|
|
55
57
|
}
|
|
56
58
|
&:after {
|
|
57
59
|
content: attr(data-icon);
|
|
@@ -63,8 +65,8 @@
|
|
|
63
65
|
background: var(--color-support-tertiary-40);
|
|
64
66
|
transition: opacity 0.2s ease;
|
|
65
67
|
}
|
|
66
|
-
&:hover:after
|
|
68
|
+
&:hover:after {
|
|
67
69
|
transform: scale(1.2);
|
|
68
70
|
opacity: 1;
|
|
69
71
|
}
|
|
70
|
-
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
# SilkeVirtualGrid
|
|
2
|
+
|
|
3
|
+
A high-performance virtualized grid component that only renders items visible in the viewport. Use this for displaying large lists or grids with thousands of items without performance degradation.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Virtualized rendering**: Only renders visible rows using IntersectionObserver
|
|
8
|
+
- **Automatic column calculation**: Computes columns based on container width and cell size
|
|
9
|
+
- **Responsive layout**: Recalculates on resize
|
|
10
|
+
- **Minimal DOM nodes**: Keeps DOM size small for massive datasets
|
|
11
|
+
- **Custom cell sizes**: Configure width and height per cell
|
|
12
|
+
- **Row attributes**: Attach custom attributes to individual rows
|
|
13
|
+
|
|
14
|
+
## Basic Usage
|
|
15
|
+
|
|
16
|
+
```js
|
|
17
|
+
const items = Array.from({ length: 100 }, (_, i) => ({ id: i, name: `Item ${i}` }));
|
|
18
|
+
|
|
19
|
+
<SilkeVirtualGrid items={items} cell={[100, 40]}>
|
|
20
|
+
{(item) => (
|
|
21
|
+
<SilkeBox key={item.id} pad="s" style={{ border: '1px solid var(--color-neutral-20)' }}>
|
|
22
|
+
<SilkeText>{item.name}</SilkeText>
|
|
23
|
+
</SilkeBox>
|
|
24
|
+
)}
|
|
25
|
+
</SilkeVirtualGrid>;
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Icon Grid
|
|
29
|
+
|
|
30
|
+
Display a large grid of icons efficiently:
|
|
31
|
+
|
|
32
|
+
```js
|
|
33
|
+
const icons = Array.from({ length: 200 }, (_, i) => `icon-${i}`);
|
|
34
|
+
|
|
35
|
+
<SilkeBox style={{ height: 300, overflow: 'auto' }}>
|
|
36
|
+
<SilkeVirtualGrid items={icons} cell={[48, 48]}>
|
|
37
|
+
{(icon, index) => (
|
|
38
|
+
<SilkeBox key={index} size="base" vAlign="center" hAlign="center">
|
|
39
|
+
<SilkeIcon icon="star" />
|
|
40
|
+
</SilkeBox>
|
|
41
|
+
)}
|
|
42
|
+
</SilkeVirtualGrid>
|
|
43
|
+
</SilkeBox>;
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Large Dataset
|
|
47
|
+
|
|
48
|
+
Handle thousands of items with smooth scrolling:
|
|
49
|
+
|
|
50
|
+
```js
|
|
51
|
+
const items = Array.from({ length: 5000 }, (_, i) => ({
|
|
52
|
+
id: i,
|
|
53
|
+
color: `hsl(${(i * 7) % 360}, 70%, 60%)`,
|
|
54
|
+
}));
|
|
55
|
+
|
|
56
|
+
<SilkeBox style={{ height: 400, overflow: 'auto' }}>
|
|
57
|
+
<SilkeVirtualGrid items={items} cell={[40, 40]}>
|
|
58
|
+
{(item) => (
|
|
59
|
+
<div
|
|
60
|
+
key={item.id}
|
|
61
|
+
style={{
|
|
62
|
+
width: 36,
|
|
63
|
+
height: 36,
|
|
64
|
+
background: item.color,
|
|
65
|
+
borderRadius: 4,
|
|
66
|
+
}}
|
|
67
|
+
/>
|
|
68
|
+
)}
|
|
69
|
+
</SilkeVirtualGrid>
|
|
70
|
+
</SilkeBox>;
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Custom Cell Dimensions
|
|
74
|
+
|
|
75
|
+
Adjust cell width and height for different layouts:
|
|
76
|
+
|
|
77
|
+
```js
|
|
78
|
+
const cards = Array.from({ length: 50 }, (_, i) => ({
|
|
79
|
+
id: i,
|
|
80
|
+
title: `Card ${i + 1}`,
|
|
81
|
+
description: `Description for card ${i + 1}`,
|
|
82
|
+
}));
|
|
83
|
+
|
|
84
|
+
<SilkeBox style={{ height: 400, overflow: 'auto' }}>
|
|
85
|
+
<SilkeVirtualGrid items={cards} cell={[200, 120]}>
|
|
86
|
+
{(card) => (
|
|
87
|
+
<SilkeCard key={card.id} style={{ width: 190, height: 110, margin: 4 }}>
|
|
88
|
+
<SilkeBox column pad="s" gap="xs">
|
|
89
|
+
<SilkeText weight="medium">{card.title}</SilkeText>
|
|
90
|
+
<SilkeText size="s" color="neutral-60">
|
|
91
|
+
{card.description}
|
|
92
|
+
</SilkeText>
|
|
93
|
+
</SilkeBox>
|
|
94
|
+
</SilkeCard>
|
|
95
|
+
)}
|
|
96
|
+
</SilkeVirtualGrid>
|
|
97
|
+
</SilkeBox>;
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## With Row Attributes
|
|
101
|
+
|
|
102
|
+
Add custom attributes or event handlers to rows:
|
|
103
|
+
|
|
104
|
+
```js
|
|
105
|
+
const items = Array.from({ length: 100 }, (_, i) => ({ id: i }));
|
|
106
|
+
|
|
107
|
+
<SilkeBox style={{ height: 300, overflow: 'auto' }}>
|
|
108
|
+
<SilkeVirtualGrid
|
|
109
|
+
items={items}
|
|
110
|
+
cell={[60, 60]}
|
|
111
|
+
rowAttrs={(rowIndex) => ({
|
|
112
|
+
'data-row': rowIndex,
|
|
113
|
+
style: { background: rowIndex % 2 === 0 ? 'var(--color-neutral-5)' : 'transparent' },
|
|
114
|
+
})}
|
|
115
|
+
>
|
|
116
|
+
{(item) => (
|
|
117
|
+
<SilkeBox key={item.id} size="base" vAlign="center" hAlign="center">
|
|
118
|
+
<SilkeText>{item.id}</SilkeText>
|
|
119
|
+
</SilkeBox>
|
|
120
|
+
)}
|
|
121
|
+
</SilkeVirtualGrid>
|
|
122
|
+
</SilkeBox>;
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Props
|
|
126
|
+
|
|
127
|
+
| Prop | Type | Default | Description |
|
|
128
|
+
| ---------- | ----------------------------------------------------------------- | ---------- | ----------------------------------------- |
|
|
129
|
+
| `items` | `T[]` | Required | Array of items to render |
|
|
130
|
+
| `children` | `(item: T, index: number) => React.ReactNode` | Required | Render function for each item |
|
|
131
|
+
| `cell` | `[width: number, height: number]` | `[32, 32]` | Cell dimensions in pixels |
|
|
132
|
+
| `rowAttrs` | `(rowIndex: number) => HTMLAttributes<HTMLDivElement>` | - | Custom attributes for each row |
|
|
133
|
+
| `className`| `string` | - | Additional CSS class name |
|
|
134
|
+
| `style` | `React.CSSProperties` | - | Inline styles |
|
|
135
|
+
|
|
136
|
+
Also accepts all standard HTML `div` attributes.
|
|
137
|
+
|
|
138
|
+
## How It Works
|
|
139
|
+
|
|
140
|
+
1. **Column calculation**: The grid measures its container width and divides by cell width to determine columns
|
|
141
|
+
2. **Row chunking**: Items are split into rows based on column count
|
|
142
|
+
3. **IntersectionObserver**: Each row observes its visibility in the viewport
|
|
143
|
+
4. **Lazy rendering**: Only visible rows render their children
|
|
144
|
+
5. **Global observer**: A single shared IntersectionObserver handles all rows efficiently
|
|
145
|
+
|
|
146
|
+
## Performance Characteristics
|
|
147
|
+
|
|
148
|
+
- **Ideal for**: Lists/grids with 1000+ items
|
|
149
|
+
- **DOM efficiency**: Only visible rows + their cells exist in DOM
|
|
150
|
+
- **Memory**: Single IntersectionObserver for all rows
|
|
151
|
+
- **Cleanup**: Listeners are properly removed on unmount
|
|
152
|
+
|
|
153
|
+
## CSS Variable
|
|
154
|
+
|
|
155
|
+
The grid sets `--cell-height` CSS variable which can be used for styling:
|
|
156
|
+
|
|
157
|
+
```css
|
|
158
|
+
.my-grid-item {
|
|
159
|
+
height: var(--cell-height);
|
|
160
|
+
}
|
|
161
|
+
```
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
@use '../../variables' as *;
|
|
2
|
-
.grid{
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
.grid {
|
|
3
|
+
--cell-height: 32px;
|
|
4
|
+
.row {
|
|
5
|
+
height: var(--cell-height);
|
|
6
|
+
display: flex;
|
|
7
|
+
justify-content: flex-start;
|
|
8
|
+
align-items: flex-start;
|
|
9
|
+
}
|
|
10
10
|
}
|