@transferwise/components 0.0.0-experimental-28eac06 → 0.0.0-experimental-9b6d886
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/alert/Alert.js +17 -17
- package/build/alert/Alert.js.map +1 -1
- package/build/alert/Alert.mjs +14 -14
- package/build/alert/Alert.mjs.map +1 -1
- package/build/avatarLayout/AvatarLayout.js +2 -9
- package/build/avatarLayout/AvatarLayout.js.map +1 -1
- package/build/avatarLayout/AvatarLayout.mjs +2 -9
- package/build/avatarLayout/AvatarLayout.mjs.map +1 -1
- package/build/button/Button.js +79 -86
- package/build/button/Button.js.map +1 -1
- package/build/button/Button.mjs +80 -87
- package/build/button/Button.mjs.map +1 -1
- package/build/circularButton/CircularButton.js.map +1 -1
- package/build/circularButton/CircularButton.mjs.map +1 -1
- package/build/common/action/Action.js +15 -26
- package/build/common/action/Action.js.map +1 -1
- package/build/common/action/Action.mjs +15 -26
- package/build/common/action/Action.mjs.map +1 -1
- package/build/common/propsValues/sentiment.js +0 -1
- package/build/common/propsValues/sentiment.js.map +1 -1
- package/build/common/propsValues/sentiment.mjs +0 -1
- package/build/common/propsValues/sentiment.mjs.map +1 -1
- package/build/criticalBanner/CriticalCommsBanner.js +73 -10
- package/build/criticalBanner/CriticalCommsBanner.js.map +1 -1
- package/build/criticalBanner/CriticalCommsBanner.mjs +74 -11
- package/build/criticalBanner/CriticalCommsBanner.mjs.map +1 -1
- package/build/header/Header.js +2 -2
- package/build/header/Header.js.map +1 -1
- package/build/header/Header.mjs +1 -1
- package/build/i18n/en.json +0 -1
- package/build/i18n/en.json.js +0 -1
- package/build/i18n/en.json.js.map +1 -1
- package/build/i18n/en.json.mjs +0 -1
- package/build/i18n/en.json.mjs.map +1 -1
- package/build/i18n/ja.json +1 -0
- package/build/i18n/ja.json.js +1 -0
- package/build/i18n/ja.json.js.map +1 -1
- package/build/i18n/ja.json.mjs +1 -0
- package/build/i18n/ja.json.mjs.map +1 -1
- package/build/i18n/pt.json +1 -0
- package/build/i18n/pt.json.js +1 -0
- package/build/i18n/pt.json.js.map +1 -1
- package/build/i18n/pt.json.mjs +1 -0
- package/build/i18n/pt.json.mjs.map +1 -1
- package/build/i18n/ru.json +1 -0
- package/build/i18n/ru.json.js +1 -0
- package/build/i18n/ru.json.js.map +1 -1
- package/build/i18n/ru.json.mjs +1 -0
- package/build/i18n/ru.json.mjs.map +1 -1
- package/build/i18n/zh-HK.json +1 -0
- package/build/i18n/zh-HK.json.js +1 -0
- package/build/i18n/zh-HK.json.js.map +1 -1
- package/build/i18n/zh-HK.json.mjs +1 -0
- package/build/i18n/zh-HK.json.mjs.map +1 -1
- package/build/index.js +2 -2
- package/build/index.mjs +1 -1
- package/build/link/Link.js +3 -8
- package/build/link/Link.js.map +1 -1
- package/build/link/Link.mjs +3 -8
- package/build/link/Link.mjs.map +1 -1
- package/build/main.css +70 -267
- package/build/primitives/PrimitiveAnchor/src/PrimitiveAnchor.js +4 -2
- package/build/primitives/PrimitiveAnchor/src/PrimitiveAnchor.js.map +1 -1
- package/build/primitives/PrimitiveAnchor/src/PrimitiveAnchor.mjs +4 -2
- package/build/primitives/PrimitiveAnchor/src/PrimitiveAnchor.mjs.map +1 -1
- package/build/primitives/PrimitiveButton/src/PrimitiveButton.js +5 -3
- package/build/primitives/PrimitiveButton/src/PrimitiveButton.js.map +1 -1
- package/build/primitives/PrimitiveButton/src/PrimitiveButton.mjs +5 -3
- package/build/primitives/PrimitiveButton/src/PrimitiveButton.mjs.map +1 -1
- package/build/select/Select.js +2 -2
- package/build/select/Select.js.map +1 -1
- package/build/select/Select.mjs +1 -1
- package/build/statusIcon/StatusIcon.js +1 -5
- package/build/statusIcon/StatusIcon.js.map +1 -1
- package/build/statusIcon/StatusIcon.messages.js +0 -3
- package/build/statusIcon/StatusIcon.messages.js.map +1 -1
- package/build/statusIcon/StatusIcon.messages.mjs +0 -3
- package/build/statusIcon/StatusIcon.messages.mjs.map +1 -1
- package/build/statusIcon/StatusIcon.mjs +1 -5
- package/build/statusIcon/StatusIcon.mjs.map +1 -1
- package/build/styles/avatarLayout/AvatarLayout.css +0 -11
- package/build/styles/button/Button.css +15 -230
- package/build/styles/criticalBanner/CriticalCommsBanner.css +73 -21
- package/build/styles/main.css +70 -267
- package/build/types/alert/Alert.d.ts +4 -3
- package/build/types/alert/Alert.d.ts.map +1 -1
- package/build/types/avatarLayout/AvatarLayout.d.ts.map +1 -1
- package/build/types/button/Button.d.ts +23 -2
- package/build/types/button/Button.d.ts.map +1 -1
- package/build/types/button/index.d.ts +2 -2
- package/build/types/button/index.d.ts.map +1 -1
- package/build/types/circularButton/CircularButton.d.ts.map +1 -1
- package/build/types/common/action/Action.d.ts +2 -5
- package/build/types/common/action/Action.d.ts.map +1 -1
- package/build/types/common/propsValues/sentiment.d.ts +0 -1
- package/build/types/common/propsValues/sentiment.d.ts.map +1 -1
- package/build/types/criticalBanner/CriticalCommsBanner.d.ts.map +1 -1
- package/build/types/index.d.ts +1 -0
- package/build/types/index.d.ts.map +1 -1
- package/build/types/link/Link.d.ts +2 -2
- package/build/types/link/Link.d.ts.map +1 -1
- package/build/types/primitives/PrimitiveAnchor/src/PrimitiveAnchor.d.ts.map +1 -1
- package/build/types/primitives/PrimitiveAnchor/src/PrimitiveAnchor.types.d.ts +2 -6
- package/build/types/primitives/PrimitiveAnchor/src/PrimitiveAnchor.types.d.ts.map +1 -1
- package/build/types/primitives/PrimitiveButton/src/PrimitiveButton.d.ts.map +1 -1
- package/build/types/statusIcon/StatusIcon.d.ts.map +1 -1
- package/build/types/statusIcon/StatusIcon.messages.d.ts +0 -5
- package/build/types/statusIcon/StatusIcon.messages.d.ts.map +1 -1
- package/build/types/test-utils/index.d.ts +0 -2
- package/build/types/test-utils/index.d.ts.map +1 -1
- package/build/types/test-utils/story-config.d.ts +1 -1
- package/build/types/test-utils/story-config.d.ts.map +1 -1
- package/build/upload/steps/completeStep/completeStep.js +2 -2
- package/build/upload/steps/completeStep/completeStep.js.map +1 -1
- package/build/upload/steps/completeStep/completeStep.mjs +1 -1
- package/build/upload/steps/processingStep/processingStep.js +2 -2
- package/build/upload/steps/processingStep/processingStep.js.map +1 -1
- package/build/upload/steps/processingStep/processingStep.mjs +1 -1
- package/build/uploadInput/UploadInput.js +3 -3
- package/build/uploadInput/UploadInput.js.map +1 -1
- package/build/uploadInput/UploadInput.mjs +1 -1
- package/package.json +3 -3
- package/src/alert/Alert.spec.tsx +30 -0
- package/src/alert/Alert.story.tsx +1 -34
- package/src/alert/Alert.tests.story.tsx +1 -1
- package/src/alert/Alert.tsx +15 -20
- package/src/avatarLayout/AvatarLayout.css +0 -11
- package/src/avatarLayout/AvatarLayout.less +1 -18
- package/src/avatarLayout/AvatarLayout.tsx +2 -10
- package/src/button/Button.css +15 -230
- package/src/button/Button.less +14 -242
- package/src/button/Button.spec.tsx +226 -215
- package/src/button/Button.story.tsx +134 -761
- package/src/button/Button.tsx +132 -103
- package/src/button/__snapshots__/Button.spec.tsx.snap +309 -0
- package/src/button/index.ts +3 -2
- package/src/circularButton/CircularButton.tsx +0 -1
- package/src/common/action/Action.tsx +22 -40
- package/src/common/propsValues/sentiment.ts +0 -1
- package/src/criticalBanner/CriticalCommsBanner.css +73 -21
- package/src/criticalBanner/CriticalCommsBanner.less +70 -24
- package/src/criticalBanner/CriticalCommsBanner.story.tsx +4 -26
- package/src/criticalBanner/CriticalCommsBanner.tsx +50 -8
- package/src/field/Field.story.tsx +1 -1
- package/src/flowNavigation/__snapshots__/FlowNavigation.spec.js.snap +2 -1
- package/src/i18n/en.json +0 -1
- package/src/i18n/ja.json +1 -0
- package/src/i18n/pt.json +1 -0
- package/src/i18n/ru.json +1 -0
- package/src/i18n/zh-HK.json +1 -0
- package/src/index.ts +1 -0
- package/src/inputs/SelectInput.story.tsx +1 -1
- package/src/label/Label.story.tsx +1 -1
- package/src/link/Link.tsx +6 -15
- package/src/main.css +70 -267
- package/src/main.less +0 -1
- package/src/primitives/PrimitiveAnchor/src/PrimitiveAnchor.tsx +8 -2
- package/src/primitives/PrimitiveAnchor/src/PrimitiveAnchor.types.ts +2 -7
- package/src/primitives/PrimitiveAnchor/test/PrimitiveAnchor.spec.tsx +3 -1
- package/src/primitives/PrimitiveButton/src/PrimitiveButton.tsx +12 -4
- package/src/primitives/PrimitiveButton/test/PrimitiveButton.spec.tsx +13 -16
- package/src/radio/Radio.spec.tsx +73 -0
- package/src/radio/Radio.story.tsx +22 -52
- package/src/radioGroup/RadioGroup.spec.tsx +91 -0
- package/src/radioGroup/RadioGroup.story.tsx +3 -5
- package/src/statusIcon/StatusIcon.less +0 -1
- package/src/statusIcon/StatusIcon.messages.ts +0 -6
- package/src/statusIcon/StatusIcon.tsx +1 -8
- package/src/test-utils/Parameters.d.ts +1 -9
- package/src/test-utils/story-config.ts +1 -10
- package/build/button/Button.resolver.js +0 -74
- package/build/button/Button.resolver.js.map +0 -1
- package/build/button/Button.resolver.mjs +0 -72
- package/build/button/Button.resolver.mjs.map +0 -1
- package/build/button/LegacyButton.js +0 -114
- package/build/button/LegacyButton.js.map +0 -1
- package/build/button/LegacyButton.mjs +0 -112
- package/build/button/LegacyButton.mjs.map +0 -1
- package/build/styles/button/Button.vars.css +0 -46
- package/build/styles/button/LegacyButton.css +0 -23
- package/build/types/button/Button.resolver.d.ts +0 -35
- package/build/types/button/Button.resolver.d.ts.map +0 -1
- package/build/types/button/Button.types.d.ts +0 -70
- package/build/types/button/Button.types.d.ts.map +0 -1
- package/build/types/button/LegacyButton.d.ts +0 -44
- package/build/types/button/LegacyButton.d.ts.map +0 -1
- package/src/button/Button.accessibility.docs.mdx +0 -103
- package/src/button/Button.resolver.tsx +0 -73
- package/src/button/Button.tests.story.tsx +0 -27
- package/src/button/Button.types.ts +0 -92
- package/src/button/Button.vars.css +0 -46
- package/src/button/Button.vars.less +0 -55
- package/src/button/LegacyButton.css +0 -23
- package/src/button/LegacyButton.less +0 -24
- package/src/button/LegacyButton.spec.tsx +0 -147
- package/src/button/LegacyButton.story.tsx +0 -228
- package/src/button/LegacyButton.tsx +0 -177
- package/src/radio/Radio.rtl.spec.tsx +0 -24
- package/src/radio/Radio.spec.js +0 -76
- package/src/radio/__snapshots__/Radio.rtl.spec.tsx.snap +0 -49
- package/src/radioGroup/RadioGroup.rtl.spec.tsx +0 -30
- package/src/radioGroup/RadioGroup.spec.js +0 -90
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
import { clsx } from 'clsx';
|
|
2
|
-
import { ElementType, forwardRef, MouseEvent } from 'react';
|
|
3
|
-
import { useIntl } from 'react-intl';
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
Size,
|
|
7
|
-
ControlType,
|
|
8
|
-
Priority,
|
|
9
|
-
ControlTypeAccent,
|
|
10
|
-
ControlTypeNegative,
|
|
11
|
-
ControlTypePositive,
|
|
12
|
-
PriorityPrimary,
|
|
13
|
-
PrioritySecondary,
|
|
14
|
-
PriorityTertiary,
|
|
15
|
-
SizeExtraSmall,
|
|
16
|
-
SizeSmall,
|
|
17
|
-
SizeMedium,
|
|
18
|
-
SizeLarge,
|
|
19
|
-
} from '../common';
|
|
20
|
-
import ProcessIndicator from '../processIndicator';
|
|
21
|
-
|
|
22
|
-
import messages from '../i18n/commonMessages/Button.messages';
|
|
23
|
-
import { typeClassMap, priorityClassMap } from './classMap';
|
|
24
|
-
import { establishNewPriority, establishNewType, logDeprecationNotices } from './legacyUtils';
|
|
25
|
-
import { ButtonReferenceType } from './Button.types';
|
|
26
|
-
|
|
27
|
-
/** @deprecated */
|
|
28
|
-
type DeprecatedTypes = 'primary' | 'pay' | 'secondary' | 'danger' | 'link';
|
|
29
|
-
|
|
30
|
-
/** @deprecated */
|
|
31
|
-
type DeprecatedSizes = SizeExtraSmall;
|
|
32
|
-
|
|
33
|
-
type CommonProps = {
|
|
34
|
-
v2?: false;
|
|
35
|
-
|
|
36
|
-
/** Makes the button take up the full width of its container */
|
|
37
|
-
block?: boolean;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* The `target` attribute for HTML anchor.
|
|
41
|
-
* If set to `_blank`, `rel="noopener noreferrer"` is automatically added to the rendered node.
|
|
42
|
-
*/
|
|
43
|
-
target?: string;
|
|
44
|
-
/**
|
|
45
|
-
* Toggles the disabled state
|
|
46
|
-
* @default false
|
|
47
|
-
*/
|
|
48
|
-
|
|
49
|
-
disabled?: boolean;
|
|
50
|
-
/**
|
|
51
|
-
* Toggles the loading state
|
|
52
|
-
* @default false
|
|
53
|
-
*/
|
|
54
|
-
loading?: boolean;
|
|
55
|
-
type?: ControlTypeAccent | ControlTypeNegative | ControlTypePositive | DeprecatedTypes | null;
|
|
56
|
-
priority?: PriorityPrimary | PrioritySecondary | PriorityTertiary | null;
|
|
57
|
-
size?: SizeSmall | SizeMedium | SizeLarge | DeprecatedSizes;
|
|
58
|
-
htmlType?: 'submit' | 'reset' | 'button';
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
type ButtonProps = CommonProps &
|
|
62
|
-
Omit<React.ComponentPropsWithRef<'button'>, 'type'> & {
|
|
63
|
-
as?: 'button';
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
type AnchorProps = CommonProps &
|
|
67
|
-
Omit<React.ComponentPropsWithRef<'a'>, 'type'> & {
|
|
68
|
-
as?: 'a';
|
|
69
|
-
href?: string;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
export type LegacyButtonProps = ButtonProps | AnchorProps;
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* @deprecated make sure you use new Button component via `<Button v2 .. />` and new props
|
|
76
|
-
*/
|
|
77
|
-
const LegacyButton = forwardRef<ButtonReferenceType, LegacyButtonProps>(
|
|
78
|
-
(
|
|
79
|
-
{
|
|
80
|
-
as: component = 'button',
|
|
81
|
-
block = false,
|
|
82
|
-
children,
|
|
83
|
-
className,
|
|
84
|
-
disabled,
|
|
85
|
-
loading = false,
|
|
86
|
-
priority = Priority.PRIMARY,
|
|
87
|
-
size = Size.MEDIUM,
|
|
88
|
-
type = ControlType.ACCENT,
|
|
89
|
-
onClick,
|
|
90
|
-
...rest
|
|
91
|
-
}: LegacyButtonProps,
|
|
92
|
-
ref,
|
|
93
|
-
) => {
|
|
94
|
-
const intl = useIntl();
|
|
95
|
-
|
|
96
|
-
logDeprecationNotices({ size, type });
|
|
97
|
-
|
|
98
|
-
const newType = establishNewType(type);
|
|
99
|
-
const newPriority = establishNewPriority(priority, type);
|
|
100
|
-
|
|
101
|
-
const classes = clsx(
|
|
102
|
-
`btn btn-${size}`,
|
|
103
|
-
`np-btn np-btn-${size}`,
|
|
104
|
-
{
|
|
105
|
-
'btn-loading': loading,
|
|
106
|
-
'btn-block np-btn-block': block,
|
|
107
|
-
disabled,
|
|
108
|
-
},
|
|
109
|
-
// @ts-expect-error fix when refactor `typeClassMap` to TypeScript
|
|
110
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
111
|
-
typeClassMap[newType],
|
|
112
|
-
// @ts-expect-error fix when refactor `typeClassMap` to TypeScript
|
|
113
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
114
|
-
priorityClassMap[newPriority],
|
|
115
|
-
className,
|
|
116
|
-
);
|
|
117
|
-
|
|
118
|
-
function processIndicatorSize() {
|
|
119
|
-
return ['sm', 'xs'].includes(size) ? 'xxs' : 'xs';
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const Element = (component as ElementType) ?? 'button';
|
|
123
|
-
let props;
|
|
124
|
-
|
|
125
|
-
if (Element === 'button') {
|
|
126
|
-
const { htmlType = 'button', ...restProps } = rest as ButtonProps;
|
|
127
|
-
props = {
|
|
128
|
-
...restProps,
|
|
129
|
-
disabled,
|
|
130
|
-
'aria-disabled': loading,
|
|
131
|
-
type: htmlType,
|
|
132
|
-
};
|
|
133
|
-
} else {
|
|
134
|
-
props = {
|
|
135
|
-
...rest,
|
|
136
|
-
'aria-disabled': loading,
|
|
137
|
-
} as AnchorProps;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Ensures that the button cannot be activated in loading or disabled mode,
|
|
142
|
-
* when `aria-disabled` might be used over the `disabled` HTML attribute
|
|
143
|
-
*/
|
|
144
|
-
const handleClick =
|
|
145
|
-
(handler: LegacyButtonProps['onClick']) =>
|
|
146
|
-
(event: MouseEvent<HTMLButtonElement> & MouseEvent<HTMLAnchorElement>) => {
|
|
147
|
-
if (disabled || loading) {
|
|
148
|
-
event.preventDefault();
|
|
149
|
-
} else if (typeof handler === 'function') {
|
|
150
|
-
handler(event);
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
return (
|
|
155
|
-
<Element
|
|
156
|
-
ref={ref as React.Ref<ButtonReferenceType>}
|
|
157
|
-
className={classes}
|
|
158
|
-
onClick={handleClick(onClick)}
|
|
159
|
-
{...props}
|
|
160
|
-
aria-live={loading ? 'polite' : 'off'}
|
|
161
|
-
aria-busy={loading}
|
|
162
|
-
aria-label={loading ? intl.formatMessage(messages.loadingAriaLabel) : rest['aria-label']}
|
|
163
|
-
>
|
|
164
|
-
{children}
|
|
165
|
-
{loading && (
|
|
166
|
-
<ProcessIndicator
|
|
167
|
-
size={processIndicatorSize()}
|
|
168
|
-
className="btn-loader"
|
|
169
|
-
data-testid="ButtonProgressIndicator"
|
|
170
|
-
/>
|
|
171
|
-
)}
|
|
172
|
-
</Element>
|
|
173
|
-
);
|
|
174
|
-
},
|
|
175
|
-
);
|
|
176
|
-
|
|
177
|
-
export default LegacyButton;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import Avatar, { AvatarType } from '../avatar';
|
|
2
|
-
import { render } from '../test-utils';
|
|
3
|
-
|
|
4
|
-
import Radio from '.';
|
|
5
|
-
|
|
6
|
-
jest.mock('../common/hooks');
|
|
7
|
-
|
|
8
|
-
describe('Radio', () => {
|
|
9
|
-
const props = {
|
|
10
|
-
label: 'This is a label',
|
|
11
|
-
name: 'name',
|
|
12
|
-
onChange: jest.fn(),
|
|
13
|
-
checked: false,
|
|
14
|
-
disabled: false,
|
|
15
|
-
secondary: '',
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
it('shows the avatar when supplied', () => {
|
|
19
|
-
expect(
|
|
20
|
-
render(<Radio {...props} avatar={<Avatar type={AvatarType.INITIALS}>HD</Avatar>} />)
|
|
21
|
-
.container,
|
|
22
|
-
).toMatchSnapshot();
|
|
23
|
-
});
|
|
24
|
-
});
|
package/src/radio/Radio.spec.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { shallow } from 'enzyme';
|
|
2
|
-
|
|
3
|
-
import Body from '../body';
|
|
4
|
-
import RadioButton from '../common/RadioButton';
|
|
5
|
-
|
|
6
|
-
import Radio from '.';
|
|
7
|
-
|
|
8
|
-
jest.mock('../common/hooks');
|
|
9
|
-
|
|
10
|
-
describe('Radio', () => {
|
|
11
|
-
let props;
|
|
12
|
-
let component;
|
|
13
|
-
|
|
14
|
-
beforeEach(() => {
|
|
15
|
-
props = {
|
|
16
|
-
label: 'hello, i am a radio',
|
|
17
|
-
name: 'radio name',
|
|
18
|
-
onChange: jest.fn(),
|
|
19
|
-
checked: false,
|
|
20
|
-
disabled: false,
|
|
21
|
-
secondary: '',
|
|
22
|
-
};
|
|
23
|
-
component = shallow(<Radio {...props} />);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('displays the given label', () => {
|
|
27
|
-
expect(component.find(Body).props().children).toContain(props.label);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('does not render secondary text', () => {
|
|
31
|
-
expect(component.find('small')).toHaveLength(0);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('has id as label for prop', () => {
|
|
35
|
-
component.setProps({ id: 'some-id' });
|
|
36
|
-
expect(component.find('label').prop('htmlFor')).toBe('some-id');
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('passes radio button id', () => {
|
|
40
|
-
component.setProps({ id: 'some-id' });
|
|
41
|
-
expect(radioButton().prop('id')).toBe('some-id');
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('passes radio button name', () => {
|
|
45
|
-
component.setProps({ name: 'a-name' });
|
|
46
|
-
expect(radioButton().prop('name')).toBe('a-name');
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('passes radio button checked', () => {
|
|
50
|
-
expect(radioButton().prop('checked')).toBe(false);
|
|
51
|
-
component.setProps({ checked: true });
|
|
52
|
-
expect(radioButton().prop('checked')).toBe(true);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('passes radio button change handler', () => {
|
|
56
|
-
const onChange = jest.fn();
|
|
57
|
-
component.setProps({ onChange });
|
|
58
|
-
expect(radioButton().prop('onChange')).toBe(onChange);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('passes radio button disabled', () => {
|
|
62
|
-
expect(radioButton().prop('disabled')).toBe(false);
|
|
63
|
-
component.setProps({ disabled: true });
|
|
64
|
-
expect(radioButton().prop('disabled')).toBe(true);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('displays secondary text when supplied', () => {
|
|
68
|
-
component.setProps({ secondary: 'additional info' });
|
|
69
|
-
expect(component.find(Body).last().props().children).toContain('additional info');
|
|
70
|
-
expect(component.find('.radio').hasClass('radio-lg')).toBe(true);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
function radioButton() {
|
|
74
|
-
return component.find(RadioButton);
|
|
75
|
-
}
|
|
76
|
-
});
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`Radio shows the avatar when supplied 1`] = `
|
|
4
|
-
<div>
|
|
5
|
-
<div
|
|
6
|
-
class="radio np-radio"
|
|
7
|
-
>
|
|
8
|
-
<label
|
|
9
|
-
class=""
|
|
10
|
-
>
|
|
11
|
-
<span
|
|
12
|
-
class="m-r-2 np-radio-button"
|
|
13
|
-
>
|
|
14
|
-
<input
|
|
15
|
-
class="sr-only"
|
|
16
|
-
name="name"
|
|
17
|
-
type="radio"
|
|
18
|
-
value=""
|
|
19
|
-
/>
|
|
20
|
-
<span
|
|
21
|
-
class="tw-radio-button"
|
|
22
|
-
>
|
|
23
|
-
<span
|
|
24
|
-
class="tw-radio-check"
|
|
25
|
-
/>
|
|
26
|
-
</span>
|
|
27
|
-
</span>
|
|
28
|
-
<span
|
|
29
|
-
class="np-text-body-large np-radio__text"
|
|
30
|
-
>
|
|
31
|
-
This is a label
|
|
32
|
-
</span>
|
|
33
|
-
<span
|
|
34
|
-
class="np-radio__avatar m-l-auto"
|
|
35
|
-
>
|
|
36
|
-
<div
|
|
37
|
-
class="tw-avatar tw-avatar--48 tw-avatar--initials np-text-title-body"
|
|
38
|
-
>
|
|
39
|
-
<div
|
|
40
|
-
class="tw-avatar__content"
|
|
41
|
-
>
|
|
42
|
-
HD
|
|
43
|
-
</div>
|
|
44
|
-
</div>
|
|
45
|
-
</span>
|
|
46
|
-
</label>
|
|
47
|
-
</div>
|
|
48
|
-
</div>
|
|
49
|
-
`;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { render, screen } from '../test-utils';
|
|
2
|
-
|
|
3
|
-
import RadioGroup from '.';
|
|
4
|
-
import { Field } from '../field/Field';
|
|
5
|
-
|
|
6
|
-
describe('RadioGroup', () => {
|
|
7
|
-
it('has accessible role', () => {
|
|
8
|
-
render(
|
|
9
|
-
<RadioGroup
|
|
10
|
-
name="currency"
|
|
11
|
-
radios={[{ label: 'USD' }, { label: 'EUR' }]}
|
|
12
|
-
onChange={() => {}}
|
|
13
|
-
/>,
|
|
14
|
-
);
|
|
15
|
-
expect(screen.getByRole('radiogroup')).toBeInTheDocument();
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it('supports `Field` for labeling', () => {
|
|
19
|
-
render(
|
|
20
|
-
<Field label="Currency">
|
|
21
|
-
<RadioGroup
|
|
22
|
-
name="currency"
|
|
23
|
-
radios={[{ label: 'USD' }, { label: 'EUR' }]}
|
|
24
|
-
onChange={() => {}}
|
|
25
|
-
/>
|
|
26
|
-
</Field>,
|
|
27
|
-
);
|
|
28
|
-
expect(screen.getByRole('radiogroup')).toHaveAccessibleName(/^Currency/);
|
|
29
|
-
});
|
|
30
|
-
});
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
|
-
import { shallow } from 'enzyme';
|
|
3
|
-
|
|
4
|
-
import { Radio, RadioGroup } from '..';
|
|
5
|
-
import Avatar, { AvatarType } from '../avatar';
|
|
6
|
-
|
|
7
|
-
const props = { onChange: jest.fn(), name: 'radio-group' };
|
|
8
|
-
const avatar = <Avatar type={AvatarType.INITIALS}>HD</Avatar>;
|
|
9
|
-
|
|
10
|
-
const RADIOS = [
|
|
11
|
-
{
|
|
12
|
-
id: 'id-test-0',
|
|
13
|
-
value: 'value-test0',
|
|
14
|
-
label: 'Radio1',
|
|
15
|
-
secondary: 'secondary',
|
|
16
|
-
disabled: true,
|
|
17
|
-
avatar,
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
id: 'id-test-1',
|
|
21
|
-
value: 'value-test1',
|
|
22
|
-
label: 'Radio2',
|
|
23
|
-
secondary: 'secondary',
|
|
24
|
-
disabled: false,
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
id: 'id-test-2',
|
|
28
|
-
value: 'value-test2',
|
|
29
|
-
label: 'Radio3',
|
|
30
|
-
secondary: 'secondary',
|
|
31
|
-
disabled: false,
|
|
32
|
-
},
|
|
33
|
-
];
|
|
34
|
-
|
|
35
|
-
describe('RadioGroup', () => {
|
|
36
|
-
it('renders null if no radios are provided', () => {
|
|
37
|
-
expect(shallow(<RadioGroup radios={[]} {...props} />).isEmptyRender()).toBe(true);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('renders radio options', () => {
|
|
41
|
-
const component = shallow(<RadioGroup radios={RADIOS} {...props} />);
|
|
42
|
-
expect(component.find(Radio)).toHaveLength(RADIOS.length);
|
|
43
|
-
|
|
44
|
-
const { onChange, ...primitiveProps } = component.find(Radio).at(0).props();
|
|
45
|
-
expect(primitiveProps).toStrictEqual({
|
|
46
|
-
id: 'id-test-0',
|
|
47
|
-
value: 'value-test0',
|
|
48
|
-
label: 'Radio1',
|
|
49
|
-
name: 'radio-group',
|
|
50
|
-
disabled: true,
|
|
51
|
-
checked: false,
|
|
52
|
-
secondary: 'secondary',
|
|
53
|
-
avatar,
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('renders a single radio option, when radios array contains a single element', () => {
|
|
58
|
-
const component = shallow(<RadioGroup radios={RADIOS.slice(0, 1)} {...props} />);
|
|
59
|
-
expect(component.find(Radio)).toHaveLength(1);
|
|
60
|
-
|
|
61
|
-
const { onChange, ...primitiveProps } = component.find(Radio).at(0).props();
|
|
62
|
-
expect(primitiveProps).toStrictEqual({
|
|
63
|
-
id: 'id-test-0',
|
|
64
|
-
value: 'value-test0',
|
|
65
|
-
label: 'Radio1',
|
|
66
|
-
name: 'radio-group',
|
|
67
|
-
disabled: true,
|
|
68
|
-
checked: false,
|
|
69
|
-
secondary: 'secondary',
|
|
70
|
-
avatar,
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it('checks specified radio', () => {
|
|
75
|
-
const component = shallow(
|
|
76
|
-
<RadioGroup radios={RADIOS} selectedValue="value-test2" {...props} />,
|
|
77
|
-
);
|
|
78
|
-
expect(component.find(Radio)).toHaveLength(RADIOS.length);
|
|
79
|
-
expect(component.find(Radio).at(2).props().checked).toBeTruthy();
|
|
80
|
-
|
|
81
|
-
expect(component.find(Radio).at(0).props().checked).toBeFalsy();
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('calls onChange with selected value', () => {
|
|
85
|
-
const component = shallow(<RadioGroup radios={RADIOS} {...props} />);
|
|
86
|
-
component.find(Radio).at(2).simulate('change', 'value-test2');
|
|
87
|
-
|
|
88
|
-
expect(props.onChange).toHaveBeenCalledWith('value-test2');
|
|
89
|
-
});
|
|
90
|
-
});
|