@transferwise/components 0.0.0-experimental-2f6892d → 0.0.0-experimental-9296e7a
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 +10 -1
- package/build/checkboxButton/CheckboxButton.js.map +1 -1
- package/build/checkboxButton/CheckboxButton.mjs +11 -2
- package/build/checkboxButton/CheckboxButton.mjs.map +1 -1
- package/build/types/checkboxButton/CheckboxButton.d.ts +6 -2
- package/build/types/checkboxButton/CheckboxButton.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/checkboxButton/CheckboxButton.story.tsx +6 -15
- package/src/checkboxButton/CheckboxButton.tsx +17 -4
|
@@ -7,18 +7,27 @@ 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,
|
|
@@ -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","_j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AA;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,22 +1,31 @@
|
|
|
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,
|
|
@@ -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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,GAAM,CAAC,CAAA;AAEX,CAAC;;;;"}
|
|
@@ -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": "0.0.0-experimental-
|
|
3
|
+
"version": "0.0.0-experimental-9296e7a",
|
|
4
4
|
"description": "Neptune React components",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -93,12 +93,12 @@
|
|
|
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": "0.0.0-experimental-
|
|
96
|
+
"@transferwise/neptune-css": "0.0.0-experimental-9296e7a",
|
|
97
97
|
"@wise/components-theming": "1.6.0"
|
|
98
98
|
},
|
|
99
99
|
"peerDependencies": {
|
|
100
100
|
"@transferwise/icons": "^3.7.0",
|
|
101
|
-
"@transferwise/neptune-css": "0.0.0-experimental-
|
|
101
|
+
"@transferwise/neptune-css": "0.0.0-experimental-9296e7a",
|
|
102
102
|
"@wise/art": "^2.7.0",
|
|
103
103
|
"@wise/components-theming": "^1.0.0",
|
|
104
104
|
"react": ">=18",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { action } from '@storybook/addon-actions';
|
|
2
2
|
import { Meta, StoryObj } from '@storybook/react';
|
|
3
|
-
import {
|
|
3
|
+
import { useState } from 'react';
|
|
4
4
|
|
|
5
5
|
import CheckboxButton, { CheckboxButtonProps } from './CheckboxButton';
|
|
6
6
|
|
|
@@ -31,25 +31,15 @@ export const Basic: Story = {
|
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
const Template = (props: CheckboxButtonProps) => {
|
|
34
|
-
const
|
|
35
|
-
const [
|
|
36
|
-
|
|
37
|
-
useEffect(() => {
|
|
38
|
-
if (checkboxRef.current) {
|
|
39
|
-
if (!checkboxRef.current.checked) {
|
|
40
|
-
checkboxRef.current.indeterminate = true;
|
|
41
|
-
} else {
|
|
42
|
-
checkboxRef.current.indeterminate = false;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}, [checked]);
|
|
34
|
+
const checked = true;
|
|
35
|
+
const [indeterminate, setIndeterminate] = useState(true);
|
|
46
36
|
|
|
47
37
|
return (
|
|
48
38
|
<CheckboxButton
|
|
49
39
|
{...props}
|
|
50
|
-
ref={checkboxRef}
|
|
51
40
|
checked={checked}
|
|
52
|
-
|
|
41
|
+
indeterminate={indeterminate}
|
|
42
|
+
onChange={() => setIndeterminate(!indeterminate)}
|
|
53
43
|
/>
|
|
54
44
|
);
|
|
55
45
|
};
|
|
@@ -58,6 +48,7 @@ export const Indeterminate = () => {
|
|
|
58
48
|
const args = {
|
|
59
49
|
'aria-label': 'Group checkbox with indeterminate state',
|
|
60
50
|
disabled: false,
|
|
51
|
+
indeterminate: true,
|
|
61
52
|
};
|
|
62
53
|
return <Template {...args} />;
|
|
63
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}
|