@onewelcome/react-lib-components 0.1.0-alpha
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/LICENSE +21 -0
- package/README.md +71 -0
- package/dist/BaseModal/BaseModal.d.ts +16 -0
- package/dist/BaseModal/BaseModalActions/BaseModalActions.d.ts +5 -0
- package/dist/BaseModal/BaseModalContent/BaseModalContent.d.ts +8 -0
- package/dist/BaseModal/BaseModalContext.d.ts +2 -0
- package/dist/BaseModal/BaseModalHeader/BaseModalHeader.d.ts +8 -0
- package/dist/Breadcrumbs/Breadcrumbs.d.ts +9 -0
- package/dist/Button/BaseButton.d.ts +8 -0
- package/dist/Button/Button.d.ts +10 -0
- package/dist/Button/IconButton.d.ts +10 -0
- package/dist/ContextMenu/ContextMenu.d.ts +18 -0
- package/dist/ContextMenu/ContextMenuItem.d.ts +6 -0
- package/dist/Dialog/Dialog.d.ts +18 -0
- package/dist/Dialog/DialogActions/DialogActions.d.ts +6 -0
- package/dist/Dialog/DialogTitle/DialogTitle.d.ts +6 -0
- package/dist/Form/Checkbox/Checkbox.d.ts +13 -0
- package/dist/Form/Fieldset/Fieldset.d.ts +13 -0
- package/dist/Form/Form.d.ts +5 -0
- package/dist/Form/FormControl/FormControl.d.ts +8 -0
- package/dist/Form/FormGroup/FormGroup.d.ts +18 -0
- package/dist/Form/FormHelperText/FormHelperText.d.ts +7 -0
- package/dist/Form/FormSelectorWrapper/FormSelectorWrapper.d.ts +18 -0
- package/dist/Form/Input/Input.d.ts +12 -0
- package/dist/Form/Label/Label.d.ts +6 -0
- package/dist/Form/Radio/Radio.d.ts +11 -0
- package/dist/Form/Select/Option.d.ts +12 -0
- package/dist/Form/Select/Select.d.ts +15 -0
- package/dist/Form/Textarea/Textarea.d.ts +7 -0
- package/dist/Form/Toggle/Toggle.d.ts +6 -0
- package/dist/Form/Wrapper/CheckboxWrapper/CheckboxWrapper.d.ts +8 -0
- package/dist/Form/Wrapper/InputWrapper/InputWrapper.d.ts +17 -0
- package/dist/Form/Wrapper/RadioWrapper/RadioWrapper.d.ts +10 -0
- package/dist/Form/Wrapper/SelectWrapper/SelectWrapper.d.ts +12 -0
- package/dist/Form/Wrapper/TextareaWrapper/TextareaWrapper.d.ts +14 -0
- package/dist/Form/Wrapper/Wrapper/Wrapper.d.ts +28 -0
- package/dist/Form/form.interfaces.d.ts +12 -0
- package/dist/Icon/Icon.d.ts +75 -0
- package/dist/Link/Link.d.ts +15 -0
- package/dist/Modal/Modal.d.ts +1 -0
- package/dist/Modal/ModalActions/ModalActions.d.ts +1 -0
- package/dist/Modal/ModalContent/ModalContent.d.ts +1 -0
- package/dist/Modal/ModalHeader/ModalHeader.d.ts +1 -0
- package/dist/Popover/Popover.d.ts +11 -0
- package/dist/Snackbar/SnackbarContainer/SnackbarContainer.d.ts +12 -0
- package/dist/Snackbar/SnackbarItem/SnackbarItem.d.ts +13 -0
- package/dist/Snackbar/SnackbarProvider/SnackbarProvider.d.ts +18 -0
- package/dist/Snackbar/SnackbarProvider/SnackbarStateProvider.d.ts +14 -0
- package/dist/Snackbar/interfaces.d.ts +10 -0
- package/dist/Snackbar/useSnackbar.d.ts +1 -0
- package/dist/Tiles/Tile.d.ts +16 -0
- package/dist/Tiles/Tiles.d.ts +6 -0
- package/dist/Tooltip/Tooltip.d.ts +11 -0
- package/dist/Typography/Typography.d.ts +12 -0
- package/dist/Wizard/BaseWizardSteps/BaseWizardSteps.d.ts +13 -0
- package/dist/Wizard/Wizard.d.ts +12 -0
- package/dist/Wizard/WizardActions/WizardActions.d.ts +12 -0
- package/dist/Wizard/WizardStateProvider.d.ts +12 -0
- package/dist/Wizard/WizardSteps/WizardSteps.d.ts +5 -0
- package/dist/Wizard/wizardStateReducer.d.ts +26 -0
- package/dist/_BaseStyling_/BaseStyling.d.ts +47 -0
- package/dist/hooks/useAnimation.d.ts +6 -0
- package/dist/hooks/useBodyClick.d.ts +1 -0
- package/dist/hooks/useFormSelector.d.ts +13 -0
- package/dist/hooks/usePosition.d.ts +36 -0
- package/dist/hooks/useScroll.d.ts +2 -0
- package/dist/hooks/useSpacing.d.ts +18 -0
- package/dist/hooks/useWrapper.d.ts +11 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.js +8 -0
- package/dist/interfaces.d.ts +13 -0
- package/dist/react-lib-components.cjs.development.js +3282 -0
- package/dist/react-lib-components.cjs.development.js.map +1 -0
- package/dist/react-lib-components.cjs.production.min.js +2 -0
- package/dist/react-lib-components.cjs.production.min.js.map +1 -0
- package/dist/react-lib-components.esm.js +3235 -0
- package/dist/react-lib-components.esm.js.map +1 -0
- package/dist/util/helper.d.ts +1 -0
- package/package.json +88 -0
- package/src/BaseModal/BaseModal.module.scss +58 -0
- package/src/BaseModal/BaseModal.test.tsx +59 -0
- package/src/BaseModal/BaseModal.tsx +113 -0
- package/src/BaseModal/BaseModalActions/BaseModalActions.module.scss +9 -0
- package/src/BaseModal/BaseModalActions/BaseModalActions.test.tsx +17 -0
- package/src/BaseModal/BaseModalActions/BaseModalActions.tsx +14 -0
- package/src/BaseModal/BaseModalContent/BaseModalContent.module.scss +6 -0
- package/src/BaseModal/BaseModalContent/BaseModalContent.test.tsx +29 -0
- package/src/BaseModal/BaseModalContent/BaseModalContent.tsx +35 -0
- package/src/BaseModal/BaseModalContext.ts +2 -0
- package/src/BaseModal/BaseModalHeader/BaseModalHeader.module.scss +17 -0
- package/src/BaseModal/BaseModalHeader/BaseModalHeader.test.tsx +30 -0
- package/src/BaseModal/BaseModalHeader/BaseModalHeader.tsx +28 -0
- package/src/Breadcrumbs/Breadcrumbs.module.scss +14 -0
- package/src/Breadcrumbs/Breadcrumbs.test.tsx +42 -0
- package/src/Breadcrumbs/Breadcrumbs.tsx +48 -0
- package/src/Button/BaseButton.module.scss +20 -0
- package/src/Button/BaseButton.test.tsx +59 -0
- package/src/Button/BaseButton.tsx +31 -0
- package/src/Button/Button.module.scss +336 -0
- package/src/Button/Button.test.tsx +76 -0
- package/src/Button/Button.tsx +44 -0
- package/src/Button/IconButton.module.scss +161 -0
- package/src/Button/IconButton.test.tsx +47 -0
- package/src/Button/IconButton.tsx +29 -0
- package/src/ContextMenu/ContextMenu.module.scss +20 -0
- package/src/ContextMenu/ContextMenu.test.tsx +93 -0
- package/src/ContextMenu/ContextMenu.tsx +91 -0
- package/src/ContextMenu/ContextMenuItem.module.scss +31 -0
- package/src/ContextMenu/ContextMenuItem.tsx +15 -0
- package/src/Dialog/Dialog.module.scss +16 -0
- package/src/Dialog/Dialog.test.tsx +79 -0
- package/src/Dialog/Dialog.tsx +96 -0
- package/src/Dialog/DialogActions/DialogActions.module.scss +11 -0
- package/src/Dialog/DialogActions/DialogActions.test.tsx +25 -0
- package/src/Dialog/DialogActions/DialogActions.tsx +21 -0
- package/src/Dialog/DialogTitle/DialogTitle.module.scss +7 -0
- package/src/Dialog/DialogTitle/DialogTitle.test.tsx +18 -0
- package/src/Dialog/DialogTitle/DialogTitle.tsx +18 -0
- package/src/Form/Checkbox/Checkbox.module.scss +65 -0
- package/src/Form/Checkbox/Checkbox.test.tsx +119 -0
- package/src/Form/Checkbox/Checkbox.tsx +145 -0
- package/src/Form/Fieldset/Fieldset.module.scss +19 -0
- package/src/Form/Fieldset/Fieldset.test.tsx +85 -0
- package/src/Form/Fieldset/Fieldset.tsx +55 -0
- package/src/Form/Form.module.scss +3 -0
- package/src/Form/Form.test.tsx +47 -0
- package/src/Form/Form.tsx +14 -0
- package/src/Form/FormControl/FormControl.module.scss +67 -0
- package/src/Form/FormControl/FormControl.test.tsx +56 -0
- package/src/Form/FormControl/FormControl.tsx +47 -0
- package/src/Form/FormGroup/FormGroup.module.scss +29 -0
- package/src/Form/FormGroup/FormGroup.test.tsx +61 -0
- package/src/Form/FormGroup/FormGroup.tsx +78 -0
- package/src/Form/FormHelperText/FormHelperText.module.scss +8 -0
- package/src/Form/FormHelperText/FormHelperText.test.tsx +42 -0
- package/src/Form/FormHelperText/FormHelperText.tsx +22 -0
- package/src/Form/FormSelectorWrapper/FormSelectorWrapper.module.scss +33 -0
- package/src/Form/FormSelectorWrapper/FormSelectorWrapper.tsx +65 -0
- package/src/Form/Input/Input.module.scss +65 -0
- package/src/Form/Input/Input.test.tsx +135 -0
- package/src/Form/Input/Input.tsx +72 -0
- package/src/Form/Label/Label.module.scss +5 -0
- package/src/Form/Label/Label.test.tsx +26 -0
- package/src/Form/Label/Label.tsx +19 -0
- package/src/Form/Radio/Radio.module.scss +100 -0
- package/src/Form/Radio/Radio.test.tsx +88 -0
- package/src/Form/Radio/Radio.tsx +98 -0
- package/src/Form/Select/Option.test.tsx +15 -0
- package/src/Form/Select/Option.tsx +57 -0
- package/src/Form/Select/Select.module.scss +189 -0
- package/src/Form/Select/Select.test.tsx +96 -0
- package/src/Form/Select/Select.tsx +217 -0
- package/src/Form/Textarea/Textarea.module.scss +53 -0
- package/src/Form/Textarea/Textarea.test.tsx +76 -0
- package/src/Form/Textarea/Textarea.tsx +33 -0
- package/src/Form/Toggle/Toggle.module.scss +58 -0
- package/src/Form/Toggle/Toggle.test.tsx +29 -0
- package/src/Form/Toggle/Toggle.tsx +20 -0
- package/src/Form/Wrapper/CheckboxWrapper/CheckboxWrapper.module.scss +12 -0
- package/src/Form/Wrapper/CheckboxWrapper/CheckboxWrapper.test.tsx +99 -0
- package/src/Form/Wrapper/CheckboxWrapper/CheckboxWrapper.tsx +62 -0
- package/src/Form/Wrapper/InputWrapper/InputWrapper.module.scss +24 -0
- package/src/Form/Wrapper/InputWrapper/InputWrapper.test.tsx +93 -0
- package/src/Form/Wrapper/InputWrapper/InputWrapper.tsx +92 -0
- package/src/Form/Wrapper/RadioWrapper/RadioWrapper.module.scss +12 -0
- package/src/Form/Wrapper/RadioWrapper/RadioWrapper.test.tsx +101 -0
- package/src/Form/Wrapper/RadioWrapper/RadioWrapper.tsx +74 -0
- package/src/Form/Wrapper/SelectWrapper/SelectWrapper.module.scss +14 -0
- package/src/Form/Wrapper/SelectWrapper/SelectWrapper.test.tsx +101 -0
- package/src/Form/Wrapper/SelectWrapper/SelectWrapper.tsx +59 -0
- package/src/Form/Wrapper/TextareaWrapper/TextareaWrapper.module.scss +65 -0
- package/src/Form/Wrapper/TextareaWrapper/TextareaWrapper.test.tsx +125 -0
- package/src/Form/Wrapper/TextareaWrapper/TextareaWrapper.tsx +105 -0
- package/src/Form/Wrapper/Wrapper/Wrapper.module.scss +35 -0
- package/src/Form/Wrapper/Wrapper/Wrapper.test.tsx +17 -0
- package/src/Form/Wrapper/Wrapper/Wrapper.tsx +101 -0
- package/src/Form/form.interfaces.ts +14 -0
- package/src/Icon/Icon.module.scss +278 -0
- package/src/Icon/Icon.test.tsx +39 -0
- package/src/Icon/Icon.tsx +94 -0
- package/src/Link/Link.module.scss +46 -0
- package/src/Link/Link.test.tsx +122 -0
- package/src/Link/Link.tsx +80 -0
- package/src/Link/types.d.ts +9 -0
- package/src/Modal/Modal.test.tsx +16 -0
- package/src/Modal/Modal.tsx +1 -0
- package/src/Modal/ModalActions/ModalActions.tsx +4 -0
- package/src/Modal/ModalContent/ModalContent.tsx +4 -0
- package/src/Modal/ModalHeader/ModalHeader.tsx +4 -0
- package/src/Popover/Popover.module.scss +18 -0
- package/src/Popover/Popover.test.tsx +84 -0
- package/src/Popover/Popover.tsx +46 -0
- package/src/Snackbar/SnackbarContainer/SnackbarContainer.module.scss +35 -0
- package/src/Snackbar/SnackbarContainer/SnackbarContainer.test.tsx +37 -0
- package/src/Snackbar/SnackbarContainer/SnackbarContainer.tsx +28 -0
- package/src/Snackbar/SnackbarItem/SnackbarItem.module.scss +135 -0
- package/src/Snackbar/SnackbarItem/SnackbarItem.test.tsx +47 -0
- package/src/Snackbar/SnackbarItem/SnackbarItem.tsx +105 -0
- package/src/Snackbar/SnackbarProvider/SnackbarProvider.test.tsx +179 -0
- package/src/Snackbar/SnackbarProvider/SnackbarProvider.tsx +127 -0
- package/src/Snackbar/SnackbarProvider/SnackbarStateProvider.tsx +25 -0
- package/src/Snackbar/interfaces.ts +11 -0
- package/src/Snackbar/useSnackbar.ts +4 -0
- package/src/Tiles/Tile.module.scss +72 -0
- package/src/Tiles/Tile.test.tsx +129 -0
- package/src/Tiles/Tile.tsx +48 -0
- package/src/Tiles/Tiles.module.scss +11 -0
- package/src/Tiles/Tiles.test.tsx +118 -0
- package/src/Tiles/Tiles.tsx +48 -0
- package/src/Tooltip/Tooltip.module.scss +42 -0
- package/src/Tooltip/Tooltip.test.tsx +72 -0
- package/src/Tooltip/Tooltip.tsx +130 -0
- package/src/Typography/Typography.module.scss +46 -0
- package/src/Typography/Typography.test.tsx +114 -0
- package/src/Typography/Typography.tsx +84 -0
- package/src/Wizard/BaseWizardSteps/BaseWizardSteps.module.scss +192 -0
- package/src/Wizard/BaseWizardSteps/BaseWizardSteps.test.tsx +75 -0
- package/src/Wizard/BaseWizardSteps/BaseWizardSteps.tsx +86 -0
- package/src/Wizard/Wizard.test.tsx +198 -0
- package/src/Wizard/Wizard.tsx +49 -0
- package/src/Wizard/WizardActions/WizardActions.test.tsx +168 -0
- package/src/Wizard/WizardActions/WizardActions.tsx +100 -0
- package/src/Wizard/WizardStateProvider.tsx +26 -0
- package/src/Wizard/WizardSteps/WizardSteps.test.tsx +110 -0
- package/src/Wizard/WizardSteps/WizardSteps.tsx +30 -0
- package/src/Wizard/wizardStateReducer.ts +51 -0
- package/src/_BaseStyling_/BaseStyling.test.tsx +39 -0
- package/src/_BaseStyling_/BaseStyling.tsx +115 -0
- package/src/hooks/useAnimation.test.tsx +45 -0
- package/src/hooks/useAnimation.ts +20 -0
- package/src/hooks/useBodyClick.test.tsx +39 -0
- package/src/hooks/useBodyClick.ts +20 -0
- package/src/hooks/useFormSelector.test.ts +40 -0
- package/src/hooks/useFormSelector.ts +47 -0
- package/src/hooks/usePosition.test.tsx +494 -0
- package/src/hooks/usePosition.ts +347 -0
- package/src/hooks/useScroll.test.tsx +20 -0
- package/src/hooks/useScroll.ts +16 -0
- package/src/hooks/useSpacing.test.ts +70 -0
- package/src/hooks/useSpacing.ts +42 -0
- package/src/hooks/useWrapper.test.ts +49 -0
- package/src/hooks/useWrapper.ts +35 -0
- package/src/index.ts +52 -0
- package/src/interfaces.ts +15 -0
- package/src/readyclasses.module.scss +77 -0
- package/src/types.d.ts +4 -0
- package/src/util/helper.test.tsx +15 -0
- package/src/util/helper.tsx +80 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import React, { ReactElement } from 'react';
|
|
2
|
+
import classes from './FormControl.module.scss';
|
|
3
|
+
import { HTMLProps } from '../../interfaces';
|
|
4
|
+
|
|
5
|
+
export interface Props extends HTMLProps<HTMLDivElement> {
|
|
6
|
+
children: ReactElement | ReactElement[];
|
|
7
|
+
grid?: 1 | 2 | 3;
|
|
8
|
+
align?: 'top' | 'start' | 'middle' | 'center' | 'bottom' | 'end' | 'stretch';
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const FormControl = ({
|
|
12
|
+
children,
|
|
13
|
+
disabled,
|
|
14
|
+
className,
|
|
15
|
+
grid,
|
|
16
|
+
align = 'center',
|
|
17
|
+
...rest
|
|
18
|
+
}: Props) => {
|
|
19
|
+
const renderChildren = () =>
|
|
20
|
+
React.Children.map(children, (child) => {
|
|
21
|
+
if (!child) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const childElement = React.cloneElement(child, {
|
|
26
|
+
disabled: child.props.disabled !== undefined ? child.props.disabled : disabled,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
if (grid && grid > 1) {
|
|
30
|
+
return <div className={`${classes['col-' + grid]} ${classes.column}`}>{childElement}</div>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return childElement;
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<div
|
|
38
|
+
{...rest}
|
|
39
|
+
data-formcontrol
|
|
40
|
+
className={`${classes['form-control']} ${className ? className : ''} ${
|
|
41
|
+
grid && grid > 1 ? `${classes.grid} ${classes['grid-' + grid]}` : ''
|
|
42
|
+
} ${classes[align]}`}
|
|
43
|
+
>
|
|
44
|
+
{renderChildren()}
|
|
45
|
+
</div>
|
|
46
|
+
);
|
|
47
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
.form-group {
|
|
2
|
+
position: relative;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.error {
|
|
6
|
+
color: var(--error);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.error-message {
|
|
10
|
+
display: flex;
|
|
11
|
+
align-items: flex-end;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.error-icon {
|
|
15
|
+
margin-right: 0.5rem;
|
|
16
|
+
font-size: 1.25rem;
|
|
17
|
+
|
|
18
|
+
&-before {
|
|
19
|
+
margin-right: 0.5rem;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
&-after {
|
|
23
|
+
margin-left: 0.5rem;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.default-helper {
|
|
28
|
+
font-size: 0.75rem;
|
|
29
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { FormGroup, Props } from './FormGroup';
|
|
3
|
+
import { render } from '@testing-library/react';
|
|
4
|
+
|
|
5
|
+
const defaultParams: Props = {
|
|
6
|
+
children: 'Formcontent here',
|
|
7
|
+
helperId: 'helper_id',
|
|
8
|
+
helperText: 'example helper text',
|
|
9
|
+
errorMessage: 'example error message',
|
|
10
|
+
errorId: 'error_id',
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const createFormGroup = (params?: (defaultParams: Props) => Props) => {
|
|
14
|
+
let parameters: Props = defaultParams;
|
|
15
|
+
if (params) {
|
|
16
|
+
parameters = params(defaultParams);
|
|
17
|
+
}
|
|
18
|
+
const queries = render(<FormGroup {...parameters} data-testid="formgroup"></FormGroup>);
|
|
19
|
+
const formgroup = queries.getByTestId('formgroup');
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
...queries,
|
|
23
|
+
formgroup,
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
describe('FormSelectorGroup should render', () => {
|
|
28
|
+
it('renders without crashing', () => {
|
|
29
|
+
const { formgroup } = createFormGroup();
|
|
30
|
+
|
|
31
|
+
expect(formgroup).toBeDefined();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('has the correct values and attributes', () => {
|
|
35
|
+
const { getByTestId } = createFormGroup((defaultParams) => ({
|
|
36
|
+
...defaultParams,
|
|
37
|
+
helperProps: { 'data-testid': 'helper_text' },
|
|
38
|
+
}));
|
|
39
|
+
|
|
40
|
+
const helperText = getByTestId('helper_text');
|
|
41
|
+
|
|
42
|
+
expect(helperText).toHaveAttribute('id', 'helper_id');
|
|
43
|
+
expect(helperText).toHaveTextContent('example helper text');
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe('Correct error state', () => {
|
|
48
|
+
it('has the correct state', () => {
|
|
49
|
+
const { formgroup } = createFormGroup((defaultParams) => ({
|
|
50
|
+
...defaultParams,
|
|
51
|
+
error: true,
|
|
52
|
+
errorMessage: 'example error message',
|
|
53
|
+
errorId: 'error_id',
|
|
54
|
+
}));
|
|
55
|
+
const errorMessage = formgroup.querySelector('.error-message');
|
|
56
|
+
|
|
57
|
+
expect(errorMessage).toBeTruthy();
|
|
58
|
+
expect(errorMessage?.querySelector('#error_id')).toBeTruthy();
|
|
59
|
+
expect(errorMessage?.querySelector('#error_id')).toHaveTextContent('example error message');
|
|
60
|
+
});
|
|
61
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/** The empty className property on FormHelperText is on purpose! We want to basically "filter" out the className from helperProps because we're adding this to the surrounding div. This makes it so also the errormessage receives this styling. */
|
|
2
|
+
|
|
3
|
+
import React, { ReactChild } from 'react';
|
|
4
|
+
import classes from './FormGroup.module.scss';
|
|
5
|
+
import { FormHelperText, Props as HelperProps } from '../FormHelperText/FormHelperText';
|
|
6
|
+
import { Icon, Icons } from '../../Icon/Icon';
|
|
7
|
+
import { HTMLProps } from '../../interfaces';
|
|
8
|
+
|
|
9
|
+
export interface Props extends HTMLProps<HTMLDivElement> {
|
|
10
|
+
children: ReactChild[] | ReactChild;
|
|
11
|
+
error?: boolean;
|
|
12
|
+
errorMessageIcon?: Icons;
|
|
13
|
+
errorMessageIconPosition?: 'before' | 'after';
|
|
14
|
+
errorMessage?: string;
|
|
15
|
+
errorId?: string;
|
|
16
|
+
helperIndent?: number;
|
|
17
|
+
helperText?: string;
|
|
18
|
+
helperId?: string;
|
|
19
|
+
helperProps?: HelperProps;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const FormGroup = ({
|
|
23
|
+
children,
|
|
24
|
+
className,
|
|
25
|
+
error,
|
|
26
|
+
errorMessage,
|
|
27
|
+
errorId,
|
|
28
|
+
errorMessageIcon,
|
|
29
|
+
errorMessageIconPosition = 'before',
|
|
30
|
+
helperText,
|
|
31
|
+
helperId,
|
|
32
|
+
helperProps,
|
|
33
|
+
helperIndent,
|
|
34
|
+
...rest
|
|
35
|
+
}: Props) => {
|
|
36
|
+
return (
|
|
37
|
+
<div
|
|
38
|
+
{...rest}
|
|
39
|
+
className={`${classes['form-group']} ${error ? classes.error : ''} ${className ?? ''}`}
|
|
40
|
+
>
|
|
41
|
+
{children}
|
|
42
|
+
|
|
43
|
+
{(helperText || errorMessage) && (
|
|
44
|
+
<div
|
|
45
|
+
style={{ marginLeft: `${helperIndent}px` }}
|
|
46
|
+
className={`${classes['default-helper']} ${
|
|
47
|
+
helperProps?.className ? helperProps.className : ''
|
|
48
|
+
}`}
|
|
49
|
+
>
|
|
50
|
+
{helperText && !error && (
|
|
51
|
+
<FormHelperText {...helperProps} className={''} id={helperId}>
|
|
52
|
+
{helperText}
|
|
53
|
+
</FormHelperText>
|
|
54
|
+
)}
|
|
55
|
+
{error && errorMessage && (
|
|
56
|
+
<span className={classes['error-message']}>
|
|
57
|
+
<span className={classes.message} id={errorId}>
|
|
58
|
+
{errorMessageIcon && errorMessageIconPosition === 'before' && (
|
|
59
|
+
<Icon
|
|
60
|
+
className={`${classes['error-icon']} ${classes['error-icon-before']}`}
|
|
61
|
+
icon={errorMessageIcon}
|
|
62
|
+
/>
|
|
63
|
+
)}
|
|
64
|
+
{errorMessage}
|
|
65
|
+
{errorMessageIcon && errorMessageIconPosition === 'after' && (
|
|
66
|
+
<Icon
|
|
67
|
+
className={`${classes['error-icon']} ${classes['error-icon-after']}`}
|
|
68
|
+
icon={errorMessageIcon}
|
|
69
|
+
/>
|
|
70
|
+
)}
|
|
71
|
+
</span>
|
|
72
|
+
</span>
|
|
73
|
+
)}
|
|
74
|
+
</div>
|
|
75
|
+
)}
|
|
76
|
+
</div>
|
|
77
|
+
);
|
|
78
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { FormHelperText, Props } from './FormHelperText';
|
|
3
|
+
import { render } from '@testing-library/react';
|
|
4
|
+
|
|
5
|
+
const defaultParams: Props = {
|
|
6
|
+
error: false,
|
|
7
|
+
children: 'This is a field description',
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const createFormHelperText = (params?: (defaultParams: Props) => Props) => {
|
|
11
|
+
let parameters: Props = defaultParams;
|
|
12
|
+
if (params) {
|
|
13
|
+
parameters = params(defaultParams);
|
|
14
|
+
}
|
|
15
|
+
const queries = render(<FormHelperText {...parameters} data-testid="formhelpertext" />);
|
|
16
|
+
const formhelpertext = queries.getByTestId('formhelpertext');
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
...queries,
|
|
20
|
+
formhelpertext,
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
describe('FormHelperText should render', () => {
|
|
25
|
+
it('renders without crashing', () => {
|
|
26
|
+
const { formhelpertext } = createFormHelperText();
|
|
27
|
+
|
|
28
|
+
expect(formhelpertext).toBeTruthy();
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe('Attributes', () => {
|
|
33
|
+
it('contains the error class', () => {
|
|
34
|
+
const { formhelpertext } = createFormHelperText((defaultParams) => ({
|
|
35
|
+
...defaultParams,
|
|
36
|
+
error: true,
|
|
37
|
+
}));
|
|
38
|
+
|
|
39
|
+
expect(formhelpertext).toHaveClass('error');
|
|
40
|
+
expect(formhelpertext).toHaveStyle({ color: 'rgb(226, 42, 29);' });
|
|
41
|
+
});
|
|
42
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
import classes from './FormHelperText.module.scss';
|
|
3
|
+
import { HTMLProps } from '../../interfaces';
|
|
4
|
+
import { Typography } from '../../Typography/Typography';
|
|
5
|
+
|
|
6
|
+
export interface Props extends HTMLProps<HTMLDivElement> {
|
|
7
|
+
children?: ReactNode;
|
|
8
|
+
error?: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const FormHelperText = ({ children, error, className, ...rest }: Props) => {
|
|
12
|
+
return (
|
|
13
|
+
<Typography
|
|
14
|
+
{...rest}
|
|
15
|
+
variant="sub-text"
|
|
16
|
+
tag="div"
|
|
17
|
+
className={`${classes['form-helper-text']} ${error ? classes.error : ''} ${className ?? ''}`}
|
|
18
|
+
>
|
|
19
|
+
{children}
|
|
20
|
+
</Typography>
|
|
21
|
+
);
|
|
22
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
.error {
|
|
2
|
+
color: var(--error);
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.helper-text {
|
|
6
|
+
margin-top: 0.25rem;
|
|
7
|
+
margin-left: 1.75rem;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.error-message {
|
|
11
|
+
margin-top: 1.25rem;
|
|
12
|
+
display: flex;
|
|
13
|
+
align-items: flex-end;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.error-icon {
|
|
17
|
+
margin-right: 0.5rem;
|
|
18
|
+
font-size: 1.25rem;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.disabled {
|
|
22
|
+
input {
|
|
23
|
+
color: var(--disabled);
|
|
24
|
+
|
|
25
|
+
&:disabled {
|
|
26
|
+
cursor: not-allowed;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
label {
|
|
31
|
+
cursor: not-allowed;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
import { Icon, Icons } from '../../Icon/Icon';
|
|
3
|
+
import { HTMLProps } from '../../interfaces';
|
|
4
|
+
import { FormHelperText, Props as FormHelperTextProps } from '../FormHelperText/FormHelperText';
|
|
5
|
+
import classes from './FormSelectorWrapper.module.scss';
|
|
6
|
+
|
|
7
|
+
export interface Props extends HTMLProps<HTMLDivElement> {
|
|
8
|
+
children?: ReactNode;
|
|
9
|
+
nestedChildren?: ReactNode;
|
|
10
|
+
containerProps: HTMLProps<HTMLDivElement>;
|
|
11
|
+
helperProps?: FormHelperTextProps;
|
|
12
|
+
error?: boolean;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
helperText?: string;
|
|
15
|
+
errorMessage?: string;
|
|
16
|
+
parentHelperId?: string;
|
|
17
|
+
parentErrorId?: string;
|
|
18
|
+
errorId: string;
|
|
19
|
+
identifier: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const FormSelectorWrapper = ({
|
|
23
|
+
children,
|
|
24
|
+
className,
|
|
25
|
+
nestedChildren,
|
|
26
|
+
containerProps,
|
|
27
|
+
helperProps,
|
|
28
|
+
error,
|
|
29
|
+
disabled,
|
|
30
|
+
helperText,
|
|
31
|
+
errorMessage,
|
|
32
|
+
parentErrorId,
|
|
33
|
+
errorId,
|
|
34
|
+
identifier,
|
|
35
|
+
...rest
|
|
36
|
+
}: Props) => {
|
|
37
|
+
return (
|
|
38
|
+
<div
|
|
39
|
+
{...rest}
|
|
40
|
+
className={`${error ? classes['error'] : ''} ${disabled ? classes['disabled'] : ''} ${
|
|
41
|
+
className ?? ''
|
|
42
|
+
}`}
|
|
43
|
+
>
|
|
44
|
+
<div {...containerProps}>{children}</div>
|
|
45
|
+
{helperText && (!error || parentErrorId || !errorMessage) && (
|
|
46
|
+
<FormHelperText
|
|
47
|
+
{...helperProps}
|
|
48
|
+
id={`${identifier}`}
|
|
49
|
+
className={`${classes['helper-text']} ${helperProps?.className ?? ''} ${
|
|
50
|
+
error ? classes['error'] : ''
|
|
51
|
+
}`}
|
|
52
|
+
>
|
|
53
|
+
{helperText}
|
|
54
|
+
</FormHelperText>
|
|
55
|
+
)}
|
|
56
|
+
{errorMessage && !parentErrorId && error && (
|
|
57
|
+
<span className={classes['error-message']}>
|
|
58
|
+
<Icon className={classes['error-icon']} icon={Icons.Warning} />
|
|
59
|
+
<span id={errorId}>{errorMessage}</span>
|
|
60
|
+
</span>
|
|
61
|
+
)}
|
|
62
|
+
{nestedChildren}
|
|
63
|
+
</div>
|
|
64
|
+
);
|
|
65
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
.input-wrapper {
|
|
2
|
+
position: relative;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.input {
|
|
6
|
+
height: 4rem;
|
|
7
|
+
padding: 0 1.25rem;
|
|
8
|
+
border-color: var(--input-border-color);
|
|
9
|
+
border-style: var(--input-border-style);
|
|
10
|
+
border-width: var(--input-border-width);
|
|
11
|
+
border-radius: var(--input-border-radius);
|
|
12
|
+
transition: all 0.2s ease-in-out;
|
|
13
|
+
color: var(--greyed-out);
|
|
14
|
+
font-size: var(--font-size);
|
|
15
|
+
font-family: var(--font-family);
|
|
16
|
+
width: 100%;
|
|
17
|
+
box-sizing: border-box;
|
|
18
|
+
|
|
19
|
+
&:disabled {
|
|
20
|
+
color: var(--greyed-out);
|
|
21
|
+
background-color: var(--disabled);
|
|
22
|
+
border-color: #fff;
|
|
23
|
+
cursor: not-allowed;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
&:hover:not(:disabled) {
|
|
27
|
+
border-color: var(--default);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
&:focus:not(:disabled) {
|
|
31
|
+
outline: none;
|
|
32
|
+
border-color: var(--color-primary);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.error {
|
|
37
|
+
border-color: var(--error);
|
|
38
|
+
color: var(--error);
|
|
39
|
+
padding-right: 3.75rem;
|
|
40
|
+
|
|
41
|
+
&.remove-extra-indent {
|
|
42
|
+
padding-right: 1.25rem;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.warning {
|
|
47
|
+
color: var(--error);
|
|
48
|
+
position: absolute;
|
|
49
|
+
height: 100%;
|
|
50
|
+
width: 1.25rem;
|
|
51
|
+
right: 1.25rem;
|
|
52
|
+
top: 0px;
|
|
53
|
+
font-size: 1.125rem;
|
|
54
|
+
display: flex;
|
|
55
|
+
align-items: center;
|
|
56
|
+
justify-content: center;
|
|
57
|
+
|
|
58
|
+
&:before {
|
|
59
|
+
height: 1.3125rem;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
&.extra-indent {
|
|
63
|
+
right: 3.75rem;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Input, Props } from './Input';
|
|
3
|
+
import { render } from '@testing-library/react';
|
|
4
|
+
import userEvent from '@testing-library/user-event';
|
|
5
|
+
|
|
6
|
+
const defaultParams: Props = {
|
|
7
|
+
name: 'input',
|
|
8
|
+
type: 'text',
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const createInput = (params?: (defaultParams: Props) => Props) => {
|
|
12
|
+
let parameters: Props = defaultParams;
|
|
13
|
+
if (params) {
|
|
14
|
+
parameters = params(defaultParams);
|
|
15
|
+
}
|
|
16
|
+
const queries = render(<Input {...parameters} data-testid="input" />);
|
|
17
|
+
const input = queries.getByTestId('input');
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
...queries,
|
|
21
|
+
input,
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
describe('Input should render', () => {
|
|
26
|
+
it('renders without crashing and has a name and type', () => {
|
|
27
|
+
const { input } = createInput();
|
|
28
|
+
expect(input).toBeTruthy();
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe('Should have the appropriate attributes', () => {
|
|
33
|
+
it('is disabled and has a class', () => {
|
|
34
|
+
const { input } = createInput((defaultParams) => ({
|
|
35
|
+
...defaultParams,
|
|
36
|
+
disabled: true,
|
|
37
|
+
className: 'classname',
|
|
38
|
+
}));
|
|
39
|
+
|
|
40
|
+
expect(input).toHaveAttribute('disabled');
|
|
41
|
+
expect(input).toHaveClass('classname');
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe('Should render all different types of inputs', () => {
|
|
46
|
+
it('should render a text input', () => {
|
|
47
|
+
const { input } = createInput((defaultParams) => ({ ...defaultParams, type: 'text' }));
|
|
48
|
+
|
|
49
|
+
expect(input).toHaveAttribute('type', 'text');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('should render a email input', () => {
|
|
53
|
+
const { input } = createInput((defaultParams) => ({ ...defaultParams, type: 'email' }));
|
|
54
|
+
|
|
55
|
+
expect(input).toHaveAttribute('type', 'email');
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('should render a tel input', () => {
|
|
59
|
+
const { input } = createInput((defaultParams) => ({ ...defaultParams, type: 'tel' }));
|
|
60
|
+
|
|
61
|
+
expect(input).toHaveAttribute('type', 'tel');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('should render a number input', () => {
|
|
65
|
+
const { input } = createInput((defaultParams) => ({ ...defaultParams, type: 'number' }));
|
|
66
|
+
|
|
67
|
+
expect(input).toHaveAttribute('type', 'number');
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('should render a password input', () => {
|
|
71
|
+
const { input } = createInput((defaultParams) => ({ ...defaultParams, type: 'password' }));
|
|
72
|
+
|
|
73
|
+
expect(input).toHaveAttribute('type', 'password');
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('should render a search input', () => {
|
|
77
|
+
const { input } = createInput((defaultParams) => ({ ...defaultParams, type: 'search' }));
|
|
78
|
+
|
|
79
|
+
expect(input).toHaveAttribute('type', 'search');
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('should render a time input', () => {
|
|
83
|
+
const { input } = createInput((defaultParams) => ({ ...defaultParams, type: 'time' }));
|
|
84
|
+
|
|
85
|
+
expect(input).toHaveAttribute('type', 'time');
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('should render a url input', () => {
|
|
89
|
+
const { input } = createInput((defaultParams) => ({ ...defaultParams, type: 'url' }));
|
|
90
|
+
|
|
91
|
+
expect(input).toHaveAttribute('type', 'url');
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('should render a datetime input', () => {
|
|
95
|
+
const { input } = createInput((defaultParams) => ({
|
|
96
|
+
...defaultParams,
|
|
97
|
+
type: 'datetime-local',
|
|
98
|
+
}));
|
|
99
|
+
|
|
100
|
+
expect(input).toHaveAttribute('type', 'datetime-local');
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('should be hidden', () => {
|
|
104
|
+
const { input } = createInput((defaultParams) => ({ ...defaultParams, type: 'hidden' }));
|
|
105
|
+
|
|
106
|
+
expect(input.parentElement).toHaveClass('hidden');
|
|
107
|
+
expect(input).toHaveAttribute('type', 'hidden');
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
describe('It should execute the listeners', () => {
|
|
112
|
+
it('fires event handlers', () => {
|
|
113
|
+
const onChangeHandler = jest.fn();
|
|
114
|
+
const onKeyUpHandler = jest.fn();
|
|
115
|
+
const onKeyDownHandler = jest.fn();
|
|
116
|
+
|
|
117
|
+
const { input } = createInput((defaultParams) => ({
|
|
118
|
+
...defaultParams,
|
|
119
|
+
type: 'text',
|
|
120
|
+
onKeyUp: onKeyUpHandler,
|
|
121
|
+
onKeyDown: onKeyDownHandler,
|
|
122
|
+
onChange: onChangeHandler,
|
|
123
|
+
}));
|
|
124
|
+
|
|
125
|
+
input.focus();
|
|
126
|
+
|
|
127
|
+
expect(input).toHaveFocus();
|
|
128
|
+
|
|
129
|
+
userEvent.keyboard('test');
|
|
130
|
+
|
|
131
|
+
expect(onKeyUpHandler).toHaveBeenCalled();
|
|
132
|
+
expect(onKeyDownHandler).toHaveBeenCalled();
|
|
133
|
+
expect(onChangeHandler).toHaveBeenCalled();
|
|
134
|
+
});
|
|
135
|
+
});
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import React, { useEffect } from 'react';
|
|
2
|
+
import classes from './Input.module.scss';
|
|
3
|
+
import readyclasses from '../../readyclasses.module.scss';
|
|
4
|
+
import { Icon, Icons } from '../../Icon/Icon';
|
|
5
|
+
import { HTMLProps } from '../../interfaces';
|
|
6
|
+
|
|
7
|
+
const dateTypes = ['date', 'time', 'datetime-local'] as const;
|
|
8
|
+
|
|
9
|
+
export type Type =
|
|
10
|
+
| 'text'
|
|
11
|
+
| 'email'
|
|
12
|
+
| 'file'
|
|
13
|
+
| 'number'
|
|
14
|
+
| 'password'
|
|
15
|
+
| 'search'
|
|
16
|
+
| 'tel'
|
|
17
|
+
| 'url'
|
|
18
|
+
| 'hidden'
|
|
19
|
+
| typeof dateTypes[number];
|
|
20
|
+
|
|
21
|
+
export interface Props extends HTMLProps<HTMLInputElement> {
|
|
22
|
+
wrapperProps?: HTMLProps<HTMLInputElement>;
|
|
23
|
+
labeledBy?: string;
|
|
24
|
+
type: Type;
|
|
25
|
+
error?: boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const Input = ({
|
|
29
|
+
error = false,
|
|
30
|
+
className,
|
|
31
|
+
name,
|
|
32
|
+
style,
|
|
33
|
+
wrapperProps,
|
|
34
|
+
type,
|
|
35
|
+
labeledBy,
|
|
36
|
+
...rest
|
|
37
|
+
}: Props) => {
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (name === undefined) {
|
|
40
|
+
throw new Error("Please give your <Input /> component a 'name' attribute");
|
|
41
|
+
}
|
|
42
|
+
}, []);
|
|
43
|
+
|
|
44
|
+
const inputClassNames = [classes['input']];
|
|
45
|
+
error && inputClassNames.push(classes['error']);
|
|
46
|
+
(dateTypes as ReadonlyArray<string>).includes(type) &&
|
|
47
|
+
inputClassNames.push(classes['remove-extra-indent']);
|
|
48
|
+
className && inputClassNames.push(className);
|
|
49
|
+
|
|
50
|
+
const iconClassNames = [classes['warning']];
|
|
51
|
+
(dateTypes as ReadonlyArray<string>).includes(type) &&
|
|
52
|
+
iconClassNames.push(classes['extra-indent']);
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<div
|
|
56
|
+
{...wrapperProps}
|
|
57
|
+
style={{ ...style }}
|
|
58
|
+
className={`${classes['input-wrapper']} ${wrapperProps?.className ?? ''} ${
|
|
59
|
+
type === 'hidden' ? readyclasses['hidden'] : ''
|
|
60
|
+
}`}
|
|
61
|
+
>
|
|
62
|
+
<input
|
|
63
|
+
{...rest}
|
|
64
|
+
aria-labelledby={labeledBy}
|
|
65
|
+
type={type}
|
|
66
|
+
name={name}
|
|
67
|
+
className={inputClassNames.join(' ')}
|
|
68
|
+
/>
|
|
69
|
+
{error && <Icon className={iconClassNames.join(' ')} icon={Icons.Warning} />}
|
|
70
|
+
</div>
|
|
71
|
+
);
|
|
72
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Label } from './Label';
|
|
3
|
+
import { render } from '@testing-library/react';
|
|
4
|
+
|
|
5
|
+
describe('Label should render', () => {
|
|
6
|
+
it('renders without crashing', () => {
|
|
7
|
+
const { getByTestId } = render(
|
|
8
|
+
<Label htmlFor="input-name" data-testid="component">
|
|
9
|
+
Label
|
|
10
|
+
</Label>
|
|
11
|
+
);
|
|
12
|
+
const component = getByTestId('component');
|
|
13
|
+
expect(component).toBeDefined();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('adds htmlFor attribute', () => {
|
|
17
|
+
const { getByTestId } = render(
|
|
18
|
+
<Label htmlFor="input-name" data-testid="component">
|
|
19
|
+
Label
|
|
20
|
+
</Label>
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
const component = getByTestId('component');
|
|
24
|
+
expect(component.getAttribute('for')).toBe('input-name');
|
|
25
|
+
});
|
|
26
|
+
});
|