@simplybusiness/mobius 4.12.0 → 4.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/dist/cjs/components/Checkbox/Checkbox.js +2 -2
- package/dist/cjs/components/Checkbox/Checkbox.js.map +1 -1
- package/dist/cjs/components/Container/Container.js +3 -2
- package/dist/cjs/components/Container/Container.js.map +1 -1
- package/dist/cjs/components/Radio/index.js +0 -1
- package/dist/cjs/components/Radio/index.js.map +1 -1
- package/dist/esm/components/Checkbox/Checkbox.js +2 -2
- package/dist/esm/components/Checkbox/Checkbox.js.map +1 -1
- package/dist/esm/components/Container/Container.js +3 -2
- package/dist/esm/components/Container/Container.js.map +1 -1
- package/dist/esm/components/Radio/index.js +0 -1
- package/dist/esm/components/Radio/index.js.map +1 -1
- package/dist/types/components/Container/Container.d.ts +2 -0
- package/dist/types/components/Radio/index.d.ts +0 -1
- package/package.json +1 -1
- package/src/components/Button/Button.story.styles.css +1 -0
- package/src/components/Checkbox/Checkbox.mdx +1 -1
- package/src/components/Checkbox/Checkbox.test.tsx +9 -7
- package/src/components/Checkbox/Checkbox.tsx +6 -2
- package/src/components/Checkbox/CheckboxGroup.test.tsx +1 -1
- package/src/components/Container/Container.tsx +5 -1
- package/src/components/PasswordField/PasswordField.mdx +0 -2
- package/src/components/Radio/index.tsx +0 -1
- package/src/utils/StoryContainer.tsx +1 -1
- package/dist/cjs/components/Radio/RadioButton.js +0 -33
- package/dist/cjs/components/Radio/RadioButton.js.map +0 -1
- package/dist/esm/components/Radio/RadioButton.js +0 -18
- package/dist/esm/components/Radio/RadioButton.js.map +0 -1
- package/dist/types/components/Radio/RadioButton.d.ts +0 -3
- package/dist/types/components/Radio/RadioButton.stories.d.ts +0 -11
- package/dist/types/components/Radio/RadioButton.test.d.ts +0 -1
- package/src/components/Radio/RadioButton.mdx +0 -150
- package/src/components/Radio/RadioButton.stories.tsx +0 -148
- package/src/components/Radio/RadioButton.test.tsx +0 -35
- package/src/components/Radio/RadioButton.tsx +0 -18
package/CHANGELOG.md
CHANGED
|
@@ -37,9 +37,9 @@ const Checkbox = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
|
|
|
37
37
|
"--is-selected": selected,
|
|
38
38
|
"--is-required": typeof isRequired === "boolean" && isRequired,
|
|
39
39
|
"--is-optional": typeof isRequired === "boolean" && !isRequired
|
|
40
|
-
}, validationClasses
|
|
40
|
+
}, validationClasses);
|
|
41
41
|
// Append an additional wrapper class name to differenitate from input
|
|
42
|
-
const wrapperClasses = (0, _dedupe.default)("mobius", "mobius/Checkbox", sharedClasses);
|
|
42
|
+
const wrapperClasses = (0, _dedupe.default)("mobius", "mobius/Checkbox", sharedClasses, className);
|
|
43
43
|
const inputClasses = (0, _dedupe.default)("mobius/CheckboxInput", sharedClasses);
|
|
44
44
|
const iconClasses = (0, _dedupe.default)("mobius/CheckboxIcon", sharedClasses);
|
|
45
45
|
const errorMessageId = (0, _react.useId)();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/Checkbox/Checkbox.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n ChangeEvent,\n forwardRef,\n useRef,\n useState,\n KeyboardEvent,\n MouseEvent,\n useId,\n} from \"react\";\nimport classNames from \"classnames/dedupe\";\nimport { squareTick, square } from \"@simplybusiness/icons\";\nimport { ErrorMessage } from \"../ErrorMessage\";\nimport { ForwardedRefComponent } from \"../../types/components\";\nimport { CheckboxElementType, CheckboxProps, CheckboxRef } from \"./types\";\nimport { spaceDelimitedList } from \"../../utils/spaceDelimitedList\";\nimport { useValidationClasses } from \"../../hooks\";\nimport { Icon } from \"../Icon\";\n\nexport const Checkbox: ForwardedRefComponent<\n CheckboxProps,\n CheckboxElementType\n> = forwardRef((props: CheckboxProps, ref: CheckboxRef) => {\n const {\n id,\n label,\n isDisabled,\n isRequired,\n validationState,\n isInvalid,\n onChange,\n className,\n errorMessage,\n defaultSelected = false,\n isReadOnly,\n value,\n [\"aria-describedby\"]: ariaDescribedBy,\n ...rest\n } = props;\n const [selected, setSelected] = useState<boolean>(defaultSelected);\n const fallbackRef = useRef<HTMLInputElement>(null);\n const refObj = ref || fallbackRef;\n const inputId = useId();\n const validationClasses = useValidationClasses({\n validationState,\n isInvalid,\n });\n const sharedClasses = classNames(\n {\n \"--is-disabled\": isDisabled,\n \"--is-selected\": selected,\n \"--is-required\": typeof isRequired === \"boolean\" && isRequired,\n \"--is-optional\": typeof isRequired === \"boolean\" && !isRequired,\n },\n validationClasses,\n
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/Checkbox/Checkbox.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n ChangeEvent,\n forwardRef,\n useRef,\n useState,\n KeyboardEvent,\n MouseEvent,\n useId,\n} from \"react\";\nimport classNames from \"classnames/dedupe\";\nimport { squareTick, square } from \"@simplybusiness/icons\";\nimport { ErrorMessage } from \"../ErrorMessage\";\nimport { ForwardedRefComponent } from \"../../types/components\";\nimport { CheckboxElementType, CheckboxProps, CheckboxRef } from \"./types\";\nimport { spaceDelimitedList } from \"../../utils/spaceDelimitedList\";\nimport { useValidationClasses } from \"../../hooks\";\nimport { Icon } from \"../Icon\";\n\nexport const Checkbox: ForwardedRefComponent<\n CheckboxProps,\n CheckboxElementType\n> = forwardRef((props: CheckboxProps, ref: CheckboxRef) => {\n const {\n id,\n label,\n isDisabled,\n isRequired,\n validationState,\n isInvalid,\n onChange,\n className,\n errorMessage,\n defaultSelected = false,\n isReadOnly,\n value,\n [\"aria-describedby\"]: ariaDescribedBy,\n ...rest\n } = props;\n const [selected, setSelected] = useState<boolean>(defaultSelected);\n const fallbackRef = useRef<HTMLInputElement>(null);\n const refObj = ref || fallbackRef;\n const inputId = useId();\n const validationClasses = useValidationClasses({\n validationState,\n isInvalid,\n });\n const sharedClasses = classNames(\n {\n \"--is-disabled\": isDisabled,\n \"--is-selected\": selected,\n \"--is-required\": typeof isRequired === \"boolean\" && isRequired,\n \"--is-optional\": typeof isRequired === \"boolean\" && !isRequired,\n },\n validationClasses,\n );\n // Append an additional wrapper class name to differenitate from input\n const wrapperClasses = classNames(\n \"mobius\",\n \"mobius/Checkbox\",\n sharedClasses,\n className,\n );\n const inputClasses = classNames(\"mobius/CheckboxInput\", sharedClasses);\n const iconClasses = classNames(\"mobius/CheckboxIcon\", sharedClasses);\n const errorMessageId = useId();\n const shouldErrorMessageShow = errorMessage ? errorMessageId : undefined;\n const describedBy = spaceDelimitedList([\n shouldErrorMessageShow,\n ariaDescribedBy,\n ]);\n const labelId = useId();\n\n const toggleState = () => {\n setSelected(!selected);\n };\n\n const handleClick = (event: MouseEvent<CheckboxElementType>) => {\n const isMouseEvent = event.clientX;\n\n if (isMouseEvent) {\n toggleState();\n }\n };\n\n const handleChange = (event: ChangeEvent<CheckboxElementType>) => {\n if (onChange) {\n onChange(event);\n }\n };\n\n const handleKeyDown = (event: KeyboardEvent) => {\n if (event.code === \"Space\") {\n toggleState();\n }\n };\n\n return (\n <>\n <label className={wrapperClasses}>\n <input\n aria-describedby={describedBy}\n aria-errormessage={shouldErrorMessageShow}\n aria-invalid={isInvalid}\n aria-labelledby={labelId}\n readOnly={isReadOnly}\n disabled={isDisabled}\n ref={refObj}\n className={inputClasses}\n onClick={handleClick}\n onChange={handleChange}\n onKeyDown={handleKeyDown}\n type=\"checkbox\"\n defaultChecked={defaultSelected}\n required={isRequired}\n id={id || inputId}\n value={value}\n {...rest}\n />\n <Icon\n icon={selected ? squareTick : square}\n size=\"md\"\n className={iconClasses}\n />\n <span id={labelId} className=\"mobius/CheckboxLabel\">\n {label}\n </span>\n </label>\n <ErrorMessage id={errorMessageId} errorMessage={errorMessage} />\n </>\n );\n});\n"],"names":["Checkbox","forwardRef","props","ref","id","label","isDisabled","isRequired","validationState","isInvalid","onChange","className","errorMessage","defaultSelected","isReadOnly","value","ariaDescribedBy","rest","selected","setSelected","useState","fallbackRef","useRef","refObj","inputId","useId","validationClasses","useValidationClasses","sharedClasses","classNames","wrapperClasses","inputClasses","iconClasses","errorMessageId","shouldErrorMessageShow","undefined","describedBy","spaceDelimitedList","labelId","toggleState","handleClick","event","isMouseEvent","clientX","handleChange","handleKeyDown","code","input","aria-describedby","aria-errormessage","aria-invalid","aria-labelledby","readOnly","disabled","onClick","onKeyDown","type","defaultChecked","required","Icon","icon","squareTick","square","size","span","ErrorMessage"],"mappings":"AAAA;;;;;+BAoBaA;;;eAAAA;;;;uBAVN;+DACgB;uBACY;8BACN;oCAGM;uBACE;sBAChB;;;;;;AAEd,MAAMA,yBAGTC,IAAAA,iBAAU,EAAC,CAACC,OAAsBC;IACpC,MAAM,EACJC,EAAE,EACFC,KAAK,EACLC,UAAU,EACVC,UAAU,EACVC,eAAe,EACfC,SAAS,EACTC,QAAQ,EACRC,SAAS,EACTC,YAAY,EACZC,kBAAkB,KAAK,EACvBC,UAAU,EACVC,KAAK,EACL,CAAC,mBAAmB,EAAEC,eAAe,EACrC,GAAGC,MACJ,GAAGf;IACJ,MAAM,CAACgB,UAAUC,YAAY,GAAGC,IAAAA,eAAQ,EAAUP;IAClD,MAAMQ,cAAcC,IAAAA,aAAM,EAAmB;IAC7C,MAAMC,SAASpB,OAAOkB;IACtB,MAAMG,UAAUC,IAAAA,YAAK;IACrB,MAAMC,oBAAoBC,IAAAA,2BAAoB,EAAC;QAC7CnB;QACAC;IACF;IACA,MAAMmB,gBAAgBC,IAAAA,eAAU,EAC9B;QACE,iBAAiBvB;QACjB,iBAAiBY;QACjB,iBAAiB,OAAOX,eAAe,aAAaA;QACpD,iBAAiB,OAAOA,eAAe,aAAa,CAACA;IACvD,GACAmB;IAEF,sEAAsE;IACtE,MAAMI,iBAAiBD,IAAAA,eAAU,EAC/B,UACA,mBACAD,eACAjB;IAEF,MAAMoB,eAAeF,IAAAA,eAAU,EAAC,wBAAwBD;IACxD,MAAMI,cAAcH,IAAAA,eAAU,EAAC,uBAAuBD;IACtD,MAAMK,iBAAiBR,IAAAA,YAAK;IAC5B,MAAMS,yBAAyBtB,eAAeqB,iBAAiBE;IAC/D,MAAMC,cAAcC,IAAAA,sCAAkB,EAAC;QACrCH;QACAlB;KACD;IACD,MAAMsB,UAAUb,IAAAA,YAAK;IAErB,MAAMc,cAAc;QAClBpB,YAAY,CAACD;IACf;IAEA,MAAMsB,cAAc,CAACC;QACnB,MAAMC,eAAeD,MAAME,OAAO;QAElC,IAAID,cAAc;YAChBH;QACF;IACF;IAEA,MAAMK,eAAe,CAACH;QACpB,IAAI/B,UAAU;YACZA,SAAS+B;QACX;IACF;IAEA,MAAMI,gBAAgB,CAACJ;QACrB,IAAIA,MAAMK,IAAI,KAAK,SAAS;YAC1BP;QACF;IACF;IAEA,qBACE;;0BACE,sBAAClC;gBAAMM,WAAWmB;;kCAChB,qBAACiB;wBACCC,oBAAkBZ;wBAClBa,qBAAmBf;wBACnBgB,gBAAczC;wBACd0C,mBAAiBb;wBACjBc,UAAUtC;wBACVuC,UAAU/C;wBACVH,KAAKoB;wBACLZ,WAAWoB;wBACXuB,SAASd;wBACT9B,UAAUkC;wBACVW,WAAWV;wBACXW,MAAK;wBACLC,gBAAgB5C;wBAChB6C,UAAUnD;wBACVH,IAAIA,MAAMoB;wBACVT,OAAOA;wBACN,GAAGE,IAAI;;kCAEV,qBAAC0C,UAAI;wBACHC,MAAM1C,WAAW2C,iBAAU,GAAGC,aAAM;wBACpCC,MAAK;wBACLpD,WAAWqB;;kCAEb,qBAACgC;wBAAK5D,IAAIkC;wBAAS3B,WAAU;kCAC1BN;;;;0BAGL,qBAAC4D,0BAAY;gBAAC7D,IAAI6B;gBAAgBrB,cAAcA;;;;AAGtD"}
|
|
@@ -11,14 +11,15 @@ Object.defineProperty(exports, "Container", {
|
|
|
11
11
|
const _jsxruntime = require("react/jsx-runtime");
|
|
12
12
|
const _react = require("react");
|
|
13
13
|
const _dedupe = /*#__PURE__*/ _interop_require_default(require("classnames/dedupe"));
|
|
14
|
+
const _utils = require("../../utils");
|
|
14
15
|
function _interop_require_default(obj) {
|
|
15
16
|
return obj && obj.__esModule ? obj : {
|
|
16
17
|
default: obj
|
|
17
18
|
};
|
|
18
19
|
}
|
|
19
20
|
const Container = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
|
|
20
|
-
const { elementType: Element = "div", ...otherProps } = props;
|
|
21
|
-
const classes = (0, _dedupe.default)("mobius", "mobius/Container", otherProps.className);
|
|
21
|
+
const { elementType: Element = "div", size = "md", ...otherProps } = props;
|
|
22
|
+
const classes = (0, _dedupe.default)("mobius", "mobius/Container", (0, _utils.sizeClasses)(size), otherProps.className);
|
|
22
23
|
return /*#__PURE__*/ (0, _jsxruntime.jsx)(Element, {
|
|
23
24
|
ref: ref,
|
|
24
25
|
...otherProps,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/Container/Container.tsx"],"sourcesContent":["import { forwardRef, Ref, RefAttributes, ReactNode } from \"react\";\nimport classNames from \"classnames/dedupe\";\nimport { DOMProps } from \"../../types/dom\";\nimport { ForwardedRefComponent } from \"../../types/components\";\n\nexport type ContainerElementType = HTMLDivElement;\nexport type ContainerRef = Ref<ContainerElementType>;\n\nexport interface ContainerProps\n extends DOMProps,\n RefAttributes<ContainerElementType> {\n id?: string;\n /** Custom class name for setting specific CSS */\n className?: string;\n /** HTML element for the Box */\n elementType?: \"div\" | \"span\";\n children?: ReactNode;\n}\n\nconst Container: ForwardedRefComponent<ContainerProps, ContainerElementType> =\n forwardRef((props: ContainerProps, ref: ContainerRef) => {\n const { elementType: Element = \"div\", ...otherProps } = props;\n\n const classes = classNames(\n \"mobius\",\n \"mobius/Container\",\n otherProps.className,\n );\n\n return <Element ref={ref} {...otherProps} className={classes} />;\n });\n\nContainer.displayName = \"Container\";\nexport { Container };\n"],"names":["Container","forwardRef","props","ref","elementType","Element","otherProps","classes","classNames","className","displayName"],"mappings":";;;;+
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/Container/Container.tsx"],"sourcesContent":["import { forwardRef, Ref, RefAttributes, ReactNode } from \"react\";\nimport classNames from \"classnames/dedupe\";\nimport { DOMProps } from \"../../types/dom\";\nimport { ForwardedRefComponent } from \"../../types/components\";\nimport { SizeType } from \"../../types\";\nimport { sizeClasses } from \"../../utils\";\n\nexport type ContainerElementType = HTMLDivElement;\nexport type ContainerRef = Ref<ContainerElementType>;\n\nexport interface ContainerProps\n extends DOMProps,\n RefAttributes<ContainerElementType> {\n id?: string;\n /** Custom class name for setting specific CSS */\n className?: string;\n /** HTML element for the Box */\n elementType?: \"div\" | \"span\";\n size?: SizeType;\n children?: ReactNode;\n}\n\nconst Container: ForwardedRefComponent<ContainerProps, ContainerElementType> =\n forwardRef((props: ContainerProps, ref: ContainerRef) => {\n const { elementType: Element = \"div\", size = \"md\", ...otherProps } = props;\n\n const classes = classNames(\n \"mobius\",\n \"mobius/Container\",\n sizeClasses(size),\n otherProps.className,\n );\n\n return <Element ref={ref} {...otherProps} className={classes} />;\n });\n\nContainer.displayName = \"Container\";\nexport { Container };\n"],"names":["Container","forwardRef","props","ref","elementType","Element","size","otherProps","classes","classNames","sizeClasses","className","displayName"],"mappings":";;;;+BAqCSA;;;eAAAA;;;;uBArCiD;+DACnC;uBAIK;;;;;;AAiB5B,MAAMA,0BACJC,IAAAA,iBAAU,EAAC,CAACC,OAAuBC;IACjC,MAAM,EAAEC,aAAaC,UAAU,KAAK,EAAEC,OAAO,IAAI,EAAE,GAAGC,YAAY,GAAGL;IAErE,MAAMM,UAAUC,IAAAA,eAAU,EACxB,UACA,oBACAC,IAAAA,kBAAW,EAACJ,OACZC,WAAWI,SAAS;IAGtB,qBAAO,qBAACN;QAAQF,KAAKA;QAAM,GAAGI,UAAU;QAAEI,WAAWH;;AACvD;AAEFR,UAAUY,WAAW,GAAG"}
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
5
|
_export_star(require("./Radio"), exports);
|
|
6
|
-
_export_star(require("./RadioButton"), exports);
|
|
7
6
|
_export_star(require("./RadioGroup"), exports);
|
|
8
7
|
function _export_star(from, to) {
|
|
9
8
|
Object.keys(from).forEach(function(k) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/Radio/index.tsx"],"sourcesContent":["export * from \"./Radio\";\nexport * from \"./
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/Radio/index.tsx"],"sourcesContent":["export * from \"./Radio\";\nexport * from \"./RadioGroup\";\n"],"names":[],"mappings":";;;;qBAAc;qBACA"}
|
|
@@ -22,9 +22,9 @@ export const Checkbox = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
|
22
22
|
"--is-selected": selected,
|
|
23
23
|
"--is-required": typeof isRequired === "boolean" && isRequired,
|
|
24
24
|
"--is-optional": typeof isRequired === "boolean" && !isRequired
|
|
25
|
-
}, validationClasses
|
|
25
|
+
}, validationClasses);
|
|
26
26
|
// Append an additional wrapper class name to differenitate from input
|
|
27
|
-
const wrapperClasses = classNames("mobius", "mobius/Checkbox", sharedClasses);
|
|
27
|
+
const wrapperClasses = classNames("mobius", "mobius/Checkbox", sharedClasses, className);
|
|
28
28
|
const inputClasses = classNames("mobius/CheckboxInput", sharedClasses);
|
|
29
29
|
const iconClasses = classNames("mobius/CheckboxIcon", sharedClasses);
|
|
30
30
|
const errorMessageId = useId();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/Checkbox/Checkbox.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n ChangeEvent,\n forwardRef,\n useRef,\n useState,\n KeyboardEvent,\n MouseEvent,\n useId,\n} from \"react\";\nimport classNames from \"classnames/dedupe\";\nimport { squareTick, square } from \"@simplybusiness/icons\";\nimport { ErrorMessage } from \"../ErrorMessage\";\nimport { ForwardedRefComponent } from \"../../types/components\";\nimport { CheckboxElementType, CheckboxProps, CheckboxRef } from \"./types\";\nimport { spaceDelimitedList } from \"../../utils/spaceDelimitedList\";\nimport { useValidationClasses } from \"../../hooks\";\nimport { Icon } from \"../Icon\";\n\nexport const Checkbox: ForwardedRefComponent<\n CheckboxProps,\n CheckboxElementType\n> = forwardRef((props: CheckboxProps, ref: CheckboxRef) => {\n const {\n id,\n label,\n isDisabled,\n isRequired,\n validationState,\n isInvalid,\n onChange,\n className,\n errorMessage,\n defaultSelected = false,\n isReadOnly,\n value,\n [\"aria-describedby\"]: ariaDescribedBy,\n ...rest\n } = props;\n const [selected, setSelected] = useState<boolean>(defaultSelected);\n const fallbackRef = useRef<HTMLInputElement>(null);\n const refObj = ref || fallbackRef;\n const inputId = useId();\n const validationClasses = useValidationClasses({\n validationState,\n isInvalid,\n });\n const sharedClasses = classNames(\n {\n \"--is-disabled\": isDisabled,\n \"--is-selected\": selected,\n \"--is-required\": typeof isRequired === \"boolean\" && isRequired,\n \"--is-optional\": typeof isRequired === \"boolean\" && !isRequired,\n },\n validationClasses,\n
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/Checkbox/Checkbox.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n ChangeEvent,\n forwardRef,\n useRef,\n useState,\n KeyboardEvent,\n MouseEvent,\n useId,\n} from \"react\";\nimport classNames from \"classnames/dedupe\";\nimport { squareTick, square } from \"@simplybusiness/icons\";\nimport { ErrorMessage } from \"../ErrorMessage\";\nimport { ForwardedRefComponent } from \"../../types/components\";\nimport { CheckboxElementType, CheckboxProps, CheckboxRef } from \"./types\";\nimport { spaceDelimitedList } from \"../../utils/spaceDelimitedList\";\nimport { useValidationClasses } from \"../../hooks\";\nimport { Icon } from \"../Icon\";\n\nexport const Checkbox: ForwardedRefComponent<\n CheckboxProps,\n CheckboxElementType\n> = forwardRef((props: CheckboxProps, ref: CheckboxRef) => {\n const {\n id,\n label,\n isDisabled,\n isRequired,\n validationState,\n isInvalid,\n onChange,\n className,\n errorMessage,\n defaultSelected = false,\n isReadOnly,\n value,\n [\"aria-describedby\"]: ariaDescribedBy,\n ...rest\n } = props;\n const [selected, setSelected] = useState<boolean>(defaultSelected);\n const fallbackRef = useRef<HTMLInputElement>(null);\n const refObj = ref || fallbackRef;\n const inputId = useId();\n const validationClasses = useValidationClasses({\n validationState,\n isInvalid,\n });\n const sharedClasses = classNames(\n {\n \"--is-disabled\": isDisabled,\n \"--is-selected\": selected,\n \"--is-required\": typeof isRequired === \"boolean\" && isRequired,\n \"--is-optional\": typeof isRequired === \"boolean\" && !isRequired,\n },\n validationClasses,\n );\n // Append an additional wrapper class name to differenitate from input\n const wrapperClasses = classNames(\n \"mobius\",\n \"mobius/Checkbox\",\n sharedClasses,\n className,\n );\n const inputClasses = classNames(\"mobius/CheckboxInput\", sharedClasses);\n const iconClasses = classNames(\"mobius/CheckboxIcon\", sharedClasses);\n const errorMessageId = useId();\n const shouldErrorMessageShow = errorMessage ? errorMessageId : undefined;\n const describedBy = spaceDelimitedList([\n shouldErrorMessageShow,\n ariaDescribedBy,\n ]);\n const labelId = useId();\n\n const toggleState = () => {\n setSelected(!selected);\n };\n\n const handleClick = (event: MouseEvent<CheckboxElementType>) => {\n const isMouseEvent = event.clientX;\n\n if (isMouseEvent) {\n toggleState();\n }\n };\n\n const handleChange = (event: ChangeEvent<CheckboxElementType>) => {\n if (onChange) {\n onChange(event);\n }\n };\n\n const handleKeyDown = (event: KeyboardEvent) => {\n if (event.code === \"Space\") {\n toggleState();\n }\n };\n\n return (\n <>\n <label className={wrapperClasses}>\n <input\n aria-describedby={describedBy}\n aria-errormessage={shouldErrorMessageShow}\n aria-invalid={isInvalid}\n aria-labelledby={labelId}\n readOnly={isReadOnly}\n disabled={isDisabled}\n ref={refObj}\n className={inputClasses}\n onClick={handleClick}\n onChange={handleChange}\n onKeyDown={handleKeyDown}\n type=\"checkbox\"\n defaultChecked={defaultSelected}\n required={isRequired}\n id={id || inputId}\n value={value}\n {...rest}\n />\n <Icon\n icon={selected ? squareTick : square}\n size=\"md\"\n className={iconClasses}\n />\n <span id={labelId} className=\"mobius/CheckboxLabel\">\n {label}\n </span>\n </label>\n <ErrorMessage id={errorMessageId} errorMessage={errorMessage} />\n </>\n );\n});\n"],"names":["forwardRef","useRef","useState","useId","classNames","squareTick","square","ErrorMessage","spaceDelimitedList","useValidationClasses","Icon","Checkbox","props","ref","id","label","isDisabled","isRequired","validationState","isInvalid","onChange","className","errorMessage","defaultSelected","isReadOnly","value","ariaDescribedBy","rest","selected","setSelected","fallbackRef","refObj","inputId","validationClasses","sharedClasses","wrapperClasses","inputClasses","iconClasses","errorMessageId","shouldErrorMessageShow","undefined","describedBy","labelId","toggleState","handleClick","event","isMouseEvent","clientX","handleChange","handleKeyDown","code","input","aria-describedby","aria-errormessage","aria-invalid","aria-labelledby","readOnly","disabled","onClick","onKeyDown","type","defaultChecked","required","icon","size","span"],"mappings":"AAAA;;AAEA,SAEEA,UAAU,EACVC,MAAM,EACNC,QAAQ,EAGRC,KAAK,QACA,QAAQ;AACf,OAAOC,gBAAgB,oBAAoB;AAC3C,SAASC,UAAU,EAAEC,MAAM,QAAQ,wBAAwB;AAC3D,SAASC,YAAY,QAAQ,kBAAkB;AAG/C,SAASC,kBAAkB,QAAQ,iCAAiC;AACpE,SAASC,oBAAoB,QAAQ,cAAc;AACnD,SAASC,IAAI,QAAQ,UAAU;AAE/B,OAAO,MAAMC,yBAGTX,WAAW,CAACY,OAAsBC;IACpC,MAAM,EACJC,EAAE,EACFC,KAAK,EACLC,UAAU,EACVC,UAAU,EACVC,eAAe,EACfC,SAAS,EACTC,QAAQ,EACRC,SAAS,EACTC,YAAY,EACZC,kBAAkB,KAAK,EACvBC,UAAU,EACVC,KAAK,EACL,CAAC,mBAAmB,EAAEC,eAAe,EACrC,GAAGC,MACJ,GAAGf;IACJ,MAAM,CAACgB,UAAUC,YAAY,GAAG3B,SAAkBqB;IAClD,MAAMO,cAAc7B,OAAyB;IAC7C,MAAM8B,SAASlB,OAAOiB;IACtB,MAAME,UAAU7B;IAChB,MAAM8B,oBAAoBxB,qBAAqB;QAC7CS;QACAC;IACF;IACA,MAAMe,gBAAgB9B,WACpB;QACE,iBAAiBY;QACjB,iBAAiBY;QACjB,iBAAiB,OAAOX,eAAe,aAAaA;QACpD,iBAAiB,OAAOA,eAAe,aAAa,CAACA;IACvD,GACAgB;IAEF,sEAAsE;IACtE,MAAME,iBAAiB/B,WACrB,UACA,mBACA8B,eACAb;IAEF,MAAMe,eAAehC,WAAW,wBAAwB8B;IACxD,MAAMG,cAAcjC,WAAW,uBAAuB8B;IACtD,MAAMI,iBAAiBnC;IACvB,MAAMoC,yBAAyBjB,eAAegB,iBAAiBE;IAC/D,MAAMC,cAAcjC,mBAAmB;QACrC+B;QACAb;KACD;IACD,MAAMgB,UAAUvC;IAEhB,MAAMwC,cAAc;QAClBd,YAAY,CAACD;IACf;IAEA,MAAMgB,cAAc,CAACC;QACnB,MAAMC,eAAeD,MAAME,OAAO;QAElC,IAAID,cAAc;YAChBH;QACF;IACF;IAEA,MAAMK,eAAe,CAACH;QACpB,IAAIzB,UAAU;YACZA,SAASyB;QACX;IACF;IAEA,MAAMI,gBAAgB,CAACJ;QACrB,IAAIA,MAAMK,IAAI,KAAK,SAAS;YAC1BP;QACF;IACF;IAEA,qBACE;;0BACE,MAAC5B;gBAAMM,WAAWc;;kCAChB,KAACgB;wBACCC,oBAAkBX;wBAClBY,qBAAmBd;wBACnBe,gBAAcnC;wBACdoC,mBAAiBb;wBACjBc,UAAUhC;wBACViC,UAAUzC;wBACVH,KAAKkB;wBACLV,WAAWe;wBACXsB,SAASd;wBACTxB,UAAU4B;wBACVW,WAAWV;wBACXW,MAAK;wBACLC,gBAAgBtC;wBAChBuC,UAAU7C;wBACVH,IAAIA,MAAMkB;wBACVP,OAAOA;wBACN,GAAGE,IAAI;;kCAEV,KAACjB;wBACCqD,MAAMnC,WAAWvB,aAAaC;wBAC9B0D,MAAK;wBACL3C,WAAWgB;;kCAEb,KAAC4B;wBAAKnD,IAAI4B;wBAASrB,WAAU;kCAC1BN;;;;0BAGL,KAACR;gBAAaO,IAAIwB;gBAAgBhB,cAAcA;;;;AAGtD,GAAG"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { forwardRef } from "react";
|
|
3
3
|
import classNames from "classnames/dedupe";
|
|
4
|
+
import { sizeClasses } from "../../utils";
|
|
4
5
|
const Container = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
5
|
-
const { elementType: Element = "div", ...otherProps } = props;
|
|
6
|
-
const classes = classNames("mobius", "mobius/Container", otherProps.className);
|
|
6
|
+
const { elementType: Element = "div", size = "md", ...otherProps } = props;
|
|
7
|
+
const classes = classNames("mobius", "mobius/Container", sizeClasses(size), otherProps.className);
|
|
7
8
|
return /*#__PURE__*/ _jsx(Element, {
|
|
8
9
|
ref: ref,
|
|
9
10
|
...otherProps,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/Container/Container.tsx"],"sourcesContent":["import { forwardRef, Ref, RefAttributes, ReactNode } from \"react\";\nimport classNames from \"classnames/dedupe\";\nimport { DOMProps } from \"../../types/dom\";\nimport { ForwardedRefComponent } from \"../../types/components\";\n\nexport type ContainerElementType = HTMLDivElement;\nexport type ContainerRef = Ref<ContainerElementType>;\n\nexport interface ContainerProps\n extends DOMProps,\n RefAttributes<ContainerElementType> {\n id?: string;\n /** Custom class name for setting specific CSS */\n className?: string;\n /** HTML element for the Box */\n elementType?: \"div\" | \"span\";\n children?: ReactNode;\n}\n\nconst Container: ForwardedRefComponent<ContainerProps, ContainerElementType> =\n forwardRef((props: ContainerProps, ref: ContainerRef) => {\n const { elementType: Element = \"div\", ...otherProps } = props;\n\n const classes = classNames(\n \"mobius\",\n \"mobius/Container\",\n otherProps.className,\n );\n\n return <Element ref={ref} {...otherProps} className={classes} />;\n });\n\nContainer.displayName = \"Container\";\nexport { Container };\n"],"names":["forwardRef","classNames","Container","props","ref","elementType","Element","otherProps","classes","className","displayName"],"mappings":";AAAA,SAASA,UAAU,QAAuC,QAAQ;AAClE,OAAOC,gBAAgB,oBAAoB;
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/Container/Container.tsx"],"sourcesContent":["import { forwardRef, Ref, RefAttributes, ReactNode } from \"react\";\nimport classNames from \"classnames/dedupe\";\nimport { DOMProps } from \"../../types/dom\";\nimport { ForwardedRefComponent } from \"../../types/components\";\nimport { SizeType } from \"../../types\";\nimport { sizeClasses } from \"../../utils\";\n\nexport type ContainerElementType = HTMLDivElement;\nexport type ContainerRef = Ref<ContainerElementType>;\n\nexport interface ContainerProps\n extends DOMProps,\n RefAttributes<ContainerElementType> {\n id?: string;\n /** Custom class name for setting specific CSS */\n className?: string;\n /** HTML element for the Box */\n elementType?: \"div\" | \"span\";\n size?: SizeType;\n children?: ReactNode;\n}\n\nconst Container: ForwardedRefComponent<ContainerProps, ContainerElementType> =\n forwardRef((props: ContainerProps, ref: ContainerRef) => {\n const { elementType: Element = \"div\", size = \"md\", ...otherProps } = props;\n\n const classes = classNames(\n \"mobius\",\n \"mobius/Container\",\n sizeClasses(size),\n otherProps.className,\n );\n\n return <Element ref={ref} {...otherProps} className={classes} />;\n });\n\nContainer.displayName = \"Container\";\nexport { Container };\n"],"names":["forwardRef","classNames","sizeClasses","Container","props","ref","elementType","Element","size","otherProps","classes","className","displayName"],"mappings":";AAAA,SAASA,UAAU,QAAuC,QAAQ;AAClE,OAAOC,gBAAgB,oBAAoB;AAI3C,SAASC,WAAW,QAAQ,cAAc;AAiB1C,MAAMC,0BACJH,WAAW,CAACI,OAAuBC;IACjC,MAAM,EAAEC,aAAaC,UAAU,KAAK,EAAEC,OAAO,IAAI,EAAE,GAAGC,YAAY,GAAGL;IAErE,MAAMM,UAAUT,WACd,UACA,oBACAC,YAAYM,OACZC,WAAWE,SAAS;IAGtB,qBAAO,KAACJ;QAAQF,KAAKA;QAAM,GAAGI,UAAU;QAAEE,WAAWD;;AACvD;AAEFP,UAAUS,WAAW,GAAG;AACxB,SAAST,SAAS,GAAG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/Radio/index.tsx"],"sourcesContent":["export * from \"./Radio\";\nexport * from \"./
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/Radio/index.tsx"],"sourcesContent":["export * from \"./Radio\";\nexport * from \"./RadioGroup\";\n"],"names":[],"mappings":"AAAA,cAAc,UAAU;AACxB,cAAc,eAAe"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Ref, RefAttributes, ReactNode } from "react";
|
|
2
2
|
import { DOMProps } from "../../types/dom";
|
|
3
3
|
import { ForwardedRefComponent } from "../../types/components";
|
|
4
|
+
import { SizeType } from "../../types";
|
|
4
5
|
export type ContainerElementType = HTMLDivElement;
|
|
5
6
|
export type ContainerRef = Ref<ContainerElementType>;
|
|
6
7
|
export interface ContainerProps extends DOMProps, RefAttributes<ContainerElementType> {
|
|
@@ -9,6 +10,7 @@ export interface ContainerProps extends DOMProps, RefAttributes<ContainerElement
|
|
|
9
10
|
className?: string;
|
|
10
11
|
/** HTML element for the Box */
|
|
11
12
|
elementType?: "div" | "span";
|
|
13
|
+
size?: SizeType;
|
|
12
14
|
children?: ReactNode;
|
|
13
15
|
}
|
|
14
16
|
declare const Container: ForwardedRefComponent<ContainerProps, ContainerElementType>;
|
package/package.json
CHANGED
|
@@ -24,7 +24,7 @@ import { Checkbox } from "@simplybusiness/mobius";
|
|
|
24
24
|
|
|
25
25
|
### Normal
|
|
26
26
|
|
|
27
|
-
For this component appear selected use `defaultSelected` boolean prop.
|
|
27
|
+
For this component to appear selected use `defaultSelected` boolean prop.
|
|
28
28
|
|
|
29
29
|
This will allow user to change the value.
|
|
30
30
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { render } from "@testing-library/react";
|
|
1
|
+
import { render, screen } from "@testing-library/react";
|
|
2
2
|
import userEvent from "@testing-library/user-event";
|
|
3
3
|
import { Checkbox } from ".";
|
|
4
4
|
|
|
@@ -193,17 +193,19 @@ describe("Checkbox", () => {
|
|
|
193
193
|
});
|
|
194
194
|
|
|
195
195
|
it("includes custom class name", () => {
|
|
196
|
-
const
|
|
196
|
+
const labelText = "Agree";
|
|
197
197
|
const customClass = "my-class";
|
|
198
198
|
|
|
199
|
-
|
|
200
|
-
<Checkbox label={
|
|
199
|
+
render(
|
|
200
|
+
<Checkbox label={labelText} className={customClass} value="value" />,
|
|
201
201
|
);
|
|
202
202
|
|
|
203
|
-
const
|
|
203
|
+
const input = screen.getByRole("checkbox");
|
|
204
|
+
const label = input.parentElement;
|
|
204
205
|
|
|
205
|
-
expect(
|
|
206
|
-
expect(
|
|
206
|
+
expect(input).not.toHaveClass(customClass);
|
|
207
|
+
expect(input).toHaveClass(CHECKBOX_CLASS_NAME);
|
|
208
|
+
expect(label).toHaveClass(customClass);
|
|
207
209
|
});
|
|
208
210
|
|
|
209
211
|
it("only sets id on the input element", () => {
|
|
@@ -54,10 +54,14 @@ export const Checkbox: ForwardedRefComponent<
|
|
|
54
54
|
"--is-optional": typeof isRequired === "boolean" && !isRequired,
|
|
55
55
|
},
|
|
56
56
|
validationClasses,
|
|
57
|
-
className,
|
|
58
57
|
);
|
|
59
58
|
// Append an additional wrapper class name to differenitate from input
|
|
60
|
-
const wrapperClasses = classNames(
|
|
59
|
+
const wrapperClasses = classNames(
|
|
60
|
+
"mobius",
|
|
61
|
+
"mobius/Checkbox",
|
|
62
|
+
sharedClasses,
|
|
63
|
+
className,
|
|
64
|
+
);
|
|
61
65
|
const inputClasses = classNames("mobius/CheckboxInput", sharedClasses);
|
|
62
66
|
const iconClasses = classNames("mobius/CheckboxIcon", sharedClasses);
|
|
63
67
|
const errorMessageId = useId();
|
|
@@ -415,7 +415,7 @@ describe("CheckboxGroup", () => {
|
|
|
415
415
|
|
|
416
416
|
const option = getByLabelText(optionText);
|
|
417
417
|
|
|
418
|
-
expect(option).toHaveClass(customClass);
|
|
418
|
+
expect(option.parentElement).toHaveClass(customClass);
|
|
419
419
|
expect(option).toHaveClass(CHECKBOX_CLASS_NAME);
|
|
420
420
|
});
|
|
421
421
|
|
|
@@ -2,6 +2,8 @@ import { forwardRef, Ref, RefAttributes, ReactNode } from "react";
|
|
|
2
2
|
import classNames from "classnames/dedupe";
|
|
3
3
|
import { DOMProps } from "../../types/dom";
|
|
4
4
|
import { ForwardedRefComponent } from "../../types/components";
|
|
5
|
+
import { SizeType } from "../../types";
|
|
6
|
+
import { sizeClasses } from "../../utils";
|
|
5
7
|
|
|
6
8
|
export type ContainerElementType = HTMLDivElement;
|
|
7
9
|
export type ContainerRef = Ref<ContainerElementType>;
|
|
@@ -14,16 +16,18 @@ export interface ContainerProps
|
|
|
14
16
|
className?: string;
|
|
15
17
|
/** HTML element for the Box */
|
|
16
18
|
elementType?: "div" | "span";
|
|
19
|
+
size?: SizeType;
|
|
17
20
|
children?: ReactNode;
|
|
18
21
|
}
|
|
19
22
|
|
|
20
23
|
const Container: ForwardedRefComponent<ContainerProps, ContainerElementType> =
|
|
21
24
|
forwardRef((props: ContainerProps, ref: ContainerRef) => {
|
|
22
|
-
const { elementType: Element = "div", ...otherProps } = props;
|
|
25
|
+
const { elementType: Element = "div", size = "md", ...otherProps } = props;
|
|
23
26
|
|
|
24
27
|
const classes = classNames(
|
|
25
28
|
"mobius",
|
|
26
29
|
"mobius/Container",
|
|
30
|
+
sizeClasses(size),
|
|
27
31
|
otherProps.className,
|
|
28
32
|
);
|
|
29
33
|
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
"use strict";
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "RadioButton", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function() {
|
|
9
|
-
return RadioButton;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
const _jsxruntime = require("react/jsx-runtime");
|
|
13
|
-
const _react = require("react");
|
|
14
|
-
const _dedupe = /*#__PURE__*/ _interop_require_default(require("classnames/dedupe"));
|
|
15
|
-
const _Radio = require("./Radio");
|
|
16
|
-
function _interop_require_default(obj) {
|
|
17
|
-
return obj && obj.__esModule ? obj : {
|
|
18
|
-
default: obj
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
const RadioButton = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
|
|
22
|
-
const classes = (0, _dedupe.default)(props.className, "--is-radio-button");
|
|
23
|
-
const radioProps = {
|
|
24
|
-
...props,
|
|
25
|
-
className: classes,
|
|
26
|
-
ref
|
|
27
|
-
};
|
|
28
|
-
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_Radio.Radio, {
|
|
29
|
-
...radioProps
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
//# sourceMappingURL=RadioButton.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/Radio/RadioButton.tsx"],"sourcesContent":["\"use client\";\n\nimport { forwardRef } from \"react\";\nimport classNames from \"classnames/dedupe\";\nimport { ForwardedRefComponent } from \"../../types/components\";\nimport { Radio, RadioElementType, RadioProps, RadioRef } from \"./Radio\";\n\nexport const RadioButton: ForwardedRefComponent<RadioProps, RadioElementType> =\n forwardRef((props: RadioProps, ref: RadioRef) => {\n const classes = classNames(props.className, \"--is-radio-button\");\n const radioProps = {\n ...props,\n className: classes,\n ref,\n };\n\n return <Radio {...radioProps} />;\n });\n"],"names":["RadioButton","forwardRef","props","ref","classes","classNames","className","radioProps","Radio"],"mappings":"AAAA;;;;;+BAOaA;;;eAAAA;;;;uBALc;+DACJ;uBAEuC;;;;;;AAEvD,MAAMA,4BACXC,IAAAA,iBAAU,EAAC,CAACC,OAAmBC;IAC7B,MAAMC,UAAUC,IAAAA,eAAU,EAACH,MAAMI,SAAS,EAAE;IAC5C,MAAMC,aAAa;QACjB,GAAGL,KAAK;QACRI,WAAWF;QACXD;IACF;IAEA,qBAAO,qBAACK,YAAK;QAAE,GAAGD,UAAU;;AAC9B"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { forwardRef } from "react";
|
|
4
|
-
import classNames from "classnames/dedupe";
|
|
5
|
-
import { Radio } from "./Radio";
|
|
6
|
-
export const RadioButton = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
7
|
-
const classes = classNames(props.className, "--is-radio-button");
|
|
8
|
-
const radioProps = {
|
|
9
|
-
...props,
|
|
10
|
-
className: classes,
|
|
11
|
-
ref
|
|
12
|
-
};
|
|
13
|
-
return /*#__PURE__*/ _jsx(Radio, {
|
|
14
|
-
...radioProps
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
//# sourceMappingURL=RadioButton.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/Radio/RadioButton.tsx"],"sourcesContent":["\"use client\";\n\nimport { forwardRef } from \"react\";\nimport classNames from \"classnames/dedupe\";\nimport { ForwardedRefComponent } from \"../../types/components\";\nimport { Radio, RadioElementType, RadioProps, RadioRef } from \"./Radio\";\n\nexport const RadioButton: ForwardedRefComponent<RadioProps, RadioElementType> =\n forwardRef((props: RadioProps, ref: RadioRef) => {\n const classes = classNames(props.className, \"--is-radio-button\");\n const radioProps = {\n ...props,\n className: classes,\n ref,\n };\n\n return <Radio {...radioProps} />;\n });\n"],"names":["forwardRef","classNames","Radio","RadioButton","props","ref","classes","className","radioProps"],"mappings":"AAAA;;AAEA,SAASA,UAAU,QAAQ,QAAQ;AACnC,OAAOC,gBAAgB,oBAAoB;AAE3C,SAASC,KAAK,QAAgD,UAAU;AAExE,OAAO,MAAMC,4BACXH,WAAW,CAACI,OAAmBC;IAC7B,MAAMC,UAAUL,WAAWG,MAAMG,SAAS,EAAE;IAC5C,MAAMC,aAAa;QACjB,GAAGJ,KAAK;QACRG,WAAWD;QACXD;IACF;IAEA,qBAAO,KAACH;QAAO,GAAGM,UAAU;;AAC9B,GAAG"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
|
-
import { RadioGroup } from "./RadioGroup";
|
|
3
|
-
type StoryType = StoryObj<typeof RadioGroup>;
|
|
4
|
-
declare const meta: Meta<typeof RadioGroup>;
|
|
5
|
-
export declare const Normal: StoryType;
|
|
6
|
-
export declare const LabelProp: StoryType;
|
|
7
|
-
export declare const Selected: StoryType;
|
|
8
|
-
export declare const Disabled: StoryType;
|
|
9
|
-
export declare const VerticalOrientation: StoryType;
|
|
10
|
-
export declare const IconButtons: StoryType;
|
|
11
|
-
export default meta;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import { Meta, ArgTypes, Canvas } from "@storybook/blocks";
|
|
2
|
-
import { RadioButton } from "./RadioButton";
|
|
3
|
-
import { RadioGroup } from "./RadioGroup";
|
|
4
|
-
import * as RadioButtonStories from "./RadioButton.stories";
|
|
5
|
-
|
|
6
|
-
<Meta of={RadioButtonStories} />
|
|
7
|
-
|
|
8
|
-
# RadioButton
|
|
9
|
-
|
|
10
|
-
**RadioButton** is used to display a group of buttons, only one of which can be selected. It must be contained within a `<RadioGroup />` component to handle the ARIA attributes correctly.
|
|
11
|
-
|
|
12
|
-
A RadioButton can wrap an Icon and must have a `label` or `aria-labelledby` prop. A visible label is displayed inside the button.
|
|
13
|
-
|
|
14
|
-
## Install
|
|
15
|
-
|
|
16
|
-
```bash
|
|
17
|
-
yarn add @simplybusiness/mobius
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
## Usage
|
|
21
|
-
|
|
22
|
-
```js
|
|
23
|
-
import { RadioButton, RadioGroup } from "@simplybusiness/mobius";
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
## Examples
|
|
27
|
-
|
|
28
|
-
### Normal
|
|
29
|
-
|
|
30
|
-
For a radio button to appear selected use `value` prop which expects a string.
|
|
31
|
-
|
|
32
|
-
For example, `<RadioGroup defaultValue="blue">`
|
|
33
|
-
|
|
34
|
-
<Canvas of={RadioButtonStories.Normal} />
|
|
35
|
-
|
|
36
|
-
### Label Prop
|
|
37
|
-
|
|
38
|
-
<Canvas of={RadioButtonStories.LabelProp} />
|
|
39
|
-
|
|
40
|
-
### Selected
|
|
41
|
-
|
|
42
|
-
<Canvas of={RadioButtonStories.Selected} />
|
|
43
|
-
|
|
44
|
-
### Disabled
|
|
45
|
-
|
|
46
|
-
<Canvas of={RadioButtonStories.Disabled} />
|
|
47
|
-
|
|
48
|
-
### Vertical Orientation
|
|
49
|
-
|
|
50
|
-
<Canvas of={RadioButtonStories.VerticalOrientation} />
|
|
51
|
-
|
|
52
|
-
### Icon Buttons
|
|
53
|
-
|
|
54
|
-
<Canvas of={RadioButtonStories.IconButtons} />
|
|
55
|
-
|
|
56
|
-
## Accessibility
|
|
57
|
-
|
|
58
|
-
When the `label` prop is not provided, make sure to provide the `aria-label` prop instead. If the radio group is labeled by a separate element, the `aria-labelledby` props must be used with the id of the labeling element.
|
|
59
|
-
|
|
60
|
-
## Events
|
|
61
|
-
|
|
62
|
-
The `onChange` prop can be used to listen to changes of the selected radio button. See the prop table for the complete list of events supported.
|
|
63
|
-
|
|
64
|
-
## RadioButton Props
|
|
65
|
-
|
|
66
|
-
<ArgTypes of={{ ...RadioGroup, ...RadioButton }} />
|
|
67
|
-
|
|
68
|
-
## Component HTML Structure and Class names
|
|
69
|
-
|
|
70
|
-
The following HTML is rendered for a Radio Group with simple label prop only:
|
|
71
|
-
|
|
72
|
-
```html
|
|
73
|
-
<div class="mobius mobius/RadioGroup --is-horizontal">
|
|
74
|
-
<label class="mobius/Label --is-horizontal"> Color </label>
|
|
75
|
-
<div class="mobius/RadioWrapper --is-horizontal">
|
|
76
|
-
<label class="mobius/RadioLabel --is-radio-button">
|
|
77
|
-
<input class="mobius/RadioInput" type="radio" value="red" />
|
|
78
|
-
<div class="mobius/RadioContent">Red</div>
|
|
79
|
-
</label>
|
|
80
|
-
<label class="mobius/RadioLabel --is-radio-button">
|
|
81
|
-
<input class="mobius/RadioInput" type="radio" value="blue" checked />
|
|
82
|
-
<div class="mobius/RadioContent">Blue</div>
|
|
83
|
-
</label>
|
|
84
|
-
</div>
|
|
85
|
-
</div>
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
And this is rendered when there is a child Icon component:
|
|
89
|
-
|
|
90
|
-
```html
|
|
91
|
-
<div class="mobius mobius mobius/RadioGroup --is-horizontal">
|
|
92
|
-
<label class="mobius/Label --is-horizontal">Business Type</label>
|
|
93
|
-
<div class="mobius/RadioWrapper">
|
|
94
|
-
<label class="mobius/RadioLabel --is-multiline --is-radio-button">
|
|
95
|
-
<input
|
|
96
|
-
class="mobius/RadioInput --is-multiline"
|
|
97
|
-
type="radio"
|
|
98
|
-
value="sole_trader"
|
|
99
|
-
/>
|
|
100
|
-
<div class="mobius/RadioContentMultiline">
|
|
101
|
-
<div class="mobius/RadioContentFirstLine">Sole Trader</div>
|
|
102
|
-
<div class="mobius/RadioExtraContent">{Icon}</div>
|
|
103
|
-
</div>
|
|
104
|
-
</label>
|
|
105
|
-
<label class="mobius/RadioLabel --is-multiline --is-radio-button">
|
|
106
|
-
<input
|
|
107
|
-
class="mobius/RadioInput --is-multiline"
|
|
108
|
-
type="radio"
|
|
109
|
-
value="partnership"
|
|
110
|
-
/>
|
|
111
|
-
<div class="mobius/RadioContentMultiline">
|
|
112
|
-
<div class="mobius/RadioContentFirstLine">Partnership</div>
|
|
113
|
-
<div class="mobius/RadioExtraContent">{Icon}</div>
|
|
114
|
-
</div>
|
|
115
|
-
</label>
|
|
116
|
-
<label class="mobius/RadioLabel --is-multiline --is-radio-button">
|
|
117
|
-
<input
|
|
118
|
-
class="mobius/RadioInput --is-multiline"
|
|
119
|
-
type="radio"
|
|
120
|
-
value="ltd_company"
|
|
121
|
-
/>
|
|
122
|
-
<div class="mobius/RadioContentMultiline">
|
|
123
|
-
<div class="mobius/RadioContentFirstLine">Ltd Company</div>
|
|
124
|
-
<div class="mobius/RadioExtraContent">{Icon}</div>
|
|
125
|
-
</div>
|
|
126
|
-
</label>
|
|
127
|
-
</div>
|
|
128
|
-
</div>
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
Class names are augmented with the following flags if true (affected classes shown above):
|
|
132
|
-
|
|
133
|
-
- \--is-radio-button
|
|
134
|
-
- \--is-disabled
|
|
135
|
-
- \--is-selected
|
|
136
|
-
- \--is-multiline
|
|
137
|
-
- \--is-required
|
|
138
|
-
|
|
139
|
-
Class names for `<RadioGroup />`:
|
|
140
|
-
|
|
141
|
-
- \--is-disabled
|
|
142
|
-
- \--is-valid
|
|
143
|
-
- \--is-invalid
|
|
144
|
-
- \--is-required
|
|
145
|
-
- \--is-optional
|
|
146
|
-
- \--is-horizontal OR --is-vertical
|
|
147
|
-
|
|
148
|
-
---
|
|
149
|
-
|
|
150
|
-
[See on Github](https://github.com/simplybusiness/mobius/tree/master/packages/mobius/src/components/Radio) | [Give feedback](https://simplybusiness.atlassian.net/CreateIssue.jspa?issuetype=10103&pid=10609) | [Get support](https://simplybusiness.slack.com/archives/C016CC0NDNE)
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import { menu, star, user } from "@simplybusiness/icons";
|
|
2
|
-
import type { Meta, StoryObj } from "@storybook/react";
|
|
3
|
-
import { excludeControls } from "../../utils";
|
|
4
|
-
import { StoryContainer } from "../../utils/StoryContainer";
|
|
5
|
-
import { Icon } from "../Icon";
|
|
6
|
-
import { RadioButton } from "./RadioButton";
|
|
7
|
-
import { RadioGroup, RadioGroupProps } from "./RadioGroup";
|
|
8
|
-
|
|
9
|
-
type StoryType = StoryObj<typeof RadioGroup>;
|
|
10
|
-
|
|
11
|
-
const meta: Meta<typeof RadioGroup> = {
|
|
12
|
-
title: "Forms/RadioButton",
|
|
13
|
-
component: RadioGroup,
|
|
14
|
-
argTypes: {
|
|
15
|
-
orientation: {
|
|
16
|
-
control: { type: "radio" },
|
|
17
|
-
options: ["horizontal", "vertical"],
|
|
18
|
-
},
|
|
19
|
-
...excludeControls(
|
|
20
|
-
"name",
|
|
21
|
-
"groupDisabled",
|
|
22
|
-
"selected",
|
|
23
|
-
"setSelected",
|
|
24
|
-
"defaultValue",
|
|
25
|
-
"value",
|
|
26
|
-
),
|
|
27
|
-
},
|
|
28
|
-
args: {
|
|
29
|
-
errorMessage: "",
|
|
30
|
-
},
|
|
31
|
-
decorators: [
|
|
32
|
-
Story => (
|
|
33
|
-
<StoryContainer>
|
|
34
|
-
<Story />
|
|
35
|
-
</StoryContainer>
|
|
36
|
-
),
|
|
37
|
-
],
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
export const Normal: StoryType = {
|
|
41
|
-
render: (args: RadioGroupProps) => (
|
|
42
|
-
<RadioGroup {...args}>
|
|
43
|
-
<RadioButton value="red">Red</RadioButton>
|
|
44
|
-
<RadioButton value="blue">Blue</RadioButton>
|
|
45
|
-
</RadioGroup>
|
|
46
|
-
),
|
|
47
|
-
args: {
|
|
48
|
-
label: "Color",
|
|
49
|
-
orientation: "horizontal",
|
|
50
|
-
isDisabled: false,
|
|
51
|
-
isRequired: false,
|
|
52
|
-
defaultValue: "blue",
|
|
53
|
-
},
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
export const LabelProp: StoryType = {
|
|
57
|
-
render: (args: RadioGroupProps) => (
|
|
58
|
-
<RadioGroup {...args}>
|
|
59
|
-
<RadioButton value="red" label="Red" />
|
|
60
|
-
<RadioButton value="blue" label="Blue" />
|
|
61
|
-
</RadioGroup>
|
|
62
|
-
),
|
|
63
|
-
args: {
|
|
64
|
-
label: "Color",
|
|
65
|
-
orientation: "horizontal",
|
|
66
|
-
isDisabled: false,
|
|
67
|
-
isRequired: false,
|
|
68
|
-
},
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
export const Selected: StoryType = {
|
|
72
|
-
render: (args: RadioGroupProps) => (
|
|
73
|
-
<RadioGroup {...args}>
|
|
74
|
-
<RadioButton value="red" label="Red" />
|
|
75
|
-
<RadioButton value="blue" label="Blue" />
|
|
76
|
-
</RadioGroup>
|
|
77
|
-
),
|
|
78
|
-
args: {
|
|
79
|
-
label: "Color",
|
|
80
|
-
defaultValue: "red",
|
|
81
|
-
orientation: "horizontal",
|
|
82
|
-
isDisabled: false,
|
|
83
|
-
isRequired: false,
|
|
84
|
-
},
|
|
85
|
-
argTypes: {
|
|
86
|
-
value: {
|
|
87
|
-
control: { type: "radio" },
|
|
88
|
-
options: ["red", "blue"],
|
|
89
|
-
},
|
|
90
|
-
},
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
export const Disabled: StoryType = {
|
|
94
|
-
render: (args: RadioGroupProps) => (
|
|
95
|
-
<RadioGroup {...args}>
|
|
96
|
-
<RadioButton value="red" label="Red" />
|
|
97
|
-
<RadioButton value="blue" label="Blue" />
|
|
98
|
-
</RadioGroup>
|
|
99
|
-
),
|
|
100
|
-
args: {
|
|
101
|
-
label: "Color",
|
|
102
|
-
orientation: "horizontal",
|
|
103
|
-
isDisabled: true,
|
|
104
|
-
isRequired: false,
|
|
105
|
-
defaultValue: "red",
|
|
106
|
-
},
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
export const VerticalOrientation: StoryType = {
|
|
110
|
-
render: (args: RadioGroupProps) => (
|
|
111
|
-
<RadioGroup {...args}>
|
|
112
|
-
<RadioButton value="red" label="Red" />
|
|
113
|
-
<RadioButton value="blue" label="Blue" />
|
|
114
|
-
</RadioGroup>
|
|
115
|
-
),
|
|
116
|
-
args: {
|
|
117
|
-
label: "Color",
|
|
118
|
-
orientation: "vertical",
|
|
119
|
-
isDisabled: false,
|
|
120
|
-
isRequired: false,
|
|
121
|
-
defaultValue: "blue",
|
|
122
|
-
},
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
export const IconButtons: StoryType = {
|
|
126
|
-
render: (args: RadioGroupProps) => (
|
|
127
|
-
<RadioGroup {...args}>
|
|
128
|
-
<RadioButton value="sole_trader" label="Sole Trader">
|
|
129
|
-
<Icon icon={user} />
|
|
130
|
-
</RadioButton>
|
|
131
|
-
<RadioButton value="partnership" label="Partnership">
|
|
132
|
-
<Icon icon={star} />
|
|
133
|
-
</RadioButton>
|
|
134
|
-
<RadioButton value="company" label="Ltd Company">
|
|
135
|
-
<Icon icon={menu} />
|
|
136
|
-
</RadioButton>
|
|
137
|
-
</RadioGroup>
|
|
138
|
-
),
|
|
139
|
-
args: {
|
|
140
|
-
label: "Business Type",
|
|
141
|
-
orientation: "horizontal",
|
|
142
|
-
isDisabled: false,
|
|
143
|
-
isRequired: false,
|
|
144
|
-
defaultValue: "partnership",
|
|
145
|
-
},
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
export default meta;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { render, screen } from "@testing-library/react";
|
|
2
|
-
import { RadioGroup, RadioButton } from ".";
|
|
3
|
-
|
|
4
|
-
describe("RadioButton", () => {
|
|
5
|
-
it("should render without error", () => {
|
|
6
|
-
const component = render(
|
|
7
|
-
<RadioGroup label="Color">
|
|
8
|
-
<RadioButton value="red">Red</RadioButton>
|
|
9
|
-
<RadioButton value="blue">Blue</RadioButton>
|
|
10
|
-
</RadioGroup>,
|
|
11
|
-
);
|
|
12
|
-
|
|
13
|
-
expect(component).toBeTruthy();
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it("uses base Mobius class", () => {
|
|
17
|
-
const labelText = "Color";
|
|
18
|
-
const redText = "Red";
|
|
19
|
-
const blueText = "Blue";
|
|
20
|
-
const RADIO_BUTTON_CLASS_NAME = "--is-radio-button";
|
|
21
|
-
|
|
22
|
-
render(
|
|
23
|
-
<RadioGroup label={labelText}>
|
|
24
|
-
<RadioButton value="red">{redText}</RadioButton>
|
|
25
|
-
<RadioButton value="blue">{blueText}</RadioButton>
|
|
26
|
-
</RadioGroup>,
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
const redOption = screen.getByLabelText(redText);
|
|
30
|
-
const blueOption = screen.getByLabelText(blueText);
|
|
31
|
-
|
|
32
|
-
expect(redOption.parentElement).toHaveClass(RADIO_BUTTON_CLASS_NAME);
|
|
33
|
-
expect(blueOption.parentElement).toHaveClass(RADIO_BUTTON_CLASS_NAME);
|
|
34
|
-
});
|
|
35
|
-
});
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
import { forwardRef } from "react";
|
|
4
|
-
import classNames from "classnames/dedupe";
|
|
5
|
-
import { ForwardedRefComponent } from "../../types/components";
|
|
6
|
-
import { Radio, RadioElementType, RadioProps, RadioRef } from "./Radio";
|
|
7
|
-
|
|
8
|
-
export const RadioButton: ForwardedRefComponent<RadioProps, RadioElementType> =
|
|
9
|
-
forwardRef((props: RadioProps, ref: RadioRef) => {
|
|
10
|
-
const classes = classNames(props.className, "--is-radio-button");
|
|
11
|
-
const radioProps = {
|
|
12
|
-
...props,
|
|
13
|
-
className: classes,
|
|
14
|
-
ref,
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
return <Radio {...radioProps} />;
|
|
18
|
-
});
|