@sb1/ffe-form-react 101.1.1 → 102.0.1

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/es/Checkbox.js CHANGED
@@ -1,8 +1,20 @@
1
- import React, { useId } from 'react';
1
+ import React, { useEffect, useId, useMemo, useRef } from 'react';
2
2
  import classNames from 'classnames';
3
- export const Checkbox = React.forwardRef(({ children, hiddenLabel, inline = true, noMargins, id, checked, onChange, disabled, ...rest }, ref) => {
3
+ import { mergeRefs } from './mergeRefs';
4
+ export const Checkbox = React.forwardRef(({ children, hiddenLabel, inline = true, noMargins, id, checked, indeterminate, onChange, disabled, ...rest }, ref) => {
4
5
  const generatedId = useId();
5
6
  const inputId = id !== null && id !== void 0 ? id : generatedId;
7
+ const innerRef = useRef(null);
8
+ const mergedRef = useMemo(() => mergeRefs([innerRef, ref]), [ref]);
9
+ /* `indeterminate` finnes bare som DOM-egenskap, ikke som attributt, så
10
+ * den må settes imperativt. Ingen dep-array: nettleseren nullstiller
11
+ * egenskapen når brukeren klikker på checkboxen, så den må settes på
12
+ * nytt hver render for ikke å bli stille utdatert. */
13
+ useEffect(() => {
14
+ if (innerRef.current) {
15
+ innerRef.current.indeterminate = !!indeterminate;
16
+ }
17
+ });
6
18
  const labelProps = {
7
19
  className: classNames({
8
20
  'ffe-checkbox': true,
@@ -13,7 +25,7 @@ export const Checkbox = React.forwardRef(({ children, hiddenLabel, inline = true
13
25
  htmlFor: inputId,
14
26
  };
15
27
  return (React.createElement(React.Fragment, null,
16
- React.createElement("input", { ref: ref, className: "ffe-hidden-checkbox", id: inputId, type: "checkbox", checked: checked, disabled: disabled, onChange: !disabled ? onChange : undefined, ...rest }),
28
+ React.createElement("input", { ref: mergedRef, className: "ffe-hidden-checkbox", id: inputId, type: "checkbox", checked: checked, disabled: disabled, onChange: !disabled ? onChange : undefined, ...rest }),
17
29
  typeof children === 'function' ? (children(labelProps)) : (
18
30
  // eslint-disable-next-line jsx-a11y/label-has-for
19
31
  React.createElement("label", { ...labelProps },
@@ -0,0 +1,13 @@
1
+ export function mergeRefs(refs) {
2
+ return value => {
3
+ refs.forEach(ref => {
4
+ if (typeof ref === 'function') {
5
+ ref(value);
6
+ }
7
+ else if (ref != null) {
8
+ // eslint-disable-next-line no-param-reassign
9
+ ref.current = value;
10
+ }
11
+ });
12
+ };
13
+ }
@@ -1 +1 @@
1
- {"root":["../src/BaseRadioButton.tsx","../src/Checkbox.tsx","../src/Input.tsx","../src/InputGroup.tsx","../src/InputTextLike.tsx","../src/Label.tsx","../src/PhoneNumber.tsx","../src/RadioBlock.tsx","../src/RadioButton.tsx","../src/RadioButtonInputGroup.tsx","../src/RadioSwitch.tsx","../src/TextArea.tsx","../src/TextField.tsx","../src/ToggleSwitch.tsx","../src/Tooltip.tsx","../src/index.ts","../src/types.ts","../src/documentation/RadioButton-example.tsx","../src/documentation/RadioSwitch-example.tsx","../src/i18n/en.ts","../src/i18n/i18n.ts","../src/i18n/nb.ts","../src/i18n/nn.ts","../src/message/BaseFieldMessage.tsx","../src/message/ErrorFieldMessage.tsx","../src/message/InfoFieldMessage.tsx","../src/message/SuccessFieldMessage.tsx","../src/message/index.tsx"],"version":"5.9.3"}
1
+ {"root":["../src/BaseRadioButton.tsx","../src/Checkbox.tsx","../src/Input.tsx","../src/InputGroup.tsx","../src/InputTextLike.tsx","../src/Label.tsx","../src/PhoneNumber.tsx","../src/RadioBlock.tsx","../src/RadioButton.tsx","../src/RadioButtonInputGroup.tsx","../src/RadioSwitch.tsx","../src/TextArea.tsx","../src/TextField.tsx","../src/ToggleSwitch.tsx","../src/Tooltip.tsx","../src/index.ts","../src/mergeRefs.ts","../src/types.ts","../src/documentation/RadioButton-example.tsx","../src/documentation/RadioSwitch-example.tsx","../src/i18n/en.ts","../src/i18n/i18n.ts","../src/i18n/nb.ts","../src/i18n/nn.ts","../src/message/BaseFieldMessage.tsx","../src/message/ErrorFieldMessage.tsx","../src/message/InfoFieldMessage.tsx","../src/message/SuccessFieldMessage.tsx","../src/message/index.tsx"],"version":"5.9.3"}
package/lib/Checkbox.js CHANGED
@@ -39,9 +39,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.Checkbox = void 0;
40
40
  const react_1 = __importStar(require("react"));
41
41
  const classnames_1 = __importDefault(require("classnames"));
42
- exports.Checkbox = react_1.default.forwardRef(({ children, hiddenLabel, inline = true, noMargins, id, checked, onChange, disabled, ...rest }, ref) => {
42
+ const mergeRefs_1 = require("./mergeRefs");
43
+ exports.Checkbox = react_1.default.forwardRef(({ children, hiddenLabel, inline = true, noMargins, id, checked, indeterminate, onChange, disabled, ...rest }, ref) => {
43
44
  const generatedId = (0, react_1.useId)();
44
45
  const inputId = id !== null && id !== void 0 ? id : generatedId;
46
+ const innerRef = (0, react_1.useRef)(null);
47
+ const mergedRef = (0, react_1.useMemo)(() => (0, mergeRefs_1.mergeRefs)([innerRef, ref]), [ref]);
48
+ /* `indeterminate` finnes bare som DOM-egenskap, ikke som attributt, så
49
+ * den må settes imperativt. Ingen dep-array: nettleseren nullstiller
50
+ * egenskapen når brukeren klikker på checkboxen, så den må settes på
51
+ * nytt hver render for ikke å bli stille utdatert. */
52
+ (0, react_1.useEffect)(() => {
53
+ if (innerRef.current) {
54
+ innerRef.current.indeterminate = !!indeterminate;
55
+ }
56
+ });
45
57
  const labelProps = {
46
58
  className: (0, classnames_1.default)({
47
59
  'ffe-checkbox': true,
@@ -52,7 +64,7 @@ exports.Checkbox = react_1.default.forwardRef(({ children, hiddenLabel, inline =
52
64
  htmlFor: inputId,
53
65
  };
54
66
  return (react_1.default.createElement(react_1.default.Fragment, null,
55
- react_1.default.createElement("input", { ref: ref, className: "ffe-hidden-checkbox", id: inputId, type: "checkbox", checked: checked, disabled: disabled, onChange: !disabled ? onChange : undefined, ...rest }),
67
+ react_1.default.createElement("input", { ref: mergedRef, className: "ffe-hidden-checkbox", id: inputId, type: "checkbox", checked: checked, disabled: disabled, onChange: !disabled ? onChange : undefined, ...rest }),
56
68
  typeof children === 'function' ? (children(labelProps)) : (
57
69
  // eslint-disable-next-line jsx-a11y/label-has-for
58
70
  react_1.default.createElement("label", { ...labelProps },
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mergeRefs = mergeRefs;
4
+ function mergeRefs(refs) {
5
+ return value => {
6
+ refs.forEach(ref => {
7
+ if (typeof ref === 'function') {
8
+ ref(value);
9
+ }
10
+ else if (ref != null) {
11
+ // eslint-disable-next-line no-param-reassign
12
+ ref.current = value;
13
+ }
14
+ });
15
+ };
16
+ }
@@ -1 +1 @@
1
- {"root":["../src/BaseRadioButton.tsx","../src/Checkbox.tsx","../src/Input.tsx","../src/InputGroup.tsx","../src/InputTextLike.tsx","../src/Label.tsx","../src/PhoneNumber.tsx","../src/RadioBlock.tsx","../src/RadioButton.tsx","../src/RadioButtonInputGroup.tsx","../src/RadioSwitch.tsx","../src/TextArea.tsx","../src/TextField.tsx","../src/ToggleSwitch.tsx","../src/Tooltip.tsx","../src/index.ts","../src/types.ts","../src/documentation/RadioButton-example.tsx","../src/documentation/RadioSwitch-example.tsx","../src/i18n/en.ts","../src/i18n/i18n.ts","../src/i18n/nb.ts","../src/i18n/nn.ts","../src/message/BaseFieldMessage.tsx","../src/message/ErrorFieldMessage.tsx","../src/message/InfoFieldMessage.tsx","../src/message/SuccessFieldMessage.tsx","../src/message/index.tsx"],"version":"5.9.3"}
1
+ {"root":["../src/BaseRadioButton.tsx","../src/Checkbox.tsx","../src/Input.tsx","../src/InputGroup.tsx","../src/InputTextLike.tsx","../src/Label.tsx","../src/PhoneNumber.tsx","../src/RadioBlock.tsx","../src/RadioButton.tsx","../src/RadioButtonInputGroup.tsx","../src/RadioSwitch.tsx","../src/TextArea.tsx","../src/TextField.tsx","../src/ToggleSwitch.tsx","../src/Tooltip.tsx","../src/index.ts","../src/mergeRefs.ts","../src/types.ts","../src/documentation/RadioButton-example.tsx","../src/documentation/RadioSwitch-example.tsx","../src/i18n/en.ts","../src/i18n/i18n.ts","../src/i18n/nb.ts","../src/i18n/nn.ts","../src/message/BaseFieldMessage.tsx","../src/message/ErrorFieldMessage.tsx","../src/message/InfoFieldMessage.tsx","../src/message/SuccessFieldMessage.tsx","../src/message/index.tsx"],"version":"5.9.3"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sb1/ffe-form-react",
3
- "version": "101.1.1",
3
+ "version": "102.0.1",
4
4
  "description": "React component for form elements in ffe",
5
5
  "license": "MIT",
6
6
  "author": "SpareBank 1",
@@ -25,13 +25,13 @@
25
25
  "test:watch": "ffe-buildtool jest --watch"
26
26
  },
27
27
  "dependencies": {
28
- "@sb1/ffe-collapse-react": "^101.1.1",
29
- "@sb1/ffe-form": "^101.1.1",
30
- "@sb1/ffe-icons-react": "^101.1.1",
28
+ "@sb1/ffe-collapse-react": "^102.0.1",
29
+ "@sb1/ffe-form": "^102.0.1",
30
+ "@sb1/ffe-icons-react": "^102.0.1",
31
31
  "classnames": "^2.5.1"
32
32
  },
33
33
  "devDependencies": {
34
- "@sb1/ffe-buildtool": "^101.1.1",
34
+ "@sb1/ffe-buildtool": "^102.0.1",
35
35
  "eslint": "^10.2.0",
36
36
  "react": "^18.2.0",
37
37
  "react-dom": "^18.2.0"
@@ -42,5 +42,5 @@
42
42
  "publishConfig": {
43
43
  "access": "public"
44
44
  },
45
- "gitHead": "d47d8ed9af0fc027d713577b40e0429d6b5b1330"
45
+ "gitHead": "295ff0e2baed87fed6ed09b2c78139c19faeda55"
46
46
  }
@@ -6,6 +6,11 @@ export interface CheckboxProps extends Omit<React.ComponentPropsWithoutRef<'inpu
6
6
  hiddenLabel?: boolean;
7
7
  /** Display inline */
8
8
  inline?: boolean;
9
+ /** Shows the checkbox in a mixed state, for when it represents a set of
10
+ * checkboxes where only some are checked. Sets the `indeterminate` DOM
11
+ * property on the input, which is what makes screen readers announce the
12
+ * mixed state. Does not change `checked`. */
13
+ indeterminate?: boolean;
9
14
  children: React.ReactNode | ((labelProps: {
10
15
  className: string;
11
16
  htmlFor: string;
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export declare function mergeRefs<T = any>(refs: Array<React.MutableRefObject<T> | React.LegacyRef<T> | undefined | null>): React.RefCallback<T>;
@@ -1 +1 @@
1
- {"root":["../src/BaseRadioButton.tsx","../src/Checkbox.tsx","../src/Input.tsx","../src/InputGroup.tsx","../src/InputTextLike.tsx","../src/Label.tsx","../src/PhoneNumber.tsx","../src/RadioBlock.tsx","../src/RadioButton.tsx","../src/RadioButtonInputGroup.tsx","../src/RadioSwitch.tsx","../src/TextArea.tsx","../src/TextField.tsx","../src/ToggleSwitch.tsx","../src/Tooltip.tsx","../src/index.ts","../src/types.ts","../src/documentation/RadioButton-example.tsx","../src/documentation/RadioSwitch-example.tsx","../src/i18n/en.ts","../src/i18n/i18n.ts","../src/i18n/nb.ts","../src/i18n/nn.ts","../src/message/BaseFieldMessage.tsx","../src/message/ErrorFieldMessage.tsx","../src/message/InfoFieldMessage.tsx","../src/message/SuccessFieldMessage.tsx","../src/message/index.tsx"],"version":"5.9.3"}
1
+ {"root":["../src/BaseRadioButton.tsx","../src/Checkbox.tsx","../src/Input.tsx","../src/InputGroup.tsx","../src/InputTextLike.tsx","../src/Label.tsx","../src/PhoneNumber.tsx","../src/RadioBlock.tsx","../src/RadioButton.tsx","../src/RadioButtonInputGroup.tsx","../src/RadioSwitch.tsx","../src/TextArea.tsx","../src/TextField.tsx","../src/ToggleSwitch.tsx","../src/Tooltip.tsx","../src/index.ts","../src/mergeRefs.ts","../src/types.ts","../src/documentation/RadioButton-example.tsx","../src/documentation/RadioSwitch-example.tsx","../src/i18n/en.ts","../src/i18n/i18n.ts","../src/i18n/nb.ts","../src/i18n/nn.ts","../src/message/BaseFieldMessage.tsx","../src/message/ErrorFieldMessage.tsx","../src/message/InfoFieldMessage.tsx","../src/message/SuccessFieldMessage.tsx","../src/message/index.tsx"],"version":"5.9.3"}