@onewelcome/react-lib-components 0.1.3-alpha → 0.1.6-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/dist/Link/Link.d.ts +2 -2
- package/dist/Tabs/TabButton.d.ts +1 -1
- package/dist/Tabs/TabPanel.d.ts +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/react-lib-components.cjs.development.js +276 -48
- package/dist/react-lib-components.cjs.development.js.map +1 -1
- package/dist/react-lib-components.cjs.production.min.js +1 -1
- package/dist/react-lib-components.cjs.production.min.js.map +1 -1
- package/dist/react-lib-components.esm.js +274 -49
- package/dist/react-lib-components.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/Form/FormGroup/FormGroup.test.tsx +24 -0
- package/src/Form/FormGroup/FormGroup.tsx +1 -1
- package/src/Form/Toggle/Toggle.test.tsx +45 -19
- package/src/Form/Toggle/Toggle.tsx +2 -2
- package/src/Link/Link.tsx +7 -2
- package/src/index.ts +4 -0
package/package.json
CHANGED
|
@@ -85,3 +85,27 @@ describe('Correct error state', () => {
|
|
|
85
85
|
expect(errorMessage?.querySelector('#error_id')).toHaveTextContent('example error message');
|
|
86
86
|
});
|
|
87
87
|
});
|
|
88
|
+
|
|
89
|
+
describe('no helpertext, but errorMessage is defined', () => {
|
|
90
|
+
it("doesn't show the div with 'default-helper' class when there's no error and no helpertext defined", () => {
|
|
91
|
+
const { formgroup } = createFormGroup((defaultParams) => ({
|
|
92
|
+
...defaultParams,
|
|
93
|
+
error: false,
|
|
94
|
+
helperText: undefined,
|
|
95
|
+
errorMessage: 'example error message',
|
|
96
|
+
}));
|
|
97
|
+
|
|
98
|
+
expect(formgroup.querySelector('.default-helper')).toBeFalsy();
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("does show the div with 'default-helper' class when there's an error and no helpertext defined", () => {
|
|
102
|
+
const { formgroup } = createFormGroup((defaultParams) => ({
|
|
103
|
+
...defaultParams,
|
|
104
|
+
error: true,
|
|
105
|
+
helperText: undefined,
|
|
106
|
+
errorMessage: 'example error message',
|
|
107
|
+
}));
|
|
108
|
+
|
|
109
|
+
expect(formgroup.querySelector('.default-helper')).toBeTruthy();
|
|
110
|
+
});
|
|
111
|
+
});
|
|
@@ -45,7 +45,7 @@ export const FormGroup = React.forwardRef<HTMLDivElement, Props>(
|
|
|
45
45
|
>
|
|
46
46
|
{children}
|
|
47
47
|
|
|
48
|
-
{(helperText || errorMessage) && (
|
|
48
|
+
{(helperText || (errorMessage && error)) && (
|
|
49
49
|
<div
|
|
50
50
|
style={{ marginLeft: `${helperIndent}px` }}
|
|
51
51
|
className={`${classes['default-helper']} ${
|
|
@@ -1,16 +1,43 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
import { Toggle } from './Toggle';
|
|
1
|
+
import React, { useRef, useEffect } from 'react';
|
|
2
|
+
import { Toggle, Props } from './Toggle';
|
|
3
3
|
import { render } from '@testing-library/react';
|
|
4
4
|
|
|
5
|
+
const defaultParams: Props = {
|
|
6
|
+
children: 'label',
|
|
7
|
+
name: 'example toggle',
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const createToggle = (params?: (defaultParams: Props) => Props) => {
|
|
11
|
+
let parameters: Props = defaultParams;
|
|
12
|
+
if (params) {
|
|
13
|
+
parameters = params(defaultParams);
|
|
14
|
+
}
|
|
15
|
+
const queries = render(
|
|
16
|
+
<Toggle {...parameters} data-testid="toggle">
|
|
17
|
+
toggle content
|
|
18
|
+
</Toggle>
|
|
19
|
+
);
|
|
20
|
+
const toggle = queries.getByTestId('toggle');
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
...queries,
|
|
24
|
+
toggle,
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
|
|
5
28
|
describe('Toggle should render', () => {
|
|
6
29
|
it('renders without crashing', () => {
|
|
7
|
-
const {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
30
|
+
const { toggle } = createToggle();
|
|
31
|
+
|
|
32
|
+
expect(toggle).toBeDefined();
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe('Toggle attributes', () => {
|
|
37
|
+
it('should be checked', () => {
|
|
38
|
+
const { toggle } = createToggle((defaultParams) => ({ ...defaultParams, checked: true }));
|
|
39
|
+
|
|
40
|
+
expect(toggle).toHaveAttribute('aria-checked', 'true');
|
|
14
41
|
});
|
|
15
42
|
});
|
|
16
43
|
|
|
@@ -29,7 +56,7 @@ describe('ref should work', () => {
|
|
|
29
56
|
}
|
|
30
57
|
}, [ref]);
|
|
31
58
|
|
|
32
|
-
return <Toggle
|
|
59
|
+
return <Toggle {...defaultParams} data-ref="testing" ref={ref} />;
|
|
33
60
|
};
|
|
34
61
|
|
|
35
62
|
const refCheck = (ref: React.RefObject<HTMLElement>) => {
|
|
@@ -40,16 +67,15 @@ describe('ref should work', () => {
|
|
|
40
67
|
});
|
|
41
68
|
});
|
|
42
69
|
|
|
43
|
-
describe('
|
|
44
|
-
it('
|
|
45
|
-
const { getByTestId } =
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
);
|
|
70
|
+
describe('helperProps should be properly propagated down', () => {
|
|
71
|
+
it('renders an anchor tag as helper', () => {
|
|
72
|
+
const { getByTestId } = createToggle((defaultParams) => ({
|
|
73
|
+
...defaultParams,
|
|
74
|
+
helperProps: { children: <a data-testid="helpertextanchor">test</a> },
|
|
75
|
+
}));
|
|
50
76
|
|
|
51
|
-
const
|
|
77
|
+
const helperTextAnchor = getByTestId('helpertextanchor');
|
|
52
78
|
|
|
53
|
-
expect(
|
|
79
|
+
expect(helperTextAnchor).toBeTruthy();
|
|
54
80
|
});
|
|
55
81
|
});
|
|
@@ -9,14 +9,14 @@ export interface Props
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export const Toggle = React.forwardRef<HTMLInputElement, Props>(
|
|
12
|
-
({ children, checked, disabled, ...rest }: Props, ref) => (
|
|
12
|
+
({ children, checked, disabled, helperProps, ...rest }: Props, ref) => (
|
|
13
13
|
<div className={classes['toggle-wrapper']}>
|
|
14
14
|
<Checkbox
|
|
15
15
|
{...rest}
|
|
16
16
|
ref={ref}
|
|
17
17
|
checked={checked}
|
|
18
18
|
className={classes['checkbox']}
|
|
19
|
-
helperProps={{ className: classes['toggle-helper'] }}
|
|
19
|
+
helperProps={{ className: classes['toggle-helper'], ...helperProps }}
|
|
20
20
|
disabled={disabled}
|
|
21
21
|
label={children}
|
|
22
22
|
>
|
package/src/Link/Link.tsx
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, {
|
|
2
|
+
ComponentPropsWithRef,
|
|
3
|
+
ForwardRefExoticComponent,
|
|
4
|
+
ReactNode,
|
|
5
|
+
RefAttributes,
|
|
6
|
+
} from 'react';
|
|
2
7
|
import classes from './Link.module.scss';
|
|
3
8
|
import { LinkProps } from './types';
|
|
4
9
|
|
|
5
10
|
type AnchorType = 'external' | 'internal' | 'download';
|
|
6
11
|
|
|
7
12
|
export interface Props extends ComponentPropsWithRef<'a'> {
|
|
8
|
-
children?:
|
|
13
|
+
children?: ReactNode;
|
|
9
14
|
color?: 'primary' | 'secondary' | 'tertiary';
|
|
10
15
|
type?: AnchorType;
|
|
11
16
|
to: string;
|
package/src/index.ts
CHANGED
|
@@ -13,6 +13,9 @@ export {
|
|
|
13
13
|
} from './Pagination/Pagination';
|
|
14
14
|
export { Icon, Icons } from './Icon/Icon';
|
|
15
15
|
|
|
16
|
+
export { Tabs, Props as TabsProps } from './Tabs/Tabs';
|
|
17
|
+
export { Tab, Props as TabProps } from './Tabs/Tab';
|
|
18
|
+
|
|
16
19
|
export { Dialog } from './Notifications/Dialog/Dialog';
|
|
17
20
|
export { Modal } from './Notifications/Modal/Modal';
|
|
18
21
|
export { ModalActions } from './Notifications/Modal/ModalActions/ModalActions';
|
|
@@ -52,6 +55,7 @@ export { TextareaWrapper } from './Form/Wrapper/TextareaWrapper/TextareaWrapper'
|
|
|
52
55
|
export { Input } from './Form/Input/Input';
|
|
53
56
|
export { Radio } from './Form/Radio/Radio';
|
|
54
57
|
export { Checkbox } from './Form/Checkbox/Checkbox';
|
|
58
|
+
export { Toggle } from './Form/Toggle/Toggle';
|
|
55
59
|
|
|
56
60
|
/** Wizard */
|
|
57
61
|
export {
|