@simplybusiness/mobius 4.13.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 +12 -0
- package/dist/cjs/components/Checkbox/Checkbox.js +2 -1
- package/dist/cjs/components/Checkbox/Checkbox.js.map +1 -1
- package/dist/esm/components/Checkbox/Checkbox.js +2 -1
- package/dist/esm/components/Checkbox/Checkbox.js.map +1 -1
- package/dist/esm/components/Checkbox/types.js.map +1 -1
- package/dist/types/components/Checkbox/types.d.ts +2 -0
- package/package.json +18 -18
- package/src/components/Checkbox/Checkbox.test.tsx +14 -0
- package/src/components/Checkbox/Checkbox.tsx +2 -0
- package/src/components/Checkbox/types.ts +2 -0
- package/src/hooks/useBreakpoint/useBreakpoint.test.tsx +5 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
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
|
+
|
|
3
15
|
## 4.13.0
|
|
4
16
|
|
|
5
17
|
### 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;
|
|
@@ -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 );\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,
|
|
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;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CAEb,qBAACgC;wBAAK7D,IAAImC;wBAAS5B,WAAU;kCAC1BN;;;;0BAGL,qBAAC6D,0BAAY;gBAAC9D,IAAI8B;gBAAgBtB,cAAcA;;;;AAGtD"}
|
|
@@ -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;
|
|
@@ -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 );\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,
|
|
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","defaultChec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c;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"}
|
|
@@ -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;
|
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",
|
|
@@ -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";
|
|
@@ -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
|
|
@@ -115,6 +116,7 @@ export const Checkbox: ForwardedRefComponent<
|
|
|
115
116
|
defaultChecked={defaultSelected}
|
|
116
117
|
required={isRequired}
|
|
117
118
|
id={id || inputId}
|
|
119
|
+
name={name}
|
|
118
120
|
value={value}
|
|
119
121
|
{...rest}
|
|
120
122
|
/>
|
|
@@ -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.
|
|
@@ -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 />);
|