@snack-uikit/avatar 0.4.1 → 0.5.1-preview-993a9cfb.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 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={Avatar.sizes.Xl}
16
+ size='xl'
17
17
  />
18
18
 
19
19
  <Avatar
20
20
  name="Name Surname"
21
- appearance={Avatar.appearances.Pink}
22
- indicator={Avatar.indicators.Violet}
23
- shape={Avatar.shapes.Square}
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"` | Avatar.appearances.Red | Внешний вид |
38
- | size | enum Size: `"xxs"`, `"xs"`, `"s"`, `"m"`, `"l"`, `"xl"`, `"xxl"` | Avatar.sizes.S | Размер |
39
- | shape | enum Shape: `"round"`, `"square"` | Avatar.shapes.Round | Форма: круглая или квадратная |
40
- | indicator | enum Appearance: `"primary"`, `"neutral"`, `"red"`, `"orange"`, `"yellow"`, `"green"`, `"blue"`, `"violet"`, `"pink"` | - | Индикатор |
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 './constants';
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 { Appearance, Shape, Size } from './constants';
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
- [Size.Xxs]: StatusIndicator.sizes.Xxs,
22
- [Size.Xs]: StatusIndicator.sizes.Xs,
23
- [Size.S]: StatusIndicator.sizes.Xs,
24
- [Size.M]: StatusIndicator.sizes.M,
25
- [Size.L]: StatusIndicator.sizes.M,
26
- [Size.Xl]: StatusIndicator.sizes.L,
27
- [Size.Xxl]: StatusIndicator.sizes.L,
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 = Avatar.appearances.Red, size = Avatar.sizes.S, shape = Avatar.shapes.Round, indicator, showTwoSymbols, src, className } = _a, rest = __rest(_a, ["name", "appearance", "size", "shape", "indicator", "showTwoSymbols", "src", "className"]);
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 !== Size.Xxs && showTwoSymbols ? 2 : 1;
36
+ const numberOfSymbols = size !== SIZE.Xxs && showTwoSymbols ? 2 : 1;
37
37
  useEffect(() => {
38
38
  setImageError(false);
39
39
  }, [src]);
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] }) })))] })));
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", { "data-test-id": 'abbreviation', children: getAbbreviation(name, numberOfSymbols) })), indicator && (_jsx("div", { 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 enum 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 declare enum 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 declare enum Shape {
21
- Round = "round",
22
- Square = "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 var Appearance;
2
- (function (Appearance) {
3
- Appearance["Red"] = "red";
4
- Appearance["Orange"] = "orange";
5
- Appearance["Yellow"] = "yellow";
6
- Appearance["Green"] = "green";
7
- Appearance["Blue"] = "blue";
8
- Appearance["Violet"] = "violet";
9
- Appearance["Pink"] = "pink";
10
- Appearance["Neutral"] = "neutral";
11
- })(Appearance || (Appearance = {}));
12
- export var Size;
13
- (function (Size) {
14
- Size["Xxs"] = "xxs";
15
- Size["Xs"] = "xs";
16
- Size["S"] = "s";
17
- Size["M"] = "m";
18
- Size["L"] = "l";
19
- Size["Xl"] = "xl";
20
- Size["Xxl"] = "xxl";
21
- })(Size || (Size = {}));
22
- export var Shape;
23
- (function (Shape) {
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
+ };
@@ -6,36 +6,36 @@
6
6
  justify-content:center;
7
7
  }
