@ssa-ui-kit/core 1.0.2 → 1.0.4
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/components/Button/fixtures.d.ts +8 -0
- package/dist/components/Button/types.d.ts +2 -0
- package/dist/components/FormHelperText/FormHelperText.d.ts +1 -1
- package/dist/components/ImageItem/ImageItem.d.ts +2 -0
- package/dist/components/ImageItem/index.d.ts +1 -0
- package/dist/components/ImageItem/types.d.ts +8 -0
- package/dist/components/Input/types.d.ts +1 -0
- package/dist/components/Label/Label.d.ts +1 -1
- package/dist/components/Label/LabelBase.d.ts +2 -0
- package/dist/components/Label/types.d.ts +1 -0
- package/dist/components/Typeahead/Typeahead.context.d.ts +36 -0
- package/dist/components/Typeahead/Typeahead.d.ts +11 -0
- package/dist/components/Typeahead/components/MultipleTrigger.d.ts +1 -0
- package/dist/components/Typeahead/components/NoOptions.d.ts +1 -0
- package/dist/components/Typeahead/components/SingleTrigger.d.ts +1 -0
- package/dist/components/Typeahead/components/TypeaheadItem.d.ts +8 -0
- package/dist/components/Typeahead/components/TypeaheadOption.d.ts +2 -0
- package/dist/components/Typeahead/components/TypeaheadOptions.d.ts +2 -0
- package/dist/components/Typeahead/components/TypeaheadTrigger.d.ts +1 -0
- package/dist/components/Typeahead/components/index.d.ts +7 -0
- package/dist/components/Typeahead/index.d.ts +5 -0
- package/dist/components/Typeahead/styles.d.ts +47 -0
- package/dist/components/Typeahead/types.d.ts +46 -0
- package/dist/components/Typeahead/useTypeahead.d.ts +36 -0
- package/dist/components/Typeahead/utils.d.ts +1 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/types/emotion.d.ts +4 -1
- package/package.json +3 -3
- package/src/components/Badge/Badge.stories.tsx +1 -1
- package/src/components/Button/Button.tsx +10 -2
- package/src/components/Button/types.ts +2 -0
- package/src/components/FormHelperText/FormHelperText.tsx +2 -1
- package/src/components/ImageItem/ImageItem.spec.tsx +54 -0
- package/src/components/ImageItem/ImageItem.stories.tsx +33 -0
- package/src/components/ImageItem/ImageItem.tsx +43 -0
- package/src/components/ImageItem/index.ts +1 -0
- package/src/components/ImageItem/types.ts +7 -0
- package/src/components/Input/Input.spec.tsx +6 -8
- package/src/components/Input/Input.tsx +14 -8
- package/src/components/Input/types.ts +1 -0
- package/src/components/Label/Label.tsx +2 -0
- package/src/components/Label/LabelBase.tsx +3 -2
- package/src/components/Label/types.ts +1 -0
- package/src/components/Typeahead/Typeahead.context.ts +59 -0
- package/src/components/Typeahead/Typeahead.spec.tsx +506 -0
- package/src/components/Typeahead/Typeahead.stories.tsx +372 -0
- package/src/components/Typeahead/Typeahead.tsx +120 -0
- package/src/components/Typeahead/components/MultipleTrigger.tsx +116 -0
- package/src/components/Typeahead/components/NoOptions.tsx +7 -0
- package/src/components/Typeahead/components/SingleTrigger.tsx +71 -0
- package/src/components/Typeahead/components/TypeaheadItem.ts +14 -0
- package/src/components/Typeahead/components/TypeaheadOption.tsx +12 -0
- package/src/components/Typeahead/components/TypeaheadOptions.tsx +25 -0
- package/src/components/Typeahead/components/TypeaheadTrigger.tsx +26 -0
- package/src/components/Typeahead/components/index.ts +7 -0
- package/src/components/Typeahead/index.ts +5 -0
- package/src/components/Typeahead/styles.ts +193 -0
- package/src/components/Typeahead/types.ts +77 -0
- package/src/components/Typeahead/useTypeahead.tsx +321 -0
- package/src/components/Typeahead/utils.tsx +22 -0
- package/src/components/index.ts +2 -0
- package/src/themes/main.ts +3 -0
- package/src/types/emotion.ts +3 -0
- package/tsbuildcache +1 -1
package/dist/types/emotion.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ type Colors = MakeColors<[
|
|
|
12
12
|
'white30',
|
|
13
13
|
'dark',
|
|
14
14
|
'greyLighter',
|
|
15
|
+
'greyLighter40',
|
|
15
16
|
'greySelectedMenuItem',
|
|
16
17
|
'greyFocused',
|
|
17
18
|
'greyFocused40',
|
|
@@ -20,6 +21,7 @@ type Colors = MakeColors<[
|
|
|
20
21
|
'grey40',
|
|
21
22
|
'greyShadow24',
|
|
22
23
|
'greyDarker',
|
|
24
|
+
'greyDarker40',
|
|
23
25
|
'greyDarker60',
|
|
24
26
|
'greyDarker80',
|
|
25
27
|
'greyDarker14',
|
|
@@ -105,7 +107,8 @@ type Colors = MakeColors<[
|
|
|
105
107
|
'blueButtonHoverGradientFrom',
|
|
106
108
|
'blueButtonHoverGradientTo',
|
|
107
109
|
'blueButtonActive',
|
|
108
|
-
'blueRoyal'
|
|
110
|
+
'blueRoyal',
|
|
111
|
+
'blueRoyal12'
|
|
109
112
|
]>;
|
|
110
113
|
export type ColorsKeys = keyof Colors;
|
|
111
114
|
type MediaQueryString = `@media${string}`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ssa-ui-kit/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"private": false,
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"loose-envify": "^1.4.0",
|
|
30
30
|
"scheduler": "^0.23.0",
|
|
31
31
|
"uuid": "^9.0.0",
|
|
32
|
-
"@ssa-ui-kit/
|
|
33
|
-
"@ssa-ui-kit/
|
|
32
|
+
"@ssa-ui-kit/hooks": "^1.0.0",
|
|
33
|
+
"@ssa-ui-kit/utils": "^1.0.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@emotion/jest": "^11.11.0",
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { Meta } from '@storybook/react';
|
|
3
3
|
import { useTheme } from '@emotion/react';
|
|
4
|
+
import Icon from '@components/Icon';
|
|
4
5
|
import { HeaderTitle, GridWrapper, colors, sizes, icons } from './helpers';
|
|
5
6
|
|
|
6
7
|
import Badge from './index';
|
|
7
|
-
import Icon from '@components/Icon';
|
|
8
8
|
|
|
9
9
|
export default {
|
|
10
10
|
title: 'Components/Badge',
|
|
@@ -47,6 +47,8 @@ export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
|
|
|
47
47
|
text,
|
|
48
48
|
startIcon,
|
|
49
49
|
endIcon,
|
|
50
|
+
startIconClassName,
|
|
51
|
+
endIconClassName,
|
|
50
52
|
variant = 'primary',
|
|
51
53
|
type = 'button',
|
|
52
54
|
className,
|
|
@@ -89,7 +91,10 @@ export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
|
|
|
89
91
|
onClick={onClick}
|
|
90
92
|
{...ariaProps}>
|
|
91
93
|
{startIcon ? (
|
|
92
|
-
<span
|
|
94
|
+
<span
|
|
95
|
+
style={noMargin}
|
|
96
|
+
css={[iconWrapperRight]}
|
|
97
|
+
className={startIconClassName}>
|
|
93
98
|
{startIcon}
|
|
94
99
|
</span>
|
|
95
100
|
) : null}
|
|
@@ -107,7 +112,10 @@ export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
|
|
|
107
112
|
)
|
|
108
113
|
) : null}
|
|
109
114
|
{endIcon ? (
|
|
110
|
-
<span
|
|
115
|
+
<span
|
|
116
|
+
style={noMargin}
|
|
117
|
+
css={[iconWrapperLeft]}
|
|
118
|
+
className={endIconClassName}>
|
|
111
119
|
{endIcon}
|
|
112
120
|
</span>
|
|
113
121
|
) : null}
|
|
@@ -21,6 +21,8 @@ export interface ButtonProps extends ButtonAriaProps {
|
|
|
21
21
|
text?: string;
|
|
22
22
|
startIcon?: React.ReactNode;
|
|
23
23
|
endIcon?: React.ReactNode;
|
|
24
|
+
startIconClassName?: string;
|
|
25
|
+
endIconClassName?: string;
|
|
24
26
|
variant?: keyof ButtonVariants | 'custom';
|
|
25
27
|
type?: 'button' | 'reset' | 'submit';
|
|
26
28
|
isDisabled?: boolean;
|
|
@@ -6,10 +6,11 @@ const FormHelperText = ({
|
|
|
6
6
|
status,
|
|
7
7
|
disabled,
|
|
8
8
|
children,
|
|
9
|
+
...rest
|
|
9
10
|
}: FormHelperTextProps) => {
|
|
10
11
|
status = disabled ? 'basic' : status;
|
|
11
12
|
return (
|
|
12
|
-
<FormHelperTextBase role={role} status={status}>
|
|
13
|
+
<FormHelperTextBase role={role} status={status} {...rest}>
|
|
13
14
|
{children}
|
|
14
15
|
</FormHelperTextBase>
|
|
15
16
|
);
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { screen } from '@testing-library/dom';
|
|
2
|
+
import { ImageItem } from '@components/ImageItem';
|
|
3
|
+
|
|
4
|
+
const image =
|
|
5
|
+
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAASGSURBVHgBfVVbUhtXEO2eGQ0SLz1AIAgYycSO7XKVo898hazA3kGSFeBkATHFAhJYAVlCvIKwgiiqpCLHNhbgBwgkIYHempl2952HBkr2VI10de/M6dOnT7cQPnMVCoWEaU5vEsIGgbNGDuRknwgaRM7fRPQcnP4f+Xz+8FMYOG6zVCpnQac9x6ENchwGJP+IZO3dGOwT7fVosP3NmEDazY2X5aNNzcACx/4WXIAwOvq3YoeoAvLih5g+8Vex+GLzswFeld8+Ixt2HKKEz9wDC5hfA3bXcswbkOTPneI/pWdjJToov3tqE/1Gtg0Og/u3xxw0TSO+URLq9wdhDEI3Hwmmojno/Jx/+GAnCFAqn2QjYBVYc2HOMVQQpfHUVIzS8ymMRaO8Zyu9zEgEWq02nFaq1Gp3gkTkQ7Lj3017SFz7+4eGnOpkb/myOCNZYCmThpmZKTw7q8HR5XuwLNvVlROJz87ArdVlrNcbUDmvkUsWPc6UMCb0PV58hy57uyzMLdtGh9kL8/R8UsChfPiOGBhZHohOmIrhVautiqDrOt5ZXwPJ4uT0nJRarl78nAbWoJ3UDLCfCKAwV6UUWSZjkEjMCriwRtM06e6XWchwRouL8/jg3joYho5So9dvjiEen2EpJ9EvqSsVkBmd3mQX0WPPMfKCeiKdToHIYtuOYjw/l0BhecBgrw+OqNlscYYpdSb1qlSqsLgwBzfqINlsaLx8pLiPbKkyuLpqBzbVdY2L2gl+d3s9MM2IWgvg5VULYtEJycrvGfQCZTVVXE8iiSwOGQyHwPUILCrgUhMGJQkm7FvtbiCFZGozQV3TR/5XZ1rW8OyoMgj3RbiR6hdNikQi+NWd2+r8vFoDcY/0hltY750Rc1VkZLcZDHzEYGs+qDAXJpLucGih17V4dl6FRrMJ7Bzo9fqezkoiMgxDegMtywpIqcZErWEwZpkBbvne54yINcaZ6Slk5jA5GcXMwjzEYjEYDIYqR9G/2+lhtV6Hy8u2PAttlkwIMgHpeL+1ixyA9vneCMmiGmvliwywLJBKxuH47QfxOvnshMxcKgHLS4tc3CYkE3F4f1Lx5pLykgrEjz3HQrmcMDrDi7Du8r2UWVCF/f/VG+h2+948ElkwGA3TzPx2dhXOzut819S5zCuNJdZYSgOtnJbP5Rr8zr47tEZT8gMzOj2rQm5thRnOqpqI0eQxcVIqmaCV5QzUahcg9fF6AKW4IpGm4++5XO7QHXalUnZo6wWZIV4dFGMJyMOOa5BmtpOqBrLHAVCyqjBwp9P15pMA6yDBWZ4GD4p8EECu4r8vnnJVfg3/Y4VlE1eYEUPZUAiw731/oucaBjZI4wAaGj+t55Z31Xt+gEcP7+1ww2x7wH7ga4UdDC2SJrRVz6B/+bZ0nUO47YNfayz/KhT/40zgF0ZOhvf9AgteUOWR54V9AzV96+766m74vbF/+oVCKcsibQHS9z6QG8Cd+SLXCF9Zcp8i+ON91vwm1tgA4UBc7ic89h8z0NeMFfcCHrNmh2zFPwc9YzefZyd+4voIMSvIE1PFRoIAAAAASUVORK5CYII=';
|
|
6
|
+
|
|
7
|
+
describe('ImageItem', () => {
|
|
8
|
+
it('Should be rendered without link', () => {
|
|
9
|
+
render(<ImageItem image={image}>Name Surname</ImageItem>);
|
|
10
|
+
|
|
11
|
+
expect(
|
|
12
|
+
screen.getByText(
|
|
13
|
+
(content, element) =>
|
|
14
|
+
element?.tagName.toLowerCase() === 'div' &&
|
|
15
|
+
element?.getAttribute('data-testid') === 'image-item',
|
|
16
|
+
),
|
|
17
|
+
).toBeInTheDocument();
|
|
18
|
+
});
|
|
19
|
+
it('Should be rendered with the link', () => {
|
|
20
|
+
render(
|
|
21
|
+
<ImageItem
|
|
22
|
+
image={image}
|
|
23
|
+
link="/?path=/story/components-button--all-states">
|
|
24
|
+
Name Surname
|
|
25
|
+
</ImageItem>,
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
expect(
|
|
29
|
+
screen.getByText(
|
|
30
|
+
(content, element) =>
|
|
31
|
+
element?.tagName.toLowerCase() === 'a' &&
|
|
32
|
+
element.getAttribute('target') !== '_blank',
|
|
33
|
+
),
|
|
34
|
+
).toBeInTheDocument();
|
|
35
|
+
});
|
|
36
|
+
it('Should be rendered with the link, opening in the new window', () => {
|
|
37
|
+
render(
|
|
38
|
+
<ImageItem
|
|
39
|
+
image={image}
|
|
40
|
+
link="/?path=/story/components-button--all-states"
|
|
41
|
+
openLinkInNewTab>
|
|
42
|
+
Name Surname
|
|
43
|
+
</ImageItem>,
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
expect(
|
|
47
|
+
screen.getByText(
|
|
48
|
+
(content, element) =>
|
|
49
|
+
element?.tagName.toLowerCase() === 'a' &&
|
|
50
|
+
element.getAttribute('target') === '_blank',
|
|
51
|
+
),
|
|
52
|
+
).toBeInTheDocument();
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Meta } from '@storybook/react';
|
|
2
|
+
import { ImageItem } from './ImageItem';
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
title: 'Widgets/ImageItem',
|
|
6
|
+
component: ImageItem,
|
|
7
|
+
} as Meta<typeof ImageItem>;
|
|
8
|
+
|
|
9
|
+
export const Default = {
|
|
10
|
+
args: {
|
|
11
|
+
children: 'Name Surname',
|
|
12
|
+
image:
|
|
13
|
+
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAASGSURBVHgBfVVbUhtXEO2eGQ0SLz1AIAgYycSO7XKVo898hazA3kGSFeBkATHFAhJYAVlCvIKwgiiqpCLHNhbgBwgkIYHempl2952HBkr2VI10de/M6dOnT7cQPnMVCoWEaU5vEsIGgbNGDuRknwgaRM7fRPQcnP4f+Xz+8FMYOG6zVCpnQac9x6ENchwGJP+IZO3dGOwT7fVosP3NmEDazY2X5aNNzcACx/4WXIAwOvq3YoeoAvLih5g+8Vex+GLzswFeld8+Ixt2HKKEz9wDC5hfA3bXcswbkOTPneI/pWdjJToov3tqE/1Gtg0Og/u3xxw0TSO+URLq9wdhDEI3Hwmmojno/Jx/+GAnCFAqn2QjYBVYc2HOMVQQpfHUVIzS8ymMRaO8Zyu9zEgEWq02nFaq1Gp3gkTkQ7Lj3017SFz7+4eGnOpkb/myOCNZYCmThpmZKTw7q8HR5XuwLNvVlROJz87ArdVlrNcbUDmvkUsWPc6UMCb0PV58hy57uyzMLdtGh9kL8/R8UsChfPiOGBhZHohOmIrhVautiqDrOt5ZXwPJ4uT0nJRarl78nAbWoJ3UDLCfCKAwV6UUWSZjkEjMCriwRtM06e6XWchwRouL8/jg3joYho5So9dvjiEen2EpJ9EvqSsVkBmd3mQX0WPPMfKCeiKdToHIYtuOYjw/l0BhecBgrw+OqNlscYYpdSb1qlSqsLgwBzfqINlsaLx8pLiPbKkyuLpqBzbVdY2L2gl+d3s9MM2IWgvg5VULYtEJycrvGfQCZTVVXE8iiSwOGQyHwPUILCrgUhMGJQkm7FvtbiCFZGozQV3TR/5XZ1rW8OyoMgj3RbiR6hdNikQi+NWd2+r8vFoDcY/0hltY750Rc1VkZLcZDHzEYGs+qDAXJpLucGih17V4dl6FRrMJ7Bzo9fqezkoiMgxDegMtywpIqcZErWEwZpkBbvne54yINcaZ6Slk5jA5GcXMwjzEYjEYDIYqR9G/2+lhtV6Hy8u2PAttlkwIMgHpeL+1ixyA9vneCMmiGmvliwywLJBKxuH47QfxOvnshMxcKgHLS4tc3CYkE3F4f1Lx5pLykgrEjz3HQrmcMDrDi7Du8r2UWVCF/f/VG+h2+948ElkwGA3TzPx2dhXOzut819S5zCuNJdZYSgOtnJbP5Rr8zr47tEZT8gMzOj2rQm5thRnOqpqI0eQxcVIqmaCV5QzUahcg9fF6AKW4IpGm4++5XO7QHXalUnZo6wWZIV4dFGMJyMOOa5BmtpOqBrLHAVCyqjBwp9P15pMA6yDBWZ4GD4p8EECu4r8vnnJVfg3/Y4VlE1eYEUPZUAiw731/oucaBjZI4wAaGj+t55Z31Xt+gEcP7+1ww2x7wH7ga4UdDC2SJrRVz6B/+bZ0nUO47YNfayz/KhT/40zgF0ZOhvf9AgteUOWR54V9AzV96+766m74vbF/+oVCKcsibQHS9z6QG8Cd+SLXCF9Zcp8i+ON91vwm1tgA4UBc7ic89h8z0NeMFfcCHrNmh2zFPwc9YzefZyd+4voIMSvIE1PFRoIAAAAASUVORK5CYII=',
|
|
14
|
+
avatarSize: 24,
|
|
15
|
+
link: '',
|
|
16
|
+
openLinkInNewTab: false,
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const WithLink = {
|
|
21
|
+
args: {
|
|
22
|
+
...Default.args,
|
|
23
|
+
link: 'https://uikit.ssa.group',
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const WithLinkOpeningInNewTab = {
|
|
28
|
+
args: {
|
|
29
|
+
...Default.args,
|
|
30
|
+
link: 'https://uikit.ssa.group',
|
|
31
|
+
openLinkInNewTab: true,
|
|
32
|
+
},
|
|
33
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { useTheme } from '@emotion/react';
|
|
2
|
+
import Avatar from '@components/Avatar';
|
|
3
|
+
import Wrapper from '@components/Wrapper';
|
|
4
|
+
import { ImageItemProps } from './types';
|
|
5
|
+
|
|
6
|
+
export const ImageItem = ({
|
|
7
|
+
children,
|
|
8
|
+
image,
|
|
9
|
+
avatarSize = 24,
|
|
10
|
+
link = '',
|
|
11
|
+
openLinkInNewTab = false,
|
|
12
|
+
className,
|
|
13
|
+
}: ImageItemProps) => {
|
|
14
|
+
const theme = useTheme();
|
|
15
|
+
const additionalProps = link
|
|
16
|
+
? {
|
|
17
|
+
href: link,
|
|
18
|
+
target: openLinkInNewTab ? '_blank' : undefined,
|
|
19
|
+
}
|
|
20
|
+
: {};
|
|
21
|
+
return (
|
|
22
|
+
<Wrapper
|
|
23
|
+
css={{ gap: 8, textDecoration: 'none' }}
|
|
24
|
+
as={link ? 'a' : 'div'}
|
|
25
|
+
className={className}
|
|
26
|
+
data-testid="image-item"
|
|
27
|
+
{...additionalProps}>
|
|
28
|
+
<Avatar size={avatarSize} image={image} />
|
|
29
|
+
<span
|
|
30
|
+
css={{
|
|
31
|
+
color: theme.colors.greyDarker,
|
|
32
|
+
fontSize: 14,
|
|
33
|
+
fontWeight: 500,
|
|
34
|
+
cursor: link ? 'pointer' : 'default',
|
|
35
|
+
'&:hover': {
|
|
36
|
+
color: theme.colors.blue,
|
|
37
|
+
},
|
|
38
|
+
}}>
|
|
39
|
+
{children}
|
|
40
|
+
</span>
|
|
41
|
+
</Wrapper>
|
|
42
|
+
);
|
|
43
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ImageItem';
|
|
@@ -15,14 +15,12 @@ describe('Inputs', () => {
|
|
|
15
15
|
expect(input).toBeInTheDocument();
|
|
16
16
|
});
|
|
17
17
|
|
|
18
|
-
it('
|
|
19
|
-
jest.spyOn(console, '
|
|
20
|
-
|
|
21
|
-
expect((
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
render(<Input placeholder="Field" name="field" disabled={true} />),
|
|
25
|
-
).toThrow('Input component must be used within a Form component');
|
|
18
|
+
it('Throw warning when without register', () => {
|
|
19
|
+
const warnSpy = jest.spyOn(console, 'warn').mockImplementation();
|
|
20
|
+
render(<Input placeholder="Field" name="field" disabled={true} />);
|
|
21
|
+
expect(warnSpy).toBeCalledWith(
|
|
22
|
+
'Input component must be used within a Form component',
|
|
23
|
+
);
|
|
26
24
|
});
|
|
27
25
|
|
|
28
26
|
it('Render input disabled', () => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { forwardRef } from 'react';
|
|
1
|
+
import { forwardRef, useEffect } from 'react';
|
|
2
2
|
import { useMergeRefs } from '@floating-ui/react';
|
|
3
3
|
import { InputBase } from './InputBase';
|
|
4
4
|
import { InputGroup } from './InputGroup';
|
|
@@ -25,21 +25,27 @@ const InputInner = (
|
|
|
25
25
|
startElement,
|
|
26
26
|
endElement,
|
|
27
27
|
className,
|
|
28
|
+
wrapperClassName,
|
|
28
29
|
inputProps = {},
|
|
29
30
|
register,
|
|
30
31
|
onKeyUp,
|
|
31
32
|
}: InputProps,
|
|
32
33
|
inputRef?: React.ForwardedRef<HTMLInputElement | null>,
|
|
33
34
|
) => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
if (!register) {
|
|
37
|
+
console.warn('Input component must be used within a Form component');
|
|
38
|
+
}
|
|
39
|
+
}, []);
|
|
37
40
|
|
|
38
41
|
const showStatusIcon = () => !disabled && !endElement;
|
|
39
42
|
|
|
40
|
-
const registerResult = register(name, validationSchema);
|
|
43
|
+
const registerResult = register?.(name, validationSchema);
|
|
41
44
|
return (
|
|
42
|
-
<InputGroup
|
|
45
|
+
<InputGroup
|
|
46
|
+
css={[mapColors[status]]}
|
|
47
|
+
className={wrapperClassName}
|
|
48
|
+
disabled={disabled}>
|
|
43
49
|
{startElement ? <div css={S.startElement}>{startElement}</div> : null}
|
|
44
50
|
<InputBase
|
|
45
51
|
type={type}
|
|
@@ -53,8 +59,8 @@ const InputInner = (
|
|
|
53
59
|
className={className}
|
|
54
60
|
onKeyUp={onKeyUp}
|
|
55
61
|
{...inputProps}
|
|
56
|
-
{...register(name, validationSchema)}
|
|
57
|
-
ref={useMergeRefs([registerResult
|
|
62
|
+
{...register?.(name, validationSchema)}
|
|
63
|
+
ref={useMergeRefs([registerResult?.ref, inputRef])}
|
|
58
64
|
/>
|
|
59
65
|
|
|
60
66
|
{status === 'error' && showStatusIcon() ? <InputStatusError /> : null}
|
|
@@ -5,11 +5,13 @@ const Label = ({
|
|
|
5
5
|
children,
|
|
6
6
|
htmlFor,
|
|
7
7
|
className,
|
|
8
|
+
isDisabled,
|
|
8
9
|
onMouseEnter,
|
|
9
10
|
onMouseLeave,
|
|
10
11
|
}: LabelProps) => (
|
|
11
12
|
<LabelBase
|
|
12
13
|
htmlFor={htmlFor}
|
|
14
|
+
isDisabled={isDisabled}
|
|
13
15
|
className={className}
|
|
14
16
|
onMouseEnter={onMouseEnter}
|
|
15
17
|
onMouseLeave={onMouseLeave}>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import styled from '@emotion/styled';
|
|
2
2
|
|
|
3
|
-
export const LabelBase = styled.label
|
|
3
|
+
export const LabelBase = styled.label<{ isDisabled?: boolean }>`
|
|
4
4
|
display: inline-block;
|
|
5
5
|
|
|
6
6
|
flex: 1;
|
|
@@ -8,7 +8,8 @@ export const LabelBase = styled.label`
|
|
|
8
8
|
font-size: 1rem;
|
|
9
9
|
line-height: 22px;
|
|
10
10
|
|
|
11
|
-
color: ${({ theme }) =>
|
|
11
|
+
color: ${({ theme, isDisabled }) =>
|
|
12
|
+
isDisabled ? theme.colors.grey : theme.colors.greyDarker};
|
|
12
13
|
|
|
13
14
|
margin: 0 0 6px 4px;
|
|
14
15
|
`;
|
|
@@ -4,6 +4,7 @@ import { CommonProps } from '@global-types/emotion';
|
|
|
4
4
|
export interface LabelProps extends CommonProps {
|
|
5
5
|
htmlFor?: string;
|
|
6
6
|
children: React.ReactNode;
|
|
7
|
+
isDisabled?: boolean;
|
|
7
8
|
onMouseEnter?: MouseEventHandler<HTMLLabelElement>;
|
|
8
9
|
onMouseLeave?: MouseEventHandler<HTMLLabelElement>;
|
|
9
10
|
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { UseTypeaheadResult } from './useTypeahead';
|
|
3
|
+
|
|
4
|
+
export const TypeaheadContext = React.createContext<UseTypeaheadResult>({
|
|
5
|
+
optionsWithKey: {},
|
|
6
|
+
isMultiple: false,
|
|
7
|
+
selectedItems: [],
|
|
8
|
+
typeaheadId: '',
|
|
9
|
+
firstSuggestion: '',
|
|
10
|
+
inputRef: { current: null },
|
|
11
|
+
triggerRef: { current: null },
|
|
12
|
+
isOpen: false,
|
|
13
|
+
className: undefined,
|
|
14
|
+
startIcon: null,
|
|
15
|
+
endIcon: null,
|
|
16
|
+
startIconClassName: undefined,
|
|
17
|
+
endIconClassName: undefined,
|
|
18
|
+
name: '',
|
|
19
|
+
inputName: '',
|
|
20
|
+
inputValue: '',
|
|
21
|
+
validationSchema: {},
|
|
22
|
+
status: 'basic',
|
|
23
|
+
isDisabled: false,
|
|
24
|
+
options: [],
|
|
25
|
+
placeholder: '',
|
|
26
|
+
setValue: () => {
|
|
27
|
+
/* no-op */
|
|
28
|
+
},
|
|
29
|
+
register: () => {
|
|
30
|
+
return {} as any;
|
|
31
|
+
},
|
|
32
|
+
handleChange: () => {
|
|
33
|
+
/* no-op */
|
|
34
|
+
},
|
|
35
|
+
handleClearAll: () => {
|
|
36
|
+
/* no-op */
|
|
37
|
+
},
|
|
38
|
+
handleInputClick: () => {
|
|
39
|
+
/* no-op */
|
|
40
|
+
},
|
|
41
|
+
handleInputKeyDown: () => {
|
|
42
|
+
/* no-op */
|
|
43
|
+
},
|
|
44
|
+
handleInputChange: () => {
|
|
45
|
+
/* no-op */
|
|
46
|
+
},
|
|
47
|
+
handleOpenChange: () => {
|
|
48
|
+
/* no-op */
|
|
49
|
+
},
|
|
50
|
+
handleRemoveSelectedClick: () => () => {
|
|
51
|
+
/* no-op */
|
|
52
|
+
},
|
|
53
|
+
handleSelectedClick: () => {
|
|
54
|
+
/* no-op */
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
export const useTypeaheadContext = (): UseTypeaheadResult =>
|
|
59
|
+
React.useContext(TypeaheadContext);
|