@ssa-ui-kit/core 1.0.3 → 1.0.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ssa-ui-kit/core",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "private": false,
@@ -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',
@@ -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/+GAnCFAqn2QjYBVYc2HOMVQQpfHUVIzS8ymMRaO8Zyu9zEgEWq02nFaq1Gp3gkTkQ7Lj3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7ic89h8z0NeMFfcCHrNmh2zFPwc9YzefZyd+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,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAASGSURBVHgBfVVbUhtXEO2eGQ0SLz1AIAg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CF/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: link ? theme.colors.blue : theme.colors.greyDarker,
37
+ },
38
+ }}>
39
+ {children}
40
+ </span>
41
+ </Wrapper>
42
+ );
43
+ };
@@ -0,0 +1 @@
1
+ export * from './ImageItem';
@@ -0,0 +1,7 @@
1
+ export type ImageItemProps = React.PropsWithChildren<{
2
+ image: string;
3
+ avatarSize?: number;
4
+ link?: string;
5
+ className?: string;
6
+ openLinkInNewTab?: boolean;
7
+ }>;
@@ -37,11 +37,24 @@ export default {
37
37
  },
38
38
  },
39
39
  decorators: [
40
- (Story) => (
41
- <Form>
42
- <FormGroup>{Story()}</FormGroup>
43
- </Form>
44
- ),
40
+ (Story, context) => {
41
+ const useFormResult = useForm<FieldValues>();
42
+ return (
43
+ <Form
44
+ onSubmit={useFormResult.handleSubmit((data) => {
45
+ console.log('>>>onSubmit', data);
46
+ })}>
47
+ <FormGroup>
48
+ {Story({
49
+ args: {
50
+ ...context.args,
51
+ register: useFormResult.register,
52
+ },
53
+ })}
54
+ </FormGroup>
55
+ </Form>
56
+ );
57
+ },
45
58
  ],
46
59
  } as Meta<typeof TextField>;
47
60
 
@@ -51,9 +64,7 @@ const mockError: FieldError = {
51
64
  };
52
65
 
53
66
  export const Basic: StoryObj<typeof TextField> = (args: Args) => {
54
- const { register } = useForm<FieldValues>();
55
-
56
- return <TextField {...args} register={register} />;
67
+ return <TextField {...args} register={args.register} />;
57
68
  };
