@dxos/react-ui-card 0.8.2 → 0.11.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.
Files changed (74) hide show
  1. package/LICENSE +102 -5
  2. package/dist/lib/index.mjs +288 -0
  3. package/dist/lib/index.mjs.map +1 -0
  4. package/dist/lib/translations.mjs +11 -0
  5. package/dist/lib/translations.mjs.map +1 -0
  6. package/dist/types/src/components/Avatar/Avatar.d.ts +14 -0
  7. package/dist/types/src/components/Avatar/Avatar.d.ts.map +1 -0
  8. package/dist/types/src/components/Avatar/Avatar.stories.d.ts +15 -0
  9. package/dist/types/src/components/Avatar/Avatar.stories.d.ts.map +1 -0
  10. package/dist/types/src/components/Avatar/avatar-name.d.ts +6 -0
  11. package/dist/types/src/components/Avatar/avatar-name.d.ts.map +1 -0
  12. package/dist/types/src/components/Avatar/index.d.ts +3 -0
  13. package/dist/types/src/components/Avatar/index.d.ts.map +1 -0
  14. package/dist/types/src/components/CardTile/CardTile.d.ts +46 -0
  15. package/dist/types/src/components/CardTile/CardTile.d.ts.map +1 -0
  16. package/dist/types/src/components/CardTile/CardTile.stories.d.ts +27 -0
  17. package/dist/types/src/components/CardTile/CardTile.stories.d.ts.map +1 -0
  18. package/dist/types/src/components/CardTile/index.d.ts +2 -0
  19. package/dist/types/src/components/CardTile/index.d.ts.map +1 -0
  20. package/dist/types/src/components/Row/Row.d.ts +100 -0
  21. package/dist/types/src/components/Row/Row.d.ts.map +1 -0
  22. package/dist/types/src/components/Row/Row.stories.d.ts +23 -0
  23. package/dist/types/src/components/Row/Row.stories.d.ts.map +1 -0
  24. package/dist/types/src/components/Row/index.d.ts +2 -0
  25. package/dist/types/src/components/Row/index.d.ts.map +1 -0
  26. package/dist/types/src/components/index.d.ts +3 -1
  27. package/dist/types/src/components/index.d.ts.map +1 -1
  28. package/dist/types/src/hooks/index.d.ts +2 -0
  29. package/dist/types/src/hooks/index.d.ts.map +1 -0
  30. package/dist/types/src/hooks/useActorContact.d.ts +5 -0
  31. package/dist/types/src/hooks/useActorContact.d.ts.map +1 -0
  32. package/dist/types/src/index.d.ts +2 -1
  33. package/dist/types/src/index.d.ts.map +1 -1
  34. package/dist/types/src/translations.d.ts +11 -0
  35. package/dist/types/src/translations.d.ts.map +1 -0
  36. package/dist/types/src/util.d.ts +3 -0
  37. package/dist/types/src/util.d.ts.map +1 -0
  38. package/dist/types/tsconfig.tsbuildinfo +1 -1
  39. package/package.json +39 -30
  40. package/src/components/Avatar/Avatar.stories.tsx +31 -0
  41. package/src/components/Avatar/Avatar.tsx +39 -0
  42. package/src/components/Avatar/avatar-name.ts +19 -0
  43. package/src/components/Avatar/index.ts +7 -0
  44. package/src/components/CardTile/CardTile.stories.tsx +54 -0
  45. package/src/components/CardTile/CardTile.tsx +103 -0
  46. package/src/components/CardTile/index.ts +5 -0
  47. package/src/components/Row/Row.stories.tsx +65 -0
  48. package/src/components/Row/Row.tsx +379 -0
  49. package/src/components/Row/index.ts +5 -0
  50. package/src/components/index.ts +4 -2
  51. package/src/hooks/index.ts +5 -0
  52. package/src/hooks/useActorContact.ts +31 -0
  53. package/src/index.ts +3 -2
  54. package/src/translations.ts +19 -0
  55. package/src/util.ts +7 -0
  56. package/README.md +0 -3
  57. package/dist/lib/browser/index.mjs +0 -200
  58. package/dist/lib/browser/index.mjs.map +0 -7
  59. package/dist/lib/browser/meta.json +0 -1
  60. package/dist/lib/node/index.cjs +0 -243
  61. package/dist/lib/node/index.cjs.map +0 -7
  62. package/dist/lib/node/meta.json +0 -1
  63. package/dist/lib/node-esm/index.mjs +0 -202
  64. package/dist/lib/node-esm/index.mjs.map +0 -7
  65. package/dist/lib/node-esm/meta.json +0 -1
  66. package/dist/types/src/components/Card.d.ts +0 -52
  67. package/dist/types/src/components/Card.d.ts.map +0 -1
  68. package/dist/types/src/components/Card.stories.d.ts +0 -57
  69. package/dist/types/src/components/Card.stories.d.ts.map +0 -1
  70. package/dist/types/src/theme.d.ts +0 -31
  71. package/dist/types/src/theme.d.ts.map +0 -1
  72. package/src/components/Card.stories.tsx +0 -217
  73. package/src/components/Card.tsx +0 -149
  74. package/src/theme.ts +0 -101
