@vev/silke 1.1.6 → 1.1.8
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 +14 -0
- package/dist/index.js +34 -34
- 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-conditions-input/utils.d.ts +1 -1
- package/dist/types/components/silke-form-schema/fields/color-field.d.ts +3 -0
- package/dist/types/components/silke-form-schema/schema-utils.d.ts +6 -1
- 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 +32 -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 +672 -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 +9 -4
- package/src/components/silke-form-schema/fields/array-field.tsx +27 -3
- package/src/components/silke-form-schema/fields/color-field.tsx +36 -0
- package/src/components/silke-form-schema/fields/styles.scss +34 -35
- package/src/components/silke-form-schema/schema-utils.ts +27 -1
- package/src/components/silke-form-schema/silke-schema-field.tsx +2 -0
- 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 +50 -13
- 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 +58 -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,19 +1,144 @@
|
|
|
1
|
-
#
|
|
1
|
+
# SilkeCheckbox
|
|
2
|
+
|
|
3
|
+
A checkbox input component for boolean selections with label support, validation, and form integration.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Controlled value**: Works with React state
|
|
8
|
+
- **Form integration**: Works seamlessly with SilkeForm
|
|
9
|
+
- **Validation**: Built-in required validation with error display
|
|
10
|
+
- **Size variants**: Standard and small sizes
|
|
11
|
+
- **Accessibility**: Proper label association with generated IDs
|
|
12
|
+
|
|
13
|
+
## Basic Usage
|
|
2
14
|
|
|
3
15
|
```js
|
|
4
16
|
const [checked, setChecked] = React.useState(false);
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
/>
|
|
16
|
-
<
|
|
17
|
+
|
|
18
|
+
<SilkeCheckbox label="Accept terms" value={checked} onChange={setChecked} />;
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## States
|
|
22
|
+
|
|
23
|
+
```js
|
|
24
|
+
const [checked, setChecked] = React.useState(false);
|
|
25
|
+
|
|
26
|
+
<SilkeBox column gap="s">
|
|
27
|
+
<SilkeCheckbox label="Unchecked" value={false} onChange={() => {}} />
|
|
28
|
+
<SilkeCheckbox label="Checked" value={true} onChange={() => {}} />
|
|
29
|
+
<SilkeCheckbox label="Disabled unchecked" disabled value={false} onChange={() => {}} />
|
|
30
|
+
<SilkeCheckbox label="Disabled checked" disabled value={true} onChange={() => {}} />
|
|
31
|
+
</SilkeBox>;
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Size Variants
|
|
35
|
+
|
|
36
|
+
```js
|
|
37
|
+
const [value1, setValue1] = React.useState(false);
|
|
38
|
+
const [value2, setValue2] = React.useState(false);
|
|
39
|
+
|
|
40
|
+
<SilkeBox column gap="s">
|
|
41
|
+
<SilkeCheckbox label="Default size (base)" value={value1} onChange={setValue1} />
|
|
42
|
+
<SilkeCheckbox label="Small size" size="s" value={value2} onChange={setValue2} />
|
|
43
|
+
</SilkeBox>;
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Required Validation
|
|
47
|
+
|
|
48
|
+
Shows error when required checkbox is not checked:
|
|
49
|
+
|
|
50
|
+
```js
|
|
51
|
+
const [checked, setChecked] = React.useState(false);
|
|
52
|
+
|
|
53
|
+
<SilkeBox column gap="s">
|
|
54
|
+
<SilkeCheckbox label="I agree to the terms" required value={checked} onChange={setChecked} />
|
|
55
|
+
<SilkeText size="s" color={checked ? 'success-50' : 'neutral-60'}>
|
|
56
|
+
{checked ? 'Thanks for agreeing!' : 'You must check to continue'}
|
|
57
|
+
</SilkeText>
|
|
58
|
+
</SilkeBox>;
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Without Label
|
|
62
|
+
|
|
63
|
+
```js
|
|
64
|
+
const [checked, setChecked] = React.useState(false);
|
|
65
|
+
|
|
66
|
+
<SilkeBox gap="s" vAlign="center">
|
|
17
67
|
<SilkeCheckbox value={checked} onChange={setChecked} />
|
|
18
|
-
|
|
68
|
+
<SilkeText>Custom label next to checkbox</SilkeText>
|
|
69
|
+
</SilkeBox>;
|
|
19
70
|
```
|
|
71
|
+
|
|
72
|
+
## With Name (Auto-Label)
|
|
73
|
+
|
|
74
|
+
When `name` is provided without `label`, the name is used as the label:
|
|
75
|
+
|
|
76
|
+
```js
|
|
77
|
+
const [checked, setChecked] = React.useState(false);
|
|
78
|
+
|
|
79
|
+
<SilkeCheckbox name="newsletter" value={checked} onChange={setChecked} />;
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Form Integration
|
|
83
|
+
|
|
84
|
+
Use within SilkeForm for automatic form state management:
|
|
85
|
+
|
|
86
|
+
```js
|
|
87
|
+
const [formValue, setFormValue] = React.useState({
|
|
88
|
+
marketing: false,
|
|
89
|
+
analytics: true,
|
|
90
|
+
terms: false,
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
<SilkeForm value={formValue} onChange={(value) => setFormValue(value)}>
|
|
94
|
+
<SilkeBox column gap="s">
|
|
95
|
+
<SilkeCheckbox name="marketing" label="Receive marketing emails" />
|
|
96
|
+
<SilkeCheckbox name="analytics" label="Allow analytics tracking" />
|
|
97
|
+
<SilkeCheckbox name="terms" label="Accept terms and conditions" required />
|
|
98
|
+
</SilkeBox>
|
|
99
|
+
</SilkeForm>;
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Read-Only State
|
|
103
|
+
|
|
104
|
+
Prevent changes while showing current value:
|
|
105
|
+
|
|
106
|
+
```js
|
|
107
|
+
<SilkeBox column gap="s">
|
|
108
|
+
<SilkeCheckbox label="Read-only unchecked" readOnly value={false} />
|
|
109
|
+
<SilkeCheckbox label="Read-only checked" readOnly value={true} />
|
|
110
|
+
</SilkeBox>;
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Custom Error Message
|
|
114
|
+
|
|
115
|
+
Pass a custom error message:
|
|
116
|
+
|
|
117
|
+
```js
|
|
118
|
+
const [checked, setChecked] = React.useState(false);
|
|
119
|
+
|
|
120
|
+
<SilkeCheckbox
|
|
121
|
+
label="Enable feature"
|
|
122
|
+
value={checked}
|
|
123
|
+
onChange={setChecked}
|
|
124
|
+
error={!checked ? 'This feature must be enabled' : undefined}
|
|
125
|
+
/>;
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Props
|
|
129
|
+
|
|
130
|
+
| Prop | Type | Default | Description |
|
|
131
|
+
| ---------- | --------------------------- | ------- | ---------------------------------------- |
|
|
132
|
+
| `value` | `boolean` | - | Current checked state |
|
|
133
|
+
| `onChange` | `(value: boolean) => void` | - | Called when checkbox is toggled |
|
|
134
|
+
| `label` | `string` | - | Label text displayed next to checkbox |
|
|
135
|
+
| `name` | `string` | - | Field name (also used as label fallback) |
|
|
136
|
+
| `size` | `'s' \| 'base'` | `'base'`| Checkbox size |
|
|
137
|
+
| `disabled` | `boolean` | `false` | Disable the checkbox |
|
|
138
|
+
| `readOnly` | `boolean` | `false` | Prevent changes |
|
|
139
|
+
| `required` | `boolean` | `false` | Mark as required (shows error if false) |
|
|
140
|
+
| `error` | `string` | - | Custom error message to display |
|
|
141
|
+
| `id` | `string` | - | Custom ID (auto-generated if not set) |
|
|
142
|
+
| `style` | `React.CSSProperties` | - | Inline styles |
|
|
143
|
+
|
|
144
|
+
Also accepts standard HTML input attributes.
|
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
@use '../../variables' as *;
|
|
2
|
-
body{
|
|
3
|
-
--checkbox-size:
|
|
2
|
+
body {
|
|
3
|
+
--checkbox-size: #{$size-xs};
|
|
4
4
|
}
|
|
5
5
|
.container {
|
|
6
6
|
position: relative;
|
|
7
7
|
cursor: pointer;
|
|
8
8
|
user-select: none;
|
|
9
9
|
|
|
10
|
-
&.small{
|
|
11
|
-
--checkbox-size:
|
|
12
|
-
font-size
|
|
10
|
+
&.small {
|
|
11
|
+
--checkbox-size: 16px;
|
|
12
|
+
font-size: $font-small;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
&.disabled {
|
|
16
16
|
color: var(--color-neutral-100);
|
|
17
17
|
cursor: default;
|
|
18
18
|
|
|
19
|
-
input,
|
|
19
|
+
input,
|
|
20
|
+
.label {
|
|
20
21
|
cursor: default;
|
|
21
22
|
}
|
|
22
23
|
|
|
@@ -25,7 +26,7 @@ body{
|
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
.check {
|
|
28
|
-
border:1px solid var(--color-neutral-40);
|
|
29
|
+
border: 1px solid var(--color-neutral-40);
|
|
29
30
|
|
|
30
31
|
& > * {
|
|
31
32
|
color: var(--color-neutral-0);
|
|
@@ -47,7 +48,7 @@ body{
|
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
.checkmark {
|
|
50
|
-
display: none
|
|
51
|
+
display: none;
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
&:hover .check {
|
|
@@ -79,11 +80,11 @@ body{
|
|
|
79
80
|
display: block;
|
|
80
81
|
color: var(--color-neutral-100);
|
|
81
82
|
}
|
|
82
|
-
|
|
83
|
+
|
|
83
84
|
// Disabled state
|
|
84
85
|
|
|
85
86
|
input:disabled ~ .check {
|
|
86
|
-
background-color:var(--color-neutral-30);
|
|
87
|
+
background-color: var(--color-neutral-30);
|
|
87
88
|
border-color: var(--color-neutral-30);
|
|
88
89
|
.checkmark {
|
|
89
90
|
color: var(--color-neutral-50);
|
|
@@ -97,7 +98,6 @@ body{
|
|
|
97
98
|
input:checked:disabled ~ .check {
|
|
98
99
|
background-color: var(--color-neutral-30);
|
|
99
100
|
}
|
|
100
|
-
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
/* Create a custom checkbox */
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
2
1
|
:root {
|
|
3
|
-
--transparent-bg: url(
|
|
2
|
+
--transparent-bg: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAIElEQVQ4y2P4TwDcv38fL2YYNWBYGEBIASEwasCwMAAAv7rMLvozJBUAAAAASUVORK5CYII=');
|
|
4
3
|
}
|
|
5
4
|
.root {
|
|
6
5
|
max-width: 320px;
|
|
@@ -42,13 +41,14 @@
|
|
|
42
41
|
|
|
43
42
|
.colorDot {
|
|
44
43
|
cursor: grab;
|
|
45
|
-
transition:
|
|
44
|
+
transition:
|
|
45
|
+
width 0.2s,
|
|
46
|
+
height 0.2s,
|
|
47
|
+
box-shadow 0.2s;
|
|
46
48
|
position: absolute;
|
|
47
49
|
background: transparent;
|
|
48
|
-
border: 1px solid
|
|
49
|
-
|
|
50
|
-
box-shadow: 0 0 0 1px
|
|
51
|
-
rgba(var(--color-neutral-100-rgb), var(--opacity-level-semiopaque));
|
|
50
|
+
border: 1px solid rgba(var(--color-neutral-0-rgb), var(--opacity-level-semiopaque));
|
|
51
|
+
box-shadow: 0 0 0 1px rgba(var(--color-neutral-100-rgb), var(--opacity-level-semiopaque));
|
|
52
52
|
width: 15px;
|
|
53
53
|
height: 15px;
|
|
54
54
|
border-radius: 50%;
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
|
|
85
85
|
.handle {
|
|
86
86
|
background: var(--track-bg);
|
|
87
|
-
background-size:5000%, 5px;
|
|
87
|
+
background-size: 5000%, 5px;
|
|
88
88
|
background-position-x: calc(100% * var(--value));
|
|
89
89
|
border: 2px solid var(--color-neutral-100);
|
|
90
90
|
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# SilkeSwatches
|
|
2
|
+
|
|
3
|
+
A multi-mode color selection component that displays colors as swatches, palettes, or CSS variables. Use this for color pickers that need to show predefined colors, project palettes, or design system variables.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Three display modes**: Swatches, Palettes, and Variables
|
|
8
|
+
- **Gradient support**: Optionally include gradient swatches
|
|
9
|
+
- **Default colors**: Built-in white, black, and gradient swatches
|
|
10
|
+
- **Add/delete swatches**: Users can save and remove custom colors
|
|
11
|
+
- **CSS variable integration**: Works with project color variables
|
|
12
|
+
- **Mode persistence**: Remembers user's preferred view mode
|
|
13
|
+
|
|
14
|
+
## Basic Usage
|
|
15
|
+
|
|
16
|
+
```js
|
|
17
|
+
const [color, setColor] = React.useState('#6366f1');
|
|
18
|
+
|
|
19
|
+
<SilkeSwatches selected={color} onSelect={(value) => setColor(value)} />;
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## With Custom Swatches
|
|
23
|
+
|
|
24
|
+
Provide a list of custom color swatches:
|
|
25
|
+
|
|
26
|
+
```js
|
|
27
|
+
const [color, setColor] = React.useState('#ef4444');
|
|
28
|
+
const customSwatches = ['#ef4444', '#f97316', '#eab308', '#22c55e', '#3b82f6', '#8b5cf6', '#ec4899'];
|
|
29
|
+
|
|
30
|
+
<SilkeSwatches selected={color} swatches={customSwatches} onSelect={(value) => setColor(value)} />;
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## With Gradients
|
|
34
|
+
|
|
35
|
+
Enable gradient selection alongside solid colors:
|
|
36
|
+
|
|
37
|
+
```js
|
|
38
|
+
const [color, setColor] = React.useState('#6366f1');
|
|
39
|
+
|
|
40
|
+
<SilkeSwatches selected={color} gradient onSelect={(value, type) => setColor(value)} />;
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Swatches Only Mode
|
|
44
|
+
|
|
45
|
+
Hide palettes and variables to show only swatches:
|
|
46
|
+
|
|
47
|
+
```js
|
|
48
|
+
const [color, setColor] = React.useState('#22c55e');
|
|
49
|
+
|
|
50
|
+
<SilkeSwatches selected={color} hidePalettes hideVariables onSelect={(value) => setColor(value)} />;
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Palettes Only Mode
|
|
54
|
+
|
|
55
|
+
Show only color palettes:
|
|
56
|
+
|
|
57
|
+
```js
|
|
58
|
+
const [color, setColor] = React.useState('');
|
|
59
|
+
|
|
60
|
+
<SilkeSwatches selected={color} hideSwatches hideVariables mode="palettes" onSelect={(value) => setColor(value)} />;
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Handling Selection Types
|
|
64
|
+
|
|
65
|
+
The `onSelect` callback provides the color value and its type:
|
|
66
|
+
|
|
67
|
+
```js
|
|
68
|
+
const [color, setColor] = React.useState('#6366f1');
|
|
69
|
+
const [colorType, setColorType] = React.useState('color');
|
|
70
|
+
|
|
71
|
+
<SilkeBox column gap="s">
|
|
72
|
+
<SilkeSwatches
|
|
73
|
+
selected={color}
|
|
74
|
+
gradient
|
|
75
|
+
onSelect={(value, type) => {
|
|
76
|
+
setColor(value);
|
|
77
|
+
setColorType(type);
|
|
78
|
+
}}
|
|
79
|
+
/>
|
|
80
|
+
<SilkeText size="s">
|
|
81
|
+
Selected: {color} (type: {colorType})
|
|
82
|
+
</SilkeText>
|
|
83
|
+
</SilkeBox>;
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Props
|
|
87
|
+
|
|
88
|
+
| Prop | Type | Default | Description |
|
|
89
|
+
| --------------- | -------------------------------------------------------------------- | ------------ | ---------------------------------------------- |
|
|
90
|
+
| `selected` | `string` | Required | Currently selected color value |
|
|
91
|
+
| `onSelect` | `(color: string, type: 'color' \| 'gradient' \| 'variable') => void` | Required | Callback when a color is selected |
|
|
92
|
+
| `swatches` | `string[]` | - | Custom color swatches to display |
|
|
93
|
+
| `palettes` | `{ key: string; label: string; colors: string[] }[]` | - | Custom color palettes |
|
|
94
|
+
| `gradient` | `boolean` | `false` | Enable gradient swatch selection |
|
|
95
|
+
| `mode` | `'swatches' \| 'palettes' \| 'variables'` | `'swatches'` | Default display mode |
|
|
96
|
+
| `hidePalettes` | `boolean` | `false` | Hide palette mode |
|
|
97
|
+
| `hideSwatches` | `boolean` | `false` | Hide swatches mode |
|
|
98
|
+
| `hideVariables` | `boolean` | `false` | Hide variables mode |
|
|
99
|
+
| `type` | `'color' \| 'palette' \| 'gradient'` | - | Filter swatches by type |
|
|
100
|
+
|
|
101
|
+
## Types
|
|
102
|
+
|
|
103
|
+
```typescript
|
|
104
|
+
type SilkeSwatchType = 'color' | 'palette' | 'gradient';
|
|
105
|
+
type ModeType = 'swatches' | 'palettes' | 'variables';
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Default Swatches
|
|
109
|
+
|
|
110
|
+
The component includes these built-in swatches:
|
|
111
|
+
- White (`rgba(255, 255, 255, 1)`)
|
|
112
|
+
- Black (`rgba(0, 0, 0, 1)`)
|
|
113
|
+
- Three gradient presets (fade to black, fade to white, primary gradient)
|
|
114
|
+
|
|
115
|
+
## SilkeColorSwatchButton
|
|
116
|
+
|
|
117
|
+
Individual swatch button component used internally:
|
|
118
|
+
|
|
119
|
+
```js
|
|
120
|
+
<SilkeColorSwatchButton value="#6366f1" selected onClick={() => console.log('clicked')} />
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### SilkeColorSwatchButton Props
|
|
124
|
+
|
|
125
|
+
| Prop | Type | Default | Description |
|
|
126
|
+
| ---------- | -------------------------- | ------- | ------------------------------ |
|
|
127
|
+
| `value` | `string` | Required| Color value to display |
|
|
128
|
+
| `selected` | `boolean` | `false` | Whether swatch is selected |
|
|
129
|
+
|
|
130
|
+
Also accepts all `SilkeButton` props except `icon`, `color`, and `value`.
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { SilkeImageValue } from './utils';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Reads a File and converts it to a SilkeImageValue with base64 data.
|
|
5
|
+
* Returns a promise that resolves with the image value or null if reading fails.
|
|
6
|
+
*/
|
|
7
|
+
export function fileToImageValue(file: File): Promise<SilkeImageValue | null> {
|
|
8
|
+
return new Promise((resolve) => {
|
|
9
|
+
if (!file.type.startsWith('image/')) {
|
|
10
|
+
resolve(null);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const reader = new FileReader();
|
|
15
|
+
reader.onload = (event) => {
|
|
16
|
+
const result = event.target?.result;
|
|
17
|
+
if (typeof result === 'string') {
|
|
18
|
+
const [, base64Data] = result.split(',');
|
|
19
|
+
resolve({
|
|
20
|
+
type: 'image',
|
|
21
|
+
data: base64Data,
|
|
22
|
+
mimeType: file.type,
|
|
23
|
+
name: file.name || undefined,
|
|
24
|
+
});
|
|
25
|
+
} else {
|
|
26
|
+
resolve(null);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
reader.onerror = () => resolve(null);
|
|
30
|
+
reader.readAsDataURL(file);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Extracts the first image file from a ClipboardEvent.
|
|
36
|
+
* Returns the File or null if no image is found.
|
|
37
|
+
*/
|
|
38
|
+
export function getImageFromClipboard(e: React.ClipboardEvent): File | null {
|
|
39
|
+
const items = e.clipboardData?.items;
|
|
40
|
+
if (!items) return null;
|
|
41
|
+
|
|
42
|
+
for (const item of items) {
|
|
43
|
+
if (item.type.startsWith('image/')) {
|
|
44
|
+
return item.getAsFile();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Extracts the first image file from a DragEvent.
|
|
52
|
+
* Returns the File or null if no image is found.
|
|
53
|
+
*/
|
|
54
|
+
export function getImageFromDragEvent(e: DragEvent): File | null {
|
|
55
|
+
const files = e.dataTransfer?.files;
|
|
56
|
+
if (!files || files.length === 0) return null;
|
|
57
|
+
|
|
58
|
+
for (const file of files) {
|
|
59
|
+
if (file.type.startsWith('image/')) {
|
|
60
|
+
return file;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Generates a data URL from a SilkeImageValue for use in img src.
|
|
68
|
+
*/
|
|
69
|
+
export function imageValueToDataUrl(img: SilkeImageValue): string {
|
|
70
|
+
return `data:${img.mimeType};base64,${img.data}`;
|
|
71
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { fileToImageValue, imageValueToDataUrl } from './image-utils';
|
|
2
|
+
export { parseTextToSilkeCommands } from './silke-command-parser';
|
|
3
|
+
export * from './silke-command-text-field';
|
|
4
|
+
export {
|
|
5
|
+
SilkeCommand,
|
|
6
|
+
SilkeCommandTextFieldValue,
|
|
7
|
+
SilkeCommandType,
|
|
8
|
+
SilkeImageValue,
|
|
9
|
+
SilkeTextValue,
|
|
10
|
+
convertSilkeCommandsToString,
|
|
11
|
+
isImage,
|
|
12
|
+
} from './utils';
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { parseTextToSilkeCommands } from './silke-command-parser';
|
|
2
|
+
import { SilkeCommand, SilkeCommandType } from './utils';
|
|
3
|
+
|
|
4
|
+
const availableCommands: SilkeCommand[] = [
|
|
5
|
+
{ type: SilkeCommandType.MENTION, value: 'user' },
|
|
6
|
+
{ type: SilkeCommandType.ACTION, value: 'command' },
|
|
7
|
+
];
|
|
8
|
+
|
|
9
|
+
describe('parseTextToCommands', () => {
|
|
10
|
+
test('parses text with mentions and actions', () => {
|
|
11
|
+
const result = parseTextToSilkeCommands('Hello @user /command @partial', availableCommands);
|
|
12
|
+
expect(result).toEqual([
|
|
13
|
+
{ type: 'text', value: 'Hello ' },
|
|
14
|
+
{ type: '@', value: 'user' },
|
|
15
|
+
{ type: 'text', value: ' ' },
|
|
16
|
+
{ type: '/', value: 'command' },
|
|
17
|
+
{ type: 'text', value: ' ' },
|
|
18
|
+
{ partialMatch: true, type: '@', value: 'partial' },
|
|
19
|
+
]);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test('parses plain text without commands', () => {
|
|
23
|
+
const result = parseTextToSilkeCommands('Hello world', availableCommands);
|
|
24
|
+
expect(result).toEqual([{ type: 'text', value: 'Hello world' }]);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test('parses command at the start of text', () => {
|
|
28
|
+
const result = parseTextToSilkeCommands('@user hello', availableCommands);
|
|
29
|
+
expect(result).toEqual([
|
|
30
|
+
{ type: '@', value: 'user' },
|
|
31
|
+
{ type: 'text', value: ' hello' },
|
|
32
|
+
]);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('parses command at the end of text', () => {
|
|
36
|
+
const result = parseTextToSilkeCommands('hello @user', availableCommands);
|
|
37
|
+
expect(result).toEqual([
|
|
38
|
+
{ type: 'text', value: 'hello ' },
|
|
39
|
+
{ type: '@', value: 'user' },
|
|
40
|
+
]);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('parses multiple commands separated by space', () => {
|
|
44
|
+
const result = parseTextToSilkeCommands('@user @unknown /command', availableCommands);
|
|
45
|
+
expect(result).toEqual([
|
|
46
|
+
{ type: '@', value: 'user' },
|
|
47
|
+
{ type: 'text', value: ' ' },
|
|
48
|
+
{ partialMatch: true, type: '@', value: 'unknown' },
|
|
49
|
+
{ type: 'text', value: ' ' },
|
|
50
|
+
{ type: '/', value: 'command' },
|
|
51
|
+
]);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test('does not parse command without preceding space', () => {
|
|
55
|
+
const result = parseTextToSilkeCommands('hello@user email@test.com', availableCommands);
|
|
56
|
+
expect(result).toEqual([{ type: 'text', value: 'hello@user email@test.com' }]);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test('parses command with empty value', () => {
|
|
60
|
+
const result = parseTextToSilkeCommands('@ /command', availableCommands);
|
|
61
|
+
expect(result).toEqual([
|
|
62
|
+
{ partialMatch: true, type: '@', value: '' },
|
|
63
|
+
{ type: 'text', value: ' ' },
|
|
64
|
+
{ type: '/', value: 'command' },
|
|
65
|
+
]);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('handles empty text', () => {
|
|
69
|
+
const result = parseTextToSilkeCommands('', availableCommands);
|
|
70
|
+
expect(result).toEqual([]);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test('handles command only', () => {
|
|
74
|
+
const result = parseTextToSilkeCommands('@user', availableCommands);
|
|
75
|
+
expect(result).toEqual([{ type: '@', value: 'user' }]);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test('handles command with hyphens and underscores', () => {
|
|
79
|
+
const commands: SilkeCommand[] = [{ type: SilkeCommandType.MENTION, value: 'user-name_123' }];
|
|
80
|
+
const result = parseTextToSilkeCommands('@user-name_123', commands);
|
|
81
|
+
expect(result).toEqual([{ type: '@', value: 'user-name_123' }]);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test('is case insensitive for command values', () => {
|
|
85
|
+
const result = parseTextToSilkeCommands('@USER', availableCommands);
|
|
86
|
+
// Note: the regex is case insensitive, so @USER matches, but user !== USER
|
|
87
|
+
expect(result).toEqual([{ partialMatch: true, type: '@', value: 'USER' }]);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { SilkeCommand, SilkeCommandTextFieldValue, SilkeCommandType } from './utils';
|
|
2
|
+
|
|
3
|
+
/** Parse raw text into structured command values */
|
|
4
|
+
export function parseTextToSilkeCommands(
|
|
5
|
+
text: string,
|
|
6
|
+
availableCommands: SilkeCommand[],
|
|
7
|
+
): SilkeCommandTextFieldValue[] {
|
|
8
|
+
// Normalize non-breaking spaces to regular spaces
|
|
9
|
+
const normalizedText = text.replace(/\u00A0/g, ' ');
|
|
10
|
+
|
|
11
|
+
const result: SilkeCommandTextFieldValue[] = [];
|
|
12
|
+
let lastIndex = 0;
|
|
13
|
+
|
|
14
|
+
// Match @ or / at start of string or after whitespace, followed by alphanumeric, underscore, or hyphen
|
|
15
|
+
const commandRegexp = /(^|[\s])(@|\/)([a-z0-9_-]*)/gi;
|
|
16
|
+
let match: RegExpExecArray | null;
|
|
17
|
+
|
|
18
|
+
while ((match = commandRegexp.exec(normalizedText)) !== null) {
|
|
19
|
+
const [, prefix, type, value = ''] = match;
|
|
20
|
+
const commandStart = match.index + prefix.length;
|
|
21
|
+
|
|
22
|
+
// Add any text before this command (including the whitespace prefix)
|
|
23
|
+
if (commandStart > lastIndex) {
|
|
24
|
+
result.push({ type: 'text', value: normalizedText.slice(lastIndex, commandStart) });
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const commandType = type as SilkeCommandType;
|
|
28
|
+
const commandValue = value;
|
|
29
|
+
|
|
30
|
+
// Check if this is a complete command (exists in availableCommands)
|
|
31
|
+
const foundCommand = availableCommands.some(
|
|
32
|
+
(cmd) => cmd.type === commandType && cmd.value === commandValue,
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
const command: SilkeCommand = { type: commandType, value: commandValue };
|
|
36
|
+
if (!foundCommand) command.partialMatch = true;
|
|
37
|
+
result.push(command);
|
|
38
|
+
lastIndex = match.index + match[0].length;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Add any remaining text after the last command
|
|
42
|
+
if (lastIndex < normalizedText.length) {
|
|
43
|
+
result.push({ type: 'text', value: normalizedText.slice(lastIndex) });
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return result;
|
|
47
|
+
}
|