@vev/silke 1.0.15 → 1.0.17
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 +16 -0
- package/dist/chunk-SOFGXMET.js +22 -0
- package/dist/chunk-SOFGXMET.js.LEGAL.txt +11 -0
- package/dist/{chunk-KMZFUBRE.js.map → chunk-SOFGXMET.js.map} +3 -3
- package/dist/index.js +44 -9
- package/dist/index.js.LEGAL.txt +45 -21
- package/dist/index.js.map +4 -4
- package/dist/silke-code-editor-3Y2KM5KB.js +25 -0
- package/dist/silke-code-editor-3Y2KM5KB.js.LEGAL.txt +0 -0
- package/dist/silke-code-editor-3Y2KM5KB.js.map +7 -0
- package/dist/styles.css +351 -425
- package/esbuild.config.mjs +47 -43
- package/jest.config.js +1 -2
- package/package.json +4 -4
- package/src/components/silke-autocomplete-field/autocomplete-item.tsx +33 -7
- package/src/components/silke-autocomplete-field/autocomplete-tags.tsx +6 -2
- package/src/components/silke-autocomplete-field/autocomplete-types.ts +4 -0
- package/src/components/silke-autocomplete-field/silke-autocomplete-field.mdx +67 -24
- package/src/components/silke-autocomplete-field/silke-autocomplete-field.scss +32 -13
- package/src/components/silke-autocomplete-field/silke-autocomplete-field.spec.tsx +24 -111
- package/src/components/silke-autocomplete-field/silke-autocomplete-field.tsx +305 -219
- package/src/components/silke-box/silke-box.scss +9 -10
- package/src/components/silke-box/silke-box.tsx +9 -0
- package/src/components/silke-button/silke-button.scss +3 -3
- package/src/components/silke-color-picker/silke-color-info.tsx +2 -18
- package/src/components/silke-context-menu/silke-context-menu.tsx +0 -1
- package/src/components/silke-css-number-field/silke-css-number-field.mdx +43 -4
- package/src/components/silke-css-number-field/silke-css-number-field.scss +47 -14
- package/src/components/silke-css-number-field/silke-css-number-field.tsx +114 -186
- package/src/components/silke-css-number-field/utils.ts +25 -0
- package/src/components/silke-drawer/silke-drawer.tsx +0 -14
- package/src/components/silke-form/silke-form.tsx +1 -1
- package/src/components/silke-form-schema/fields/array-field-inline.tsx +1 -1
- package/src/components/silke-form-schema/fields/array-field-modal.tsx +1 -1
- package/src/components/silke-form-schema/fields/array-field.tsx +2 -2
- package/src/components/silke-form-schema/fields/event-field.tsx +1 -1
- package/src/components/silke-form-schema/fields/icon-field.tsx +1 -1
- package/src/components/silke-form-schema/fields/image-field.tsx +1 -1
- package/src/components/silke-form-schema/fields/layout-field.tsx +1 -1
- package/src/components/silke-form-schema/fields/link-field.tsx +1 -1
- package/src/components/silke-form-schema/fields/number-field.tsx +1 -1
- package/src/components/silke-form-schema/fields/object-field.tsx +1 -1
- package/src/components/silke-form-schema/fields/select-field.tsx +1 -1
- package/src/components/silke-form-schema/fields/string-field.tsx +1 -1
- package/src/components/silke-form-schema/fields/toggle-field.tsx +1 -1
- package/src/components/silke-form-schema/fields/upload-field.tsx +1 -1
- package/src/components/silke-form-schema/fields/utils/generate-image.ts +1 -1
- package/src/components/silke-form-schema/fields/utils/generate-title.ts +6 -5
- package/src/components/silke-form-schema/schema-utils.ts +1 -1
- package/src/components/silke-form-schema/silke-form-schema.tsx +1 -1
- package/src/components/silke-form-schema/silke-schema-context.tsx +1 -1
- package/src/components/silke-form-schema/silke-schema-field.tsx +1 -1
- package/src/components/silke-form-schema/silke-schema-fields.tsx +1 -1
- package/src/components/silke-image/silke-image.scss +2 -2
- package/src/components/silke-modal/silke-modal.tsx +11 -2
- package/src/components/silke-navigation-link/silke-navigation-link.scss +12 -2
- package/src/components/silke-navigation-link/silke-navigation-link.tsx +21 -17
- package/src/components/silke-notification/silke-notification.scss +1 -1
- package/src/components/silke-overflow-menu/silke-overflow-menu.tsx +1 -2
- package/src/components/silke-popover/silke-popover.tsx +1 -20
- package/src/components/silke-select-field/silke-select-field.mdx +137 -7
- package/src/components/silke-select-field/silke-select-field.spec.tsx +45 -128
- package/src/components/silke-sortable-list/silke-nested-sortable-item.tsx +17 -2
- package/src/components/silke-sortable-list/silke-nested-sortable-list.tsx +6 -2
- package/src/components/silke-sortable-list/silke-nested-sortable-utils.ts +6 -0
- package/src/components/silke-table/silke-table.tsx +1 -1
- package/src/components/silke-tag/silke-tag.tsx +3 -3
- package/src/components/silke-text-field/silke-text-field-item.tsx +12 -7
- package/src/components/silke-text-field/silke-text-field-outline.tsx +39 -42
- package/src/components/silke-text-field/silke-text-field.mdx +73 -6
- package/src/components/silke-text-field/silke-text-field.scss +153 -247
- package/src/components/silke-text-field/silke-text-field.tsx +4 -3
- package/src/components/silke-tooltip/silke-icon-tooltip.tsx +2 -1
- package/src/docs/app.tsx +9 -16
- package/src/hooks/form/use-form-field.ts +1 -1
- package/src/hooks/index.ts +1 -0
- package/src/hooks/use-drop-zone.ts +0 -3
- package/src/hooks/use-uniq-id.ts +6 -0
- package/src/icons.tsx +9 -1
- package/tsconfig.json +1 -1
- package/webpack.docs.ts +1 -1
- package/dist/chunk-KMZFUBRE.js +0 -22
- package/dist/chunk-KMZFUBRE.js.LEGAL.txt +0 -8
- package/dist/silke-code-editor-UX2ML2WG.js +0 -23
- package/dist/silke-code-editor-UX2ML2WG.js.map +0 -7
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { fireEvent, render, screen } from '@testing-library/react';
|
|
2
|
+
import { fireEvent, render, screen, within, act } from '@testing-library/react';
|
|
3
3
|
import { SilkeSelectField } from './silke-select-field';
|
|
4
|
-
import userEvent from '@testing-library/user-event';
|
|
4
|
+
import userEvent, { UserEvent } from '@testing-library/user-event';
|
|
5
5
|
import { SilkeForm } from '../silke-form';
|
|
6
|
-
import { ARROW_DOWN, ARROW_UP, ENTER
|
|
6
|
+
import { ARROW_DOWN, ARROW_UP, ENTER } from '../../../jest/keys';
|
|
7
7
|
|
|
8
8
|
describe('silke-select-field', () => {
|
|
9
9
|
beforeAll(() => {
|
|
@@ -11,6 +11,7 @@ describe('silke-select-field', () => {
|
|
|
11
11
|
});
|
|
12
12
|
|
|
13
13
|
const makeItem = (value: string) => ({ label: value, value });
|
|
14
|
+
const pressKey = (key: string, user: UserEvent) => act(async () => await user.keyboard(key));
|
|
14
15
|
|
|
15
16
|
const items = [
|
|
16
17
|
makeItem('rat'),
|
|
@@ -22,7 +23,7 @@ describe('silke-select-field', () => {
|
|
|
22
23
|
|
|
23
24
|
it('Has no value when no value passed', () => {
|
|
24
25
|
render(<SilkeSelectField items={items} label="Animal" />);
|
|
25
|
-
expect(screen.getByLabelText('Animal').getAttribute('value')).
|
|
26
|
+
expect(screen.getByLabelText('Animal').getAttribute('value')).toBeNull();
|
|
26
27
|
});
|
|
27
28
|
|
|
28
29
|
it('Has value when value passed', () => {
|
|
@@ -43,17 +44,17 @@ describe('silke-select-field', () => {
|
|
|
43
44
|
const onChange = jest.fn();
|
|
44
45
|
render(<SilkeSelectField items={items} label="Animal" value="rat" onChange={onChange} />);
|
|
45
46
|
const input = screen.getByLabelText('Animal');
|
|
46
|
-
await user.click(input);
|
|
47
|
+
await act(async () => await user.click(input));
|
|
47
48
|
|
|
48
49
|
const optionsList = screen.queryAllByRole('listbox');
|
|
49
50
|
|
|
50
51
|
expect(optionsList).toHaveLength(1);
|
|
52
|
+
const { getByText } = within(optionsList[0]);
|
|
53
|
+
const lionOption = getByText('lion');
|
|
54
|
+
const ratOption = getByText('rat');
|
|
51
55
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
expect(lionOption).toBeInTheDocument();
|
|
56
|
-
expect(ratOption).toBeInTheDocument();
|
|
56
|
+
expect(lionOption).toBeDefined();
|
|
57
|
+
expect(ratOption).toBeDefined();
|
|
57
58
|
});
|
|
58
59
|
|
|
59
60
|
it('Calls onChange with value when option is clicked', async () => {
|
|
@@ -63,10 +64,9 @@ describe('silke-select-field', () => {
|
|
|
63
64
|
render(<SilkeSelectField items={items} label="Animal" value="rat" onChange={onChange} />);
|
|
64
65
|
|
|
65
66
|
const input = screen.getByLabelText('Animal');
|
|
66
|
-
await user.click(input);
|
|
67
|
+
await act(async () => await user.click(input));
|
|
67
68
|
const option = screen.getByText('lion');
|
|
68
|
-
await user.click(option);
|
|
69
|
-
fireEvent.blur(input);
|
|
69
|
+
await act(async () => await user.click(option));
|
|
70
70
|
|
|
71
71
|
expect(onChange).toHaveBeenCalledWith('lion');
|
|
72
72
|
});
|
|
@@ -78,13 +78,12 @@ describe('silke-select-field', () => {
|
|
|
78
78
|
render(<SilkeSelectField items={items} label="Animal" onChange={onChange} />);
|
|
79
79
|
|
|
80
80
|
const input = screen.getByLabelText('Animal');
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
await user.keyboard(ARROW_DOWN); // opens dropdown
|
|
81
|
+
act(() => input.focus());
|
|
84
82
|
|
|
85
|
-
await user
|
|
83
|
+
await pressKey(ARROW_DOWN, user);
|
|
84
|
+
await pressKey(ENTER, user);
|
|
86
85
|
|
|
87
|
-
expect(onChange).toHaveBeenCalledWith('
|
|
86
|
+
expect(onChange).toHaveBeenCalledWith('lion');
|
|
88
87
|
});
|
|
89
88
|
|
|
90
89
|
it('Can be selected with keyboard only', async () => {
|
|
@@ -94,15 +93,13 @@ describe('silke-select-field', () => {
|
|
|
94
93
|
render(<SilkeSelectField items={items} label="Animal" onChange={onChange} />);
|
|
95
94
|
|
|
96
95
|
const input = screen.getByLabelText('Animal');
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
await
|
|
96
|
+
act(() => input.focus());
|
|
97
|
+
await pressKey(ARROW_DOWN, user);
|
|
98
|
+
await pressKey(ARROW_DOWN, user);
|
|
99
|
+
await pressKey(ARROW_DOWN, user);
|
|
100
|
+
await pressKey(ENTER, user);
|
|
100
101
|
|
|
101
|
-
|
|
102
|
-
await user.keyboard(ARROW_DOWN);
|
|
103
|
-
await user.keyboard(ENTER);
|
|
104
|
-
|
|
105
|
-
expect(onChange).toHaveBeenCalledWith('bear');
|
|
102
|
+
expect(onChange).toHaveBeenCalledWith('deer');
|
|
106
103
|
});
|
|
107
104
|
|
|
108
105
|
it('When it has value already, pressing arrow key selects item next to value', async () => {
|
|
@@ -112,35 +109,16 @@ describe('silke-select-field', () => {
|
|
|
112
109
|
render(<SilkeSelectField items={items} label="Animal" value="bear" onChange={onChange} />);
|
|
113
110
|
|
|
114
111
|
const input = screen.getByLabelText('Animal');
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
await user.keyboard(ARROW_DOWN); // opens dropdown
|
|
118
|
-
|
|
119
|
-
await user.keyboard(ARROW_UP);
|
|
120
|
-
await user.keyboard(ARROW_UP);
|
|
121
|
-
await user.keyboard(ARROW_UP);
|
|
112
|
+
act(() => input.focus());
|
|
122
113
|
|
|
123
|
-
await user
|
|
114
|
+
await pressKey(ARROW_UP, user);
|
|
115
|
+
await pressKey(ARROW_UP, user);
|
|
116
|
+
await pressKey(ARROW_UP, user);
|
|
117
|
+
await pressKey(ENTER, user);
|
|
124
118
|
|
|
125
119
|
expect(onChange).toHaveBeenCalledWith('cat');
|
|
126
120
|
});
|
|
127
121
|
|
|
128
|
-
it('Selects previous value when pressing enter twice', async () => {
|
|
129
|
-
const onChange = jest.fn();
|
|
130
|
-
const user = userEvent.setup();
|
|
131
|
-
|
|
132
|
-
render(<SilkeSelectField items={items} label="Animal" value="deer" onChange={onChange} />);
|
|
133
|
-
|
|
134
|
-
const input = screen.getByLabelText('Animal');
|
|
135
|
-
await input.focus();
|
|
136
|
-
|
|
137
|
-
await user.keyboard(ARROW_UP); // opens dropdown
|
|
138
|
-
|
|
139
|
-
await user.keyboard(ENTER);
|
|
140
|
-
|
|
141
|
-
expect(onChange).toHaveBeenCalledWith('deer');
|
|
142
|
-
});
|
|
143
|
-
|
|
144
122
|
it('Does not hide dropdown when item is selected on a multiselect select', async () => {
|
|
145
123
|
const onChange = jest.fn();
|
|
146
124
|
const user = userEvent.setup();
|
|
@@ -148,108 +126,47 @@ describe('silke-select-field', () => {
|
|
|
148
126
|
render(<SilkeSelectField items={items} label="Animal" multiple onChange={onChange} />);
|
|
149
127
|
|
|
150
128
|
const input = screen.getByLabelText('Animal');
|
|
151
|
-
|
|
129
|
+
act(() => input.focus());
|
|
152
130
|
|
|
153
|
-
await user.keyboard(ARROW_UP);
|
|
131
|
+
await act(async () => await user.keyboard(ARROW_UP));
|
|
154
132
|
|
|
155
133
|
const lionOption = screen.getByText('lion');
|
|
156
134
|
|
|
157
135
|
const dropdown = screen.getByRole('listbox');
|
|
158
|
-
expect(dropdown).
|
|
136
|
+
expect(dropdown).toBeDefined();
|
|
159
137
|
|
|
160
|
-
await user.click(lionOption);
|
|
138
|
+
await act(async () => await user.click(lionOption));
|
|
161
139
|
|
|
162
140
|
expect(onChange).toHaveBeenCalledWith(['lion']);
|
|
163
|
-
expect(dropdown).
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
it('Should not be possible to select anything when the dropdown is not open', async () => {
|
|
167
|
-
const onChange = jest.fn();
|
|
168
|
-
const user = userEvent.setup();
|
|
169
|
-
|
|
170
|
-
render(<SilkeSelectField items={items} label="Animal" onChange={onChange} />);
|
|
171
|
-
|
|
172
|
-
const input = screen.getByLabelText('Animal');
|
|
173
|
-
input.focus();
|
|
174
|
-
|
|
175
|
-
await user.keyboard(ARROW_DOWN); // opens dropdown
|
|
176
|
-
|
|
177
|
-
await user.keyboard(ARROW_DOWN);
|
|
178
|
-
await user.keyboard(ENTER);
|
|
179
|
-
|
|
180
|
-
await user.keyboard(ENTER);
|
|
181
|
-
|
|
182
|
-
expect(onChange).toHaveBeenCalledWith('lion');
|
|
183
|
-
expect(onChange).toHaveBeenCalledTimes(1);
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
it('Sets focus on input field and closes dropdown when item selected', async () => {
|
|
187
|
-
const onChange = jest.fn();
|
|
188
|
-
const user = userEvent.setup();
|
|
189
|
-
|
|
190
|
-
render(<SilkeSelectField items={items} label="Animal" onChange={onChange} />);
|
|
191
|
-
|
|
192
|
-
const input = screen.getByLabelText('Animal');
|
|
193
|
-
input.focus();
|
|
194
|
-
|
|
195
|
-
await user.click(input); // opens dropdown
|
|
196
|
-
|
|
197
|
-
const dropdown = screen.getByRole('listbox');
|
|
198
|
-
|
|
199
|
-
expect(dropdown).toBeInTheDocument();
|
|
200
|
-
|
|
201
|
-
const option = screen.getByText('lion');
|
|
202
|
-
await user.click(option);
|
|
203
|
-
|
|
204
|
-
expect(dropdown).not.toBeInTheDocument();
|
|
205
|
-
expect(input).toHaveFocus();
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
it('Closes dropdown when input looses focus', async () => {
|
|
209
|
-
const onChange = jest.fn();
|
|
210
|
-
const user = userEvent.setup();
|
|
211
|
-
|
|
212
|
-
render(<SilkeSelectField items={items} label="Animal" onChange={onChange} />);
|
|
213
|
-
|
|
214
|
-
render(<input type="text" data-testid="other" />);
|
|
215
|
-
|
|
216
|
-
const input = screen.getByLabelText('Animal');
|
|
217
|
-
const otherInput = screen.getByTestId('other');
|
|
218
|
-
input.focus();
|
|
219
|
-
|
|
220
|
-
await user.click(input); // opens dropdown
|
|
221
|
-
|
|
222
|
-
const dropdown = screen.getByRole('listbox');
|
|
223
|
-
|
|
224
|
-
expect(dropdown).toBeInTheDocument();
|
|
225
|
-
|
|
226
|
-
await otherInput.focus();
|
|
227
|
-
|
|
228
|
-
expect(dropdown).not.toBeInTheDocument();
|
|
141
|
+
expect(dropdown).toBeDefined();
|
|
229
142
|
});
|
|
230
143
|
|
|
231
144
|
describe('When Silke Select field is within a Silke form', () => {
|
|
232
145
|
it('Gets value from form', async () => {
|
|
233
146
|
const onChange = jest.fn();
|
|
234
|
-
const
|
|
235
|
-
|
|
147
|
+
const currentIndex = 2;
|
|
236
148
|
render(
|
|
237
|
-
<SilkeForm value={{ animal:
|
|
149
|
+
<SilkeForm value={{ animal: items[currentIndex].value }} onChange={onChange}>
|
|
238
150
|
<SilkeSelectField items={items} name="animal" label="Animal" />
|
|
239
151
|
</SilkeForm>,
|
|
240
152
|
);
|
|
241
153
|
|
|
242
154
|
const input = screen.getByLabelText('Animal');
|
|
243
|
-
|
|
155
|
+
act(() => input.focus());
|
|
244
156
|
|
|
245
157
|
expect(input.getAttribute('value')).toEqual('bear');
|
|
246
158
|
|
|
247
|
-
|
|
159
|
+
const dropdown = screen.getByRole('listbox');
|
|
160
|
+
expect(dropdown).toBeDefined();
|
|
161
|
+
|
|
162
|
+
const searchField = dropdown.querySelector('input') as HTMLInputElement;
|
|
163
|
+
expect(searchField).toBeDefined();
|
|
248
164
|
|
|
249
|
-
|
|
250
|
-
|
|
165
|
+
act(() => fireEvent.keyUp(searchField, { key: 'ArrowDown', code: 'ArrowDown' }));
|
|
166
|
+
act(() => fireEvent.keyUp(searchField, { key: 'ArrowDown', code: 'ArrowDown' }));
|
|
167
|
+
act(() => fireEvent.keyUp(searchField, { key: 'Enter', code: 'Enter' }));
|
|
251
168
|
|
|
252
|
-
expect(onChange).toHaveBeenCalledWith({ animal:
|
|
169
|
+
expect(onChange).toHaveBeenCalledWith({ animal: items[currentIndex + 2].value }, true);
|
|
253
170
|
});
|
|
254
171
|
});
|
|
255
172
|
});
|
|
@@ -94,8 +94,23 @@ export function SilkeNestedSortableItem<T>({
|
|
|
94
94
|
onCollapseToggle(item);
|
|
95
95
|
}}
|
|
96
96
|
>
|
|
97
|
-
{shouldShowIcon && (
|
|
98
|
-
<SilkeIcon
|
|
97
|
+
{(shouldShowIcon || item.replaceIcon) && (
|
|
98
|
+
<SilkeIcon
|
|
99
|
+
icon={
|
|
100
|
+
item.replaceIcon
|
|
101
|
+
? item.replaceIcon.icon
|
|
102
|
+
: hasState(state, ItemState.collapsed)
|
|
103
|
+
? 'caret.right'
|
|
104
|
+
: 'caret.down'
|
|
105
|
+
}
|
|
106
|
+
style={
|
|
107
|
+
item.replaceIcon
|
|
108
|
+
? {
|
|
109
|
+
color: item.replaceIcon.color,
|
|
110
|
+
}
|
|
111
|
+
: undefined
|
|
112
|
+
}
|
|
113
|
+
/>
|
|
99
114
|
)}
|
|
100
115
|
</SilkeBox>
|
|
101
116
|
)}
|
|
@@ -65,8 +65,12 @@ export function SilkeNestedSortableList<T>({
|
|
|
65
65
|
const ref = useRef<HTMLDivElement>(null);
|
|
66
66
|
const [pendingClickItem, setPendingClickItem] = useState<Item<T>>();
|
|
67
67
|
const [startDrag, setStartDrag] = useState(false);
|
|
68
|
-
const [dropState, setDropState] =
|
|
69
|
-
|
|
68
|
+
const [dropState, setDropState] = useState<{
|
|
69
|
+
index: number;
|
|
70
|
+
state: number;
|
|
71
|
+
childIndex: number;
|
|
72
|
+
top: number;
|
|
73
|
+
}>();
|
|
70
74
|
|
|
71
75
|
let cl = styles.list;
|
|
72
76
|
if (className) cl += ' ' + className;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Dictionary, last } from 'lodash';
|
|
2
|
+
import { SilkeIcons } from '../silke-icon';
|
|
2
3
|
|
|
3
4
|
export type RenderFunction<T> = (item: Item<T>, index: number) => React.ReactElement;
|
|
4
5
|
export type Item<T> = T & {
|
|
@@ -11,6 +12,11 @@ export type Item<T> = T & {
|
|
|
11
12
|
/** Override the default behavior with checking for children length */
|
|
12
13
|
showExpandIcon?: boolean;
|
|
13
14
|
style?: React.CSSProperties;
|
|
15
|
+
/** Overwrite icon */
|
|
16
|
+
replaceIcon?: {
|
|
17
|
+
icon: SilkeIcons;
|
|
18
|
+
color: string;
|
|
19
|
+
};
|
|
14
20
|
};
|
|
15
21
|
|
|
16
22
|
const INDENT_BITS = 6;
|
|
@@ -110,7 +110,7 @@ export function SilkeTable<T>({
|
|
|
110
110
|
<ButtonContext size="m">
|
|
111
111
|
<SilkeBox column gap="s" className={styles.root}>
|
|
112
112
|
{children && (
|
|
113
|
-
<TextFieldContext size="m" kind="
|
|
113
|
+
<TextFieldContext size="m" kind="ghost" inline>
|
|
114
114
|
<SilkeBox
|
|
115
115
|
className={styles.toolbar}
|
|
116
116
|
gap="m"
|
|
@@ -19,7 +19,7 @@ export type SilkeTagProps = {
|
|
|
19
19
|
* Will add a remove button to tag
|
|
20
20
|
*/
|
|
21
21
|
onRemove?: (e: React.MouseEvent) => void;
|
|
22
|
-
} & BoxProps
|
|
22
|
+
} & Omit<BoxProps, 'size'>;
|
|
23
23
|
|
|
24
24
|
function SilkeTagComp(
|
|
25
25
|
{
|
|
@@ -43,7 +43,7 @@ function SilkeTagComp(
|
|
|
43
43
|
if (rest?.onClick) cl.push(styles.selectable);
|
|
44
44
|
|
|
45
45
|
return (
|
|
46
|
-
<SilkeBox {...rest} className={cl.join(' ')} hPad="xs" vAlign="center" ref={ref}>
|
|
46
|
+
<SilkeBox {...(rest as BoxProps)} className={cl.join(' ')} hPad="xs" vAlign="center" ref={ref}>
|
|
47
47
|
<SilkeText overflow flex className={styles.label}>
|
|
48
48
|
<SilkeBox gap={innerGap} align="center">
|
|
49
49
|
{icon && <SilkeIcon icon={icon} />}
|
|
@@ -51,7 +51,7 @@ function SilkeTagComp(
|
|
|
51
51
|
</SilkeBox>
|
|
52
52
|
</SilkeText>
|
|
53
53
|
{!disabled && onRemove && (
|
|
54
|
-
<SilkeBox tag="button" vAlign="center" hAlign="center"
|
|
54
|
+
<SilkeBox tag="button" vAlign="center" hAlign="center" onMouseDown={onRemove}>
|
|
55
55
|
<SilkeIcon icon="close" />
|
|
56
56
|
</SilkeBox>
|
|
57
57
|
)}
|
|
@@ -7,17 +7,22 @@ type SilkeTextFieldItemProps = {
|
|
|
7
7
|
before?: boolean;
|
|
8
8
|
} & BoxProps;
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
before,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
...rest
|
|
15
|
-
}: SilkeTextFieldItemProps) {
|
|
10
|
+
function TextFieldItem(
|
|
11
|
+
{ before, children, className, ...rest }: SilkeTextFieldItemProps,
|
|
12
|
+
ref: any,
|
|
13
|
+
) {
|
|
16
14
|
let cl = before ? styles.itemBefore : styles.itemAfter;
|
|
17
15
|
if (className) cl += ' ' + className;
|
|
18
16
|
return (
|
|
19
|
-
<SilkeBox
|
|
17
|
+
<SilkeBox
|
|
18
|
+
ref={ref}
|
|
19
|
+
className={cl}
|
|
20
|
+
align={rest.hAlign || rest.vAlign ? undefined : 'center'}
|
|
21
|
+
{...rest}
|
|
22
|
+
>
|
|
20
23
|
{children}
|
|
21
24
|
</SilkeBox>
|
|
22
25
|
);
|
|
23
26
|
}
|
|
27
|
+
export const SilkeTextFieldItem = React.forwardRef(TextFieldItem);
|
|
28
|
+
SilkeTextFieldItem.displayName = 'SilkeTextFieldItem';
|
|
@@ -5,6 +5,7 @@ import { SilkeIcon } from '../silke-icon';
|
|
|
5
5
|
import { SilkeText } from '../silke-text/silke-text';
|
|
6
6
|
import styles from './silke-text-field.scss';
|
|
7
7
|
import { useTextFieldContext } from './text-field-context';
|
|
8
|
+
import { SilkeTextFieldItem } from './silke-text-field-item';
|
|
8
9
|
|
|
9
10
|
type InputSize = 'tiny' | 'small' | 'base' | 'large';
|
|
10
11
|
|
|
@@ -28,15 +29,16 @@ export type SilkeTextFieldOutlineProps = {
|
|
|
28
29
|
// Makes text field flex
|
|
29
30
|
flex?: boolean;
|
|
30
31
|
size?: BoxSize;
|
|
31
|
-
kind?: 'default' | 'ghost' | '
|
|
32
|
+
kind?: 'default' | 'ghost' | 'zombie';
|
|
32
33
|
width?: number;
|
|
33
34
|
/** Flex gap added to the container with the children */
|
|
34
35
|
gap?: BoxSpace;
|
|
35
36
|
/** Horizontal padding added to the container with the children */
|
|
36
37
|
hPad?: BoxSpace;
|
|
37
38
|
hAlign?: BoxProps['hAlign'];
|
|
39
|
+
vAlign?: BoxProps['vAlign'];
|
|
38
40
|
/** Inline will add the label before the input field */
|
|
39
|
-
inline?: boolean;
|
|
41
|
+
inline?: boolean | 'label-inside';
|
|
40
42
|
/** Width of the inline label */
|
|
41
43
|
inlineLabelWidth?: number;
|
|
42
44
|
/** Field required input (if string the string will be used as error msg) */
|
|
@@ -49,6 +51,7 @@ export type SilkeTextFieldOutlineProps = {
|
|
|
49
51
|
/** Id to link help label with (input should have aria-describedby) */
|
|
50
52
|
helpId?: string;
|
|
51
53
|
labelId?: string;
|
|
54
|
+
labelUsingAria?: boolean;
|
|
52
55
|
onClick?: (e: React.MouseEvent<HTMLElement>) => void;
|
|
53
56
|
onMouseDown?: (e: React.MouseEvent<HTMLElement>) => void;
|
|
54
57
|
disabled?: boolean;
|
|
@@ -64,6 +67,7 @@ export const SilkeTextFieldOutline = React.forwardRef<HTMLDivElement, SilkeTextF
|
|
|
64
67
|
gap,
|
|
65
68
|
hPad,
|
|
66
69
|
hAlign,
|
|
70
|
+
vAlign,
|
|
67
71
|
inline,
|
|
68
72
|
children,
|
|
69
73
|
help,
|
|
@@ -71,6 +75,7 @@ export const SilkeTextFieldOutline = React.forwardRef<HTMLDivElement, SilkeTextF
|
|
|
71
75
|
helpId,
|
|
72
76
|
label,
|
|
73
77
|
labelId,
|
|
78
|
+
labelUsingAria,
|
|
74
79
|
width,
|
|
75
80
|
flex,
|
|
76
81
|
onClick,
|
|
@@ -96,6 +101,20 @@ export const SilkeTextFieldOutline = React.forwardRef<HTMLDivElement, SilkeTextF
|
|
|
96
101
|
|
|
97
102
|
const showError = Boolean(error);
|
|
98
103
|
const showHelp = Boolean((help || helpRight) && !error);
|
|
104
|
+
const boxSize: BoxSize = size === 'xs' ? 's' : size === 's' ? 'base' : 'm';
|
|
105
|
+
|
|
106
|
+
const labelComponent = label && (
|
|
107
|
+
<SilkeText
|
|
108
|
+
className={styles.label}
|
|
109
|
+
tag="label"
|
|
110
|
+
id={labelUsingAria ? labelId : undefined}
|
|
111
|
+
htmlFor={!labelUsingAria ? labelId : undefined}
|
|
112
|
+
color="neutral-100"
|
|
113
|
+
style={inlineLabelWidth ? { width: `${inlineLabelWidth}px` } : undefined}
|
|
114
|
+
>
|
|
115
|
+
{label}
|
|
116
|
+
</SilkeText>
|
|
117
|
+
);
|
|
99
118
|
return (
|
|
100
119
|
<SilkeBox
|
|
101
120
|
data-size={`data-input-${mappedSize}`}
|
|
@@ -108,63 +127,41 @@ export const SilkeTextFieldOutline = React.forwardRef<HTMLDivElement, SilkeTextF
|
|
|
108
127
|
onClick={onClick}
|
|
109
128
|
onMouseDown={onMouseDown}
|
|
110
129
|
>
|
|
111
|
-
{label &&
|
|
112
|
-
<SilkeText
|
|
113
|
-
className={styles.label}
|
|
114
|
-
tag="label"
|
|
115
|
-
htmlFor={labelId}
|
|
116
|
-
color="neutral-100"
|
|
117
|
-
style={inlineLabelWidth ? { width: `${inlineLabelWidth}px` } : undefined}
|
|
118
|
-
>
|
|
119
|
-
{label}
|
|
120
|
-
</SilkeText>
|
|
121
|
-
)}
|
|
130
|
+
{inline !== 'label-inside' && labelComponent}
|
|
122
131
|
|
|
123
132
|
<ButtonContext kind="ghost" size="base">
|
|
124
133
|
<SilkeBox
|
|
125
134
|
gap={gap}
|
|
126
135
|
hPad={hPad}
|
|
127
136
|
hAlign={hAlign}
|
|
137
|
+
vAlign={vAlign}
|
|
128
138
|
className={styles.field}
|
|
129
|
-
flex={inline}
|
|
139
|
+
flex={!!inline}
|
|
130
140
|
ref={ref}
|
|
131
141
|
>
|
|
142
|
+
{labelComponent && inline === 'label-inside' && (
|
|
143
|
+
<SilkeTextFieldItem before minWidth={boxSize} hPad="xs">
|
|
144
|
+
{labelComponent}
|
|
145
|
+
</SilkeTextFieldItem>
|
|
146
|
+
)}
|
|
132
147
|
{children}
|
|
133
|
-
<div className={styles.border} />
|
|
134
148
|
</SilkeBox>
|
|
135
149
|
</ButtonContext>
|
|
136
150
|
|
|
137
151
|
{!inline && (
|
|
138
|
-
|
|
139
|
-
{showHelp && (
|
|
140
|
-
<
|
|
141
|
-
{help
|
|
142
|
-
|
|
143
|
-
{help}
|
|
144
|
-
</SilkeText>
|
|
145
|
-
)}
|
|
146
|
-
{helpRight && <SilkeText>{helpRight}</SilkeText>}
|
|
147
|
-
</SilkeBox>
|
|
152
|
+
<SilkeBox hAlign="spread" className={styles.help}>
|
|
153
|
+
{showHelp && help && (
|
|
154
|
+
<SilkeText flex id={helpId}>
|
|
155
|
+
{help}
|
|
156
|
+
</SilkeText>
|
|
148
157
|
)}
|
|
158
|
+
{showHelp && helpRight && <SilkeText>{helpRight}</SilkeText>}
|
|
149
159
|
{showError && (
|
|
150
|
-
<
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
tag="small"
|
|
154
|
-
className={styles.formErrorMessage}
|
|
155
|
-
color="error-30"
|
|
156
|
-
aria-live="polite"
|
|
157
|
-
role="alert"
|
|
158
|
-
>
|
|
159
|
-
{error}{' '}
|
|
160
|
-
<SilkeIcon
|
|
161
|
-
icon="error.circle"
|
|
162
|
-
style={{ fontSize: '1.25rem', paddingLeft: '4px', verticalAlign: 'middle' }}
|
|
163
|
-
/>
|
|
164
|
-
</SilkeText>
|
|
165
|
-
</SilkeBox>
|
|
160
|
+
<SilkeText flex aria-live="polite" role="alert">
|
|
161
|
+
{error}
|
|
162
|
+
</SilkeText>
|
|
166
163
|
)}
|
|
167
|
-
|
|
164
|
+
</SilkeBox>
|
|
168
165
|
)}
|
|
169
166
|
</SilkeBox>
|
|
170
167
|
);
|
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
const [value, setValue] = React.useState("");
|
|
7
7
|
|
|
8
8
|
<SilkeBox column gap="l">
|
|
9
|
-
{["default", "
|
|
10
|
-
|
|
11
|
-
{
|
|
9
|
+
{["default", "zombie", "ghost"].map((kind) =>
|
|
10
|
+
["base", "s", "xs"].map((size) => (
|
|
11
|
+
<SilkeBox key={kind} gap="l" vAlign="end">
|
|
12
12
|
<SilkeTextField
|
|
13
13
|
flex
|
|
14
14
|
key={size || "default"}
|
|
@@ -20,9 +20,75 @@ const [value, setValue] = React.useState("");
|
|
|
20
20
|
value={value}
|
|
21
21
|
onChange={setValue}
|
|
22
22
|
/>
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
<SilkeTextField
|
|
24
|
+
flex
|
|
25
|
+
error="Got error"
|
|
26
|
+
key={size || "default"}
|
|
27
|
+
label={`${kind || "default"} - ${size}`}
|
|
28
|
+
placeholder={kind || "default" + " " + size}
|
|
29
|
+
size={size}
|
|
30
|
+
kind={kind}
|
|
31
|
+
value={value}
|
|
32
|
+
onChange={setValue}
|
|
33
|
+
/>
|
|
34
|
+
<SilkeTextField
|
|
35
|
+
flex
|
|
36
|
+
disabled
|
|
37
|
+
key={size || "default"}
|
|
38
|
+
label={`${kind || "default"} - ${size}`}
|
|
39
|
+
placeholder={kind || "default" + " " + size}
|
|
40
|
+
size={size}
|
|
41
|
+
kind={kind}
|
|
42
|
+
help={kind + " -- " + "help"}
|
|
43
|
+
value={value}
|
|
44
|
+
onChange={setValue}
|
|
45
|
+
/>
|
|
46
|
+
</SilkeBox>
|
|
47
|
+
))
|
|
48
|
+
)}
|
|
49
|
+
</SilkeBox>;
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Inline fields
|
|
53
|
+
|
|
54
|
+
```js
|
|
55
|
+
const [value, setValue] = React.useState("");
|
|
56
|
+
|
|
57
|
+
<SilkeBox column gap="l">
|
|
58
|
+
{["default", "zombie", "ghost"].map((kind) =>
|
|
59
|
+
["base", "s", "xs"].map((size) => (
|
|
60
|
+
<SilkeBox key={kind} gap="l" vAlign="center">
|
|
61
|
+
<SilkeBox width="xxl">
|
|
62
|
+
{kind}/{size}
|
|
63
|
+
</SilkeBox>
|
|
64
|
+
<SilkeTextField
|
|
65
|
+
flex
|
|
66
|
+
inline
|
|
67
|
+
key={size || "default"}
|
|
68
|
+
label={`${kind || "default"} - ${size}`}
|
|
69
|
+
placeholder={kind || "default" + " " + size}
|
|
70
|
+
size={size}
|
|
71
|
+
kind={kind}
|
|
72
|
+
help={kind + " -- " + "help"}
|
|
73
|
+
value={value}
|
|
74
|
+
onChange={setValue}
|
|
75
|
+
/>
|
|
76
|
+
<SilkeTextField
|
|
77
|
+
flex
|
|
78
|
+
inline="label-inside"
|
|
79
|
+
key={size || "default"}
|
|
80
|
+
label={`${kind || "default"} - ${size}`}
|
|
81
|
+
placeholder={kind || "default" + " " + size}
|
|
82
|
+
size={size}
|
|
83
|
+
kind={kind}
|
|
84
|
+
error="Testing"
|
|
85
|
+
help={kind + " -- " + "help"}
|
|
86
|
+
value={value}
|
|
87
|
+
onChange={setValue}
|
|
88
|
+
/>
|
|
89
|
+
</SilkeBox>
|
|
90
|
+
))
|
|
91
|
+
)}
|
|
26
92
|
</SilkeBox>;
|
|
27
93
|
```
|
|
28
94
|
|
|
@@ -92,6 +158,7 @@ const items = ipsum.list((i) => ({
|
|
|
92
158
|
<SilkeTextFieldItem>
|
|
93
159
|
<SilkeSelectField
|
|
94
160
|
kind="ghost"
|
|
161
|
+
inline
|
|
95
162
|
onChange={() => console.log("selected")}
|
|
96
163
|
value={items[1].value}
|
|
97
164
|
items={items}
|