@appdirect/design-system 0.0.14 → 0.0.16

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.
@@ -2,175 +2,39 @@
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import React from 'react';
4
4
  import { Box } from '../../Layout/Box.js';
5
- import { Text } from '../../Typography/Text.js';
6
- import { Title } from '../../Typography/Title.js';
7
- import { Inline } from '../../Layout/Inline.js';
8
- // Size mappings for different elements
9
- const sizeConfig = {
10
- xs: {
11
- valueOrder: 4, // h4
12
- titleSize: 'xs',
13
- subtitleSize: 'xs',
14
- padding: 'xs',
15
- customValueStyle: undefined,
16
- customTitleStyle: undefined,
17
- customSubtitleStyle: undefined,
18
- },
19
- sm: {
20
- valueOrder: 3, // h3
21
- titleSize: 'sm',
22
- subtitleSize: 'sm',
23
- padding: 'xs',
24
- customValueStyle: undefined,
25
- customTitleStyle: undefined,
26
- customSubtitleStyle: undefined,
27
- },
28
- md: {
29
- valueOrder: 2, // h2
30
- titleSize: 'md',
31
- subtitleSize: 'md',
32
- padding: 'sm',
33
- customValueStyle: undefined,
34
- customTitleStyle: undefined,
35
- customSubtitleStyle: undefined,
36
- },
37
- lg: {
38
- valueOrder: 1, // h1
39
- titleSize: 'lg',
40
- subtitleSize: 'lg',
41
- padding: 'sm',
42
- customValueStyle: undefined,
43
- customTitleStyle: undefined,
44
- customSubtitleStyle: undefined,
45
- },
46
- jumbo: {
47
- valueOrder: 1, // h1 as base, but will be overridden
48
- titleSize: 'xl',
49
- subtitleSize: 'xl',
50
- padding: 'md',
51
- customValueStyle: {
52
- fontSize: '96px',
53
- lineHeight: '130%',
54
- },
55
- customTitleStyle: undefined,
56
- customSubtitleStyle: undefined,
57
- },
58
- 'super-jumbo': {
59
- valueOrder: 1, // h1 as base, but will be overridden
60
- titleSize: 'xl', // Will be overridden
61
- subtitleSize: 'xl', // Will be overridden
62
- padding: 'lg',
63
- customValueStyle: {
64
- fontSize: '128px',
65
- lineHeight: '130%',
66
- },
67
- customTitleStyle: {
68
- fontSize: '32px',
69
- lineHeight: '116%',
70
- },
71
- customSubtitleStyle: {
72
- fontSize: '32px',
73
- lineHeight: '116%',
74
- },
75
- },
5
+ const LEGACY_SIZE_ALIASES = {
6
+ xs: 'level-4',
7
+ sm: 'level-3',
8
+ md: 'level-2',
9
+ lg: 'level-1',
76
10
  };
11
+ const DEFAULT_VALUE_ELEMENT = {
12
+ 'super-jumbo': 'h1',
13
+ jumbo: 'h1',
14
+ 'level-1': 'h1',
15
+ 'level-2': 'h2',
16
+ 'level-3': 'h3',
17
+ 'level-4': 'h4',
18
+ 'level-5': 'h5',
19
+ 'level-6': 'h6',
20
+ };
21
+ function resolveSize(size) {
22
+ if (size in LEGACY_SIZE_ALIASES) {
23
+ return LEGACY_SIZE_ALIASES[size];
24
+ }
25
+ return size;
26
+ }
77
27
  /**
78
28
  * KeyInsight Component
79
29
  *
80
30
  * A reusable component for displaying key metrics or insights with a title, value, and optional subtitle.
81
- * Commonly used in dashboards, analytics pages, or summary sections.
82
- *
83
- * @example
84
- * // Basic usage
85
- * <KeyInsight
86
- * value={1250}
87
- * title="Total Users"
88
- * />
89
- *
90
- * @example
91
- * // With subtitle and custom size
92
- * <KeyInsight
93
- * value="95%"
94
- * title="Success Rate"
95
- * subtitle="Last 30 days"
96
- * size="lg"
97
- * />
98
- *
99
- * @example
100
- * // Different sizes showcase
101
- * <Stack gap="md">
102
- * <KeyInsight value={1250} title="Extra Small" size="xs" />
103
- * <KeyInsight value={1250} title="Small" size="sm" />
104
- * <KeyInsight value={1250} title="Medium" size="md" />
105
- * <KeyInsight value={1250} title="Large" size="lg" />
106
- * <KeyInsight value={1250} title="Jumbo" size="jumbo" />
107
- * <KeyInsight value={1250} title="Super Jumbo" size="super-jumbo" />
108
- * </Stack>
31
+ * Sizes are tokenized (`keyInsights.sizes.*`) and applied through `data-size` rules in mantine.css.
109
32
  *
110
33
  * @example
111
- * // With a trend indicator next to the value
112
- * <KeyInsight
113
- * value="42%"
114
- * title="Conversion Rate"
115
- * rightSection={<RiArrowUpLine size={16} color="var(--ad-color-status-success)" />}
116
- * />
117
- *
118
- * @example
119
- * // Hero metrics with jumbo size
120
- * <KeyInsight
121
- * value="$2.4M"
122
- * title="Annual Revenue"
123
- * subtitle="2024 Performance"
124
- * size="jumbo"
125
- * />
126
- *
127
- * @example
128
- * // In a simple grid layout with borders
129
- * <SimpleGrid cols={3} spacing="sm">
130
- * <KeyInsight
131
- * value={1250}
132
- * title="Total Users"
133
- * size="lg"
134
- * showBorder={true}
135
- * />
136
- * <KeyInsight
137
- * value={987}
138
- * title="Active Users"
139
- * size="lg"
140
- * showBorder={true}
141
- * />
142
- * <KeyInsight
143
- * value={263}
144
- * title="New Users"
145
- * subtitle="This month"
146
- * size="lg"
147
- * showBorder={false}
148
- * />
149
- * </SimpleGrid>
150
- *
151
- * @example
152
- * // Dynamic usage with data
153
- * const insights = [
154
- * { value: userData.length, title: "Total Users" },
155
- * { value: activeUsers.length, title: "Active Users" },
156
- * { value: newUsers.length, title: "New Users" },
157
- * ];
158
- *
159
- * <Inline>
160
- * {insights.map((insight, index) => (
161
- * <KeyInsight
162
- * key={index}
163
- * value={insight.value}
164
- * title={insight.title}
165
- * size="md"
166
- * showBorder={index < insights.length - 1}
167
- * />
168
- * ))}
169
- * </Inline>
34
+ * <KeyInsight value="95%" title="Success Rate" subtitle="Last 30 days" size="level-1" valueAs="p" />
170
35
  */
171
- export function KeyInsight({ value, title, subtitle, showBorder = false, size = 'md', leftSection, rightSection, }) {
172
- const config = sizeConfig[size];
173
- return (_jsxs(Box, { ta: "center", p: config.padding, style: {
174
- borderRight: showBorder ? '1px solid var(--ad-color-border-subtle)' : undefined
175
- }, children: [_jsxs(Inline, { gap: "xxs", align: "center", justify: "center", children: [leftSection, _jsx(Title, { order: config.valueOrder, style: config.customValueStyle, children: value }), rightSection] }), _jsx(Text, { size: config.titleSize, mt: 0, style: config.customTitleStyle, children: title }), subtitle && (_jsx(Text, { size: config.subtitleSize, c: "dimmed", style: config.customSubtitleStyle, children: subtitle }))] }));
36
+ export function KeyInsight({ value, title, subtitle, showBorder = false, size = 'level-2', valueAs, leftSection, rightSection, }) {
37
+ const canonicalSize = resolveSize(size);
38
+ const ValueElement = valueAs ?? DEFAULT_VALUE_ELEMENT[canonicalSize];
39
+ return (_jsxs(Box, { className: "ad-KeyInsight", "data-size": canonicalSize, "data-border": showBorder ? '' : undefined, children: [_jsxs(Box, { className: "ad-KeyInsight-valueRow", children: [leftSection, _jsx(ValueElement, { className: "ad-KeyInsight-value", children: value }), rightSection] }), _jsx("p", { className: "ad-KeyInsight-title", children: title }), subtitle ? _jsx("p", { className: "ad-KeyInsight-subtitle", children: subtitle }) : null] }));
176
40
  }
@@ -2,11 +2,26 @@
2
2
 
3
3
  import React from 'react';
4
4
  import { Box } from '../../Layout/Box';
5
- import { Text } from '../../Typography/Text';
6
- import { Title } from '../../Typography/Title';
7
- import { Inline } from '../../Layout/Inline';
8
5
 
9
- export type KeyInsightSize = 'xs' | 'sm' | 'md' | 'lg' | 'jumbo' | 'super-jumbo';
6
+ export type KeyInsightCanonicalSize =
7
+ | 'super-jumbo'
8
+ | 'jumbo'
9
+ | 'level-1'
10
+ | 'level-2'
11
+ | 'level-3'
12
+ | 'level-4'
13
+ | 'level-5'
14
+ | 'level-6';
15
+
16
+ /**
17
+ * @deprecated Legacy KeyInsight sizes. `xs` is `level-4`, `sm` is `level-3`, `md` is `level-2`, `lg` is `level-1`.
18
+ */
19
+ export type KeyInsightLegacySize = 'xs' | 'sm' | 'md' | 'lg';
20
+
21
+ export type KeyInsightSize = KeyInsightCanonicalSize | KeyInsightLegacySize;
22
+
23
+ /** Element for the value. Visual size comes from `size`, not from this element. */
24
+ export type KeyInsightValueAs = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'p' | 'span';
10
25
 
11
26
  export interface KeyInsightProps {
12
27
  /** Value to display (can be number or string) */
@@ -17,223 +32,85 @@ export interface KeyInsightProps {
17
32
  subtitle?: string;
18
33
  /** Whether to show border on the right */
19
34
  showBorder?: boolean;
20
- /** Size of the KeyInsight component */
35
+ /**
36
+ * Visual size. Canonical values: `super-jumbo`, `jumbo`, `level-1` … `level-6`
37
+ * (Figma: KeyInsights/Super Jumbo, KeyInsights/Jumbo, KeyInsights/level-1 … KeyInsights/level-6).
38
+ *
39
+ * Deprecated aliases, still accepted: `xs` → `level-4`, `sm` → `level-3`, `md` → `level-2`, `lg` → `level-1`.
40
+ */
21
41
  size?: KeyInsightSize;
42
+ /**
43
+ * HTML element for the value. Defaults to the heading that matches the resolved size
44
+ * (`level-1`, `jumbo`, and `super-jumbo` → `h1`; `level-2` → `h2`; … `level-6` → `h6`).
45
+ * Pass `"p"` or `"span"` to keep a level-1 visual size without rendering an `<h1>`.
46
+ */
47
+ valueAs?: KeyInsightValueAs;
22
48
  /** Optional content rendered inline before the value (e.g. a trend arrow or unit) */
23
49
  leftSection?: React.ReactNode;
24
50
  /** Optional content rendered inline after the value (e.g. a trend arrow or unit) */
25
51
  rightSection?: React.ReactNode;
26
52
  }
27
53
 
28
- // Size mappings for different elements
29
- const sizeConfig = {
30
- xs: {
31
- valueOrder: 4 as const, // h4
32
- titleSize: 'xs' as const,
33
- subtitleSize: 'xs' as const,
34
- padding: 'xs' as const,
35
- customValueStyle: undefined,
36
- customTitleStyle: undefined,
37
- customSubtitleStyle: undefined,
38
- },
39
- sm: {
40
- valueOrder: 3 as const, // h3
41
- titleSize: 'sm' as const,
42
- subtitleSize: 'sm' as const,
43
- padding: 'xs' as const,
44
- customValueStyle: undefined,
45
- customTitleStyle: undefined,
46
- customSubtitleStyle: undefined,
47
- },
48
- md: {
49
- valueOrder: 2 as const, // h2
50
- titleSize: 'md' as const,
51
- subtitleSize: 'md' as const,
52
- padding: 'sm' as const,
53
- customValueStyle: undefined,
54
- customTitleStyle: undefined,
55
- customSubtitleStyle: undefined,
56
- },
57
- lg: {
58
- valueOrder: 1 as const, // h1
59
- titleSize: 'lg' as const,
60
- subtitleSize: 'lg' as const,
61
- padding: 'sm' as const,
62
- customValueStyle: undefined,
63
- customTitleStyle: undefined,
64
- customSubtitleStyle: undefined,
65
- },
66
- jumbo: {
67
- valueOrder: 1 as const, // h1 as base, but will be overridden
68
- titleSize: 'xl' as const,
69
- subtitleSize: 'xl' as const,
70
- padding: 'md' as const,
71
- customValueStyle: {
72
- fontSize: '96px',
73
- lineHeight: '130%',
74
- },
75
- customTitleStyle: undefined,
76
- customSubtitleStyle: undefined,
77
- },
78
- 'super-jumbo': {
79
- valueOrder: 1 as const, // h1 as base, but will be overridden
80
- titleSize: 'xl' as const, // Will be overridden
81
- subtitleSize: 'xl' as const, // Will be overridden
82
- padding: 'lg' as const,
83
- customValueStyle: {
84
- fontSize: '128px',
85
- lineHeight: '130%',
86
- },
87
- customTitleStyle: {
88
- fontSize: '32px',
89
- lineHeight: '116%',
90
- },
91
- customSubtitleStyle: {
92
- fontSize: '32px',
93
- lineHeight: '116%',
94
- },
95
- },
96
- } as const;
54
+ const LEGACY_SIZE_ALIASES: Record<KeyInsightLegacySize, KeyInsightCanonicalSize> = {
55
+ xs: 'level-4',
56
+ sm: 'level-3',
57
+ md: 'level-2',
58
+ lg: 'level-1',
59
+ };
60
+
61
+ const DEFAULT_VALUE_ELEMENT: Record<KeyInsightCanonicalSize, KeyInsightValueAs> = {
62
+ 'super-jumbo': 'h1',
63
+ jumbo: 'h1',
64
+ 'level-1': 'h1',
65
+ 'level-2': 'h2',
66
+ 'level-3': 'h3',
67
+ 'level-4': 'h4',
68
+ 'level-5': 'h5',
69
+ 'level-6': 'h6',
70
+ };
71
+
72
+ function resolveSize(size: KeyInsightSize): KeyInsightCanonicalSize {
73
+ if (size in LEGACY_SIZE_ALIASES) {
74
+ return LEGACY_SIZE_ALIASES[size as KeyInsightLegacySize];
75
+ }
76
+ return size as KeyInsightCanonicalSize;
77
+ }
97
78
 
98
79
  /**
99
80
  * KeyInsight Component
100
- *
81
+ *
101
82
  * A reusable component for displaying key metrics or insights with a title, value, and optional subtitle.
102
- * Commonly used in dashboards, analytics pages, or summary sections.
103
- *
104
- * @example
105
- * // Basic usage
106
- * <KeyInsight
107
- * value={1250}
108
- * title="Total Users"
109
- * />
110
- *
111
- * @example
112
- * // With subtitle and custom size
113
- * <KeyInsight
114
- * value="95%"
115
- * title="Success Rate"
116
- * subtitle="Last 30 days"
117
- * size="lg"
118
- * />
119
- *
120
- * @example
121
- * // Different sizes showcase
122
- * <Stack gap="md">
123
- * <KeyInsight value={1250} title="Extra Small" size="xs" />
124
- * <KeyInsight value={1250} title="Small" size="sm" />
125
- * <KeyInsight value={1250} title="Medium" size="md" />
126
- * <KeyInsight value={1250} title="Large" size="lg" />
127
- * <KeyInsight value={1250} title="Jumbo" size="jumbo" />
128
- * <KeyInsight value={1250} title="Super Jumbo" size="super-jumbo" />
129
- * </Stack>
130
- *
131
- * @example
132
- * // With a trend indicator next to the value
133
- * <KeyInsight
134
- * value="42%"
135
- * title="Conversion Rate"
136
- * rightSection={<RiArrowUpLine size={16} color="var(--ad-color-status-success)" />}
137
- * />
83
+ * Sizes are tokenized (`keyInsights.sizes.*`) and applied through `data-size` rules in mantine.css.
138
84
  *
139
85
  * @example
140
- * // Hero metrics with jumbo size
141
- * <KeyInsight
142
- * value="$2.4M"
143
- * title="Annual Revenue"
144
- * subtitle="2024 Performance"
145
- * size="jumbo"
146
- * />
147
- *
148
- * @example
149
- * // In a simple grid layout with borders
150
- * <SimpleGrid cols={3} spacing="sm">
151
- * <KeyInsight
152
- * value={1250}
153
- * title="Total Users"
154
- * size="lg"
155
- * showBorder={true}
156
- * />
157
- * <KeyInsight
158
- * value={987}
159
- * title="Active Users"
160
- * size="lg"
161
- * showBorder={true}
162
- * />
163
- * <KeyInsight
164
- * value={263}
165
- * title="New Users"
166
- * subtitle="This month"
167
- * size="lg"
168
- * showBorder={false}
169
- * />
170
- * </SimpleGrid>
171
- *
172
- * @example
173
- * // Dynamic usage with data
174
- * const insights = [
175
- * { value: userData.length, title: "Total Users" },
176
- * { value: activeUsers.length, title: "Active Users" },
177
- * { value: newUsers.length, title: "New Users" },
178
- * ];
179
- *
180
- * <Inline>
181
- * {insights.map((insight, index) => (
182
- * <KeyInsight
183
- * key={index}
184
- * value={insight.value}
185
- * title={insight.title}
186
- * size="md"
187
- * showBorder={index < insights.length - 1}
188
- * />
189
- * ))}
190
- * </Inline>
86
+ * <KeyInsight value="95%" title="Success Rate" subtitle="Last 30 days" size="level-1" valueAs="p" />
191
87
  */
192
88
  export function KeyInsight({
193
89
  value,
194
90
  title,
195
91
  subtitle,
196
92
  showBorder = false,
197
- size = 'md',
93
+ size = 'level-2',
94
+ valueAs,
198
95
  leftSection,
199
96
  rightSection,
200
97
  }: KeyInsightProps) {
201
- const config = sizeConfig[size];
98
+ const canonicalSize = resolveSize(size);
99
+ const ValueElement = valueAs ?? DEFAULT_VALUE_ELEMENT[canonicalSize];
202
100
 
203
101
  return (
204
102
  <Box
205
- ta="center"
206
- p={config.padding}
207
- style={{
208
- borderRight: showBorder ? '1px solid var(--ad-color-border-subtle)' : undefined
209
- }}
103
+ className="ad-KeyInsight"
104
+ data-size={canonicalSize}
105
+ data-border={showBorder ? '' : undefined}
210
106
  >
211
- <Inline gap="xxs" align="center" justify="center">
107
+ <Box className="ad-KeyInsight-valueRow">
212
108
  {leftSection}
213
- <Title
214
- order={config.valueOrder}
215
- style={config.customValueStyle}
216
- >
217
- {value}
218
- </Title>
109
+ <ValueElement className="ad-KeyInsight-value">{value}</ValueElement>
219
110
  {rightSection}
220
- </Inline>
221
- <Text
222
- size={config.titleSize}
223
- mt={0}
224
- style={config.customTitleStyle}
225
- >
226
- {title}
227
- </Text>
228
- {subtitle && (
229
- <Text
230
- size={config.subtitleSize}
231
- c="dimmed"
232
- style={config.customSubtitleStyle}
233
- >
234
- {subtitle}
235
- </Text>
236
- )}
111
+ </Box>
112
+ <p className="ad-KeyInsight-title">{title}</p>
113
+ {subtitle ? <p className="ad-KeyInsight-subtitle">{subtitle}</p> : null}
237
114
  </Box>
238
115
  );
239
- }
116
+ }
@@ -1,2 +1,8 @@
1
1
  export { KeyInsight } from './KeyInsights';
2
- export type { KeyInsightProps } from './KeyInsights';
2
+ export type {
3
+ KeyInsightProps,
4
+ KeyInsightSize,
5
+ KeyInsightCanonicalSize,
6
+ KeyInsightLegacySize,
7
+ KeyInsightValueAs,
8
+ } from './KeyInsights';
@@ -0,0 +1,31 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import React from 'react';
4
+ import { Indicator } from '../../DataDisplay/Indicator.js';
5
+ import { Inline } from '../../Layout/index.js';
6
+ import { Text } from '../../Typography/Text.js';
7
+ // Indicator dot size per step, matching Indicator's own Code Connect mapping (indicator.figma.tsx)
8
+ const DOT_SIZE_BY_SIZE = {
9
+ xs: 8,
10
+ sm: 12,
11
+ md: 16,
12
+ lg: 20,
13
+ xl: 24,
14
+ };
15
+ // ========================== COMPONENT ==========================
16
+ /**
17
+ * StatusGem Component
18
+ *
19
+ * A colored status dot with an adjacent label, used to call out a record's
20
+ * state inline (e.g. in a table cell or list row).
21
+ *
22
+ * @example
23
+ * <StatusGem variant="success" label="Active" />
24
+ *
25
+ * @example
26
+ * <StatusGem variant="pending" label="Awaiting approval" size="md" />
27
+ */
28
+ export function StatusGem({ variant = 'success', label, size = 'xs' }) {
29
+ const dotSize = DOT_SIZE_BY_SIZE[size];
30
+ return (_jsxs(Inline, { gap: 5, align: "center", children: [_jsx(Indicator, { type: variant, size: dotSize, position: "middle-center", offset: 0, inline: true, children: _jsx("div", { style: { width: dotSize, height: dotSize } }) }), _jsx(Text, { size: size, c: "dimmed", children: label })] }));
31
+ }
@@ -0,0 +1,58 @@
1
+ 'use client';
2
+
3
+ import React from 'react';
4
+ import { Indicator } from '../../DataDisplay/Indicator';
5
+ import { Inline } from '../../Layout';
6
+ import { Text } from '../../Typography/Text';
7
+
8
+ // ========================== TYPES ==========================
9
+
10
+ export type StatusGemVariant = 'success' | 'danger' | 'pending' | 'info' | 'default';
11
+ export type StatusGemSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
12
+
13
+ export interface StatusGemProps {
14
+ /** Semantic status color */
15
+ variant?: StatusGemVariant;
16
+ /** Label text */
17
+ label: string;
18
+ /** Overall size - scales the dot and label together */
19
+ size?: StatusGemSize;
20
+ }
21
+
22
+ // Indicator dot size per step, matching Indicator's own Code Connect mapping (indicator.figma.tsx)
23
+ const DOT_SIZE_BY_SIZE: Record<StatusGemSize, number> = {
24
+ xs: 8,
25
+ sm: 12,
26
+ md: 16,
27
+ lg: 20,
28
+ xl: 24,
29
+ };
30
+
31
+ // ========================== COMPONENT ==========================
32
+
33
+ /**
34
+ * StatusGem Component
35
+ *
36
+ * A colored status dot with an adjacent label, used to call out a record's
37
+ * state inline (e.g. in a table cell or list row).
38
+ *
39
+ * @example
40
+ * <StatusGem variant="success" label="Active" />
41
+ *
42
+ * @example
43
+ * <StatusGem variant="pending" label="Awaiting approval" size="md" />
44
+ */
45
+ export function StatusGem({ variant = 'success', label, size = 'xs' }: StatusGemProps) {
46
+ const dotSize = DOT_SIZE_BY_SIZE[size];
47
+
48
+ return (
49
+ <Inline gap={5} align="center">
50
+ <Indicator type={variant} size={dotSize} position="middle-center" offset={0} inline>
51
+ <div style={{ width: dotSize, height: dotSize }} />
52
+ </Indicator>
53
+ <Text size={size} c="dimmed">
54
+ {label}
55
+ </Text>
56
+ </Inline>
57
+ );
58
+ }
@@ -0,0 +1 @@
1
+ export { StatusGem } from './StatusGem.js';
@@ -0,0 +1,2 @@
1
+ export { StatusGem } from './StatusGem';
2
+ export type { StatusGemProps, StatusGemVariant, StatusGemSize } from './StatusGem';