@chayns-components/core 5.0.0-beta.249 → 5.0.0-beta.252
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,5 +1,4 @@
|
|
|
1
1
|
import React, { Dispatch, FC, ReactNode, SetStateAction } from 'react';
|
|
2
|
-
import type { RadioButtonItem } from '../types';
|
|
3
2
|
type IUpdateSelectedRadioButtonId = (id: string) => void;
|
|
4
3
|
interface IRadioButtonGroupContext {
|
|
5
4
|
selectedRadioButtonId: string | undefined;
|
|
@@ -13,10 +12,6 @@ export type RadioButtonGroupProps = {
|
|
|
13
12
|
* automatically unchecked when an `RadioButton` of the group is checked.
|
|
14
13
|
*/
|
|
15
14
|
children: ReactNode;
|
|
16
|
-
/**
|
|
17
|
-
* Function to be executed when a button is checked.
|
|
18
|
-
*/
|
|
19
|
-
onChange?: (item: RadioButtonItem) => void;
|
|
20
15
|
};
|
|
21
16
|
declare const RadioButtonGroup: FC<RadioButtonGroupProps>;
|
|
22
17
|
export default RadioButtonGroup;
|
|
@@ -16,8 +16,7 @@ exports.RadioButtonGroupContext = RadioButtonGroupContext;
|
|
|
16
16
|
RadioButtonGroupContext.displayName = 'RadioButtonGroupContext';
|
|
17
17
|
const RadioButtonGroup = _ref => {
|
|
18
18
|
let {
|
|
19
|
-
children
|
|
20
|
-
onChange
|
|
19
|
+
children
|
|
21
20
|
} = _ref;
|
|
22
21
|
const [selectedRadioButtonId, setSelectedRadioButtonId] = (0, _react.useState)(undefined);
|
|
23
22
|
const isInitialRenderRef = (0, _react.useRef)(true);
|
|
@@ -32,15 +31,8 @@ const RadioButtonGroup = _ref => {
|
|
|
32
31
|
(0, _react.useEffect)(() => {
|
|
33
32
|
if (isInitialRenderRef.current) {
|
|
34
33
|
isInitialRenderRef.current = false;
|
|
35
|
-
} else if (typeof selectedRadioButtonId === 'string') {
|
|
36
|
-
if (typeof onChange === 'function') {
|
|
37
|
-
onChange({
|
|
38
|
-
id: selectedRadioButtonId !== null && selectedRadioButtonId !== void 0 ? selectedRadioButtonId : '',
|
|
39
|
-
isChecked: true
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
34
|
}
|
|
43
|
-
}, [
|
|
35
|
+
}, [selectedRadioButtonId]);
|
|
44
36
|
const providerValue = (0, _react.useMemo)(() => ({
|
|
45
37
|
selectedRadioButtonId,
|
|
46
38
|
setSelectedRadioButtonId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RadioButtonGroup.js","names":["_react","_interopRequireWildcard","require","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","RadioButtonGroupContext","React","createContext","selectedRadioButtonId","undefined","setSelectedRadioButtonId","updateSelectedRadioButtonId","exports","displayName","RadioButtonGroup","_ref","children","
|
|
1
|
+
{"version":3,"file":"RadioButtonGroup.js","names":["_react","_interopRequireWildcard","require","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","RadioButtonGroupContext","React","createContext","selectedRadioButtonId","undefined","setSelectedRadioButtonId","updateSelectedRadioButtonId","exports","displayName","RadioButtonGroup","_ref","children","useState","isInitialRenderRef","useRef","useCallback","id","currentSelectedRadioButtonId","useEffect","current","providerValue","useMemo","createElement","Provider","value","_default"],"sources":["../../../../src/components/radio-button/radio-button-group/RadioButtonGroup.tsx"],"sourcesContent":["import React, {\n Dispatch,\n FC,\n ReactNode,\n SetStateAction,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\n\ntype IUpdateSelectedRadioButtonId = (id: string) => void;\n\ninterface IRadioButtonGroupContext {\n selectedRadioButtonId: string | undefined;\n setSelectedRadioButtonId?: Dispatch<SetStateAction<string | undefined>>;\n updateSelectedRadioButtonId?: IUpdateSelectedRadioButtonId;\n}\n\nexport const RadioButtonGroupContext = React.createContext<IRadioButtonGroupContext>({\n selectedRadioButtonId: undefined,\n setSelectedRadioButtonId: undefined,\n updateSelectedRadioButtonId: undefined,\n});\n\nRadioButtonGroupContext.displayName = 'RadioButtonGroupContext';\n\nexport type RadioButtonGroupProps = {\n /**\n * The RadioButtons that should be grouped. Radio buttons with the same group are\n * automatically unchecked when an `RadioButton` of the group is checked.\n */\n children: ReactNode;\n};\n\nconst RadioButtonGroup: FC<RadioButtonGroupProps> = ({ children }) => {\n const [selectedRadioButtonId, setSelectedRadioButtonId] =\n useState<IRadioButtonGroupContext['selectedRadioButtonId']>(undefined);\n\n const isInitialRenderRef = useRef(true);\n\n const updateSelectedRadioButtonId = useCallback<IUpdateSelectedRadioButtonId>((id) => {\n setSelectedRadioButtonId((currentSelectedRadioButtonId) => {\n if (currentSelectedRadioButtonId === id) {\n return undefined;\n }\n\n return id;\n });\n }, []);\n\n useEffect(() => {\n if (isInitialRenderRef.current) {\n isInitialRenderRef.current = false;\n }\n }, [selectedRadioButtonId]);\n\n const providerValue = useMemo<IRadioButtonGroupContext>(\n () => ({\n selectedRadioButtonId,\n setSelectedRadioButtonId,\n updateSelectedRadioButtonId,\n }),\n [selectedRadioButtonId, updateSelectedRadioButtonId]\n );\n\n return (\n <RadioButtonGroupContext.Provider value={providerValue}>\n {children}\n </RadioButtonGroupContext.Provider>\n );\n};\n\nRadioButtonGroup.displayName = 'RadioButtonGroup';\n\nexport default RadioButtonGroup;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAUe,SAAAC,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAA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,IAAA;EAC7D,MAAM,CAACP,qBAAqB,EAAEE,wBAAwB,CAAC,GACnD,IAAAO,eAAQ,EAAoDR,SAAS,CAAC;EAE1E,MAAMS,kBAAkB,GAAG,IAAAC,aAAM,EAAC,IAAI,CAAC;EAEvC,MAAMR,2BAA2B,GAAG,IAAAS,kBAAW,EAAgCC,EAAE,IAAK;IAClFX,wBAAwB,CAAEY,4BAA4B,IAAK;MACvD,IAAIA,4BAA4B,KAAKD,EAAE,EAAE;QACrC,OAAOZ,SAAS;MACpB;MAEA,OAAOY,EAAE;IACb,CAAC,CAAC;EACN,CAAC,EAAE,EAAE,CAAC;EAEN,IAAAE,gBAAS,EAAC,MAAM;IACZ,IAAIL,kBAAkB,CAACM,OAAO,EAAE;MAC5BN,kBAAkB,CAACM,OAAO,GAAG,KAAK;IACtC;EACJ,CAAC,EAAE,CAAChB,qBAAqB,CAAC,CAAC;EAE3B,MAAMiB,aAAa,GAAG,IAAAC,cAAO,EACzB,OAAO;IACHlB,qBAAqB;IACrBE,wBAAwB;IACxBC;EACJ,CAAC,CAAC,EACF,CAACH,qBAAqB,EAAEG,2BAA2B,CACvD,CAAC;EAED,oBACI/B,MAAA,CAAAU,OAAA,CAAAqC,aAAA,CAACtB,uBAAuB,CAACuB,QAAQ;IAACC,KAAK,EAAEJ;EAAc,GAClDT,QAC6B,CAAC;AAE3C,CAAC;AAEDF,gBAAgB,CAACD,WAAW,GAAG,kBAAkB;AAAC,IAAAiB,QAAA,GAEnChB,gBAAgB;AAAAF,OAAA,CAAAtB,OAAA,GAAAwC,QAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chayns-components/core",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.252",
|
|
4
4
|
"description": "A set of beautiful React components for developing your own applications with chayns.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"chayns",
|
|
@@ -65,5 +65,5 @@
|
|
|
65
65
|
"publishConfig": {
|
|
66
66
|
"access": "public"
|
|
67
67
|
},
|
|
68
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "5db7cf52c27ed96aca2130ab623c0d5f819c316a"
|
|
69
69
|
}
|