@stack-spot/citric-react 0.19.0 → 0.20.0
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/components/Button.d.ts +1 -1
- package/dist/utils/checkbox.d.ts +6 -1
- package/dist/utils/checkbox.d.ts.map +1 -1
- package/dist/utils/checkbox.js +7 -3
- package/dist/utils/checkbox.js.map +1 -1
- package/dist/utils/radio.d.ts +6 -1
- package/dist/utils/radio.d.ts.map +1 -1
- package/dist/utils/radio.js +6 -2
- package/dist/utils/radio.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Button.tsx +1 -1
- package/src/utils/checkbox.ts +13 -3
- package/src/utils/radio.ts +12 -2
|
@@ -4,7 +4,7 @@ export interface BaseButtonProps extends WithColorScheme {
|
|
|
4
4
|
* - contained for buttons with background;
|
|
5
5
|
* - outlined for transparent buttons with borders;
|
|
6
6
|
* - text for buttons with no borders or background;
|
|
7
|
-
* - none for buttons with no borders, background, paddings or any effect
|
|
7
|
+
* - none for buttons with no borders, background, paddings or any state effect (e.g. hover).
|
|
8
8
|
* @default 'contained'
|
|
9
9
|
*/
|
|
10
10
|
appearance?: 'outlined' | 'text' | 'contained' | 'none';
|
package/dist/utils/checkbox.d.ts
CHANGED
|
@@ -22,6 +22,11 @@ export interface CheckboxGroupHookParams<T, F = string> {
|
|
|
22
22
|
* @returns a unique key.
|
|
23
23
|
*/
|
|
24
24
|
renderKey: (option: T) => string | number | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* A function to call whenever the value changes.
|
|
27
|
+
* @param value the new value.
|
|
28
|
+
*/
|
|
29
|
+
onChange?: (value: T[]) => void;
|
|
25
30
|
}
|
|
26
31
|
/**
|
|
27
32
|
* Use this hook to easily implement filtering and selection controls for a checkbox group.
|
|
@@ -56,7 +61,7 @@ export declare function useCheckboxGroupControls<T, F = string>(params: Checkbox
|
|
|
56
61
|
/**
|
|
57
62
|
* Changes the current value, should be passed to the property `onChange` of the checkbox group.
|
|
58
63
|
*/
|
|
59
|
-
setValue:
|
|
64
|
+
setValue: (newValue: T[]) => void;
|
|
60
65
|
/**
|
|
61
66
|
* A function to render a unique key for an option. Should be passed to the property `renderKey` of the checkbox group.
|
|
62
67
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkbox.d.ts","sourceRoot":"","sources":["../../src/utils/checkbox.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,uBAAuB,CAAC,CAAC,EAAE,CAAC,GAAG,MAAM;IACpD;;;;OAIG;IACH,YAAY,CAAC,EAAE,CAAC,EAAE,CAAC;IACnB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,KAAK,OAAO,CAAC;IAChD;;OAEG;IACH,OAAO,EAAE,CAAC,EAAE,CAAC;IACb;;;;OAIG;IACH,SAAS,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"checkbox.d.ts","sourceRoot":"","sources":["../../src/utils/checkbox.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,uBAAuB,CAAC,CAAC,EAAE,CAAC,GAAG,MAAM;IACpD;;;;OAIG;IACH,YAAY,CAAC,EAAE,CAAC,EAAE,CAAC;IACnB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,KAAK,OAAO,CAAC;IAChD;;OAEG;IACH,OAAO,EAAE,CAAC,EAAE,CAAC;IACb;;;;OAIG;IACH,SAAS,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IACtD;;;OAGG;IACH,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,IAAI,CAAC;CACjC;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,MAAM,EAAE,uBAAuB,CAAC,CAAC,EAAE,CAAC,CAAC;IAoCzF;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;yBAzDuC,CAAC,EAAE;IA2D7C;;OAEG;8BA/EqB,MAAM,GAAG,MAAM,GAAG,SAAS;IAiFnD;;;;OAIG;gCAhDmF,CAAC;IAkDvF;;OAEG;;EAGN"}
|
package/dist/utils/checkbox.js
CHANGED
|
@@ -9,6 +9,10 @@ export function useCheckboxGroupControls(params) {
|
|
|
9
9
|
const [value, setValue] = useState(params.initialValue ?? []);
|
|
10
10
|
const [filter, setFilter] = useState();
|
|
11
11
|
const renderKey = params.renderKey ?? defaultRenderKey;
|
|
12
|
+
const handleChange = useCallback((newValue) => {
|
|
13
|
+
setValue(newValue);
|
|
14
|
+
params.onChange?.(newValue);
|
|
15
|
+
}, []);
|
|
12
16
|
const { options, isUnfilteredButChecked } = useMemo(() => {
|
|
13
17
|
if (!params.applyFilter || !filter)
|
|
14
18
|
return { options: params.options, isUnfilteredButChecked: () => false };
|
|
@@ -28,10 +32,10 @@ export function useCheckboxGroupControls(params) {
|
|
|
28
32
|
return { options: [...unfilteredButChecked, ...filtered], isUnfilteredButChecked: (o) => map.has(renderKey(o)) };
|
|
29
33
|
}, [params.options, filter]);
|
|
30
34
|
const selectAll = useCallback(() => {
|
|
31
|
-
|
|
35
|
+
handleChange([...options]);
|
|
32
36
|
}, [options]);
|
|
33
37
|
const removeSelection = useCallback(() => {
|
|
34
|
-
|
|
38
|
+
handleChange([]);
|
|
35
39
|
}, []);
|
|
36
40
|
return {
|
|
37
41
|
/**
|
|
@@ -61,7 +65,7 @@ export function useCheckboxGroupControls(params) {
|
|
|
61
65
|
/**
|
|
62
66
|
* Changes the current value, should be passed to the property `onChange` of the checkbox group.
|
|
63
67
|
*/
|
|
64
|
-
setValue,
|
|
68
|
+
setValue: handleChange,
|
|
65
69
|
/**
|
|
66
70
|
* A function to render a unique key for an option. Should be passed to the property `renderKey` of the checkbox group.
|
|
67
71
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkbox.js","sourceRoot":"","sources":["../../src/utils/checkbox.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"checkbox.js","sourceRoot":"","sources":["../../src/utils/checkbox.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAA;AAiC5C;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CAAgB,MAAqC;IAC3F,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC,YAAY,IAAI,EAAE,CAAC,CAAA;IAC7D,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,EAAiB,CAAA;IACrD,MAAM,SAAS,GAAG,MAAM,CAAC,SAAS,IAAI,gBAAgB,CAAA;IAEtD,MAAM,YAAY,GAAG,WAAW,CAAC,CAAC,QAAa,EAAE,EAAE;QACjD,QAAQ,CAAC,QAAQ,CAAC,CAAA;QAClB,MAAM,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAA;IAC7B,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,MAAM,EAAE,OAAO,EAAE,sBAAsB,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE;QACvD,IAAI,CAAC,MAAM,CAAC,WAAW,IAAI,CAAC,MAAM;YAAE,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,sBAAsB,EAAE,GAAG,EAAE,CAAC,KAAK,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;WAEG;QACH,SAAS;QACT;;WAEG;QACH,eAAe;QACf;;WAEG;QACH,MAAM;QACN;;WAEG;QACH,SAAS,EAAE,SAAS;QACpB;;WAEG;QACH,OAAO;QACP;;WAEG;QACH,KAAK;QACL;;WAEG;QACH,QAAQ,EAAE,YAAY;QACtB;;WAEG;QACH,SAAS;QACT;;;;WAIG;QACH,sBAAsB;QACtB;;WAEG;QACH,aAAa,EAAE,KAAK,CAAC,MAAM,KAAK,OAAO,CAAC,MAAM;KAC/C,CAAA;AACH,CAAC"}
|
package/dist/utils/radio.d.ts
CHANGED
|
@@ -20,6 +20,11 @@ export interface RadioGroupHookParams<T, F = string> {
|
|
|
20
20
|
* @returns a unique key.
|
|
21
21
|
*/
|
|
22
22
|
renderKey: (option: T) => string | number | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* A function to call whenever the value changes.
|
|
25
|
+
* @param value the new value.
|
|
26
|
+
*/
|
|
27
|
+
onChange?: (value: T) => void;
|
|
23
28
|
}
|
|
24
29
|
/**
|
|
25
30
|
* Use this hook to easily implement filtering for a radio group.
|
|
@@ -46,7 +51,7 @@ export declare function useRadioGroupControls<T, F = string>(params: RadioGroupH
|
|
|
46
51
|
/**
|
|
47
52
|
* Changes the current value, should be passed to the property `onChange` of the radio group.
|
|
48
53
|
*/
|
|
49
|
-
setValue:
|
|
54
|
+
setValue: (newValue: T) => void;
|
|
50
55
|
/**
|
|
51
56
|
* A function to render a unique key for an option. Should be passed to the property `renderKey` of the radio group.
|
|
52
57
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"radio.d.ts","sourceRoot":"","sources":["../../src/utils/radio.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,oBAAoB,CAAC,CAAC,EAAE,CAAC,GAAG,MAAM;IACjD;;OAEG;IACH,YAAY,CAAC,EAAE,CAAC,CAAC;IACjB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,KAAK,OAAO,CAAC;IAChD;;OAEG;IACH,OAAO,EAAE,CAAC,EAAE,CAAC;IACb;;;;OAIG;IACH,SAAS,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"radio.d.ts","sourceRoot":"","sources":["../../src/utils/radio.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,oBAAoB,CAAC,CAAC,EAAE,CAAC,GAAG,MAAM;IACjD;;OAEG;IACH,YAAY,CAAC,EAAE,CAAC,CAAC;IACjB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,KAAK,OAAO,CAAC;IAChD;;OAEG;IACH,OAAO,EAAE,CAAC,EAAE,CAAC;IACb;;;;OAIG;IACH,SAAS,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IACtD;;;OAGG;IACH,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;CAC/B;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,MAAM,EAAE,oBAAoB,CAAC,CAAC,EAAE,CAAC,CAAC;IAsBnF;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;yBAnCuC,CAAC;IAqC3C;;OAEG;8BAzDqB,MAAM,GAAG,MAAM,GAAG,SAAS;IA2DnD;;;;OAIG;gCAjC2B,CAAC;EAoClC"}
|
package/dist/utils/radio.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useMemo, useState } from 'react';
|
|
1
|
+
import { useCallback, useMemo, useState } from 'react';
|
|
2
2
|
import { defaultRenderKey } from './options.js';
|
|
3
3
|
/**
|
|
4
4
|
* Use this hook to easily implement filtering for a radio group.
|
|
@@ -9,6 +9,10 @@ export function useRadioGroupControls(params) {
|
|
|
9
9
|
const [value, setValue] = useState(params.initialValue);
|
|
10
10
|
const [filter, setFilter] = useState();
|
|
11
11
|
const renderKey = params.renderKey ?? defaultRenderKey;
|
|
12
|
+
const handleChange = useCallback((newValue) => {
|
|
13
|
+
setValue(newValue);
|
|
14
|
+
params.onChange?.(newValue);
|
|
15
|
+
}, []);
|
|
12
16
|
const { options, isUnfilteredButChecked } = useMemo(() => {
|
|
13
17
|
if (!params.applyFilter || !filter)
|
|
14
18
|
return { options: params.options, isUnfilteredButChecked: () => false };
|
|
@@ -40,7 +44,7 @@ export function useRadioGroupControls(params) {
|
|
|
40
44
|
/**
|
|
41
45
|
* Changes the current value, should be passed to the property `onChange` of the radio group.
|
|
42
46
|
*/
|
|
43
|
-
setValue,
|
|
47
|
+
setValue: handleChange,
|
|
44
48
|
/**
|
|
45
49
|
* A function to render a unique key for an option. Should be passed to the property `renderKey` of the radio group.
|
|
46
50
|
*/
|
package/dist/utils/radio.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"radio.js","sourceRoot":"","sources":["../../src/utils/radio.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"radio.js","sourceRoot":"","sources":["../../src/utils/radio.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAA;AA+B5C;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAgB,MAAkC;IACrF,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC,YAAY,CAAC,CAAA;IACvD,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,EAAiB,CAAA;IACrD,MAAM,SAAS,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O;QACP;;WAEG;QACH,KAAK;QACL;;WAEG;QACH,QAAQ,EAAE,YAAY;QACtB;;WAEG;QACH,SAAS;QACT;;;;WAIG;QACH,sBAAsB;KACvB,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@ export interface BaseButtonProps extends WithColorScheme {
|
|
|
11
11
|
* - contained for buttons with background;
|
|
12
12
|
* - outlined for transparent buttons with borders;
|
|
13
13
|
* - text for buttons with no borders or background;
|
|
14
|
-
* - none for buttons with no borders, background, paddings or any effect
|
|
14
|
+
* - none for buttons with no borders, background, paddings or any state effect (e.g. hover).
|
|
15
15
|
* @default 'contained'
|
|
16
16
|
*/
|
|
17
17
|
appearance?: 'outlined' | 'text' | 'contained' | 'none',
|
package/src/utils/checkbox.ts
CHANGED
|
@@ -25,6 +25,11 @@ export interface CheckboxGroupHookParams<T, F = string> {
|
|
|
25
25
|
* @returns a unique key.
|
|
26
26
|
*/
|
|
27
27
|
renderKey: (option: T) => string | number | undefined,
|
|
28
|
+
/**
|
|
29
|
+
* A function to call whenever the value changes.
|
|
30
|
+
* @param value the new value.
|
|
31
|
+
*/
|
|
32
|
+
onChange?: (value: T[]) => void,
|
|
28
33
|
}
|
|
29
34
|
|
|
30
35
|
/**
|
|
@@ -37,6 +42,11 @@ export function useCheckboxGroupControls<T, F = string>(params: CheckboxGroupHoo
|
|
|
37
42
|
const [filter, setFilter] = useState<F | undefined>()
|
|
38
43
|
const renderKey = params.renderKey ?? defaultRenderKey
|
|
39
44
|
|
|
45
|
+
const handleChange = useCallback((newValue: T[]) => {
|
|
46
|
+
setValue(newValue)
|
|
47
|
+
params.onChange?.(newValue)
|
|
48
|
+
}, [])
|
|
49
|
+
|
|
40
50
|
const { options, isUnfilteredButChecked } = useMemo(() => {
|
|
41
51
|
if (!params.applyFilter || !filter) return { options: params.options, isUnfilteredButChecked: () => false }
|
|
42
52
|
const filtered: T[] = []
|
|
@@ -55,11 +65,11 @@ export function useCheckboxGroupControls<T, F = string>(params: CheckboxGroupHoo
|
|
|
55
65
|
}, [params.options, filter])
|
|
56
66
|
|
|
57
67
|
const selectAll = useCallback(() => {
|
|
58
|
-
|
|
68
|
+
handleChange([...options])
|
|
59
69
|
}, [options])
|
|
60
70
|
|
|
61
71
|
const removeSelection = useCallback(() => {
|
|
62
|
-
|
|
72
|
+
handleChange([])
|
|
63
73
|
}, [])
|
|
64
74
|
|
|
65
75
|
return {
|
|
@@ -90,7 +100,7 @@ export function useCheckboxGroupControls<T, F = string>(params: CheckboxGroupHoo
|
|
|
90
100
|
/**
|
|
91
101
|
* Changes the current value, should be passed to the property `onChange` of the checkbox group.
|
|
92
102
|
*/
|
|
93
|
-
setValue,
|
|
103
|
+
setValue: handleChange,
|
|
94
104
|
/**
|
|
95
105
|
* A function to render a unique key for an option. Should be passed to the property `renderKey` of the checkbox group.
|
|
96
106
|
*/
|
package/src/utils/radio.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useMemo, useState } from 'react'
|
|
1
|
+
import { useCallback, useMemo, useState } from 'react'
|
|
2
2
|
import { defaultRenderKey } from './options'
|
|
3
3
|
|
|
4
4
|
export interface RadioGroupHookParams<T, F = string> {
|
|
@@ -23,6 +23,11 @@ export interface RadioGroupHookParams<T, F = string> {
|
|
|
23
23
|
* @returns a unique key.
|
|
24
24
|
*/
|
|
25
25
|
renderKey: (option: T) => string | number | undefined,
|
|
26
|
+
/**
|
|
27
|
+
* A function to call whenever the value changes.
|
|
28
|
+
* @param value the new value.
|
|
29
|
+
*/
|
|
30
|
+
onChange?: (value: T) => void,
|
|
26
31
|
}
|
|
27
32
|
|
|
28
33
|
/**
|
|
@@ -35,6 +40,11 @@ export function useRadioGroupControls<T, F = string>(params: RadioGroupHookParam
|
|
|
35
40
|
const [filter, setFilter] = useState<F | undefined>()
|
|
36
41
|
const renderKey = params.renderKey ?? defaultRenderKey
|
|
37
42
|
|
|
43
|
+
const handleChange = useCallback((newValue: T) => {
|
|
44
|
+
setValue(newValue)
|
|
45
|
+
params.onChange?.(newValue)
|
|
46
|
+
}, [])
|
|
47
|
+
|
|
38
48
|
const { options, isUnfilteredButChecked } = useMemo(() => {
|
|
39
49
|
if (!params.applyFilter || !filter) return { options: params.options, isUnfilteredButChecked: () => false }
|
|
40
50
|
const valueKey = value ? renderKey(value) : undefined
|
|
@@ -66,7 +76,7 @@ export function useRadioGroupControls<T, F = string>(params: RadioGroupHookParam
|
|
|
66
76
|
/**
|
|
67
77
|
* Changes the current value, should be passed to the property `onChange` of the radio group.
|
|
68
78
|
*/
|
|
69
|
-
setValue,
|
|
79
|
+
setValue: handleChange,
|
|
70
80
|
/**
|
|
71
81
|
* A function to render a unique key for an option. Should be passed to the property `renderKey` of the radio group.
|
|
72
82
|
*/
|