@chayns-components/core 5.0.0-beta.852 → 5.0.0-beta.854

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.
Files changed (24) hide show
  1. package/lib/cjs/components/radio-button/RadioButton.js +60 -8
  2. package/lib/cjs/components/radio-button/RadioButton.js.map +1 -1
  3. package/lib/cjs/components/radio-button/RadioButton.styles.js +36 -5
  4. package/lib/cjs/components/radio-button/RadioButton.styles.js.map +1 -1
  5. package/lib/cjs/components/radio-button/radio-button-group/RadioButtonGroup.js +23 -3
  6. package/lib/cjs/components/radio-button/radio-button-group/RadioButtonGroup.js.map +1 -1
  7. package/lib/cjs/types/radioButton.js.map +1 -1
  8. package/lib/cjs/utils/radioButton.js +25 -0
  9. package/lib/cjs/utils/radioButton.js.map +1 -0
  10. package/lib/esm/components/radio-button/RadioButton.js +62 -10
  11. package/lib/esm/components/radio-button/RadioButton.js.map +1 -1
  12. package/lib/esm/components/radio-button/RadioButton.styles.js +41 -9
  13. package/lib/esm/components/radio-button/RadioButton.styles.js.map +1 -1
  14. package/lib/esm/components/radio-button/radio-button-group/RadioButtonGroup.js +23 -3
  15. package/lib/esm/components/radio-button/radio-button-group/RadioButtonGroup.js.map +1 -1
  16. package/lib/esm/types/radioButton.js.map +1 -1
  17. package/lib/esm/utils/radioButton.js +16 -0
  18. package/lib/esm/utils/radioButton.js.map +1 -0
  19. package/lib/types/components/radio-button/RadioButton.d.ts +8 -0
  20. package/lib/types/components/radio-button/RadioButton.styles.d.ts +8 -7
  21. package/lib/types/components/radio-button/radio-button-group/RadioButtonGroup.d.ts +7 -0
  22. package/lib/types/types/radioButton.d.ts +1 -0
  23. package/lib/types/utils/radioButton.d.ts +2 -0
  24. package/package.json +2 -2
