@rockshin/tao-ui 0.0.13 → 0.0.14

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.
@@ -1,4 +1,4 @@
1
- button[data-tao-variant] {
1
+ button[data-tao-button] {
2
2
  justify-content: center;
3
3
  align-items: center;
4
4
  gap: var(--tao-padding-xs);
@@ -17,91 +17,91 @@ button[data-tao-variant] {
17
17
  display: inline-flex;
18
18
  }
19
19
 
20
- button[data-tao-size="small"] {
20
+ button[data-tao-button][data-tao-size="small"] {
21
21
  height: var(--tao-control-height-sm);
22
22
  padding-inline: var(--tao-padding-xs);
23
23
  font-size: var(--tao-font-size-sm);
24
24
  border-radius: var(--tao-radius-sm);
25
25
  }
26
26
 
27
- button[data-tao-size="medium"] {
27
+ button[data-tao-button][data-tao-size="medium"] {
28
28
  height: var(--tao-control-height);
29
29
  padding-inline: var(--tao-padding);
30
30
  font-size: var(--tao-font-size-base);
31
31
  border-radius: var(--tao-radius-md);
32
32
  }
33
33
 
34
- button[data-tao-size="large"] {
34
+ button[data-tao-button][data-tao-size="large"] {
35
35
  height: var(--tao-control-height-lg);
36
36
  padding-inline: var(--tao-padding);
37
37
  font-size: var(--tao-font-size-base);
38
38
  border-radius: var(--tao-radius-md);
39
39
  }
40
40
 
41
- button[data-tao-variant="primary"] {
41
+ button[data-tao-button][data-tao-variant="primary"] {
42
42
  background: var(--tao-primary);
43
43
  color: var(--tao-primary-fg);
44
44
  box-shadow: var(--tao-box-shadow-xs);
45
45
  }
46
46
 
47
- button[data-tao-variant="primary"]:hover:not(:disabled) {
47
+ button[data-tao-button][data-tao-variant="primary"]:hover:not(:disabled) {
48
48
  background: var(--tao-primary-hover);
49
49
  }
50
50
 
51
- button[data-tao-variant="primary"]:active:not(:disabled) {
51
+ button[data-tao-button][data-tao-variant="primary"]:active:not(:disabled) {
52
52
  background: var(--tao-primary-active);
53
53
  }
54
54
 
55
- button[data-tao-variant="secondary"] {
55
+ button[data-tao-button][data-tao-variant="secondary"] {
56
56
  color: var(--tao-color-text);
57
57
  border-color: var(--tao-color-border);
58
58
  box-shadow: var(--tao-box-shadow-xs);
59
59
  background: none;
60
60
  }
61
61
 
62
- button[data-tao-variant="secondary"]:hover:not(:disabled) {
62
+ button[data-tao-button][data-tao-variant="secondary"]:hover:not(:disabled) {
63
63
  background: var(--tao-color-fill-tertiary);
64
64
  border-color: var(--tao-color-border);
65
65
  }
66
66
 
67
- button[data-tao-variant="secondary"]:active:not(:disabled) {
67
+ button[data-tao-button][data-tao-variant="secondary"]:active:not(:disabled) {
68
68
  background: var(--tao-color-fill-secondary);
69
69
  }
70
70
 
71
- button[data-tao-variant="ghost"] {
71
+ button[data-tao-button][data-tao-variant="ghost"] {
72
72
  color: var(--tao-color-text-secondary);
73
73
  background: none;
74
74
  }
75
75
 
76
- button[data-tao-variant="ghost"]:hover:not(:disabled) {
76
+ button[data-tao-button][data-tao-variant="ghost"]:hover:not(:disabled) {
77
77
  background: var(--tao-color-fill-tertiary);
78
78
  color: var(--tao-color-text);
79
79
  }
80
80
 
81
- button[data-tao-variant="ghost"]:active:not(:disabled) {
81
+ button[data-tao-button][data-tao-variant="ghost"]:active:not(:disabled) {
82
82
  background: var(--tao-color-fill-secondary);
83
83
  }
84
84
 
85
- button[data-tao-variant="destructive"] {
85
+ button[data-tao-button][data-tao-variant="destructive"] {
86
86
  background: var(--tao-error);
87
87
  color: var(--tao-error-fg);
88
88
  box-shadow: var(--tao-box-shadow-xs);
89
89
  }
90
90
 
91
- button[data-tao-variant="destructive"]:hover:not(:disabled) {
91
+ button[data-tao-button][data-tao-variant="destructive"]:hover:not(:disabled) {
92
92
  background: var(--tao-error-hover);
93
93
  }
94
94
 
95
- button[data-tao-variant="destructive"]:active:not(:disabled) {
95
+ button[data-tao-button][data-tao-variant="destructive"]:active:not(:disabled) {
96
96
  background: var(--tao-error-active);
97
97
  }
98
98
 
99
- button[data-tao-variant]:disabled {
99
+ button[data-tao-button]:disabled {
100
100
  opacity: var(--tao-opacity-loading);
101
101
  cursor: not-allowed;
102
102
  }
103
103
 
104
- button[data-tao-variant]:focus-visible {
104
+ button[data-tao-button]:focus-visible {
105
105
  box-shadow: 0 0 0 var(--tao-ring-width) var(--tao-control-outline);
106
106
  outline: none;
107
107
  }
@@ -74,6 +74,7 @@ function Button(t0) {
74
74
  style: t5,
75
75
  disabled: isDisabled,
76
76
  "aria-busy": t6,
77
+ "data-tao-button": "",
77
78
  "data-tao-variant": variant,
78
79
  "data-tao-size": resolvedSize,
79
80
  children: children
@@ -131,3 +131,32 @@
131
131
  color: var(--tao-color-text-tertiary);
132
132
  }
133
133
 
134
+ [data-tao-sheet-footer] {
135
+ padding: var(--tao-padding-sm) var(--tao-padding);
136
+ border-block-start: var(--tao-line-width) solid
137
+ var(--tao-color-border-secondary);
138
+ background: var(--tao-color-bg-elevated);
139
+ flex-shrink: 0;
140
+ }
141
+
142
+ [data-tao-sheet-done] {
143
+ border-radius: var(--tao-radius-md);
144
+ background: var(--tao-primary);
145
+ color: #fff;
146
+ width: 100%;
147
+ height: 44px;
148
+ font-family: var(--tao-font-family);
149
+ font-size: var(--tao-font-size-base);
150
+ font-weight: var(--tao-font-weight-medium);
151
+ cursor: pointer;
152
+ -webkit-tap-highlight-color: transparent;
153
+ border: none;
154
+ justify-content: center;
155
+ align-items: center;
156
+ display: flex;
157
+ }
158
+
159
+ [data-tao-sheet-done]:active {
160
+ opacity: .85;
161
+ }
162
+
@@ -1,10 +1,12 @@
1
1
  import { type ReactNode } from 'react';
2
- import type { SelectOption } from './select';
2
+ import { type SelectOption } from './select';
3
3
  import './mobile-select.css';
4
4
  interface MobileSelectContentProps {
5
5
  options: SelectOption[];
6
- value?: string;
6
+ value?: string | string[];
7
7
  onChange?: (value: string) => void;
8
+ /** Multi-mode commit callback: fires when "Done" is pressed with the full array. */
9
+ onMultiChange?: (values: string[]) => void;
8
10
  placeholder?: string;
9
11
  showSearch?: boolean;
10
12
  filterOption?: (input: string, option: SelectOption) => boolean;
@@ -13,10 +15,12 @@ interface MobileSelectContentProps {
13
15
  index: number;
14
16
  }) => ReactNode;
15
17
  onClose: () => void;
18
+ /** Enable multi-select checkboxes + Done button flow. */
19
+ multiple?: boolean;
16
20
  }
17
- export declare function MobileSelectContent({ options, value, onChange, showSearch, filterOption, notFoundContent, optionRender, onClose, }: MobileSelectContentProps): import("react/jsx-runtime").JSX.Element;
21
+ declare function MobileSelectContentInner({ options, value, onChange, onMultiChange, showSearch, filterOption, notFoundContent, optionRender, onClose, multiple, }: MobileSelectContentProps): import("react/jsx-runtime").JSX.Element;
22
+ export { MobileSelectContentInner as MobileSelectContent };
18
23
  export interface MobileSelectDrawerProps extends MobileSelectContentProps {
19
24
  open: boolean;
20
25
  }
21
26
  export declare function MobileSelectDrawer({ open, onClose, placeholder, ...rest }: MobileSelectDrawerProps): import("react/jsx-runtime").JSX.Element;
22
- export {};
@@ -2,6 +2,7 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
2
  import { c } from "react/compiler-runtime";
3
3
  import { useCallback, useMemo, useState } from "react";
4
4
  import { Drawer } from "../drawer/drawer.js";
5
+ import { SearchIcon } from "./select.js";
5
6
  import "./mobile-select.css";
6
7
  const defaultFilter = (input, option)=>{
7
8
  const label = 'string' == typeof option.label ? option.label : String(option.label);
@@ -21,8 +22,18 @@ function filterTree(options, fn, input) {
21
22
  function countLeaves(options) {
22
23
  return options.reduce((n, o)=>n + (o.options ? countLeaves(o.options) : 1), 0);
23
24
  }
24
- function MobileSelectContent({ options, value, onChange, showSearch, filterOption, notFoundContent = 'No results', optionRender, onClose }) {
25
+ function MobileSelectContentInner({ options, value, onChange, onMultiChange, showSearch, filterOption, notFoundContent = 'No results', optionRender, onClose, multiple }) {
25
26
  const [search, setSearch] = useState('');
27
+ const valueArray = useMemo(()=>{
28
+ if (multiple) return value ?? [];
29
+ return value ? [
30
+ value
31
+ ] : [];
32
+ }, [
33
+ multiple,
34
+ value
35
+ ]);
36
+ const [draft, setDraft] = useState(valueArray);
26
37
  const filteredOptions = useMemo(()=>{
27
38
  if (!showSearch || !search) return options;
28
39
  const fn = filterOption ?? defaultFilter;
@@ -34,16 +45,31 @@ function MobileSelectContent({ options, value, onChange, showSearch, filterOptio
34
45
  filterOption
35
46
  ]);
36
47
  const handleSelect = useCallback((optValue)=>{
37
- onChange?.(optValue);
38
- onClose();
48
+ if (multiple) setDraft((prev)=>prev.includes(optValue) ? prev.filter((v)=>v !== optValue) : [
49
+ ...prev,
50
+ optValue
51
+ ]);
52
+ else {
53
+ onChange?.(optValue);
54
+ onClose();
55
+ }
39
56
  }, [
57
+ multiple,
40
58
  onChange,
41
59
  onClose
42
60
  ]);
61
+ const handleDone = useCallback(()=>{
62
+ onMultiChange?.(draft);
63
+ onClose();
64
+ }, [
65
+ draft,
66
+ onMultiChange,
67
+ onClose
68
+ ]);
43
69
  let optIndex = 0;
44
70
  const renderItem = (opt)=>{
45
71
  const index = optIndex++;
46
- const isSelected = opt.value === value;
72
+ const isSelected = multiple ? draft.includes(opt.value) : opt.value === value;
47
73
  return /*#__PURE__*/ jsxs("button", {
48
74
  type: "button",
49
75
  "data-tao-sheet-item": "",
@@ -115,6 +141,15 @@ function MobileSelectContent({ options, value, onChange, showSearch, filterOptio
115
141
  "data-tao-sheet-empty": "",
116
142
  children: notFoundContent
117
143
  })
144
+ }),
145
+ multiple && /*#__PURE__*/ jsx("div", {
146
+ "data-tao-sheet-footer": "",
147
+ children: /*#__PURE__*/ jsx("button", {
148
+ type: "button",
149
+ "data-tao-sheet-done": "",
150
+ onClick: handleDone,
151
+ children: "Done"
152
+ })
118
153
  })
119
154
  ]
120
155
  });
@@ -141,7 +176,7 @@ function MobileSelectDrawer(t0) {
141
176
  const t1 = placeholder ?? "Select";
142
177
  let t2;
143
178
  if ($[5] !== onClose || $[6] !== placeholder || $[7] !== rest) {
144
- t2 = /*#__PURE__*/ jsx(MobileSelectContent, {
179
+ t2 = /*#__PURE__*/ jsx(MobileSelectContentInner, {
145
180
  onClose: onClose,
146
181
  placeholder: placeholder,
147
182
  ...rest
@@ -169,36 +204,6 @@ function MobileSelectDrawer(t0) {
169
204
  } else t3 = $[13];
170
205
  return t3;
171
206
  }
172
- function SearchIcon() {
173
- const $ = c(1);
174
- let t0;
175
- if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
176
- t0 = /*#__PURE__*/ jsxs("svg", {
177
- "aria-hidden": "true",
178
- focusable: "false",
179
- width: "14",
180
- height: "14",
181
- viewBox: "0 0 24 24",
182
- fill: "none",
183
- stroke: "currentColor",
184
- strokeWidth: "2",
185
- strokeLinecap: "round",
186
- strokeLinejoin: "round",
187
- children: [
188
- /*#__PURE__*/ jsx("circle", {
189
- cx: "11",
190
- cy: "11",
191
- r: "8"
192
- }),
193
- /*#__PURE__*/ jsx("path", {
194
- d: "m21 21-4.3-4.3"
195
- })
196
- ]
197
- });
198
- $[0] = t0;
199
- } else t0 = $[0];
200
- return t0;
201
- }
202
207
  function CheckIcon() {
203
208
  const $ = c(1);
204
209
  let t0;
@@ -222,4 +227,4 @@ function CheckIcon() {
222
227
  } else t0 = $[0];
223
228
  return t0;
224
229
  }
225
- export { MobileSelectContent, MobileSelectDrawer };
230
+ export { MobileSelectContentInner as MobileSelectContent, MobileSelectDrawer };
@@ -2,7 +2,6 @@
2
2
  --tao-select-height: var(--tao-control-height);
3
3
  --tao-select-font-size: var(--tao-font-size-base);
4
4
  --tao-select-line-height: var(--tao-line-height);
5
- --tao-select-padding-inline: var(--tao-padding-sm);
6
5
  --tao-select-padding-block: calc((
7
6
  var(--tao-select-height) -
8
7
  var(--tao-select-font-size) *
@@ -10,34 +9,29 @@
10
9
  ) /
11
10
  2 -
12
11
  var(--tao-line-width));
13
- align-items: flex-start;
12
+ --tao-select-padding-inline: calc(var(--tao-padding-sm) -
13
+ var(--tao-line-width));
14
+ align-items: center;
14
15
  gap: var(--tao-padding-xs);
15
16
  width: 100%;
16
17
  font-family: var(--tao-font-family);
17
18
  font-size: var(--tao-select-font-size);
18
19
  line-height: var(--tao-select-line-height);
19
20
  height: var(--tao-select-height);
20
- padding-block: max(var(--tao-select-padding-block), 0px);
21
+ padding-block: var(--tao-select-padding-block);
21
22
  padding-inline: var(--tao-select-padding-inline);
22
23
  cursor: pointer;
23
24
  outline: none;
24
25
  display: flex;
25
26
  }
26
27
 
27
- button[data-tao-select] {
28
- appearance: none;
29
- text-align: start;
30
- }
31
-
32
28
  [data-tao-select-value] {
33
29
  text-overflow: ellipsis;
34
30
  white-space: nowrap;
35
31
  min-width: 0;
36
32
  color: var(--tao-color-text);
37
- line-height: var(--tao-select-line-height);
33
+ line-height: inherit;
38
34
  flex: 1;
39
- align-self: center;
40
- display: block;
41
35
  overflow: hidden;
42
36
  }
43
37
 
@@ -46,11 +40,16 @@ button[data-tao-select] {
46
40
  line-height: var(--tao-select-line-height);
47
41
  }
48
42
 
43
+ [data-tao-select][data-tao-multiple] [data-tao-select-placeholder] {
44
+ padding-inline-start: var(--tao-select-padding-inline);
45
+ }
46
+
49
47
  [data-tao-select][data-tao-size="small"] {
50
48
  --tao-select-height: var(--tao-control-height-sm);
51
49
  --tao-select-font-size: var(--tao-font-size-sm);
52
50
  --tao-select-line-height: var(--tao-line-height-sm);
53
- --tao-select-padding-inline: var(--tao-padding-xs);
51
+ --tao-select-padding-inline: calc(var(--tao-padding-xs) -
52
+ var(--tao-line-width));
54
53
  border-radius: var(--tao-radius-sm);
55
54
  }
56
55
 
@@ -326,3 +325,77 @@ button[data-tao-select] {
326
325
  color: var(--tao-color-text-tertiary);
327
326
  }
328
327
 
328
+ [data-tao-select][data-tao-multiple] {
329
+ height: auto;
330
+ min-height: var(--tao-select-height);
331
+ flex-wrap: wrap;
332
+ padding-block: 4px;
333
+ padding-inline-start: 4px;
334
+ padding-inline-end: var(--tao-select-padding-inline);
335
+ }
336
+
337
+ [data-tao-select-values] {
338
+ flex-wrap: wrap;
339
+ flex: 1;
340
+ align-items: center;
341
+ gap: 4px;
342
+ min-width: 0;
343
+ padding-block: 1px;
344
+ display: flex;
345
+ }
346
+
347
+ [data-tao-select-tag] {
348
+ max-width: 160px;
349
+ font-size: var(--tao-font-size-sm);
350
+ height: 24px;
351
+ color: var(--tao-color-text);
352
+ background: var(--tao-color-fill-quaternary);
353
+ border-radius: var(--tao-radius-sm);
354
+ border: var(--tao-line-width) solid var(--tao-color-border-secondary);
355
+ align-items: center;
356
+ gap: 0;
357
+ padding-block: 0;
358
+ padding-inline: 6px;
359
+ line-height: 1.53846;
360
+ display: inline-flex;
361
+ }
362
+
363
+ [data-tao-select-tag][data-tao-disabled] {
364
+ opacity: .5;
365
+ cursor: not-allowed;
366
+ }
367
+
368
+ [data-tao-select-tag-label] {
369
+ text-overflow: ellipsis;
370
+ white-space: nowrap;
371
+ overflow: hidden;
372
+ }
373
+
374
+ [data-tao-select-tag-close] {
375
+ cursor: pointer;
376
+ width: 16px;
377
+ height: 16px;
378
+ color: var(--tao-color-text-quaternary);
379
+ border-radius: var(--tao-radius-xs);
380
+ transition: color var(--tao-motion-duration-fast) var(--tao-motion-ease-out),
381
+ background-color var(--tao-motion-duration-fast) var(--tao-motion-ease-out);
382
+ flex-shrink: 0;
383
+ justify-content: center;
384
+ align-items: center;
385
+ margin-inline: 2px -2px;
386
+ display: inline-flex;
387
+ }
388
+
389
+ [data-tao-select-tag-close]:hover {
390
+ color: var(--tao-color-text-secondary);
391
+ }
392
+
393
+ [data-tao-select-tag-rest] {
394
+ cursor: default;
395
+ color: var(--tao-color-text-tertiary);
396
+ }
397
+
398
+ [data-tao-select-item][data-tao-selected] {
399
+ font-weight: var(--tao-font-weight-medium);
400
+ }
401
+
@@ -13,18 +13,29 @@ export interface SelectOption {
13
13
  /** Nested options turn this entry into a group; `label` becomes the group title. */
14
14
  options?: SelectOption[];
15
15
  }
16
- export type SelectSemanticPart = 'root' | 'prefix' | 'suffix' | 'placeholder' | 'clear' | 'popup' | 'search' | 'group' | 'groupLabel' | 'item' | 'itemIcon' | 'itemLabel' | 'itemDesc' | 'empty';
16
+ export type SelectSemanticPart = 'root' | 'prefix' | 'suffix' | 'placeholder' | 'clear' | 'popup' | 'search' | 'searchInput' | 'group' | 'groupLabel' | 'item' | 'itemIcon' | 'itemLabel' | 'itemDesc' | 'empty' | 'tag' | 'tagLabel' | 'tagClose' | 'tagRest' | 'values';
17
17
  export type SelectPlacement = 'bottomLeft' | 'bottomRight' | 'topLeft' | 'topRight';
18
+ export interface TagRenderProps {
19
+ label: ReactNode;
20
+ value: string;
21
+ closable: boolean;
22
+ disabled: boolean;
23
+ onClose: (e: React.MouseEvent) => void;
24
+ }
18
25
  export interface SelectProps {
19
26
  options: SelectOption[];
20
- value?: string;
21
- defaultValue?: string;
22
- /** Fired on selection or clear. `option` is undefined when cleared. */
23
- onChange?: (value: string, option?: SelectOption) => void;
24
- /** Fired only when an option is picked (not on clear). */
27
+ value?: string | string[];
28
+ defaultValue?: string | string[];
29
+ /** Fired on selection or clear. Multi-mode receives `string[]`. */
30
+ onChange?: (value: string | string[], option?: SelectOption | SelectOption[]) => void;
31
+ /** Fired only when an option is picked (not on clear). Multi-mode receives a single value. */
25
32
  onSelect?: (value: string, option: SelectOption) => void;
33
+ /** Fired when an option is deselected (multi-mode only). */
34
+ onDeselect?: (value: string, option: SelectOption) => void;
26
35
  /** Fired when the value is cleared via the clear button. */
27
36
  onClear?: () => void;
37
+ /** Selection mode. `multiple` for multi-select, `tags` for free-form tag input. */
38
+ mode?: 'multiple' | 'tags';
28
39
  placeholder?: string;
29
40
  size?: TaoSize;
30
41
  variant?: TaoVariant;
@@ -53,9 +64,11 @@ export interface SelectProps {
53
64
  prefix?: ReactNode;
54
65
  /** Custom suffix (arrow) icon. */
55
66
  suffixIcon?: ReactNode;
67
+ /** Custom remove icon for multi-select tags. */
68
+ removeIcon?: ReactNode;
56
69
  autoFocus?: boolean;
57
70
  id?: string;
58
- /** Name for hidden form field. */
71
+ /** Name for hidden form field (single mode only). */
59
72
  name?: string;
60
73
  /** Controlled open state of the dropdown. */
61
74
  open?: boolean;
@@ -73,10 +86,26 @@ export interface SelectProps {
73
86
  optionRender?: (option: SelectOption, info: {
74
87
  index: number;
75
88
  }) => ReactNode;
76
- /** Customize the selected label shown in the trigger. */
89
+ /** Customize the selected label shown in the trigger (single mode only). */
77
90
  labelRender?: (option: SelectOption) => ReactNode;
78
91
  /** Wrap/customize the dropdown content. */
79
92
  popupRender?: (menu: ReactNode) => ReactNode;
93
+ /** Custom tag rendering (multi-mode only). */
94
+ tagRender?: (props: TagRenderProps) => ReactNode;
95
+ /** Max visible tags before collapsing into "+N". */
96
+ maxTagCount?: number | 'responsive';
97
+ /** Placeholder for collapsed tags: node or `(omittedValues) => node`. */
98
+ maxTagPlaceholder?: ReactNode | ((omittedValues: SelectOption[]) => ReactNode);
99
+ /** Truncate tag label text to this length. */
100
+ maxTagTextLength?: number;
101
+ /** Max selectable items (multi-mode only). */
102
+ maxCount?: number;
103
+ /** Auto-clear search text after selection (multi-mode only, default: true). */
104
+ autoClearSearchValue?: boolean;
105
+ /** Characters that split pasted/typed text into multiple selections. */
106
+ tokenSeparators?: string[];
107
+ /** Hide already-selected options from the dropdown (multi-mode only). */
108
+ hideSelected?: boolean;
80
109
  /** Force mobile mode (bottom sheet) regardless of screen size */
81
110
  mobile?: boolean;
82
111
  /** Merged onto the trigger root; use to override width etc. */
@@ -88,3 +117,4 @@ export interface SelectProps {
88
117
  export declare function Select(props: SelectProps): import("react/jsx-runtime").JSX.Element;
89
118
  /** Double chevron (↕) for a switcher-style trigger. Pass to `suffixIcon`. */
90
119
  export declare function ChevronsUpDownIcon(): import("react/jsx-runtime").JSX.Element;
120
+ export declare function SearchIcon(): import("react/jsx-runtime").JSX.Element;