@dxos/react-ui 0.3.9-main.915c0ba → 0.3.9-main.9c4408c
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/dist/lib/browser/index.mjs +275 -390
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/components/Avatars/Avatar.stories.d.ts +1 -0
- package/dist/types/src/components/Avatars/Avatar.stories.d.ts.map +1 -1
- package/dist/types/src/components/Avatars/AvatarGroup.stories.d.ts +1 -0
- package/dist/types/src/components/Avatars/AvatarGroup.stories.d.ts.map +1 -1
- package/dist/types/src/components/Breadcrumb/Breadcrumb.stories.d.ts +1 -0
- package/dist/types/src/components/Breadcrumb/Breadcrumb.stories.d.ts.map +1 -1
- package/dist/types/src/components/Buttons/Button.stories.d.ts +1 -0
- package/dist/types/src/components/Buttons/Button.stories.d.ts.map +1 -1
- package/dist/types/src/components/Buttons/Toggle.stories.d.ts +1 -0
- package/dist/types/src/components/Buttons/Toggle.stories.d.ts.map +1 -1
- package/dist/types/src/components/Buttons/ToggleGroup.stories.d.ts +1 -0
- package/dist/types/src/components/Buttons/ToggleGroup.stories.d.ts.map +1 -1
- package/dist/types/src/components/Dialogs/AlertDialog.stories.d.ts +1 -0
- package/dist/types/src/components/Dialogs/AlertDialog.stories.d.ts.map +1 -1
- package/dist/types/src/components/Dialogs/Dialog.stories.d.ts +1 -0
- package/dist/types/src/components/Dialogs/Dialog.stories.d.ts.map +1 -1
- package/dist/types/src/components/DropdownMenu/DropdownMenu.stories.d.ts +1 -0
- package/dist/types/src/components/DropdownMenu/DropdownMenu.stories.d.ts.map +1 -1
- package/dist/types/src/components/Input/Input.d.ts +2 -2
- package/dist/types/src/components/Input/Input.d.ts.map +1 -1
- package/dist/types/src/components/Input/Input.stories.d.ts +2 -1
- package/dist/types/src/components/Input/Input.stories.d.ts.map +1 -1
- package/dist/types/src/components/Link/Link.stories.d.ts.map +1 -1
- package/dist/types/src/components/Lists/List.stories.d.ts +1 -0
- package/dist/types/src/components/Lists/List.stories.d.ts.map +1 -1
- package/dist/types/src/components/Lists/Tree.stories.d.ts +1 -0
- package/dist/types/src/components/Lists/Tree.stories.d.ts.map +1 -1
- package/dist/types/src/components/Main/Main.d.ts +2 -2
- package/dist/types/src/components/Main/Main.stories.d.ts +1 -0
- package/dist/types/src/components/Main/Main.stories.d.ts.map +1 -1
- package/dist/types/src/components/Message/Message.stories.d.ts +1 -0
- package/dist/types/src/components/Message/Message.stories.d.ts.map +1 -1
- package/dist/types/src/components/Popover/Popover.stories.d.ts +6 -0
- package/dist/types/src/components/Popover/Popover.stories.d.ts.map +1 -1
- package/dist/types/src/components/ScrollArea/ScrollArea.stories.d.ts +6 -0
- package/dist/types/src/components/ScrollArea/ScrollArea.stories.d.ts.map +1 -1
- package/dist/types/src/components/Select/Select.stories.d.ts +6 -0
- package/dist/types/src/components/Select/Select.stories.d.ts.map +1 -1
- package/dist/types/src/components/Status/Status.stories.d.ts +6 -0
- package/dist/types/src/components/Status/Status.stories.d.ts.map +1 -1
- package/dist/types/src/components/Tag/Tag.stories.d.ts.map +1 -1
- package/dist/types/src/components/Toast/Toast.stories.d.ts +6 -0
- package/dist/types/src/components/Toast/Toast.stories.d.ts.map +1 -1
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts +6 -0
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts.map +1 -1
- package/dist/types/src/components/Tooltip/Tooltip.stories.d.ts +6 -0
- package/dist/types/src/components/Tooltip/Tooltip.stories.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +0 -1
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/playground/Controls.stories.d.ts +6 -0
- package/dist/types/src/playground/Controls.stories.d.ts.map +1 -1
- package/dist/types/src/playground/Surfaces.stories.d.ts +6 -0
- package/dist/types/src/playground/Surfaces.stories.d.ts.map +1 -1
- package/dist/types/src/testing/decorators/index.d.ts +2 -0
- package/dist/types/src/testing/decorators/index.d.ts.map +1 -0
- package/dist/types/src/testing/decorators/with-theme.d.ts +3 -0
- package/dist/types/src/testing/decorators/with-theme.d.ts.map +1 -0
- package/dist/types/src/testing/index.d.ts +2 -0
- package/dist/types/src/testing/index.d.ts.map +1 -0
- package/package.json +8 -14
- package/src/components/Avatars/Avatar.stories.tsx +2 -0
- package/src/components/Avatars/AvatarGroup.stories.tsx +2 -0
- package/src/components/Breadcrumb/Breadcrumb.stories.tsx +2 -0
- package/src/components/Buttons/Button.stories.tsx +2 -0
- package/src/components/Buttons/Toggle.stories.tsx +2 -0
- package/src/components/Buttons/ToggleGroup.stories.tsx +2 -0
- package/src/components/Dialogs/AlertDialog.stories.tsx +2 -0
- package/src/components/Dialogs/Dialog.stories.tsx +2 -0
- package/src/components/DropdownMenu/DropdownMenu.stories.tsx +2 -0
- package/src/components/Input/Input.stories.tsx +21 -2
- package/src/components/Input/Input.tsx +3 -1
- package/src/components/Link/Link.stories.tsx +2 -0
- package/src/components/Lists/List.stories.tsx +2 -0
- package/src/components/Lists/Tree.stories.tsx +2 -0
- package/src/components/Main/Main.stories.tsx +5 -1
- package/src/components/Message/Message.stories.tsx +2 -0
- package/src/components/Popover/Popover.stories.tsx +3 -0
- package/src/components/ScrollArea/ScrollArea.stories.tsx +3 -0
- package/src/components/Select/Select.stories.tsx +3 -0
- package/src/components/Status/Status.stories.tsx +3 -0
- package/src/components/Tag/Tag.stories.tsx +3 -0
- package/src/components/Toast/Toast.stories.tsx +3 -0
- package/src/components/Toolbar/Toolbar.stories.tsx +3 -0
- package/src/components/Tooltip/Tooltip.stories.tsx +3 -0
- package/src/components/index.ts +0 -1
- package/src/playground/Controls.stories.tsx +3 -0
- package/src/playground/Surfaces.stories.tsx +4 -0
- package/src/{components/Card → testing/decorators}/index.ts +1 -1
- package/src/testing/decorators/with-theme.ts +22 -0
- package/src/testing/index.ts +5 -0
- package/dist/types/src/components/Card/Card.d.ts +0 -52
- package/dist/types/src/components/Card/Card.d.ts.map +0 -1
- package/dist/types/src/components/Card/Card.stories.d.ts +0 -56
- package/dist/types/src/components/Card/Card.stories.d.ts.map +0 -1
- package/dist/types/src/components/Card/index.d.ts +0 -2
- package/dist/types/src/components/Card/index.d.ts.map +0 -1
- package/src/components/Card/Card.stories.tsx +0 -220
- package/src/components/Card/Card.tsx +0 -147
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import '@dxosTheme';
|
|
6
|
-
|
|
7
|
-
import { DndContext, type DragEndEvent } from '@dnd-kit/core';
|
|
8
|
-
import { arrayMove, SortableContext, useSortable, verticalListSortingStrategy } from '@dnd-kit/sortable';
|
|
9
|
-
import { CSS } from '@dnd-kit/utilities';
|
|
10
|
-
import { faker } from '@faker-js/faker';
|
|
11
|
-
import React, { type FC, type PropsWithChildren, useState } from 'react';
|
|
12
|
-
|
|
13
|
-
import { chromeSurface, mx } from '@dxos/react-ui-theme';
|
|
14
|
-
|
|
15
|
-
import { Card } from './Card';
|
|
16
|
-
import { DensityProvider } from '../DensityProvider';
|
|
17
|
-
import { DropdownMenu } from '../DropdownMenu';
|
|
18
|
-
import { Input } from '../Input';
|
|
19
|
-
import { ScrollArea } from '../ScrollArea';
|
|
20
|
-
|
|
21
|
-
faker.seed(1);
|
|
22
|
-
|
|
23
|
-
// https://unsplash.com
|
|
24
|
-
// TODO(burdon): Use https://picsum.photos
|
|
25
|
-
const testImages = [
|
|
26
|
-
'https://images.unsplash.com/photo-1616394158624-a2ba9cfe2994',
|
|
27
|
-
'https://images.unsplash.com/photo-1507941097613-9f2157b69235',
|
|
28
|
-
'https://images.unsplash.com/photo-1431274172761-fca41d930114',
|
|
29
|
-
'https://images.unsplash.com/photo-1513635269975-59663e0ac1ad',
|
|
30
|
-
'https://images.unsplash.com/photo-1564221710304-0b37c8b9d729',
|
|
31
|
-
'https://images.unsplash.com/photo-1605425183435-25b7e99104a4',
|
|
32
|
-
];
|
|
33
|
-
|
|
34
|
-
type CardData = {
|
|
35
|
-
id: string;
|
|
36
|
-
title: string;
|
|
37
|
-
body: string;
|
|
38
|
-
image?: string;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const DraggableCard: FC<{ data: CardData; onDelete: (id: string) => void }> = ({
|
|
42
|
-
data: { id, title, body, image },
|
|
43
|
-
onDelete,
|
|
44
|
-
}) => {
|
|
45
|
-
const { attributes, listeners, setNodeRef, transform } = useSortable({ id });
|
|
46
|
-
const t = transform ? Object.assign(transform, { scaleY: 1 }) : null;
|
|
47
|
-
|
|
48
|
-
return (
|
|
49
|
-
<Card.Root ref={setNodeRef} style={{ transform: CSS.Transform.toString(t) }}>
|
|
50
|
-
<Card.Header>
|
|
51
|
-
<Card.DragHandle {...listeners} {...attributes} />
|
|
52
|
-
<Card.Title title={title} />
|
|
53
|
-
<DropdownMenu.Root>
|
|
54
|
-
<DropdownMenu.Trigger asChild>
|
|
55
|
-
<Card.Menu />
|
|
56
|
-
</DropdownMenu.Trigger>
|
|
57
|
-
<DropdownMenu.Content>
|
|
58
|
-
<DropdownMenu.Viewport>
|
|
59
|
-
<DropdownMenu.Item onClick={() => onDelete(id)}>Delete</DropdownMenu.Item>
|
|
60
|
-
</DropdownMenu.Viewport>
|
|
61
|
-
</DropdownMenu.Content>
|
|
62
|
-
</DropdownMenu.Root>
|
|
63
|
-
</Card.Header>
|
|
64
|
-
<Card.Body classNames={'text-sm'} gutter>
|
|
65
|
-
<p>{body}</p>
|
|
66
|
-
</Card.Body>
|
|
67
|
-
{image && <Card.Media src={image} classNames={'h-[160px]'} />}
|
|
68
|
-
</Card.Root>
|
|
69
|
-
);
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
const DraggableStory: FC<PropsWithChildren> = ({ children }) => {
|
|
73
|
-
const [cards, setCards] = useState<CardData[]>(
|
|
74
|
-
Array.from({ length: 7 }).map(() => ({
|
|
75
|
-
id: faker.string.uuid(),
|
|
76
|
-
title: faker.lorem.sentence(3),
|
|
77
|
-
body: faker.lorem.sentences(),
|
|
78
|
-
image: faker.datatype.boolean() ? faker.helpers.arrayElement(testImages) : undefined,
|
|
79
|
-
})),
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
const handleDelete = (id: string) => {
|
|
83
|
-
setCards((cards) => cards.filter((card) => card.id !== id));
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
const handleDragEnd = (event: DragEndEvent) => {
|
|
87
|
-
const { active, over } = event;
|
|
88
|
-
if (active.id !== over?.id) {
|
|
89
|
-
setCards((cards) => {
|
|
90
|
-
const oldIndex = cards.findIndex((card) => card.id === active.id);
|
|
91
|
-
const newIndex = cards.findIndex((card) => card.id === over?.id);
|
|
92
|
-
return arrayMove(cards, oldIndex, newIndex);
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
return (
|
|
98
|
-
<DndContext onDragEnd={handleDragEnd}>
|
|
99
|
-
<SortableContext items={cards.map(({ id }) => id)} strategy={verticalListSortingStrategy}>
|
|
100
|
-
<div className='flex flex-col overflow-y-scroll'>
|
|
101
|
-
<div className='flex flex-col gap-4'>
|
|
102
|
-
{cards.map((card) => (
|
|
103
|
-
<DraggableCard key={card.id} data={card} onDelete={handleDelete} />
|
|
104
|
-
))}
|
|
105
|
-
</div>
|
|
106
|
-
</div>
|
|
107
|
-
</SortableContext>
|
|
108
|
-
</DndContext>
|
|
109
|
-
);
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
const ReadonlyCardStory = () => {
|
|
113
|
-
return (
|
|
114
|
-
<div className='flex flex-col overflow-y-scroll'>
|
|
115
|
-
<div className='flex flex-col gap-4'>
|
|
116
|
-
<Card.Root square noPadding>
|
|
117
|
-
<Card.Header floating>
|
|
118
|
-
<Card.DragHandle position='left' />
|
|
119
|
-
<Card.Menu position='right' />
|
|
120
|
-
</Card.Header>
|
|
121
|
-
<Card.Media src={testImages[1]} />
|
|
122
|
-
</Card.Root>
|
|
123
|
-
|
|
124
|
-
<Card.Root>
|
|
125
|
-
<Card.Header>
|
|
126
|
-
<Card.Title title={faker.lorem.sentence(3)} />
|
|
127
|
-
</Card.Header>
|
|
128
|
-
</Card.Root>
|
|
129
|
-
|
|
130
|
-
<Card.Root>
|
|
131
|
-
<Card.Body classNames={'text-sm font-thin h-[100px]'}>
|
|
132
|
-
<ScrollArea.Root>
|
|
133
|
-
<ScrollArea.Viewport>{faker.lorem.sentences(16)}</ScrollArea.Viewport>
|
|
134
|
-
<ScrollArea.Scrollbar orientation='vertical'>
|
|
135
|
-
<ScrollArea.Thumb />
|
|
136
|
-
</ScrollArea.Scrollbar>
|
|
137
|
-
</ScrollArea.Root>
|
|
138
|
-
</Card.Body>
|
|
139
|
-
</Card.Root>
|
|
140
|
-
|
|
141
|
-
<Card.Root>
|
|
142
|
-
<Card.Header>
|
|
143
|
-
<Card.Title center title={faker.lorem.sentence(3)} />
|
|
144
|
-
</Card.Header>
|
|
145
|
-
<Card.Body classNames={'text-sm font-thin'}>{faker.lorem.sentences(3)}</Card.Body>
|
|
146
|
-
</Card.Root>
|
|
147
|
-
|
|
148
|
-
<Card.Root>
|
|
149
|
-
<Card.Header>
|
|
150
|
-
<Card.DragHandle />
|
|
151
|
-
<Card.Title title={faker.lorem.sentence(8)} />
|
|
152
|
-
{/* TODO(burdon): Menu util. */}
|
|
153
|
-
<Card.Menu />
|
|
154
|
-
</Card.Header>
|
|
155
|
-
<Card.Body gutter classNames={'gap-2 text-sm font-thin'}>
|
|
156
|
-
<p>Content with gutter</p>
|
|
157
|
-
<p className='line-clamp-3'>{faker.lorem.sentences(3)}</p>
|
|
158
|
-
</Card.Body>
|
|
159
|
-
</Card.Root>
|
|
160
|
-
|
|
161
|
-
<Card.Root>
|
|
162
|
-
<Card.Header>
|
|
163
|
-
<Card.DragHandle />
|
|
164
|
-
<Card.Title title={faker.lorem.sentence(3)} />
|
|
165
|
-
<Card.Menu />
|
|
166
|
-
</Card.Header>
|
|
167
|
-
<Card.Body gutter classNames={'text-sm gap-2 font-thin'}>
|
|
168
|
-
<p className='line-clamp-3'>{faker.lorem.sentences(1)}</p>
|
|
169
|
-
</Card.Body>
|
|
170
|
-
<Card.Media classNames={'h-[200px] grayscale'} src={testImages[0]} />
|
|
171
|
-
<Card.Body gutter classNames={'text-sm gap-2 font-thin'}>
|
|
172
|
-
<p className='line-clamp-3'>{faker.lorem.sentences(3)}</p>
|
|
173
|
-
</Card.Body>
|
|
174
|
-
</Card.Root>
|
|
175
|
-
</div>
|
|
176
|
-
</div>
|
|
177
|
-
);
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
const EditableCardStory = () => {
|
|
181
|
-
return (
|
|
182
|
-
<div className='flex flex-col h-full justify-center'>
|
|
183
|
-
<Card.Root>
|
|
184
|
-
<Card.Header>
|
|
185
|
-
<Card.DragHandle />
|
|
186
|
-
<Input.Root>
|
|
187
|
-
<Input.TextInput classNames={'-mx-2 px-2'} variant='subdued' placeholder={'Title'} />
|
|
188
|
-
</Input.Root>
|
|
189
|
-
<Card.Menu />
|
|
190
|
-
</Card.Header>
|
|
191
|
-
<Card.Body gutter classNames={'gap-2 text-sm font-thin'}>
|
|
192
|
-
{faker.lorem.sentences()}
|
|
193
|
-
</Card.Body>
|
|
194
|
-
</Card.Root>
|
|
195
|
-
</div>
|
|
196
|
-
);
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
export default {
|
|
200
|
-
component: Card,
|
|
201
|
-
decorators: [
|
|
202
|
-
(Story: any) => (
|
|
203
|
-
<div className={mx('flex h-screen w-full justify-center overflow-hidden', chromeSurface)}>
|
|
204
|
-
<div className='flex flex-col w-[360px] overflow-hidden'>
|
|
205
|
-
{/* TODO(burdon): Story for different densities. */}
|
|
206
|
-
<DensityProvider density='fine'>
|
|
207
|
-
<Story />
|
|
208
|
-
</DensityProvider>
|
|
209
|
-
</div>
|
|
210
|
-
</div>
|
|
211
|
-
),
|
|
212
|
-
],
|
|
213
|
-
parameters: {
|
|
214
|
-
layout: 'fullscreen',
|
|
215
|
-
},
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
export const Draggable = () => <DraggableStory />;
|
|
219
|
-
export const ReadOnly = () => <ReadonlyCardStory />;
|
|
220
|
-
export const Editable = () => <EditableCardStory />;
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { DotsSixVertical, DotsThreeVertical, type Icon } from '@phosphor-icons/react';
|
|
6
|
-
import { type Primitive } from '@radix-ui/react-primitive';
|
|
7
|
-
import React, {
|
|
8
|
-
type ComponentPropsWithoutRef,
|
|
9
|
-
type ComponentPropsWithRef,
|
|
10
|
-
type FC,
|
|
11
|
-
forwardRef,
|
|
12
|
-
type PropsWithChildren,
|
|
13
|
-
} from 'react';
|
|
14
|
-
|
|
15
|
-
import { useDensityContext, useThemeContext } from '../../hooks';
|
|
16
|
-
import { type ThemedClassName } from '../../util';
|
|
17
|
-
import { DropdownMenu } from '../DropdownMenu';
|
|
18
|
-
|
|
19
|
-
type CardRootProps = ThemedClassName<ComponentPropsWithRef<typeof Primitive.div>> & {
|
|
20
|
-
grow?: boolean;
|
|
21
|
-
square?: boolean;
|
|
22
|
-
noPadding?: boolean;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
// TODO(burdon): Forward refs for all components?
|
|
26
|
-
const CardRoot = forwardRef<HTMLDivElement, CardRootProps>(
|
|
27
|
-
({ grow, square, noPadding, classNames, children, ...props }, forwardedRef) => {
|
|
28
|
-
const { tx } = useThemeContext();
|
|
29
|
-
return (
|
|
30
|
-
<div {...props} ref={forwardedRef} className={tx('card.root', 'card', { grow, square, noPadding }, classNames)}>
|
|
31
|
-
{children}
|
|
32
|
-
</div>
|
|
33
|
-
);
|
|
34
|
-
},
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
type CardHeaderProps = ThemedClassName<ComponentPropsWithoutRef<'div'>> & { floating?: boolean };
|
|
38
|
-
|
|
39
|
-
export const CardHeader: FC<CardHeaderProps> = ({ floating, classNames, children, ...props }) => {
|
|
40
|
-
const { tx } = useThemeContext();
|
|
41
|
-
return (
|
|
42
|
-
<div {...props} className={tx('card.header', 'card', { floating }, classNames)}>
|
|
43
|
-
{children}
|
|
44
|
-
</div>
|
|
45
|
-
);
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
type CardTitleProps = ThemedClassName<ComponentPropsWithoutRef<'div'>> & {
|
|
49
|
-
center?: boolean;
|
|
50
|
-
title?: string;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
export const CardTitle: FC<CardTitleProps> = ({ center, title, classNames, ...props }) => {
|
|
54
|
-
const { tx } = useThemeContext();
|
|
55
|
-
return (
|
|
56
|
-
<div {...props} className={tx('card.title', 'card', { center }, classNames)}>
|
|
57
|
-
{title}
|
|
58
|
-
</div>
|
|
59
|
-
);
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
// TODO(burdon): Reuse ListItemEndcap?
|
|
63
|
-
type CardDragHandleProps = ThemedClassName<ComponentPropsWithoutRef<'div'>> & { position?: 'left' | 'right' };
|
|
64
|
-
|
|
65
|
-
const CardDragHandle: FC<CardDragHandleProps> = ({ position, classNames, ...props }) => {
|
|
66
|
-
const { tx } = useThemeContext();
|
|
67
|
-
const density = useDensityContext();
|
|
68
|
-
return (
|
|
69
|
-
<div {...props} className={tx('card.dragHandle', 'card', { density, position }, classNames)}>
|
|
70
|
-
<DotsSixVertical className={tx('card.dragHandleIcon', 'card')} />
|
|
71
|
-
</div>
|
|
72
|
-
);
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
type CardEndcapProps = ThemedClassName<ComponentPropsWithoutRef<'div'>> & { Icon: Icon; position?: 'left' | 'right' };
|
|
76
|
-
|
|
77
|
-
const CardEndcap: FC<CardEndcapProps> = ({ Icon, position, classNames, ...props }) => {
|
|
78
|
-
const { tx } = useThemeContext();
|
|
79
|
-
const density = useDensityContext();
|
|
80
|
-
return (
|
|
81
|
-
<div {...props} className={tx('card.menu', 'card', { density, position }, classNames)}>
|
|
82
|
-
<Icon className={tx('card.menuIcon', 'card')} />
|
|
83
|
-
</div>
|
|
84
|
-
);
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
type CardMenuProps = PropsWithChildren<
|
|
88
|
-
ThemedClassName<ComponentPropsWithoutRef<'div'>> & { position?: 'left' | 'right' }
|
|
89
|
-
>;
|
|
90
|
-
|
|
91
|
-
// TODO(burdon): Reconcile with Endcap (remove dropdown from here). See ListItem.Endcap (style icon/size?)
|
|
92
|
-
const CardMenu = forwardRef<HTMLDivElement, CardMenuProps>(
|
|
93
|
-
({ children, position, classNames, ...props }, forwardRef) => {
|
|
94
|
-
const { tx } = useThemeContext();
|
|
95
|
-
const density = useDensityContext();
|
|
96
|
-
return (
|
|
97
|
-
<div {...props} className={tx('card.menu', 'card', { density, position }, classNames)} ref={forwardRef}>
|
|
98
|
-
<DropdownMenu.Root>
|
|
99
|
-
<DropdownMenu.Trigger asChild>
|
|
100
|
-
<DotsThreeVertical className={tx('card.menuIcon', 'card', {})} />
|
|
101
|
-
</DropdownMenu.Trigger>
|
|
102
|
-
{/* TODO(burdon): Position to the left of the menu button. */}
|
|
103
|
-
<DropdownMenu.Content>
|
|
104
|
-
<DropdownMenu.Viewport>{children}</DropdownMenu.Viewport>
|
|
105
|
-
</DropdownMenu.Content>
|
|
106
|
-
</DropdownMenu.Root>
|
|
107
|
-
</div>
|
|
108
|
-
);
|
|
109
|
-
},
|
|
110
|
-
);
|
|
111
|
-
|
|
112
|
-
type CardBodyProps = ThemedClassName<ComponentPropsWithoutRef<'div'>> & { gutter?: boolean };
|
|
113
|
-
|
|
114
|
-
export const CardBody: FC<CardBodyProps> = ({ gutter, classNames, children, ...props }) => {
|
|
115
|
-
const { tx } = useThemeContext();
|
|
116
|
-
const density = useDensityContext();
|
|
117
|
-
return (
|
|
118
|
-
<div {...props} className={tx('card.body', 'card', { density, gutter }, classNames)}>
|
|
119
|
-
{children}
|
|
120
|
-
</div>
|
|
121
|
-
);
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
type CardMediaProps = ThemedClassName<ComponentPropsWithoutRef<'div'>> & { src?: string; contain?: boolean };
|
|
125
|
-
|
|
126
|
-
// TODO(burdon): Option to set to 50% of height of card.
|
|
127
|
-
export const CardMedia: FC<CardMediaProps> = ({ src, contain, classNames, ...props }) => {
|
|
128
|
-
const { tx } = useThemeContext();
|
|
129
|
-
return (
|
|
130
|
-
<div className='flex grow overflow-hidden'>
|
|
131
|
-
<img {...props} className={tx('card.media', 'card', { contain }, classNames)} src={src} />
|
|
132
|
-
</div>
|
|
133
|
-
);
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
export const Card = {
|
|
137
|
-
Root: CardRoot,
|
|
138
|
-
Header: CardHeader,
|
|
139
|
-
DragHandle: CardDragHandle,
|
|
140
|
-
Endcap: CardEndcap,
|
|
141
|
-
Menu: CardMenu,
|
|
142
|
-
Title: CardTitle,
|
|
143
|
-
Body: CardBody,
|
|
144
|
-
Media: CardMedia,
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
export type { CardRootProps };
|