chili-ui 0.2.0 → 0.3.1
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/chili/components/Radio/RadioGroup.tsx +8 -6
- package/chili/components/Radio/handlers.ts +4 -2
- package/chili/components/Radio/types.ts +3 -1
- package/dist/components/Radio/RadioGroup.js +5 -6
- package/dist/components/Radio/RadioGroup.js.map +1 -1
- package/dist/components/Radio/handlers.d.ts +1 -1
- package/dist/components/Radio/handlers.js +4 -3
- package/dist/components/Radio/handlers.js.map +1 -1
- package/dist/components/Radio/types.d.ts +3 -1
- package/docs/src/app/form-components/radio/_demo/Uncontrolled.tsx +1 -0
- package/docs/src/app/form-components/radio/page.tsx +7 -2
- package/package.json +1 -1
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import { isFunction, isBoolean } from 'lodash';
|
|
3
3
|
import { RadioButton } from './RadioButton';
|
|
4
4
|
import {
|
|
5
|
-
getClassNames, useTheme, useElement, useProps,
|
|
5
|
+
getClassNames, useTheme, useElement, useProps, useValue,
|
|
6
6
|
} from '../../utils';
|
|
7
7
|
import { Div } from '../Div';
|
|
8
8
|
import { COMPONENTS_NAMESPACES } from '../../constants';
|
|
@@ -16,6 +16,7 @@ export const RadioGroup = React.forwardRef((props: RadioGroupProps, ref?: React.
|
|
|
16
16
|
const {
|
|
17
17
|
children,
|
|
18
18
|
className,
|
|
19
|
+
defaultValue,
|
|
19
20
|
name,
|
|
20
21
|
onChange,
|
|
21
22
|
value: valueProp,
|
|
@@ -25,14 +26,15 @@ export const RadioGroup = React.forwardRef((props: RadioGroupProps, ref?: React.
|
|
|
25
26
|
|
|
26
27
|
const theme = useTheme(props.theme, COMPONENTS_NAMESPACES.radio);
|
|
27
28
|
|
|
28
|
-
const [
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
const [value, setValueState] = useValue<string | number | null | undefined>(
|
|
30
|
+
valueProp,
|
|
31
|
+
defaultValue ?? null,
|
|
32
|
+
);
|
|
31
33
|
|
|
32
34
|
const { isValid, InvalidMessage } = useValidation(props, {
|
|
33
35
|
value,
|
|
34
36
|
}, {
|
|
35
|
-
reset: createResetHandler(props, setValueState),
|
|
37
|
+
reset: createResetHandler(props, setValueState, defaultValue),
|
|
36
38
|
});
|
|
37
39
|
|
|
38
40
|
const combinedClassNames = getClassNames(
|
|
@@ -51,7 +53,7 @@ export const RadioGroup = React.forwardRef((props: RadioGroupProps, ref?: React.
|
|
|
51
53
|
Div,
|
|
52
54
|
wrapperRender,
|
|
53
55
|
props,
|
|
54
|
-
{ value
|
|
56
|
+
{ value },
|
|
55
57
|
);
|
|
56
58
|
|
|
57
59
|
return (
|
|
@@ -4,13 +4,15 @@ import type { RadioGroupProps } from './types';
|
|
|
4
4
|
export const createResetHandler = (
|
|
5
5
|
props: RadioGroupProps,
|
|
6
6
|
setValue: SetState<string | number | null | undefined>,
|
|
7
|
+
defaultValue?: string | number | null,
|
|
7
8
|
) => () => {
|
|
8
|
-
|
|
9
|
+
const newValue = defaultValue ?? null;
|
|
10
|
+
setValue(newValue);
|
|
9
11
|
|
|
10
12
|
props.onChange?.({
|
|
11
13
|
component: {
|
|
12
14
|
name: props.name,
|
|
13
|
-
value:
|
|
15
|
+
value: newValue,
|
|
14
16
|
},
|
|
15
17
|
});
|
|
16
18
|
};
|
|
@@ -6,7 +6,7 @@ import type { ValidationProps } from '../Validation/types';
|
|
|
6
6
|
|
|
7
7
|
export interface ResetEvent {
|
|
8
8
|
component: {
|
|
9
|
-
value: null,
|
|
9
|
+
value: string | number | null,
|
|
10
10
|
name?: string,
|
|
11
11
|
},
|
|
12
12
|
}
|
|
@@ -23,6 +23,8 @@ export interface RadioGroupProps extends ValidationProps {
|
|
|
23
23
|
children: React.ReactNode,
|
|
24
24
|
/** Whole component disabled state */
|
|
25
25
|
isDisabled?: boolean,
|
|
26
|
+
/** Default value */
|
|
27
|
+
defaultValue?: string | number | null,
|
|
26
28
|
/** Name */
|
|
27
29
|
name?: string,
|
|
28
30
|
/** Change handler */
|
|
@@ -2,20 +2,19 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { isFunction, isBoolean } from 'lodash';
|
|
4
4
|
import { RadioButton } from './RadioButton';
|
|
5
|
-
import { getClassNames, useTheme, useElement, useProps, } from '../../utils';
|
|
5
|
+
import { getClassNames, useTheme, useElement, useProps, useValue, } from '../../utils';
|
|
6
6
|
import { Div } from '../Div';
|
|
7
7
|
import { COMPONENTS_NAMESPACES } from '../../constants';
|
|
8
8
|
import { createResetHandler } from './handlers';
|
|
9
9
|
import { useValidation } from '../Validation';
|
|
10
10
|
export const RadioGroup = React.forwardRef((props, ref) => {
|
|
11
|
-
const { children, className, name, onChange, value: valueProp, wrapperRender, isDisabled, } = useProps(props);
|
|
11
|
+
const { children, className, defaultValue, name, onChange, value: valueProp, wrapperRender, isDisabled, } = useProps(props);
|
|
12
12
|
const theme = useTheme(props.theme, COMPONENTS_NAMESPACES.radio);
|
|
13
|
-
const [
|
|
14
|
-
const value = valueProp === undefined ? valueState : valueProp;
|
|
13
|
+
const [value, setValueState] = useValue(valueProp, defaultValue !== null && defaultValue !== void 0 ? defaultValue : null);
|
|
15
14
|
const { isValid, InvalidMessage } = useValidation(props, {
|
|
16
15
|
value,
|
|
17
16
|
}, {
|
|
18
|
-
reset: createResetHandler(props, setValueState),
|
|
17
|
+
reset: createResetHandler(props, setValueState, defaultValue),
|
|
19
18
|
});
|
|
20
19
|
const combinedClassNames = getClassNames(theme.wrapper, className);
|
|
21
20
|
const handleChange = React.useCallback((ev) => {
|
|
@@ -23,7 +22,7 @@ export const RadioGroup = React.forwardRef((props, ref) => {
|
|
|
23
22
|
onChange(ev);
|
|
24
23
|
return setValueState(ev.component.value);
|
|
25
24
|
}, [onChange]);
|
|
26
|
-
const Wrapper = useElement('Wrapper', Div, wrapperRender, props, { value
|
|
25
|
+
const Wrapper = useElement('Wrapper', Div, wrapperRender, props, { value });
|
|
27
26
|
return (_jsxs(Wrapper, { className: combinedClassNames, ref: ref, children: [React.Children.toArray(children).map((child) => {
|
|
28
27
|
if (child
|
|
29
28
|
&& React.isValidElement(child)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RadioGroup.js","sourceRoot":"","sources":["../../../chili/components/Radio/RadioGroup.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EACL,aAAa,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"RadioGroup.js","sourceRoot":"","sources":["../../../chili/components/Radio/RadioGroup.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EACL,aAAa,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,GACxD,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAC7B,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAIxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,KAAsB,EAAE,GAA4B,EAAsB,EAAE;IACtH,MAAM,EACJ,QAAQ,EACR,SAAS,EACT,YAAY,EACZ,IAAI,EACJ,QAAQ,EACR,KAAK,EAAE,SAAS,EAChB,aAAa,EACb,UAAU,GACX,GAAG,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AC3F,CAAC;oBACD,OAAO,KAAK,CAAC,YAAY,CAAC,KAAK,EAAE;wBAC/B,IAAI;wBACJ,QAAQ,EAAE,YAAY;wBACtB,UAAU,EAAE,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,UAAU;wBACvE,SAAS,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,KAAK,KAAK;wBACtC,KAAK,kCAAO,KAAK,GAAK,KAAK,CAAC,KAAK,CAAC,KAAK,CAAE;wBAC3C,gEAAgE;wBAChE,8DAA8D;qBACtD,CAAC,CAAC;gBACZ,CAAC;gBACD,OAAO,KAAK,CAAC;YACf,CAAC,CAAC,EACD,CAAC,OAAO,IAAI,KAAC,cAAc,KAAG,IACvB,CACX,CAAC;AACJ,CAAC,CAA8B,CAAC;AAEhC,UAAU,CAAC,WAAW,GAAG,YAAY,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { SetState } from '../../commonTypes';
|
|
2
2
|
import type { RadioGroupProps } from './types';
|
|
3
|
-
export declare const createResetHandler: (props: RadioGroupProps, setValue: SetState<string | number | null | undefined
|
|
3
|
+
export declare const createResetHandler: (props: RadioGroupProps, setValue: SetState<string | number | null | undefined>, defaultValue?: string | number | null) => () => void;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
export const createResetHandler = (props, setValue) => () => {
|
|
1
|
+
export const createResetHandler = (props, setValue, defaultValue) => () => {
|
|
2
2
|
var _a;
|
|
3
|
-
|
|
3
|
+
const newValue = defaultValue !== null && defaultValue !== void 0 ? defaultValue : null;
|
|
4
|
+
setValue(newValue);
|
|
4
5
|
(_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, {
|
|
5
6
|
component: {
|
|
6
7
|
name: props.name,
|
|
7
|
-
value:
|
|
8
|
+
value: newValue,
|
|
8
9
|
},
|
|
9
10
|
});
|
|
10
11
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlers.js","sourceRoot":"","sources":["../../../chili/components/Radio/handlers.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,KAAsB,EACtB,QAAsD,EACtD,EAAE,CAAC,GAAG,EAAE;;IACR,QAAQ,
|
|
1
|
+
{"version":3,"file":"handlers.js","sourceRoot":"","sources":["../../../chili/components/Radio/handlers.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,KAAsB,EACtB,QAAsD,EACtD,YAAqC,EACrC,EAAE,CAAC,GAAG,EAAE;;IACR,MAAM,QAAQ,GAAG,YAAY,aAAZ,YAAY,cAAZ,YAAY,GAAI,IAAI,CAAC;IACtC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAEnB,MAAA,KAAK,CAAC,QAAQ,sDAAG;QACf,SAAS,EAAE;YACT,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,KAAK,EAAE,QAAQ;SAChB;KACF,CAAC,CAAC;AACL,CAAC,CAAC"}
|
|
@@ -5,7 +5,7 @@ import type { CustomRender } from '../../commonTypes';
|
|
|
5
5
|
import type { ValidationProps } from '../Validation/types';
|
|
6
6
|
export interface ResetEvent {
|
|
7
7
|
component: {
|
|
8
|
-
value: null;
|
|
8
|
+
value: string | number | null;
|
|
9
9
|
name?: string;
|
|
10
10
|
};
|
|
11
11
|
}
|
|
@@ -20,6 +20,8 @@ export interface RadioGroupProps extends ValidationProps {
|
|
|
20
20
|
children: React.ReactNode;
|
|
21
21
|
/** Whole component disabled state */
|
|
22
22
|
isDisabled?: boolean;
|
|
23
|
+
/** Default value */
|
|
24
|
+
defaultValue?: string | number | null;
|
|
23
25
|
/** Name */
|
|
24
26
|
name?: string;
|
|
25
27
|
/** Change handler */
|
|
@@ -28,6 +28,11 @@ const RadioPage = () => (
|
|
|
28
28
|
<Td>React.Node</Td>
|
|
29
29
|
<Td>RadioButton elements</Td>
|
|
30
30
|
</tr>
|
|
31
|
+
<tr>
|
|
32
|
+
<Td>defaultValue</Td>
|
|
33
|
+
<Td>number | string | null</Td>
|
|
34
|
+
<Td>Default value</Td>
|
|
35
|
+
</tr>
|
|
31
36
|
<tr>
|
|
32
37
|
<Td>isDisabled</Td>
|
|
33
38
|
<Td>boolean</Td>
|
|
@@ -47,7 +52,7 @@ const RadioPage = () => (
|
|
|
47
52
|
<Td>theme</Td>
|
|
48
53
|
<Td>
|
|
49
54
|
PartialGlobalDefaultTheme[
|
|
50
|
-
typeof COMPONENTS_NAMESPACES.
|
|
55
|
+
typeof COMPONENTS_NAMESPACES.radio
|
|
51
56
|
]
|
|
52
57
|
</Td>
|
|
53
58
|
<Td>...</Td>
|
|
@@ -92,7 +97,7 @@ const RadioPage = () => (
|
|
|
92
97
|
<Td>theme</Td>
|
|
93
98
|
<Td>
|
|
94
99
|
PartialGlobalDefaultTheme[
|
|
95
|
-
typeof COMPONENTS_NAMESPACES.
|
|
100
|
+
typeof COMPONENTS_NAMESPACES.radio
|
|
96
101
|
]
|
|
97
102
|
</Td>
|
|
98
103
|
<Td>...</Td>
|