@simplybusiness/mobius 4.12.0 → 4.14.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 +19 -0
- package/dist/cjs/components/Checkbox/Checkbox.js +4 -3
- 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 +4 -3
- package/dist/esm/components/Checkbox/Checkbox.js.map +1 -1
- package/dist/esm/components/Checkbox/types.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/Checkbox/types.d.ts +2 -0
- package/dist/types/components/Container/Container.d.ts +2 -0
- package/dist/types/components/Radio/index.d.ts +0 -1
- package/package.json +18 -18
- 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 +23 -7
- package/src/components/Checkbox/Checkbox.tsx +8 -2
- package/src/components/Checkbox/CheckboxGroup.test.tsx +1 -1
- package/src/components/Checkbox/types.ts +2 -0
- 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/hooks/useBreakpoint/useBreakpoint.test.tsx +5 -0
- 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
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 4.14.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- a03d10d: Add `name` attribute to `<Checkbox />` component
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 1f347dd: Dependency updates
|
|
12
|
+
- Updated dependencies [1f347dd]
|
|
13
|
+
- @simplybusiness/icons@4.12.1
|
|
14
|
+
|
|
15
|
+
## 4.13.0
|
|
16
|
+
|
|
17
|
+
### Minor Changes
|
|
18
|
+
|
|
19
|
+
- e8b6adf: Remove `<RadioButton>`; align component styles with design guidelines
|
|
20
|
+
- b260279: Add `<ProgressSteps>`; add `size` prop to `<Container>`
|
|
21
|
+
|
|
3
22
|
## 4.12.0
|
|
4
23
|
|
|
5
24
|
### Minor Changes
|
|
@@ -23,7 +23,7 @@ function _interop_require_default(obj) {
|
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
25
|
const Checkbox = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
|
|
26
|
-
const { id, label, isDisabled, isRequired, validationState, isInvalid, onChange, className, errorMessage, defaultSelected = false, isReadOnly, value, ["aria-describedby"]: ariaDescribedBy, ...rest } = props;
|
|
26
|
+
const { id, label, isDisabled, isRequired, validationState, isInvalid, onChange, className, errorMessage, defaultSelected = false, isReadOnly, name, value, ["aria-describedby"]: ariaDescribedBy, ...rest } = props;
|
|
27
27
|
const [selected, setSelected] = (0, _react.useState)(defaultSelected);
|
|
28
28
|
const fallbackRef = (0, _react.useRef)(null);
|
|
29
29
|
const refObj = ref || fallbackRef;
|
|
@@ -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)();
|
|
@@ -89,6 +89,7 @@ const Checkbox = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
|
|
|
89
89
|
defaultChecked: defaultSelected,
|
|
90
90
|
required: isRequired,
|
|
91
91
|
id: id || inputId,
|
|
92
|
+
name: name,
|
|
92
93
|
value: value,
|
|
93
94
|
...rest
|
|
94
95
|
}),
|
|
@@ -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 name,\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 name={name}\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","name","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,IAAI,EACJC,KAAK,EACL,CAAC,mBAAmB,EAAEC,eAAe,EACrC,GAAGC,MACJ,GAAGhB;IACJ,MAAM,CAACiB,UAAUC,YAAY,GAAGC,IAAAA,eAAQ,EAAUR;IAClD,MAAMS,cAAcC,IAAAA,aAAM,EAAmB;IAC7C,MAAMC,SAASrB,OAAOmB;IACtB,MAAMG,UAAUC,IAAAA,YAAK;IACrB,MAAMC,oBAAoBC,IAAAA,2BAAoB,EAAC;QAC7CpB;QACAC;IACF;IACA,MAAMoB,gBAAgBC,IAAAA,eAAU,EAC9B;QACE,iBAAiBxB;QACjB,iBAAiBa;QACjB,iBAAiB,OAAOZ,eAAe,aAAaA;QACpD,iBAAiB,OAAOA,eAAe,aAAa,CAACA;IACvD,GACAoB;IAEF,sEAAsE;IACtE,MAAMI,iBAAiBD,IAAAA,eAAU,EAC/B,UACA,mBACAD,eACAlB;IAEF,MAAMqB,eAAeF,IAAAA,eAAU,EAAC,wBAAwBD;IACxD,MAAMI,cAAcH,IAAAA,eAAU,EAAC,uBAAuBD;IACtD,MAAMK,iBAAiBR,IAAAA,YAAK;IAC5B,MAAMS,yBAAyBvB,eAAesB,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,IAAIhC,UAAU;YACZA,SAASgC;QACX;IACF;IAEA,MAAMI,gBAAgB,CAACJ;QACrB,IAAIA,MAAMK,IAAI,KAAK,SAAS;YAC1BP;QACF;IACF;IAEA,qBACE;;0BACE,sBAACnC;gBAAMM,WAAWoB;;kCAChB,qBAACiB;wBACCC,oBAAkBZ;wBAClBa,qBAAmBf;wBACnBgB,gBAAc1C;wBACd2C,mBAAiBb;wBACjBc,UAAUvC;wBACVwC,UAAUhD;wBACVH,KAAKqB;wBACLb,WAAWqB;wBACXuB,SAASd;wBACT/B,UAAUmC;wBACVW,WAAWV;wBACXW,MAAK;wBACLC,gBAAgB7C;wBAChB8C,UAAUpD;wBACVH,IAAIA,MAAMqB;wBACVV,MAAMA;wBACNC,OAAOA;wBACN,GAAGE,IAAI;;kCAEV,qBAAC0C,UAAI;wBACHC,MAAM1C,WAAW2C,iBAAU,GAAGC,aAAM;wBACpCC,MAAK;wBACLrD,WAAWsB;;kCAEb,qBAACgC;wBAAK7D,IAAImC;wBAAS5B,WAAU;kCAC1BN;;;;0BAGL,qBAAC6D,0BAAY;gBAAC9D,IAAI8B;gBAAgBtB,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"}
|
|
@@ -8,7 +8,7 @@ import { spaceDelimitedList } from "../../utils/spaceDelimitedList";
|
|
|
8
8
|
import { useValidationClasses } from "../../hooks";
|
|
9
9
|
import { Icon } from "../Icon";
|
|
10
10
|
export const Checkbox = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
11
|
-
const { id, label, isDisabled, isRequired, validationState, isInvalid, onChange, className, errorMessage, defaultSelected = false, isReadOnly, value, ["aria-describedby"]: ariaDescribedBy, ...rest } = props;
|
|
11
|
+
const { id, label, isDisabled, isRequired, validationState, isInvalid, onChange, className, errorMessage, defaultSelected = false, isReadOnly, name, value, ["aria-describedby"]: ariaDescribedBy, ...rest } = props;
|
|
12
12
|
const [selected, setSelected] = useState(defaultSelected);
|
|
13
13
|
const fallbackRef = useRef(null);
|
|
14
14
|
const refObj = ref || fallbackRef;
|
|
@@ -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();
|
|
@@ -74,6 +74,7 @@ export const Checkbox = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
|
74
74
|
defaultChecked: defaultSelected,
|
|
75
75
|
required: isRequired,
|
|
76
76
|
id: id || inputId,
|
|
77
|
+
name: name,
|
|
77
78
|
value: value,
|
|
78
79
|
...rest
|
|
79
80
|
}),
|
|
@@ -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 name,\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 name={name}\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","name","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,IAAI,EACJC,KAAK,EACL,CAAC,mBAAmB,EAAEC,eAAe,EACrC,GAAGC,MACJ,GAAGhB;IACJ,MAAM,CAACiB,UAAUC,YAAY,GAAG5B,SAAkBqB;IAClD,MAAMQ,cAAc9B,OAAyB;IAC7C,MAAM+B,SAASnB,OAAOkB;IACtB,MAAME,UAAU9B;IAChB,MAAM+B,oBAAoBzB,qBAAqB;QAC7CS;QACAC;IACF;IACA,MAAMgB,gBAAgB/B,WACpB;QACE,iBAAiBY;QACjB,iBAAiBa;QACjB,iBAAiB,OAAOZ,eAAe,aAAaA;QACpD,iBAAiB,OAAOA,eAAe,aAAa,CAACA;IACvD,GACAiB;IAEF,sEAAsE;IACtE,MAAME,iBAAiBhC,WACrB,UACA,mBACA+B,eACAd;IAEF,MAAMgB,eAAejC,WAAW,wBAAwB+B;IACxD,MAAMG,cAAclC,WAAW,uBAAuB+B;IACtD,MAAMI,iBAAiBpC;IACvB,MAAMqC,yBAAyBlB,eAAeiB,iBAAiBE;IAC/D,MAAMC,cAAclC,mBAAmB;QACrCgC;QACAb;KACD;IACD,MAAMgB,UAAUxC;IAEhB,MAAMyC,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,IAAI1B,UAAU;YACZA,SAAS0B;QACX;IACF;IAEA,MAAMI,gBAAgB,CAACJ;QACrB,IAAIA,MAAMK,IAAI,KAAK,SAAS;YAC1BP;QACF;IACF;IAEA,qBACE;;0BACE,MAAC7B;gBAAMM,WAAWe;;kCAChB,KAACgB;wBACCC,oBAAkBX;wBAClBY,qBAAmBd;wBACnBe,gBAAcpC;wBACdqC,mBAAiBb;wBACjBc,UAAUjC;wBACVkC,UAAU1C;wBACVH,KAAKmB;wBACLX,WAAWgB;wBACXsB,SAASd;wBACTzB,UAAU6B;wBACVW,WAAWV;wBACXW,MAAK;wBACLC,gBAAgBvC;wBAChBwC,UAAU9C;wBACVH,IAAIA,MAAMmB;wBACVR,MAAMA;wBACNC,OAAOA;wBACN,GAAGE,IAAI;;kCAEV,KAAClB;wBACCsD,MAAMnC,WAAWxB,aAAaC;wBAC9B2D,MAAK;wBACL5C,WAAWiB;;kCAEb,KAAC4B;wBAAKpD,IAAI6B;wBAAStB,WAAU;kCAC1BN;;;;0BAGL,KAACR;gBAAaO,IAAIyB;gBAAgBjB,cAAcA;;;;AAGtD,GAAG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/Checkbox/types.ts"],"sourcesContent":["import { ChangeEvent, ReactNode, Ref, RefAttributes } from \"react\";\nimport { DOMProps } from \"../../types/dom\";\nimport { Validation } from \"../../types\";\n\nexport type CheckboxElementType = HTMLInputElement;\nexport type CheckboxRef = Ref<CheckboxElementType>;\n\nexport interface CheckboxProps\n extends DOMProps,\n Validation,\n RefAttributes<CheckboxElementType> {\n className?: string;\n // The content to display as the label.\n label?: ReactNode;\n errorMessage?: string;\n /** The current value (controlled). */\n value?: string;\n // Whether the input is disabled.\n isDisabled?: boolean;\n onChange?: (event: ChangeEvent<CheckboxElementType>) => void;\n // The default value (uncontrolled).\n defaultSelected?: boolean;\n // Whether the input can be selected but not changed by the user.\n isReadOnly?: boolean;\n // Whether user input is required on the input before form submission.\n isRequired?: boolean;\n // Identifies the element that provides an error message for the object.\n \"aria-errormessage\"?: string;\n /**\n * Identifies the element (or elements) that describes the object.\n */\n \"aria-describedby\"?: string;\n /**\n * **Internal:** Do not use\n */\n groupDisabled?: boolean;\n /**\n * **Internal:** Do not use\n */\n selected?: string;\n /**\n * **Internal:** Do not use\n */\n setSelected?: React.Dispatch<React.SetStateAction<string>>;\n}\n\nexport type CheckboxGroupElementType = HTMLDivElement;\ninterface CheckboxGroupPropsInternal\n extends DOMProps,\n Validation,\n RefAttributes<CheckboxGroupElementType> {\n children: ReactNode;\n className?: string;\n orientation?: \"horizontal\" | \"vertical\";\n // Defines number of items to be displayed on a single row when used with orientation=\"horizontal\". Defaults to number of items in the group.\n itemsPerRow?: number;\n errorMessage?: string;\n onChange?: (values: string[]) => void;\n // Defines a string value that labels the current element.\n // \"aria-label\"?: string;\n // Identifies the element (or elements) that labels the current element.\n \"aria-labelledby\"?: string;\n // Identifies the element that provides an error message for the object.\n // \"aria-errormessage\"?: string;\n // Identifies the element (or elements) that describes the object.\n \"aria-describedby\"?: string;\n // Whether user input is required on the input before form submission.\n isRequired?: boolean;\n // Whether the input is disabled.\n isDisabled?: boolean;\n // Whether the input can be selected but not changed by the user.\n isReadOnly?: boolean;\n // The default value (uncontrolled).\n defaultValue?: string[];\n // The content to display as the label.\n label?: ReactNode;\n /**\n * The value of the radio button, used when submitting an HTML form.\n * See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/radio#Value).\n */\n value?: string;\n}\n\ninterface HorizontalCheckboxGroupProps extends CheckboxGroupPropsInternal {\n orientation?: \"horizontal\";\n itemsPerRow: number;\n}\n\ninterface VerticalCheckboxGroupProps extends CheckboxGroupPropsInternal {\n orientation?: \"vertical\";\n itemsPerRow?: never;\n}\n\nexport type CheckboxGroupProps =\n | HorizontalCheckboxGroupProps\n | VerticalCheckboxGroupProps;\n\nexport type CheckboxGroupRef = Ref<CheckboxGroupElementType>;\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/Checkbox/types.ts"],"sourcesContent":["import { ChangeEvent, ReactNode, Ref, RefAttributes } from \"react\";\nimport { DOMProps } from \"../../types/dom\";\nimport { Validation } from \"../../types\";\n\nexport type CheckboxElementType = HTMLInputElement;\nexport type CheckboxRef = Ref<CheckboxElementType>;\n\nexport interface CheckboxProps\n extends DOMProps,\n Validation,\n RefAttributes<CheckboxElementType> {\n className?: string;\n // The content to display as the label.\n label?: ReactNode;\n errorMessage?: string;\n /** The name of the input */\n name?: string;\n /** The current value (controlled). */\n value?: string;\n // Whether the input is disabled.\n isDisabled?: boolean;\n onChange?: (event: ChangeEvent<CheckboxElementType>) => void;\n // The default value (uncontrolled).\n defaultSelected?: boolean;\n // Whether the input can be selected but not changed by the user.\n isReadOnly?: boolean;\n // Whether user input is required on the input before form submission.\n isRequired?: boolean;\n // Identifies the element that provides an error message for the object.\n \"aria-errormessage\"?: string;\n /**\n * Identifies the element (or elements) that describes the object.\n */\n \"aria-describedby\"?: string;\n /**\n * **Internal:** Do not use\n */\n groupDisabled?: boolean;\n /**\n * **Internal:** Do not use\n */\n selected?: string;\n /**\n * **Internal:** Do not use\n */\n setSelected?: React.Dispatch<React.SetStateAction<string>>;\n}\n\nexport type CheckboxGroupElementType = HTMLDivElement;\ninterface CheckboxGroupPropsInternal\n extends DOMProps,\n Validation,\n RefAttributes<CheckboxGroupElementType> {\n children: ReactNode;\n className?: string;\n orientation?: \"horizontal\" | \"vertical\";\n // Defines number of items to be displayed on a single row when used with orientation=\"horizontal\". Defaults to number of items in the group.\n itemsPerRow?: number;\n errorMessage?: string;\n onChange?: (values: string[]) => void;\n // Defines a string value that labels the current element.\n // \"aria-label\"?: string;\n // Identifies the element (or elements) that labels the current element.\n \"aria-labelledby\"?: string;\n // Identifies the element that provides an error message for the object.\n // \"aria-errormessage\"?: string;\n // Identifies the element (or elements) that describes the object.\n \"aria-describedby\"?: string;\n // Whether user input is required on the input before form submission.\n isRequired?: boolean;\n // Whether the input is disabled.\n isDisabled?: boolean;\n // Whether the input can be selected but not changed by the user.\n isReadOnly?: boolean;\n // The default value (uncontrolled).\n defaultValue?: string[];\n // The content to display as the label.\n label?: ReactNode;\n /**\n * The value of the radio button, used when submitting an HTML form.\n * See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/radio#Value).\n */\n value?: string;\n}\n\ninterface HorizontalCheckboxGroupProps extends CheckboxGroupPropsInternal {\n orientation?: \"horizontal\";\n itemsPerRow: number;\n}\n\ninterface VerticalCheckboxGroupProps extends CheckboxGroupPropsInternal {\n orientation?: \"vertical\";\n itemsPerRow?: never;\n}\n\nexport type CheckboxGroupProps =\n | HorizontalCheckboxGroupProps\n | VerticalCheckboxGroupProps;\n\nexport type CheckboxGroupRef = Ref<CheckboxGroupElementType>;\n"],"names":[],"mappings":"AAmGA,WAA6D"}
|
|
@@ -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"}
|
|
@@ -7,6 +7,8 @@ export interface CheckboxProps extends DOMProps, Validation, RefAttributes<Check
|
|
|
7
7
|
className?: string;
|
|
8
8
|
label?: ReactNode;
|
|
9
9
|
errorMessage?: string;
|
|
10
|
+
/** The name of the input */
|
|
11
|
+
name?: string;
|
|
10
12
|
/** The current value (controlled). */
|
|
11
13
|
value?: string;
|
|
12
14
|
isDisabled?: boolean;
|
|
@@ -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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simplybusiness/mobius",
|
|
3
3
|
"license": "UNLICENSED",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.14.0",
|
|
5
5
|
"description": "Core library of Mobius react components",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -41,24 +41,24 @@
|
|
|
41
41
|
},
|
|
42
42
|
"sideEffects": false,
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@react-types/button": "^3.9.
|
|
45
|
-
"@react-types/dialog": "^3.5.
|
|
46
|
-
"@react-types/progress": "^3.5.
|
|
47
|
-
"@swc/cli": "^0.
|
|
48
|
-
"@swc/core": "^1.
|
|
44
|
+
"@react-types/button": "^3.9.6",
|
|
45
|
+
"@react-types/dialog": "^3.5.12",
|
|
46
|
+
"@react-types/progress": "^3.5.6",
|
|
47
|
+
"@swc/cli": "^0.4.0",
|
|
48
|
+
"@swc/core": "^1.7.1",
|
|
49
49
|
"@swc/jest": "^0.2.36",
|
|
50
|
-
"@testing-library/dom": "^10.
|
|
51
|
-
"@testing-library/jest-dom": "6.4.
|
|
50
|
+
"@testing-library/dom": "^10.4.0",
|
|
51
|
+
"@testing-library/jest-dom": "6.4.8",
|
|
52
52
|
"@testing-library/react": "^16.0.0",
|
|
53
53
|
"@testing-library/user-event": "^14.5.2",
|
|
54
54
|
"@total-typescript/shoehorn": "^0.1.2",
|
|
55
55
|
"@types/jest": "^29.5.12",
|
|
56
56
|
"@types/lodash.debounce": "^4.0.9",
|
|
57
|
-
"@types/node": "^20.14.
|
|
57
|
+
"@types/node": "^20.14.12",
|
|
58
58
|
"@types/react": "^18.3.3",
|
|
59
59
|
"@types/react-dom": "^18.3.0",
|
|
60
|
-
"@typescript-eslint/eslint-plugin": "^7.
|
|
61
|
-
"@typescript-eslint/parser": "^7.
|
|
60
|
+
"@typescript-eslint/eslint-plugin": "^7.17.0",
|
|
61
|
+
"@typescript-eslint/parser": "^7.17.0",
|
|
62
62
|
"csstype": "^3.1.3",
|
|
63
63
|
"eslint": "^8.57.0",
|
|
64
64
|
"eslint-config-airbnb": "^19.0.4",
|
|
@@ -67,27 +67,27 @@
|
|
|
67
67
|
"eslint-plugin-import": "^2.29.1",
|
|
68
68
|
"eslint-plugin-jsx-a11y": "^6.9.0",
|
|
69
69
|
"eslint-plugin-no-only-tests": "^3.1.0",
|
|
70
|
-
"eslint-plugin-prettier": "^5.1
|
|
71
|
-
"eslint-plugin-react": "^7.
|
|
70
|
+
"eslint-plugin-prettier": "^5.2.1",
|
|
71
|
+
"eslint-plugin-react": "^7.35.0",
|
|
72
72
|
"eslint-plugin-react-hooks": "^4.6.2",
|
|
73
73
|
"eslint-plugin-storybook": "^0.8.0",
|
|
74
74
|
"identity-obj-proxy": "^3.0.0",
|
|
75
75
|
"jest": "^29.7.0",
|
|
76
76
|
"jest-environment-jsdom": "^29.7.0",
|
|
77
|
-
"prettier": "^3.3.
|
|
77
|
+
"prettier": "^3.3.3",
|
|
78
78
|
"react": "^18.3.1",
|
|
79
79
|
"react-dom": "^18.3.1",
|
|
80
|
-
"ts-jest": "^29.
|
|
80
|
+
"ts-jest": "^29.2.3",
|
|
81
81
|
"tslib": "^2.6.3",
|
|
82
|
-
"typescript": "^5.5.
|
|
82
|
+
"typescript": "^5.5.4"
|
|
83
83
|
},
|
|
84
84
|
"peerDependencies": {
|
|
85
85
|
"react": "^18.2.0",
|
|
86
86
|
"react-dom": "^18.2.0"
|
|
87
87
|
},
|
|
88
88
|
"dependencies": {
|
|
89
|
-
"@floating-ui/react": "^0.26.
|
|
90
|
-
"@simplybusiness/icons": "^4.12.
|
|
89
|
+
"@floating-ui/react": "^0.26.20",
|
|
90
|
+
"@simplybusiness/icons": "^4.12.1",
|
|
91
91
|
"classnames": "^2.5.1",
|
|
92
92
|
"dialog-polyfill": "^0.5.6",
|
|
93
93
|
"lodash.debounce": "^4.0.8",
|
|
@@ -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
|
|
|
@@ -13,6 +13,20 @@ describe("Checkbox", () => {
|
|
|
13
13
|
expect(component).toBeTruthy();
|
|
14
14
|
});
|
|
15
15
|
|
|
16
|
+
it("should render with a name", async () => {
|
|
17
|
+
const optionText = "Agree";
|
|
18
|
+
const name = "name";
|
|
19
|
+
|
|
20
|
+
render(
|
|
21
|
+
<form name="form">
|
|
22
|
+
<Checkbox label={optionText} name={name} value="value" />
|
|
23
|
+
</form>,
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
const checkbox = screen.getByRole("checkbox");
|
|
27
|
+
expect(checkbox).toHaveAttribute("name", name);
|
|
28
|
+
});
|
|
29
|
+
|
|
16
30
|
it("should call onChange when clicked", async () => {
|
|
17
31
|
const callback = jest.fn();
|
|
18
32
|
const optionText = "Agree";
|
|
@@ -193,17 +207,19 @@ describe("Checkbox", () => {
|
|
|
193
207
|
});
|
|
194
208
|
|
|
195
209
|
it("includes custom class name", () => {
|
|
196
|
-
const
|
|
210
|
+
const labelText = "Agree";
|
|
197
211
|
const customClass = "my-class";
|
|
198
212
|
|
|
199
|
-
|
|
200
|
-
<Checkbox label={
|
|
213
|
+
render(
|
|
214
|
+
<Checkbox label={labelText} className={customClass} value="value" />,
|
|
201
215
|
);
|
|
202
216
|
|
|
203
|
-
const
|
|
217
|
+
const input = screen.getByRole("checkbox");
|
|
218
|
+
const label = input.parentElement;
|
|
204
219
|
|
|
205
|
-
expect(
|
|
206
|
-
expect(
|
|
220
|
+
expect(input).not.toHaveClass(customClass);
|
|
221
|
+
expect(input).toHaveClass(CHECKBOX_CLASS_NAME);
|
|
222
|
+
expect(label).toHaveClass(customClass);
|
|
207
223
|
});
|
|
208
224
|
|
|
209
225
|
it("only sets id on the input element", () => {
|
|
@@ -34,6 +34,7 @@ export const Checkbox: ForwardedRefComponent<
|
|
|
34
34
|
errorMessage,
|
|
35
35
|
defaultSelected = false,
|
|
36
36
|
isReadOnly,
|
|
37
|
+
name,
|
|
37
38
|
value,
|
|
38
39
|
["aria-describedby"]: ariaDescribedBy,
|
|
39
40
|
...rest
|
|
@@ -54,10 +55,14 @@ export const Checkbox: ForwardedRefComponent<
|
|
|
54
55
|
"--is-optional": typeof isRequired === "boolean" && !isRequired,
|
|
55
56
|
},
|
|
56
57
|
validationClasses,
|
|
57
|
-
className,
|
|
58
58
|
);
|
|
59
59
|
// Append an additional wrapper class name to differenitate from input
|
|
60
|
-
const wrapperClasses = classNames(
|
|
60
|
+
const wrapperClasses = classNames(
|
|
61
|
+
"mobius",
|
|
62
|
+
"mobius/Checkbox",
|
|
63
|
+
sharedClasses,
|
|
64
|
+
className,
|
|
65
|
+
);
|
|
61
66
|
const inputClasses = classNames("mobius/CheckboxInput", sharedClasses);
|
|
62
67
|
const iconClasses = classNames("mobius/CheckboxIcon", sharedClasses);
|
|
63
68
|
const errorMessageId = useId();
|
|
@@ -111,6 +116,7 @@ export const Checkbox: ForwardedRefComponent<
|
|
|
111
116
|
defaultChecked={defaultSelected}
|
|
112
117
|
required={isRequired}
|
|
113
118
|
id={id || inputId}
|
|
119
|
+
name={name}
|
|
114
120
|
value={value}
|
|
115
121
|
{...rest}
|
|
116
122
|
/>
|
|
@@ -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
|
|
|
@@ -13,6 +13,8 @@ export interface CheckboxProps
|
|
|
13
13
|
// The content to display as the label.
|
|
14
14
|
label?: ReactNode;
|
|
15
15
|
errorMessage?: string;
|
|
16
|
+
/** The name of the input */
|
|
17
|
+
name?: string;
|
|
16
18
|
/** The current value (controlled). */
|
|
17
19
|
value?: string;
|
|
18
20
|
// Whether the input is disabled.
|
|
@@ -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
|
|
|
@@ -27,6 +27,11 @@ describe("useBreakpoint", () => {
|
|
|
27
27
|
window.dispatchEvent(new Event("resize"));
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
+
afterEach(() => {
|
|
31
|
+
// Reset window width
|
|
32
|
+
setWindowWidth(undefined as any);
|
|
33
|
+
});
|
|
34
|
+
|
|
30
35
|
describe("given no breakpoints are provided through a Context", () => {
|
|
31
36
|
it("returns default breakpoint", () => {
|
|
32
37
|
render(<TestComponent />);
|
|
@@ -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
|
-
});
|