@chayns-components/core 5.0.0-beta.226 → 5.0.0-beta.228
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/lib/components/radio-button/RadioButton.js +9 -4
- package/lib/components/radio-button/RadioButton.js.map +1 -1
- package/lib/components/radio-button/radio-button-group/RadioButtonGroup.d.ts +2 -1
- package/lib/components/radio-button/radio-button-group/RadioButtonGroup.js +2 -0
- package/lib/components/radio-button/radio-button-group/RadioButtonGroup.js.map +1 -1
- package/package.json +2 -2
|
@@ -19,7 +19,8 @@ const RadioButton = _ref => {
|
|
|
19
19
|
} = _ref;
|
|
20
20
|
const {
|
|
21
21
|
selectedRadioButtonId,
|
|
22
|
-
updateSelectedRadioButtonId
|
|
22
|
+
updateSelectedRadioButtonId,
|
|
23
|
+
setSelectedRadioButtonId
|
|
23
24
|
} = (0, _react.useContext)(_RadioButtonGroup.RadioButtonGroupContext);
|
|
24
25
|
const [internalIsChecked, setInternalIsChecked] = (0, _react.useState)(false);
|
|
25
26
|
const [isHovered, setIsHovered] = (0, _react.useState)(false);
|
|
@@ -27,10 +28,14 @@ const RadioButton = _ref => {
|
|
|
27
28
|
const isMarked = isInGroup ? selectedRadioButtonId === id : internalIsChecked;
|
|
28
29
|
const isInitialRenderRef = (0, _react.useRef)(true);
|
|
29
30
|
(0, _react.useEffect)(() => {
|
|
30
|
-
if (isChecked) {
|
|
31
|
-
|
|
31
|
+
if (typeof isChecked === 'boolean') {
|
|
32
|
+
if (typeof setSelectedRadioButtonId === 'function') {
|
|
33
|
+
setSelectedRadioButtonId(isChecked ? id : undefined);
|
|
34
|
+
} else {
|
|
35
|
+
setInternalIsChecked(isChecked);
|
|
36
|
+
}
|
|
32
37
|
}
|
|
33
|
-
}, [isChecked]);
|
|
38
|
+
}, [id, isChecked, setSelectedRadioButtonId]);
|
|
34
39
|
(0, _react.useEffect)(() => {
|
|
35
40
|
if (isInitialRenderRef.current) {
|
|
36
41
|
isInitialRenderRef.current = false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RadioButton.js","names":["_react","_interopRequireWildcard","require","_RadioButtonGroup","_RadioButton","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","RadioButton","_ref","isChecked","label","onChange","id","isDisabled","selectedRadioButtonId","updateSelectedRadioButtonId","useContext","RadioButtonGroupContext","internalIsChecked","setInternalIsChecked","useState","isHovered","setIsHovered","isInGroup","isMarked","isInitialRenderRef","useRef","useEffect","current","handleClick","useCallback","prevState","handleMouseEnter","handleMouseLeave","useMemo","createElement","StyledRadioButton","onClick","onMouseEnter","onMouseLeave","StyledRadioButtonPseudoCheckBox","StyledRadioButtonCheckBoxMark","isSelected","StyledRadioButtonCheckBox","disabled","type","checked","StyledRadioButtonLabel","displayName","_default","exports"],"sources":["../../../src/components/radio-button/RadioButton.tsx"],"sourcesContent":["import React, { FC, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';\nimport { RadioButtonGroupContext } from './radio-button-group/RadioButtonGroup';\nimport {\n StyledRadioButton,\n StyledRadioButtonCheckBox,\n StyledRadioButtonCheckBoxMark,\n StyledRadioButtonLabel,\n StyledRadioButtonPseudoCheckBox,\n} from './RadioButton.styles';\nimport type { RadioButtonItem } from './types';\n\nexport type RadioButtonProps = {\n /**\n * Whether the radio button should be checked.\n */\n isChecked?: boolean;\n /**\n * whether the RadioButton should be shown.\n */\n isDisabled?: boolean;\n /**\n * The id of the radio button.\n */\n id: string;\n /**\n * The label that should be displayed next to the radio button.\n */\n label?: string;\n /**\n * Function to be executed when a button is checked.\n */\n onChange?: (item: RadioButtonItem) => void;\n};\n\nconst RadioButton: FC<RadioButtonProps> = ({\n isChecked,\n label,\n onChange,\n id,\n isDisabled = false,\n}) => {\n const { selectedRadioButtonId, updateSelectedRadioButtonId } =\n useContext(RadioButtonGroupContext);\n\n const [internalIsChecked, setInternalIsChecked] = useState(false);\n const [isHovered, setIsHovered] = useState(false);\n\n const isInGroup = typeof updateSelectedRadioButtonId === 'function';\n\n const isMarked = isInGroup ? selectedRadioButtonId === id : internalIsChecked;\n\n const isInitialRenderRef = useRef(true);\n\n useEffect(() => {\n if (isChecked) {\n setInternalIsChecked(isChecked);\n }\n }, [isChecked]);\n\n useEffect(() => {\n if (isInitialRenderRef.current) {\n isInitialRenderRef.current = false;\n } else if (typeof onChange === 'function') {\n onChange({ isChecked: isMarked, id });\n }\n }, [id, isMarked, onChange]);\n\n const handleClick = useCallback(() => {\n if (isDisabled) {\n return;\n }\n\n if (typeof updateSelectedRadioButtonId === 'function') {\n updateSelectedRadioButtonId(id);\n }\n\n setInternalIsChecked((prevState) => !prevState);\n }, [id, isDisabled, updateSelectedRadioButtonId]);\n\n const handleMouseEnter = useCallback(() => {\n if (!isDisabled) {\n setIsHovered(true);\n }\n }, [isDisabled]);\n\n const handleMouseLeave = () => {\n setIsHovered(false);\n };\n\n return useMemo(\n () => (\n <StyledRadioButton\n isDisabled={isDisabled}\n onClick={handleClick}\n onMouseEnter={handleMouseEnter}\n onMouseLeave={handleMouseLeave}\n >\n <StyledRadioButtonPseudoCheckBox isChecked={isMarked}>\n <StyledRadioButtonCheckBoxMark isHovered={isHovered} isSelected={isMarked} />\n </StyledRadioButtonPseudoCheckBox>\n <StyledRadioButtonCheckBox\n disabled={isDisabled}\n type=\"radio\"\n checked={isMarked}\n onChange={() => {}}\n />\n {label && <StyledRadioButtonLabel>{label}</StyledRadioButtonLabel>}\n </StyledRadioButton>\n ),\n [handleClick, handleMouseEnter, isDisabled, isHovered, isMarked, label]\n );\n};\n\nRadioButton.displayName = 'RadioButton';\n\nexport default RadioButton;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,iBAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,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jB,CAAC,GAAAL,IAAA;EACG,MAAM;IAAEM,qBAAqB;IAAEC;
|
|
1
|
+
{"version":3,"file":"RadioButton.js","names":["_react","_interopRequireWildcard","require","_RadioButtonGroup","_RadioButton","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","RadioButton","_ref","isChecked","label","onChange","id","isDisabled","selectedRadioButtonId","updateSelectedRadioButtonId","setSelectedRadioButtonId","useContext","RadioButtonGroupContext","internalIsChecked","setInternalIsChecked","useState","isHovered","setIsHovered","isInGroup","isMarked","isInitialRenderRef","useRef","useEffect","undefined","current","handleClick","useCallback","prevState","handleMouseEnter","handleMouseLeave","useMemo","createElement","StyledRadioButton","onClick","onMouseEnter","onMouseLeave","StyledRadioButtonPseudoCheckBox","StyledRadioButtonCheckBoxMark","isSelected","StyledRadioButtonCheckBox","disabled","type","checked","StyledRadioButtonLabel","displayName","_default","exports"],"sources":["../../../src/components/radio-button/RadioButton.tsx"],"sourcesContent":["import React, { FC, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';\nimport { RadioButtonGroupContext } from './radio-button-group/RadioButtonGroup';\nimport {\n StyledRadioButton,\n StyledRadioButtonCheckBox,\n StyledRadioButtonCheckBoxMark,\n StyledRadioButtonLabel,\n StyledRadioButtonPseudoCheckBox,\n} from './RadioButton.styles';\nimport type { RadioButtonItem } from './types';\n\nexport type RadioButtonProps = {\n /**\n * Whether the radio button should be checked.\n */\n isChecked?: boolean;\n /**\n * whether the RadioButton should be shown.\n */\n isDisabled?: boolean;\n /**\n * The id of the radio button.\n */\n id: string;\n /**\n * The label that should be displayed next to the radio button.\n */\n label?: string;\n /**\n * Function to be executed when a button is checked.\n */\n onChange?: (item: RadioButtonItem) => void;\n};\n\nconst RadioButton: FC<RadioButtonProps> = ({\n isChecked,\n label,\n onChange,\n id,\n isDisabled = false,\n}) => {\n const { selectedRadioButtonId, updateSelectedRadioButtonId, setSelectedRadioButtonId } =\n useContext(RadioButtonGroupContext);\n\n const [internalIsChecked, setInternalIsChecked] = useState(false);\n const [isHovered, setIsHovered] = useState(false);\n\n const isInGroup = typeof updateSelectedRadioButtonId === 'function';\n\n const isMarked = isInGroup ? selectedRadioButtonId === id : internalIsChecked;\n\n const isInitialRenderRef = useRef(true);\n\n useEffect(() => {\n if (typeof isChecked === 'boolean') {\n if (typeof setSelectedRadioButtonId === 'function') {\n setSelectedRadioButtonId(isChecked ? id : undefined);\n } else {\n setInternalIsChecked(isChecked);\n }\n }\n }, [id, isChecked, setSelectedRadioButtonId]);\n\n useEffect(() => {\n if (isInitialRenderRef.current) {\n isInitialRenderRef.current = false;\n } else if (typeof onChange === 'function') {\n onChange({ isChecked: isMarked, id });\n }\n }, [id, isMarked, onChange]);\n\n const handleClick = useCallback(() => {\n if (isDisabled) {\n return;\n }\n\n if (typeof updateSelectedRadioButtonId === 'function') {\n updateSelectedRadioButtonId(id);\n }\n\n setInternalIsChecked((prevState) => !prevState);\n }, [id, isDisabled, updateSelectedRadioButtonId]);\n\n const handleMouseEnter = useCallback(() => {\n if (!isDisabled) {\n setIsHovered(true);\n }\n }, [isDisabled]);\n\n const handleMouseLeave = () => {\n setIsHovered(false);\n };\n\n return useMemo(\n () => (\n <StyledRadioButton\n isDisabled={isDisabled}\n onClick={handleClick}\n onMouseEnter={handleMouseEnter}\n onMouseLeave={handleMouseLeave}\n >\n <StyledRadioButtonPseudoCheckBox isChecked={isMarked}>\n <StyledRadioButtonCheckBoxMark isHovered={isHovered} isSelected={isMarked} />\n </StyledRadioButtonPseudoCheckBox>\n <StyledRadioButtonCheckBox\n disabled={isDisabled}\n type=\"radio\"\n checked={isMarked}\n onChange={() => {}}\n />\n {label && <StyledRadioButtonLabel>{label}</StyledRadioButtonLabel>}\n </StyledRadioButton>\n ),\n [handleClick, handleMouseEnter, isDisabled, isHovered, isMarked, label]\n );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AS;IAClBd,QAAQ,EAAEA,CAAA,KAAM,CAAC;EAAE,CACtB,CAAC,EACDD,KAAK,iBAAI9B,MAAA,CAAAY,OAAA,CAAA6C,aAAA,CAACrD,YAAA,CAAAiE,sBAAsB,QAAEvC,KAA8B,CAClD,CACtB,EACD,CAACqB,WAAW,EAAEG,gBAAgB,EAAErB,UAAU,EAAES,SAAS,EAAEG,QAAQ,EAAEf,KAAK,CAC1E,CAAC;AACL,CAAC;AAEDH,WAAW,CAAC2C,WAAW,GAAG,aAAa;AAAC,IAAAC,QAAA,GAEzB5C,WAAW;AAAA6C,OAAA,CAAA5D,OAAA,GAAA2D,QAAA"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import React, { FC, ReactNode } from 'react';
|
|
1
|
+
import React, { Dispatch, FC, ReactNode, SetStateAction } from 'react';
|
|
2
2
|
import type { RadioButtonItem } from '../types';
|
|
3
3
|
type IUpdateSelectedRadioButtonId = (id: string) => void;
|
|
4
4
|
interface IRadioButtonGroupContext {
|
|
5
5
|
selectedRadioButtonId: string | undefined;
|
|
6
|
+
setSelectedRadioButtonId?: Dispatch<SetStateAction<string | undefined>>;
|
|
6
7
|
updateSelectedRadioButtonId?: IUpdateSelectedRadioButtonId;
|
|
7
8
|
}
|
|
8
9
|
export declare const RadioButtonGroupContext: React.Context<IRadioButtonGroupContext>;
|
|
@@ -9,6 +9,7 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
9
9
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
10
10
|
const RadioButtonGroupContext = /*#__PURE__*/_react.default.createContext({
|
|
11
11
|
selectedRadioButtonId: undefined,
|
|
12
|
+
setSelectedRadioButtonId: undefined,
|
|
12
13
|
updateSelectedRadioButtonId: undefined
|
|
13
14
|
});
|
|
14
15
|
exports.RadioButtonGroupContext = RadioButtonGroupContext;
|
|
@@ -42,6 +43,7 @@ const RadioButtonGroup = _ref => {
|
|
|
42
43
|
}, [onChange, selectedRadioButtonId]);
|
|
43
44
|
const providerValue = (0, _react.useMemo)(() => ({
|
|
44
45
|
selectedRadioButtonId,
|
|
46
|
+
setSelectedRadioButtonId,
|
|
45
47
|
updateSelectedRadioButtonId
|
|
46
48
|
}), [selectedRadioButtonId, updateSelectedRadioButtonId]);
|
|
47
49
|
return /*#__PURE__*/_react.default.createElement(RadioButtonGroupContext.Provider, {
|
|
@@ -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","updateSelectedRadioButtonId","exports","displayName","RadioButtonGroup","_ref","children","onChange","
|
|
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","onChange","useState","isInitialRenderRef","useRef","useCallback","id","currentSelectedRadioButtonId","useEffect","current","isChecked","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';\nimport type { RadioButtonItem } from '../types';\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 * Function to be executed when a button is checked.\n */\n onChange?: (item: RadioButtonItem) => void;\n};\n\nconst RadioButtonGroup: FC<RadioButtonGroupProps> = ({ children, onChange }) => {\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 } else if (typeof selectedRadioButtonId === 'string') {\n if (typeof onChange === 'function') {\n onChange({ id: selectedRadioButtonId ?? '', isChecked: true });\n }\n }\n }, [onChange, 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,KAAAF,WAAA;AAAA,SAAAH,wBAAAO,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAJ,GAAA,YAAAG,KAAA,CAAAE,GAAA,CAAAL,GAAA,SAAAM,MAAA,WAAAC,qBAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,GAAA,IAAAX,GAAA,QAAAW,GAAA,kBAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAd,GAAA,EAAAW,GAAA,SAAAI,IAAA,GAAAR,qBAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAV,GAAA,EAAAW,GAAA,cAAAI,IAAA,KAAAA,IAAA,CAAAV,GAAA,IAAAU,IAAA,CAAAC,GA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qB,aAArBA,qBAAqB,cAArBA,qBAAqB,GAAI,EAAE;UAAEkB,SAAS,EAAE;QAAK,CAAC,CAAC;MAClE;IACJ;EACJ,CAAC,EAAE,CAACT,QAAQ,EAAET,qBAAqB,CAAC,CAAC;EAErC,MAAMmB,aAAa,GAAG,IAAAC,cAAO,EACzB,OAAO;IACHpB,qBAAqB;IACrBE,wBAAwB;IACxBC;EACJ,CAAC,CAAC,EACF,CAACH,qBAAqB,EAAEG,2BAA2B,CACvD,CAAC;EAED,oBACI/B,MAAA,CAAAU,OAAA,CAAAuC,aAAA,CAACxB,uBAAuB,CAACyB,QAAQ;IAACC,KAAK,EAAEJ;EAAc,GAClDX,QAC6B,CAAC;AAE3C,CAAC;AAEDF,gBAAgB,CAACD,WAAW,GAAG,kBAAkB;AAAC,IAAAmB,QAAA,GAEnClB,gBAAgB;AAAAF,OAAA,CAAAtB,OAAA,GAAA0C,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.228",
|
|
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": "75f6677410b7b2fb99cce79af3dfd533fa717d38"
|
|
69
69
|
}
|