@ankhorage/zora 1.0.5 → 1.0.7
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 +12 -0
- package/README.md +284 -0
- package/dist/components/media-card/MediaCard.d.ts +4 -0
- package/dist/components/media-card/MediaCard.d.ts.map +1 -0
- package/dist/components/media-card/MediaCard.js +64 -0
- package/dist/components/media-card/MediaCard.js.map +1 -0
- package/dist/components/media-card/index.d.ts +3 -0
- package/dist/components/media-card/index.d.ts.map +1 -0
- package/dist/components/media-card/index.js +2 -0
- package/dist/components/media-card/index.js.map +1 -0
- package/dist/components/media-card/types.d.ts +36 -0
- package/dist/components/media-card/types.d.ts.map +1 -0
- package/dist/components/media-card/types.js +2 -0
- package/dist/components/media-card/types.js.map +1 -0
- package/dist/components/metric-card/MetricCard.d.ts +4 -0
- package/dist/components/metric-card/MetricCard.d.ts.map +1 -0
- package/dist/components/metric-card/MetricCard.js +43 -0
- package/dist/components/metric-card/MetricCard.js.map +1 -0
- package/dist/components/metric-card/index.d.ts +3 -0
- package/dist/components/metric-card/index.d.ts.map +1 -0
- package/dist/components/metric-card/index.js +2 -0
- package/dist/components/metric-card/index.js.map +1 -0
- package/dist/components/metric-card/types.d.ts +17 -0
- package/dist/components/metric-card/types.d.ts.map +1 -0
- package/dist/components/metric-card/types.js +2 -0
- package/dist/components/metric-card/types.js.map +1 -0
- package/dist/components/progress/Progress.d.ts +4 -0
- package/dist/components/progress/Progress.d.ts.map +1 -0
- package/dist/components/progress/Progress.js +28 -0
- package/dist/components/progress/Progress.js.map +1 -0
- package/dist/components/progress/index.d.ts +3 -0
- package/dist/components/progress/index.d.ts.map +1 -0
- package/dist/components/progress/index.js +2 -0
- package/dist/components/progress/index.js.map +1 -0
- package/dist/components/progress/resolveProgressFraction.d.ts +5 -0
- package/dist/components/progress/resolveProgressFraction.d.ts.map +1 -0
- package/dist/components/progress/resolveProgressFraction.js +14 -0
- package/dist/components/progress/resolveProgressFraction.js.map +1 -0
- package/dist/components/progress/types.d.ts +11 -0
- package/dist/components/progress/types.d.ts.map +1 -0
- package/dist/components/progress/types.js +16 -0
- package/dist/components/progress/types.js.map +1 -0
- package/dist/components/rating/Rating.d.ts +4 -0
- package/dist/components/rating/Rating.d.ts.map +1 -0
- package/dist/components/rating/Rating.js +23 -0
- package/dist/components/rating/Rating.js.map +1 -0
- package/dist/components/rating/index.d.ts +3 -0
- package/dist/components/rating/index.d.ts.map +1 -0
- package/dist/components/rating/index.js +2 -0
- package/dist/components/rating/index.js.map +1 -0
- package/dist/components/rating/resolveRatingSegments.d.ts +7 -0
- package/dist/components/rating/resolveRatingSegments.d.ts.map +1 -0
- package/dist/components/rating/resolveRatingSegments.js +22 -0
- package/dist/components/rating/resolveRatingSegments.js.map +1 -0
- package/dist/components/rating/types.d.ts +11 -0
- package/dist/components/rating/types.d.ts.map +1 -0
- package/dist/components/rating/types.js +16 -0
- package/dist/components/rating/types.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/patterns/list/List.d.ts +4 -0
- package/dist/patterns/list/List.d.ts.map +1 -0
- package/dist/patterns/list/List.js +35 -0
- package/dist/patterns/list/List.js.map +1 -0
- package/dist/patterns/list/ListRow.d.ts +4 -0
- package/dist/patterns/list/ListRow.d.ts.map +1 -0
- package/dist/patterns/list/ListRow.js +108 -0
- package/dist/patterns/list/ListRow.js.map +1 -0
- package/dist/patterns/list/ListSection.d.ts +4 -0
- package/dist/patterns/list/ListSection.d.ts.map +1 -0
- package/dist/patterns/list/ListSection.js +14 -0
- package/dist/patterns/list/ListSection.js.map +1 -0
- package/dist/patterns/list/index.d.ts +5 -0
- package/dist/patterns/list/index.d.ts.map +1 -0
- package/dist/patterns/list/index.js +4 -0
- package/dist/patterns/list/index.js.map +1 -0
- package/dist/patterns/list/resolveListSeparator.d.ts +5 -0
- package/dist/patterns/list/resolveListSeparator.d.ts.map +1 -0
- package/dist/patterns/list/resolveListSeparator.js +6 -0
- package/dist/patterns/list/resolveListSeparator.js.map +1 -0
- package/dist/patterns/list/types.d.ts +55 -0
- package/dist/patterns/list/types.d.ts.map +1 -0
- package/dist/patterns/list/types.js +2 -0
- package/dist/patterns/list/types.js.map +1 -0
- package/dist/patterns/timeline/Timeline.d.ts +4 -0
- package/dist/patterns/timeline/Timeline.d.ts.map +1 -0
- package/dist/patterns/timeline/Timeline.js +59 -0
- package/dist/patterns/timeline/Timeline.js.map +1 -0
- package/dist/patterns/timeline/index.d.ts +3 -0
- package/dist/patterns/timeline/index.d.ts.map +1 -0
- package/dist/patterns/timeline/index.js +2 -0
- package/dist/patterns/timeline/index.js.map +1 -0
- package/dist/patterns/timeline/types.d.ts +18 -0
- package/dist/patterns/timeline/types.d.ts.map +1 -0
- package/dist/patterns/timeline/types.js +2 -0
- package/dist/patterns/timeline/types.js.map +1 -0
- package/package.json +1 -1
- package/src/components/media-card/MediaCard.tsx +120 -0
- package/src/components/media-card/index.ts +2 -0
- package/src/components/media-card/types.ts +44 -0
- package/src/components/metric-card/MetricCard.tsx +84 -0
- package/src/components/metric-card/index.ts +2 -0
- package/src/components/metric-card/types.ts +18 -0
- package/src/components/progress/Progress.tsx +50 -0
- package/src/components/progress/index.ts +2 -0
- package/src/components/progress/resolveProgressFraction.test.ts +23 -0
- package/src/components/progress/resolveProgressFraction.ts +17 -0
- package/src/components/progress/types.ts +27 -0
- package/src/components/rating/Rating.tsx +38 -0
- package/src/components/rating/index.ts +2 -0
- package/src/components/rating/resolveRatingSegments.test.ts +60 -0
- package/src/components/rating/resolveRatingSegments.ts +34 -0
- package/src/components/rating/types.ts +27 -0
- package/src/index.ts +19 -0
- package/src/patterns/list/List.tsx +72 -0
- package/src/patterns/list/ListRow.tsx +193 -0
- package/src/patterns/list/ListSection.tsx +36 -0
- package/src/patterns/list/index.ts +11 -0
- package/src/patterns/list/resolveListSeparator.test.ts +18 -0
- package/src/patterns/list/resolveListSeparator.ts +8 -0
- package/src/patterns/list/types.ts +67 -0
- package/src/patterns/timeline/Timeline.tsx +104 -0
- package/src/patterns/timeline/index.ts +2 -0
- package/src/patterns/timeline/types.ts +20 -0
- package/src/showcaseCoverage.test.ts +8 -0
- package/src/theme/themeScopeStructure.test.ts +14 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export function resolveProgressFraction({ value, max }: { value: number; max: number }): number {
|
|
2
|
+
if (!Number.isFinite(value) || !Number.isFinite(max) || max <= 0) {
|
|
3
|
+
return 0;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
const fraction = value / max;
|
|
7
|
+
|
|
8
|
+
if (fraction <= 0) {
|
|
9
|
+
return 0;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (fraction >= 1) {
|
|
13
|
+
return 1;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return fraction;
|
|
17
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { RoleSemantics, SurfaceTheme } from '@ankhorage/surface';
|
|
2
|
+
|
|
3
|
+
import type { ZoraControlSize, ZoraTone } from '../../internal/recipes';
|
|
4
|
+
import type { ZoraBaseProps } from '../../theme/ZoraBaseProps';
|
|
5
|
+
|
|
6
|
+
export interface ProgressProps extends ZoraBaseProps {
|
|
7
|
+
value: number;
|
|
8
|
+
max?: number;
|
|
9
|
+
tone?: ZoraTone;
|
|
10
|
+
size?: ZoraControlSize;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function resolveProgressRole(theme: SurfaceTheme, tone: ZoraTone): RoleSemantics {
|
|
14
|
+
switch (tone) {
|
|
15
|
+
case 'primary':
|
|
16
|
+
return theme.semantics.action.primary;
|
|
17
|
+
case 'danger':
|
|
18
|
+
return theme.semantics.action.danger;
|
|
19
|
+
case 'success':
|
|
20
|
+
return theme.semantics.success;
|
|
21
|
+
case 'warning':
|
|
22
|
+
return theme.semantics.warning;
|
|
23
|
+
case 'neutral':
|
|
24
|
+
default:
|
|
25
|
+
return theme.semantics.action.neutral;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { Inline } from '../../foundation';
|
|
4
|
+
import { resolveIconSize } from '../../internal/recipes';
|
|
5
|
+
import { useZoraTheme } from '../../theme/useZoraTheme';
|
|
6
|
+
import { withZoraThemeScope } from '../../theme/withZoraThemeScope';
|
|
7
|
+
import { Icon } from '../icon';
|
|
8
|
+
import { resolveRatingSegments } from './resolveRatingSegments';
|
|
9
|
+
import { type RatingProps, resolveRatingRole } from './types';
|
|
10
|
+
|
|
11
|
+
function RatingInner({
|
|
12
|
+
themeId: _themeId,
|
|
13
|
+
mode: _mode,
|
|
14
|
+
testID,
|
|
15
|
+
value,
|
|
16
|
+
max = 5,
|
|
17
|
+
tone = 'warning',
|
|
18
|
+
size = 'm',
|
|
19
|
+
}: RatingProps) {
|
|
20
|
+
const { theme } = useZoraTheme();
|
|
21
|
+
const role = resolveRatingRole(theme, tone);
|
|
22
|
+
const segments = resolveRatingSegments({ value, max });
|
|
23
|
+
const iconSize = resolveIconSize(size);
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<Inline align="center" gap="xxs" testID={testID} wrap="nowrap">
|
|
27
|
+
{segments.map((segment, index) => {
|
|
28
|
+
const name =
|
|
29
|
+
segment === 'full' ? 'star' : segment === 'half' ? 'star-half' : 'star-outline';
|
|
30
|
+
const color = segment === 'empty' ? theme.semantics.content.muted : role.base;
|
|
31
|
+
|
|
32
|
+
return <Icon key={index} color={color} name={name} size={iconSize} />;
|
|
33
|
+
})}
|
|
34
|
+
</Inline>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const Rating = withZoraThemeScope(RatingInner);
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test';
|
|
2
|
+
|
|
3
|
+
import { resolveRatingSegments } from './resolveRatingSegments';
|
|
4
|
+
|
|
5
|
+
describe('resolveRatingSegments', () => {
|
|
6
|
+
test('returns empty segments for invalid input', () => {
|
|
7
|
+
expect(resolveRatingSegments({ value: 3, max: 0 })).toEqual([]);
|
|
8
|
+
expect(resolveRatingSegments({ value: Number.NaN, max: 5 })).toEqual([]);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
test('clamps and rounds to nearest half-step', () => {
|
|
12
|
+
expect(resolveRatingSegments({ value: -1, max: 5 })).toEqual([
|
|
13
|
+
'empty',
|
|
14
|
+
'empty',
|
|
15
|
+
'empty',
|
|
16
|
+
'empty',
|
|
17
|
+
'empty',
|
|
18
|
+
]);
|
|
19
|
+
|
|
20
|
+
expect(resolveRatingSegments({ value: 3, max: 5 })).toEqual([
|
|
21
|
+
'full',
|
|
22
|
+
'full',
|
|
23
|
+
'full',
|
|
24
|
+
'empty',
|
|
25
|
+
'empty',
|
|
26
|
+
]);
|
|
27
|
+
|
|
28
|
+
expect(resolveRatingSegments({ value: 3.2, max: 5 })).toEqual([
|
|
29
|
+
'full',
|
|
30
|
+
'full',
|
|
31
|
+
'full',
|
|
32
|
+
'empty',
|
|
33
|
+
'empty',
|
|
34
|
+
]);
|
|
35
|
+
|
|
36
|
+
expect(resolveRatingSegments({ value: 3.25, max: 5 })).toEqual([
|
|
37
|
+
'full',
|
|
38
|
+
'full',
|
|
39
|
+
'full',
|
|
40
|
+
'half',
|
|
41
|
+
'empty',
|
|
42
|
+
]);
|
|
43
|
+
|
|
44
|
+
expect(resolveRatingSegments({ value: 5, max: 5 })).toEqual([
|
|
45
|
+
'full',
|
|
46
|
+
'full',
|
|
47
|
+
'full',
|
|
48
|
+
'full',
|
|
49
|
+
'full',
|
|
50
|
+
]);
|
|
51
|
+
|
|
52
|
+
expect(resolveRatingSegments({ value: 6, max: 5 })).toEqual([
|
|
53
|
+
'full',
|
|
54
|
+
'full',
|
|
55
|
+
'full',
|
|
56
|
+
'full',
|
|
57
|
+
'full',
|
|
58
|
+
]);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
type RatingSegment = 'full' | 'half' | 'empty';
|
|
2
|
+
|
|
3
|
+
export function resolveRatingSegments({
|
|
4
|
+
value,
|
|
5
|
+
max,
|
|
6
|
+
}: {
|
|
7
|
+
value: number;
|
|
8
|
+
max: number;
|
|
9
|
+
}): RatingSegment[] {
|
|
10
|
+
if (!Number.isFinite(value) || !Number.isFinite(max) || max <= 0) {
|
|
11
|
+
return [];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const clamped = Math.max(0, Math.min(value, max));
|
|
15
|
+
const halfSteps = Math.round(clamped * 2);
|
|
16
|
+
const segments: RatingSegment[] = [];
|
|
17
|
+
|
|
18
|
+
for (let index = 0; index < max; index += 1) {
|
|
19
|
+
const threshold = (index + 1) * 2;
|
|
20
|
+
if (halfSteps >= threshold) {
|
|
21
|
+
segments.push('full');
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (halfSteps === threshold - 1) {
|
|
26
|
+
segments.push('half');
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
segments.push('empty');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return segments;
|
|
34
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { RoleSemantics, SurfaceTheme } from '@ankhorage/surface';
|
|
2
|
+
|
|
3
|
+
import type { ZoraControlSize, ZoraTone } from '../../internal/recipes';
|
|
4
|
+
import type { ZoraBaseProps } from '../../theme/ZoraBaseProps';
|
|
5
|
+
|
|
6
|
+
export interface RatingProps extends ZoraBaseProps {
|
|
7
|
+
value: number;
|
|
8
|
+
max?: number;
|
|
9
|
+
tone?: ZoraTone;
|
|
10
|
+
size?: ZoraControlSize;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function resolveRatingRole(theme: SurfaceTheme, tone: ZoraTone): RoleSemantics {
|
|
14
|
+
switch (tone) {
|
|
15
|
+
case 'primary':
|
|
16
|
+
return theme.semantics.action.primary;
|
|
17
|
+
case 'danger':
|
|
18
|
+
return theme.semantics.action.danger;
|
|
19
|
+
case 'success':
|
|
20
|
+
return theme.semantics.success;
|
|
21
|
+
case 'warning':
|
|
22
|
+
return theme.semantics.warning;
|
|
23
|
+
case 'neutral':
|
|
24
|
+
default:
|
|
25
|
+
return theme.semantics.action.neutral;
|
|
26
|
+
}
|
|
27
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -60,10 +60,18 @@ export type { IconButtonProps } from './components/icon-button';
|
|
|
60
60
|
export { IconButton } from './components/icon-button';
|
|
61
61
|
export type { InputProps, InputTrailingAction } from './components/input';
|
|
62
62
|
export { Input } from './components/input';
|
|
63
|
+
export type { MediaCardImageProps, MediaCardProps } from './components/media-card';
|
|
64
|
+
export { MediaCard } from './components/media-card';
|
|
65
|
+
export type { MetricCardProps } from './components/metric-card';
|
|
66
|
+
export { MetricCard } from './components/metric-card';
|
|
63
67
|
export type { ModalProps } from './components/modal';
|
|
64
68
|
export { Modal } from './components/modal';
|
|
69
|
+
export type { ProgressProps } from './components/progress';
|
|
70
|
+
export { Progress } from './components/progress';
|
|
65
71
|
export type { RadioGroupOption, RadioGroupProps, RadioProps } from './components/radio';
|
|
66
72
|
export { Radio, RadioGroup } from './components/radio';
|
|
73
|
+
export type { RatingProps } from './components/rating';
|
|
74
|
+
export { Rating } from './components/rating';
|
|
67
75
|
export type { SearchBarProps } from './components/search-bar';
|
|
68
76
|
export { SearchBar } from './components/search-bar';
|
|
69
77
|
export type { SelectOption, SelectProps } from './components/select';
|
|
@@ -146,6 +154,15 @@ export type { FilterBarProps } from './patterns/filter-bar';
|
|
|
146
154
|
export { FilterBar } from './patterns/filter-bar';
|
|
147
155
|
export type { InspectorFieldProps } from './patterns/inspector-field';
|
|
148
156
|
export { InspectorField } from './patterns/inspector-field';
|
|
157
|
+
export type {
|
|
158
|
+
ListChildrenProps,
|
|
159
|
+
ListItemsProps,
|
|
160
|
+
ListProps,
|
|
161
|
+
ListRowProps,
|
|
162
|
+
ListRowVariant,
|
|
163
|
+
ListSectionProps,
|
|
164
|
+
} from './patterns/list';
|
|
165
|
+
export { List, ListRow, ListSection } from './patterns/list';
|
|
149
166
|
export type { NoticeProps } from './patterns/notice';
|
|
150
167
|
export { Notice } from './patterns/notice';
|
|
151
168
|
export type { PanelProps } from './patterns/panel';
|
|
@@ -162,6 +179,8 @@ export type { ThemeComposerProps } from './patterns/theme-composer';
|
|
|
162
179
|
export { ThemeComposer } from './patterns/theme-composer';
|
|
163
180
|
export type { PaletteItemProps, TileGridProps } from './patterns/tile-grid';
|
|
164
181
|
export { PaletteItem, TileGrid } from './patterns/tile-grid';
|
|
182
|
+
export type { TimelineItem, TimelineProps } from './patterns/timeline';
|
|
183
|
+
export { Timeline } from './patterns/timeline';
|
|
165
184
|
export type { TreeItemNode, TreeItemRenderProps, TreeViewProps } from './patterns/tree-view';
|
|
166
185
|
export { TreeItem, TreeView } from './patterns/tree-view';
|
|
167
186
|
export * from './theme';
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { Divider, Spacer, Stack } from '../../foundation';
|
|
4
|
+
import { withZoraThemeScope } from '../../theme/withZoraThemeScope';
|
|
5
|
+
import { ListRow } from './ListRow';
|
|
6
|
+
import { resolveListSeparator } from './resolveListSeparator';
|
|
7
|
+
import type { ListItemsProps, ListProps, ListRowProps, ListRowVariant } from './types';
|
|
8
|
+
|
|
9
|
+
function resolveRowVariant({
|
|
10
|
+
item,
|
|
11
|
+
defaultVariant,
|
|
12
|
+
}: {
|
|
13
|
+
item: ListRowProps;
|
|
14
|
+
defaultVariant: ListRowVariant;
|
|
15
|
+
}): ListRowVariant {
|
|
16
|
+
return item.variant ?? defaultVariant;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function resolveRowCompact({
|
|
20
|
+
item,
|
|
21
|
+
compact,
|
|
22
|
+
}: {
|
|
23
|
+
item: ListRowProps;
|
|
24
|
+
compact: boolean | undefined;
|
|
25
|
+
}): boolean {
|
|
26
|
+
return item.compact ?? compact ?? false;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function ListItemsInner({
|
|
30
|
+
themeId: _themeId,
|
|
31
|
+
mode: _mode,
|
|
32
|
+
testID,
|
|
33
|
+
items,
|
|
34
|
+
rowVariant = 'divider',
|
|
35
|
+
compact,
|
|
36
|
+
}: ListItemsProps) {
|
|
37
|
+
return (
|
|
38
|
+
<Stack gap="none" testID={testID}>
|
|
39
|
+
{items.map((item, index) => {
|
|
40
|
+
const effectiveVariant = resolveRowVariant({ item, defaultVariant: rowVariant });
|
|
41
|
+
const separator = resolveListSeparator(effectiveVariant, index);
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<React.Fragment key={`${index}`}>
|
|
45
|
+
{separator === 'divider' ? <Divider /> : null}
|
|
46
|
+
{separator === 'spacer' ? <Spacer size="s" /> : null}
|
|
47
|
+
<ListRow
|
|
48
|
+
{...item}
|
|
49
|
+
compact={resolveRowCompact({ item, compact })}
|
|
50
|
+
variant={effectiveVariant}
|
|
51
|
+
/>
|
|
52
|
+
</React.Fragment>
|
|
53
|
+
);
|
|
54
|
+
})}
|
|
55
|
+
</Stack>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function ListInner(props: ListProps) {
|
|
60
|
+
if ('items' in props) {
|
|
61
|
+
return <ListItemsInner {...props} />;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const { themeId: _themeId, mode: _mode, children, testID } = props;
|
|
65
|
+
return (
|
|
66
|
+
<Stack gap="none" testID={testID}>
|
|
67
|
+
{children}
|
|
68
|
+
</Stack>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export const List = withZoraThemeScope(ListInner);
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { ButtonBase } from '@ankhorage/surface';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
import { Text } from '../../components/text';
|
|
5
|
+
import { Box, Inline, Spacer, Stack } from '../../foundation';
|
|
6
|
+
import { useZoraTheme } from '../../theme/useZoraTheme';
|
|
7
|
+
import { withZoraThemeScope } from '../../theme/withZoraThemeScope';
|
|
8
|
+
import type { ListRowProps, ListRowVariant } from './types';
|
|
9
|
+
|
|
10
|
+
function resolvePadding(compact: boolean) {
|
|
11
|
+
return compact ? { px: 'm' as const, py: 's' as const } : { px: 'm' as const, py: 'm' as const };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function resolveContainerStyles({
|
|
15
|
+
variant,
|
|
16
|
+
theme,
|
|
17
|
+
selected,
|
|
18
|
+
pressed,
|
|
19
|
+
hovered,
|
|
20
|
+
disabled,
|
|
21
|
+
}: {
|
|
22
|
+
variant: ListRowVariant;
|
|
23
|
+
theme: ReturnType<typeof useZoraTheme>['theme'];
|
|
24
|
+
selected: boolean;
|
|
25
|
+
pressed: boolean;
|
|
26
|
+
hovered: boolean;
|
|
27
|
+
disabled: boolean;
|
|
28
|
+
}) {
|
|
29
|
+
const borderColor = selected ? theme.semantics.border.focus : theme.semantics.border.default;
|
|
30
|
+
const dividerBorderColor = selected ? theme.semantics.border.focus : 'transparent';
|
|
31
|
+
|
|
32
|
+
if (variant === 'card') {
|
|
33
|
+
return {
|
|
34
|
+
bg: pressed
|
|
35
|
+
? theme.semantics.neutral.surfaceActive
|
|
36
|
+
: hovered
|
|
37
|
+
? theme.semantics.neutral.surfaceHover
|
|
38
|
+
: theme.semantics.surface.raised,
|
|
39
|
+
borderColor,
|
|
40
|
+
borderWidth: 1,
|
|
41
|
+
radius: 'l' as const,
|
|
42
|
+
opacity: disabled ? 0.72 : 1,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
bg: pressed
|
|
48
|
+
? theme.semantics.neutral.surfaceActive
|
|
49
|
+
: hovered
|
|
50
|
+
? theme.semantics.neutral.surfaceHover
|
|
51
|
+
: selected
|
|
52
|
+
? theme.semantics.neutral.surface
|
|
53
|
+
: 'transparent',
|
|
54
|
+
borderColor: dividerBorderColor,
|
|
55
|
+
borderWidth: selected ? 1 : 0,
|
|
56
|
+
radius: 'm' as const,
|
|
57
|
+
opacity: disabled ? 0.72 : 1,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function ListRowInner({
|
|
62
|
+
themeId: _themeId,
|
|
63
|
+
mode: _mode,
|
|
64
|
+
testID,
|
|
65
|
+
title,
|
|
66
|
+
description,
|
|
67
|
+
meta,
|
|
68
|
+
leading,
|
|
69
|
+
trailing,
|
|
70
|
+
action,
|
|
71
|
+
onPress,
|
|
72
|
+
selected = false,
|
|
73
|
+
disabled = false,
|
|
74
|
+
compact = false,
|
|
75
|
+
variant = 'divider',
|
|
76
|
+
}: ListRowProps) {
|
|
77
|
+
const { theme } = useZoraTheme();
|
|
78
|
+
const padding = resolvePadding(compact);
|
|
79
|
+
const isInteractive = Boolean(onPress) && !action;
|
|
80
|
+
|
|
81
|
+
const content = (
|
|
82
|
+
<Stack
|
|
83
|
+
align="center"
|
|
84
|
+
direction="row"
|
|
85
|
+
style={{
|
|
86
|
+
flex: 1,
|
|
87
|
+
}}
|
|
88
|
+
>
|
|
89
|
+
{leading ? (
|
|
90
|
+
<>
|
|
91
|
+
<Box>{leading}</Box>
|
|
92
|
+
<Spacer axis="horizontal" size="m" />
|
|
93
|
+
</>
|
|
94
|
+
) : null}
|
|
95
|
+
|
|
96
|
+
<Box flex={1}>
|
|
97
|
+
<Stack gap="xxs">
|
|
98
|
+
<Text variant="body" weight={selected ? 'semiBold' : 'medium'}>
|
|
99
|
+
{title}
|
|
100
|
+
</Text>
|
|
101
|
+
{description ? (
|
|
102
|
+
<Text tone="muted" variant="bodySmall">
|
|
103
|
+
{description}
|
|
104
|
+
</Text>
|
|
105
|
+
) : null}
|
|
106
|
+
{meta ? (
|
|
107
|
+
<Text tone="subtle" variant="caption">
|
|
108
|
+
{meta}
|
|
109
|
+
</Text>
|
|
110
|
+
) : null}
|
|
111
|
+
</Stack>
|
|
112
|
+
</Box>
|
|
113
|
+
|
|
114
|
+
{trailing || action ? (
|
|
115
|
+
<>
|
|
116
|
+
<Spacer axis="horizontal" size="m" />
|
|
117
|
+
<Inline align="center" gap="s" wrap="nowrap">
|
|
118
|
+
{trailing}
|
|
119
|
+
{action}
|
|
120
|
+
</Inline>
|
|
121
|
+
</>
|
|
122
|
+
) : null}
|
|
123
|
+
</Stack>
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
if (!isInteractive) {
|
|
127
|
+
const styles = resolveContainerStyles({
|
|
128
|
+
variant,
|
|
129
|
+
theme,
|
|
130
|
+
selected,
|
|
131
|
+
pressed: false,
|
|
132
|
+
hovered: false,
|
|
133
|
+
disabled,
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
return (
|
|
137
|
+
<Box
|
|
138
|
+
bg={styles.bg}
|
|
139
|
+
borderColor={styles.borderColor}
|
|
140
|
+
borderWidth={styles.borderWidth}
|
|
141
|
+
px={padding.px}
|
|
142
|
+
py={padding.py}
|
|
143
|
+
radius={styles.radius}
|
|
144
|
+
testID={testID}
|
|
145
|
+
style={{
|
|
146
|
+
opacity: styles.opacity,
|
|
147
|
+
}}
|
|
148
|
+
>
|
|
149
|
+
{content}
|
|
150
|
+
</Box>
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return (
|
|
155
|
+
<ButtonBase
|
|
156
|
+
accessibilityRole="button"
|
|
157
|
+
accessibilityState={{ disabled, selected }}
|
|
158
|
+
disabled={disabled}
|
|
159
|
+
onPress={onPress}
|
|
160
|
+
radius={variant === 'card' ? 'l' : 'm'}
|
|
161
|
+
testID={testID}
|
|
162
|
+
>
|
|
163
|
+
{(state) => {
|
|
164
|
+
const styles = resolveContainerStyles({
|
|
165
|
+
variant,
|
|
166
|
+
theme,
|
|
167
|
+
selected,
|
|
168
|
+
pressed: state.pressed,
|
|
169
|
+
hovered: state.hovered,
|
|
170
|
+
disabled: state.disabled,
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
return (
|
|
174
|
+
<Box
|
|
175
|
+
bg={styles.bg}
|
|
176
|
+
borderColor={styles.borderColor}
|
|
177
|
+
borderWidth={styles.borderWidth}
|
|
178
|
+
px={padding.px}
|
|
179
|
+
py={padding.py}
|
|
180
|
+
radius={styles.radius}
|
|
181
|
+
style={{
|
|
182
|
+
opacity: styles.opacity,
|
|
183
|
+
}}
|
|
184
|
+
>
|
|
185
|
+
{content}
|
|
186
|
+
</Box>
|
|
187
|
+
);
|
|
188
|
+
}}
|
|
189
|
+
</ButtonBase>
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export const ListRow = withZoraThemeScope(ListRowInner);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { Stack } from '../../foundation';
|
|
4
|
+
import { withZoraThemeScope } from '../../theme/withZoraThemeScope';
|
|
5
|
+
import { SectionHeader } from '../section-header';
|
|
6
|
+
import { List } from './List';
|
|
7
|
+
import type { ListSectionProps } from './types';
|
|
8
|
+
|
|
9
|
+
function ListSectionInner({
|
|
10
|
+
themeId: _themeId,
|
|
11
|
+
mode: _mode,
|
|
12
|
+
testID,
|
|
13
|
+
title,
|
|
14
|
+
description,
|
|
15
|
+
eyebrow,
|
|
16
|
+
actions,
|
|
17
|
+
...props
|
|
18
|
+
}: ListSectionProps) {
|
|
19
|
+
const hasHeader = title !== undefined;
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<Stack gap="s" testID={testID}>
|
|
23
|
+
{hasHeader ? (
|
|
24
|
+
<SectionHeader
|
|
25
|
+
actions={actions}
|
|
26
|
+
description={description}
|
|
27
|
+
eyebrow={eyebrow}
|
|
28
|
+
title={title}
|
|
29
|
+
/>
|
|
30
|
+
) : null}
|
|
31
|
+
<List {...props} />
|
|
32
|
+
</Stack>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const ListSection = withZoraThemeScope(ListSectionInner);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { List } from './List';
|
|
2
|
+
export { ListRow } from './ListRow';
|
|
3
|
+
export { ListSection } from './ListSection';
|
|
4
|
+
export type {
|
|
5
|
+
ListChildrenProps,
|
|
6
|
+
ListItemsProps,
|
|
7
|
+
ListProps,
|
|
8
|
+
ListRowProps,
|
|
9
|
+
ListRowVariant,
|
|
10
|
+
ListSectionProps,
|
|
11
|
+
} from './types';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { describe, expect, it } from 'bun:test';
|
|
2
|
+
|
|
3
|
+
import { resolveListSeparator } from './resolveListSeparator';
|
|
4
|
+
|
|
5
|
+
describe('resolveListSeparator', () => {
|
|
6
|
+
it('returns none for the first item', () => {
|
|
7
|
+
expect(resolveListSeparator('divider', 0)).toBe('none');
|
|
8
|
+
expect(resolveListSeparator('card', 0)).toBe('none');
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('returns divider for divider rows', () => {
|
|
12
|
+
expect(resolveListSeparator('divider', 1)).toBe('divider');
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('returns spacer for card rows', () => {
|
|
16
|
+
expect(resolveListSeparator('card', 1)).toBe('spacer');
|
|
17
|
+
});
|
|
18
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ListRowVariant } from './types';
|
|
2
|
+
|
|
3
|
+
type ListSeparatorKind = 'none' | 'divider' | 'spacer';
|
|
4
|
+
|
|
5
|
+
export function resolveListSeparator(variant: ListRowVariant, index: number): ListSeparatorKind {
|
|
6
|
+
if (index === 0) return 'none';
|
|
7
|
+
return variant === 'divider' ? 'divider' : 'spacer';
|
|
8
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
|
|
3
|
+
import type { ZoraBaseProps } from '../../theme/ZoraBaseProps';
|
|
4
|
+
|
|
5
|
+
export type ListRowVariant = 'divider' | 'card';
|
|
6
|
+
|
|
7
|
+
interface ListRowBaseProps extends ZoraBaseProps {
|
|
8
|
+
title: React.ReactNode;
|
|
9
|
+
description?: React.ReactNode;
|
|
10
|
+
meta?: React.ReactNode;
|
|
11
|
+
leading?: React.ReactNode;
|
|
12
|
+
trailing?: React.ReactNode;
|
|
13
|
+
selected?: boolean;
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
compact?: boolean;
|
|
16
|
+
variant?: ListRowVariant;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface ListRowPressableProps {
|
|
20
|
+
onPress: () => void;
|
|
21
|
+
action?: never;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface ListRowActionProps {
|
|
25
|
+
action: React.ReactNode;
|
|
26
|
+
onPress?: never;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface ListRowStaticProps {
|
|
30
|
+
action?: never;
|
|
31
|
+
onPress?: never;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export type ListRowProps = ListRowBaseProps &
|
|
35
|
+
(ListRowPressableProps | ListRowActionProps | ListRowStaticProps);
|
|
36
|
+
|
|
37
|
+
export interface ListItemsProps extends ZoraBaseProps {
|
|
38
|
+
items: readonly ListRowProps[];
|
|
39
|
+
rowVariant?: ListRowVariant;
|
|
40
|
+
compact?: boolean;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface ListChildrenProps extends ZoraBaseProps {
|
|
44
|
+
children: React.ReactNode;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export type ListProps = ListItemsProps | ListChildrenProps;
|
|
48
|
+
|
|
49
|
+
export interface ListSectionItemsProps extends ZoraBaseProps {
|
|
50
|
+
title?: React.ReactNode;
|
|
51
|
+
description?: React.ReactNode;
|
|
52
|
+
eyebrow?: React.ReactNode;
|
|
53
|
+
actions?: React.ReactNode;
|
|
54
|
+
items: readonly ListRowProps[];
|
|
55
|
+
rowVariant?: ListRowVariant;
|
|
56
|
+
compact?: boolean;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface ListSectionChildrenProps extends ZoraBaseProps {
|
|
60
|
+
title?: React.ReactNode;
|
|
61
|
+
description?: React.ReactNode;
|
|
62
|
+
eyebrow?: React.ReactNode;
|
|
63
|
+
actions?: React.ReactNode;
|
|
64
|
+
children: React.ReactNode;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export type ListSectionProps = ListSectionItemsProps | ListSectionChildrenProps;
|