@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
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
# SilkeCommandTextField
|
|
2
|
+
|
|
3
|
+
A rich text input component that supports inline commands (mentions and actions) with autocomplete suggestions. Perfect for chat interfaces, command palettes, or any input that needs to reference users, actions, or other entities.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Mentions (`@`)**: Reference users, entities, or any mentionable items
|
|
8
|
+
- **Actions (`/`)**: Trigger commands or actions
|
|
9
|
+
- **Autocomplete**: Show suggestions as users type
|
|
10
|
+
- **Keyboard navigation**: Navigate and select suggestions with keyboard
|
|
11
|
+
- **Placeholder support**: Show placeholder text when empty
|
|
12
|
+
- **Disabled state**: Prevent editing when needed
|
|
13
|
+
- **XSS protection**: Safe HTML rendering of user input
|
|
14
|
+
|
|
15
|
+
## Basic Usage
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
const [value, setValue] = React.useState([]);
|
|
19
|
+
const availableCommands = [
|
|
20
|
+
{ type: SilkeCommandType.MENTION, value: 'john' },
|
|
21
|
+
{ type: SilkeCommandType.MENTION, value: 'jane' },
|
|
22
|
+
{ type: SilkeCommandType.ACTION, value: 'help' },
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
<SilkeCommandTextField
|
|
26
|
+
availableCommands={availableCommands}
|
|
27
|
+
onChange={setValue}
|
|
28
|
+
placeholder="Type @ to mention someone or / for commands..."
|
|
29
|
+
value={value}
|
|
30
|
+
/>;
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## With Autocomplete Suggestions
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
const [value, setValue] = React.useState([]);
|
|
37
|
+
const ref = React.useRef(null);
|
|
38
|
+
const [suggestions, setSuggestions] = React.useState([]);
|
|
39
|
+
|
|
40
|
+
const availableCommands = [
|
|
41
|
+
{ type: SilkeCommandType.MENTION, value: 'alice' },
|
|
42
|
+
{ type: SilkeCommandType.MENTION, value: 'bob' },
|
|
43
|
+
{ type: SilkeCommandType.MENTION, value: 'charlie' },
|
|
44
|
+
{ type: SilkeCommandType.ACTION, value: 'help' },
|
|
45
|
+
{ type: SilkeCommandType.ACTION, value: 'search' },
|
|
46
|
+
{ type: SilkeCommandType.ACTION, value: 'settings' },
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
<SilkeBox column gap="s">
|
|
50
|
+
<SilkeCommandTextField
|
|
51
|
+
autoFocus
|
|
52
|
+
availableCommands={availableCommands}
|
|
53
|
+
onChange={setValue}
|
|
54
|
+
onKeyDown={(e) => {
|
|
55
|
+
if (e.key === 'Enter' && suggestions.length > 0) {
|
|
56
|
+
e.preventDefault();
|
|
57
|
+
ref.current?.update(suggestions[0]);
|
|
58
|
+
}
|
|
59
|
+
}}
|
|
60
|
+
onSuggestions={setSuggestions}
|
|
61
|
+
placeholder="Type @ or / to see suggestions..."
|
|
62
|
+
ref={ref}
|
|
63
|
+
value={value}
|
|
64
|
+
/>
|
|
65
|
+
{suggestions.length > 0 && (
|
|
66
|
+
<SilkeBox
|
|
67
|
+
column
|
|
68
|
+
gap="xs"
|
|
69
|
+
style={{ background: 'var(--color-neutral-10)', padding: 8, borderRadius: 4 }}
|
|
70
|
+
>
|
|
71
|
+
<SilkeText size="s" weight="medium">
|
|
72
|
+
Suggestions:
|
|
73
|
+
</SilkeText>
|
|
74
|
+
{suggestions.map((suggestion) => (
|
|
75
|
+
<SilkeBox
|
|
76
|
+
key={suggestion.type + suggestion.value}
|
|
77
|
+
onClick={() => ref.current?.update(suggestion)}
|
|
78
|
+
style={{ cursor: 'pointer', padding: '4px 8px' }}
|
|
79
|
+
>
|
|
80
|
+
<SilkeText>
|
|
81
|
+
{suggestion.type}
|
|
82
|
+
{suggestion.value}
|
|
83
|
+
</SilkeText>
|
|
84
|
+
</SilkeBox>
|
|
85
|
+
))}
|
|
86
|
+
</SilkeBox>
|
|
87
|
+
)}
|
|
88
|
+
</SilkeBox>;
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## With Command Focus Tracking
|
|
92
|
+
|
|
93
|
+
Track which command the user is currently editing:
|
|
94
|
+
|
|
95
|
+
```js
|
|
96
|
+
const [value, setValue] = React.useState([]);
|
|
97
|
+
const [activeIndex, setActiveIndex] = React.useState(0);
|
|
98
|
+
const [activeCommand, setActiveCommand] = React.useState(null);
|
|
99
|
+
|
|
100
|
+
const availableCommands = [
|
|
101
|
+
{ type: SilkeCommandType.MENTION, value: 'user' },
|
|
102
|
+
{ type: SilkeCommandType.ACTION, value: 'run' },
|
|
103
|
+
];
|
|
104
|
+
|
|
105
|
+
<SilkeBox column gap="s">
|
|
106
|
+
<SilkeCommandTextField
|
|
107
|
+
availableCommands={availableCommands}
|
|
108
|
+
onChange={setValue}
|
|
109
|
+
onCommandFocus={(index, command) => {
|
|
110
|
+
setActiveIndex(index);
|
|
111
|
+
setActiveCommand(command);
|
|
112
|
+
}}
|
|
113
|
+
placeholder="Type something with @mentions..."
|
|
114
|
+
value={value}
|
|
115
|
+
/>
|
|
116
|
+
<SilkeBox gap="m">
|
|
117
|
+
<SilkeText size="s">Active index: {activeIndex}</SilkeText>
|
|
118
|
+
<SilkeText size="s">Active type: {activeCommand?.type || 'text'}</SilkeText>
|
|
119
|
+
</SilkeBox>
|
|
120
|
+
</SilkeBox>;
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Pre-populated Value
|
|
124
|
+
|
|
125
|
+
Start with existing commands:
|
|
126
|
+
|
|
127
|
+
```js
|
|
128
|
+
const [value, setValue] = React.useState([
|
|
129
|
+
{ type: 'text', value: 'Hello ' },
|
|
130
|
+
{ type: SilkeCommandType.MENTION, value: 'alice', partial: false },
|
|
131
|
+
{ type: 'text', value: ' please ' },
|
|
132
|
+
{ type: SilkeCommandType.ACTION, value: 'review', partial: false },
|
|
133
|
+
{ type: 'text', value: ' this PR' },
|
|
134
|
+
]);
|
|
135
|
+
|
|
136
|
+
const availableCommands = [
|
|
137
|
+
{ type: SilkeCommandType.MENTION, value: 'alice' },
|
|
138
|
+
{ type: SilkeCommandType.ACTION, value: 'review' },
|
|
139
|
+
];
|
|
140
|
+
|
|
141
|
+
<SilkeCommandTextField availableCommands={availableCommands} onChange={setValue} value={value} />;
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Disabled State
|
|
145
|
+
|
|
146
|
+
```js
|
|
147
|
+
const [value, setValue] = React.useState([{ type: 'text', value: 'This field is disabled' }]);
|
|
148
|
+
|
|
149
|
+
<SilkeCommandTextField availableCommands={[]} disabled onChange={setValue} value={value} />;
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Using the Ref Handle
|
|
153
|
+
|
|
154
|
+
Access component methods via ref:
|
|
155
|
+
|
|
156
|
+
```js
|
|
157
|
+
const ref = React.useRef(null);
|
|
158
|
+
const [value, setValue] = React.useState([]);
|
|
159
|
+
|
|
160
|
+
const availableCommands = [{ type: SilkeCommandType.MENTION, value: 'team' }];
|
|
161
|
+
|
|
162
|
+
<SilkeBox column gap="s">
|
|
163
|
+
<SilkeCommandTextField
|
|
164
|
+
availableCommands={availableCommands}
|
|
165
|
+
onChange={setValue}
|
|
166
|
+
placeholder="Use the buttons below..."
|
|
167
|
+
ref={ref}
|
|
168
|
+
value={value}
|
|
169
|
+
/>
|
|
170
|
+
<SilkeBox gap="s">
|
|
171
|
+
<SilkeButton label="Focus" onClick={() => ref.current?.focus()} />
|
|
172
|
+
<SilkeButton label="Blur" onClick={() => ref.current?.blur()} />
|
|
173
|
+
<SilkeButton
|
|
174
|
+
label="Insert @team"
|
|
175
|
+
onClick={() =>
|
|
176
|
+
ref.current?.update({ type: SilkeCommandType.MENTION, value: 'team', partial: false })
|
|
177
|
+
}
|
|
178
|
+
/>
|
|
179
|
+
<SilkeButton label="Get as String" onClick={() => alert(ref.current?.toString())} />
|
|
180
|
+
</SilkeBox>
|
|
181
|
+
</SilkeBox>;
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## Full Interactive Example
|
|
185
|
+
|
|
186
|
+
```js
|
|
187
|
+
const [value, setValue] = React.useState([]);
|
|
188
|
+
const ref = React.useRef(null);
|
|
189
|
+
const [activeIndex, setActiveIndex] = React.useState(0);
|
|
190
|
+
const [suggestions, setSuggestions] = React.useState([]);
|
|
191
|
+
|
|
192
|
+
const availableCommands = [
|
|
193
|
+
{ type: SilkeCommandType.MENTION, value: 'alice' },
|
|
194
|
+
{ type: SilkeCommandType.MENTION, value: 'bob' },
|
|
195
|
+
{ type: SilkeCommandType.MENTION, value: 'charlie' },
|
|
196
|
+
{ type: SilkeCommandType.ACTION, value: 'help' },
|
|
197
|
+
{ type: SilkeCommandType.ACTION, value: 'search' },
|
|
198
|
+
{ type: SilkeCommandType.ACTION, value: 'clear' },
|
|
199
|
+
];
|
|
200
|
+
|
|
201
|
+
<SilkeBox column gap="s">
|
|
202
|
+
<SilkeText weight="medium">Active index: {activeIndex}</SilkeText>
|
|
203
|
+
<SilkeCommandTextField
|
|
204
|
+
autoFocus
|
|
205
|
+
availableCommands={availableCommands}
|
|
206
|
+
onChange={setValue}
|
|
207
|
+
onCommandFocus={setActiveIndex}
|
|
208
|
+
onKeyDown={(e) => {
|
|
209
|
+
if (e.key === 'Enter' && suggestions.length > 0) {
|
|
210
|
+
e.preventDefault();
|
|
211
|
+
ref.current?.update(suggestions[0]);
|
|
212
|
+
}
|
|
213
|
+
}}
|
|
214
|
+
onSuggestions={setSuggestions}
|
|
215
|
+
placeholder="Type @ to mention or / for actions..."
|
|
216
|
+
ref={ref}
|
|
217
|
+
value={value}
|
|
218
|
+
/>
|
|
219
|
+
{suggestions.length > 0 && (
|
|
220
|
+
<SilkeBox column gap="xs">
|
|
221
|
+
<SilkeText size="s" weight="medium">
|
|
222
|
+
Suggestions (press Enter to select first):
|
|
223
|
+
</SilkeText>
|
|
224
|
+
{suggestions.map((suggestion) => (
|
|
225
|
+
<SilkeBox
|
|
226
|
+
key={suggestion.type + suggestion.value}
|
|
227
|
+
onClick={() => ref.current?.update(suggestion)}
|
|
228
|
+
style={{
|
|
229
|
+
cursor: 'pointer',
|
|
230
|
+
padding: '4px 8px',
|
|
231
|
+
background: 'var(--color-neutral-10)',
|
|
232
|
+
borderRadius: 4,
|
|
233
|
+
}}
|
|
234
|
+
>
|
|
235
|
+
<SilkeText>
|
|
236
|
+
{suggestion.type}
|
|
237
|
+
{suggestion.value}
|
|
238
|
+
</SilkeText>
|
|
239
|
+
</SilkeBox>
|
|
240
|
+
))}
|
|
241
|
+
</SilkeBox>
|
|
242
|
+
)}
|
|
243
|
+
<SilkeBox column gap="xs">
|
|
244
|
+
<SilkeText size="s" weight="medium">
|
|
245
|
+
Output as string:
|
|
246
|
+
</SilkeText>
|
|
247
|
+
<SilkeCodeSnippet code={ref.current?.toString() || ''} />
|
|
248
|
+
</SilkeBox>
|
|
249
|
+
<SilkeBox column gap="xs">
|
|
250
|
+
<SilkeText size="s" weight="medium">
|
|
251
|
+
Value structure:
|
|
252
|
+
</SilkeText>
|
|
253
|
+
<SilkeCodeSnippet code={JSON.stringify(value, null, 2)} />
|
|
254
|
+
</SilkeBox>
|
|
255
|
+
</SilkeBox>;
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
## Props
|
|
259
|
+
|
|
260
|
+
| Prop | Type | Default | Description |
|
|
261
|
+
| ------------------- | --------------------------------------------------------------- | -------- | -------------------------------------------------------------- |
|
|
262
|
+
| `availableCommands` | `SilkeCommand[]` | Required | List of valid commands for autocomplete and validation |
|
|
263
|
+
| `value` | `SilkeCommandTextFieldValue[]` | Required | Current value of the field |
|
|
264
|
+
| `onChange` | `(value: SilkeCommandTextFieldValue[]) => void` | Required | Called when the value changes |
|
|
265
|
+
| `onSuggestions` | `(suggestions: SilkeCommand[]) => void` | - | Called with matching suggestions when typing a partial command |
|
|
266
|
+
| `onCommandFocus` | `(index: number, command?: SilkeCommandTextFieldValue) => void` | - | Called when the active command changes |
|
|
267
|
+
| `onKeyDown` | `(e: React.KeyboardEvent) => void` | - | Called on key down events |
|
|
268
|
+
| `placeholder` | `string` | - | Placeholder text shown when empty |
|
|
269
|
+
| `disabled` | `boolean` | `false` | Disable editing |
|
|
270
|
+
| `autoFocus` | `boolean` | `false` | Focus on mount |
|
|
271
|
+
|
|
272
|
+
## Ref Methods
|
|
273
|
+
|
|
274
|
+
| Method | Type | Description |
|
|
275
|
+
| ------------------------- | -------------------------------------------------- | ------------------------------------------------------------------------------------------ |
|
|
276
|
+
| `focus()` | `() => void` | Focus the input |
|
|
277
|
+
| `blur()` | `() => void` | Remove focus from the input |
|
|
278
|
+
| `update(command, index?)` | `(command: SilkeCommand, index?: number) => void` | Insert or update a command at the given index (defaults to active index, use -1 to append) |
|
|
279
|
+
| `toString(value?)` | `(value?: SilkeCommandTextFieldValue[]) => string` | Convert value to plain string |
|
|
280
|
+
|
|
281
|
+
## Types
|
|
282
|
+
|
|
283
|
+
```typescript
|
|
284
|
+
enum SilkeCommandType {
|
|
285
|
+
ACTION = '/',
|
|
286
|
+
MENTION = '@',
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
type SilkeCommand = {
|
|
290
|
+
partial?: boolean;
|
|
291
|
+
type: SilkeCommandType;
|
|
292
|
+
value: string;
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
type SilkeTextValue = {
|
|
296
|
+
type: 'text';
|
|
297
|
+
value: string;
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
type SilkeCommandTextFieldValue = SilkeCommand | SilkeTextValue;
|
|
301
|
+
```
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
.container {
|
|
2
|
+
flex: 1;
|
|
3
|
+
min-height: 32px;
|
|
4
|
+
overflow: hidden;
|
|
5
|
+
position: relative;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.imageList {
|
|
9
|
+
display: flex;
|
|
10
|
+
flex-wrap: wrap;
|
|
11
|
+
gap: 8px;
|
|
12
|
+
padding: 8px 4px;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.imageThumbnail {
|
|
16
|
+
position: relative;
|
|
17
|
+
width: 48px;
|
|
18
|
+
height: 48px;
|
|
19
|
+
border-radius: var(--border-radius-tiny);
|
|
20
|
+
overflow: hidden;
|
|
21
|
+
background-color: var(--color-neutral-20);
|
|
22
|
+
cursor: pointer;
|
|
23
|
+
|
|
24
|
+
img {
|
|
25
|
+
width: 100%;
|
|
26
|
+
height: 100%;
|
|
27
|
+
object-fit: cover;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
&:hover {
|
|
31
|
+
opacity: 0.9;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.imageRemove {
|
|
36
|
+
opacity: 0;
|
|
37
|
+
transition: opacity 0.15s ease;
|
|
38
|
+
|
|
39
|
+
.imageThumbnail:hover & {
|
|
40
|
+
opacity: 1;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.imagePreviewOverlay {
|
|
45
|
+
position: fixed;
|
|
46
|
+
top: 0;
|
|
47
|
+
left: 0;
|
|
48
|
+
right: 0;
|
|
49
|
+
bottom: 0;
|
|
50
|
+
background-color: rgba(0, 0, 0, 0.7);
|
|
51
|
+
display: flex;
|
|
52
|
+
align-items: center;
|
|
53
|
+
justify-content: center;
|
|
54
|
+
z-index: 1000;
|
|
55
|
+
cursor: pointer;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.imagePreview {
|
|
59
|
+
position: relative;
|
|
60
|
+
max-width: 90vw;
|
|
61
|
+
max-height: 90vh;
|
|
62
|
+
cursor: default;
|
|
63
|
+
|
|
64
|
+
img {
|
|
65
|
+
max-width: 100%;
|
|
66
|
+
max-height: 90vh;
|
|
67
|
+
object-fit: contain;
|
|
68
|
+
border-radius: var(--border-radius-small);
|
|
69
|
+
box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.placeholder {
|
|
74
|
+
color: var(--color-neutral-50);
|
|
75
|
+
left: 4px;
|
|
76
|
+
pointer-events: none;
|
|
77
|
+
position: absolute;
|
|
78
|
+
top: 4px;
|
|
79
|
+
user-select: none;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.textfield {
|
|
83
|
+
border: none;
|
|
84
|
+
height: 100%;
|
|
85
|
+
outline: none;
|
|
86
|
+
padding: 4px 4px;
|
|
87
|
+
white-space: pre-wrap;
|
|
88
|
+
width: 100%;
|
|
89
|
+
word-break: break-word;
|
|
90
|
+
|
|
91
|
+
&[aria-disabled='true'] {
|
|
92
|
+
cursor: not-allowed;
|
|
93
|
+
opacity: 0.5;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
.tag {
|
|
97
|
+
display: inline-block;
|
|
98
|
+
line-height: 1;
|
|
99
|
+
padding: 2px 4px;
|
|
100
|
+
cursor: default !important;
|
|
101
|
+
border-radius: var(--border-radius-tiny);
|
|
102
|
+
color: var(--color-neutral-80);
|
|
103
|
+
background-color: rgba(var(--color-neutral-40-rgb), var(--opacity-level-medium));
|
|
104
|
+
|
|
105
|
+
&:active {
|
|
106
|
+
opacity: 0.8;
|
|
107
|
+
}
|
|
108
|
+
&:not(.partial) {
|
|
109
|
+
&.mention {
|
|
110
|
+
color: var(--color-accent-60);
|
|
111
|
+
background-color: rgba(var(--color-accent-30-rgb), var(--opacity-level-medium));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
&.action {
|
|
115
|
+
color: var(--color-support-quaternary-60);
|
|
116
|
+
background-color: rgba(var(--color-support-quaternary-30-rgb), var(--opacity-level-light));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|