@transferwise/components 0.0.0-experimental-1605d4e → 0.0.0-experimental-65253b2
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { CheckboxButtonProps } from '../checkboxButton/CheckboxButton';
|
|
2
|
-
export type ItemCheckboxProps = Pick<CheckboxButtonProps, 'checked' | 'indeterminate' | 'onChange'>;
|
|
2
|
+
export type ItemCheckboxProps = Pick<CheckboxButtonProps, 'checked' | 'indeterminate' | 'onChange' | 'disabled'>;
|
|
3
3
|
export declare const Checkbox: (props: ItemCheckboxProps) => import("react").JSX.Element;
|
|
4
4
|
//# sourceMappingURL=ItemCheckbox.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ItemCheckbox.d.ts","sourceRoot":"","sources":["../../../src/item/ItemCheckbox.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAGvE,MAAM,MAAM,iBAAiB,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"ItemCheckbox.d.ts","sourceRoot":"","sources":["../../../src/item/ItemCheckbox.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAGvE,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAClC,mBAAmB,EACnB,SAAS,GAAG,eAAe,GAAG,UAAU,GAAG,UAAU,CACtD,CAAC;AAEF,eAAO,MAAM,QAAQ,UAAoB,iBAAiB,gCAQzD,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-65253b2",
|
|
4
4
|
"description": "Neptune React components",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -95,13 +95,13 @@
|
|
|
95
95
|
"rollup-preserve-directives": "^1.1.1",
|
|
96
96
|
"storybook": "^8.2.2",
|
|
97
97
|
"@transferwise/less-config": "3.1.1",
|
|
98
|
-
"@transferwise/neptune-css": "0.0.0-experimental-
|
|
98
|
+
"@transferwise/neptune-css": "0.0.0-experimental-65253b2",
|
|
99
99
|
"@wise/components-theming": "1.6.2",
|
|
100
100
|
"@wise/wds-configs": "0.0.0"
|
|
101
101
|
},
|
|
102
102
|
"peerDependencies": {
|
|
103
103
|
"@transferwise/icons": "^3.21.0",
|
|
104
|
-
"@transferwise/neptune-css": "0.0.0-experimental-
|
|
104
|
+
"@transferwise/neptune-css": "0.0.0-experimental-65253b2",
|
|
105
105
|
"@wise/art": "^2.16",
|
|
106
106
|
"@wise/components-theming": "^1.0.0",
|
|
107
107
|
"react": ">=18",
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { render, screen, mockMatchMedia } from '../test-utils';
|
|
2
|
+
import { Button as ItemButton } from './ItemButton';
|
|
3
|
+
import { ButtonPriority } from '../button/Button.types';
|
|
4
|
+
import { ItemContext } from './Item';
|
|
5
|
+
|
|
6
|
+
mockMatchMedia();
|
|
7
|
+
|
|
8
|
+
describe('ItemButton', () => {
|
|
9
|
+
const mockSetControlType = jest.fn();
|
|
10
|
+
|
|
11
|
+
const renderWithItemContext = (ui: React.ReactNode) => {
|
|
12
|
+
return render(
|
|
13
|
+
<ItemContext.Provider
|
|
14
|
+
value={{
|
|
15
|
+
setControlType: mockSetControlType,
|
|
16
|
+
ids: {
|
|
17
|
+
label: 'label',
|
|
18
|
+
additionalInfo: 'additional Info',
|
|
19
|
+
value: 'value',
|
|
20
|
+
control: 'control',
|
|
21
|
+
prompt: 'prompt',
|
|
22
|
+
},
|
|
23
|
+
props: {},
|
|
24
|
+
}}
|
|
25
|
+
>
|
|
26
|
+
{ui}
|
|
27
|
+
</ItemContext.Provider>,
|
|
28
|
+
);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
beforeEach(() => {
|
|
32
|
+
jest.clearAllMocks();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('always sets v2 to true', () => {
|
|
36
|
+
renderWithItemContext(<ItemButton priority="primary">Test Button</ItemButton>);
|
|
37
|
+
const button = screen.getByRole('button');
|
|
38
|
+
expect(button).toBeInTheDocument();
|
|
39
|
+
expect(mockSetControlType).toHaveBeenCalledWith('button');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('always sets size to "md"', () => {
|
|
43
|
+
renderWithItemContext(<ItemButton priority="primary">Test Button</ItemButton>);
|
|
44
|
+
const button = screen.getByRole('button');
|
|
45
|
+
expect(button).toHaveClass('wds-Button--medium');
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('supports all priorities', () => {
|
|
49
|
+
const priorities: ButtonPriority[] = ['primary', 'secondary', 'tertiary'];
|
|
50
|
+
priorities.forEach((priority) => {
|
|
51
|
+
renderWithItemContext(<ItemButton priority={priority}>Test {priority}</ItemButton>);
|
|
52
|
+
const button = screen.getByRole('button', { name: `Test ${priority}` });
|
|
53
|
+
expect(button).toBeInTheDocument();
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('renders as a button by default', () => {
|
|
58
|
+
renderWithItemContext(<ItemButton>Click me</ItemButton>);
|
|
59
|
+
const button = screen.getByRole('button');
|
|
60
|
+
expect(button).toBeInTheDocument();
|
|
61
|
+
expect(button.tagName).toBe('BUTTON');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('renders as an anchor when href is provided', () => {
|
|
65
|
+
renderWithItemContext(<ItemButton href="https://example.com">Go to Example</ItemButton>);
|
|
66
|
+
const link = screen.getByRole('link', { name: 'Go to Example' });
|
|
67
|
+
expect(link).toBeInTheDocument();
|
|
68
|
+
expect(link.tagName).toBe('A');
|
|
69
|
+
expect(link).toHaveAttribute('href', 'https://example.com');
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('spreads additional props to the button', () => {
|
|
73
|
+
renderWithItemContext(<ItemButton aria-label="Custom Button">Custom</ItemButton>);
|
|
74
|
+
const button = screen.getByRole('button', { name: 'Custom Button' });
|
|
75
|
+
expect(button).toBeInTheDocument();
|
|
76
|
+
expect(button).toHaveAttribute('aria-label', 'Custom Button');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('spreads additional props to the anchor', () => {
|
|
80
|
+
renderWithItemContext(
|
|
81
|
+
<ItemButton href="https://example.com" target="_blank" aria-label="Custom Link">
|
|
82
|
+
Custom Link
|
|
83
|
+
</ItemButton>,
|
|
84
|
+
);
|
|
85
|
+
const link = screen.getByRole('link', { name: 'Custom Link' });
|
|
86
|
+
expect(link).toBeInTheDocument();
|
|
87
|
+
expect(link).toHaveAttribute('href', 'https://example.com');
|
|
88
|
+
expect(link).toHaveAttribute('target', '_blank');
|
|
89
|
+
});
|
|
90
|
+
});
|
|
@@ -3,14 +3,17 @@ import CheckboxButton from '../checkboxButton';
|
|
|
3
3
|
import { CheckboxButtonProps } from '../checkboxButton/CheckboxButton';
|
|
4
4
|
import { ItemContext, ItemContextData } from './Item';
|
|
5
5
|
|
|
6
|
-
export type ItemCheckboxProps = Pick<
|
|
6
|
+
export type ItemCheckboxProps = Pick<
|
|
7
|
+
CheckboxButtonProps,
|
|
8
|
+
'checked' | 'indeterminate' | 'onChange' | 'disabled'
|
|
9
|
+
>;
|
|
7
10
|
|
|
8
11
|
export const Checkbox = function (props: ItemCheckboxProps) {
|
|
9
|
-
const { setControlType
|
|
12
|
+
const { setControlType } = useContext<ItemContextData>(ItemContext);
|
|
10
13
|
|
|
11
14
|
useEffect(() => {
|
|
12
15
|
setControlType('checkbox');
|
|
13
16
|
}, []);
|
|
14
17
|
|
|
15
|
-
return <CheckboxButton
|
|
18
|
+
return <CheckboxButton {...props} />;
|
|
16
19
|
};
|
package/src/item/ItemSwitch.tsx
CHANGED
|
@@ -3,11 +3,11 @@ import { default as SwitchComp, SwitchProps } from '../switch';
|
|
|
3
3
|
import { ItemContext, ItemContextData } from './Item';
|
|
4
4
|
|
|
5
5
|
export const Switch = function (props: SwitchProps) {
|
|
6
|
-
const { setControlType
|
|
6
|
+
const { setControlType } = useContext<ItemContextData>(ItemContext);
|
|
7
7
|
|
|
8
8
|
useEffect(() => {
|
|
9
9
|
setControlType('checkbox');
|
|
10
10
|
}, []);
|
|
11
11
|
|
|
12
|
-
return <SwitchComp
|
|
12
|
+
return <SwitchComp {...props} />;
|
|
13
13
|
};
|