@snack-uikit/counter
Advanced tools
Comparing version 0.4.1 to 0.5.0
@@ -6,2 +6,13 @@ # Change Log | ||
# 0.5.0 (2023-12-14) | ||
### BREAKING CHANGES | ||
* **FF-3729:** replace enum with unions ([910db4a](https://github.com/cloud-ru-tech/snack-uikit/commit/910db4aa8231ccbc58e538e5c5c1f461b1dec275)) | ||
## 0.4.1 (2023-12-06) | ||
@@ -126,3 +137,4 @@ | ||
**Note:** Version bump only for package @snack-uikit/counter | ||
### Only dependencies have been changed | ||
* [@snack-uikit/utils@3.2.0](https://git.sbercloud.tech/sbercloud-ui/tokens-design-system/snack-uikit/-/blob/master/packages/utils/CHANGELOG.md) | ||
@@ -129,0 +141,0 @@ |
@@ -1,17 +0,17 @@ | ||
export declare enum Appearance { | ||
Primary = "primary", | ||
Neutral = "neutral", | ||
Red = "red" | ||
} | ||
export declare enum Variant { | ||
Count = "count", | ||
CountPlus = "count-plus", | ||
CountK = "count-k" | ||
} | ||
export declare enum Size { | ||
S = "s", | ||
M = "m" | ||
} | ||
export declare const APPEARANCE: { | ||
readonly Primary: "primary"; | ||
readonly Neutral: "neutral"; | ||
readonly Red: "red"; | ||
}; | ||
export declare const VARIANT: { | ||
readonly Count: "count"; | ||
readonly CountPlus: "count-plus"; | ||
readonly CountK: "count-k"; | ||
}; | ||
export declare const SIZE: { | ||
readonly S: "s"; | ||
readonly M: "m"; | ||
}; | ||
export declare const DEFAULT_PLUS_LIMIT = 10; | ||
export declare const DEFAULT_KEY_LIMIT = 1000; | ||
export declare const DEFAULT_KEY_POSTFIX = "K"; |
@@ -1,20 +0,17 @@ | ||
export var Appearance; | ||
(function (Appearance) { | ||
Appearance["Primary"] = "primary"; | ||
Appearance["Neutral"] = "neutral"; | ||
Appearance["Red"] = "red"; | ||
})(Appearance || (Appearance = {})); | ||
export var Variant; | ||
(function (Variant) { | ||
Variant["Count"] = "count"; | ||
Variant["CountPlus"] = "count-plus"; | ||
Variant["CountK"] = "count-k"; | ||
})(Variant || (Variant = {})); | ||
export var Size; | ||
(function (Size) { | ||
Size["S"] = "s"; | ||
Size["M"] = "m"; | ||
})(Size || (Size = {})); | ||
export const APPEARANCE = { | ||
Primary: 'primary', | ||
Neutral: 'neutral', | ||
Red: 'red', | ||
}; | ||
export const VARIANT = { | ||
Count: 'count', | ||
CountPlus: 'count-plus', | ||
CountK: 'count-k', | ||
}; | ||
export const SIZE = { | ||
S: 's', | ||
M: 'm', | ||
}; | ||
export const DEFAULT_PLUS_LIMIT = 10; | ||
export const DEFAULT_KEY_LIMIT = 1000; | ||
export const DEFAULT_KEY_POSTFIX = 'K'; |
import { WithSupportProps } from '@snack-uikit/utils'; | ||
import { Appearance, Size, Variant } from './constants'; | ||
import { Appearance, Size, Variant } from './types'; | ||
export type CounterProps = WithSupportProps<{ | ||
@@ -19,6 +19,1 @@ /** Значение */ | ||
export declare function Counter({ value, appearance, variant, size, plusLimit, className, ...rest }: CounterProps): import("react/jsx-runtime").JSX.Element; | ||
export declare namespace Counter { | ||
var appearances: typeof Appearance; | ||
var variants: typeof Variant; | ||
var sizes: typeof Size; | ||
} |
@@ -15,3 +15,3 @@ var __rest = (this && this.__rest) || function (s, e) { | ||
import { extractSupportProps } from '@snack-uikit/utils'; | ||
import { Appearance, DEFAULT_PLUS_LIMIT, Size, Variant } from './constants'; | ||
import { APPEARANCE, DEFAULT_PLUS_LIMIT, SIZE, VARIANT } from './constants'; | ||
import classNames from './styles.module.css'; | ||
@@ -21,8 +21,5 @@ import { formatValue } from './utils'; | ||
export function Counter(_a) { | ||
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"]); | ||
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"]); | ||
const formattedValue = formatValue({ value, variant, plusLimit }); | ||
return (_jsx("div", Object.assign({ className: cn(classNames.counter, className) }, extractSupportProps(rest), { "data-size": size, "data-variant": variant, "data-appearance": appearance }, { children: formattedValue }))); | ||
} | ||
Counter.appearances = Appearance; | ||
Counter.variants = Variant; | ||
Counter.sizes = Size; |
import { ReactNode } from 'react'; | ||
import { Variant } from './constants'; | ||
import { Variant } from './types'; | ||
export declare function formatValue({ value, variant, plusLimit, }: { | ||
@@ -4,0 +4,0 @@ value: number; |
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime"; | ||
import { DEFAULT_KEY_LIMIT, DEFAULT_KEY_POSTFIX, Variant } from './constants'; | ||
import { DEFAULT_KEY_LIMIT, DEFAULT_KEY_POSTFIX, VARIANT } from './constants'; | ||
import styles from './styles.module.css'; | ||
export function formatValue({ value, variant, plusLimit, }) { | ||
if (variant === Variant.Count) { | ||
if (variant === VARIANT.Count) { | ||
return value; | ||
} | ||
if (variant === Variant.CountPlus) { | ||
if (variant === VARIANT.CountPlus) { | ||
return value < plusLimit ? (value) : (_jsxs(_Fragment, { children: [plusLimit - 1, _jsx("span", Object.assign({ className: styles.plus }, { children: "+" }))] })); | ||
} | ||
if (variant === Variant.CountK) { | ||
if (variant === VARIANT.CountK) { | ||
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 }))] })); | ||
} | ||
} |
@@ -7,3 +7,3 @@ { | ||
"title": "Counter", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"sideEffects": [ | ||
@@ -36,6 +36,6 @@ "*.css", | ||
"dependencies": { | ||
"@snack-uikit/utils": "3.1.0", | ||
"@snack-uikit/utils": "3.2.0", | ||
"classnames": "2.3.2" | ||
}, | ||
"gitHead": "76a159dde7baccf49dc7b11e1fd7abc31424b42f" | ||
"gitHead": "bd39c5e674f3b91b0e2487782a04b15034cf3d8b" | ||
} |
@@ -11,7 +11,7 @@ # Counter | ||
```typescript jsx | ||
import {Counter} from "@snack-uikit/counter"; | ||
import { Counter } from "@snack-uikit/counter"; | ||
<Counter | ||
value={42} | ||
size={Counter.sizes.M} | ||
size='m' | ||
/> | ||
@@ -21,4 +21,4 @@ | ||
value={101} | ||
appearance={Counter.appearances.Critical} | ||
variant={Counter.variants.CountPlus} | ||
appearance='critical' | ||
variant='count-plus' | ||
plusLimit={100} | ||
@@ -36,5 +36,5 @@ /> | ||
| value* | `number` | - | Значение | | ||
| appearance | enum Appearance: `"primary"`, `"neutral"`, `"red"` | Appearance.Primary | Внешний вид | | ||
| variant | enum Variant: `"count"`, `"count-plus"`, `"count-k"` | Variant.Count | Вариант | | ||
| size | enum Size: `"s"`, `"m"` | Size.S | Размер | | ||
| appearance | enum Appearance: `"primary"`, `"neutral"`, `"red"` | primary | Внешний вид | | ||
| variant | enum Variant: `"count"`, `"count-plus"`, `"count-k"` | count | Вариант | | ||
| size | enum Size: `"s"`, `"m"` | s | Размер | | ||
| plusLimit | `number` | 10 | Порог сокращения значения в формат v+. Например `1500` -> `999+` для 1000 | | ||
@@ -41,0 +41,0 @@ | className | `string` | - | CSS-класс | |
@@ -1,17 +0,17 @@ | ||
export enum Appearance { | ||
Primary = 'primary', | ||
Neutral = 'neutral', | ||
Red = 'red', | ||
} | ||
export const APPEARANCE = { | ||
Primary: 'primary', | ||
Neutral: 'neutral', | ||
Red: 'red', | ||
} as const; | ||
export enum Variant { | ||
Count = 'count', | ||
CountPlus = 'count-plus', | ||
CountK = 'count-k', | ||
} | ||
export const VARIANT = { | ||
Count: 'count', | ||
CountPlus: 'count-plus', | ||
CountK: 'count-k', | ||
} as const; | ||
export enum Size { | ||
S = 's', | ||
M = 'm', | ||
} | ||
export const SIZE = { | ||
S: 's', | ||
M: 'm', | ||
} as const; | ||
@@ -18,0 +18,0 @@ export const DEFAULT_PLUS_LIMIT = 10; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30777
25
8
294
+ Added@snack-uikit/utils@3.2.0(transitive)
- Removed@snack-uikit/utils@3.1.0(transitive)
Updated@snack-uikit/utils@3.2.0