58
69
  Basic.args = {
59
70
  placeholder: 'Field',
@@ -65,15 +76,13 @@ Basic.args = {
65
76
  helperText: 'some nice text',
66
77
  };
67
78
 
68
- export const WithError: StoryObj<typeof TextField> = () => {
69
- const { register } = useForm<FieldValues>();
70
-
79
+ export const WithError: StoryObj<typeof TextField> = (args: Args) => {
71
80
  return (
72
81
  <TextField
73
82
  placeholder="Field error"
74
83
  label="Field"
75
84
  name="field2"
76
- register={register}
85
+ register={args.register}
77
86
  validationSchema={{
78
87
  required: 'Required',
79
88
  }}
@@ -83,15 +92,13 @@ export const WithError: StoryObj<typeof TextField> = () => {
83
92
  };
84
93
  WithError.args = {};
85
94
 
86
- export const WithSuccess: StoryObj<typeof TextField> = () => {
87
- const { register } = useForm<FieldValues>();
88
-
95
+ export const WithSuccess: StoryObj<typeof TextField> = (args: Args) => {
89
96
  return (
90
97
  <TextField
91
98
  placeholder="Field success"
92
99
  label="Field"
93
100
  name="field3"
94
- register={register}
101
+ register={args.register}
95
102
  validationSchema={{
96
103
  required: 'Required',
97
104
  }}
@@ -102,15 +109,13 @@ export const WithSuccess: StoryObj<typeof TextField> = () => {
102
109
  };
103
110
  WithSuccess.args = {};
104
111
 
105
- export const Disabled: StoryObj<typeof TextField> = () => {
106
- const { register } = useForm<FieldValues>();
107
-
112
+ export const Disabled: StoryObj<typeof TextField> = (args: Args) => {
108
113
  return (
109
114
  <TextField
110
115
  placeholder="Field disabled"
111
116
  label="Field"
112
117
  name="field4"
113
- register={register}
118
+ register={args.register}
114
119
  helperText="some nice text"
115
120
  disabled={true}
116
121
  endElement={<Icon name="visible" size={16} />}
@@ -119,15 +124,13 @@ export const Disabled: StoryObj<typeof TextField> = () => {
119
124
  };
120
125
  Disabled.args = {};
121
126
 
122
- export const WithStatusDisabled: StoryObj<typeof TextField> = () => {
123
- const { register } = useForm<FieldValues>();
124
-
127
+ export const WithStatusDisabled: StoryObj<typeof TextField> = (args: Args) => {
125
128
  return (
126
129
  <TextField
127
130
  placeholder="Field success disabled"
128
131
  label="Field"
129
132
  name="field5"
130
- register={register}
133
+ register={args.register}
131
134
  helperText="some nice text"
132
135
  disabled={true}
133
136
  success={true}
@@ -136,23 +139,21 @@ export const WithStatusDisabled: StoryObj<typeof TextField> = () => {
136
139
  };
137
140
  WithStatusDisabled.args = {};
138
141
 
139
- export const WithAction: StoryObj<typeof TextField> = () => {
140
- const { register } = useForm<FieldValues>();
141
-
142
+ export const WithAction: StoryObj<typeof TextField> = (args: Args) => {
142
143
  return (
143
144
  <TextField
144
145
  type="password"
145
146
  placeholder="Field"
146
147
  label="Field"
147
148
  name="field6"
148
- register={register}
149
+ register={args.register}
149
150
  helperText="some nice text"
150
151
  endElement={
151
152
  <button
153
+ type="submit"
152
154
  onClick={(event) => {
153
- event.stopPropagation();
155
+ console.log('>>>action...');
154
156
  event.preventDefault();
155
- console.log('calling action...');
156
157
  }}>
157
158
  Action
158
159
  </button>
@@ -162,24 +163,20 @@ export const WithAction: StoryObj<typeof TextField> = () => {
162
163
  };
163
164
  WithAction.args = {};
164
165
 
165
- export const MultilineSimple: StoryObj<typeof TextField> = () => {
166
- const { register } = useForm<FieldValues>();
167
-
166
+ export const MultilineSimple: StoryObj<typeof TextField> = (args: Args) => {
168
167
  return (
169
168
  <TextField
170
169
  multirow
171
170
  rows={10}
172
171
  placeholder="Textarea"
173
172
  name="textarea"
174
- register={register}
173
+ register={args.register}
175
174
  />
176
175
  );
177
176
  };
178
177
  MultilineSimple.args = {};
179
178
 
180
- export const Multiline: StoryObj<typeof TextField> = () => {
181
- const { register } = useForm<FieldValues>();
182
-
179
+ export const Multiline: StoryObj<typeof TextField> = (args: Args) => {
183
180
  return (
184
181
  <TextField
185
182
  multirow
@@ -188,15 +185,13 @@ export const Multiline: StoryObj<typeof TextField> = () => {
188
185
  placeholder="Textarea"
189
186
  name="textarea"
190
187
  helperText="some nice text"
191
- register={register}
188
+ register={args.register}
192
189
  />
193
190
  );
194
191
  };
195
192
  Multiline.args = {};
196
193
 
197
- export const MultilineDisabled: StoryObj<typeof TextField> = () => {
198
- const { register } = useForm<FieldValues>();
199
-
194
+ export const MultilineDisabled: StoryObj<typeof TextField> = (args: Args) => {
200
195
  return (
201
196
  <TextField
202
197
  multirow
@@ -205,16 +200,14 @@ export const MultilineDisabled: StoryObj<typeof TextField> = () => {
205
200
  placeholder="Textarea"
206
201
  name="textarea"
207
202
  helperText="some nice text"
208
- register={register}
203
+ register={args.register}
209
204
  />
210
205
  );
211
206
  };
212
207
  MultilineDisabled.args = {};
213
208
 
214
209
  export const Focused: StoryObj<typeof TextField> = (args: Args) => {
215
- const { register } = useForm<FieldValues>();
216
-
217
- return <TextField {...args} register={register} />;
210
+ return <TextField {...args} />;
218
211
  };
219
212
  Focused.args = {
220
213
  ...Basic.args,
@@ -101,3 +101,4 @@ export * from './CollapsibleNavBar';
101
101
  export * from './Filters';
102
102
  export * from './TableFilters';
103
103
  export * from './Typeahead';
104
+ export * from './ImageItem';