@stack-spot/citric-react 0.27.0 → 0.27.2
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/dist/citric.css +19 -4
- package/dist/components/Select/MultiSelect.d.ts +22 -24
- package/dist/components/Select/MultiSelect.d.ts.map +1 -1
- package/dist/components/Select/MultiSelect.js +24 -3
- package/dist/components/Select/MultiSelect.js.map +1 -1
- package/dist/components/Select/types.d.ts +3 -0
- package/dist/components/Select/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/Select/MultiSelect.tsx +25 -27
- package/src/components/Select/types.ts +3 -0
package/dist/citric.css
CHANGED
|
@@ -1564,10 +1564,25 @@ input[type="range"][data-citric="slider"] {
|
|
|
1564
1564
|
--default-padding: 8px;
|
|
1565
1565
|
header {
|
|
1566
1566
|
outline: none;
|
|
1567
|
-
&:not(.custom)
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1567
|
+
&:not(.custom) {
|
|
1568
|
+
> span, > .row {
|
|
1569
|
+
overflow: hidden;
|
|
1570
|
+
white-space: nowrap;
|
|
1571
|
+
text-overflow: ellipsis;
|
|
1572
|
+
}
|
|
1573
|
+
> .row {
|
|
1574
|
+
position: relative;
|
|
1575
|
+
&:after {
|
|
1576
|
+
content: '';
|
|
1577
|
+
position: absolute;
|
|
1578
|
+
top: 0;
|
|
1579
|
+
bottom: 0;
|
|
1580
|
+
right: 0;
|
|
1581
|
+
width: 50px;
|
|
1582
|
+
pointer-events: none;
|
|
1583
|
+
background: linear-gradient(90deg, transparent 0%, var(--light-300) 100%);;
|
|
1584
|
+
}
|
|
1585
|
+
}
|
|
1571
1586
|
}
|
|
1572
1587
|
}
|
|
1573
1588
|
[data-citric="checkbox-row"] {
|
|
@@ -1,29 +1,7 @@
|
|
|
1
1
|
import { RichSelectProps } from './types.js';
|
|
2
|
-
|
|
3
|
-
* A component that looks like a Select and behaves like a CheckboxGroup. This is a component that lets the user select multiple options
|
|
4
|
-
* in a list.
|
|
5
|
-
*
|
|
6
|
-
* Differently than then the component Select, this does not render the native select of the browser. Instead, it renders a series of
|
|
7
|
-
* checkboxes.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
*
|
|
11
|
-
* ```
|
|
12
|
-
* const options = useMemo(() => [
|
|
13
|
-
* { id: 1, name: 'Option 1' },
|
|
14
|
-
* { id: 2, name: 'Option 2' },
|
|
15
|
-
* { id: 3, name: 'Option 3' },
|
|
16
|
-
* ], [])
|
|
17
|
-
*
|
|
18
|
-
* const [value, setValue] = useState<typeof options>([])
|
|
19
|
-
*
|
|
20
|
-
* return <MultiSelect options={options} renderLabel={o => o.name} renderKey={o => o.id} value={value} setValue={setValue} />
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
interface BaseMultiSelectProps<T> extends Omit<RichSelectProps<T>, 'value' | 'onChange' | 'renderHeader' | 'renderLabel' | 'renderOption' | 'required' | 'onFocus' | 'onBlur'> {
|
|
2
|
+
export interface BaseMultiSelectProps<T> extends Omit<RichSelectProps<T>, 'value' | 'onChange' | 'renderHeader' | 'renderLabel' | 'renderOption' | 'required' | 'onFocus' | 'onBlur'> {
|
|
24
3
|
value: T[];
|
|
25
4
|
onChange: (value: T[]) => void;
|
|
26
|
-
onFocus: (event: React.FocusEvent<HTMLElement, Element>) => void;
|
|
27
5
|
/**
|
|
28
6
|
* A function to render the option in the selectable list.
|
|
29
7
|
*
|
|
@@ -57,6 +35,26 @@ interface BaseMultiSelectProps<T> extends Omit<RichSelectProps<T>, 'value' | 'on
|
|
|
57
35
|
showSelectAll?: boolean;
|
|
58
36
|
}
|
|
59
37
|
export type MultiSelectProps<T> = Omit<React.JSX.IntrinsicElements['div'], 'ref' | 'onChange' | 'onFocus' | 'onBlur'> & BaseMultiSelectProps<T>;
|
|
38
|
+
/**
|
|
39
|
+
* A component that looks like a Select and behaves like a CheckboxGroup. This is a component that lets the user select multiple options
|
|
40
|
+
* in a list.
|
|
41
|
+
*
|
|
42
|
+
* Differently than then the component Select, this does not render the native select of the browser. Instead, it renders a series of
|
|
43
|
+
* checkboxes.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
*
|
|
47
|
+
* ```
|
|
48
|
+
* const options = useMemo(() => [
|
|
49
|
+
* { id: 1, name: 'Option 1' },
|
|
50
|
+
* { id: 2, name: 'Option 2' },
|
|
51
|
+
* { id: 3, name: 'Option 3' },
|
|
52
|
+
* ], [])
|
|
53
|
+
*
|
|
54
|
+
* const [value, setValue] = useState<typeof options>([])
|
|
55
|
+
*
|
|
56
|
+
* return <MultiSelect options={options} renderLabel={o => o.name} renderKey={o => o.id} value={value} setValue={setValue} />
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
60
59
|
export declare const MultiSelect: <T>({ ref, options, value, onChange, renderLabel, renderKey, disabled, loading, renderOption, renderHeader, searchable, maxHeight, style, className, showArrow, placeholder, showSelectAll, ...props }: MultiSelectProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
61
|
-
export {};
|
|
62
60
|
//# sourceMappingURL=MultiSelect.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MultiSelect.d.ts","sourceRoot":"","sources":["../../../src/components/Select/MultiSelect.tsx"],"names":[],"mappings":"AAcA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAEzC
|
|
1
|
+
{"version":3,"file":"MultiSelect.d.ts","sourceRoot":"","sources":["../../../src/components/Select/MultiSelect.tsx"],"names":[],"mappings":"AAcA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAEzC,MAAM,WAAW,oBAAoB,CAAC,CAAC,CAAE,SACvC,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,OAAO,GAAG,UAAU,GAAG,cAAc,GAAG,aAAa,GAAG,cAAc,GAAG,UAAU,GAAG,SAAS,GAAG,QAAQ,CAAC;IACpI,KAAK,EAAE,CAAC,EAAE,CAAC;IACX,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,IAAI,CAAC;IAC/B;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,KAAK,CAAC,SAAS,CAAC;IAC9C;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,KAAK,CAAC,SAAS,CAAC;IAC/C;;;;;;;OAOG;IACH,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,MAAM,CAAC;IACpC;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,iBAAiB,CAAC,KAAK,CAAC,EAAE,KAAK,GAAG,UAAU,GAAG,SAAS,GAAG,QAAQ,CAAC,GACnH,oBAAoB,CAAC,CAAC,CAAC,CAAA;AAEzB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,WAAW,GACD,CAAC,sMAmBnB,gBAAgB,CAAC,CAAC,CAAC,4CA4FvB,CAAA"}
|
|
@@ -13,6 +13,27 @@ import { Input } from '../Input.js';
|
|
|
13
13
|
import { Row } from '../layout.js';
|
|
14
14
|
import { ProgressCircular } from '../ProgressCircular.js';
|
|
15
15
|
import { useDisabledEffect, useFocusEffect, useOpenPanelEffect } from './hooks.js';
|
|
16
|
+
/**
|
|
17
|
+
* A component that looks like a Select and behaves like a CheckboxGroup. This is a component that lets the user select multiple options
|
|
18
|
+
* in a list.
|
|
19
|
+
*
|
|
20
|
+
* Differently than then the component Select, this does not render the native select of the browser. Instead, it renders a series of
|
|
21
|
+
* checkboxes.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
*
|
|
25
|
+
* ```
|
|
26
|
+
* const options = useMemo(() => [
|
|
27
|
+
* { id: 1, name: 'Option 1' },
|
|
28
|
+
* { id: 2, name: 'Option 2' },
|
|
29
|
+
* { id: 3, name: 'Option 3' },
|
|
30
|
+
* ], [])
|
|
31
|
+
*
|
|
32
|
+
* const [value, setValue] = useState<typeof options>([])
|
|
33
|
+
*
|
|
34
|
+
* return <MultiSelect options={options} renderLabel={o => o.name} renderKey={o => o.id} value={value} setValue={setValue} />
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
16
37
|
export const MultiSelect = withRef(function MultiSelect({ ref, options, value = [], onChange, renderLabel = defaultRenderLabel, renderKey = defaultRenderKey, disabled, loading, renderOption, renderHeader, searchable, maxHeight, style, className, showArrow, placeholder, showSelectAll, ...props }) {
|
|
17
38
|
const t = useTranslate(dictionary);
|
|
18
39
|
const _element = useRef(null);
|
|
@@ -32,9 +53,9 @@ export const MultiSelect = withRef(function MultiSelect({ ref, options, value =
|
|
|
32
53
|
const header = useMemo(() => {
|
|
33
54
|
if (value.length === 0)
|
|
34
55
|
return _jsx("span", { className: "placeholder", children: placeholder });
|
|
35
|
-
const
|
|
36
|
-
return ((renderHeader?.(
|
|
37
|
-
?? (renderOption ? _jsx(Row, { gap: "4px", children:
|
|
56
|
+
const reversed = [...value].reverse();
|
|
57
|
+
return ((renderHeader?.(reversed)
|
|
58
|
+
?? (renderOption ? _jsx(Row, { gap: "4px", children: reversed.map(renderOption) }) : _jsx("span", { children: reversed.map(renderLabel).join(', ') })))
|
|
38
59
|
|| _jsx("span", {}));
|
|
39
60
|
}, [value, placeholder]);
|
|
40
61
|
return (_jsxs(CitricComponent, { tag: "div", component: "multi-select", style: maxHeight ? applyCSSVariable(style, 'max-height', `${maxHeight}px`) : style, className: listToClass([className, showArrow === false && 'hide-arrow', open && 'open', focused && 'focused']), ref: element, "aria-busy": loading, ...props, children: [_jsxs("header", { onClick: (e) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MultiSelect.js","sourceRoot":"","sources":["../../../src/components/Select/MultiSelect.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,MAAM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|
|
87
87
|
* Whether or not to render a search field. The search is based on the value returned by `renderLabel`.
|
|
88
88
|
*
|
|
89
|
+
* Attention: when "searchable" is true, make sure to implement `renderLabel` if your options are not strings or number. The search will
|
|
90
|
+
* be performed on the result of this function.
|
|
91
|
+
*
|
|
89
92
|
* @default false
|
|
90
93
|
*/
|
|
91
94
|
searchable?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/components/Select/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAE7C,MAAM,WAAW,iBAAiB,CAAC,CAAC,CAAE,SAAQ,eAAe;IAC3D;;OAEG;IACH,OAAO,EAAE,CAAC,EAAE,CAAC;IACb;;;OAGG;IACH,KAAK,CAAC,EAAE,CAAC,CAAC;IACV;;;OAGG;IACH,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,SAAS,KAAK,IAAI,CAAC;IAC1C;;;;;;;OAOG;IACH,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,SAAS,KAAK,MAAM,CAAC;IAC/C;;;;;;;OAOG;IACH,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IACvD;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;;OAKG;IACH,OAAO,CAAC,EAAE,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,UAAU,CAAC,cAAc,GAAG,iBAAiB,CAAC,CAAC,CAAC;IACnF;;;;;OAKG;IACH,MAAM,CAAC,EAAE,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,UAAU,CAAC,cAAc,GAAG,iBAAiB,CAAC,CAAC,CA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,MAAM,WAAW,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,iBAAiB,CAAC,KAAK,CAAC,EAAE,KAAK,GAAG,UAAU,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -14,32 +14,10 @@ import { ProgressCircular } from '../ProgressCircular'
|
|
|
14
14
|
import { useDisabledEffect, useFocusEffect, useOpenPanelEffect } from './hooks'
|
|
15
15
|
import { RichSelectProps } from './types'
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
* A component that looks like a Select and behaves like a CheckboxGroup. This is a component that lets the user select multiple options
|
|
19
|
-
* in a list.
|
|
20
|
-
*
|
|
21
|
-
* Differently than then the component Select, this does not render the native select of the browser. Instead, it renders a series of
|
|
22
|
-
* checkboxes.
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
*
|
|
26
|
-
* ```
|
|
27
|
-
* const options = useMemo(() => [
|
|
28
|
-
* { id: 1, name: 'Option 1' },
|
|
29
|
-
* { id: 2, name: 'Option 2' },
|
|
30
|
-
* { id: 3, name: 'Option 3' },
|
|
31
|
-
* ], [])
|
|
32
|
-
*
|
|
33
|
-
* const [value, setValue] = useState<typeof options>([])
|
|
34
|
-
*
|
|
35
|
-
* return <MultiSelect options={options} renderLabel={o => o.name} renderKey={o => o.id} value={value} setValue={setValue} />
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
interface BaseMultiSelectProps<T> extends
|
|
17
|
+
export interface BaseMultiSelectProps<T> extends
|
|
39
18
|
Omit<RichSelectProps<T>, 'value' | 'onChange' | 'renderHeader' | 'renderLabel' | 'renderOption' | 'required' | 'onFocus' | 'onBlur'> {
|
|
40
19
|
value: T[],
|
|
41
20
|
onChange: (value: T[]) => void,
|
|
42
|
-
onFocus: (event: React.FocusEvent<HTMLElement, Element>) => void,
|
|
43
21
|
/**
|
|
44
22
|
* A function to render the option in the selectable list.
|
|
45
23
|
*
|
|
@@ -73,10 +51,30 @@ interface BaseMultiSelectProps<T> extends
|
|
|
73
51
|
showSelectAll?: boolean,
|
|
74
52
|
}
|
|
75
53
|
|
|
76
|
-
|
|
77
54
|
export type MultiSelectProps<T> = Omit<React.JSX.IntrinsicElements['div'], 'ref' | 'onChange' | 'onFocus' | 'onBlur'> &
|
|
78
55
|
BaseMultiSelectProps<T>
|
|
79
56
|
|
|
57
|
+
/**
|
|
58
|
+
* A component that looks like a Select and behaves like a CheckboxGroup. This is a component that lets the user select multiple options
|
|
59
|
+
* in a list.
|
|
60
|
+
*
|
|
61
|
+
* Differently than then the component Select, this does not render the native select of the browser. Instead, it renders a series of
|
|
62
|
+
* checkboxes.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
*
|
|
66
|
+
* ```
|
|
67
|
+
* const options = useMemo(() => [
|
|
68
|
+
* { id: 1, name: 'Option 1' },
|
|
69
|
+
* { id: 2, name: 'Option 2' },
|
|
70
|
+
* { id: 3, name: 'Option 3' },
|
|
71
|
+
* ], [])
|
|
72
|
+
*
|
|
73
|
+
* const [value, setValue] = useState<typeof options>([])
|
|
74
|
+
*
|
|
75
|
+
* return <MultiSelect options={options} renderLabel={o => o.name} renderKey={o => o.id} value={value} setValue={setValue} />
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
80
78
|
export const MultiSelect = withRef(
|
|
81
79
|
function MultiSelect<T>({
|
|
82
80
|
ref,
|
|
@@ -118,10 +116,10 @@ export const MultiSelect = withRef(
|
|
|
118
116
|
|
|
119
117
|
const header = useMemo(() => {
|
|
120
118
|
if (value.length === 0) return <span className="placeholder">{placeholder}</span>
|
|
121
|
-
const
|
|
119
|
+
const reversed = [...value].reverse()
|
|
122
120
|
return (
|
|
123
|
-
(renderHeader?.(
|
|
124
|
-
?? (renderOption ? <Row gap="4px">{
|
|
121
|
+
(renderHeader?.(reversed)
|
|
122
|
+
?? (renderOption ? <Row gap="4px">{reversed.map(renderOption)}</Row> : <span>{reversed.map(renderLabel).join(', ')}</span>))
|
|
125
123
|
|| <span></span>
|
|
126
124
|
)}, [value, placeholder])
|
|
127
125
|
|
|
@@ -89,6 +89,9 @@ export interface RichSelectProps<T> extends CommonSelectProps<T> {
|
|
|
89
89
|
/**
|
|
90
90
|
* Whether or not to render a search field. The search is based on the value returned by `renderLabel`.
|
|
91
91
|
*
|
|
92
|
+
* Attention: when "searchable" is true, make sure to implement `renderLabel` if your options are not strings or number. The search will
|
|
93
|
+
* be performed on the result of this function.
|
|
94
|
+
*
|
|
92
95
|
* @default false
|
|
93
96
|
*/
|
|
94
97
|
searchable?: boolean,
|