@@ -12,13 +12,17 @@ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return
12
12
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
13
13
  const RadioButton = ({
14
14
  children,
15
+ shouldShowRightElementOnlyOnChecked = false,
15
16
  label,
16
17
  id,
18
+ rightElement,
17
19
  isDisabled = false
18
20
  }) => {
19
21
  const {
20
22
  selectedRadioButtonId,
21
23
  updateSelectedRadioButtonId,
24
+ radioButtonRightElements,
25
+ updateHasRightElement,
22
26
  radioButtonsCanBeUnchecked
23
27
  } = (0, _react.useContext)(_RadioButtonGroup.RadioButtonGroupContext);
24
28
  const [internalIsChecked, setInternalIsChecked] = (0, _react.useState)(false);
@@ -50,27 +54,75 @@ const RadioButton = ({
50
54
  const handleMouseLeave = () => {
51
55
  setIsHovered(false);
52
56
  };
57
+ const radioButtonRightElementMargin = (0, _react.useMemo)(() => {
58
+ if (!radioButtonRightElements) {
59
+ return 'NONE';
60
+ }
61
+ const index = radioButtonRightElements.findIndex(element => element.id === id);
62
+ if (index < 0) {
63
+ return 'NONE';
64
+ }
65
+ const prevButton = radioButtonRightElements[index - 1];
66
+ const currentButton = radioButtonRightElements[index];
67
+ const nextButton = radioButtonRightElements[index + 1];
68
+ if (!(currentButton !== null && currentButton !== void 0 && currentButton.hasRightElement)) {
69
+ return 'NONE';
70
+ }
71
+ switch (true) {
72
+ case (prevButton === null || prevButton === void 0 ? void 0 : prevButton.hasRightElement) && !(nextButton !== null && nextButton !== void 0 && nextButton.hasRightElement):
73
+ return 'TOP';
74
+ case !(prevButton !== null && prevButton !== void 0 && prevButton.hasRightElement) && (nextButton === null || nextButton === void 0 ? void 0 : nextButton.hasRightElement):
75
+ return 'BOTTOM';
76
+ case (currentButton === null || currentButton === void 0 ? void 0 : currentButton.hasRightElement) && !(nextButton !== null && nextButton !== void 0 && nextButton.hasRightElement) && !(prevButton !== null && prevButton !== void 0 && prevButton.hasRightElement):
77
+ return 'NONE';
78
+ default:
79
+ return 'BOTH';
80
+ }
81
+ }, [id, radioButtonRightElements]);
82
+ const shouldShowRightElement = (0, _react.useMemo)(() => {
83
+ if (rightElement) {
84
+ if (shouldShowRightElementOnlyOnChecked) {
85
+ return isMarked;
86
+ }
87
+ return true;
88
+ }
89
+ return false;
90
+ }, [isMarked, rightElement, shouldShowRightElementOnlyOnChecked]);
91
+ (0, _react.useEffect)(() => {
92
+ if (typeof updateHasRightElement === 'function') {
93
+ window.setTimeout(() => {
94
+ updateHasRightElement(id, shouldShowRightElement);
95
+ }, 10);
96
+ }
97
+ }, [id, shouldShowRightElement, updateHasRightElement]);
53
98
  return (0, _react.useMemo)(() => /*#__PURE__*/_react.default.createElement(_RadioButton.StyledRadioButton, {
54
99
  $isDisabled: isDisabled,
55
- onMouseEnter: handleMouseEnter,
56
- onMouseLeave: handleMouseLeave
57
- }, /*#__PURE__*/_react.default.createElement(_RadioButton.StyledRadioButtonWrapper, {
100
+ $radioButtonRightElementMargin: radioButtonRightElementMargin
101
+ }, /*#__PURE__*/_react.default.createElement(_RadioButton.StyledRadioButtonWrapper, null, /*#__PURE__*/_react.default.createElement(_RadioButton.StyledRadioButtonPseudoCheckBox, {
58
102
  $isDisabled: isDisabled,
103
+ $isChecked: isMarked,
59
104
  onClick: handleClick
60
- }, /*#__PURE__*/_react.default.createElement(_RadioButton.StyledRadioButtonPseudoCheckBox, {
61
- $isDisabled: isDisabled,
62
- $isChecked: isMarked
63
105
  }, /*#__PURE__*/_react.default.createElement(_RadioButton.StyledRadioButtonCheckBoxMark, {
106
+ onMouseEnter: handleMouseEnter,
107
+ onMouseLeave: handleMouseLeave,
64
108
  $isHovered: isHovered,
65
109
  $isSelected: isMarked,
66
110
  $isDisabled: isDisabled
67
111
  })), /*#__PURE__*/_react.default.createElement(_RadioButton.StyledRadioButtonCheckBox, {
112
+ onClick: handleClick,
113
+ onMouseEnter: handleMouseEnter,
114
+ onMouseLeave: handleMouseLeave,
68
115
  disabled: isDisabled,
69
116
  $isDisabled: isDisabled,
70
117
  type: "radio",
71
118
  checked: isMarked,
72
119
  onChange: () => {}
73
- }), label && /*#__PURE__*/_react.default.createElement(_RadioButton.StyledRadioButtonLabel, null, label)), children && /*#__PURE__*/_react.default.createElement(_framerMotion.AnimatePresence, {
120
+ }), /*#__PURE__*/_react.default.createElement(_RadioButton.StyledLabelWrapper, null, label && /*#__PURE__*/_react.default.createElement(_RadioButton.StyledRadioButtonLabel, {
121
+ $isDisabled: isDisabled,
122
+ onClick: handleClick,
123
+ onMouseEnter: handleMouseEnter,
124
+ onMouseLeave: handleMouseLeave
125
+ }, label), shouldShowRightElement && rightElement)), children && /*#__PURE__*/_react.default.createElement(_framerMotion.AnimatePresence, {
74
126
  initial: false
75
127
  }, /*#__PURE__*/_react.default.createElement(_RadioButton.StyledMotionRadioButtonChildren, {
76
128
  animate: isMarked ? {
@@ -83,7 +135,7 @@ const RadioButton = ({
83
135
  transition: {
84
136
  duration: 0.2
85
137
  }
86
- }, children))), [children, handleClick, handleMouseEnter, isDisabled, isHovered, isMarked, label]);
138
+ }, children))), [children, handleClick, handleMouseEnter, isDisabled, isHovered, isMarked, label, radioButtonRightElementMargin, rightElement, shouldShowRightElement]);
87
139
  };
88
140
  RadioButton.displayName = 'RadioButton';
89
141
  var _default = exports.default = RadioButton;
@@ -1 +1 @@
1
- {"version":3,"file":"RadioButton.js","names":["_framerMotion","require","_react","_interopRequireWildcard","_RadioButtonGroup","_RadioButton","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","RadioButton","children","label","id","isDisabled","selectedRadioButtonId","updateSelectedRadioButtonId","radioButtonsCanBeUnchecked","useContext","RadioButtonGroupContext","internalIsChecked","setInternalIsChecked","useState","isHovered","setIsHovered","isInGroup","isMarked","uncheckable","handleClick","useCallback","undefined","prev","handleMouseEnter","handleMouseLeave","useMemo","createElement","StyledRadioButton","$isDisabled","onMouseEnter","onMouseLeave","StyledRadioButtonWrapper","onClick","StyledRadioButtonPseudoCheckBox","$isChecked","StyledRadioButtonCheckBoxMark","$isHovered","$isSelected","StyledRadioButtonCheckBox","disabled","type","checked","onChange","StyledRadioButtonLabel","AnimatePresence","initial","StyledMotionRadioButtonChildren","animate","opacity","height","transition","duration","displayName","_default","exports"],"sources":["../../../../src/components/radio-button/RadioButton.tsx"],"sourcesContent":["import { AnimatePresence } from 'framer-motion';\nimport React, { FC, useCallback, useContext, useMemo, useState, type ReactNode } from 'react';\nimport { RadioButtonGroupContext } from './radio-button-group/RadioButtonGroup';\nimport {\n StyledMotionRadioButtonChildren,\n StyledRadioButton,\n StyledRadioButtonCheckBox,\n StyledRadioButtonCheckBoxMark,\n StyledRadioButtonLabel,\n StyledRadioButtonPseudoCheckBox,\n StyledRadioButtonWrapper,\n} from './RadioButton.styles';\n\nexport type RadioButtonProps = {\n /**\n * The children that should be displayed after the RadioButton is checked.\n */\n children?: ReactNode;\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\nconst RadioButton: FC<RadioButtonProps> = ({ children, label, id, isDisabled = false }) => {\n const { selectedRadioButtonId, updateSelectedRadioButtonId, radioButtonsCanBeUnchecked } =\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 uncheckable = radioButtonsCanBeUnchecked;\n\n const handleClick = useCallback(() => {\n if (isDisabled) {\n return;\n }\n\n if (uncheckable) {\n if (updateSelectedRadioButtonId) {\n updateSelectedRadioButtonId(id === selectedRadioButtonId ? undefined : id);\n }\n setInternalIsChecked((prev) => !prev);\n return;\n }\n if (typeof updateSelectedRadioButtonId === 'function') {\n updateSelectedRadioButtonId(id);\n }\n setInternalIsChecked(true);\n }, [id, isDisabled, uncheckable, selectedRadioButtonId, 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 onMouseEnter={handleMouseEnter}\n onMouseLeave={handleMouseLeave}\n >\n <StyledRadioButtonWrapper $isDisabled={isDisabled} onClick={handleClick}>\n <StyledRadioButtonPseudoCheckBox $isDisabled={isDisabled} $isChecked={isMarked}>\n <StyledRadioButtonCheckBoxMark\n $isHovered={isHovered}\n $isSelected={isMarked}\n $isDisabled={isDisabled}\n />\n </StyledRadioButtonPseudoCheckBox>\n <StyledRadioButtonCheckBox\n disabled={isDisabled}\n $isDisabled={isDisabled}\n type=\"radio\"\n checked={isMarked}\n onChange={() => {}}\n />\n {label && <StyledRadioButtonLabel>{label}</StyledRadioButtonLabel>}\n </StyledRadioButtonWrapper>\n {children && (\n <AnimatePresence initial={false}>\n <StyledMotionRadioButtonChildren\n animate={\n isMarked\n ? { opacity: 1, height: 'auto' }\n : { opacity: 0, height: 0 }\n }\n transition={{ duration: 0.2 }}\n >\n {children}\n </StyledMotionRadioButtonChildren>\n </AnimatePresence>\n )}\n </StyledRadioButton>\n ),\n [children, handleClick, handleMouseEnter, isDisabled, isHovered, isMarked, label],\n );\n};\n\nRadioButton.displayName = 'RadioButton';\n\nexport default RadioButton;\n"],"mappings":";;;;;;AAAA,IAAAA,aAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAC,uBAAA,CAAAF,OAAA;AACA,IAAAG,iBAAA,GAAAH,OAAA;AACA,IAAAI,YAAA,GAAAJ,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C;MAAEC,MAAM,EAAE;IAAE,CACjC;IACDC,UAAU,EAAE;MAAEC,QAAQ,EAAE;IAAI;EAAE,GAE7BjD,QAC4B,CACpB,CAEN,CACtB,EACD,CAACA,QAAQ,EAAEiB,WAAW,EAAEI,gBAAgB,EAAElB,UAAU,EAAES,SAAS,EAAEG,QAAQ,EAAEd,KAAK,CACpF,CAAC;AACL,CAAC;AAEDF,WAAW,CAACmD,WAAW,GAAG,aAAa;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAnE,OAAA,GAEzBc,WAAW","ignoreList":[]}
1
+ {"version":3,"file":"RadioButton.js","names":["_framerMotion","require","_react","_interopRequireWildcard","_RadioButtonGroup","_RadioButton","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","RadioButton","children","shouldShowRightElementOnlyOnChecked","label","id","rightElement","isDisabled","selectedRadioButtonId","updateSelectedRadioButtonId","radioButtonRightElements","updateHasRightElement","radioButtonsCanBeUnchecked","useContext","RadioButtonGroupContext","internalIsChecked","setInternalIsChecked","useState","isHovered","setIsHovered","isInGroup","isMarked","uncheckable","handleClick","useCallback","undefined","prev","handleMouseEnter","handleMouseLeave","radioButtonRightElementMargin","useMemo","index","findIndex","element","prevButton","currentButton","nextButton","hasRightElement","shouldShowRightElement","useEffect","window","setTimeout","createElement","StyledRadioButton","$isDisabled","$radioButtonRightElementMargin","StyledRadioButtonWrapper","StyledRadioButtonPseudoCheckBox","$isChecked","onClick","StyledRadioButtonCheckBoxMark","onMouseEnter","onMouseLeave","$isHovered","$isSelected","StyledRadioButtonCheckBox","disabled","type","checked","onChange","StyledLabelWrapper","StyledRadioButtonLabel","AnimatePresence","initial","StyledMotionRadioButtonChildren","animate","opacity","height","transition","duration","displayName","_default","exports"],"sources":["../../../../src/components/radio-button/RadioButton.tsx"],"sourcesContent":["import { AnimatePresence } from 'framer-motion';\nimport React, {\n FC,\n useCallback,\n useContext,\n useMemo,\n useState,\n type ReactNode,\n useEffect,\n} from 'react';\nimport { RadioButtonGroupContext } from './radio-button-group/RadioButtonGroup';\nimport {\n StyledLabelWrapper,\n StyledMotionRadioButtonChildren,\n StyledRadioButton,\n StyledRadioButtonCheckBox,\n StyledRadioButtonCheckBoxMark,\n StyledRadioButtonLabel,\n StyledRadioButtonPseudoCheckBox,\n StyledRadioButtonWrapper,\n} from './RadioButton.styles';\nimport { RadioButtonRightElementMargin } from '../../types/radioButton';\n\nexport type RadioButtonProps = {\n /**\n * The children that should be displayed after the RadioButton is checked.\n */\n children?: ReactNode;\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 * An element that should be displayed on the right side of the label.\n */\n rightElement?: ReactNode;\n /**\n * Whether the rightElement should only be displayed when the RadioButton is checked\n */\n shouldShowRightElementOnlyOnChecked?: boolean;\n};\n\nconst RadioButton: FC<RadioButtonProps> = ({\n children,\n shouldShowRightElementOnlyOnChecked = false,\n label,\n id,\n rightElement,\n isDisabled = false,\n}) => {\n const {\n selectedRadioButtonId,\n updateSelectedRadioButtonId,\n radioButtonRightElements,\n updateHasRightElement,\n radioButtonsCanBeUnchecked,\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 uncheckable = radioButtonsCanBeUnchecked;\n\n const handleClick = useCallback(() => {\n if (isDisabled) {\n return;\n }\n\n if (uncheckable) {\n if (updateSelectedRadioButtonId) {\n updateSelectedRadioButtonId(id === selectedRadioButtonId ? undefined : id);\n }\n setInternalIsChecked((prev) => !prev);\n return;\n }\n if (typeof updateSelectedRadioButtonId === 'function') {\n updateSelectedRadioButtonId(id);\n }\n setInternalIsChecked(true);\n }, [id, isDisabled, uncheckable, selectedRadioButtonId, 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 const radioButtonRightElementMargin: RadioButtonRightElementMargin = useMemo(() => {\n if (!radioButtonRightElements) {\n return 'NONE';\n }\n\n const index = radioButtonRightElements.findIndex((element) => element.id === id);\n\n if (index < 0) {\n return 'NONE';\n }\n\n const prevButton = radioButtonRightElements[index - 1];\n const currentButton = radioButtonRightElements[index];\n const nextButton = radioButtonRightElements[index + 1];\n\n if (!currentButton?.hasRightElement) {\n return 'NONE';\n }\n\n switch (true) {\n case prevButton?.hasRightElement && !nextButton?.hasRightElement:\n return 'TOP';\n case !prevButton?.hasRightElement && nextButton?.hasRightElement:\n return 'BOTTOM';\n case currentButton?.hasRightElement &&\n !nextButton?.hasRightElement &&\n !prevButton?.hasRightElement:\n return 'NONE';\n default:\n return 'BOTH';\n }\n }, [id, radioButtonRightElements]);\n\n const shouldShowRightElement = useMemo(() => {\n if (rightElement) {\n if (shouldShowRightElementOnlyOnChecked) {\n return isMarked;\n }\n\n return true;\n }\n\n return false;\n }, [isMarked, rightElement, shouldShowRightElementOnlyOnChecked]);\n\n useEffect(() => {\n if (typeof updateHasRightElement === 'function') {\n window.setTimeout(() => {\n updateHasRightElement(id, shouldShowRightElement);\n }, 10);\n }\n }, [id, shouldShowRightElement, updateHasRightElement]);\n\n return useMemo(\n () => (\n <StyledRadioButton\n $isDisabled={isDisabled}\n $radioButtonRightElementMargin={radioButtonRightElementMargin}\n >\n <StyledRadioButtonWrapper>\n <StyledRadioButtonPseudoCheckBox\n $isDisabled={isDisabled}\n $isChecked={isMarked}\n onClick={handleClick}\n >\n <StyledRadioButtonCheckBoxMark\n onMouseEnter={handleMouseEnter}\n onMouseLeave={handleMouseLeave}\n $isHovered={isHovered}\n $isSelected={isMarked}\n $isDisabled={isDisabled}\n />\n </StyledRadioButtonPseudoCheckBox>\n <StyledRadioButtonCheckBox\n onClick={handleClick}\n onMouseEnter={handleMouseEnter}\n onMouseLeave={handleMouseLeave}\n disabled={isDisabled}\n $isDisabled={isDisabled}\n type=\"radio\"\n checked={isMarked}\n onChange={() => {}}\n />\n <StyledLabelWrapper>\n {label && (\n <StyledRadioButtonLabel\n $isDisabled={isDisabled}\n onClick={handleClick}\n onMouseEnter={handleMouseEnter}\n onMouseLeave={handleMouseLeave}\n >\n {label}\n </StyledRadioButtonLabel>\n )}\n {shouldShowRightElement && rightElement}\n </StyledLabelWrapper>\n </StyledRadioButtonWrapper>\n {children && (\n <AnimatePresence initial={false}>\n <StyledMotionRadioButtonChildren\n animate={\n isMarked\n ? { opacity: 1, height: 'auto' }\n : { opacity: 0, height: 0 }\n }\n transition={{ duration: 0.2 }}\n >\n {children}\n </StyledMotionRadioButtonChildren>\n </AnimatePresence>\n )}\n </StyledRadioButton>\n ),\n [\n children,\n handleClick,\n handleMouseEnter,\n isDisabled,\n isHovered,\n isMarked,\n label,\n radioButtonRightElementMargin,\n rightElement,\n shouldShowRightElement,\n ],\n );\n};\n\nRadioButton.displayName = 'RadioButton';\n\nexport default RadioButton;\n"],"mappings":";;;;;;AAAA,IAAAA,aAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAC,uBAAA,CAAAF,OAAA;AASA,IAAAG,iBAAA,GAAAH,OAAA;AACA,IAAAI,YAAA,GAAAJ,OAAA;AAS8B,SAAAK,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAJ,wBAAAI,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uB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AAAU,OAAA,CAAAuD,aAAA,CAAC9D,YAAA,CAAAiF,sBAAsB;IACnBjB,WAAW,EAAErC,UAAW;IACxB0C,OAAO,EAAE1B,WAAY;IACrB4B,YAAY,EAAExB,gBAAiB;IAC/ByB,YAAY,EAAExB;EAAiB,GAE9BxB,KACmB,CAC3B,EACAkC,sBAAsB,IAAIhC,YACX,CACE,CAAC,EAC1BJ,QAAQ,iBACLzB,MAAA,CAAAU,OAAA,CAAAuD,aAAA,CAACnE,aAAA,CAAAuF,eAAe;IAACC,OAAO,EAAE;EAAM,gBAC5BtF,MAAA,CAAAU,OAAA,CAAAuD,aAAA,CAAC9D,YAAA,CAAAoF,+BAA+B;IAC5BC,OAAO,EACH5C,QAAQ,GACF;MAAE6C,OAAO,EAAE,CAAC;MAAEC,MAAM,EAAE;IAAO,CAAC,GAC9B;MAAED,OAAO,EAAE,CAAC;MAAEC,MAAM,EAAE;IAAE,CACjC;IACDC,UAAU,EAAE;MAAEC,QAAQ,EAAE;IAAI;EAAE,GAE7BnE,QAC4B,CACpB,CAEN,CACtB,EACD,CACIA,QAAQ,EACRqB,WAAW,EACXI,gBAAgB,EAChBpB,UAAU,EACVW,SAAS,EACTG,QAAQ,EACRjB,KAAK,EACLyB,6BAA6B,EAC7BvB,YAAY,EACZgC,sBAAsB,CAE9B,CAAC;AACL,CAAC;AAEDrC,WAAW,CAACqE,WAAW,GAAG,aAAa;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAArF,OAAA,GAEzBc,WAAW","ignoreList":[]}
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.StyledRadioButtonWrapper = exports.StyledRadioButtonPseudoCheckBox = exports.StyledRadioButtonLabel = exports.StyledRadioButtonCheckBoxMark = exports.StyledRadioButtonCheckBox = exports.StyledRadioButton = exports.StyledMotionRadioButtonChildren = void 0;
6
+ exports.StyledRadioButtonWrapper = exports.StyledRadioButtonPseudoCheckBox = exports.StyledRadioButtonLabel = exports.StyledRadioButtonCheckBoxMark = exports.StyledRadioButtonCheckBox = exports.StyledRadioButton = exports.StyledMotionRadioButtonChildren = exports.StyledLabelWrapper = void 0;
7
7
  var _framerMotion = require("framer-motion");
8
8
  var _styledComponents = _interopRequireWildcard(require("styled-components"));
9
9
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
@@ -17,6 +17,30 @@ const StyledRadioButton = exports.StyledRadioButton = _styledComponents.default.
17
17
  opacity: ${({
18
18
  $isDisabled
19
19
  }) => $isDisabled ? 0.5 : 1};
20
+
21
+ ${({
22
+ $radioButtonRightElementMargin
23
+ }) => {
24
+ switch ($radioButtonRightElementMargin) {
25
+ case 'BOTH':
26
+ return (0, _styledComponents.css)`
27
+ margin: 6px 0;
28
+ `;
29
+ case 'TOP':
30
+ return (0, _styledComponents.css)`
31
+ margin-top: 6px;
32
+ `;
33
+ case 'BOTTOM':
34
+ return (0, _styledComponents.css)`
35
+ margin-bottom: 6px;
36
+ `;
37
+ case 'NONE':
38
+ default:
39
+ return (0, _styledComponents.css)`
40
+ margin: 0;
41
+ `;
42
+ }
43
+ }}
20
44
  `;
21
45
  const StyledRadioButtonWrapper = exports.StyledRadioButtonWrapper = _styledComponents.default.div`
22
46
  display: flex;
@@ -24,10 +48,6 @@ const StyledRadioButtonWrapper = exports.StyledRadioButtonWrapper = _styledCompo
24
48
  position: relative;
25
49
  gap: 5px;
26
50
  user-select: none;
27
-
28
- cursor: ${({
29
- $isDisabled
30
- }) => $isDisabled ? 'default !important' : 'pointer !important'};
31
51
  `;
32
52
  const StyledRadioButtonCheckBox = exports.StyledRadioButtonCheckBox = _styledComponents.default.input`
33
53
  opacity: 0;
@@ -98,6 +118,17 @@ const StyledRadioButtonLabel = exports.StyledRadioButtonLabel = _styledComponent
98
118
  color: ${({
99
119
  theme
100
120
  }) => theme.text};
121
+ margin: 0;
122
+ cursor: ${({
123
+ $isDisabled
124
+ }) => $isDisabled ? 'default !important' : 'pointer !important'};
125
+ `;
126
+ const StyledLabelWrapper = exports.StyledLabelWrapper = _styledComponents.default.div`
127
+ display: flex;
128
+ align-items: center;
129
+ justify-content: space-between;
130
+ width: 100%;
131
+ gap: 12px;
101
132
  `;
102
133
  const StyledMotionRadioButtonChildren = exports.StyledMotionRadioButtonChildren = (0, _styledComponents.default)(_framerMotion.motion.div)`
103
134
  margin-left: 18px;
@@ -1 +1 @@
1
- {"version":3,"file":"RadioButton.styles.js","names":["_framerMotion","require","_styledComponents","_interopRequireWildcard","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","StyledRadioButton","exports","styled","span","$isDisabled","StyledRadioButtonWrapper","div","StyledRadioButtonCheckBox","input","StyledRadioButtonPseudoCheckBox","theme","$isChecked","StyledRadioButtonCheckBoxMark","$isHovered","$isSelected","css","StyledRadioButtonLabel","p","text","StyledMotionRadioButtonChildren","motion"],"sources":["../../../../src/components/radio-button/RadioButton.styles.ts"],"sourcesContent":["import { motion } from 'framer-motion';\nimport styled, { css } from 'styled-components';\nimport type { WithTheme } from '../color-scheme-provider/ColorSchemeProvider';\n\ntype StyledRadioButtonProps = WithTheme<{ $isDisabled: boolean }>;\n\nexport const StyledRadioButton = styled.span<StyledRadioButtonProps>`\n display: flex;\n flex-direction: column;\n\n position: relative;\n\n opacity: ${({ $isDisabled }: StyledRadioButtonProps) => ($isDisabled ? 0.5 : 1)};\n`;\n\ntype StyledRadioButtonWrapperProps = WithTheme<{ $isDisabled: boolean }>;\n\nexport const StyledRadioButtonWrapper = styled.div<StyledRadioButtonWrapperProps>`\n display: flex;\n align-items: center;\n position: relative;\n gap: 5px;\n user-select: none;\n\n cursor: ${({ $isDisabled }: StyledRadioButtonWrapperProps) =>\n $isDisabled ? 'default !important' : 'pointer !important'};\n`;\n\ntype StyledRadioButtonCheckBoxProps = WithTheme<{ $isDisabled: boolean }>;\n\nexport const StyledRadioButtonCheckBox = styled.input<StyledRadioButtonCheckBoxProps>`\n opacity: 0;\n height: 15px;\n width: 15px;\n cursor: ${({ $isDisabled }: StyledRadioButtonCheckBoxProps) =>\n $isDisabled ? 'default !important' : 'pointer !important'};\n`;\n\ntype StyledRadioButtonPseudoCheckBoxProps = WithTheme<{\n $isChecked: boolean;\n $isDisabled: boolean;\n}>;\n\nexport const StyledRadioButtonPseudoCheckBox = styled.div<StyledRadioButtonPseudoCheckBoxProps>`\n background-color: ${({ theme, $isChecked }: StyledRadioButtonPseudoCheckBoxProps) =>\n $isChecked ? theme['secondary-408'] : theme['secondary-403']};\n opacity: 1;\n border: 1px solid\n rgba(${({ theme }: StyledRadioButtonPseudoCheckBoxProps) => theme['409-rgb']}, 0.5);\n width: 15px;\n height: 15px;\n position: absolute;\n border-radius: 100%;\n top: 50%;\n transform: translateY(-50%);\n cursor: ${({ $isDisabled }: StyledRadioButtonPseudoCheckBoxProps) =>\n $isDisabled ? 'default !important' : 'pointer !important'};\n`;\n\ntype StyledRadioButtonCheckBoxMarkProps = WithTheme<{\n $isHovered: boolean;\n $isSelected: boolean;\n $isDisabled: boolean;\n}>;\n\nexport const StyledRadioButtonCheckBoxMark = styled.span<StyledRadioButtonCheckBoxMarkProps>`\n background-color: transparent;\n position: absolute;\n top: 1px;\n left: 3.925px;\n display: inline-block;\n transform: rotate(35deg);\n height: 9px;\n width: 5px;\n border-bottom: 2px solid white;\n border-right: 2px solid white;\n border-top: transparent;\n border-left: transparent;\n z-index: 2;\n cursor: ${({ $isDisabled }: StyledRadioButtonCheckBoxMarkProps) =>\n $isDisabled ? 'default !important' : 'pointer !important'};\n\n ${({ $isHovered, $isSelected }) => {\n if ($isSelected) {\n return css`\n opacity: 1;\n `;\n }\n\n if ($isHovered) {\n return css`\n opacity: 0.5;\n `;\n }\n\n return css`\n opacity: 0;\n `;\n }}\n`;\n\ntype StyledRadioButtonLabelProps = WithTheme<unknown>;\n\nexport const StyledRadioButtonLabel = styled.p<StyledRadioButtonLabelProps>`\n color: ${({ theme }: StyledRadioButtonLabelProps) => theme.text};\n`;\n\ntype StyledMotionRadioButtonChildrenProps = WithTheme<unknown>;\n\nexport const StyledMotionRadioButtonChildren = styled(\n motion.div,\n)<StyledMotionRadioButtonChildrenProps>`\n margin-left: 18px;\n cursor: text;\n overflow: hidden;\n color: ${({ theme }: StyledMotionRadioButtonChildrenProps) => theme.text};\n`;\n"],"mappings":";;;;;;AAAA,IAAAA,aAAA,GAAAC,OAAA;AACA,IAAAC,iBAAA,GAAAC,uBAAA,CAAAF,OAAA;AAAgD,SAAAG,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAF,wBAAAE,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAd,CAAA,oBAAAc,CAAA,OAAAC,cAAA,CAAAC,IAAA,CAAAhB,CAAA,EAAAc,CAAA,SAAAG,CAAA,GAAAP,CAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAb,CAAA,EAAAc,CAAA,UAAAG,CAAA,KAAAA,CAAA,CAAAV,GAAA,IAAAU,CAAA,CAAAC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AAC;AAQM,MAAMQ,6BAA6B,GAAAX,OAAA,CAAAW,6BAAA,GAAGV,yBAAM,CAACC,IAAwC;AAC5F;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,cAAc,CAAC;EAAEC;AAAgD,CAAC,KAC1DA,WAAW,GAAG,oBAAoB,GAAG,oBAAoB;AACjE;AACA,MAAM,CAAC;EAAES,UAAU;EAAEC;AAAY,CAAC,KAAK;EAC/B,IAAIA,WAAW,EAAE;IACb,OAAO,IAAAC,qBAAG;AACtB;AACA,aAAa;EACL;EAEA,IAAIF,UAAU,EAAE;IACZ,OAAO,IAAAE,qBAAG;AACtB;AACA,aAAa;EACL;EAEA,OAAO,IAAAA,qBAAG;AAClB;AACA,SAAS;AACL,CAAC;AACL,CAAC;AAIM,MAAMC,sBAAsB,GAAAf,OAAA,CAAAe,sBAAA,GAAGd,yBAAM,CAACe,CAA8B;AAC3E,aAAa,CAAC;EAAEP;AAAmC,CAAC,KAAKA,KAAK,CAACQ,IAAI;AACnE,CAAC;AAIM,MAAMC,+BAA+B,GAAAlB,OAAA,CAAAkB,+BAAA,GAAG,IAAAjB,yBAAM,EACjDkB,oBAAM,CAACd,GACX,CAAuC;AACvC;AACA;AACA;AACA,aAAa,CAAC;EAAEI;AAA4C,CAAC,KAAKA,KAAK,CAACQ,IAAI;AAC5E,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"RadioButton.styles.js","names":["_framerMotion","require","_styledComponents","_interopRequireWildcard","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","StyledRadioButton","exports","styled","span","$isDisabled","$radioButtonRightElementMargin","css","StyledRadioButtonWrapper","div","StyledRadioButtonCheckBox","input","StyledRadioButtonPseudoCheckBox","theme","$isChecked","StyledRadioButtonCheckBoxMark","$isHovered","$isSelected","StyledRadioButtonLabel","p","text","StyledLabelWrapper","StyledMotionRadioButtonChildren","motion"],"sources":["../../../../src/components/radio-button/RadioButton.styles.ts"],"sourcesContent":["import { motion } from 'framer-motion';\nimport styled, { css } from 'styled-components';\nimport type { WithTheme } from '../color-scheme-provider/ColorSchemeProvider';\nimport { RadioButtonRightElementMargin } from '../../types/radioButton';\n\ntype StyledRadioButtonProps = WithTheme<{\n $isDisabled: boolean;\n $radioButtonRightElementMargin: RadioButtonRightElementMargin;\n}>;\n\nexport const StyledRadioButton = styled.span<StyledRadioButtonProps>`\n display: flex;\n flex-direction: column;\n\n position: relative;\n\n opacity: ${({ $isDisabled }: StyledRadioButtonProps) => ($isDisabled ? 0.5 : 1)};\n\n ${({ $radioButtonRightElementMargin }: StyledRadioButtonProps) => {\n switch ($radioButtonRightElementMargin) {\n case 'BOTH':\n return css`\n margin: 6px 0;\n `;\n case 'TOP':\n return css`\n margin-top: 6px;\n `;\n case 'BOTTOM':\n return css`\n margin-bottom: 6px;\n `;\n case 'NONE':\n default:\n return css`\n margin: 0;\n `;\n }\n }}\n`;\n\nexport const StyledRadioButtonWrapper = styled.div`\n display: flex;\n align-items: center;\n position: relative;\n gap: 5px;\n user-select: none;\n`;\n\ntype StyledRadioButtonCheckBoxProps = WithTheme<{ $isDisabled: boolean }>;\n\nexport const StyledRadioButtonCheckBox = styled.input<StyledRadioButtonCheckBoxProps>`\n opacity: 0;\n height: 15px;\n width: 15px;\n cursor: ${({ $isDisabled }: StyledRadioButtonCheckBoxProps) =>\n $isDisabled ? 'default !important' : 'pointer !important'};\n`;\n\ntype StyledRadioButtonPseudoCheckBoxProps = WithTheme<{\n $isChecked: boolean;\n $isDisabled: boolean;\n}>;\n\nexport const StyledRadioButtonPseudoCheckBox = styled.div<StyledRadioButtonPseudoCheckBoxProps>`\n background-color: ${({ theme, $isChecked }: StyledRadioButtonPseudoCheckBoxProps) =>\n $isChecked ? theme['secondary-408'] : theme['secondary-403']};\n opacity: 1;\n border: 1px solid\n rgba(${({ theme }: StyledRadioButtonPseudoCheckBoxProps) => theme['409-rgb']}, 0.5);\n width: 15px;\n height: 15px;\n position: absolute;\n border-radius: 100%;\n top: 50%;\n transform: translateY(-50%);\n cursor: ${({ $isDisabled }: StyledRadioButtonPseudoCheckBoxProps) =>\n $isDisabled ? 'default !important' : 'pointer !important'};\n`;\n\ntype StyledRadioButtonCheckBoxMarkProps = WithTheme<{\n $isHovered: boolean;\n $isSelected: boolean;\n $isDisabled: boolean;\n}>;\n\nexport const StyledRadioButtonCheckBoxMark = styled.span<StyledRadioButtonCheckBoxMarkProps>`\n background-color: transparent;\n position: absolute;\n top: 1px;\n left: 3.925px;\n display: inline-block;\n transform: rotate(35deg);\n height: 9px;\n width: 5px;\n border-bottom: 2px solid white;\n border-right: 2px solid white;\n border-top: transparent;\n border-left: transparent;\n z-index: 2;\n cursor: ${({ $isDisabled }: StyledRadioButtonCheckBoxMarkProps) =>\n $isDisabled ? 'default !important' : 'pointer !important'};\n\n ${({ $isHovered, $isSelected }) => {\n if ($isSelected) {\n return css`\n opacity: 1;\n `;\n }\n\n if ($isHovered) {\n return css`\n opacity: 0.5;\n `;\n }\n\n return css`\n opacity: 0;\n `;\n }}\n`;\n\ntype StyledRadioButtonLabelProps = WithTheme<{ $isDisabled: boolean }>;\n\nexport const StyledRadioButtonLabel = styled.p<StyledRadioButtonLabelProps>`\n color: ${({ theme }: StyledRadioButtonLabelProps) => theme.text};\n margin: 0;\n cursor: ${({ $isDisabled }: StyledRadioButtonLabelProps) =>\n $isDisabled ? 'default !important' : 'pointer !important'};\n`;\n\nexport const StyledLabelWrapper = styled.div`\n display: flex;\n align-items: center;\n justify-content: space-between;\n width: 100%;\n gap: 12px;\n`;\n\ntype StyledMotionRadioButtonChildrenProps = WithTheme<unknown>;\n\nexport const StyledMotionRadioButtonChildren = styled(\n motion.div,\n)<StyledMotionRadioButtonChildrenProps>`\n margin-left: 18px;\n cursor: text;\n overflow: hidden;\n color: ${({ theme }: StyledMotionRadioButtonChildrenProps) => theme.text};\n`;\n"],"mappings":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BAAM,CAACC,IAAwC;AAC5F;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,cAAc,CAAC;EAAEC;AAAgD,CAAC,KAC1DA,WAAW,GAAG,oBAAoB,GAAG,oBAAoB;AACjE;AACA,MAAM,CAAC;EAAEW,UAAU;EAAEC;AAAY,CAAC,KAAK;EAC/B,IAAIA,WAAW,EAAE;IACb,OAAO,IAAAV,qBAAG;AACtB;AACA,aAAa;EACL;EAEA,IAAIS,UAAU,EAAE;IACZ,OAAO,IAAAT,qBAAG;AACtB;AACA,aAAa;EACL;EAEA,OAAO,IAAAA,qBAAG;AAClB;AACA,SAAS;AACL,CAAC;AACL,CAAC;AAIM,MAAMW,sBAAsB,GAAAhB,OAAA,CAAAgB,sBAAA,GAAGf,yBAAM,CAACgB,CAA8B;AAC3E,aAAa,CAAC;EAAEN;AAAmC,CAAC,KAAKA,KAAK,CAACO,IAAI;AACnE;AACA,cAAc,CAAC;EAAEf;AAAyC,CAAC,KACnDA,WAAW,GAAG,oBAAoB,GAAG,oBAAoB;AACjE,CAAC;AAEM,MAAMgB,kBAAkB,GAAAnB,OAAA,CAAAmB,kBAAA,GAAGlB,yBAAM,CAACM,GAAG;AAC5C;AACA;AACA;AACA;AACA;AACA,CAAC;AAIM,MAAMa,+BAA+B,GAAApB,OAAA,CAAAoB,+BAAA,GAAG,IAAAnB,yBAAM,EACjDoB,oBAAM,CAACd,GACX,CAAuC;AACvC;AACA;AACA;AACA,aAAa,CAAC;EAAEI;AAA4C,CAAC,KAAKA,KAAK,CAACO,IAAI;AAC5E,CAAC","ignoreList":[]}
@@ -5,12 +5,15 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = exports.RadioButtonGroupContext = void 0;
7
7
  var _react = _interopRequireWildcard(require("react"));
8
+ var _radioButton = require("../../../utils/radioButton");
8
9
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
9
10
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
10
11
  const RadioButtonGroupContext = exports.RadioButtonGroupContext = /*#__PURE__*/_react.default.createContext({
11
12
  selectedRadioButtonId: undefined,
12
13
  updateSelectedRadioButtonId: undefined,
13
- radioButtonsCanBeUnchecked: false
14
+ radioButtonsCanBeUnchecked: false,
15
+ radioButtonRightElements: [],
16
+ updateHasRightElement: undefined
14
17
  });
15
18
  RadioButtonGroupContext.displayName = 'RadioButtonGroupContext';
16
19
  const RadioButtonGroup = /*#__PURE__*/(0, _react.forwardRef)(({
@@ -20,6 +23,7 @@ const RadioButtonGroup = /*#__PURE__*/(0, _react.forwardRef)(({
20
23
  onSelect
21
24
  }, ref) => {
22
25
  const [selectedRadioButtonId, setSelectedRadioButtonId] = (0, _react.useState)(undefined);
26
+ const [radioButtonRightElements, setRadioButtonRightElements] = (0, _react.useState)([]);
23
27
  const isInitialRenderRef = (0, _react.useRef)(true);
24
28
  (0, _react.useEffect)(() => {
25
29
  setSelectedRadioButtonId(selectedId);
@@ -30,6 +34,20 @@ const RadioButtonGroup = /*#__PURE__*/(0, _react.forwardRef)(({
30
34
  }
31
35
  setSelectedRadioButtonId(id);
32
36
  }, [onSelect]);
37
+ const updateHasRightElement = (0, _react.useCallback)((id, hasRightElement) => {
38
+ setRadioButtonRightElements(prevState => prevState.map(prev => id === prev.id ? {
39
+ id,
40
+ hasRightElement
41
+ } : prev));
42
+ }, []);
43
+ (0, _react.useEffect)(() => {
44
+ const ids = (0, _radioButton.getRadioButtonOrder)(children);
45
+ const rightElements = ids.map(id => ({
46
+ id,
47
+ hasRightElement: false
48
+ }));
49
+ setRadioButtonRightElements(rightElements);
50
+ }, [children]);
33
51
  (0, _react.useImperativeHandle)(ref, () => ({
34
52
  updateSelectedRadioButtonId
35
53
  }), [updateSelectedRadioButtonId]);
@@ -41,8 +59,10 @@ const RadioButtonGroup = /*#__PURE__*/(0, _react.forwardRef)(({
41
59
  const providerValue = (0, _react.useMemo)(() => ({
42
60
  selectedRadioButtonId,
43
61
  updateSelectedRadioButtonId,
44
- radioButtonsCanBeUnchecked: canUncheckRadioButtons
45
- }), [canUncheckRadioButtons, selectedRadioButtonId, updateSelectedRadioButtonId]);
62
+ radioButtonsCanBeUnchecked: canUncheckRadioButtons,
63
+ updateHasRightElement,
64
+ radioButtonRightElements
65
+ }), [canUncheckRadioButtons, radioButtonRightElements, selectedRadioButtonId, updateHasRightElement, updateSelectedRadioButtonId]);
46
66
  return /*#__PURE__*/_react.default.createElement(RadioButtonGroupContext.Provider, {
47
67
  value: providerValue
48
68
  }, children);
@@ -1 +1 @@
1
- {"version":3,"file":"RadioButtonGroup.js","names":["_react","_interopRequireWildcard","require","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","RadioButtonGroupContext","exports","React","createContext","selectedRadioButtonId","undefined","updateSelectedRadioButtonId","radioButtonsCanBeUnchecked","displayName","RadioButtonGroup","forwardRef","children","canUncheckRadioButtons","selectedId","onSelect","ref","setSelectedRadioButtonId","useState","isInitialRenderRef","useRef","useEffect","useCallback","id","useImperativeHandle","current","providerValue","useMemo","createElement","Provider","value","_default"],"sources":["../../../../../src/components/radio-button/radio-button-group/RadioButtonGroup.tsx"],"sourcesContent":["import React, {\n forwardRef,\n ReactNode,\n useCallback,\n useEffect,\n useImperativeHandle,\n useMemo,\n useRef,\n useState,\n} from 'react';\n\ntype IUpdateSelectedRadioButtonId = (id: string | undefined) => void;\n\ninterface IRadioButtonGroupContext {\n selectedRadioButtonId: string | undefined;\n updateSelectedRadioButtonId?: IUpdateSelectedRadioButtonId;\n radioButtonsCanBeUnchecked?: boolean;\n}\n\nexport const RadioButtonGroupContext = React.createContext<IRadioButtonGroupContext>({\n selectedRadioButtonId: undefined,\n updateSelectedRadioButtonId: undefined,\n radioButtonsCanBeUnchecked: false,\n});\n\nRadioButtonGroupContext.displayName = 'RadioButtonGroupContext';\n\nexport type RadioButtonGroupRef = {\n updateSelectedRadioButtonId: IUpdateSelectedRadioButtonId;\n};\n\nexport type RadioButtonGroupProps = {\n /**\n * Whether the RadioButtons can be unchecked.\n */\n canUncheckRadioButtons?: boolean;\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 an id is selected.\n */\n onSelect?: (id?: string) => void;\n /**\n * The id of the current selected RadioButton.\n */\n selectedId?: string;\n};\n\nconst RadioButtonGroup = forwardRef<RadioButtonGroupRef, RadioButtonGroupProps>(\n ({ children, canUncheckRadioButtons, selectedId, onSelect }, ref) => {\n const [selectedRadioButtonId, setSelectedRadioButtonId] =\n useState<IRadioButtonGroupContext['selectedRadioButtonId']>(undefined);\n\n const isInitialRenderRef = useRef(true);\n\n useEffect(() => {\n setSelectedRadioButtonId(selectedId);\n }, [selectedId]);\n\n const updateSelectedRadioButtonId = useCallback<IUpdateSelectedRadioButtonId>(\n (id) => {\n if (typeof onSelect === 'function') {\n onSelect(id);\n }\n\n setSelectedRadioButtonId(id);\n },\n [onSelect],\n );\n\n useImperativeHandle(\n ref,\n () => ({\n updateSelectedRadioButtonId,\n }),\n [updateSelectedRadioButtonId],\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 updateSelectedRadioButtonId,\n radioButtonsCanBeUnchecked: canUncheckRadioButtons,\n }),\n [canUncheckRadioButtons, selectedRadioButtonId, updateSelectedRadioButtonId],\n );\n\n return (\n <RadioButtonGroupContext.Provider value={providerValue}>\n {children}\n </RadioButtonGroupContext.Provider>\n );\n },\n);\n\nRadioButtonGroup.displayName = 'RadioButtonGroup';\n\nexport default RadioButtonGroup;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AASe,SAAAC,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAH,wBAAAG,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAd,CAAA,oBAAAc,CAAA,OAAAC,cAAA,CAAAC,IAAA,CAAAhB,CAAA,EAAAc,CAAA,SAAAG,CAAA,GAAAP,CAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAb,CAAA,EAAAc,CAAA,UAAAG,CAAA,KAAAA,CAAA,CAAAV,GAAA,IAAAU,CAAA,CAAAC,GAAA,IAAAP,MAAA,CAAAC,cAAA,CAAAJ,CAAA,EAAAM,CAAA,EAAAG,CAAA,IAAAT,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J,CAAC,EAAE,CAACpB,qBAAqB,CAAC,CAAC;EAE3B,MAAMqB,aAAa,GAAG,IAAAC,cAAO,EACzB,OAAO;IACHtB,qBAAqB;IACrBE,2BAA2B;IAC3BC,0BAA0B,EAAEK;EAChC,CAAC,CAAC,EACF,CAACA,sBAAsB,EAAER,qBAAqB,EAAEE,2BAA2B,CAC/E,CAAC;EAED,oBACI7B,MAAA,CAAAS,OAAA,CAAAyC,aAAA,CAAC3B,uBAAuB,CAAC4B,QAAQ;IAACC,KAAK,EAAEJ;EAAc,GAClDd,QAC6B,CAAC;AAE3C,CACJ,CAAC;AAEDF,gBAAgB,CAACD,WAAW,GAAG,kBAAkB;AAAC,IAAAsB,QAAA,GAAA7B,OAAA,CAAAf,OAAA,GAEnCuB,gBAAgB","ignoreList":[]}
1
+ {"version":3,"file":"RadioButtonGroup.js","names":["_react","_interopRequireWildcard","require","_radioButton","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","RadioButtonGroupContext","exports","React","createContext","selectedRadioButtonId","undefined","updateSelectedRadioButtonId","radioButtonsCanBeUnchecked","radioButtonRightElements","updateHasRightElement","displayName","RadioButtonGroup","forwardRef","children","canUncheckRadioButtons","selectedId","onSelect","ref","setSelectedRadioButtonId","useState","setRadioButtonRightElements","isInitialRenderRef","useRef","useEffect","useCallback","id","hasRightElement","prevState","map","prev","ids","getRadioButtonOrder","rightElements","useImperativeHandle","current","providerValue","useMemo","createElement","Provider","value","_default"],"sources":["../../../../../src/components/radio-button/radio-button-group/RadioButtonGroup.tsx"],"sourcesContent":["import React, {\n forwardRef,\n ReactNode,\n useCallback,\n useEffect,\n useImperativeHandle,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { getRadioButtonOrder } from '../../../utils/radioButton';\n\ntype IUpdateSelectedRadioButtonId = (id: string | undefined) => void;\n\ntype IUpdateHasRightElement = (id: string, hasRightElement: boolean) => void;\n\ntype IRadioButtonRightElements = { id: string; hasRightElement: boolean }[];\n\ninterface IRadioButtonGroupContext {\n selectedRadioButtonId: string | undefined;\n updateSelectedRadioButtonId?: IUpdateSelectedRadioButtonId;\n radioButtonRightElements: IRadioButtonRightElements;\n updateHasRightElement?: IUpdateHasRightElement;\n radioButtonsCanBeUnchecked?: boolean;\n}\n\nexport const RadioButtonGroupContext = React.createContext<IRadioButtonGroupContext>({\n selectedRadioButtonId: undefined,\n updateSelectedRadioButtonId: undefined,\n radioButtonsCanBeUnchecked: false,\n radioButtonRightElements: [],\n updateHasRightElement: undefined,\n});\n\nRadioButtonGroupContext.displayName = 'RadioButtonGroupContext';\n\nexport type RadioButtonGroupRef = {\n updateSelectedRadioButtonId: IUpdateSelectedRadioButtonId;\n};\n\nexport type RadioButtonGroupProps = {\n /**\n * Whether the RadioButtons can be unchecked.\n */\n canUncheckRadioButtons?: boolean;\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 an id is selected.\n */\n onSelect?: (id?: string) => void;\n /**\n * The id of the current selected RadioButton.\n */\n selectedId?: string;\n};\n\nconst RadioButtonGroup = forwardRef<RadioButtonGroupRef, RadioButtonGroupProps>(\n ({ children, canUncheckRadioButtons, selectedId, onSelect }, ref) => {\n const [selectedRadioButtonId, setSelectedRadioButtonId] =\n useState<IRadioButtonGroupContext['selectedRadioButtonId']>(undefined);\n const [radioButtonRightElements, setRadioButtonRightElements] =\n useState<IRadioButtonRightElements>([]);\n\n const isInitialRenderRef = useRef(true);\n\n useEffect(() => {\n setSelectedRadioButtonId(selectedId);\n }, [selectedId]);\n\n const updateSelectedRadioButtonId = useCallback<IUpdateSelectedRadioButtonId>(\n (id) => {\n if (typeof onSelect === 'function') {\n onSelect(id);\n }\n\n setSelectedRadioButtonId(id);\n },\n [onSelect],\n );\n\n const updateHasRightElement = useCallback<IUpdateHasRightElement>((id, hasRightElement) => {\n setRadioButtonRightElements((prevState) =>\n prevState.map((prev) => (id === prev.id ? { id, hasRightElement } : prev)),\n );\n }, []);\n\n useEffect(() => {\n const ids = getRadioButtonOrder(children);\n\n const rightElements = ids.map((id) => ({ id, hasRightElement: false }));\n\n setRadioButtonRightElements(rightElements);\n }, [children]);\n\n useImperativeHandle(\n ref,\n () => ({\n updateSelectedRadioButtonId,\n }),\n [updateSelectedRadioButtonId],\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 updateSelectedRadioButtonId,\n radioButtonsCanBeUnchecked: canUncheckRadioButtons,\n updateHasRightElement,\n radioButtonRightElements,\n }),\n [\n canUncheckRadioButtons,\n radioButtonRightElements,\n selectedRadioButtonId,\n updateHasRightElement,\n updateSelectedRadioButtonId,\n ],\n );\n\n return (\n <RadioButtonGroupContext.Provider value={providerValue}>\n {children}\n </RadioButtonGroupContext.Provider>\n );\n },\n);\n\nRadioButtonGroup.displayName = 'RadioButtonGroup';\n\nexport default RadioButtonGroup;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAUA,IAAAC,YAAA,GAAAD,OAAA;AAAiE,SAAAE,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAJ,wBAAAI,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,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,CAAC,EAAE,CAAC9B,qBAAqB,CAAC,CAAC;EAE3B,MAAM+B,aAAa,GAAG,IAAAC,cAAO,EACzB,OAAO;IACHhC,qBAAqB;IACrBE,2BAA2B;IAC3BC,0BAA0B,EAAEO,sBAAsB;IAClDL,qBAAqB;IACrBD;EACJ,CAAC,CAAC,EACF,CACIM,sBAAsB,EACtBN,wBAAwB,EACxBJ,qBAAqB,EACrBK,qBAAqB,EACrBH,2BAA2B,CAEnC,CAAC;EAED,oBACI9B,MAAA,CAAAU,OAAA,CAAAmD,aAAA,CAACrC,uBAAuB,CAACsC,QAAQ;IAACC,KAAK,EAAEJ;EAAc,GAClDtB,QAC6B,CAAC;AAE3C,CACJ,CAAC;AAEDF,gBAAgB,CAACD,WAAW,GAAG,kBAAkB;AAAC,IAAA8B,QAAA,GAAAvC,OAAA,CAAAf,OAAA,GAEnCyB,gBAAgB","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"radioButton.js","names":[],"sources":["../../../src/types/radioButton.ts"],"sourcesContent":["export interface RadioButtonItem {\n id: string;\n isChecked: boolean;\n}\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"file":"radioButton.js","names":[],"sources":["../../../src/types/radioButton.ts"],"sourcesContent":["export interface RadioButtonItem {\n id: string;\n isChecked: boolean;\n}\n\nexport type RadioButtonRightElementMargin = 'NONE' | 'TOP' | 'BOTTOM' | 'BOTH';\n"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getRadioButtonOrder = void 0;
7
+ var _react = _interopRequireWildcard(require("react"));
8
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
9
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
10
+ const getRadioButtonOrder = children => {
11
+ const radioButtonIds = [];
12
+ _react.Children.forEach(children, child => {
13
+ if (/*#__PURE__*/_react.default.isValidElement(child)) {
14
+ const {
15
+ id
16
+ } = child.props;
17
+ if (typeof id === 'string') {
18
+ radioButtonIds.push(id);
19
+ }
20
+ }
21
+ });
22
+ return radioButtonIds;
23
+ };
24
+ exports.getRadioButtonOrder = getRadioButtonOrder;
25
+ //# sourceMappingURL=radioButton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"radioButton.js","names":["_react","_interopRequireWildcard","require","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","getRadioButtonOrder","children","radioButtonIds","Children","forEach","child","React","isValidElement","id","props","push","exports"],"sources":["../../../src/utils/radioButton.ts"],"sourcesContent":["import React, { Children, ReactNode } from 'react';\n\nexport const getRadioButtonOrder = (children: ReactNode): string[] => {\n const radioButtonIds: string[] = [];\n\n Children.forEach(children, (child) => {\n if (React.isValidElement<{ id?: string }>(child)) {\n const { id } = child.props;\n\n if (typeof id === 'string') {\n radioButtonIds.push(id);\n }\n }\n });\n\n return radioButtonIds;\n};\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAAmD,SAAAC,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,C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,CAACF,EAAE,CAAC;MAC3B;IACJ;EACJ,CAAC,CAAC;EAEF,OAAON,cAAc;AACzB,CAAC;AAACS,OAAA,CAAAX,mBAAA,GAAAA,mBAAA","ignoreList":[]}
@@ -1,17 +1,21 @@
1
1
  import { AnimatePresence } from 'framer-motion';
2
- import React, { useCallback, useContext, useMemo, useState } from 'react';
2
+ import React, { useCallback, useContext, useMemo, useState, useEffect } from 'react';
3
3
  import { RadioButtonGroupContext } from './radio-button-group/RadioButtonGroup';
4
- import { StyledMotionRadioButtonChildren, StyledRadioButton, StyledRadioButtonCheckBox, StyledRadioButtonCheckBoxMark, StyledRadioButtonLabel, StyledRadioButtonPseudoCheckBox, StyledRadioButtonWrapper } from './RadioButton.styles';
4
+ import { StyledLabelWrapper, StyledMotionRadioButtonChildren, StyledRadioButton, StyledRadioButtonCheckBox, StyledRadioButtonCheckBoxMark, StyledRadioButtonLabel, StyledRadioButtonPseudoCheckBox, StyledRadioButtonWrapper } from './RadioButton.styles';
5
5
  const RadioButton = _ref => {
6
6
  let {
7
7
  children,
8
+ shouldShowRightElementOnlyOnChecked = false,
8
9
  label,
9
10
  id,
11
+ rightElement,
10
12
  isDisabled = false
11
13
  } = _ref;
12
14
  const {
13
15
  selectedRadioButtonId,
14
16
  updateSelectedRadioButtonId,
17
+ radioButtonRightElements,
18
+ updateHasRightElement,
15
19
  radioButtonsCanBeUnchecked
16
20
  } = useContext(RadioButtonGroupContext);
17
21
  const [internalIsChecked, setInternalIsChecked] = useState(false);
@@ -43,27 +47,75 @@ const RadioButton = _ref => {
43
47
  const handleMouseLeave = () => {
44
48
  setIsHovered(false);
45
49
  };
50
+ const radioButtonRightElementMargin = useMemo(() => {
51
+ if (!radioButtonRightElements) {
52
+ return 'NONE';
53
+ }
54
+ const index = radioButtonRightElements.findIndex(element => element.id === id);
55
+ if (index < 0) {
56
+ return 'NONE';
57
+ }
58
+ const prevButton = radioButtonRightElements[index - 1];
59
+ const currentButton = radioButtonRightElements[index];
60
+ const nextButton = radioButtonRightElements[index + 1];
61
+ if (!currentButton?.hasRightElement) {
62
+ return 'NONE';
63
+ }
64
+ switch (true) {
65
+ case prevButton?.hasRightElement && !nextButton?.hasRightElement:
66
+ return 'TOP';
67
+ case !prevButton?.hasRightElement && nextButton?.hasRightElement:
68
+ return 'BOTTOM';
69
+ case currentButton?.hasRightElement && !nextButton?.hasRightElement && !prevButton?.hasRightElement:
70
+ return 'NONE';
71
+ default:
72
+ return 'BOTH';
73
+ }
74
+ }, [id, radioButtonRightElements]);
75
+ const shouldShowRightElement = useMemo(() => {
76
+ if (rightElement) {
77
+ if (shouldShowRightElementOnlyOnChecked) {
78
+ return isMarked;
79
+ }
80
+ return true;
81
+ }
82
+ return false;
83
+ }, [isMarked, rightElement, shouldShowRightElementOnlyOnChecked]);
84
+ useEffect(() => {
85
+ if (typeof updateHasRightElement === 'function') {
86
+ window.setTimeout(() => {
87
+ updateHasRightElement(id, shouldShowRightElement);
88
+ }, 10);
89
+ }
90
+ }, [id, shouldShowRightElement, updateHasRightElement]);
46
91
  return useMemo(() => /*#__PURE__*/React.createElement(StyledRadioButton, {
47
92
  $isDisabled: isDisabled,
48
- onMouseEnter: handleMouseEnter,
49
- onMouseLeave: handleMouseLeave
50
- }, /*#__PURE__*/React.createElement(StyledRadioButtonWrapper, {
93
+ $radioButtonRightElementMargin: radioButtonRightElementMargin
94
+ }, /*#__PURE__*/React.createElement(StyledRadioButtonWrapper, null, /*#__PURE__*/React.createElement(StyledRadioButtonPseudoCheckBox, {
51
95
  $isDisabled: isDisabled,
96
+ $isChecked: isMarked,
52
97
  onClick: handleClick
53
- }, /*#__PURE__*/React.createElement(StyledRadioButtonPseudoCheckBox, {
54
- $isDisabled: isDisabled,
55
- $isChecked: isMarked
56
98
  }, /*#__PURE__*/React.createElement(StyledRadioButtonCheckBoxMark, {
99
+ onMouseEnter: handleMouseEnter,
100
+ onMouseLeave: handleMouseLeave,
57
101
  $isHovered: isHovered,
58
102
  $isSelected: isMarked,
59
103
  $isDisabled: isDisabled
60
104
  })), /*#__PURE__*/React.createElement(StyledRadioButtonCheckBox, {
105
+ onClick: handleClick,
106
+ onMouseEnter: handleMouseEnter,
107
+ onMouseLeave: handleMouseLeave,
61
108
  disabled: isDisabled,
62
109
  $isDisabled: isDisabled,
63
110
  type: "radio",
64
111
  checked: isMarked,
65
112
  onChange: () => {}
66
- }), label && /*#__PURE__*/React.createElement(StyledRadioButtonLabel, null, label)), children && /*#__PURE__*/React.createElement(AnimatePresence, {
113
+ }), /*#__PURE__*/React.createElement(StyledLabelWrapper, null, label && /*#__PURE__*/React.createElement(StyledRadioButtonLabel, {
114
+ $isDisabled: isDisabled,
115
+ onClick: handleClick,
116
+ onMouseEnter: handleMouseEnter,
117
+ onMouseLeave: handleMouseLeave
118
+ }, label), shouldShowRightElement && rightElement)), children && /*#__PURE__*/React.createElement(AnimatePresence, {
67
119
  initial: false
68
120
  }, /*#__PURE__*/React.createElement(StyledMotionRadioButtonChildren, {
69
121
  animate: isMarked ? {
@@ -76,7 +128,7 @@ const RadioButton = _ref => {
76
128
  transition: {
77
129
  duration: 0.2
78
130
  }
79
- }, children))), [children, handleClick, handleMouseEnter, isDisabled, isHovered, isMarked, label]);
131
+ }, children))), [children, handleClick, handleMouseEnter, isDisabled, isHovered, isMarked, label, radioButtonRightElementMargin, rightElement, shouldShowRightElement]);
80
132
  };
81
133
  RadioButton.displayName = 'RadioButton';
82
134
  export default RadioButton;
@@ -1 +1 @@
1
- {"version":3,"file":"RadioButton.js","names":["AnimatePresence","React","useCallback","useContext","useMemo","useState","RadioButtonGroupContext","StyledMotionRadioButtonChildren","StyledRadioButton","StyledRadioButtonCheckBox","StyledRadioButtonCheckBoxMark","StyledRadioButtonLabel","StyledRadioButtonPseudoCheckBox","StyledRadioButtonWrapper","RadioButton","_ref","children","label","id","isDisabled","selectedRadioButtonId","updateSelectedRadioButtonId","radioButtonsCanBeUnchecked","internalIsChecked","setInternalIsChecked","isHovered","setIsHovered","isInGroup","isMarked","uncheckable","handleClick","undefined","prev","handleMouseEnter","handleMouseLeave","createElement","$isDisabled","onMouseEnter","onMouseLeave","onClick","$isChecked","$isHovered","$isSelected","disabled","type","checked","onChange","initial","animate","opacity","height","transition","duration","displayName"],"sources":["../../../../src/components/radio-button/RadioButton.tsx"],"sourcesContent":["import { AnimatePresence } from 'framer-motion';\nimport React, { FC, useCallback, useContext, useMemo, useState, type ReactNode } from 'react';\nimport { RadioButtonGroupContext } from './radio-button-group/RadioButtonGroup';\nimport {\n StyledMotionRadioButtonChildren,\n StyledRadioButton,\n StyledRadioButtonCheckBox,\n StyledRadioButtonCheckBoxMark,\n StyledRadioButtonLabel,\n StyledRadioButtonPseudoCheckBox,\n StyledRadioButtonWrapper,\n} from './RadioButton.styles';\n\nexport type RadioButtonProps = {\n /**\n * The children that should be displayed after the RadioButton is checked.\n */\n children?: ReactNode;\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\nconst RadioButton: FC<RadioButtonProps> = ({ children, label, id, isDisabled = false }) => {\n const { selectedRadioButtonId, updateSelectedRadioButtonId, radioButtonsCanBeUnchecked } =\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 uncheckable = radioButtonsCanBeUnchecked;\n\n const handleClick = useCallback(() => {\n if (isDisabled) {\n return;\n }\n\n if (uncheckable) {\n if (updateSelectedRadioButtonId) {\n updateSelectedRadioButtonId(id === selectedRadioButtonId ? undefined : id);\n }\n setInternalIsChecked((prev) => !prev);\n return;\n }\n if (typeof updateSelectedRadioButtonId === 'function') {\n updateSelectedRadioButtonId(id);\n }\n setInternalIsChecked(true);\n }, [id, isDisabled, uncheckable, selectedRadioButtonId, 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 onMouseEnter={handleMouseEnter}\n onMouseLeave={handleMouseLeave}\n >\n <StyledRadioButtonWrapper $isDisabled={isDisabled} onClick={handleClick}>\n <StyledRadioButtonPseudoCheckBox $isDisabled={isDisabled} $isChecked={isMarked}>\n <StyledRadioButtonCheckBoxMark\n $isHovered={isHovered}\n $isSelected={isMarked}\n $isDisabled={isDisabled}\n />\n </StyledRadioButtonPseudoCheckBox>\n <StyledRadioButtonCheckBox\n disabled={isDisabled}\n $isDisabled={isDisabled}\n type=\"radio\"\n checked={isMarked}\n onChange={() => {}}\n />\n {label && <StyledRadioButtonLabel>{label}</StyledRadioButtonLabel>}\n </StyledRadioButtonWrapper>\n {children && (\n <AnimatePresence initial={false}>\n <StyledMotionRadioButtonChildren\n animate={\n isMarked\n ? { opacity: 1, height: 'auto' }\n : { opacity: 0, height: 0 }\n }\n transition={{ duration: 0.2 }}\n >\n {children}\n </StyledMotionRadioButtonChildren>\n </AnimatePresence>\n )}\n </StyledRadioButton>\n ),\n [children, handleClick, handleMouseEnter, isDisabled, isHovered, isMarked, label],\n );\n};\n\nRadioButton.displayName = 'RadioButton';\n\nexport default RadioButton;\n"],"mappings":"AAAA,SAASA,eAAe,QAAQ,eAAe;AAC/C,OAAOC,KAAK,IAAQC,WAAW,EAAEC,UAAU,EAAEC,OAAO,EAAEC,QAAQ,QAAwB,OAAO;AAC7F,SAASC,uBAAuB,QAAQ,uCAAuC;AAC/E,SACIC,+BAA+B,EAC/BC,iBAAiB,EACjBC,yBAAyB,EACzBC,6BAA6B,EAC7BC,sBAAsB,EACtBC,+BAA+B,EAC/BC,wBAAwB,QACrB,sBAAsB;AAqB7B,MAAMC,WAAiC,GAAGC,IAAA,IAAiD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EACD,CAACA,QAAQ,EAAEc,WAAW,EAAEG,gBAAgB,EAAEd,UAAU,EAAEM,SAAS,EAAEG,QAAQ,EAAEX,KAAK,CACpF,CAAC;AACL,CAAC;AAEDH,WAAW,CAACuC,WAAW,GAAG,aAAa;AAEvC,eAAevC,WAAW","ignoreList":[]}
1
+ {"version":3,"file":"RadioButton.js","names":["AnimatePresence","React","useCallback","useContext","useMemo","useState","useEffect","RadioButtonGroupContext","StyledLabelWrapper","StyledMotionRadioButtonChildren","StyledRadioButton","StyledRadioButtonCheckBox","StyledRadioButtonCheckBoxMark","StyledRadioButtonLabel","StyledRadioButtonPseudoCheckBox","StyledRadioButtonWrapper","RadioButton","_ref","children","shouldShowRightElementOnlyOnChecked","label","id","rightElement","isDisabled","selectedRadioButtonId","updateSelectedRadioButtonId","radioButtonRightElements","updateHasRightElement","radioButtonsCanBeUnchecked","internalIsChecked","setInternalIsChecked","isHovered","setIsHovered","isInGroup","isMarked","uncheckable","handleClick","undefined","prev","handleMouseEnter","handleMouseLeave","radioButtonRightElementMargin","index","findIndex","element","prevButton","currentButton","nextButton","hasRightElement","shouldShowRightElement","window","setTimeout","createElement","$isDisabled","$radioButtonRightElementMargin","$isChecked","onClick","onMouseEnter","onMouseLeave","$isHovered","$isSelected","disabled","type","checked","onChange","initial","animate","opacity","height","transition","duration","displayName"],"sources":["../../../../src/components/radio-button/RadioButton.tsx"],"sourcesContent":["import { AnimatePresence } from 'framer-motion';\nimport React, {\n FC,\n useCallback,\n useContext,\n useMemo,\n useState,\n type ReactNode,\n useEffect,\n} from 'react';\nimport { RadioButtonGroupContext } from './radio-button-group/RadioButtonGroup';\nimport {\n StyledLabelWrapper,\n StyledMotionRadioButtonChildren,\n StyledRadioButton,\n StyledRadioButtonCheckBox,\n StyledRadioButtonCheckBoxMark,\n StyledRadioButtonLabel,\n StyledRadioButtonPseudoCheckBox,\n StyledRadioButtonWrapper,\n} from './RadioButton.styles';\nimport { RadioButtonRightElementMargin } from '../../types/radioButton';\n\nexport type RadioButtonProps = {\n /**\n * The children that should be displayed after the RadioButton is checked.\n */\n children?: ReactNode;\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 * An element that should be displayed on the right side of the label.\n */\n rightElement?: ReactNode;\n /**\n * Whether the rightElement should only be displayed when the RadioButton is checked\n */\n shouldShowRightElementOnlyOnChecked?: boolean;\n};\n\nconst RadioButton: FC<RadioButtonProps> = ({\n children,\n shouldShowRightElementOnlyOnChecked = false,\n label,\n id,\n rightElement,\n isDisabled = false,\n}) => {\n const {\n selectedRadioButtonId,\n updateSelectedRadioButtonId,\n radioButtonRightElements,\n updateHasRightElement,\n radioButtonsCanBeUnchecked,\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 uncheckable = radioButtonsCanBeUnchecked;\n\n const handleClick = useCallback(() => {\n if (isDisabled) {\n return;\n }\n\n if (uncheckable) {\n if (updateSelectedRadioButtonId) {\n updateSelectedRadioButtonId(id === selectedRadioButtonId ? undefined : id);\n }\n setInternalIsChecked((prev) => !prev);\n return;\n }\n if (typeof updateSelectedRadioButtonId === 'function') {\n updateSelectedRadioButtonId(id);\n }\n setInternalIsChecked(true);\n }, [id, isDisabled, uncheckable, selectedRadioButtonId, 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 const radioButtonRightElementMargin: RadioButtonRightElementMargin = useMemo(() => {\n if (!radioButtonRightElements) {\n return 'NONE';\n }\n\n const index = radioButtonRightElements.findIndex((element) => element.id === id);\n\n if (index < 0) {\n return 'NONE';\n }\n\n const prevButton = radioButtonRightElements[index - 1];\n const currentButton = radioButtonRightElements[index];\n const nextButton = radioButtonRightElements[index + 1];\n\n if (!currentButton?.hasRightElement) {\n return 'NONE';\n }\n\n switch (true) {\n case prevButton?.hasRightElement && !nextButton?.hasRightElement:\n return 'TOP';\n case !prevButton?.hasRightElement && nextButton?.hasRightElement:\n return 'BOTTOM';\n case currentButton?.hasRightElement &&\n !nextButton?.hasRightElement &&\n !prevButton?.hasRightElement:\n return 'NONE';\n default:\n return 'BOTH';\n }\n }, [id, radioButtonRightElements]);\n\n const shouldShowRightElement = useMemo(() => {\n if (rightElement) {\n if (shouldShowRightElementOnlyOnChecked) {\n return isMarked;\n }\n\n return true;\n }\n\n return false;\n }, [isMarked, rightElement, shouldShowRightElementOnlyOnChecked]);\n\n useEffect(() => {\n if (typeof updateHasRightElement === 'function') {\n window.setTimeout(() => {\n updateHasRightElement(id, shouldShowRightElement);\n }, 10);\n }\n }, [id, shouldShowRightElement, updateHasRightElement]);\n\n return useMemo(\n () => (\n <StyledRadioButton\n $isDisabled={isDisabled}\n $radioButtonRightElementMargin={radioButtonRightElementMargin}\n >\n <StyledRadioButtonWrapper>\n <StyledRadioButtonPseudoCheckBox\n $isDisabled={isDisabled}\n $isChecked={isMarked}\n onClick={handleClick}\n >\n <StyledRadioButtonCheckBoxMark\n onMouseEnter={handleMouseEnter}\n onMouseLeave={handleMouseLeave}\n $isHovered={isHovered}\n $isSelected={isMarked}\n $isDisabled={isDisabled}\n />\n </StyledRadioButtonPseudoCheckBox>\n <StyledRadioButtonCheckBox\n onClick={handleClick}\n onMouseEnter={handleMouseEnter}\n onMouseLeave={handleMouseLeave}\n disabled={isDisabled}\n $isDisabled={isDisabled}\n type=\"radio\"\n checked={isMarked}\n onChange={() => {}}\n />\n <StyledLabelWrapper>\n {label && (\n <StyledRadioButtonLabel\n $isDisabled={isDisabled}\n onClick={handleClick}\n onMouseEnter={handleMouseEnter}\n onMouseLeave={handleMouseLeave}\n >\n {label}\n </StyledRadioButtonLabel>\n )}\n {shouldShowRightElement && rightElement}\n </StyledLabelWrapper>\n </StyledRadioButtonWrapper>\n {children && (\n <AnimatePresence initial={false}>\n <StyledMotionRadioButtonChildren\n animate={\n isMarked\n ? { opacity: 1, height: 'auto' }\n : { opacity: 0, height: 0 }\n }\n transition={{ duration: 0.2 }}\n >\n {children}\n </StyledMotionRadioButtonChildren>\n </AnimatePresence>\n )}\n </StyledRadioButton>\n ),\n [\n children,\n handleClick,\n handleMouseEnter,\n isDisabled,\n isHovered,\n isMarked,\n label,\n radioButtonRightElementMargin,\n rightElement,\n shouldShowRightElement,\n ],\n );\n};\n\nRadioButton.displayName = 'RadioButton';\n\nexport default RadioButton;\n"],"mappings":"AAAA,SAASA,eAAe,QAAQ,eAAe;AAC/C,OAAOC,KAAK,IAERC,WAAW,EACXC,UAAU,EACVC,OAAO,EACPC,QAAQ,EAERC,SAAS,QACN,OAAO;AACd,SAASC,uBAAuB,QAAQ,uCAAuC;AAC/E,SACIC,kBAAkB,EAClBC,+BAA+B,EAC/BC,iBAAiB,EACjBC,yBAAyB,EACzBC,6BAA6B,EAC7BC,sBAAsB,EACtBC,+BAA+B,EAC/BC,wBAAwB,QACrB,sBAAsB;AA8B7B,MAAMC,WAAiC,GAAGC,IAAA,IAOpC;EAAA,IAPqC;IACvCC,QAAQ;IACRC,mCAAmC,GAAG,KAAK;IAC3CC,KAAK;IACLC,EAAE;IACFC,YAAY;IACZC,UAAU,GAAG;EACjB,CAAC,GAAAN,IAAA;EACG,MAAM;IACFO,qBAAqB;IACrBC,2BAA2B;IAC3BC,wBAAwB;IACxBC,qBAAqB;IACrBC;EACJ,CAAC,GAAGzB,UAAU,CAACI,uBAAuB,CAAC;EAEvC,MAAM,CAACsB,iBAAiB,EAAEC,oBAAoB,CAAC,GAAGzB,QAAQ,CAAC,KAAK,CAAC;EACjE,MAAM,CAAC0B,SAAS,EAAEC,YAAY,CAAC,GAAG3B,QAAQ,CAAC,KAA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,MAAM,EAAE;IAAO,CAAC,GAC9B;MAAED,OAAO,EAAE,CAAC;MAAEC,MAAM,EAAE;IAAE,CACjC;IACDC,UAAU,EAAE;MAAEC,QAAQ,EAAE;IAAI;EAAE,GAE7BpD,QAC4B,CACpB,CAEN,CACtB,EACD,CACIA,QAAQ,EACRkB,WAAW,EACXG,gBAAgB,EAChBhB,UAAU,EACVQ,SAAS,EACTG,QAAQ,EACRd,KAAK,EACLqB,6BAA6B,EAC7BnB,YAAY,EACZ2B,sBAAsB,CAE9B,CAAC;AACL,CAAC;AAEDjC,WAAW,CAACuD,WAAW,GAAG,aAAa;AAEvC,eAAevD,WAAW","ignoreList":[]}
@@ -12,6 +12,31 @@ export const StyledRadioButton = styled.span`
12
12
  } = _ref;
13
13
  return $isDisabled ? 0.5 : 1;
14
14
  }};
15
+
16
+ ${_ref2 => {
17
+ let {
18
+ $radioButtonRightElementMargin
19
+ } = _ref2;
20
+ switch ($radioButtonRightElementMargin) {
21
+ case 'BOTH':
22
+ return css`
23
+ margin: 6px 0;
24
+ `;
25
+ case 'TOP':
26
+ return css`
27
+ margin-top: 6px;
28
+ `;
29
+ case 'BOTTOM':
30
+ return css`
31
+ margin-bottom: 6px;
32
+ `;
33
+ case 'NONE':
34
+ default:
35
+ return css`
36
+ margin: 0;
37
+ `;
38
+ }
39
+ }}
15
40
  `;
16
41
  export const StyledRadioButtonWrapper = styled.div`
17
42
  display: flex;
@@ -19,13 +44,6 @@ export const StyledRadioButtonWrapper = styled.div`
19
44
  position: relative;
20
45
  gap: 5px;
21
46
  user-select: none;
22
-
23
- cursor: ${_ref2 => {
24
- let {
25
- $isDisabled
26
- } = _ref2;
27
- return $isDisabled ? 'default !important' : 'pointer !important';
28
- }};
29
47
  `;
30
48
  export const StyledRadioButtonCheckBox = styled.input`
31
49
  opacity: 0;
@@ -114,16 +132,30 @@ export const StyledRadioButtonLabel = styled.p`
114
132
  theme
115
133
  } = _ref9;
116
134
  return theme.text;
135
+ }};
136
+ margin: 0;
137
+ cursor: ${_ref10 => {
138
+ let {
139
+ $isDisabled
140
+ } = _ref10;
141
+ return $isDisabled ? 'default !important' : 'pointer !important';
117
142
  }};
118
143
  `;
144
+ export const StyledLabelWrapper = styled.div`
145
+ display: flex;
146
+ align-items: center;
147
+ justify-content: space-between;
148
+ width: 100%;
149
+ gap: 12px;
150
+ `;
119
151
  export const StyledMotionRadioButtonChildren = styled(motion.div)`
120
152
  margin-left: 18px;
121
153
  cursor: text;
122
154
  overflow: hidden;
123
- color: ${_ref10 => {
155
+ color: ${_ref11 => {
124
156
  let {
125
157
  theme
126
- } = _ref10;
158
+ } = _ref11;
127
159
  return theme.text;
128
160
  }};
129
161
  `;
@@ -1 +1 @@
1
- {"version":3,"file":"RadioButton.styles.js","names":["motion","styled","css","StyledRadioButton","span","_ref","$isDisabled","StyledRadioButtonWrapper","div","_ref2","StyledRadioButtonCheckBox","input","_ref3","StyledRadioButtonPseudoCheckBox","_ref4","theme","$isChecked","_ref5","_ref6","StyledRadioButtonCheckBoxMark","_ref7","_ref8","$isHovered","$isSelected","StyledRadioButtonLabel","p","_ref9","text","StyledMotionRadioButtonChildren","_ref10"],"sources":["../../../../src/components/radio-button/RadioButton.styles.ts"],"sourcesContent":["import { motion } from 'framer-motion';\nimport styled, { css } from 'styled-components';\nimport type { WithTheme } from '../color-scheme-provider/ColorSchemeProvider';\n\ntype StyledRadioButtonProps = WithTheme<{ $isDisabled: boolean }>;\n\nexport const StyledRadioButton = styled.span<StyledRadioButtonProps>`\n display: flex;\n flex-direction: column;\n\n position: relative;\n\n opacity: ${({ $isDisabled }: StyledRadioButtonProps) => ($isDisabled ? 0.5 : 1)};\n`;\n\ntype StyledRadioButtonWrapperProps = WithTheme<{ $isDisabled: boolean }>;\n\nexport const StyledRadioButtonWrapper = styled.div<StyledRadioButtonWrapperProps>`\n display: flex;\n align-items: center;\n position: relative;\n gap: 5px;\n user-select: none;\n\n cursor: ${({ $isDisabled }: StyledRadioButtonWrapperProps) =>\n $isDisabled ? 'default !important' : 'pointer !important'};\n`;\n\ntype StyledRadioButtonCheckBoxProps = WithTheme<{ $isDisabled: boolean }>;\n\nexport const StyledRadioButtonCheckBox = styled.input<StyledRadioButtonCheckBoxProps>`\n opacity: 0;\n height: 15px;\n width: 15px;\n cursor: ${({ $isDisabled }: StyledRadioButtonCheckBoxProps) =>\n $isDisabled ? 'default !important' : 'pointer !important'};\n`;\n\ntype StyledRadioButtonPseudoCheckBoxProps = WithTheme<{\n $isChecked: boolean;\n $isDisabled: boolean;\n}>;\n\nexport const StyledRadioButtonPseudoCheckBox = styled.div<StyledRadioButtonPseudoCheckBoxProps>`\n background-color: ${({ theme, $isChecked }: StyledRadioButtonPseudoCheckBoxProps) =>\n $isChecked ? theme['secondary-408'] : theme['secondary-403']};\n opacity: 1;\n border: 1px solid\n rgba(${({ theme }: StyledRadioButtonPseudoCheckBoxProps) => theme['409-rgb']}, 0.5);\n width: 15px;\n height: 15px;\n position: absolute;\n border-radius: 100%;\n top: 50%;\n transform: translateY(-50%);\n cursor: ${({ $isDisabled }: StyledRadioButtonPseudoCheckBoxProps) =>\n $isDisabled ? 'default !important' : 'pointer !important'};\n`;\n\ntype StyledRadioButtonCheckBoxMarkProps = WithTheme<{\n $isHovered: boolean;\n $isSelected: boolean;\n $isDisabled: boolean;\n}>;\n\nexport const StyledRadioButtonCheckBoxMark = styled.span<StyledRadioButtonCheckBoxMarkProps>`\n background-color: transparent;\n position: absolute;\n top: 1px;\n left: 3.925px;\n display: inline-block;\n transform: rotate(35deg);\n height: 9px;\n width: 5px;\n border-bottom: 2px solid white;\n border-right: 2px solid white;\n border-top: transparent;\n border-left: transparent;\n z-index: 2;\n cursor: ${({ $isDisabled }: StyledRadioButtonCheckBoxMarkProps) =>\n $isDisabled ? 'default !important' : 'pointer !important'};\n\n ${({ $isHovered, $isSelected }) => {\n if ($isSelected) {\n return css`\n opacity: 1;\n `;\n }\n\n if ($isHovered) {\n return css`\n opacity: 0.5;\n `;\n }\n\n return css`\n opacity: 0;\n `;\n }}\n`;\n\ntype StyledRadioButtonLabelProps = WithTheme<unknown>;\n\nexport const StyledRadioButtonLabel = styled.p<StyledRadioButtonLabelProps>`\n color: ${({ theme }: StyledRadioButtonLabelProps) => theme.text};\n`;\n\ntype StyledMotionRadioButtonChildrenProps = WithTheme<unknown>;\n\nexport const StyledMotionRadioButtonChildren = styled(\n motion.div,\n)<StyledMotionRadioButtonChildrenProps>`\n margin-left: 18px;\n cursor: text;\n overflow: hidden;\n color: ${({ theme }: StyledMotionRadioButtonChildrenProps) => theme.text};\n`;\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,eAAe;AACtC,OAAOC,MAAM,IAAIC,GAAG,QAAQ,mBAAmB;AAK/C,OAAO,MAAMC,iBAAiB,GAAGF,MAAM,CAACG,IAA4B;AACpE;AACA;AACA;AACA;AACA;AACA,eAAeC,IAAA;EAAA,IAAC;IAAEC;EAAoC,CAAC,GAAAD,IAAA;EAAA,OAAMC,WAAW,GAAG,GAAG,GAAG,CAAC;AAAA,CAAC;AACnF,CAAC;AAID,OAAO,MAAMC,wBAAwB,GAAGN,MAAM,CAACO,GAAkC;AACjF;AACA;AACA;AACA;AACA;AACA;AACA,cAAcC,KAAA;EAAA,IAAC;IAAEH;EAA2C,CAAC,GAAAG,KAAA;EAAA,OACrDH,WAAW,GAAG,oBAAoB,GAAG,oBAAoB;AAAA;AACjE,CAAC;AAID,OAAO,MAAMI,yBAAyB,GAAGT,MAAM,CAACU,KAAqC;AACrF;AACA;AACA;AACA,cAAcC,KAAA;EAAA,IAAC;IAAEN;EAA4C,CAAC,GAAAM,KAAA;EAAA,OACtDN,WAAW,GAAG,oBAAoB,GAAG,oBAAoB;AAAA;AACjE,CAAC;AAOD,OAAO,MAAMO,+BAA+B,GAAGZ,MAAM,CAACO,GAAyC;AAC/F,wBAAwBM,KAAA;EAAA,IAAC;IAAEC,KAAK;IAAEC;EAAiD,CAAC,GAAAF,KAAA;EAAA,OAC5EE,UAAU,GAAG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A;AAC5E,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"RadioButton.styles.js","names":["motion","styled","css","StyledRadioButton","span","_ref","$isDisabled","_ref2","$radioButtonRightElementMargin","StyledRadioButtonWrapper","div","StyledRadioButtonCheckBox","input","_ref3","StyledRadioButtonPseudoCheckBox","_ref4","theme","$isChecked","_ref5","_ref6","StyledRadioButtonCheckBoxMark","_ref7","_ref8","$isHovered","$isSelected","StyledRadioButtonLabel","p","_ref9","text","_ref10","StyledLabelWrapper","StyledMotionRadioButtonChildren","_ref11"],"sources":["../../../../src/components/radio-button/RadioButton.styles.ts"],"sourcesContent":["import { motion } from 'framer-motion';\nimport styled, { css } from 'styled-components';\nimport type { WithTheme } from '../color-scheme-provider/ColorSchemeProvider';\nimport { RadioButtonRightElementMargin } from '../../types/radioButton';\n\ntype StyledRadioButtonProps = WithTheme<{\n $isDisabled: boolean;\n $radioButtonRightElementMargin: RadioButtonRightElementMargin;\n}>;\n\nexport const StyledRadioButton = styled.span<StyledRadioButtonProps>`\n display: flex;\n flex-direction: column;\n\n position: relative;\n\n opacity: ${({ $isDisabled }: StyledRadioButtonProps) => ($isDisabled ? 0.5 : 1)};\n\n ${({ $radioButtonRightElementMargin }: StyledRadioButtonProps) => {\n switch ($radioButtonRightElementMargin) {\n case 'BOTH':\n return css`\n margin: 6px 0;\n `;\n case 'TOP':\n return css`\n margin-top: 6px;\n `;\n case 'BOTTOM':\n return css`\n margin-bottom: 6px;\n `;\n case 'NONE':\n default:\n return css`\n margin: 0;\n `;\n }\n }}\n`;\n\nexport const StyledRadioButtonWrapper = styled.div`\n display: flex;\n align-items: center;\n position: relative;\n gap: 5px;\n user-select: none;\n`;\n\ntype StyledRadioButtonCheckBoxProps = WithTheme<{ $isDisabled: boolean }>;\n\nexport const StyledRadioButtonCheckBox = styled.input<StyledRadioButtonCheckBoxProps>`\n opacity: 0;\n height: 15px;\n width: 15px;\n cursor: ${({ $isDisabled }: StyledRadioButtonCheckBoxProps) =>\n $isDisabled ? 'default !important' : 'pointer !important'};\n`;\n\ntype StyledRadioButtonPseudoCheckBoxProps = WithTheme<{\n $isChecked: boolean;\n $isDisabled: boolean;\n}>;\n\nexport const StyledRadioButtonPseudoCheckBox = styled.div<StyledRadioButtonPseudoCheckBoxProps>`\n background-color: ${({ theme, $isChecked }: StyledRadioButtonPseudoCheckBoxProps) =>\n $isChecked ? theme['secondary-408'] : theme['secondary-403']};\n opacity: 1;\n border: 1px solid\n rgba(${({ theme }: StyledRadioButtonPseudoCheckBoxProps) => theme['409-rgb']}, 0.5);\n width: 15px;\n height: 15px;\n position: absolute;\n border-radius: 100%;\n top: 50%;\n transform: translateY(-50%);\n cursor: ${({ $isDisabled }: StyledRadioButtonPseudoCheckBoxProps) =>\n $isDisabled ? 'default !important' : 'pointer !important'};\n`;\n\ntype StyledRadioButtonCheckBoxMarkProps = WithTheme<{\n $isHovered: boolean;\n $isSelected: boolean;\n $isDisabled: boolean;\n}>;\n\nexport const StyledRadioButtonCheckBoxMark = styled.span<StyledRadioButtonCheckBoxMarkProps>`\n background-color: transparent;\n position: absolute;\n top: 1px;\n left: 3.925px;\n display: inline-block;\n transform: rotate(35deg);\n height: 9px;\n width: 5px;\n border-bottom: 2px solid white;\n border-right: 2px solid white;\n border-top: transparent;\n border-left: transparent;\n z-index: 2;\n cursor: ${({ $isDisabled }: StyledRadioButtonCheckBoxMarkProps) =>\n $isDisabled ? 'default !important' : 'pointer !important'};\n\n ${({ $isHovered, $isSelected }) => {\n if ($isSelected) {\n return css`\n opacity: 1;\n `;\n }\n\n if ($isHovered) {\n return css`\n opacity: 0.5;\n `;\n }\n\n return css`\n opacity: 0;\n `;\n }}\n`;\n\ntype StyledRadioButtonLabelProps = WithTheme<{ $isDisabled: boolean }>;\n\nexport const StyledRadioButtonLabel = styled.p<StyledRadioButtonLabelProps>`\n color: ${({ theme }: StyledRadioButtonLabelProps) => theme.text};\n margin: 0;\n cursor: ${({ $isDisabled }: StyledRadioButtonLabelProps) =>\n $isDisabled ? 'default !important' : 'pointer !important'};\n`;\n\nexport const StyledLabelWrapper = styled.div`\n display: flex;\n align-items: center;\n justify-content: space-between;\n width: 100%;\n gap: 12px;\n`;\n\ntype StyledMotionRadioButtonChildrenProps = WithTheme<unknown>;\n\nexport const StyledMotionRadioButtonChildren = styled(\n motion.div,\n)<StyledMotionRadioButtonChildrenProps>`\n margin-left: 18px;\n cursor: text;\n overflow: hidden;\n color: ${({ theme }: StyledMotionRadioButtonChildrenProps) => theme.text};\n`;\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,eAAe;AACtC,OAAOC,MAAM,IAAIC,GAAG,QAAQ,mBAAmB;AAS/C,OAAO,MAAMC,iBAAiB,GAAGF,MAAM,CAACG,IAA4B;AACpE;AACA;AACA;AACA;AACA;AACA,eAAeC,IAAA;EAAA,IAAC;IAAEC;EAAoC,CAAC,GAAAD,IAAA;EAAA,OAAMC,WAAW,GAAG,GAAG,GAAG,CAAC;AAAA,CAAC;AACnF;AACA,MAAMC,KAAA,IAAgE;EAAA,IAA/D;IAAEC;EAAuD,CAAC,GAAAD,KAAA;EACzD,QAAQC,8BAA8B;IAClC,KAAK,MAAM;MACP,OAAON,GAAG;AAC1B;AACA,iBAAiB;IACL,KAAK,KAAK;MACN,OAAOA,GAAG;AAC1B;AACA,iBAAiB;IACL,KAAK,QAAQ;MACT,OAAOA,GAAG;AAC1B;AACA,iBAAiB;IACL,KAAK,MAAM;IACX;MACI,OAAOA,GAAG;AAC1B;AACA,iBAAiB;EACT;AACJ,CAAC;AACL,CAAC;AAED,OAAO,MAAMO,wBAAwB,GAAGR,MAAM,CAACS,GAAG;AAClD;AACA;AACA;AACA;AACA;AACA,CAAC;AAID,OAAO,MAAMC,yBAAyB,GAAGV,MAAM,CAACW,KAAqC;AACrF;AACA;AACA;AACA,cAAcC,KAAA;EAAA,IAAC;IAAEP;EAA4C,CAAC,GAAAO,KAAA;EAAA,OACtDP,WAAW,GAAG,oBAAoB,GAAG,oBAAoB;AAAA;AAC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AC;IAAEvB;EAAyC,CAAC,GAAAuB,MAAA;EAAA,OACnDvB,WAAW,GAAG,oBAAoB,GAAG,oBAAoB;AAAA;AACjE,CAAC;AAED,OAAO,MAAMwB,kBAAkB,GAAG7B,MAAM,CAACS,GAAG;AAC5C;AACA;AACA;AACA;AACA;AACA,CAAC;AAID,OAAO,MAAMqB,+BAA+B,GAAG9B,MAAM,CACjDD,MAAM,CAACU,GACX,CAAuC;AACvC;AACA;AACA;AACA,aAAasB,MAAA;EAAA,IAAC;IAAEhB;EAA4C,CAAC,GAAAgB,MAAA;EAAA,OAAKhB,KAAK,CAACY,IAAI;AAAA;AAC5E,CAAC","ignoreList":[]}
@@ -1,8 +1,11 @@
1
1
  import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
2
+ import { getRadioButtonOrder } from '../../../utils/radioButton';
2
3
  export const RadioButtonGroupContext = /*#__PURE__*/React.createContext({
3
4
  selectedRadioButtonId: undefined,
4
5
  updateSelectedRadioButtonId: undefined,
5
- radioButtonsCanBeUnchecked: false
6
+ radioButtonsCanBeUnchecked: false,
7
+ radioButtonRightElements: [],
8
+ updateHasRightElement: undefined
6
9
  });
7
10
  RadioButtonGroupContext.displayName = 'RadioButtonGroupContext';
8
11
  const RadioButtonGroup = /*#__PURE__*/forwardRef((_ref, ref) => {
@@ -13,6 +16,7 @@ const RadioButtonGroup = /*#__PURE__*/forwardRef((_ref, ref) => {
13
16
  onSelect
14
17
  } = _ref;
15
18
  const [selectedRadioButtonId, setSelectedRadioButtonId] = useState(undefined);
19
+ const [radioButtonRightElements, setRadioButtonRightElements] = useState([]);
16
20
  const isInitialRenderRef = useRef(true);
17
21
  useEffect(() => {
18
22
  setSelectedRadioButtonId(selectedId);
@@ -23,6 +27,20 @@ const RadioButtonGroup = /*#__PURE__*/forwardRef((_ref, ref) => {
23
27
  }
24
28
  setSelectedRadioButtonId(id);
25
29
  }, [onSelect]);
30
+ const updateHasRightElement = useCallback((id, hasRightElement) => {
31
+ setRadioButtonRightElements(prevState => prevState.map(prev => id === prev.id ? {
32
+ id,
33
+ hasRightElement
34
+ } : prev));
35
+ }, []);
36
+ useEffect(() => {
37
+ const ids = getRadioButtonOrder(children);
38
+ const rightElements = ids.map(id => ({
39
+ id,
40
+ hasRightElement: false
41
+ }));
42
+ setRadioButtonRightElements(rightElements);
43
+ }, [children]);
26
44
  useImperativeHandle(ref, () => ({
27
45
  updateSelectedRadioButtonId
28
46
  }), [updateSelectedRadioButtonId]);
@@ -34,8 +52,10 @@ const RadioButtonGroup = /*#__PURE__*/forwardRef((_ref, ref) => {
34
52
  const providerValue = useMemo(() => ({
35
53
  selectedRadioButtonId,
36
54
  updateSelectedRadioButtonId,
37
- radioButtonsCanBeUnchecked: canUncheckRadioButtons
38
- }), [canUncheckRadioButtons, selectedRadioButtonId, updateSelectedRadioButtonId]);
55
+ radioButtonsCanBeUnchecked: canUncheckRadioButtons,
56
+ updateHasRightElement,
57
+ radioButtonRightElements
58
+ }), [canUncheckRadioButtons, radioButtonRightElements, selectedRadioButtonId, updateHasRightElement, updateSelectedRadioButtonId]);
39
59
  return /*#__PURE__*/React.createElement(RadioButtonGroupContext.Provider, {
40
60
  value: providerValue
41
61
  }, children);
@@ -1 +1 @@
1
- {"version":3,"file":"RadioButtonGroup.js","names":["React","forwardRef","useCallback","useEffect","useImperativeHandle","useMemo","useRef","useState","RadioButtonGroupContext","createContext","selectedRadioButtonId","undefined","updateSelectedRadioButtonId","radioButtonsCanBeUnchecked","displayName","RadioButtonGroup","_ref","ref","children","canUncheckRadioButtons","selectedId","onSelect","setSelectedRadioButtonId","isInitialRenderRef","id","current","providerValue","createElement","Provider","value"],"sources":["../../../../../src/components/radio-button/radio-button-group/RadioButtonGroup.tsx"],"sourcesContent":["import React, {\n forwardRef,\n ReactNode,\n useCallback,\n useEffect,\n useImperativeHandle,\n useMemo,\n useRef,\n useState,\n} from 'react';\n\ntype IUpdateSelectedRadioButtonId = (id: string | undefined) => void;\n\ninterface IRadioButtonGroupContext {\n selectedRadioButtonId: string | undefined;\n updateSelectedRadioButtonId?: IUpdateSelectedRadioButtonId;\n radioButtonsCanBeUnchecked?: boolean;\n}\n\nexport const RadioButtonGroupContext = React.createContext<IRadioButtonGroupContext>({\n selectedRadioButtonId: undefined,\n updateSelectedRadioButtonId: undefined,\n radioButtonsCanBeUnchecked: false,\n});\n\nRadioButtonGroupContext.displayName = 'RadioButtonGroupContext';\n\nexport type RadioButtonGroupRef = {\n updateSelectedRadioButtonId: IUpdateSelectedRadioButtonId;\n};\n\nexport type RadioButtonGroupProps = {\n /**\n * Whether the RadioButtons can be unchecked.\n */\n canUncheckRadioButtons?: boolean;\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 an id is selected.\n */\n onSelect?: (id?: string) => void;\n /**\n * The id of the current selected RadioButton.\n */\n selectedId?: string;\n};\n\nconst RadioButtonGroup = forwardRef<RadioButtonGroupRef, RadioButtonGroupProps>(\n ({ children, canUncheckRadioButtons, selectedId, onSelect }, ref) => {\n const [selectedRadioButtonId, setSelectedRadioButtonId] =\n useState<IRadioButtonGroupContext['selectedRadioButtonId']>(undefined);\n\n const isInitialRenderRef = useRef(true);\n\n useEffect(() => {\n setSelectedRadioButtonId(selectedId);\n }, [selectedId]);\n\n const updateSelectedRadioButtonId = useCallback<IUpdateSelectedRadioButtonId>(\n (id) => {\n if (typeof onSelect === 'function') {\n onSelect(id);\n }\n\n setSelectedRadioButtonId(id);\n },\n [onSelect],\n );\n\n useImperativeHandle(\n ref,\n () => ({\n updateSelectedRadioButtonId,\n }),\n [updateSelectedRadioButtonId],\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 updateSelectedRadioButtonId,\n radioButtonsCanBeUnchecked: canUncheckRadioButtons,\n }),\n [canUncheckRadioButtons, selectedRadioButtonId, updateSelectedRadioButtonId],\n );\n\n return (\n <RadioButtonGroupContext.Provider value={providerValue}>\n {children}\n </RadioButtonGroupContext.Provider>\n );\n },\n);\n\nRadioButtonGroup.displayName = 'RadioButtonGroup';\n\nexport default RadioButtonGroup;\n"],"mappings":"AAAA,OAAOA,KAAK,IACRC,UAAU,EAEVC,WAAW,EACXC,SAAS,EACTC,mBAAmB,EACnBC,OAAO,EACPC,MAAM,EACNC,QAAQ,QACL,OAAO;AAUd,OAAO,MAAMC,uBAAuB,gBAAGR,KAAK,CAACS,aAAa,CAA2B;EACjFC,qBAAqB,EAAEC,SAAS;EAChCC,2BAA2B,EAAED,SAAS;EACtCE,0BAA0B,EAAE;AAChC,CAAC,CAAC;AAEFL,uBAAuB,CAACM,WAAW,GAAG,yBAAyB;AA0B/D,MAAMC,gBAAgB,gBAAGd,UAAU,CAC/B,CAAAe,IAAA,EAA6DC,GAAG,KAAK;EAAA,IAApE;IAAEC,QAAQ;IAAEC,sBAAsB;IAAEC,UAAU;IAAEC;EAAS,CAAC,GAAAL,IAAA;EACvD,MAAM,CAACN,qBAAqB,EAAEY,wBAAwB,CAAC,GACnDf,QAAQ,CAAoDI,SAAS,CAAC;EAE1E,MAAMY,kBAAkB,GAAGjB,MAAM,CAAC,IAAI,CAAC;EAEvCH,SAAS,CAAC,MAAM;IACZmB,wBAAwB,CAACF,UAAU,CAAC;EACxC,CAAC,EAAE,CAACA,UAAU,CAAC,CAAC;EAEhB,MAAMR,2BAA2B,GAAGV,WAAW,CAC1CsB,EAAE,IAAK;IACJ,IAAI,OAAOH,QAAQ,KAAK,UAAU,EAAE;MAChCA,QAAQ,CAACG,EAAE,CAAC;IAChB;IAEAF,wBAAwB,CAACE,EAAE,CAAC;EAChC,CAAC,EACD,CAACH,QAAQ,CACb,CAAC;EAEDjB,mBAAmB,CACfa,GAAG,EACH,OAAO;IACHL;EACJ,CAAC,CAAC,EACF,CAACA,2BAA2B,CAChC,CAAC;EAEDT,SAAS,CAAC,MAAM;IACZ,IAAIoB,kBAAkB,CAACE,OAAO,EAAE;MAC5BF,kBAAkB,CAACE,OAAO,GAAG,KAAK;IACtC;EACJ,CAAC,EAAE,CAACf,qBAAqB,CAAC,CAAC;EAE3B,MAAMgB,aAAa,GAAGrB,OAAO,CACzB,OAAO;IACHK,qBAAqB;IACrBE,2BAA2B;IAC3BC,0BAA0B,EAAEM;EAChC,CAAC,CAAC,EACF,CAACA,sBAAsB,EAAET,qBAAqB,EAAEE,2BAA2B,CAC/E,CAAC;EAED,oBACIZ,KAAA,CAAA2B,aAAA,CAACnB,uBAAuB,CAACoB,QAAQ;IAACC,KAAK,EAAEH;EAAc,GAClDR,QAC6B,CAAC;AAE3C,CACJ,CAAC;AAEDH,gBAAgB,CAACD,WAAW,GAAG,kBAAkB;AAEjD,eAAeC,gBAAgB","ignoreList":[]}
1
+ {"version":3,"file":"RadioButtonGroup.js","names":["React","forwardRef","useCallback","useEffect","useImperativeHandle","useMemo","useRef","useState","getRadioButtonOrder","RadioButtonGroupContext","createContext","selectedRadioButtonId","undefined","updateSelectedRadioButtonId","radioButtonsCanBeUnchecked","radioButtonRightElements","updateHasRightElement","displayName","RadioButtonGroup","_ref","ref","children","canUncheckRadioButtons","selectedId","onSelect","setSelectedRadioButtonId","setRadioButtonRightElements","isInitialRenderRef","id","hasRightElement","prevState","map","prev","ids","rightElements","current","providerValue","createElement","Provider","value"],"sources":["../../../../../src/components/radio-button/radio-button-group/RadioButtonGroup.tsx"],"sourcesContent":["import React, {\n forwardRef,\n ReactNode,\n useCallback,\n useEffect,\n useImperativeHandle,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { getRadioButtonOrder } from '../../../utils/radioButton';\n\ntype IUpdateSelectedRadioButtonId = (id: string | undefined) => void;\n\ntype IUpdateHasRightElement = (id: string, hasRightElement: boolean) => void;\n\ntype IRadioButtonRightElements = { id: string; hasRightElement: boolean }[];\n\ninterface IRadioButtonGroupContext {\n selectedRadioButtonId: string | undefined;\n updateSelectedRadioButtonId?: IUpdateSelectedRadioButtonId;\n radioButtonRightElements: IRadioButtonRightElements;\n updateHasRightElement?: IUpdateHasRightElement;\n radioButtonsCanBeUnchecked?: boolean;\n}\n\nexport const RadioButtonGroupContext = React.createContext<IRadioButtonGroupContext>({\n selectedRadioButtonId: undefined,\n updateSelectedRadioButtonId: undefined,\n radioButtonsCanBeUnchecked: false,\n radioButtonRightElements: [],\n updateHasRightElement: undefined,\n});\n\nRadioButtonGroupContext.displayName = 'RadioButtonGroupContext';\n\nexport type RadioButtonGroupRef = {\n updateSelectedRadioButtonId: IUpdateSelectedRadioButtonId;\n};\n\nexport type RadioButtonGroupProps = {\n /**\n * Whether the RadioButtons can be unchecked.\n */\n canUncheckRadioButtons?: boolean;\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 an id is selected.\n */\n onSelect?: (id?: string) => void;\n /**\n * The id of the current selected RadioButton.\n */\n selectedId?: string;\n};\n\nconst RadioButtonGroup = forwardRef<RadioButtonGroupRef, RadioButtonGroupProps>(\n ({ children, canUncheckRadioButtons, selectedId, onSelect }, ref) => {\n const [selectedRadioButtonId, setSelectedRadioButtonId] =\n useState<IRadioButtonGroupContext['selectedRadioButtonId']>(undefined);\n const [radioButtonRightElements, setRadioButtonRightElements] =\n useState<IRadioButtonRightElements>([]);\n\n const isInitialRenderRef = useRef(true);\n\n useEffect(() => {\n setSelectedRadioButtonId(selectedId);\n }, [selectedId]);\n\n const updateSelectedRadioButtonId = useCallback<IUpdateSelectedRadioButtonId>(\n (id) => {\n if (typeof onSelect === 'function') {\n onSelect(id);\n }\n\n setSelectedRadioButtonId(id);\n },\n [onSelect],\n );\n\n const updateHasRightElement = useCallback<IUpdateHasRightElement>((id, hasRightElement) => {\n setRadioButtonRightElements((prevState) =>\n prevState.map((prev) => (id === prev.id ? { id, hasRightElement } : prev)),\n );\n }, []);\n\n useEffect(() => {\n const ids = getRadioButtonOrder(children);\n\n const rightElements = ids.map((id) => ({ id, hasRightElement: false }));\n\n setRadioButtonRightElements(rightElements);\n }, [children]);\n\n useImperativeHandle(\n ref,\n () => ({\n updateSelectedRadioButtonId,\n }),\n [updateSelectedRadioButtonId],\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 updateSelectedRadioButtonId,\n radioButtonsCanBeUnchecked: canUncheckRadioButtons,\n updateHasRightElement,\n radioButtonRightElements,\n }),\n [\n canUncheckRadioButtons,\n radioButtonRightElements,\n selectedRadioButtonId,\n updateHasRightElement,\n updateSelectedRadioButtonId,\n ],\n );\n\n return (\n <RadioButtonGroupContext.Provider value={providerValue}>\n {children}\n </RadioButtonGroupContext.Provider>\n );\n },\n);\n\nRadioButtonGroup.displayName = 'RadioButtonGroup';\n\nexport default RadioButtonGroup;\n"],"mappings":"AAAA,OAAOA,KAAK,IACRC,UAAU,EAEVC,WAAW,EACXC,SAAS,EACTC,mBAAmB,EACnBC,OAAO,EACPC,MAAM,EACNC,QAAQ,QACL,OAAO;AACd,SAASC,mBAAmB,QAAQ,4BAA4B;AAgBhE,OAAO,MAAMC,uBAAuB,gBAAGT,KAAK,CAACU,aAAa,CAA2B;EACjFC,qBAAqB,EAAEC,SAAS;EAChCC,2BAA2B,EAAED,SAAS;EACtCE,0BAA0B,EAAE,KAAK;EACjCC,wBAAwB,EAAE,EAAE;EAC5BC,qBAAqB,EAAEJ;AAC3B,CAAC,CAAC;AAEFH,uBAAuB,CAACQ,WAAW,GAAG,yBAAyB;AA0B/D,MAAMC,gBAAgB,gBAAGjB,UAAU,CAC/B,CAAAkB,IAAA,EAA6DC,GAAG,KAAK;EAAA,IAApE;IAAEC,QAAQ;IAAEC,sBAAsB;IAAEC,U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ChC,CAAC;EAEDV,SAAS,CAAC,MAAM;IACZ,IAAIwB,kBAAkB,CAACQ,OAAO,EAAE;MAC5BR,kBAAkB,CAACQ,OAAO,GAAG,KAAK;IACtC;EACJ,CAAC,EAAE,CAACxB,qBAAqB,CAAC,CAAC;EAE3B,MAAMyB,aAAa,GAAG/B,OAAO,CACzB,OAAO;IACHM,qBAAqB;IACrBE,2BAA2B;IAC3BC,0BAA0B,EAAEQ,sBAAsB;IAClDN,qBAAqB;IACrBD;EACJ,CAAC,CAAC,EACF,CACIO,sBAAsB,EACtBP,wBAAwB,EACxBJ,qBAAqB,EACrBK,qBAAqB,EACrBH,2BAA2B,CAEnC,CAAC;EAED,oBACIb,KAAA,CAAAqC,aAAA,CAAC5B,uBAAuB,CAAC6B,QAAQ;IAACC,KAAK,EAAEH;EAAc,GAClDf,QAC6B,CAAC;AAE3C,CACJ,CAAC;AAEDH,gBAAgB,CAACD,WAAW,GAAG,kBAAkB;AAEjD,eAAeC,gBAAgB","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"radioButton.js","names":[],"sources":["../../../src/types/radioButton.ts"],"sourcesContent":["export interface RadioButtonItem {\n id: string;\n isChecked: boolean;\n}\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"file":"radioButton.js","names":[],"sources":["../../../src/types/radioButton.ts"],"sourcesContent":["export interface RadioButtonItem {\n id: string;\n isChecked: boolean;\n}\n\nexport type RadioButtonRightElementMargin = 'NONE' | 'TOP' | 'BOTTOM' | 'BOTH';\n"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,16 @@
1
+ import React, { Children } from 'react';
2
+ export const getRadioButtonOrder = children => {
3
+ const radioButtonIds = [];
4
+ Children.forEach(children, child => {
5
+ if (/*#__PURE__*/React.isValidElement(child)) {
6
+ const {
7
+ id
8
+ } = child.props;
9
+ if (typeof id === 'string') {
10
+ radioButtonIds.push(id);
11
+ }
12
+ }
13
+ });
14
+ return radioButtonIds;
15
+ };
16
+ //# sourceMappingURL=radioButton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"radioButton.js","names":["React","Children","getRadioButtonOrder","children","radioButtonIds","forEach","child","isValidElement","id","props","push"],"sources":["../../../src/utils/radioButton.ts"],"sourcesContent":["import React, { Children, ReactNode } from 'react';\n\nexport const getRadioButtonOrder = (children: ReactNode): string[] => {\n const radioButtonIds: string[] = [];\n\n Children.forEach(children, (child) => {\n if (React.isValidElement<{ id?: string }>(child)) {\n const { id } = child.props;\n\n if (typeof id === 'string') {\n radioButtonIds.push(id);\n }\n }\n });\n\n return radioButtonIds;\n};\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,QAAQ,QAAmB,OAAO;AAElD,OAAO,MAAMC,mBAAmB,GAAIC,QAAmB,IAAe;EAClE,MAAMC,cAAwB,GAAG,EAAE;EAEnCH,QAAQ,CAACI,OAAO,CAACF,QAAQ,EAAGG,KAAK,IAAK;IAClC,iBAAIN,KAAK,CAACO,cAAc,CAAkBD,KAAK,CAAC,EAAE;MAC9C,MAAM;QAAEE;MAAG,CAAC,GAAGF,KAAK,CAACG,KAAK;MAE1B,IAAI,OAAOD,EAAE,KAAK,QAAQ,EAAE;QACxBJ,cAAc,CAACM,IAAI,CAACF,EAAE,CAAC;MAC3B;IACJ;EACJ,CAAC,CAAC;EAEF,OAAOJ,cAAc;AACzB,CAAC","ignoreList":[]}
@@ -16,6 +16,14 @@ export type RadioButtonProps = {
16
16
  * The label that should be displayed next to the radio button.
17
17
  */
18
18
  label?: string;
19
+ /**
20
+ * An element that should be displayed on the right side of the label.
21
+ */
22
+ rightElement?: ReactNode;
23
+ /**
24
+ * Whether the rightElement should only be displayed when the RadioButton is checked
25
+ */
26
+ shouldShowRightElementOnlyOnChecked?: boolean;
19
27
  };
20
28
  declare const RadioButton: FC<RadioButtonProps>;
21
29
  export default RadioButton;
@@ -1,12 +1,11 @@
1
1
  import type { WithTheme } from '../color-scheme-provider/ColorSchemeProvider';
2
+ import { RadioButtonRightElementMargin } from '../../types/radioButton';
2
3
  type StyledRadioButtonProps = WithTheme<{
3
4
  $isDisabled: boolean;
5
+ $radioButtonRightElementMargin: RadioButtonRightElementMargin;
4
6
  }>;
5
7
  export declare const StyledRadioButton: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, StyledRadioButtonProps>> & string;
6
- type StyledRadioButtonWrapperProps = WithTheme<{
7
- $isDisabled: boolean;
8
- }>;
9
- export declare const StyledRadioButtonWrapper: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, StyledRadioButtonWrapperProps>> & string;
8
+ export declare const StyledRadioButtonWrapper: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
10
9
  type StyledRadioButtonCheckBoxProps = WithTheme<{
11
10
  $isDisabled: boolean;
12
11
  }>;
@@ -22,9 +21,11 @@ type StyledRadioButtonCheckBoxMarkProps = WithTheme<{
22
21
  $isDisabled: boolean;
23
22
  }>;
24
23
  export declare const StyledRadioButtonCheckBoxMark: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, StyledRadioButtonCheckBoxMarkProps>> & string;
25
- export declare const StyledRadioButtonLabel: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLParagraphElement>, HTMLParagraphElement>, {
26
- theme: import("../color-scheme-provider/ColorSchemeProvider").Theme;
27
- }>> & string;
24
+ type StyledRadioButtonLabelProps = WithTheme<{
25
+ $isDisabled: boolean;
26
+ }>;
27
+ export declare const StyledRadioButtonLabel: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLParagraphElement>, HTMLParagraphElement>, StyledRadioButtonLabelProps>> & string;
28
+ export declare const StyledLabelWrapper: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
28
29
  export declare const StyledMotionRadioButtonChildren: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Substitute<Omit<{
29
30
  slot?: string | undefined;
30
31
  title?: string | undefined;
@@ -1,8 +1,15 @@
1
1
  import React, { ReactNode } from 'react';
2
2
  type IUpdateSelectedRadioButtonId = (id: string | undefined) => void;
3
+ type IUpdateHasRightElement = (id: string, hasRightElement: boolean) => void;
4
+ type IRadioButtonRightElements = {
5
+ id: string;
6
+ hasRightElement: boolean;
7
+ }[];
3
8
  interface IRadioButtonGroupContext {
4
9
  selectedRadioButtonId: string | undefined;
5
10
  updateSelectedRadioButtonId?: IUpdateSelectedRadioButtonId;
11
+ radioButtonRightElements: IRadioButtonRightElements;
12
+ updateHasRightElement?: IUpdateHasRightElement;
6
13
  radioButtonsCanBeUnchecked?: boolean;
7
14
  }
8
15
  export declare const RadioButtonGroupContext: React.Context<IRadioButtonGroupContext>;
@@ -2,3 +2,4 @@ export interface RadioButtonItem {
2
2
  id: string;
3
3
  isChecked: boolean;
4
4
  }
5
+ export type RadioButtonRightElementMargin = 'NONE' | 'TOP' | 'BOTTOM' | 'BOTH';
@@ -0,0 +1,2 @@
1
+ import { ReactNode } from 'react';
2
+ export declare const getRadioButtonOrder: (children: ReactNode) => string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chayns-components/core",
3
- "version": "5.0.0-beta.852",
3
+ "version": "5.0.0-beta.854",
4
4
  "description": "A set of beautiful React components for developing your own applications with chayns.",
5
5
  "sideEffects": false,
6
6
  "browserslist": [
@@ -85,5 +85,5 @@
85
85
  "publishConfig": {
86
86
  "access": "public"
87
87
  },
88
- "gitHead": "64b62b37c9f3e380fbd61560a35ec1c82caf42d6"
88
+ "gitHead": "c9809fb46a1b955cbf1ee159fcfd7f767fa855ea"
89
89
  }