@snack-uikit/counter 0.4.1 → 0.6.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,28 @@
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.6.0 (2023-12-28)
7
+
8
+
9
+ ### Features
10
+
11
+ * **FF-3960:** add new prop color ([3adaa4c](https://github.com/cloud-ru-tech/snack-uikit/commit/3adaa4c7cc3018607a50446caec2fb62dd680fd3))
12
+
13
+
14
+
15
+
16
+
17
+ # 0.5.0 (2023-12-14)
18
+
19
+
20
+ ### BREAKING CHANGES
21
+
22
+
23
+ * **FF-3729:** replace enum with unions ([910db4a](https://github.com/cloud-ru-tech/snack-uikit/commit/910db4aa8231ccbc58e538e5c5c1f461b1dec275))
24
+
25
+
26
+
27
+
6
28
  ## 0.4.1 (2023-12-06)
7
29
 
8
30
  ### Only dependencies have been changed
@@ -122,7 +144,8 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
122
144
 
123
145
  ## 0.2.6 (2023-06-23)
124
146
 
125
- **Note:** Version bump only for package @snack-uikit/counter
147
+ ### Only dependencies have been changed
148
+ * [@snack-uikit/utils@3.2.0](https://git.sbercloud.tech/sbercloud-ui/tokens-design-system/snack-uikit/-/blob/master/packages/utils/CHANGELOG.md)
126
149
 
127
150
 
128
151
 
package/README.md CHANGED
@@ -8,17 +8,17 @@
8
8
  ## Example
9
9
 
10
10
  ```typescript jsx
11
- import {Counter} from "@snack-uikit/counter";
11
+ import { Counter } from "@snack-uikit/counter";
12
12
 
13
13
  <Counter
14
14
  value={42}
15
- size={Counter.sizes.M}
15
+ size='m'
16
16
  />
17
17
 
18
18
  <Counter
19
19
  value={101}
20
- appearance={Counter.appearances.Critical}
21
- variant={Counter.variants.CountPlus}
20
+ appearance='critical'
21
+ variant='count-plus'
22
22
  plusLimit={100}
23
23
  />
24
24
  ```
@@ -31,11 +31,12 @@ import {Counter} from "@snack-uikit/counter";
31
31
  | name | type | default value | description |
32
32
  |------|------|---------------|-------------|
33
33
  | value* | `number` | - | Значение |
34
- | appearance | enum Appearance: `"primary"`, `"neutral"`, `"red"` | Appearance.Primary | Внешний вид |
35
- | variant | enum Variant: `"count"`, `"count-plus"`, `"count-k"` | Variant.Count | Вариант |
36
- | size | enum Size: `"s"`, `"m"` | Size.S | Размер |
34
+ | appearance | enum Appearance: `"primary"`, `"neutral"`, `"red"` | primary | Внешний вид |
35
+ | variant | enum Variant: `"count"`, `"count-plus"`, `"count-k"` | count | Вариант |
36
+ | size | enum Size: `"s"`, `"m"` | s | Размер |
37
37
  | plusLimit | `number` | 10 | Порог сокращения значения в формат v+. Например `1500` -> `999+` для 1000 |
38
38
  | className | `string` | - | CSS-класс |
39
+ | color | enum Color: `"accent"`, `"decor"` | accent | Семантический цвет |
39
40
 
40
41
 
41
42
  [//]: DOCUMENTATION_SECTION_END
@@ -1,5 +1,5 @@
1
1
  import { WithSupportProps } from '@snack-uikit/utils';
2
- import { Appearance, Size, Variant } from './constants';
2
+ import { Appearance, Color, Size, Variant } from './types';
3
3
  export type CounterProps = WithSupportProps<{
4
4
  /** Значение */
5
5
  value: number;
@@ -13,11 +13,8 @@ export type CounterProps = WithSupportProps<{
13
13
  plusLimit?: number;
14
14
  /** CSS-класс */
15
15
  className?: string;
16
+ /** Семантический цвет */
17
+ color?: Color;
16
18
  }>;
17
19
  /** Компонент счетчик */
18
- export declare function Counter({ value, appearance, variant, size, plusLimit, className, ...rest }: CounterProps): import("react/jsx-runtime").JSX.Element;
19
- export declare namespace Counter {
20
- var appearances: typeof Appearance;
21
- var variants: typeof Variant;
22
- var sizes: typeof Size;
23
- }
20
+ export declare function Counter({ value, appearance, variant, size, plusLimit, color, className, ...rest }: CounterProps): import("react/jsx-runtime").JSX.Element;
@@ -12,15 +12,12 @@ var __rest = (this && this.__rest) || function (s, e) {
12
12
  import { jsx as _jsx } from "react/jsx-runtime";
13
13
  import cn from 'classnames';
14
14
  import { extractSupportProps } from '@snack-uikit/utils';
15
- import { Appearance, DEFAULT_PLUS_LIMIT, Size, Variant } from './constants';
15
+ import { APPEARANCE, COLOR, DEFAULT_PLUS_LIMIT, SIZE, VARIANT } from './constants';
16
16
  import classNames from './styles.module.css';
17
17
  import { formatValue } from './utils';
18
18
  /** Компонент счетчик */
19
19
  export function Counter(_a) {
20
- var { value, appearance = Appearance.Primary, variant = Variant.Count, size = Size.S, plusLimit = DEFAULT_PLUS_LIMIT, className } = _a, rest = __rest(_a, ["value", "appearance", "variant", "size", "plusLimit", "className"]);
20
+ var { value, appearance = APPEARANCE.Primary, variant = VARIANT.Count, size = SIZE.S, plusLimit = DEFAULT_PLUS_LIMIT, color = COLOR.Accent, className } = _a, rest = __rest(_a, ["value", "appearance", "variant", "size", "plusLimit", "color", "className"]);
21
21
  const formattedValue = formatValue({ value, variant, plusLimit });
22
- return (_jsx("div", Object.assign({ className: cn(classNames.counter, className) }, extractSupportProps(rest), { "data-size": size, "data-variant": variant, "data-appearance": appearance }, { children: formattedValue })));
22
+ return (_jsx("div", Object.assign({ className: cn(classNames.counter, className) }, extractSupportProps(rest), { "data-size": size, "data-variant": variant, "data-appearance": appearance, "data-color": color, children: formattedValue })));
23
23
  }
24
- Counter.appearances = Appearance;
25
- Counter.variants = Variant;
26
- Counter.sizes = Size;
@@ -1,17 +1,21 @@
1
- export declare enum Appearance {
2
- Primary = "primary",
3
- Neutral = "neutral",
4
- Red = "red"
5
- }
6
- export declare enum Variant {
7
- Count = "count",
8
- CountPlus = "count-plus",
9
- CountK = "count-k"
10
- }
11
- export declare enum Size {
12
- S = "s",
13
- M = "m"
14
- }
1
+ export declare const APPEARANCE: {
2
+ readonly Primary: "primary";
3
+ readonly Neutral: "neutral";
4
+ readonly Red: "red";
5
+ };
6
+ export declare const VARIANT: {
7
+ readonly Count: "count";
8
+ readonly CountPlus: "count-plus";
9
+ readonly CountK: "count-k";
10
+ };
11
+ export declare const SIZE: {
12
+ readonly S: "s";
13
+ readonly M: "m";
14
+ };
15
+ export declare const COLOR: {
16
+ readonly Accent: "accent";
17
+ readonly Decor: "decor";
18
+ };
15
19
  export declare const DEFAULT_PLUS_LIMIT = 10;
16
20
  export declare const DEFAULT_KEY_LIMIT = 1000;
17
21
  export declare const DEFAULT_KEY_POSTFIX = "K";
@@ -1,20 +1,21 @@
1
- export var Appearance;
2
- (function (Appearance) {
3
- Appearance["Primary"] = "primary";
4
- Appearance["Neutral"] = "neutral";
5
- Appearance["Red"] = "red";
6
- })(Appearance || (Appearance = {}));
7
- export var Variant;
8
- (function (Variant) {
9
- Variant["Count"] = "count";
10
- Variant["CountPlus"] = "count-plus";
11
- Variant["CountK"] = "count-k";
12
- })(Variant || (Variant = {}));
13
- export var Size;
14
- (function (Size) {
15
- Size["S"] = "s";
16
- Size["M"] = "m";
17
- })(Size || (Size = {}));
1
+ export const APPEARANCE = {
2
+ Primary: 'primary',
3
+ Neutral: 'neutral',
4
+ Red: 'red',
5
+ };
6
+ export const VARIANT = {
7
+ Count: 'count',
8
+ CountPlus: 'count-plus',
9
+ CountK: 'count-k',
10
+ };
11
+ export const SIZE = {
12
+ S: 's',
13
+ M: 'm',
14
+ };
15
+ export const COLOR = {
16
+ Accent: 'accent',
17
+ Decor: 'decor',
18
+ };
18
19
  export const DEFAULT_PLUS_LIMIT = 10;
19
20
  export const DEFAULT_KEY_LIMIT = 1000;
20
21
  export const DEFAULT_KEY_POSTFIX = 'K';
@@ -7,21 +7,36 @@
7
7
  width:max-content;
8
8
  border:0 solid transparent;
9
9
  }
10
- .counter[data-appearance=primary]{
10
+ .counter[data-color=accent][data-appearance=primary]{
11
11
  color:var(--sys-primary-on-accent, #fdfbff);
12
12
  background-color:var(--sys-primary-accent-default, #794ed3);
13
13
  border-color:var(--sys-neutral-background1-level, #f9f9f9);
14
14
  }
15
- .counter[data-appearance=neutral]{
15
+ .counter[data-color=accent][data-appearance=neutral]{
16
16
  color:var(--sys-neutral-on-accent, #fdfdfd);
17
17
  background-color:var(--sys-neutral-accent-default, #757575);
18
18
  border-color:var(--sys-neutral-background1-level, #f9f9f9);
19
19
  }
20
- .counter[data-appearance=red]{
20
+ .counter[data-color=accent][data-appearance=red]{
21
21
  color:var(--sys-red-on-accent, #fffbfa);
22
22
  background-color:var(--sys-red-accent-default, #d93f2f);
23
23
  border-color:var(--sys-neutral-background1-level, #f9f9f9);
24
24
  }
25
+ .counter[data-color=decor][data-appearance=primary]{
26
+ color:var(--sys-primary-text-main, #382a62);
27
+ background-color:var(--sys-primary-decor-default, #ebdefd);
28
+ border-color:var(--sys-neutral-background1-level, #f9f9f9);
29
+ }
30
+ .counter[data-color=decor][data-appearance=neutral]{
31
+ color:var(--sys-neutral-text-main, #333333);
32
+ background-color:var(--sys-neutral-decor-default, #dedede);
33
+ border-color:var(--sys-neutral-background1-level, #f9f9f9);
34
+ }
35
+ .counter[data-color=decor][data-appearance=red]{
36
+ color:var(--sys-red-text-main, #621c1e);
37
+ background-color:var(--sys-red-decor-default, #ffd8d0);
38
+ border-color:var(--sys-neutral-background1-level, #f9f9f9);
39
+ }
25
40
  .counter[data-size=s]{
26
41
  font-family:var(--sans-label-s-font-family, SB Sans Interface);
27
42
  font-weight:var(--sans-label-s-font-weight, Semibold);
@@ -0,0 +1,6 @@
1
+ import { ValueOf } from '@snack-uikit/utils';
2
+ import { APPEARANCE, COLOR, SIZE, VARIANT } from './constants';
3
+ export type Appearance = ValueOf<typeof APPEARANCE>;
4
+ export type Size = ValueOf<typeof SIZE>;
5
+ export type Variant = ValueOf<typeof VARIANT>;
6
+ export type Color = ValueOf<typeof COLOR>;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,5 +1,5 @@
1
1
  import { ReactNode } from 'react';
2
- import { Variant } from './constants';
2
+ import { Variant } from './types';
3
3
  export declare function formatValue({ value, variant, plusLimit, }: {
4
4
  value: number;
5
5
  variant: Variant;
@@ -1,14 +1,14 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { DEFAULT_KEY_LIMIT, DEFAULT_KEY_POSTFIX, Variant } from './constants';
2
+ import { DEFAULT_KEY_LIMIT, DEFAULT_KEY_POSTFIX, VARIANT } from './constants';
3
3
  import styles from './styles.module.css';
4
4
  export function formatValue({ value, variant, plusLimit, }) {
5
- if (variant === Variant.Count) {
5
+ if (variant === VARIANT.Count) {
6
6
  return value;
7
7
  }
8
- if (variant === Variant.CountPlus) {
9
- return value < plusLimit ? (value) : (_jsxs(_Fragment, { children: [plusLimit - 1, _jsx("span", Object.assign({ className: styles.plus }, { children: "+" }))] }));
8
+ if (variant === VARIANT.CountPlus) {
9
+ return value < plusLimit ? (value) : (_jsxs(_Fragment, { children: [plusLimit - 1, _jsx("span", { className: styles.plus, children: "+" })] }));
10
10
  }
11
- if (variant === Variant.CountK) {
12
- return value < DEFAULT_KEY_LIMIT ? (value) : (_jsxs(_Fragment, { children: [Math.round(value / DEFAULT_KEY_LIMIT), _jsx("span", Object.assign({ className: styles.key }, { children: DEFAULT_KEY_POSTFIX }))] }));
11
+ if (variant === VARIANT.CountK) {
12
+ return value < DEFAULT_KEY_LIMIT ? (value) : (_jsxs(_Fragment, { children: [Math.round(value / DEFAULT_KEY_LIMIT), _jsx("span", { className: styles.key, children: DEFAULT_KEY_POSTFIX })] }));
13
13
  }
14
14
  }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public"
5
5
  },
6
6
  "title": "Counter",
7
- "version": "0.4.1",
7
+ "version": "0.6.0",
8
8
  "sideEffects": [
9
9
  "*.css",
10
10
  "*.woff",
@@ -32,8 +32,8 @@
32
32
  "license": "Apache-2.0",
33
33
  "scripts": {},
34
34
  "dependencies": {
35
- "@snack-uikit/utils": "3.1.0",
35
+ "@snack-uikit/utils": "3.2.0",
36
36
  "classnames": "2.3.2"
37
37
  },
38
- "gitHead": "76a159dde7baccf49dc7b11e1fd7abc31424b42f"
38
+ "gitHead": "57c597a3eebaf6528c0c61b6b27dd244753de1cf"
39
39
  }
@@ -2,8 +2,9 @@ import cn from 'classnames';
2
2
 
3
3
  import { extractSupportProps, WithSupportProps } from '@snack-uikit/utils';
4
4
 
5
- import { Appearance, DEFAULT_PLUS_LIMIT, Size, Variant } from './constants';
5
+ import { APPEARANCE, COLOR, DEFAULT_PLUS_LIMIT, SIZE, VARIANT } from './constants';
6
6
  import classNames from './styles.module.scss';
7
+ import { Appearance, Color, Size, Variant } from './types';
7
8
  import { formatValue } from './utils';
8
9
 
9
10
  export type CounterProps = WithSupportProps<{
@@ -19,15 +20,18 @@ export type CounterProps = WithSupportProps<{
19
20
  plusLimit?: number;
20
21
  /** CSS-класс */
21
22
  className?: string;
23
+ /** Семантический цвет */
24
+ color?: Color;
22
25
  }>;
23
26
 
24
27
  /** Компонент счетчик */
25
28
  export function Counter({
26
29
  value,
27
- appearance = Appearance.Primary,
28
- variant = Variant.Count,
29
- size = Size.S,
30
+ appearance = APPEARANCE.Primary,
31
+ variant = VARIANT.Count,
32
+ size = SIZE.S,
30
33
  plusLimit = DEFAULT_PLUS_LIMIT,
34
+ color = COLOR.Accent,
31
35
  className,
32
36
  ...rest
33
37
  }: CounterProps) {
@@ -40,12 +44,9 @@ export function Counter({
40
44
  data-size={size}
41
45
  data-variant={variant}
42
46
  data-appearance={appearance}
47
+ data-color={color}
43
48
  >
44
49
  {formattedValue}
45
50
  </div>
46
51
  );
47
52
  }
48
-
49
- Counter.appearances = Appearance;
50
- Counter.variants = Variant;
51
- Counter.sizes = Size;
@@ -1,19 +1,24 @@
1
- export enum Appearance {
2
- Primary = 'primary',
3
- Neutral = 'neutral',
4
- Red = 'red',
5
- }
1
+ export const APPEARANCE = {
2
+ Primary: 'primary',
3
+ Neutral: 'neutral',
4
+ Red: 'red',
5
+ } as const;
6
6
 
7
- export enum Variant {
8
- Count = 'count',
9
- CountPlus = 'count-plus',
10
- CountK = 'count-k',
11
- }
7
+ export const VARIANT = {
8
+ Count: 'count',
9
+ CountPlus: 'count-plus',
10
+ CountK: 'count-k',
11
+ } as const;
12
12
 
13
- export enum Size {
14
- S = 's',
15
- M = 'm',
16
- }
13
+ export const SIZE = {
14
+ S: 's',
15
+ M: 'm',
16
+ } as const;
17
+
18
+ export const COLOR = {
19
+ Accent: 'accent',
20
+ Decor: 'decor',
21
+ } as const;
17
22
 
18
23
  export const DEFAULT_PLUS_LIMIT = 10;
19
24
  export const DEFAULT_KEY_LIMIT = 1000;
@@ -3,6 +3,7 @@
3
3
  $appearances: 'primary', 'neutral', 'red';
4
4
  $sizes: 's', 'm';
5
5
  $variants: 'count', 'count-plus', 'count-k';
6
+ $colors: 'accent', 'decor';
6
7
 
7
8
  $value-typography: (
8
9
  s: $sans-label-s,
@@ -16,6 +17,14 @@ $key-typography: (
16
17
  s: $sans-label-s,
17
18
  m: $sans-label-l
18
19
  );
20
+ $text-color: (
21
+ accent: 'on-accent',
22
+ decor: 'text-main'
23
+ );
24
+ $bg-color: (
25
+ accent: 'accent-default',
26
+ decor: 'decor-default'
27
+ );
19
28
 
20
29
  .counter {
21
30
  display: inline-flex;
@@ -27,11 +36,18 @@ $key-typography: (
27
36
 
28
37
  border: 0 solid transparent;
29
38
 
30
- @each $appearance in $appearances {
31
- &[data-appearance='#{$appearance}'] {
32
- color: simple-var($theme-variables, 'sys', $appearance, 'on-accent');
33
- background-color: simple-var($theme-variables, 'sys', $appearance, 'accent-default');
34
- border-color: $sys-neutral-background1-level;
39
+ @each $color in $colors {
40
+ @each $appearance in $appearances {
41
+ &[data-color='#{$color}'] {
42
+ &[data-appearance='#{$appearance}'] {
43
+ $text: simple-var($text-color, $color);
44
+ $background: simple-var($bg-color, $color);
45
+
46
+ color: simple-var($theme-variables, 'sys', $appearance, $text);
47
+ background-color: simple-var($theme-variables, 'sys', $appearance, $background);
48
+ border-color: $sys-neutral-background1-level;
49
+ }
50
+ }
35
51
  }
36
52
  }
37
53
 
@@ -0,0 +1,8 @@
1
+ import { ValueOf } from '@snack-uikit/utils';
2
+
3
+ import { APPEARANCE, COLOR, SIZE, VARIANT } from './constants';
4
+
5
+ export type Appearance = ValueOf<typeof APPEARANCE>;
6
+ export type Size = ValueOf<typeof SIZE>;
7
+ export type Variant = ValueOf<typeof VARIANT>;
8
+ export type Color = ValueOf<typeof COLOR>;
@@ -1,7 +1,8 @@
1
1
  import { ReactNode } from 'react';
2
2
 
3
- import { DEFAULT_KEY_LIMIT, DEFAULT_KEY_POSTFIX, Variant } from './constants';
3
+ import { DEFAULT_KEY_LIMIT, DEFAULT_KEY_POSTFIX, VARIANT } from './constants';
4
4
  import styles from './styles.module.scss';
5
+ import { Variant } from './types';
5
6
 
6
7
  export function formatValue({
7
8
  value,
@@ -12,11 +13,11 @@ export function formatValue({
12
13
  variant: Variant;
13
14
  plusLimit: number;
14
15
  }): ReactNode {
15
- if (variant === Variant.Count) {
16
+ if (variant === VARIANT.Count) {
16
17
  return value;
17
18
  }
18
19
 
19
- if (variant === Variant.CountPlus) {
20
+ if (variant === VARIANT.CountPlus) {
20
21
  return value < plusLimit ? (
21
22
  value
22
23
  ) : (
@@ -27,7 +28,7 @@ export function formatValue({
27
28
  );
28
29
  }
29
30
 
30
- if (variant === Variant.CountK) {
31
+ if (variant === VARIANT.CountK) {
31
32
  return value < DEFAULT_KEY_LIMIT ? (
32
33
  value
33
34
  ) : (