@dxos/react-ui 0.3.3-main.619fab4 → 0.3.3-main.6dfc6c0

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.
@@ -13,7 +13,6 @@ import React, { type FC, type PropsWithChildren, useState } from 'react';
13
13
  import { chromeSurface, mx } from '@dxos/react-ui-theme';
14
14
 
15
15
  import { Card } from './Card';
16
- import { testImages } from './testing';
17
16
  import { DensityProvider } from '../DensityProvider';
18
17
  import { DropdownMenu } from '../DropdownMenu';
19
18
  import { Input } from '../Input';
@@ -21,9 +20,16 @@ import { ScrollArea } from '../ScrollArea';
21
20
 
22
21
  faker.seed(1);
23
22
 
24
- // TODO(burdon): Menu.
25
- // TODO(burdon): Collapse.
26
- // TODO(burdon): Editable.
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
+ ];
27
33
 
28
34
  type CardData = {
29
35
  id: string;
@@ -92,7 +98,7 @@ const DraggableStory: FC<PropsWithChildren> = ({ children }) => {
92
98
  <DndContext onDragEnd={handleDragEnd}>
93
99
  <SortableContext items={cards.map(({ id }) => id)} strategy={verticalListSortingStrategy}>
94
100
  <div className='flex flex-col overflow-y-scroll'>
95
- <div className='flex flex-col m-4 gap-4'>
101
+ <div className='flex flex-col gap-4'>
96
102
  {cards.map((card) => (
97
103
  <DraggableCard key={card.id} data={card} onDelete={handleDelete} />
98
104
  ))}
@@ -105,8 +111,8 @@ const DraggableStory: FC<PropsWithChildren> = ({ children }) => {
105
111
 
106
112
  const ReadonlyCardStory = () => {
107
113
  return (
108
- <div className='flex flex-col overflow-y-scroll p-8'>
109
- <div className='flex flex-col gap-8'>
114
+ <div className='flex flex-col overflow-y-scroll'>
115
+ <div className='flex flex-col gap-4'>
110
116
  <Card.Root square noPadding>
111
117
  <Card.Header floating>
112
118
  <Card.DragHandle position='left' />
@@ -173,35 +179,34 @@ const ReadonlyCardStory = () => {
173
179
 
174
180
  const EditableCardStory = () => {
175
181
  return (
176
- <div className='flex flex-col overflow-y-scroll p-8'>
177
- <div className='flex flex-col gap-8'>
178
- <Card.Root>
179
- <Card.Header>
180
- <Card.DragHandle />
181
- <Input.Root>
182
- <Input.TextInput classNames={'-mx-2 px-2'} variant='subdued' placeholder={'Title'} />
183
- </Input.Root>
184
- <Card.Menu />
185
- </Card.Header>
186
- <Card.Body gutter classNames={'gap-2 text-sm font-thin'}>
187
- {faker.lorem.sentences()}
188
- </Card.Body>
189
- </Card.Root>
190
- </div>
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>
191
195
  </div>
192
196
  );
193
197
  };
194
198
 
195
199
  export default {
196
200
  component: Card,
197
- args: {},
198
201
  decorators: [
199
202
  (Story: any) => (
200
203
  <div className={mx('flex h-screen w-full justify-center overflow-hidden', chromeSurface)}>
201
- {/* TODO(burdon): Story for different densities. */}
202
- <DensityProvider density='fine'>
203
- <Story />
204
- </DensityProvider>
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>
205
210
  </div>
206
211
  ),
207
212
  ],
@@ -2,7 +2,7 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import { DotsSixVertical, DotsThreeVertical } from '@phosphor-icons/react';
5
+ import { DotsSixVertical, DotsThreeVertical, type Icon } from '@phosphor-icons/react';
6
6
  import { type Primitive } from '@radix-ui/react-primitive';
7
7
  import React, {
8
8
  type ComponentPropsWithoutRef,
@@ -72,10 +72,23 @@ const CardDragHandle: FC<CardDragHandleProps> = ({ position, classNames, ...prop
72
72
  );
73
73
  };
74
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
+
75
87
  type CardMenuProps = PropsWithChildren<
76
88
  ThemedClassName<ComponentPropsWithoutRef<'div'>> & { position?: 'left' | 'right' }
77
89
  >;
78
90
 
91
+ // TODO(burdon): Reconcile with Endcap (remove dropdown from here). See ListItem.Endcap (style icon/size?)
79
92
  const CardMenu = forwardRef<HTMLDivElement, CardMenuProps>(
80
93
  ({ children, position, classNames, ...props }, forwardRef) => {
81
94
  const { tx } = useThemeContext();
@@ -124,6 +137,7 @@ export const Card = {
124
137
  Root: CardRoot,
125
138
  Header: CardHeader,
126
139
  DragHandle: CardDragHandle,
140
+ Endcap: CardEndcap,
127
141
  Menu: CardMenu,
128
142
  Title: CardTitle,
129
143
  Body: CardBody,
@@ -131,8 +131,6 @@ type MainSidebarProps = ThemedClassName<ComponentPropsWithRef<typeof DialogConte
131
131
  side: 'inline-start' | 'inline-end';
132
132
  };
133
133
 
134
- // TODO(burdon): Factor out Sidebar?
135
- // TODO(burdon): Style left/right sidebar differently.
136
134
  const MainSidebar = forwardRef<HTMLDivElement, MainSidebarProps>(
137
135
  ({ classNames, children, swipeToDismiss, onOpenAutoFocus, open, setOpen, side, ...props }, forwardedRef) => {
138
136
  const [isLg] = useMediaQuery('lg', { ssr: false });
@@ -259,9 +257,9 @@ const MainOverlay = forwardRef<HTMLDivElement, MainOverlayProps>(({ classNames,
259
257
  });
260
258
 
261
259
  export const Main = {
260
+ Root: MainRoot,
262
261
  Content: MainContent,
263
262
  Overlay: MainOverlay,
264
- Root: MainRoot,
265
263
  NavigationSidebar: MainNavigationSidebar,
266
264
  ComplementarySidebar: MainComplementarySidebar,
267
265
  };
@@ -1,9 +0,0 @@
1
- type CardType = 'document' | 'message' | 'contact' | 'image' | 'event' | 'project' | 'task' | 'result' | 'table';
2
- export declare const testImages: string[];
3
- type Data = {
4
- id: string;
5
- type: string;
6
- };
7
- export declare const generators: Record<CardType, () => Data & Record<string, any>>;
8
- export {};
9
- //# sourceMappingURL=testing.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../../../../../src/components/Card/testing.ts"],"names":[],"mappings":"AAQA,KAAK,QAAQ,GAAG,UAAU,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC;AAIjH,eAAO,MAAM,UAAU,UAQtB,CAAC;AAEF,KAAK,IAAI,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEzC,eAAO,MAAM,UAAU,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAiEzE,CAAC"}
@@ -1,90 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import { faker } from '@faker-js/faker';
6
-
7
- // TODO(burdon): Standardize with mosaic.
8
-
9
- type CardType = 'document' | 'message' | 'contact' | 'image' | 'event' | 'project' | 'task' | 'result' | 'table';
10
-
11
- // https://unsplash.com
12
- // TODO(burdon): Use https://picsum.photos/
13
- export const testImages = [
14
- // 'https://images.unsplash.com/photo-1554629947-334ff61d85dc',
15
- 'https://images.unsplash.com/photo-1616394158624-a2ba9cfe2994',
16
- 'https://images.unsplash.com/photo-1507941097613-9f2157b69235',
17
- 'https://images.unsplash.com/photo-1431274172761-fca41d930114',
18
- 'https://images.unsplash.com/photo-1513635269975-59663e0ac1ad',
19
- 'https://images.unsplash.com/photo-1564221710304-0b37c8b9d729',
20
- 'https://images.unsplash.com/photo-1605425183435-25b7e99104a4',
21
- ];
22
-
23
- type Data = { id: string; type: string };
24
-
25
- export const generators: Record<CardType, () => Data & Record<string, any>> = {
26
- document: () => ({
27
- type: 'document',
28
- id: faker.string.uuid(),
29
- title: faker.lorem.sentence(),
30
- body: faker.lorem.sentences({ min: 1, max: faker.number.int({ min: 1, max: 3 }) }),
31
- }),
32
-
33
- // TODO(burdon): Timestamp.
34
- message: () => ({
35
- type: 'message',
36
- id: faker.string.uuid(),
37
- from: faker.internet.userName(),
38
- body: faker.lorem.sentence(),
39
- }),
40
-
41
- // TODO(burdon): Avatar.
42
- contact: () => ({
43
- type: 'contact',
44
- id: faker.string.uuid(),
45
- name: faker.person.fullName(),
46
- username: faker.internet.userName(),
47
- email: faker.internet.email(),
48
- }),
49
-
50
- image: () => ({
51
- type: 'image',
52
- id: faker.string.uuid(),
53
- image: faker.helpers.arrayElement(testImages),
54
- body: faker.datatype.boolean() ? faker.lorem.sentences() : undefined,
55
- }),
56
-
57
- event: () => ({
58
- type: 'event',
59
- id: faker.string.uuid(),
60
- name: faker.commerce.productName(),
61
- date: faker.date.recent(),
62
- }),
63
-
64
- project: () => ({
65
- type: 'project',
66
- id: faker.string.uuid(),
67
- name: faker.commerce.productName(),
68
- body: faker.lorem.sentences({ min: 1, max: faker.number.int({ min: 1, max: 3 }) }),
69
- tasks: Array.from({ length: faker.number.int(5) }).map(() => generators.task()),
70
- }),
71
-
72
- task: () => ({
73
- type: 'task',
74
- id: faker.string.uuid(),
75
- done: faker.datatype.boolean(),
76
- title: faker.lorem.sentence(),
77
- }),
78
-
79
- // TODO(burdon): Search result.
80
- result: () => ({
81
- type: 'result',
82
- id: faker.string.uuid(),
83
- }),
84
-
85
- // TODO(burdon): Generic data.
86
- table: () => ({
87
- type: 'table',
88
- id: faker.string.uuid(),
89
- }),
90
- };