@vev/silke 1.0.7 → 1.0.10

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.
@@ -0,0 +1,310 @@
1
+ import { Mouse } from '@vev/utils';
2
+ import { clamp, difference, keyBy, uniq } from 'lodash';
3
+ import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
4
+ import { BoxProps, SilkeBox } from '../silke-box';
5
+ import { SilkeIcon } from '../silke-icon';
6
+ import styles from './silke-nested-sortable-list.scss';
7
+ import {
8
+ generatedComputedStates,
9
+ getIndentLevel,
10
+ getParents,
11
+ getPlacementString,
12
+ hasState,
13
+ isParentOfSelf,
14
+ Item,
15
+ ItemState,
16
+ RenderFunction,
17
+ } from './silke-nested-sortable-utils';
18
+
19
+ type SilkeNestedSortableListProps<T> = {
20
+ items: Item<T>[];
21
+ selected?: string[];
22
+ collapsed?: string[];
23
+ children: RenderFunction<T>;
24
+ onSort: (
25
+ updateList: Item<T>[],
26
+ dropItem: Item<T>,
27
+ placement: 'before' | 'after' | 'inside',
28
+ ) => void;
29
+ canHaveChildren?: (item: Item<T>) => boolean;
30
+ canSort?: (
31
+ targetItem: Item<T>,
32
+ placement: 'before' | 'after' | 'inside',
33
+ parents: string[],
34
+ selected: string[],
35
+ ) => boolean | number;
36
+ /** Triggered when collapsed arrow is pressed,gives the updated collapse list */
37
+ onCollapsed: (collapsed: string[]) => void;
38
+ onClick?: (e: MouseEvent, item: Item<T>) => void;
39
+ } & BoxProps;
40
+
41
+ export function SilkeNestedSortableList<T>({
42
+ items,
43
+ selected,
44
+ collapsed,
45
+ children,
46
+ className,
47
+ onSort,
48
+ canHaveChildren,
49
+ canSort,
50
+ onCollapsed,
51
+ onClick,
52
+ ...rest
53
+ }: SilkeNestedSortableListProps<T>) {
54
+ const ref = useRef<HTMLDivElement>(null);
55
+ const [pendingClickItem, setPendingClickItem] = useState<Item<T>>();
56
+ const [startDrag, setStartDrag] = useState(false);
57
+ const [dropState, setDropState] = useState<{ index: number; state: number }>();
58
+
59
+ let cl = styles.list;
60
+ if (className) cl += ' ' + className;
61
+ if (dropState) cl += ' ' + styles.dragging;
62
+
63
+ const [computedStates, parentMap] = useMemo(() => {
64
+ const itemMap = keyBy(items, 'key');
65
+ const parentMap: { [key: string]: string } = {};
66
+ for (const item of items) {
67
+ if (item.children) {
68
+ for (const childKey of item.children) parentMap[childKey] = item.key;
69
+ }
70
+ }
71
+
72
+ const rootItemKeys = items.filter((item) => !(item.key in parentMap)).map((item) => item.key);
73
+
74
+ const computedStates = generatedComputedStates(itemMap, rootItemKeys, selected, collapsed);
75
+
76
+ return [computedStates, parentMap];
77
+ }, [items, selected, collapsed]);
78
+
79
+ const handleCollapse = useCallback(
80
+ (item: Item<T>) => {
81
+ if (onCollapsed) {
82
+ if (collapsed?.includes(item.key)) onCollapsed(collapsed.filter((k) => k !== item.key));
83
+ else onCollapsed([...(collapsed || []), item.key]);
84
+ }
85
+ },
86
+ [collapsed, onCollapsed],
87
+ );
88
+ const handleItemMouseDown = useCallback(
89
+ (e: React.MouseEvent<HTMLDivElement>, item: Item<T>) => {
90
+ // If already selected we have to wait to see if the user wants to drag or not, will be handled in mouse up of drag
91
+ // If not selected we can handle the mouse event immediately
92
+ if (selected?.includes(item.key)) {
93
+ setPendingClickItem(item);
94
+ } else {
95
+ setPendingClickItem(undefined);
96
+ onClick?.(e.nativeEvent, item);
97
+ }
98
+ setStartDrag(true);
99
+ },
100
+ [onClick, selected],
101
+ );
102
+
103
+ useEffect(() => {
104
+ const listEl = ref.current;
105
+ if (!startDrag || !listEl) return;
106
+ const itemElements = listEl.querySelectorAll<HTMLElement>('.' + styles.item);
107
+ const offsets: [offsetTop: number, height: number][] = [];
108
+ itemElements?.forEach((el) => {
109
+ offsets.push([el.offsetTop, el.offsetHeight]);
110
+ });
111
+
112
+ let dragState: 'pending' | 'dragging' = 'pending';
113
+ let dropState: { index: number; state: number };
114
+ const handleMouseMove = (e: MouseEvent) => {
115
+ if (!selected || !selected.length) return;
116
+ if (dragState === 'pending') {
117
+ if (Mouse.getDownDist() > 10) dragState = 'dragging';
118
+ } else {
119
+ const { top } = listEl.getBoundingClientRect();
120
+ const offsetY = e.pageY - top;
121
+ let index = -1;
122
+
123
+ if (offsetY > offsets[0][0]) {
124
+ for (index = 0; index < offsets.length; index++) {
125
+ const [top, height] = offsets[index];
126
+ if (offsetY <= top + height) break;
127
+ }
128
+ }
129
+
130
+ let placementState: number = ItemState.placeBefore;
131
+
132
+ if (index === -1) {
133
+ placementState = ItemState.placeBefore;
134
+ index = 0;
135
+ } else if (index === computedStates.length) {
136
+ placementState = ItemState.placeAfter;
137
+ index = computedStates.length - 1;
138
+ } else {
139
+ const [targetState, targetItem] = computedStates[index];
140
+ const allowChildren = canHaveChildren
141
+ ? canHaveChildren(targetItem)
142
+ : Boolean(targetItem?.children);
143
+ const offset = offsets[clamp(index, 0, computedStates.length - 1)];
144
+ const isTargetSelected = hasState(targetState, ItemState.selected);
145
+ const isTargetCollapsed =
146
+ hasState(targetState, ItemState.collapsed) || !targetItem?.children?.length;
147
+
148
+ const insideBottomPos = offset[0] + offset[1] + (isTargetCollapsed ? -10 : 0);
149
+
150
+ if (
151
+ allowChildren &&
152
+ !isTargetSelected &&
153
+ offsetY > offset[0] + 10 &&
154
+ offsetY < insideBottomPos
155
+ ) {
156
+ placementState = ItemState.placeInside;
157
+ } else if (offsetY > offset[0] + offset[1] / 2) {
158
+ placementState = ItemState.placeAfter;
159
+ }
160
+ }
161
+
162
+ const [, targetItem] = computedStates[index];
163
+ const parents = getParents(targetItem.key, parentMap);
164
+
165
+ const allowSort =
166
+ !canSort || canSort(targetItem, getPlacementString(placementState), parents, selected);
167
+ const selectionParentOfSelf = selected.some((key) =>
168
+ isParentOfSelf(parentMap[targetItem.key], key, parentMap),
169
+ );
170
+
171
+ if (!allowSort || selectionParentOfSelf) placementState |= ItemState.placementInvalid;
172
+
173
+ dropState = { index, state: placementState };
174
+ setDropState(dropState);
175
+ }
176
+ };
177
+
178
+ const handleMouseUp = (e: MouseEvent) => {
179
+ setStartDrag(false);
180
+ setDropState(undefined);
181
+ if (dragState === 'pending') {
182
+ if (pendingClickItem && onClick) onClick(e, pendingClickItem);
183
+ return;
184
+ }
185
+ if (dropState && selected && !hasState(dropState.state, ItemState.placementInvalid)) {
186
+ const [, targetItem] = computedStates[dropState.index];
187
+
188
+ const placeAfter = hasState(dropState.state, ItemState.placeAfter);
189
+ const placeInside = hasState(dropState.state, ItemState.placeInside);
190
+
191
+ const parentKey = placeInside ? targetItem.key : parentMap[targetItem.key];
192
+
193
+ const newItems = items.slice();
194
+ for (let i = 0; i < newItems.length; i++) {
195
+ const item = newItems[i];
196
+ const { children } = item;
197
+ if (children) {
198
+ const newChildren = difference(children, selected);
199
+ // if child difference then some children were removed so need to update item
200
+ if (newChildren.length !== children.length) {
201
+ newItems[i] = { ...item, children: newChildren };
202
+ }
203
+ }
204
+
205
+ if (item.key === parentKey) {
206
+ const newChildren = (newItems[i].children || []).slice();
207
+ let childIndex = placeInside ? 0 : children?.indexOf(targetItem.key) || 0;
208
+
209
+ if (placeAfter) childIndex++;
210
+
211
+ // Have to offset index if child existed in the children array above the position we're inserting at
212
+ childIndex -= selected.reduce((offset, key) => {
213
+ const index = children ? children.indexOf(key) : -1;
214
+ return index !== -1 && index < childIndex ? offset + 1 : offset;
215
+ }, 0);
216
+
217
+ newChildren.splice(childIndex, 0, ...uniq(selected));
218
+ newItems[i] = { ...newItems[i], children: newChildren };
219
+ }
220
+ }
221
+
222
+ onSort(newItems, targetItem, getPlacementString(dropState.state));
223
+ }
224
+ };
225
+ Mouse.on('mousemove', handleMouseMove);
226
+ Mouse.on('mouseup', handleMouseUp);
227
+ return () => {
228
+ Mouse.off('mousemove', handleMouseMove);
229
+ Mouse.off('mouseup', handleMouseUp);
230
+ };
231
+ }, [startDrag, selected, computedStates, onClick, canHaveChildren, canSort, parentMap]);
232
+
233
+ return (
234
+ <SilkeBox ref={ref} className={cl} column {...rest}>
235
+ {computedStates.map(([state, item], index) => (
236
+ <SilkeNestedSortableItem
237
+ key={item.key}
238
+ item={item}
239
+ state={state | (index === dropState?.index ? dropState.state : 0)}
240
+ index={index}
241
+ onMouseDown={handleItemMouseDown}
242
+ onCollapseToggle={handleCollapse}
243
+ >
244
+ {item.render || children}
245
+ </SilkeNestedSortableItem>
246
+ ))}
247
+ </SilkeBox>
248
+ );
249
+ }
250
+
251
+ type SilkeNestedSortableItemProps<T> = {
252
+ item: Item<T>;
253
+ state: number;
254
+ index: number;
255
+ children: RenderFunction<T>;
256
+ onMouseDown?: (e: React.MouseEvent<HTMLDivElement>, item: Item<T>) => void;
257
+ onCollapseToggle: (item: Item<T>) => void;
258
+ };
259
+
260
+ function SilkeNestedSortableItem<T>({
261
+ item,
262
+ index,
263
+ state,
264
+ children,
265
+ onCollapseToggle,
266
+ onMouseDown,
267
+ }: SilkeNestedSortableItemProps<T>) {
268
+ let cl = styles.item;
269
+ const hasChildren = !!item.children?.length;
270
+ const indent = getIndentLevel(state);
271
+
272
+ if (hasState(state, ItemState.selected)) cl += ' ' + styles.selected;
273
+ if (hasState(state, ItemState.roundTop)) cl += ' ' + styles.roundTop;
274
+ if (hasState(state, ItemState.roundBottom)) cl += ' ' + styles.roundBottom;
275
+ if (hasState(state, ItemState.childOfSelected)) cl += ' ' + styles.childOfSelected;
276
+ if (hasState(state, ItemState.childOfSelected)) cl += ' ' + styles.childOfSelected;
277
+
278
+ if (hasState(state, ItemState.placeAfter)) cl += ' ' + styles.placeAfter;
279
+ if (hasState(state, ItemState.placeBefore)) cl += ' ' + styles.placeBefore;
280
+ if (hasState(state, ItemState.placeInside)) cl += ' ' + styles.placeInside;
281
+ if (hasState(state, ItemState.placementInvalid)) cl += ' ' + styles.placementInvalid;
282
+
283
+ if (hasChildren) cl += ' ' + styles.hasChildren;
284
+ if (item.disabled) cl += ' ' + styles.disabled;
285
+ if (indent) cl += ' ' + styles[`indent${indent}`];
286
+ return (
287
+ <div
288
+ className={cl}
289
+ style={item.style}
290
+ tabIndex={item.disabled ? undefined : 0}
291
+ onMouseDown={!item.disabled && onMouseDown ? (e) => onMouseDown(e, item) : undefined}
292
+ >
293
+ <SilkeBox
294
+ className={styles.expand}
295
+ tabIndex={1}
296
+ size="s"
297
+ align="center"
298
+ onClick={(e: React.MouseEvent<HTMLDivElement>) => {
299
+ if (hasChildren) e.stopPropagation();
300
+ onCollapseToggle(item);
301
+ }}
302
+ >
303
+ {hasChildren && (
304
+ <SilkeIcon icon={hasState(state, ItemState.collapsed) ? 'caret.right' : 'caret.down'} />
305
+ )}
306
+ </SilkeBox>
307
+ {children(item, index)}
308
+ </div>
309
+ );
310
+ }
@@ -0,0 +1,57 @@
1
+ import { keyBy } from 'lodash';
2
+ import { generatedComputedStates, hasState, Item, ItemState } from './silke-nested-sortable-utils';
3
+
4
+ let id = 0;
5
+ const getItem = (children?: Item<any>[]): Item<any> => {
6
+ return { key: 'item' + id++, children: children?.map((item) => item.key) };
7
+ };
8
+ describe('SilkeNestedSortableUtils', () => {
9
+ beforeEach(() => {
10
+ id = 0;
11
+ });
12
+
13
+ it('should generate computed items', () => {
14
+ const nestedChildren = [getItem()];
15
+ const children = [getItem(), getItem(nestedChildren)];
16
+ const items = [getItem(children), getItem(), ...children, ...nestedChildren];
17
+
18
+ const selected = [items[0].key];
19
+ const computed = generatedComputedStates(keyBy(items, 'key'), selected, selected);
20
+ expect(hasState(computed[0][0], ItemState.roundTop)).toBe(true);
21
+ expect(hasState(computed[0][0], ItemState.selected)).toBe(true);
22
+ expect(hasState(computed[0][0], ItemState.roundBottom)).toBe(false);
23
+
24
+ for (let i = 1; i < 4; i++) {
25
+ expect(hasState(computed[i][0], ItemState.childOfSelected)).toBe(true);
26
+ expect(hasState(computed[i][0], ItemState.roundTop)).toBe(false);
27
+ expect(hasState(computed[i][0], ItemState.roundBottom)).toBe(i === 3);
28
+ }
29
+ });
30
+
31
+ it('should round bottom of last selected', () => {
32
+ const items = [getItem(), getItem(), getItem(), getItem()];
33
+ const keys = items.map((item) => item.key);
34
+ const selected = [items[1].key, items[2].key];
35
+ const computed = generatedComputedStates(keyBy(items, 'key'), keys, selected);
36
+
37
+ expect(hasState(computed[1][0], ItemState.selected)).toBe(true);
38
+ expect(hasState(computed[1][0], ItemState.roundTop)).toBe(true);
39
+ expect(hasState(computed[1][0], ItemState.roundBottom)).toBe(false);
40
+
41
+ expect(hasState(computed[2][0], ItemState.selected)).toBe(true);
42
+ expect(hasState(computed[2][0], ItemState.roundTop)).toBe(false);
43
+ expect(hasState(computed[2][0], ItemState.roundBottom)).toBe(true);
44
+ });
45
+
46
+ it('should round bottom of last childOfSelected', () => {
47
+ const children = [getItem()];
48
+ const items = [getItem(children), ...children];
49
+ const computed = generatedComputedStates(keyBy(items, 'key'), [items[0].key], [items[0].key]);
50
+ expect(hasState(computed[0][0], ItemState.selected)).toBe(true);
51
+ expect(hasState(computed[0][0], ItemState.roundBottom)).toBe(false);
52
+
53
+ expect(hasState(computed[1][0], ItemState.roundBottom)).toBe(true);
54
+ expect(hasState(computed[1][0], ItemState.selected)).toBe(false);
55
+ expect(hasState(computed[1][0], ItemState.childOfSelected)).toBe(true);
56
+ });
57
+ });
@@ -0,0 +1,151 @@
1
+ import { Dictionary } from 'lodash';
2
+
3
+ export type RenderFunction<T> = (item: Item<T>, index: number) => React.ReactNode;
4
+ export type Item<T> = {
5
+ key: string;
6
+ value?: T;
7
+ /** Not selectable and no hover interactions */
8
+ disabled?: boolean;
9
+ children?: string[];
10
+ render?: RenderFunction<T>;
11
+ className?: string;
12
+ style?: React.CSSProperties;
13
+ };
14
+
15
+ const INDENT_BITS = 6;
16
+ const MAX_INDENT_MASK = 0b111111;
17
+
18
+ export enum ItemState {
19
+ indentBit1 = 1 << 0,
20
+ indentBit2 = 1 << 1,
21
+ indentBit3 = 1 << 2,
22
+ indentBit4 = 1 << 3,
23
+ indentBit5 = 1 << 4,
24
+ indentBit6 = 1 << 5,
25
+
26
+ collapsed = 1 << 6,
27
+ selected = 1 << 7,
28
+ childOfSelected = 1 << 8,
29
+ roundTop = 1 << 9,
30
+ roundBottom = 1 << 10,
31
+
32
+ placeAfter = 1 << 11,
33
+ placeBefore = 1 << 12,
34
+ placeInside = 1 << 13,
35
+ placementInvalid = 1 << 14,
36
+ }
37
+
38
+ function getComputedState(
39
+ prevState = 0,
40
+ selected?: boolean,
41
+ childOfSelected?: boolean,
42
+ collapsed?: boolean,
43
+ indent = 0,
44
+ ): number {
45
+ let state = indent;
46
+ const prevSelected = hasState(prevState, ItemState.selected);
47
+
48
+ if (selected) {
49
+ state |= ItemState.selected;
50
+
51
+ if (!prevSelected && !childOfSelected) {
52
+ state |= ItemState.roundTop;
53
+ }
54
+ }
55
+
56
+ if (!selected && !childOfSelected) {
57
+ state |= ItemState.roundTop | ItemState.roundBottom;
58
+ }
59
+ if (childOfSelected) state |= ItemState.childOfSelected;
60
+ if (collapsed) state |= ItemState.collapsed;
61
+
62
+ return state;
63
+ }
64
+
65
+ export function hasState(state: number, hasState: number): boolean {
66
+ return Boolean(state & hasState);
67
+ }
68
+
69
+ export function getIndentLevel(state: number): number {
70
+ return state & MAX_INDENT_MASK;
71
+ }
72
+
73
+ export function generatedComputedStates<T>(
74
+ itemMap: Dictionary<Item<T>> = {},
75
+ itemKeys: string[],
76
+ selected?: string[],
77
+ collapsed?: string[],
78
+ isChildOfSelected?: boolean,
79
+ indent = 0,
80
+ computedStates: [number, Item<T>][] = [],
81
+ ): [number, Item<T>][] {
82
+ for (const itemKey of itemKeys) {
83
+ const item = itemMap[itemKey];
84
+ const prevState = computedStates[computedStates.length - 1]?.[0] || 0;
85
+ const isSelected = selected?.includes(item.key);
86
+ const isCollapsed = collapsed?.includes(item.key);
87
+ const state = getComputedState(prevState, isSelected, isChildOfSelected, isCollapsed, indent);
88
+
89
+ if (
90
+ prevState &&
91
+ !isSelected &&
92
+ !hasState(state, ItemState.childOfSelected) &&
93
+ hasState(prevState, ItemState.selected | ItemState.childOfSelected)
94
+ ) {
95
+ computedStates[computedStates.length - 1][0] |= ItemState.roundBottom;
96
+ }
97
+ computedStates.push([state, item]);
98
+
99
+ if (item.children && !hasState(state, ItemState.collapsed)) {
100
+ generatedComputedStates(
101
+ itemMap,
102
+ item.children,
103
+ selected,
104
+ collapsed,
105
+ isSelected || isChildOfSelected,
106
+ indent + 1,
107
+ computedStates,
108
+ );
109
+ }
110
+ }
111
+ const prevState = computedStates[computedStates.length - 1]?.[0] || 0;
112
+ if (!indent && hasState(prevState, ItemState.childOfSelected | ItemState.selected)) {
113
+ computedStates[computedStates.length - 1][0] |= ItemState.roundBottom;
114
+ }
115
+ return computedStates;
116
+ }
117
+
118
+ export function getParents(itemKey: string, parentMap: { [key: string]: string }): string[] {
119
+ const parents = [];
120
+ let parentKey = parentMap[itemKey];
121
+ while (parentKey) {
122
+ parents.push(parentKey);
123
+ parentKey = parentMap[parentKey];
124
+ }
125
+ return parents;
126
+ }
127
+
128
+ export function getPlacementString(state: number): 'after' | 'before' | 'inside' {
129
+ if (hasState(state, ItemState.placeAfter)) return 'after';
130
+ else if (hasState(state, ItemState.placeInside)) return 'inside';
131
+ return 'before';
132
+ }
133
+
134
+ export function isParentOfSelf(
135
+ targetKey: string,
136
+ itemKey: string,
137
+ parentMap: { [key: string]: string },
138
+ ): boolean {
139
+ if (itemKey === targetKey) return true;
140
+ const parentKey = parentMap[targetKey];
141
+ return !parentKey ? false : isParentOfSelf(parentKey, itemKey, parentMap);
142
+ }
143
+
144
+ export function debugLogState(message: string, state: number) {
145
+ console.group(message);
146
+ for (const key in ItemState) {
147
+ const v = ItemState[key];
148
+ if (typeof v === 'number' && state & v) console.log(ItemState[v]);
149
+ }
150
+ console.groupEnd();
151
+ }
@@ -25,8 +25,8 @@ const [list, setList] = React.useState(['Item 1', 'Item 2', 'Item 3'])
25
25
  To sort between lists just give the list the same id
