@transferwise/components 46.60.0 → 46.61.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/build/checkboxButton/CheckboxButton.js +15 -4
- package/build/checkboxButton/CheckboxButton.js.map +1 -1
- package/build/checkboxButton/CheckboxButton.mjs +16 -5
- package/build/checkboxButton/CheckboxButton.mjs.map +1 -1
- package/build/main.css +20 -1
- package/build/styles/checkboxButton/CheckboxButton.css +20 -1
- package/build/styles/main.css +20 -1
- package/build/types/checkboxButton/CheckboxButton.d.ts +6 -2
- package/build/types/checkboxButton/CheckboxButton.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/checkbox/__snapshots__/Checkbox.spec.tsx.snap +3 -0
- package/src/checkboxButton/CheckboxButton.css +20 -1
- package/src/checkboxButton/CheckboxButton.less +22 -1
- package/src/checkboxButton/CheckboxButton.story.tsx +24 -1
- package/src/checkboxButton/CheckboxButton.tsx +18 -4
- package/src/main.css +20 -1
|
@@ -7,27 +7,38 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
7
7
|
|
|
8
8
|
const CheckboxButton = /*#__PURE__*/React.forwardRef(function CheckboxButton({
|
|
9
9
|
checked,
|
|
10
|
+
indeterminate = false,
|
|
10
11
|
className,
|
|
11
12
|
disabled,
|
|
12
13
|
onChange,
|
|
13
14
|
...rest
|
|
14
15
|
}, reference) {
|
|
15
16
|
const inputAttributes = contexts.useInputAttributes();
|
|
17
|
+
const internalRef = React.useRef(null);
|
|
18
|
+
React.useImperativeHandle(reference, () => internalRef.current ?? {});
|
|
19
|
+
React.useEffect(() => {
|
|
20
|
+
if (internalRef.current) {
|
|
21
|
+
// eslint-disable-next-line functional/immutable-data, @typescript-eslint/no-unsafe-assignment
|
|
22
|
+
internalRef.current.indeterminate = indeterminate;
|
|
23
|
+
}
|
|
24
|
+
}, [indeterminate, reference]);
|
|
16
25
|
return /*#__PURE__*/jsxRuntime.jsxs("span", {
|
|
17
26
|
className: clsx.clsx('np-checkbox-button', className, disabled && 'disabled'),
|
|
18
27
|
children: [/*#__PURE__*/jsxRuntime.jsx("input", {
|
|
19
28
|
...inputAttributes,
|
|
20
29
|
...rest,
|
|
21
|
-
ref: reference,
|
|
30
|
+
ref: reference ?? internalRef,
|
|
22
31
|
type: "checkbox",
|
|
23
32
|
disabled: disabled,
|
|
24
33
|
checked: checked,
|
|
25
34
|
onChange: onChange
|
|
26
|
-
}), /*#__PURE__*/jsxRuntime.
|
|
35
|
+
}), /*#__PURE__*/jsxRuntime.jsxs("span", {
|
|
27
36
|
className: "tw-checkbox-button",
|
|
28
|
-
children: /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
37
|
+
children: [/*#__PURE__*/jsxRuntime.jsx("span", {
|
|
29
38
|
className: "tw-checkbox-check"
|
|
30
|
-
})
|
|
39
|
+
}), /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
40
|
+
className: "np-tw-checkbox-indeterminate"
|
|
41
|
+
})]
|
|
31
42
|
})]
|
|
32
43
|
});
|
|
33
44
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CheckboxButton.js","sources":["../../src/checkboxButton/CheckboxButton.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { InputHTMLAttributes, forwardRef } from 'react';\n\nimport { useInputAttributes } from '../inputs/contexts';\n\nexport type CheckboxButtonProps = InputHTMLAttributes<HTMLInputElement
|
|
1
|
+
{"version":3,"file":"CheckboxButton.js","sources":["../../src/checkboxButton/CheckboxButton.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { InputHTMLAttributes, forwardRef, useEffect, useImperativeHandle, useRef } from 'react';\n\nimport { useInputAttributes } from '../inputs/contexts';\n\nexport type CheckboxButtonProps = InputHTMLAttributes<HTMLInputElement> & {\n indeterminate?: boolean;\n};\n\nconst CheckboxButton = forwardRef<HTMLInputElement, CheckboxButtonProps>(function CheckboxButton(\n { checked, indeterminate = false, className, disabled, onChange, ...rest },\n reference,\n) {\n const inputAttributes = useInputAttributes();\n\n const internalRef = useRef<HTMLInputElement>(null);\n\n useImperativeHandle(reference, () => internalRef.current ?? ({} as HTMLInputElement));\n\n useEffect(() => {\n if (internalRef.current) {\n // eslint-disable-next-line functional/immutable-data, @typescript-eslint/no-unsafe-assignment\n internalRef.current.indeterminate = indeterminate;\n }\n }, [indeterminate, reference]);\n\n return (\n <span className={clsx('np-checkbox-button', className, disabled && 'disabled')}>\n <input\n {...inputAttributes}\n {...rest}\n ref={reference ?? internalRef}\n type=\"checkbox\"\n disabled={disabled}\n checked={checked}\n onChange={onChange}\n />\n <span className=\"tw-checkbox-button\">\n <span className=\"tw-checkbox-check\" />\n <span className=\"np-tw-checkbox-indeterminate\" />\n </span>\n </span>\n );\n});\n\nexport default CheckboxButton;\n"],"names":["CheckboxButton","forwardRef","checked","indeterminate","className","disabled","onChange","rest","reference","inputAttributes","useInputAttributes","internalRef","useRef","useImperativeHandle","current","useEffect","_jsxs","clsx","children","_jsx","ref","type"],"mappings":";;;;;;;AASA,MAAMA,cAAc,gBAAGC,gBAAU,CAAwC,SAASD,cAAcA,CAC9F;EAAEE,OAAO;AAAEC,EAAAA,aAAa,GAAG,KAAK;EAAEC,SAAS;EAAEC,QAAQ;EAAEC,QAAQ;EAAE,GAAGC,IAAAA;AAAM,CAAA,EAC1EC,SAAS,EAAA;AAET,EAAA,MAAMC,eAAe,GAAGC,2BAAkB,EAAE,CAAA;AAE5C,EAAA,MAAMC,WAAW,GAAGC,YAAM,CAAmB,IAAI,CAAC,CAAA;EAElDC,yBAAmB,CAACL,SAAS,EAAE,MAAMG,WAAW,CAACG,OAAO,IAAK,EAAuB,CAAC,CAAA;AAErFC,EAAAA,eAAS,CAAC,MAAK;IACb,IAAIJ,WAAW,CAACG,OAAO,EAAE;AACvB;AACAH,MAAAA,WAAW,CAACG,OAAO,CAACX,aAAa,GAAGA,aAAa,CAAA;AACnD,KAAA;AACF,GAAC,EAAE,CAACA,aAAa,EAAEK,SAAS,CAAC,CAAC,CAAA;AAE9B,EAAA,oBACEQ,eAAA,CAAA,MAAA,EAAA;IAAMZ,SAAS,EAAEa,SAAI,CAAC,oBAAoB,EAAEb,SAAS,EAAEC,QAAQ,IAAI,UAAU,CAAE;AAAAa,IAAAA,QAAA,gBAC7EC,cAAA,CAAA,OAAA,EAAA;AAAA,MAAA,GACMV,eAAe;AAAA,MAAA,GACfF,IAAI;MACRa,GAAG,EAAEZ,SAAS,IAAIG,WAAY;AAC9BU,MAAAA,IAAI,EAAC,UAAU;AACfhB,MAAAA,QAAQ,EAAEA,QAAS;AACnBH,MAAAA,OAAO,EAAEA,OAAQ;AACjBI,MAAAA,QAAQ,EAAEA,QAAAA;KAEZ,CAAA,eAAAU,eAAA,CAAA,MAAA,EAAA;AAAMZ,MAAAA,SAAS,EAAC,oBAAoB;AAAAc,MAAAA,QAAA,gBAClCC,cAAA,CAAA,MAAA,EAAA;AAAMf,QAAAA,SAAS,EAAC,mBAAA;OAChB,CAAA,eAAAe,cAAA,CAAA,MAAA,EAAA;AAAMf,QAAAA,SAAS,EAAC,8BAAA;AAA8B,OAChD,CAAA,CAAA;AAAA,KAAM,CACR,CAAA;AAAA,GAAM,CAAC,CAAA;AAEX,CAAC;;;;"}
|
|
@@ -1,31 +1,42 @@
|
|
|
1
1
|
import { clsx } from 'clsx';
|
|
2
|
-
import { forwardRef } from 'react';
|
|
2
|
+
import { forwardRef, useRef, useImperativeHandle, useEffect } from 'react';
|
|
3
3
|
import { useInputAttributes } from '../inputs/contexts.mjs';
|
|
4
4
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
5
5
|
|
|
6
6
|
const CheckboxButton = /*#__PURE__*/forwardRef(function CheckboxButton({
|
|
7
7
|
checked,
|
|
8
|
+
indeterminate = false,
|
|
8
9
|
className,
|
|
9
10
|
disabled,
|
|
10
11
|
onChange,
|
|
11
12
|
...rest
|
|
12
13
|
}, reference) {
|
|
13
14
|
const inputAttributes = useInputAttributes();
|
|
15
|
+
const internalRef = useRef(null);
|
|
16
|
+
useImperativeHandle(reference, () => internalRef.current ?? {});
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
if (internalRef.current) {
|
|
19
|
+
// eslint-disable-next-line functional/immutable-data, @typescript-eslint/no-unsafe-assignment
|
|
20
|
+
internalRef.current.indeterminate = indeterminate;
|
|
21
|
+
}
|
|
22
|
+
}, [indeterminate, reference]);
|
|
14
23
|
return /*#__PURE__*/jsxs("span", {
|
|
15
24
|
className: clsx('np-checkbox-button', className, disabled && 'disabled'),
|
|
16
25
|
children: [/*#__PURE__*/jsx("input", {
|
|
17
26
|
...inputAttributes,
|
|
18
27
|
...rest,
|
|
19
|
-
ref: reference,
|
|
28
|
+
ref: reference ?? internalRef,
|
|
20
29
|
type: "checkbox",
|
|
21
30
|
disabled: disabled,
|
|
22
31
|
checked: checked,
|
|
23
32
|
onChange: onChange
|
|
24
|
-
}), /*#__PURE__*/
|
|
33
|
+
}), /*#__PURE__*/jsxs("span", {
|
|
25
34
|
className: "tw-checkbox-button",
|
|
26
|
-
children: /*#__PURE__*/jsx("span", {
|
|
35
|
+
children: [/*#__PURE__*/jsx("span", {
|
|
27
36
|
className: "tw-checkbox-check"
|
|
28
|
-
})
|
|
37
|
+
}), /*#__PURE__*/jsx("span", {
|
|
38
|
+
className: "np-tw-checkbox-indeterminate"
|
|
39
|
+
})]
|
|
29
40
|
})]
|
|
30
41
|
});
|
|
31
42
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CheckboxButton.mjs","sources":["../../src/checkboxButton/CheckboxButton.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { InputHTMLAttributes, forwardRef } from 'react';\n\nimport { useInputAttributes } from '../inputs/contexts';\n\nexport type CheckboxButtonProps = InputHTMLAttributes<HTMLInputElement
|
|
1
|
+
{"version":3,"file":"CheckboxButton.mjs","sources":["../../src/checkboxButton/CheckboxButton.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { InputHTMLAttributes, forwardRef, useEffect, useImperativeHandle, useRef } from 'react';\n\nimport { useInputAttributes } from '../inputs/contexts';\n\nexport type CheckboxButtonProps = InputHTMLAttributes<HTMLInputElement> & {\n indeterminate?: boolean;\n};\n\nconst CheckboxButton = forwardRef<HTMLInputElement, CheckboxButtonProps>(function CheckboxButton(\n { checked, indeterminate = false, className, disabled, onChange, ...rest },\n reference,\n) {\n const inputAttributes = useInputAttributes();\n\n const internalRef = useRef<HTMLInputElement>(null);\n\n useImperativeHandle(reference, () => internalRef.current ?? ({} as HTMLInputElement));\n\n useEffect(() => {\n if (internalRef.current) {\n // eslint-disable-next-line functional/immutable-data, @typescript-eslint/no-unsafe-assignment\n internalRef.current.indeterminate = indeterminate;\n }\n }, [indeterminate, reference]);\n\n return (\n <span className={clsx('np-checkbox-button', className, disabled && 'disabled')}>\n <input\n {...inputAttributes}\n {...rest}\n ref={reference ?? internalRef}\n type=\"checkbox\"\n disabled={disabled}\n checked={checked}\n onChange={onChange}\n />\n <span className=\"tw-checkbox-button\">\n <span className=\"tw-checkbox-check\" />\n <span className=\"np-tw-checkbox-indeterminate\" />\n </span>\n </span>\n );\n});\n\nexport default CheckboxButton;\n"],"names":["CheckboxButton","forwardRef","checked","indeterminate","className","disabled","onChange","rest","reference","inputAttributes","useInputAttributes","internalRef","useRef","useImperativeHandle","current","useEffect","_jsxs","clsx","children","_jsx","ref","type"],"mappings":";;;;;AASA,MAAMA,cAAc,gBAAGC,UAAU,CAAwC,SAASD,cAAcA,CAC9F;EAAEE,OAAO;AAAEC,EAAAA,aAAa,GAAG,KAAK;EAAEC,SAAS;EAAEC,QAAQ;EAAEC,QAAQ;EAAE,GAAGC,IAAAA;AAAM,CAAA,EAC1EC,SAAS,EAAA;AAET,EAAA,MAAMC,eAAe,GAAGC,kBAAkB,EAAE,CAAA;AAE5C,EAAA,MAAMC,WAAW,GAAGC,MAAM,CAAmB,IAAI,CAAC,CAAA;EAElDC,mBAAmB,CAACL,SAAS,EAAE,MAAMG,WAAW,CAACG,OAAO,IAAK,EAAuB,CAAC,CAAA;AAErFC,EAAAA,SAAS,CAAC,MAAK;IACb,IAAIJ,WAAW,CAACG,OAAO,EAAE;AACvB;AACAH,MAAAA,WAAW,CAACG,OAAO,CAACX,aAAa,GAAGA,aAAa,CAAA;AACnD,KAAA;AACF,GAAC,EAAE,CAACA,aAAa,EAAEK,SAAS,CAAC,CAAC,CAAA;AAE9B,EAAA,oBACEQ,IAAA,CAAA,MAAA,EAAA;IAAMZ,SAAS,EAAEa,IAAI,CAAC,oBAAoB,EAAEb,SAAS,EAAEC,QAAQ,IAAI,UAAU,CAAE;AAAAa,IAAAA,QAAA,gBAC7EC,GAAA,CAAA,OAAA,EAAA;AAAA,MAAA,GACMV,eAAe;AAAA,MAAA,GACfF,IAAI;MACRa,GAAG,EAAEZ,SAAS,IAAIG,WAAY;AAC9BU,MAAAA,IAAI,EAAC,UAAU;AACfhB,MAAAA,QAAQ,EAAEA,QAAS;AACnBH,MAAAA,OAAO,EAAEA,OAAQ;AACjBI,MAAAA,QAAQ,EAAEA,QAAAA;KAEZ,CAAA,eAAAU,IAAA,CAAA,MAAA,EAAA;AAAMZ,MAAAA,SAAS,EAAC,oBAAoB;AAAAc,MAAAA,QAAA,gBAClCC,GAAA,CAAA,MAAA,EAAA;AAAMf,QAAAA,SAAS,EAAC,mBAAA;OAChB,CAAA,eAAAe,GAAA,CAAA,MAAA,EAAA;AAAMf,QAAAA,SAAS,EAAC,8BAAA;AAA8B,OAChD,CAAA,CAAA;AAAA,KAAM,CACR,CAAA;AAAA,GAAM,CAAC,CAAA;AAEX,CAAC;;;;"}
|
package/build/main.css
CHANGED
|
@@ -796,7 +796,8 @@ div.critical-comms .critical-comms-body {
|
|
|
796
796
|
.np-checkbox-button input[type="checkbox"]:not(:disabled) {
|
|
797
797
|
cursor: pointer;
|
|
798
798
|
}
|
|
799
|
-
.np-checkbox-button .tw-checkbox-check
|
|
799
|
+
.np-checkbox-button .tw-checkbox-check,
|
|
800
|
+
.np-checkbox-button .np-tw-checkbox-indeterminate {
|
|
800
801
|
pointer-events: none;
|
|
801
802
|
}
|
|
802
803
|
.checkbox .np-checkbox-button input[type="checkbox"] {
|
|
@@ -809,6 +810,24 @@ div.critical-comms .critical-comms-body {
|
|
|
809
810
|
left: auto;
|
|
810
811
|
left: initial;
|
|
811
812
|
}
|
|
813
|
+
.np-tw-checkbox-indeterminate {
|
|
814
|
+
position: relative;
|
|
815
|
+
}
|
|
816
|
+
.np-tw-checkbox-indeterminate::after {
|
|
817
|
+
content: "";
|
|
818
|
+
position: absolute;
|
|
819
|
+
width: 12px;
|
|
820
|
+
height: 2px;
|
|
821
|
+
top: 55%;
|
|
822
|
+
left: 50%;
|
|
823
|
+
background: #ffffff;
|
|
824
|
+
background: var(--color-background-screen);
|
|
825
|
+
transform: translate(-50%, -50%);
|
|
826
|
+
}
|
|
827
|
+
.np-tw-checkbox-indeterminate .has-error::after {
|
|
828
|
+
background-color: #e74848;
|
|
829
|
+
background-color: var(--color-interactive-negative);
|
|
830
|
+
}
|
|
812
831
|
.np-chip {
|
|
813
832
|
background-color: transparent;
|
|
814
833
|
border: 1px solid rgba(0,0,0,0.10196);
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
.np-checkbox-button input[type="checkbox"]:not(:disabled) {
|
|
10
10
|
cursor: pointer;
|
|
11
11
|
}
|
|
12
|
-
.np-checkbox-button .tw-checkbox-check
|
|
12
|
+
.np-checkbox-button .tw-checkbox-check,
|
|
13
|
+
.np-checkbox-button .np-tw-checkbox-indeterminate {
|
|
13
14
|
pointer-events: none;
|
|
14
15
|
}
|
|
15
16
|
.checkbox .np-checkbox-button input[type="checkbox"] {
|
|
@@ -22,3 +23,21 @@
|
|
|
22
23
|
left: auto;
|
|
23
24
|
left: initial;
|
|
24
25
|
}
|
|
26
|
+
.np-tw-checkbox-indeterminate {
|
|
27
|
+
position: relative;
|
|
28
|
+
}
|
|
29
|
+
.np-tw-checkbox-indeterminate::after {
|
|
30
|
+
content: "";
|
|
31
|
+
position: absolute;
|
|
32
|
+
width: 12px;
|
|
33
|
+
height: 2px;
|
|
34
|
+
top: 55%;
|
|
35
|
+
left: 50%;
|
|
36
|
+
background: #ffffff;
|
|
37
|
+
background: var(--color-background-screen);
|
|
38
|
+
transform: translate(-50%, -50%);
|
|
39
|
+
}
|
|
40
|
+
.np-tw-checkbox-indeterminate .has-error::after {
|
|
41
|
+
background-color: #e74848;
|
|
42
|
+
background-color: var(--color-interactive-negative);
|
|
43
|
+
}
|
package/build/styles/main.css
CHANGED
|
@@ -796,7 +796,8 @@ div.critical-comms .critical-comms-body {
|
|
|
796
796
|
.np-checkbox-button input[type="checkbox"]:not(:disabled) {
|
|
797
797
|
cursor: pointer;
|
|
798
798
|
}
|
|
799
|
-
.np-checkbox-button .tw-checkbox-check
|
|
799
|
+
.np-checkbox-button .tw-checkbox-check,
|
|
800
|
+
.np-checkbox-button .np-tw-checkbox-indeterminate {
|
|
800
801
|
pointer-events: none;
|
|
801
802
|
}
|
|
802
803
|
.checkbox .np-checkbox-button input[type="checkbox"] {
|
|
@@ -809,6 +810,24 @@ div.critical-comms .critical-comms-body {
|
|
|
809
810
|
left: auto;
|
|
810
811
|
left: initial;
|
|
811
812
|
}
|
|
813
|
+
.np-tw-checkbox-indeterminate {
|
|
814
|
+
position: relative;
|
|
815
|
+
}
|
|
816
|
+
.np-tw-checkbox-indeterminate::after {
|
|
817
|
+
content: "";
|
|
818
|
+
position: absolute;
|
|
819
|
+
width: 12px;
|
|
820
|
+
height: 2px;
|
|
821
|
+
top: 55%;
|
|
822
|
+
left: 50%;
|
|
823
|
+
background: #ffffff;
|
|
824
|
+
background: var(--color-background-screen);
|
|
825
|
+
transform: translate(-50%, -50%);
|
|
826
|
+
}
|
|
827
|
+
.np-tw-checkbox-indeterminate .has-error::after {
|
|
828
|
+
background-color: #e74848;
|
|
829
|
+
background-color: var(--color-interactive-negative);
|
|
830
|
+
}
|
|
812
831
|
.np-chip {
|
|
813
832
|
background-color: transparent;
|
|
814
833
|
border: 1px solid rgba(0,0,0,0.10196);
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { InputHTMLAttributes } from 'react';
|
|
2
|
-
export type CheckboxButtonProps = InputHTMLAttributes<HTMLInputElement
|
|
3
|
-
|
|
2
|
+
export type CheckboxButtonProps = InputHTMLAttributes<HTMLInputElement> & {
|
|
3
|
+
indeterminate?: boolean;
|
|
4
|
+
};
|
|
5
|
+
declare const CheckboxButton: import("react").ForwardRefExoticComponent<InputHTMLAttributes<HTMLInputElement> & {
|
|
6
|
+
indeterminate?: boolean;
|
|
7
|
+
} & import("react").RefAttributes<HTMLInputElement>>;
|
|
4
8
|
export default CheckboxButton;
|
|
5
9
|
//# sourceMappingURL=CheckboxButton.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CheckboxButton.d.ts","sourceRoot":"","sources":["../../../src/checkboxButton/CheckboxButton.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,
|
|
1
|
+
{"version":3,"file":"CheckboxButton.d.ts","sourceRoot":"","sources":["../../../src/checkboxButton/CheckboxButton.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAsD,MAAM,OAAO,CAAC;AAIhG,MAAM,MAAM,mBAAmB,GAAG,mBAAmB,CAAC,gBAAgB,CAAC,GAAG;IACxE,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB,CAAC;AAEF,QAAA,MAAM,cAAc;oBAHF,OAAO;oDAqCvB,CAAC;AAEH,eAAe,cAAc,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@transferwise/components",
|
|
3
|
-
"version": "46.
|
|
3
|
+
"version": "46.61.0",
|
|
4
4
|
"description": "Neptune React components",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -93,7 +93,7 @@
|
|
|
93
93
|
"rollup-preserve-directives": "^1.1.1",
|
|
94
94
|
"storybook": "^8.2.2",
|
|
95
95
|
"@transferwise/less-config": "3.1.0",
|
|
96
|
-
"@transferwise/neptune-css": "14.
|
|
96
|
+
"@transferwise/neptune-css": "14.14.0",
|
|
97
97
|
"@wise/components-theming": "1.6.0"
|
|
98
98
|
},
|
|
99
99
|
"peerDependencies": {
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
.np-checkbox-button input[type="checkbox"]:not(:disabled) {
|
|
10
10
|
cursor: pointer;
|
|
11
11
|
}
|
|
12
|
-
.np-checkbox-button .tw-checkbox-check
|
|
12
|
+
.np-checkbox-button .tw-checkbox-check,
|
|
13
|
+
.np-checkbox-button .np-tw-checkbox-indeterminate {
|
|
13
14
|
pointer-events: none;
|
|
14
15
|
}
|
|
15
16
|
.checkbox .np-checkbox-button input[type="checkbox"] {
|
|
@@ -22,3 +23,21 @@
|
|
|
22
23
|
left: auto;
|
|
23
24
|
left: initial;
|
|
24
25
|
}
|
|
26
|
+
.np-tw-checkbox-indeterminate {
|
|
27
|
+
position: relative;
|
|
28
|
+
}
|
|
29
|
+
.np-tw-checkbox-indeterminate::after {
|
|
30
|
+
content: "";
|
|
31
|
+
position: absolute;
|
|
32
|
+
width: 12px;
|
|
33
|
+
height: 2px;
|
|
34
|
+
top: 55%;
|
|
35
|
+
left: 50%;
|
|
36
|
+
background: #ffffff;
|
|
37
|
+
background: var(--color-background-screen);
|
|
38
|
+
transform: translate(-50%, -50%);
|
|
39
|
+
}
|
|
40
|
+
.np-tw-checkbox-indeterminate .has-error::after {
|
|
41
|
+
background-color: #e74848;
|
|
42
|
+
background-color: var(--color-interactive-negative);
|
|
43
|
+
}
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
.tw-checkbox-check {
|
|
17
|
+
.tw-checkbox-check, .np-tw-checkbox-indeterminate {
|
|
18
18
|
pointer-events: none;
|
|
19
19
|
}
|
|
20
20
|
}
|
|
@@ -27,3 +27,24 @@
|
|
|
27
27
|
margin: 0;
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
+
|
|
31
|
+
.np-tw-checkbox-indeterminate {
|
|
32
|
+
position: relative;
|
|
33
|
+
|
|
34
|
+
&::after {
|
|
35
|
+
content: "";
|
|
36
|
+
position: absolute;
|
|
37
|
+
width: 12px;
|
|
38
|
+
height: 2px;
|
|
39
|
+
top: 55%;
|
|
40
|
+
left: 50%;
|
|
41
|
+
background: var(--color-background-screen);
|
|
42
|
+
transform: translate(-50%, -50%);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.has-error {
|
|
46
|
+
&::after {
|
|
47
|
+
background-color: var(--color-interactive-negative);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -2,7 +2,7 @@ import { action } from '@storybook/addon-actions';
|
|
|
2
2
|
import { Meta, StoryObj } from '@storybook/react';
|
|
3
3
|
import { useState } from 'react';
|
|
4
4
|
|
|
5
|
-
import CheckboxButton from './CheckboxButton';
|
|
5
|
+
import CheckboxButton, { CheckboxButtonProps } from './CheckboxButton';
|
|
6
6
|
|
|
7
7
|
export default {
|
|
8
8
|
component: CheckboxButton,
|
|
@@ -29,3 +29,26 @@ export const Basic: Story = {
|
|
|
29
29
|
return <CheckboxButton {...args} checked={checked} onChange={() => setChecked(!checked)} />;
|
|
30
30
|
},
|
|
31
31
|
};
|
|
32
|
+
|
|
33
|
+
const Template = (props: CheckboxButtonProps) => {
|
|
34
|
+
const checked = true;
|
|
35
|
+
const [indeterminate, setIndeterminate] = useState(true);
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<CheckboxButton
|
|
39
|
+
{...props}
|
|
40
|
+
checked={checked}
|
|
41
|
+
indeterminate={indeterminate}
|
|
42
|
+
onChange={() => setIndeterminate(!indeterminate)}
|
|
43
|
+
/>
|
|
44
|
+
);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export const Indeterminate = () => {
|
|
48
|
+
const args = {
|
|
49
|
+
'aria-label': 'Group checkbox with indeterminate state',
|
|
50
|
+
disabled: false,
|
|
51
|
+
indeterminate: true,
|
|
52
|
+
};
|
|
53
|
+
return <Template {...args} />;
|
|
54
|
+
};
|
|
@@ -1,22 +1,35 @@
|
|
|
1
1
|
import { clsx } from 'clsx';
|
|
2
|
-
import { InputHTMLAttributes, forwardRef } from 'react';
|
|
2
|
+
import { InputHTMLAttributes, forwardRef, useEffect, useImperativeHandle, useRef } from 'react';
|
|
3
3
|
|
|
4
4
|
import { useInputAttributes } from '../inputs/contexts';
|
|
5
5
|
|
|
6
|
-
export type CheckboxButtonProps = InputHTMLAttributes<HTMLInputElement
|
|
6
|
+
export type CheckboxButtonProps = InputHTMLAttributes<HTMLInputElement> & {
|
|
7
|
+
indeterminate?: boolean;
|
|
8
|
+
};
|
|
7
9
|
|
|
8
10
|
const CheckboxButton = forwardRef<HTMLInputElement, CheckboxButtonProps>(function CheckboxButton(
|
|
9
|
-
{ checked, className, disabled, onChange, ...rest },
|
|
11
|
+
{ checked, indeterminate = false, className, disabled, onChange, ...rest },
|
|
10
12
|
reference,
|
|
11
13
|
) {
|
|
12
14
|
const inputAttributes = useInputAttributes();
|
|
13
15
|
|
|
16
|
+
const internalRef = useRef<HTMLInputElement>(null);
|
|
17
|
+
|
|
18
|
+
useImperativeHandle(reference, () => internalRef.current ?? ({} as HTMLInputElement));
|
|
19
|
+
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (internalRef.current) {
|
|
22
|
+
// eslint-disable-next-line functional/immutable-data, @typescript-eslint/no-unsafe-assignment
|
|
23
|
+
internalRef.current.indeterminate = indeterminate;
|
|
24
|
+
}
|
|
25
|
+
}, [indeterminate, reference]);
|
|
26
|
+
|
|
14
27
|
return (
|
|
15
28
|
<span className={clsx('np-checkbox-button', className, disabled && 'disabled')}>
|
|
16
29
|
<input
|
|
17
30
|
{...inputAttributes}
|
|
18
31
|
{...rest}
|
|
19
|
-
ref={reference}
|
|
32
|
+
ref={reference ?? internalRef}
|
|
20
33
|
type="checkbox"
|
|
21
34
|
disabled={disabled}
|
|
22
35
|
checked={checked}
|
|
@@ -24,6 +37,7 @@ const CheckboxButton = forwardRef<HTMLInputElement, CheckboxButtonProps>(functio
|
|
|
24
37
|
/>
|
|
25
38
|
<span className="tw-checkbox-button">
|
|
26
39
|
<span className="tw-checkbox-check" />
|
|
40
|
+
<span className="np-tw-checkbox-indeterminate" />
|
|
27
41
|
</span>
|
|
28
42
|
</span>
|
|
29
43
|
);
|
package/src/main.css
CHANGED
|
@@ -796,7 +796,8 @@ div.critical-comms .critical-comms-body {
|
|
|
796
796
|
.np-checkbox-button input[type="checkbox"]:not(:disabled) {
|
|
797
797
|
cursor: pointer;
|
|
798
798
|
}
|
|
799
|
-
.np-checkbox-button .tw-checkbox-check
|
|
799
|
+
.np-checkbox-button .tw-checkbox-check,
|
|
800
|
+
.np-checkbox-button .np-tw-checkbox-indeterminate {
|
|
800
801
|
pointer-events: none;
|
|
801
802
|
}
|
|
802
803
|
.checkbox .np-checkbox-button input[type="checkbox"] {
|
|
@@ -809,6 +810,24 @@ div.critical-comms .critical-comms-body {
|
|
|
809
810
|
left: auto;
|
|
810
811
|
left: initial;
|
|
811
812
|
}
|
|
813
|
+
.np-tw-checkbox-indeterminate {
|
|
814
|
+
position: relative;
|
|
815
|
+
}
|
|
816
|
+
.np-tw-checkbox-indeterminate::after {
|
|
817
|
+
content: "";
|
|
818
|
+
position: absolute;
|
|
819
|
+
width: 12px;
|
|
820
|
+
height: 2px;
|
|
821
|
+
top: 55%;
|
|
822
|
+
left: 50%;
|
|
823
|
+
background: #ffffff;
|
|
824
|
+
background: var(--color-background-screen);
|
|
825
|
+
transform: translate(-50%, -50%);
|
|
826
|
+
}
|
|
827
|
+
.np-tw-checkbox-indeterminate .has-error::after {
|
|
828
|
+
background-color: #e74848;
|
|
829
|
+
background-color: var(--color-interactive-negative);
|
|
830
|
+
}
|
|
812
831
|
.np-chip {
|
|
813
832
|
background-color: transparent;
|
|
814
833
|
border: 1px solid rgba(0,0,0,0.10196);
|