@snack-uikit/avatar 0.4.1 → 0.5.0
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/CHANGELOG.md +11 -0
- package/README.md +10 -10
- package/dist/components/Avatar.d.ts +1 -7
- package/dist/components/Avatar.js +10 -14
- package/dist/components/constants.d.ts +23 -23
- package/dist/components/constants.js +23 -26
- package/dist/components/types.d.ts +5 -0
- package/dist/components/types.js +1 -0
- package/package.json +4 -4
- package/src/components/Avatar.tsx +14 -18
- package/src/components/constants.ts +23 -23
- package/src/components/types.ts +9 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# 0.5.0 (2023-12-14)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### BREAKING CHANGES
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
* **FF-3729:** replace enum with unions ([910db4a](https://github.com/cloud-ru-tech/snack-uikit/commit/910db4aa8231ccbc58e538e5c5c1f461b1dec275))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
## 0.4.1 (2023-12-06)
|
|
7
18
|
|
|
8
19
|
### Only dependencies have been changed
|
package/README.md
CHANGED
|
@@ -8,19 +8,19 @@
|
|
|
8
8
|
## Example
|
|
9
9
|
|
|
10
10
|
```typescript jsx
|
|
11
|
-
import {Avatar} from "@snack-uikit/avatar";
|
|
11
|
+
import { Avatar } from "@snack-uikit/avatar";
|
|
12
12
|
|
|
13
|
-
<Avatar
|
|
13
|
+
<Avatar
|
|
14
14
|
name="Name Surname"
|
|
15
15
|
src="path-to-avatar/image.jpg"
|
|
16
|
-
size=
|
|
16
|
+
size='xl'
|
|
17
17
|
/>
|
|
18
18
|
|
|
19
19
|
<Avatar
|
|
20
20
|
name="Name Surname"
|
|
21
|
-
appearance=
|
|
22
|
-
indicator=
|
|
23
|
-
shape=
|
|
21
|
+
appearance='pink'
|
|
22
|
+
indicator='violet'
|
|
23
|
+
shape='square'
|
|
24
24
|
showTwoSymbols={true}
|
|
25
25
|
/>
|
|
26
26
|
```
|
|
@@ -34,10 +34,10 @@ import {Avatar} from "@snack-uikit/avatar";
|
|
|
34
34
|
|------|------|---------------|-------------|
|
|
35
35
|
| name* | `string` | - | Имя |
|
|
36
36
|
| src | `string` | - | src аттрибут изображеня |
|
|
37
|
-
| appearance | enum Appearance: `"red"`, `"orange"`, `"yellow"`, `"green"`, `"blue"`, `"violet"`, `"pink"`, `"neutral"` |
|
|
38
|
-
| size | enum Size: `"xxs"`, `"xs"`, `"s"`, `"m"`, `"l"`, `"xl"`, `"xxl"` |
|
|
39
|
-
| shape | enum Shape: `"round"`, `"square"` |
|
|
40
|
-
| indicator | enum Appearance: `"
|
|
37
|
+
| appearance | enum Appearance: `"red"`, `"orange"`, `"yellow"`, `"green"`, `"blue"`, `"violet"`, `"pink"`, `"neutral"` | red | Внешний вид |
|
|
38
|
+
| size | enum Size: `"xxs"`, `"xs"`, `"s"`, `"m"`, `"l"`, `"xl"`, `"xxl"` | s | Размер |
|
|
39
|
+
| shape | enum Shape: `"round"`, `"square"` | round | Форма: круглая или квадратная |
|
|
40
|
+
| indicator | enum Appearance: `"red"`, `"orange"`, `"yellow"`, `"green"`, `"blue"`, `"violet"`, `"pink"`, `"neutral"`, `"primary"` | - | Индикатор |
|
|
41
41
|
| showTwoSymbols | `boolean` | - | Отображение двух заглавных символов имени |
|
|
42
42
|
| className | `string` | - | CSS-класс |
|
|
43
43
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StatusIndicatorProps } from '@snack-uikit/status';
|
|
2
2
|
import { WithSupportProps } from '@snack-uikit/utils';
|
|
3
|
-
import { Appearance, Shape, Size } from './
|
|
3
|
+
import { Appearance, Shape, Size } from './types';
|
|
4
4
|
export type AvatarProps = WithSupportProps<{
|
|
5
5
|
/** Имя */
|
|
6
6
|
name: string;
|
|
@@ -24,9 +24,3 @@ export type AvatarProps = WithSupportProps<{
|
|
|
24
24
|
* @constructor
|
|
25
25
|
*/
|
|
26
26
|
export declare function Avatar({ name, appearance, size, shape, indicator, showTwoSymbols, src, className, ...rest }: AvatarProps): import("react/jsx-runtime").JSX.Element;
|
|
27
|
-
export declare namespace Avatar {
|
|
28
|
-
var sizes: typeof Size;
|
|
29
|
-
var appearances: typeof Appearance;
|
|
30
|
-
var shapes: typeof Shape;
|
|
31
|
-
var indicators: typeof import("@snack-uikit/status/dist/constants").Appearance;
|
|
32
|
-
}
|
|
@@ -14,32 +14,28 @@ import cn from 'classnames';
|
|
|
14
14
|
import { useEffect, useState } from 'react';
|
|
15
15
|
import { StatusIndicator } from '@snack-uikit/status';
|
|
16
16
|
import { extractSupportProps } from '@snack-uikit/utils';
|
|
17
|
-
import {
|
|
17
|
+
import { APPEARANCE, SHAPE, SIZE } from './constants';
|
|
18
18
|
import styles from './styles.module.css';
|
|
19
19
|
import { getAbbreviation } from './utils';
|
|
20
20
|
const statusIndicatorSizeMap = {
|
|
21
|
-
[
|
|
22
|
-
[
|
|
23
|
-
[
|
|
24
|
-
[
|
|
25
|
-
[
|
|
26
|
-
[
|
|
27
|
-
[
|
|
21
|
+
[SIZE.Xxs]: 'xxs',
|
|
22
|
+
[SIZE.Xs]: 'xs',
|
|
23
|
+
[SIZE.S]: 'xs',
|
|
24
|
+
[SIZE.M]: 'm',
|
|
25
|
+
[SIZE.L]: 'm',
|
|
26
|
+
[SIZE.Xl]: 'l',
|
|
27
|
+
[SIZE.Xxl]: 'l',
|
|
28
28
|
};
|
|
29
29
|
/**
|
|
30
30
|
* Компонент отображения аватара пользователя.
|
|
31
31
|
* @constructor
|
|
32
32
|
*/
|
|
33
33
|
export function Avatar(_a) {
|
|
34
|
-
var { name, appearance =
|
|
34
|
+
var { name, appearance = APPEARANCE.Red, size = SIZE.S, shape = SHAPE.Round, indicator, showTwoSymbols, src, className } = _a, rest = __rest(_a, ["name", "appearance", "size", "shape", "indicator", "showTwoSymbols", "src", "className"]);
|
|
35
35
|
const [imageError, setImageError] = useState(false);
|
|
36
|
-
const numberOfSymbols = size !==
|
|
36
|
+
const numberOfSymbols = size !== SIZE.Xxs && showTwoSymbols ? 2 : 1;
|
|
37
37
|
useEffect(() => {
|
|
38
38
|
setImageError(false);
|
|
39
39
|
}, [src]);
|
|
40
40
|
return (_jsxs("div", Object.assign({ className: cn(styles.avatar, className) }, extractSupportProps(rest), { "data-size": size, "data-appearance": appearance, "data-shape": shape }, { children: [src && !imageError ? (_jsx("img", { "data-test-id": 'image', className: styles.image, src: src, onError: () => setImageError(true), alt: '' })) : (_jsx("div", Object.assign({ "data-test-id": 'abbreviation' }, { children: getAbbreviation(name, numberOfSymbols) }))), indicator && (_jsx("div", Object.assign({ className: styles.indicatorWrapper }, { children: _jsx(StatusIndicator, { "data-test-id": 'indicator', appearance: indicator, size: statusIndicatorSizeMap[size] }) })))] })));
|
|
41
41
|
}
|
|
42
|
-
Avatar.sizes = Size;
|
|
43
|
-
Avatar.appearances = Appearance;
|
|
44
|
-
Avatar.shapes = Shape;
|
|
45
|
-
Avatar.indicators = StatusIndicator.appearances;
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
export declare
|
|
2
|
-
Red
|
|
3
|
-
Orange
|
|
4
|
-
Yellow
|
|
5
|
-
Green
|
|
6
|
-
Blue
|
|
7
|
-
Violet
|
|
8
|
-
Pink
|
|
9
|
-
Neutral
|
|
10
|
-
}
|
|
11
|
-
export declare
|
|
12
|
-
Xxs
|
|
13
|
-
Xs
|
|
14
|
-
S
|
|
15
|
-
M
|
|
16
|
-
L
|
|
17
|
-
Xl
|
|
18
|
-
Xxl
|
|
19
|
-
}
|
|
20
|
-
export declare
|
|
21
|
-
Round
|
|
22
|
-
Square
|
|
23
|
-
}
|
|
1
|
+
export declare const APPEARANCE: {
|
|
2
|
+
readonly Red: "red";
|
|
3
|
+
readonly Orange: "orange";
|
|
4
|
+
readonly Yellow: "yellow";
|
|
5
|
+
readonly Green: "green";
|
|
6
|
+
readonly Blue: "blue";
|
|
7
|
+
readonly Violet: "violet";
|
|
8
|
+
readonly Pink: "pink";
|
|
9
|
+
readonly Neutral: "neutral";
|
|
10
|
+
};
|
|
11
|
+
export declare const SIZE: {
|
|
12
|
+
readonly Xxs: "xxs";
|
|
13
|
+
readonly Xs: "xs";
|
|
14
|
+
readonly S: "s";
|
|
15
|
+
readonly M: "m";
|
|
16
|
+
readonly L: "l";
|
|
17
|
+
readonly Xl: "xl";
|
|
18
|
+
readonly Xxl: "xxl";
|
|
19
|
+
};
|
|
20
|
+
export declare const SHAPE: {
|
|
21
|
+
readonly Round: "round";
|
|
22
|
+
readonly Square: "square";
|
|
23
|
+
};
|
|
@@ -1,26 +1,23 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
Shape["Round"] = "round";
|
|
25
|
-
Shape["Square"] = "square";
|
|
26
|
-
})(Shape || (Shape = {}));
|
|
1
|
+
export const APPEARANCE = {
|
|
2
|
+
Red: 'red',
|
|
3
|
+
Orange: 'orange',
|
|
4
|
+
Yellow: 'yellow',
|
|
5
|
+
Green: 'green',
|
|
6
|
+
Blue: 'blue',
|
|
7
|
+
Violet: 'violet',
|
|
8
|
+
Pink: 'pink',
|
|
9
|
+
Neutral: 'neutral',
|
|
10
|
+
};
|
|
11
|
+
export const SIZE = {
|
|
12
|
+
Xxs: 'xxs',
|
|
13
|
+
Xs: 'xs',
|
|
14
|
+
S: 's',
|
|
15
|
+
M: 'm',
|
|
16
|
+
L: 'l',
|
|
17
|
+
Xl: 'xl',
|
|
18
|
+
Xxl: 'xxl',
|
|
19
|
+
};
|
|
20
|
+
export const SHAPE = {
|
|
21
|
+
Round: 'round',
|
|
22
|
+
Square: 'square',
|
|
23
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
6
|
"title": "Avatar",
|
|
7
|
-
"version": "0.
|
|
7
|
+
"version": "0.5.0",
|
|
8
8
|
"sideEffects": [
|
|
9
9
|
"*.css",
|
|
10
10
|
"*.woff",
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
],
|
|
32
32
|
"license": "Apache-2.0",
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@snack-uikit/status": "0.
|
|
35
|
-
"@snack-uikit/utils": "3.
|
|
34
|
+
"@snack-uikit/status": "0.5.0",
|
|
35
|
+
"@snack-uikit/utils": "3.2.0",
|
|
36
36
|
"classnames": "2.3.2"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "bd39c5e674f3b91b0e2487782a04b15034cf3d8b"
|
|
39
39
|
}
|
|
@@ -4,8 +4,9 @@ import { useEffect, useState } from 'react';
|
|
|
4
4
|
import { StatusIndicator, StatusIndicatorProps } from '@snack-uikit/status';
|
|
5
5
|
import { extractSupportProps, WithSupportProps } from '@snack-uikit/utils';
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { APPEARANCE, SHAPE, SIZE } from './constants';
|
|
8
8
|
import styles from './styles.module.scss';
|
|
9
|
+
import { Appearance, Shape, Size } from './types';
|
|
9
10
|
import { getAbbreviation } from './utils';
|
|
10
11
|
|
|
11
12
|
export type AvatarProps = WithSupportProps<{
|
|
@@ -27,14 +28,14 @@ export type AvatarProps = WithSupportProps<{
|
|
|
27
28
|
className?: string;
|
|
28
29
|
}>;
|
|
29
30
|
|
|
30
|
-
const statusIndicatorSizeMap = {
|
|
31
|
-
[
|
|
32
|
-
[
|
|
33
|
-
[
|
|
34
|
-
[
|
|
35
|
-
[
|
|
36
|
-
[
|
|
37
|
-
[
|
|
31
|
+
const statusIndicatorSizeMap: Record<Size, StatusIndicatorProps['size']> = {
|
|
32
|
+
[SIZE.Xxs]: 'xxs',
|
|
33
|
+
[SIZE.Xs]: 'xs',
|
|
34
|
+
[SIZE.S]: 'xs',
|
|
35
|
+
[SIZE.M]: 'm',
|
|
36
|
+
[SIZE.L]: 'm',
|
|
37
|
+
[SIZE.Xl]: 'l',
|
|
38
|
+
[SIZE.Xxl]: 'l',
|
|
38
39
|
};
|
|
39
40
|
|
|
40
41
|
/**
|
|
@@ -43,9 +44,9 @@ const statusIndicatorSizeMap = {
|
|
|
43
44
|
*/
|
|
44
45
|
export function Avatar({
|
|
45
46
|
name,
|
|
46
|
-
appearance =
|
|
47
|
-
size =
|
|
48
|
-
shape =
|
|
47
|
+
appearance = APPEARANCE.Red,
|
|
48
|
+
size = SIZE.S,
|
|
49
|
+
shape = SHAPE.Round,
|
|
49
50
|
indicator,
|
|
50
51
|
showTwoSymbols,
|
|
51
52
|
src,
|
|
@@ -53,7 +54,7 @@ export function Avatar({
|
|
|
53
54
|
...rest
|
|
54
55
|
}: AvatarProps) {
|
|
55
56
|
const [imageError, setImageError] = useState(false);
|
|
56
|
-
const numberOfSymbols = size !==
|
|
57
|
+
const numberOfSymbols = size !== SIZE.Xxs && showTwoSymbols ? 2 : 1;
|
|
57
58
|
|
|
58
59
|
useEffect(() => {
|
|
59
60
|
setImageError(false);
|
|
@@ -80,8 +81,3 @@ export function Avatar({
|
|
|
80
81
|
</div>
|
|
81
82
|
);
|
|
82
83
|
}
|
|
83
|
-
|
|
84
|
-
Avatar.sizes = Size;
|
|
85
|
-
Avatar.appearances = Appearance;
|
|
86
|
-
Avatar.shapes = Shape;
|
|
87
|
-
Avatar.indicators = StatusIndicator.appearances;
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
export
|
|
2
|
-
Red
|
|
3
|
-
Orange
|
|
4
|
-
Yellow
|
|
5
|
-
Green
|
|
6
|
-
Blue
|
|
7
|
-
Violet
|
|
8
|
-
Pink
|
|
9
|
-
Neutral
|
|
10
|
-
}
|
|
1
|
+
export const APPEARANCE = {
|
|
2
|
+
Red: 'red',
|
|
3
|
+
Orange: 'orange',
|
|
4
|
+
Yellow: 'yellow',
|
|
5
|
+
Green: 'green',
|
|
6
|
+
Blue: 'blue',
|
|
7
|
+
Violet: 'violet',
|
|
8
|
+
Pink: 'pink',
|
|
9
|
+
Neutral: 'neutral',
|
|
10
|
+
} as const;
|
|
11
11
|
|
|
12
|
-
export
|
|
13
|
-
Xxs
|
|
14
|
-
Xs
|
|
15
|
-
S
|
|
16
|
-
M
|
|
17
|
-
L
|
|
18
|
-
Xl
|
|
19
|
-
Xxl
|
|
20
|
-
}
|
|
12
|
+
export const SIZE = {
|
|
13
|
+
Xxs: 'xxs',
|
|
14
|
+
Xs: 'xs',
|
|
15
|
+
S: 's',
|
|
16
|
+
M: 'm',
|
|
17
|
+
L: 'l',
|
|
18
|
+
Xl: 'xl',
|
|
19
|
+
Xxl: 'xxl',
|
|
20
|
+
} as const;
|
|
21
21
|
|
|
22
|
-
export
|
|
23
|
-
Round
|
|
24
|
-
Square
|
|
25
|
-
}
|
|
22
|
+
export const SHAPE = {
|
|
23
|
+
Round: 'round',
|
|
24
|
+
Square: 'square',
|
|
25
|
+
} as const;
|