8
8
  .avatar[data-appearance=red]{
9
- color:var(--sys-red-text-main, #621c1e);
10
- background-color:var(--sys-red-decor-default, #ffd8d0);
9
+ color:var(--sys-red-text-main, #621c1b);
10
+ background-color:var(--sys-red-decor-default, #fdd6cd);
11
11
  }
12
12
  .avatar[data-appearance=orange]{
13
- color:var(--sys-orange-text-main, #572212);
14
- background-color:var(--sys-orange-decor-default, #fedeaf);
13
+ color:var(--sys-orange-text-main, #643117);
14
+ background-color:var(--sys-orange-decor-default, #fed8b8);
15
15
  }
16
16
  .avatar[data-appearance=yellow]{
17
- color:var(--sys-yellow-text-main, #54290f);
18
- background-color:var(--sys-yellow-decor-default, #f9e5ad);
17
+ color:var(--sys-yellow-text-main, #5e3d06);
18
+ background-color:var(--sys-yellow-decor-default, #f0dfb1);
19
19
  }
20
20
  .avatar[data-appearance=green]{
21
- color:var(--sys-green-text-main, #1f392a);
22
- background-color:var(--sys-green-decor-default, #cdebe3);
21
+ color:var(--sys-green-text-main, #323f27);
22
+ background-color:var(--sys-green-decor-default, #d2ead0);
23
23
  }
24
24
  .avatar[data-appearance=blue]{
25
- color:var(--sys-blue-text-main, #1f3361);
26
- background-color:var(--sys-blue-decor-default, #d5e7f6);
25
+ color:var(--sys-blue-text-main, #153a61);
26
+ background-color:var(--sys-blue-decor-default, #d6e2f4);
27
27
  }
28
28
  .avatar[data-appearance=violet]{
29
- color:var(--sys-violet-text-main, #51255f);
30
- background-color:var(--sys-violet-decor-default, #f8dffc);
29
+ color:var(--sys-violet-text-main, #502e56);
30
+ background-color:var(--sys-violet-decor-default, #efd9ef);
31
31
  }
32
32
  .avatar[data-appearance=pink]{
33
- color:var(--sys-pink-text-main, #5e1937);
34
- background-color:var(--sys-pink-decor-default, #fddde7);
33
+ color:var(--sys-pink-text-main, #5e2540);
34
+ background-color:var(--sys-pink-decor-default, #f5d9e1);
35
35
  }
36
36
  .avatar[data-appearance=neutral]{
37
- color:var(--sys-neutral-text-main, #333333);
38
- background-color:var(--sys-neutral-decor-default, #dedede);
37
+ color:var(--sys-neutral-text-main, #33333b);
38
+ background-color:var(--sys-neutral-decor-default, #dfe2ec);
39
39
  }
40
40
  .avatar[data-size=xxs]{
41
41
  font-family:var(--sans-label-s-font-family, SB Sans Interface);
@@ -0,0 +1,5 @@
1
+ import { ValueOf } from '@snack-uikit/utils';
2
+ import { APPEARANCE, SHAPE, SIZE } from './constants';
3
+ export type Appearance = ValueOf<typeof APPEARANCE>;
4
+ export type Size = ValueOf<typeof SIZE>;
5
+ export type Shape = ValueOf<typeof SHAPE>;
@@ -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.4.1",
7
+ "version": "0.5.1-preview-993a9cfb.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.4.1",
35
- "@snack-uikit/utils": "3.1.0",
34
+ "@snack-uikit/status": "0.5.1-preview-993a9cfb.0",
35
+ "@snack-uikit/utils": "3.2.0",
36
36
  "classnames": "2.3.2"
37
37
  },
38
- "gitHead": "76a159dde7baccf49dc7b11e1fd7abc31424b42f"
38
+ "gitHead": "a421965dc78af63a8c292e595b3f0a8ff1be86f9"
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 { Appearance, Shape, Size } from './constants';
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
- [Size.Xxs]: StatusIndicator.sizes.Xxs,
32
- [Size.Xs]: StatusIndicator.sizes.Xs,
33
- [Size.S]: StatusIndicator.sizes.Xs,
34
- [Size.M]: StatusIndicator.sizes.M,
35
- [Size.L]: StatusIndicator.sizes.M,
36
- [Size.Xl]: StatusIndicator.sizes.L,
37
- [Size.Xxl]: StatusIndicator.sizes.L,
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 = Avatar.appearances.Red,
47
- size = Avatar.sizes.S,
48
- shape = Avatar.shapes.Round,
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 !== Size.Xxs && showTwoSymbols ? 2 : 1;
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 enum 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
- }
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 enum Size {
13
- Xxs = 'xxs',
14
- Xs = 'xs',
15
- S = 's',
16
- M = 'm',
17
- L = 'l',
18
- Xl = 'xl',
19
- Xxl = '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 enum Shape {
23
- Round = 'round',
24
- Square = 'square',
25
- }
22
+ export const SHAPE = {
23
+ Round: 'round',
24
+ Square: 'square',
25
+ } as const;
@@ -0,0 +1,9 @@
1
+ import { ValueOf } from '@snack-uikit/utils';
2
+
3
+ import { APPEARANCE, SHAPE, SIZE } from './constants';
4
+
5
+ export type Appearance = ValueOf<typeof APPEARANCE>;
6
+
7
+ export type Size = ValueOf<typeof SIZE>;
8
+
9
+ export type Shape = ValueOf<typeof SHAPE>;