@@ -1 +0,0 @@
1
- {"version":3,"file":"Card.d.ts","sourceRoot":"","sources":["../../../../src/components/Card.tsx"],"names":[],"mappings":"AAIA,OAAO,EAA8C,KAAK,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAC9F,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,KAAK,EAAE,EACZ,KAAK,wBAAwB,EAC7B,KAAK,qBAAqB,EAC1B,KAAK,EAAE,EAGR,MAAM,OAAO,CAAC;AAEf,OAAO,EAAmC,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAcvF,KAAK,aAAa,GAAG,eAAe,CAAC,qBAAqB,CAAC,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC,GAAG;IAClF,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAaF,KAAK,eAAe,GAAG,eAAe,CAAC,wBAAwB,CAAC,KAAK,CAAC,CAAC,GAAG;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAEjG,eAAO,MAAM,UAAU,EAAE,EAAE,CAAC,eAAe,CAM1C,CAAC;AAEF,KAAK,cAAc,GAAG,eAAe,CAAC,wBAAwB,CAAC,KAAK,CAAC,CAAC,GAAG;IACvE,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,eAAO,MAAM,SAAS,EAAE,EAAE,CAAC,cAAc,CAMxC,CAAC;AAGF,KAAK,mBAAmB,GAAG,eAAe,CAAC,wBAAwB,CAAC,KAAK,CAAC,CAAC,GAAG;IAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,CAAC;AAW9G,KAAK,eAAe,GAAG,eAAe,CAAC,wBAAwB,CAAC,KAAK,CAAC,CAAC,GAAG;IAAE,IAAI,CAAC,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,CAAC;AAmCvH,KAAK,aAAa,GAAG,eAAe,CAAC,wBAAwB,CAAC,KAAK,CAAC,CAAC,GAAG;IAAE,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAE7F,eAAO,MAAM,QAAQ,EAAE,EAAE,CAAC,aAAa,CAOtC,CAAC;AAEF,KAAK,cAAc,GAAG,eAAe,CAAC,wBAAwB,CAAC,KAAK,CAAC,CAAC,GAAG;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAG7G,eAAO,MAAM,SAAS,EAAE,EAAE,CAAC,cAAc,CAMxC,CAAC;AAEF,eAAO,MAAM,IAAI;;;;;;;;mBA7CiD,MAAM,GAAG,OAAO;;;;;;;CAsDjF,CAAC;AAEF,YAAY,EAAE,aAAa,EAAE,CAAC"}
@@ -1,57 +0,0 @@
1
- import '@dxos-theme';
2
- import React from 'react';
3
- declare const _default: {
4
- title: string;
5
- component: {
6
- Root: React.ForwardRefExoticComponent<Omit<import("./Card").CardRootProps, "ref"> & React.RefAttributes<HTMLDivElement>>;
7
- Header: React.FC<Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "className"> & {
8
- classNames?: import("@dxos/react-ui-types").ClassNameValue;
9
- } & {
10
- floating?: boolean;
11
- }>;
12
- DragHandle: React.FC<Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "className"> & {
13
- classNames?: import("@dxos/react-ui-types").ClassNameValue;
14
- } & {
15
- position?: "left" | "right";
16
- }>;
17
- Endcap: React.FC<Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "className"> & {
18
- classNames?: import("@dxos/react-ui-types").ClassNameValue;
19
- } & {
20
- Icon?: import("@phosphor-icons/react").Icon;
21
- position?: "left" | "right";
22
- }>;
23
- Menu: React.ForwardRefExoticComponent<Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "className"> & {
24
- classNames?: import("@dxos/react-ui-types").ClassNameValue;
25
- } & {
26
- position?: "left" | "right";
27
- } & {
28
- children?: React.ReactNode | undefined;
29
- } & React.RefAttributes<HTMLDivElement>>;
30
- Title: React.FC<Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "className"> & {
31
- classNames?: import("@dxos/react-ui-types").ClassNameValue;
32
- } & {
33
- center?: boolean;
34
- title?: string;
35
- }>;
36
- Body: React.FC<Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "className"> & {
37
- classNames?: import("@dxos/react-ui-types").ClassNameValue;
38
- } & {
39
- gutter?: boolean;
40
- }>;
41
- Media: React.FC<Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "className"> & {
42
- classNames?: import("@dxos/react-ui-types").ClassNameValue;
43
- } & {
44
- src?: string;
45
- contain?: boolean;
46
- }>;
47
- };
48
- decorators: import("@storybook/react").Decorator[];
49
- parameters: {
50
- layout: string;
51
- };
52
- };
53
- export default _default;
54
- export declare const Draggable: () => React.JSX.Element;
55
- export declare const ReadOnly: () => React.JSX.Element;
56
- export declare const Editable: () => React.JSX.Element;
57
- //# sourceMappingURL=Card.stories.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Card.stories.d.ts","sourceRoot":"","sources":["../../../../src/components/Card.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,aAAa,CAAC;AAKrB,OAAO,KAAoD,MAAM,OAAO,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2LzE,wBAgBE;AAEF,eAAO,MAAM,SAAS,yBAA2B,CAAC;AAClD,eAAO,MAAM,QAAQ,yBAA8B,CAAC;AACpD,eAAO,MAAM,QAAQ,yBAA8B,CAAC"}
@@ -1,31 +0,0 @@
1
- import { type ComponentFunction, type Density, type Theme } from '@dxos/react-ui';
2
- export type CardStyleProps = Partial<{
3
- density: Density;
4
- grow?: boolean;
5
- square?: boolean;
6
- rounded?: boolean;
7
- noPadding?: boolean;
8
- }>;
9
- export declare const cardRoot: ComponentFunction<CardStyleProps>;
10
- export declare const cardHeader: ComponentFunction<CardStyleProps & {
11
- floating?: boolean;
12
- }>;
13
- export declare const cardTitle: ComponentFunction<CardStyleProps & {
14
- center?: boolean;
15
- }>;
16
- export declare const cardDragHandle: ComponentFunction<CardStyleProps & {
17
- position?: 'left' | 'right';
18
- }>;
19
- export declare const cardDragHandleIcon: ComponentFunction<CardStyleProps>;
20
- export declare const cardMenu: ComponentFunction<CardStyleProps & {
21
- position?: 'left' | 'right';
22
- }>;
23
- export declare const cardMenuIcon: ComponentFunction<CardStyleProps>;
24
- export declare const cardBody: ComponentFunction<CardStyleProps & {
25
- gutter?: boolean;
26
- }>;
27
- export declare const cardMedia: ComponentFunction<CardStyleProps & {
28
- contain?: boolean;
29
- }>;
30
- export declare const cardTheme: Theme<CardStyleProps>;
31
- //# sourceMappingURL=theme.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../../../src/theme.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,iBAAiB,EAAE,KAAK,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAOlF,MAAM,MAAM,cAAc,GAAG,OAAO,CAAC;IACnC,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC,CAAC;AAEH,eAAO,MAAM,QAAQ,EAAE,iBAAiB,CAAC,cAAc,CAUpD,CAAC;AAEJ,eAAO,MAAM,UAAU,EAAE,iBAAiB,CAAC,cAAc,GAAG;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,CAC4B,CAAC;AAE/G,eAAO,MAAM,SAAS,EAAE,iBAAiB,CAAC,cAAc,GAAG;IAAE,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE,CACY,CAAC;AAE5F,eAAO,MAAM,cAAc,EAAE,iBAAiB,CAAC,cAAc,GAAG;IAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,CAW5F,CAAC;AAEJ,eAAO,MAAM,kBAAkB,EAAE,iBAAiB,CAAC,cAAc,CACvB,CAAC;AAG3C,eAAO,MAAM,QAAQ,EAAE,iBAAiB,CAAC,cAAc,GAAG;IAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,CAWtF,CAAC;AAEJ,eAAO,MAAM,YAAY,EAAE,iBAAiB,CAAC,cAAc,CAAmD,CAAC;AAE/G,eAAO,MAAM,QAAQ,EAAE,iBAAiB,CAAC,cAAc,GAAG;IAAE,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE,CAU3E,CAAC;AAEJ,eAAO,MAAM,SAAS,EAAE,iBAAiB,CAAC,cAAc,GAAG;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,CAO7E,CAAC;AAEJ,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,cAAc,CAU3C,CAAC"}
@@ -1,217 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import '@dxos-theme';
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 React, { type FC, type PropsWithChildren, useState } from 'react';
11
-
12
- import { faker } from '@dxos/random';
13
- import { DropdownMenu, Input, ScrollArea } from '@dxos/react-ui';
14
- import { modalSurface, mx } from '@dxos/react-ui-theme';
15
- import { withTheme } from '@dxos/storybook-utils';
16
-
17
- import { Card } from './Card';
18
-
19
- faker.seed(1);
20
-
21
- // https://unsplash.com
22
- // TODO(burdon): Use https://picsum.photos
23
- const testImages = [
24
- 'https://images.unsplash.com/photo-1616394158624-a2ba9cfe2994',
25
- 'https://images.unsplash.com/photo-1507941097613-9f2157b69235',
26
- 'https://images.unsplash.com/photo-1431274172761-fca41d930114',
27
- 'https://images.unsplash.com/photo-1513635269975-59663e0ac1ad',
28
- 'https://images.unsplash.com/photo-1564221710304-0b37c8b9d729',
29
- 'https://images.unsplash.com/photo-1605425183435-25b7e99104a4',
30
- ];
31
-
32
- type CardData = {
33
- id: string;
34
- title: string;
35
- body: string;
36
- image?: string;
37
- };
38
-
39
- const DraggableCard: FC<{ data: CardData; onDelete: (id: string) => void }> = ({
40
- data: { id, title, body, image },
41
- onDelete,
42
- }) => {
43
- const { attributes, listeners, setNodeRef, transform } = useSortable({ id });
44
- const t = transform ? Object.assign(transform, { scaleY: 1 }) : null;
45
-
46
- return (
47
- <Card.Root ref={setNodeRef} style={{ transform: CSS.Transform.toString(t) }}>
48
- <Card.Header>
49
- <Card.DragHandle {...listeners} {...attributes} />
50
- <Card.Title title={title} />
51
- <DropdownMenu.Root>
52
- <DropdownMenu.Trigger asChild>
53
- <Card.Menu />
54
- </DropdownMenu.Trigger>
55
- <DropdownMenu.Content>
56
- <DropdownMenu.Viewport>
57
- <DropdownMenu.Item onClick={() => onDelete(id)}>Delete</DropdownMenu.Item>
58
- </DropdownMenu.Viewport>
59
- </DropdownMenu.Content>
60
- </DropdownMenu.Root>
61
- </Card.Header>
62
- <Card.Body classNames={'text-sm'} gutter>
63
- <p>{body}</p>
64
- </Card.Body>
65
- {image && <Card.Media src={image} classNames={'h-[160px]'} />}
66
- </Card.Root>
67
- );
68
- };
69
-
70
- const DraggableStory: FC<PropsWithChildren> = ({ children }) => {
71
- const [cards, setCards] = useState<CardData[]>(
72
- Array.from({ length: 7 }).map(() => ({
73
- id: faker.string.uuid(),
74
- title: faker.lorem.sentence(3),
75
- body: faker.lorem.sentences(),
76
- image: faker.datatype.boolean() ? faker.helpers.arrayElement(testImages) : undefined,
77
- })),
78
- );
79
-
80
- const handleDelete = (id: string) => {
81
- setCards((cards) => cards.filter((card) => card.id !== id));
82
- };
83
-
84
- const handleDragEnd = (event: DragEndEvent) => {
85
- const { active, over } = event;
86
- if (active.id !== over?.id) {
87
- setCards((cards) => {
88
- const oldIndex = cards.findIndex((card) => card.id === active.id);
89
- const newIndex = cards.findIndex((card) => card.id === over?.id);
90
- return arrayMove(cards, oldIndex, newIndex);
91
- });
92
- }
93
- };
94
-
95
- return (
96
- <DndContext onDragEnd={handleDragEnd}>
97
- <SortableContext items={cards.map(({ id }) => id)} strategy={verticalListSortingStrategy}>
98
- <div className='flex flex-col overflow-y-scroll'>
99
- <div className='flex flex-col gap-4'>
100
- {cards.map((card) => (
101
- <DraggableCard key={card.id} data={card} onDelete={handleDelete} />
102
- ))}
103
- </div>
104
- </div>
105
- </SortableContext>
106
- </DndContext>
107
- );
108
- };
109
-
110
- const ReadonlyCardStory = () => {
111
- return (
112
- <div className='flex flex-col overflow-y-scroll'>
113
- <div className='flex flex-col gap-4'>
114
- <Card.Root square noPadding>
115
- <Card.Header floating>
116
- <Card.DragHandle position='left' />
117
- <Card.Menu position='right' />
118
- </Card.Header>
119
- <Card.Media src={testImages[1]} />
120
- </Card.Root>
121
-
122
- <Card.Root>
123
- <Card.Header>
124
- <Card.Title title={faker.lorem.sentence(3)} />
125
- </Card.Header>
126
- </Card.Root>
127
-
128
- <Card.Root>
129
- <Card.Body classNames={'text-sm font-thin h-[100px]'}>
130
- <ScrollArea.Root>
131
- <ScrollArea.Viewport>{faker.lorem.sentences(16)}</ScrollArea.Viewport>
132
- <ScrollArea.Scrollbar orientation='vertical'>
133
- <ScrollArea.Thumb />
134
- </ScrollArea.Scrollbar>
135
- </ScrollArea.Root>
136
- </Card.Body>
137
- </Card.Root>
138
-
139
- <Card.Root>
140
- <Card.Header>
141
- <Card.Title center title={faker.lorem.sentence(3)} />
142
- </Card.Header>
143
- <Card.Body classNames={'text-sm font-thin'}>{faker.lorem.sentences(3)}</Card.Body>
144
- </Card.Root>
145
-
146
- <Card.Root>
147
- <Card.Header>
148
- <Card.DragHandle />
149
- <Card.Title title={faker.lorem.sentence(8)} />
150
- {/* TODO(burdon): Menu util. */}
151
- <Card.Menu />
152
- </Card.Header>
153
- <Card.Body gutter classNames={'gap-2 text-sm font-thin'}>
154
- <p>Content with gutter</p>
155
- <p className='line-clamp-3'>{faker.lorem.sentences(3)}</p>
156
- </Card.Body>
157
- </Card.Root>
158
-
159
- <Card.Root>
160
- <Card.Header>
161
- <Card.DragHandle />
162
- <Card.Title title={faker.lorem.sentence(3)} />
163
- <Card.Menu />
164
- </Card.Header>
165
- <Card.Body gutter classNames={'text-sm gap-2 font-thin'}>
166
- <p className='line-clamp-3'>{faker.lorem.sentences(1)}</p>
167
- </Card.Body>
168
- <Card.Media classNames={'h-[200px] grayscale'} src={testImages[0]} />
169
- <Card.Body gutter classNames={'text-sm gap-2 font-thin'}>
170
- <p className='line-clamp-3'>{faker.lorem.sentences(3)}</p>
171
- </Card.Body>
172
- </Card.Root>
173
- </div>
174
- </div>
175
- );
176
- };
177
-
178
- const EditableCardStory = () => {
179
- return (
180
- <div className='flex flex-col h-full justify-center'>
181
- <Card.Root>
182
- <Card.Header>
183
- <Card.DragHandle />
184
- <Input.Root>
185
- <Input.TextInput classNames={'-mx-2 px-2'} variant='subdued' placeholder={'Title'} />
186
- </Input.Root>
187
- <Card.Menu />
188
- </Card.Header>
189
- <Card.Body gutter classNames={'gap-2 text-sm font-thin'}>
190
- {faker.lorem.sentences()}
191
- </Card.Body>
192
- </Card.Root>
193
- </div>
194
- );
195
- };
196
-
197
- export default {
198
- title: 'ui/react-ui-card/Card',
199
- component: Card,
200
- decorators: [
201
- withTheme,
202
- (Story: any) => (
203
- <div className={mx('flex h-screen w-full justify-center overflow-hidden', modalSurface)}>
204
- <div className='flex flex-col w-[360px] overflow-hidden'>
205
- <Story />
206
- </div>
207
- </div>
208
- ),
209
- ],
210
- parameters: {
211
- layout: 'fullscreen',
212
- },
213
- };
214
-
215
- export const Draggable = () => <DraggableStory />;
216
- export const ReadOnly = () => <ReadonlyCardStory />;
217
- export const Editable = () => <EditableCardStory />;
@@ -1,149 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import { Circle, 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
- type PropsWithChildren,
12
- forwardRef,
13
- } from 'react';
14
-
15
- import { useDensityContext, DropdownMenu, type ThemedClassName } from '@dxos/react-ui';
16
-
17
- import {
18
- cardBody,
19
- cardDragHandle,
20
- cardDragHandleIcon,
21
- cardHeader,
22
- cardMedia,
23
- cardMenu,
24
- cardMenuIcon,
25
- cardRoot,
26
- cardTitle,
27
- } from '../theme';
28
-
29
- type CardRootProps = ThemedClassName<ComponentPropsWithRef<typeof Primitive.div>> & {
30
- grow?: boolean;
31
- square?: boolean;
32
- noPadding?: boolean;
33
- };
34
-
35
- // TODO(burdon): Forward refs for all components?
36
- const CardRoot = forwardRef<HTMLDivElement, CardRootProps>(
37
- ({ grow, square, noPadding, classNames, children, ...props }, forwardedRef) => {
38
- return (
39
- <div {...props} ref={forwardedRef} className={cardRoot({ grow, square, noPadding }, classNames)}>
40
- {children}
41
- </div>
42
- );
43
- },
44
- );
45
-
46
- type CardHeaderProps = ThemedClassName<ComponentPropsWithoutRef<'div'>> & { floating?: boolean };
47
-
48
- export const CardHeader: FC<CardHeaderProps> = ({ floating, classNames, children, ...props }) => {
49
- return (
50
- <div {...props} className={cardHeader({ floating }, classNames)}>
51
- {children}
52
- </div>
53
- );
54
- };
55
-
56
- type CardTitleProps = ThemedClassName<ComponentPropsWithoutRef<'div'>> & {
57
- center?: boolean;
58
- title?: string;
59
- };
60
-
61
- export const CardTitle: FC<CardTitleProps> = ({ center, title, classNames, ...props }) => {
62
- return (
63
- <div {...props} className={cardTitle({ center }, classNames)}>
64
- {title}
65
- </div>
66
- );
67
- };
68
-
69
- // TODO(burdon): Reuse ListItemEndcap?
70
- type CardDragHandleProps = ThemedClassName<ComponentPropsWithoutRef<'div'>> & { position?: 'left' | 'right' };
71
-
72
- const CardDragHandle: FC<CardDragHandleProps> = ({ position, classNames, ...props }) => {
73
- const density = useDensityContext();
74
- return (
75
- <div {...props} className={cardDragHandle({ density, position }, classNames)}>
76
- <DotsSixVertical className={cardDragHandleIcon({})} />
77
- </div>
78
- );
79
- };
80
-
81
- type CardEndcapProps = ThemedClassName<ComponentPropsWithoutRef<'div'>> & { Icon?: Icon; position?: 'left' | 'right' };
82
-
83
- const CardEndcap: FC<CardEndcapProps> = ({ Icon = Circle, position, classNames, ...props }) => {
84
- const density = useDensityContext();
85
- return (
86
- <div {...props} className={cardMenu({ density, position }, classNames)}>
87
- <Icon className={cardMenuIcon({})} />
88
- </div>
89
- );
90
- };
91
-
92
- type CardMenuProps = PropsWithChildren<
93
- ThemedClassName<ComponentPropsWithoutRef<'div'>> & { position?: 'left' | 'right' }
94
- >;
95
-
96
- // TODO(burdon): Reconcile with Endcap (remove dropdown from here). See ListItem.Endcap (style icon/size?)
97
- const CardMenu = forwardRef<HTMLDivElement, CardMenuProps>(
98
- ({ children, position, classNames, ...props }, forwardRef) => {
99
- const density = useDensityContext();
100
- return (
101
- <div {...props} className={cardMenu({ density, position }, classNames)} ref={forwardRef}>
102
- <DropdownMenu.Root>
103
- <DropdownMenu.Trigger asChild>
104
- <DotsThreeVertical className={cardMenuIcon({})} />
105
- </DropdownMenu.Trigger>
106
- {/* TODO(burdon): Position to the left of the menu button. */}
107
- <DropdownMenu.Content>
108
- <DropdownMenu.Viewport>{children}</DropdownMenu.Viewport>
109
- </DropdownMenu.Content>
110
- </DropdownMenu.Root>
111
- </div>
112
- );
113
- },
114
- );
115
-
116
- type CardBodyProps = ThemedClassName<ComponentPropsWithoutRef<'div'>> & { gutter?: boolean };
117
-
118
- export const CardBody: FC<CardBodyProps> = ({ gutter, classNames, children, ...props }) => {
119
- const density = useDensityContext();
120
- return (
121
- <div {...props} className={cardBody({ density, gutter }, classNames)}>
122
- {children}
123
- </div>
124
- );
125
- };
126
-
127
- type CardMediaProps = ThemedClassName<ComponentPropsWithoutRef<'div'>> & { src?: string; contain?: boolean };
128
-
129
- // TODO(burdon): Option to set to 50% of height of card.
130
- export const CardMedia: FC<CardMediaProps> = ({ src, contain, classNames, ...props }) => {
131
- return (
132
- <div className='flex grow overflow-hidden'>
133
- <img {...props} className={cardMedia({ contain }, classNames)} src={src} />
134
- </div>
135
- );
136
- };
137
-
138
- export const Card = {
139
- Root: CardRoot,
140
- Header: CardHeader,
141
- DragHandle: CardDragHandle,
142
- Endcap: CardEndcap,
143
- Menu: CardMenu,
144
- Title: CardTitle,
145
- Body: CardBody,
146
- Media: CardMedia,
147
- };
148
-
149
- export type { CardRootProps };
package/src/theme.ts DELETED
@@ -1,101 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import { type ComponentFunction, type Density, type Theme } from '@dxos/react-ui';
6
- import { getSize, attentionSurface, mx } from '@dxos/react-ui-theme';
7
-
8
- const defaults = {
9
- width: 'min-w-[256px]',
10
- };
11
-
12
- export type CardStyleProps = Partial<{
13
- density: Density;
14
- grow?: boolean;
15
- square?: boolean;
16
- rounded?: boolean;
17
- noPadding?: boolean;
18
- }>;
19
-
20
- export const cardRoot: ComponentFunction<CardStyleProps> = ({ grow, square, rounded = true }, ...etc) =>
21
- mx(
22
- 'flex flex-col group/card overflow-hidden',
23
- grow && 'h-full',
24
- defaults.width,
25
- attentionSurface,
26
- 'shadow', // TODO(burdon): Elevation?
27
- rounded && 'rounded',
28
- square && 'aspect-square',
29
- ...etc,
30
- );
31
-
32
- export const cardHeader: ComponentFunction<CardStyleProps & { floating?: boolean }> = ({ floating }, ...etc) =>
33
- mx(floating ? 'relative' : 'flex w-full shrink-0 justify-between overflow-hidden items-center py-1', ...etc);
34
-
35
- export const cardTitle: ComponentFunction<CardStyleProps & { center?: boolean }> = ({ center }, ...etc) =>
36
- mx('grow overflow-hidden truncate first:pl-4 last:pr-4', center && 'text-center', ...etc);
37
-
38
- export const cardDragHandle: ComponentFunction<CardStyleProps & { position?: 'left' | 'right' }> = (
39
- { density, position },
40
- ...etc
41
- ) =>
42
- mx(
43
- 'flex shrink-0 items-center justify-center select-none',
44
- density === 'fine' ? getSize(8) : getSize(10),
45
- position === 'left' && 'absolute top-1 left-1',
46
- position === 'right' && 'absolute top-1 right-1',
47
- position && 'text-black group-hover/card:bg-white group-hover/card:bg-opacity-80',
48
- ...etc,
49
- );
50
-
51
- export const cardDragHandleIcon: ComponentFunction<CardStyleProps> = (_, ...etc) =>
52
- mx(getSize(5), 'cursor-pointer', ...etc);
53
-
54
- // TODO(burdon): Helper for DropdownMenu? Density, etc?
55
- export const cardMenu: ComponentFunction<CardStyleProps & { position?: 'left' | 'right' }> = (
56
- { density, position },
57
- ...etc
58
- ) =>
59
- mx(
60
- 'flex shrink-0 items-center justify-center',
61
- density === 'fine' ? getSize(8) : getSize(10),
62
- position === 'left' && 'absolute top-1 left-1',
63
- position === 'right' && 'absolute top-1 right-1',
64
- position && 'text-black group-hover/card:bg-white group-hover/card:bg-opacity-80',
65
- ...etc,
66
- );
67
-
68
- export const cardMenuIcon: ComponentFunction<CardStyleProps> = (_, ...etc) => mx(getSize(5), 'cursor-pointer');
69
-
70
- export const cardBody: ComponentFunction<CardStyleProps & { gutter?: boolean }> = (
71
- { density, gutter, noPadding },
72
- ...etc
73
- ) =>
74
- mx(
75
- 'grow overflow-auto',
76
- !noPadding && 'px-2',
77
- // TODO(burdon): Create density-specific constants.
78
- gutter && (density === 'fine' ? 'pl-0 ml-[32px]' : 'pl-0 ml-[40px]'),
79
- ...etc,
80
- );
81
-
82
- export const cardMedia: ComponentFunction<CardStyleProps & { contain?: boolean }> = ({ contain }, ...etc) =>
83
- mx(
84
- 'grow max-h-[300px]',
85
- // Hide broken image links (e.g., if offline).
86
- "before:content-[' '] before:block before:w-full before:h-full before:border-0",
87
- contain ? 'object-contain' : 'object-cover',
88
- ...etc,
89
- );
90
-
91
- export const cardTheme: Theme<CardStyleProps> = {
92
- root: cardRoot,
93
- header: cardHeader,
94
- title: cardTitle,
95
- dragHandle: cardDragHandle,
96
- dragHandleIcon: cardDragHandleIcon,
97
- menu: cardMenu,
98
- menuIcon: cardMenuIcon,
99
- body: cardBody,
100
- media: cardMedia,
101
- };