@wallarm-org/design-system 1.2.0 → 1.4.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.
@@ -0,0 +1,32 @@
1
+ import type { FC, HTMLAttributes, Ref } from 'react';
2
+ import type { TestableProps } from '../../utils/testId';
3
+ type FormatNumberNotation = 'compact' | 'standard';
4
+ type FormatNumberType = 'decimal' | 'percent' | 'byte';
5
+ interface FormatNumberBaseProps {
6
+ /** Numeric value to display. null/undefined renders em dash + "No data" tooltip. */
7
+ value: number | null | undefined;
8
+ /**
9
+ * Formatting category. Default: 'decimal'.
10
+ * - 'decimal': plain number with optional abbreviation
11
+ * - 'percent': percentage with boundary safety
12
+ * - 'byte': decimal byte units: 512 B, 2.3 GB
13
+ */
14
+ type?: FormatNumberType;
15
+ /**
16
+ * 'compact' abbreviates (12k, 59.6M); 'standard' shows full value.
17
+ * Default: 'compact'. Only applies to type='decimal' and type='byte'.
18
+ */
19
+ notation?: FormatNumberNotation;
20
+ /**
21
+ * Unit label for accessible name + tooltip: "requests", "errors".
22
+ * Appended after a space. Only meaningful for type='decimal'.
23
+ */
24
+ unit?: string;
25
+ /** Decimal places for percent. Default: 0. */
26
+ decimals?: number;
27
+ ref?: Ref<HTMLSpanElement>;
28
+ }
29
+ type FormatNumberNativeProps = Omit<HTMLAttributes<HTMLSpanElement>, 'className'>;
30
+ export type FormatNumberProps = FormatNumberNativeProps & FormatNumberBaseProps & TestableProps;
31
+ export declare const FormatNumber: FC<FormatNumberProps>;
32
+ export {};
@@ -0,0 +1,122 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { abbreviateNumber, formatBytes, formatFullNumber, formatPercent } from "../../utils/abbreviateNumber.js";
3
+ import { cn } from "../../utils/cn.js";
4
+ import { Text } from "../Text/index.js";
5
+ import { Tooltip, TooltipContent, TooltipTrigger } from "../Tooltip/index.js";
6
+ const DASHED_UNDERLINE = 'border-b-1 border-dashed border-border-strong-primary';
7
+ const FormatNumber = ({ value, type = 'decimal', notation = 'compact', unit, decimals = 0, ref, ...props })=>{
8
+ if (null == value) return /*#__PURE__*/ jsxs(Tooltip, {
9
+ children: [
10
+ /*#__PURE__*/ jsx(TooltipTrigger, {
11
+ asChild: true,
12
+ children: /*#__PURE__*/ jsx("span", {
13
+ ref: ref,
14
+ "data-slot": "format-number",
15
+ ...props,
16
+ children: /*#__PURE__*/ jsx(Text, {
17
+ size: "sm",
18
+ color: "secondary",
19
+ children: "—"
20
+ })
21
+ })
22
+ }),
23
+ /*#__PURE__*/ jsx(TooltipContent, {
24
+ children: "No data"
25
+ })
26
+ ]
27
+ });
28
+ if (!Number.isFinite(value)) return /*#__PURE__*/ jsx("span", {
29
+ ref: ref,
30
+ "data-slot": "format-number",
31
+ ...props,
32
+ children: /*#__PURE__*/ jsx(Text, {
33
+ size: "sm",
34
+ color: "secondary",
35
+ children: "—"
36
+ })
37
+ });
38
+ if ('percent' === type) return /*#__PURE__*/ jsx("span", {
39
+ ref: ref,
40
+ "data-slot": "format-number",
41
+ ...props,
42
+ children: /*#__PURE__*/ jsx(Text, {
43
+ size: "sm",
44
+ children: formatPercent(value, decimals)
45
+ })
46
+ });
47
+ if ('byte' === type) {
48
+ const { display, full } = formatBytes(value);
49
+ const isAbbreviated = 'compact' === notation && value >= 1000;
50
+ if (isAbbreviated) return /*#__PURE__*/ jsxs(Tooltip, {
51
+ children: [
52
+ /*#__PURE__*/ jsx(TooltipTrigger, {
53
+ asChild: true,
54
+ children: /*#__PURE__*/ jsx("span", {
55
+ ref: ref,
56
+ "data-slot": "format-number",
57
+ "aria-label": full,
58
+ ...props,
59
+ children: /*#__PURE__*/ jsx(Text, {
60
+ size: "sm",
61
+ children: /*#__PURE__*/ jsx("span", {
62
+ className: cn('whitespace-nowrap tabular-nums', DASHED_UNDERLINE),
63
+ children: display
64
+ })
65
+ })
66
+ })
67
+ }),
68
+ /*#__PURE__*/ jsx(TooltipContent, {
69
+ children: full
70
+ })
71
+ ]
72
+ });
73
+ return /*#__PURE__*/ jsx("span", {
74
+ ref: ref,
75
+ "data-slot": "format-number",
76
+ ...props,
77
+ children: /*#__PURE__*/ jsx(Text, {
78
+ size: "sm",
79
+ children: full
80
+ })
81
+ });
82
+ }
83
+ const abbreviated = abbreviateNumber(value);
84
+ const fullValue = formatFullNumber(value);
85
+ const isAbbreviated = 'compact' === notation && Math.abs(value) >= 1000;
86
+ const fullWithUnit = unit ? `${fullValue}\u00A0${unit}` : fullValue;
87
+ if (isAbbreviated) return /*#__PURE__*/ jsxs(Tooltip, {
88
+ children: [
89
+ /*#__PURE__*/ jsx(TooltipTrigger, {
90
+ asChild: true,
91
+ children: /*#__PURE__*/ jsx("span", {
92
+ ref: ref,
93
+ "data-slot": "format-number",
94
+ "aria-label": fullWithUnit,
95
+ ...props,
96
+ children: /*#__PURE__*/ jsx(Text, {
97
+ size: "sm",
98
+ children: /*#__PURE__*/ jsx("span", {
99
+ className: cn('whitespace-nowrap tabular-nums', DASHED_UNDERLINE),
100
+ children: abbreviated
101
+ })
102
+ })
103
+ })
104
+ }),
105
+ /*#__PURE__*/ jsx(TooltipContent, {
106
+ children: fullWithUnit
107
+ })
108
+ ]
109
+ });
110
+ const displayValue = unit ? `${fullValue}\u00A0${unit}` : fullValue;
111
+ return /*#__PURE__*/ jsx("span", {
112
+ ref: ref,
113
+ "data-slot": "format-number",
114
+ ...props,
115
+ children: /*#__PURE__*/ jsx(Text, {
116
+ size: "sm",
117
+ children: displayValue
118
+ })
119
+ });
120
+ };
121
+ FormatNumber.displayName = 'FormatNumber';
122
+ export { FormatNumber };
@@ -0,0 +1 @@
1
+ export { FormatNumber, type FormatNumberProps } from './FormatNumber';
@@ -0,0 +1 @@
1
+ export { FormatNumber } from "./FormatNumber.js";
@@ -0,0 +1,12 @@
1
+ import type { FC, HTMLAttributes, Ref } from 'react';
2
+ import type { VariantProps } from 'class-variance-authority';
3
+ import type { TestableProps } from '../../utils/testId';
4
+ import { indicatorVariants } from './classes';
5
+ type IndicatorNativeProps = HTMLAttributes<HTMLSpanElement>;
6
+ type IndicatorVariantProps = VariantProps<typeof indicatorVariants>;
7
+ interface IndicatorBaseProps {
8
+ ref?: Ref<HTMLSpanElement>;
9
+ }
10
+ export type IndicatorProps = IndicatorNativeProps & IndicatorVariantProps & IndicatorBaseProps & TestableProps;
11
+ export declare const Indicator: FC<IndicatorProps>;
12
+ export {};
@@ -0,0 +1,14 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { cn } from "../../utils/cn.js";
3
+ import { indicatorVariants } from "./classes.js";
4
+ const Indicator = ({ ref, className, size = 'md', color = 'info', ...props })=>/*#__PURE__*/ jsx("span", {
5
+ ...props,
6
+ ref: ref,
7
+ className: cn(indicatorVariants({
8
+ size,
9
+ color
10
+ }), className),
11
+ "data-slot": "indicator"
12
+ });
13
+ Indicator.displayName = 'Indicator';
14
+ export { Indicator };
@@ -0,0 +1,4 @@
1
+ export declare const indicatorVariants: (props?: ({
2
+ size?: "md" | "sm" | null | undefined;
3
+ color?: "ai" | "brand" | "danger" | "info" | "success" | "warning" | null | undefined;
4
+ } & import("class-variance-authority/types").ClassProp) | undefined) => string;
@@ -0,0 +1,22 @@
1
+ import { cva } from "class-variance-authority";
2
+ const indicatorVariants = cva('inline-block shrink-0 rounded-2', {
3
+ variants: {
4
+ size: {
5
+ sm: 'size-6',
6
+ md: 'size-8'
7
+ },
8
+ color: {
9
+ info: 'bg-icon-info',
10
+ brand: 'bg-icon-brand',
11
+ warning: 'bg-icon-warning',
12
+ success: 'bg-icon-success',
13
+ ai: 'bg-icon-ai',
14
+ danger: 'bg-icon-danger'
15
+ }
16
+ },
17
+ defaultVariants: {
18
+ size: 'md',
19
+ color: 'info'
20
+ }
21
+ });
22
+ export { indicatorVariants };
@@ -0,0 +1 @@
1
+ export { Indicator, type IndicatorProps } from './Indicator';
@@ -0,0 +1 @@
1
+ export { Indicator } from "./Indicator.js";
package/dist/index.d.ts CHANGED
@@ -36,8 +36,10 @@ export { Field, FieldContent, FieldDescription, FieldError, FieldGroup, FieldLab
36
36
  export { type Condition, type ExprNode, type FieldMetadata, type FieldType, FilterInput, FilterInputChip, type FilterInputChipData, type FilterInputChipProps, type FilterInputChipVariant, FilterInputFieldMenu, type FilterInputFieldMenuProps, FilterInputOperatorMenu, type FilterInputOperatorMenuProps, type FilterInputProps, type FilterOperator, type Group, } from './components/FilterInput';
37
37
  export { Flex, type FlexProps } from './components/Flex';
38
38
  export { FormatDateTime, type FormatDateTimeProps } from './components/FormatDateTime';
39
+ export { FormatNumber, type FormatNumberProps } from './components/FormatNumber';
39
40
  export { Heading, type HeadingProps } from './components/Heading';
40
41
  export { HTTP_METHOD_COLOR, HTTP_METHODS, HttpMethod, type HttpMethodName, type HttpMethodProps, } from './components/HttpMethod';
42
+ export { Indicator, type IndicatorProps } from './components/Indicator';
41
43
  export { InlineEdit, type InlineEditActivationMode, type InlineEditContextValue, InlineEditControl, type InlineEditControlProps, InlineEditDate, type InlineEditDateProps, InlineEditDateTime, type InlineEditDateTimeProps, InlineEditError, type InlineEditErrorProps, InlineEditInput, type InlineEditInputProps, InlineEditNumber, type InlineEditNumberProps, InlineEditPreview, InlineEditPreviewIcon, type InlineEditPreviewIconProps, type InlineEditPreviewProps, InlineEditPreviewValue, type InlineEditPreviewValueProps, type InlineEditProps, InlineEditSelect, type InlineEditSelectProps, type InlineEditStatus, type InlineEditSubmitMode, InlineEditTextarea, type InlineEditTextareaProps, InlineEditTime, type InlineEditTimeProps, toCalendarDateValue, toReactAriaDateValue, useInlineEdit, useInlineEditSubmitMode, withMinuteGranularity, } from './components/InlineEdit';
42
44
  export { Input, type InputProps } from './components/Input';
43
45
  export { InputGroup, InputGroupAddon, InputGroupText, } from './components/InputGroup';
package/dist/index.js CHANGED
@@ -25,8 +25,10 @@ export { Field, FieldContent, FieldDescription, FieldError, FieldGroup, FieldLab
25
25
  export { FilterInput, FilterInputChip, FilterInputFieldMenu, FilterInputOperatorMenu } from "./components/FilterInput/index.js";
26
26
  export { Flex } from "./components/Flex/index.js";
27
27
  export { FormatDateTime } from "./components/FormatDateTime/index.js";
28
+ export { FormatNumber } from "./components/FormatNumber/index.js";
28
29
  export { Heading } from "./components/Heading/index.js";
29
30
  export { HTTP_METHODS, HTTP_METHOD_COLOR, HttpMethod } from "./components/HttpMethod/index.js";
31
+ export { Indicator } from "./components/Indicator/index.js";
30
32
  export { InlineEdit, InlineEditControl, InlineEditDate, InlineEditDateTime, InlineEditError, InlineEditInput, InlineEditNumber, InlineEditPreview, InlineEditPreviewIcon, InlineEditPreviewValue, InlineEditSelect, InlineEditTextarea, InlineEditTime, toCalendarDateValue, toReactAriaDateValue, useInlineEdit, useInlineEditSubmitMode, withMinuteGranularity } from "./components/InlineEdit/index.js";
31
33
  export { Input } from "./components/Input/index.js";
32
34
  export { InputGroup, InputGroupAddon, InputGroupText } from "./components/InputGroup/index.js";