26
26
 
27
27
  ```js
28
- const [list1, setList1] = React.useState(['Item 1', 'Item 2', 'Item 3']);
29
- const [list2, setList2] = React.useState(['Item 4', 'Item 5', 'Item 6']);
28
+ const [list1, setList1] = React.useState(["Item 1", "Item 2", "Item 3"]);
29
+ const [list2, setList2] = React.useState(["Item 4", "Item 5", "Item 6"]);
30
30
  const Item = (item) => (
31
31
  <SilkeBox gap="s" vAlign="center" height="base">
32
32
  <SilkeIcon icon="drag" data-drag-handle /> {item}
@@ -55,3 +55,91 @@ const Item = (item) => (
55
55
  </SilkeSortableList>
56
56
  </SilkeBox>;
57
57
  ```
58
+
59
+ ### Nested sortable
60
+
61
+ To sort between lists just give the list the same id
62
+
63
+ ```js
64
+ const [selected, setSelected] = React.useState(["item1"]);
65
+ const [collapsed, setCollapsed] = React.useState(["item2"]);
66
+ const [list, setList] = React.useState([
67
+ {
68
+ key: "header",
69
+ value: "Header item",
70
+ disabled: true,
71
+ render: (item) => (
72
+ <SilkeBox vAlign="center" height="base">
73
+ {item.value}
74
+ </SilkeBox>
75
+ ),
76
+ children: ["item1-1", "item1-2", "item1-3", "item1-4"],
77
+ },
78
+ {
79
+ key: "item1-1",
80
+ value: "Item 1.1",
81
+ children: ["item1-1-1", "item1-1-2"],
82
+ },
83
+ { key: "item1-2", value: "Item 1.2" },
84
+ { key: "item1-3", value: "Item 1.3" },
85
+ { key: "item1-4", value: "Item 1.4" },
86
+ { key: "item1-1-1", value: "Item 1.1.1" },
87
+ { key: "item1-1-2", value: "Item 1.1.2" },
88
+ {
89
+ key: "item2",
90
+ value: "Item 2",
91
+ children: ["item2-1", "item2-2"],
92
+ style: {
93
+ "--item-selection-color": "var(--color-feedback-warning-medium)",
94
+ "--item-hover-color": "var(--color-feedback-warning-dark)",
95
+ },
96
+ },
97
+ {
98
+ key: "item2-1",
99
+ value: "Item 2.1",
100
+ children: ["item2-2-1", "item2-2-2", "item2-2-3", "item2-2-4"],
101
+ },
102
+ { key: "item2-2", value: "Item 2.2", children: [] },
103
+ { key: "item2-2-1", value: "Item 2.2.1" },
104
+ { key: "item2-2-2", value: "Item 2.2.2" },
105
+ { key: "item2-2-3", value: "Item 2,2.3" },
106
+ { key: "item2-2-4", value: "Item 2.2.4" },
107
+ ]);
108
+ const Item = (item) => (
109
+ <SilkeBox gap="s" vAlign="center" height="base">
110
+ <SilkeBox size="s" align="center">
111
+ <SilkeIcon icon="package" />
112
+ </SilkeBox>
113
+ {item.value}
114
+ </SilkeBox>
115
+ );
116
+ <SilkeBox gap="xl">
117
+ <SilkeNestedSortableList
118
+ selected={selected}
119
+ collapsed={collapsed}
120
+ items={list}
121
+ flex
122
+ pad="m"
123
+ onSort={setList}
124
+ onCollapsed={setCollapsed}
125
+ onClick={(e, item) => {
126
+ if (e.shiftKey) setSelected([...selected, item.key]);
127
+ else setSelected([item.key]);
128
+ }}
129
+ canHaveChildren={(item) => item.children || item.key === "item1-4"}
130
+ canSort={(target, placement, parents, selected) => {
131
+ if (target.key === "header" && placement !== "inside") return false;
132
+ if (
133
+ (target.key === "item2" && placement === "inside") ||
134
+ parents.includes("item2")
135
+ )
136
+ return false;
137
+
138
+ return true;
139
+ }}
140
+ onSort={setList}
141
+ >
142
+ {Item}
143
+ </SilkeNestedSortableList>
144
+ </SilkeBox>;
145
+ ```
package/src/icons.tsx CHANGED
@@ -256,6 +256,7 @@ export const SilkeIconDefinitions = {
256
256
  figma: 'fab fa-figma',
257
257
  import: 'fal fa-file-import',
258
258
  stripe: 'fab fa-stripe',
259
+ okta: 'fa-solid fa-circle-dot',
259
260
  linkedin: 'fab fa-linkedin',
260
261
  twitter: 'fab fa-twitter',
261
262
  react: 'fab fa-react',