@dxos/react-ui-calendar 0.8.4-main.548089c → 0.8.4-main.e8ec1fe
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 +25 -11
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +25 -11
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/Calendar/Calendar.d.ts +4 -4
- package/dist/types/src/components/Calendar/Calendar.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +12 -12
- package/src/components/Calendar/Calendar.stories.tsx +4 -4
- package/src/components/Calendar/Calendar.tsx +40 -16
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-ui-calendar",
|
|
3
|
-
"version": "0.8.4-main.
|
|
3
|
+
"version": "0.8.4-main.e8ec1fe",
|
|
4
4
|
"description": "A calendar component.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -31,11 +31,11 @@
|
|
|
31
31
|
"react-resize-detector": "^11.0.1",
|
|
32
32
|
"react-virtualized": "^9.22.6",
|
|
33
33
|
"react-window": "^2.2.3",
|
|
34
|
-
"@dxos/async": "0.8.4-main.
|
|
35
|
-
"@dxos/debug": "0.8.4-main.
|
|
36
|
-
"@dxos/
|
|
37
|
-
"@dxos/
|
|
38
|
-
"@dxos/
|
|
34
|
+
"@dxos/async": "0.8.4-main.e8ec1fe",
|
|
35
|
+
"@dxos/debug": "0.8.4-main.e8ec1fe",
|
|
36
|
+
"@dxos/invariant": "0.8.4-main.e8ec1fe",
|
|
37
|
+
"@dxos/util": "0.8.4-main.e8ec1fe",
|
|
38
|
+
"@dxos/log": "0.8.4-main.e8ec1fe"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/react": "~19.2.2",
|
|
@@ -46,17 +46,17 @@
|
|
|
46
46
|
"react": "~19.2.0",
|
|
47
47
|
"react-dom": "~19.2.0",
|
|
48
48
|
"vite": "7.1.9",
|
|
49
|
-
"@dxos/random": "0.8.4-main.
|
|
50
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
51
|
-
"@dxos/react-ui-theme": "0.8.4-main.
|
|
52
|
-
"@dxos/storybook-utils": "0.8.4-main.
|
|
49
|
+
"@dxos/random": "0.8.4-main.e8ec1fe",
|
|
50
|
+
"@dxos/react-ui": "0.8.4-main.e8ec1fe",
|
|
51
|
+
"@dxos/react-ui-theme": "0.8.4-main.e8ec1fe",
|
|
52
|
+
"@dxos/storybook-utils": "0.8.4-main.e8ec1fe"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"effect": "3.13.3",
|
|
56
56
|
"react": "^19.0.0",
|
|
57
57
|
"react-dom": "^19.0.0",
|
|
58
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
59
|
-
"@dxos/react-ui-theme": "0.8.4-main.
|
|
58
|
+
"@dxos/react-ui": "0.8.4-main.e8ec1fe",
|
|
59
|
+
"@dxos/react-ui-theme": "0.8.4-main.e8ec1fe"
|
|
60
60
|
},
|
|
61
61
|
"publishConfig": {
|
|
62
62
|
"access": "public"
|
|
@@ -29,7 +29,7 @@ export const Default: Story = {
|
|
|
29
29
|
render: () => (
|
|
30
30
|
<Calendar.Root>
|
|
31
31
|
<Calendar.Viewport>
|
|
32
|
-
<Calendar.
|
|
32
|
+
<Calendar.Toolbar />
|
|
33
33
|
<Calendar.Grid rows={6} />
|
|
34
34
|
</Calendar.Viewport>
|
|
35
35
|
</Calendar.Root>
|
|
@@ -40,7 +40,7 @@ export const Border: Story = {
|
|
|
40
40
|
render: () => (
|
|
41
41
|
<Calendar.Root>
|
|
42
42
|
<Calendar.Viewport classNames='bg-modalSurface border border-separator rounded'>
|
|
43
|
-
<Calendar.
|
|
43
|
+
<Calendar.Toolbar />
|
|
44
44
|
<Calendar.Grid rows={6} />
|
|
45
45
|
</Calendar.Viewport>
|
|
46
46
|
</Calendar.Root>
|
|
@@ -52,7 +52,7 @@ export const Column: Story = {
|
|
|
52
52
|
<div className='absolute inset-0 flex bs-full justify-center'>
|
|
53
53
|
<Calendar.Root>
|
|
54
54
|
<Calendar.Viewport>
|
|
55
|
-
<Calendar.
|
|
55
|
+
<Calendar.Toolbar />
|
|
56
56
|
<Calendar.Grid />
|
|
57
57
|
</Calendar.Viewport>
|
|
58
58
|
</Calendar.Root>
|
|
@@ -66,7 +66,7 @@ export const Mobile: Story = {
|
|
|
66
66
|
<div className='flex bs-full is-[400px] justify-center'>
|
|
67
67
|
<Calendar.Root>
|
|
68
68
|
<Calendar.Viewport classNames='is-full'>
|
|
69
|
-
<Calendar.
|
|
69
|
+
<Calendar.Toolbar />
|
|
70
70
|
<Calendar.Grid />
|
|
71
71
|
</Calendar.Viewport>
|
|
72
72
|
</Calendar.Root>
|
|
@@ -20,7 +20,7 @@ import { useResizeDetector } from 'react-resize-detector';
|
|
|
20
20
|
import { List, type ListProps, type ListRowRenderer } from 'react-virtualized';
|
|
21
21
|
|
|
22
22
|
import { Event } from '@dxos/async';
|
|
23
|
-
import { IconButton, type ThemedClassName, useTranslation } from '@dxos/react-ui';
|
|
23
|
+
import { Icon, IconButton, type ThemedClassName, useTranslation } from '@dxos/react-ui';
|
|
24
24
|
import { mx } from '@dxos/react-ui-theme';
|
|
25
25
|
|
|
26
26
|
import { translationKey } from '../../translations';
|
|
@@ -117,11 +117,11 @@ CalendarViewport.displayName = 'CalendarContent';
|
|
|
117
117
|
// Header
|
|
118
118
|
//
|
|
119
119
|
|
|
120
|
-
type
|
|
120
|
+
type CalendarToolbarProps = ThemedClassName;
|
|
121
121
|
|
|
122
|
-
const
|
|
122
|
+
const CalendarToolbar = ({ classNames }: CalendarToolbarProps) => {
|
|
123
123
|
const { t } = useTranslation(translationKey);
|
|
124
|
-
const { weekStartsOn, event, index, selected } = useCalendarContext(
|
|
124
|
+
const { weekStartsOn, event, index, selected } = useCalendarContext(CalendarToolbar.displayName);
|
|
125
125
|
const top = useMemo(() => getDate(start, index ?? 0, 6, weekStartsOn), [index, weekStartsOn]);
|
|
126
126
|
const today = useMemo(() => new Date(), []);
|
|
127
127
|
|
|
@@ -130,11 +130,15 @@ const CalendarHeader = ({ classNames }: CalendarHeaderProps) => {
|
|
|
130
130
|
}, [event, start, today]);
|
|
131
131
|
|
|
132
132
|
return (
|
|
133
|
-
<div
|
|
133
|
+
<div
|
|
134
|
+
role='none'
|
|
135
|
+
className={mx('shink-0 is-full grid grid-cols-3 items-center bg-barSurface', classNames)}
|
|
136
|
+
style={{ width: defaultWidth }}
|
|
137
|
+
>
|
|
134
138
|
<div className='flex justify-start'>
|
|
135
139
|
<IconButton
|
|
136
140
|
variant='ghost'
|
|
137
|
-
size={
|
|
141
|
+
size={5}
|
|
138
142
|
icon='ph--calendar--regular'
|
|
139
143
|
iconOnly
|
|
140
144
|
classNames='aspect-square'
|
|
@@ -142,13 +146,13 @@ const CalendarHeader = ({ classNames }: CalendarHeaderProps) => {
|
|
|
142
146
|
onClick={handleToday}
|
|
143
147
|
/>
|
|
144
148
|
</div>
|
|
145
|
-
<
|
|
146
|
-
<
|
|
149
|
+
<div className='flex justify-center p-2 text-description'>{format(selected ?? top, 'MMMM')}</div>
|
|
150
|
+
<div className='flex justify-end p-2 text-description'>{(selected ?? top).getFullYear()}</div>
|
|
147
151
|
</div>
|
|
148
152
|
);
|
|
149
153
|
};
|
|
150
154
|
|
|
151
|
-
|
|
155
|
+
CalendarToolbar.displayName = 'CalendarHeader';
|
|
152
156
|
|
|
153
157
|
//
|
|
154
158
|
// Grid
|
|
@@ -194,6 +198,13 @@ const CalendarGrid = ({ classNames, rows, onSelect }: CalendarGridProps) => {
|
|
|
194
198
|
});
|
|
195
199
|
}, []);
|
|
196
200
|
|
|
201
|
+
// TODO(burdon): Get info by range.
|
|
202
|
+
// TODO(burdon): Border marker for "all day events?"
|
|
203
|
+
const getNumAppointments = useCallback((_date: Date) => {
|
|
204
|
+
// return Math.floor(Math.random() * 10);
|
|
205
|
+
return 0;
|
|
206
|
+
}, []);
|
|
207
|
+
|
|
197
208
|
const handleDaySelect = useCallback(
|
|
198
209
|
(date: Date) => {
|
|
199
210
|
setSelected((current) => (isSameDay(date, current) ? undefined : date));
|
|
@@ -210,11 +221,12 @@ const CalendarGrid = ({ classNames, rows, onSelect }: CalendarGridProps) => {
|
|
|
210
221
|
({ key, index, style }) => {
|
|
211
222
|
const getBgColor = (date: Date) => date.getMonth() % 2 === 0 && 'bg-modalSurface';
|
|
212
223
|
return (
|
|
213
|
-
<div key={key} style={style} className='is-full grid grid-cols-[1fr_max-content_1fr] snap-center'>
|
|
214
|
-
<div className={mx(getBgColor(getDate(start, index, 0, weekStartsOn)))} />
|
|
215
|
-
<div className='grid grid-cols-7' style={{ gridTemplateColumns: `repeat(7, ${size}px)` }}>
|
|
224
|
+
<div key={key} role='none' style={style} className='is-full grid grid-cols-[1fr_max-content_1fr] snap-center'>
|
|
225
|
+
<div role='none' className={mx(getBgColor(getDate(start, index, 0, weekStartsOn)))} />
|
|
226
|
+
<div role='none' className='grid grid-cols-7' style={{ gridTemplateColumns: `repeat(7, ${size}px)` }}>
|
|
216
227
|
{Array.from({ length: 7 }).map((_, i) => {
|
|
217
228
|
const date = getDate(start, index, i, weekStartsOn);
|
|
229
|
+
const num = getNumAppointments(date);
|
|
218
230
|
const border = isSameDay(date, selected)
|
|
219
231
|
? 'border-primary-500'
|
|
220
232
|
: isSameDay(date, today)
|
|
@@ -224,6 +236,7 @@ const CalendarGrid = ({ classNames, rows, onSelect }: CalendarGridProps) => {
|
|
|
224
236
|
return (
|
|
225
237
|
<div
|
|
226
238
|
key={i}
|
|
239
|
+
role='none'
|
|
227
240
|
className={mx('relative flex justify-center items-center cursor-pointer', getBgColor(date))}
|
|
228
241
|
onClick={() => handleDaySelect(date)}
|
|
229
242
|
>
|
|
@@ -232,7 +245,17 @@ const CalendarGrid = ({ classNames, rows, onSelect }: CalendarGridProps) => {
|
|
|
232
245
|
<span className='absolute top-0 text-xs text-description'>{format(date, 'MMM')}</span>
|
|
233
246
|
)}
|
|
234
247
|
{border && (
|
|
235
|
-
<div
|
|
248
|
+
<div
|
|
249
|
+
role='none'
|
|
250
|
+
className={mx('absolute top-0 left-0 is-full bs-full border-2 rounded-full', border)}
|
|
251
|
+
/>
|
|
252
|
+
)}
|
|
253
|
+
{num > 0 && (
|
|
254
|
+
<Icon
|
|
255
|
+
classNames='absolute bottom-0'
|
|
256
|
+
icon={num > 3 ? 'ph--dots-three--regular' : 'ph--dot--regular'}
|
|
257
|
+
size={5}
|
|
258
|
+
/>
|
|
236
259
|
)}
|
|
237
260
|
</div>
|
|
238
261
|
);
|
|
@@ -242,7 +265,7 @@ const CalendarGrid = ({ classNames, rows, onSelect }: CalendarGridProps) => {
|
|
|
242
265
|
</div>
|
|
243
266
|
);
|
|
244
267
|
},
|
|
245
|
-
[handleDaySelect, selected, weekStartsOn],
|
|
268
|
+
[handleDaySelect, getNumAppointments, selected, weekStartsOn],
|
|
246
269
|
);
|
|
247
270
|
|
|
248
271
|
return (
|
|
@@ -257,6 +280,7 @@ const CalendarGrid = ({ classNames, rows, onSelect }: CalendarGridProps) => {
|
|
|
257
280
|
))}
|
|
258
281
|
</div>
|
|
259
282
|
</div>
|
|
283
|
+
|
|
260
284
|
{/* Grid */}
|
|
261
285
|
<div role='none' className='flex flex-col bs-full is-full justify-center overflow-hidden' ref={containerRef}>
|
|
262
286
|
<List
|
|
@@ -287,8 +311,8 @@ CalendarGrid.displayName = 'CalendarGrid';
|
|
|
287
311
|
export const Calendar = {
|
|
288
312
|
Root: CalendarRoot,
|
|
289
313
|
Viewport: CalendarViewport,
|
|
290
|
-
|
|
314
|
+
Toolbar: CalendarToolbar,
|
|
291
315
|
Grid: CalendarGrid,
|
|
292
316
|
};
|
|
293
317
|
|
|
294
|
-
export type { CalendarController, CalendarRootProps, CalendarViewportProps,
|
|
318
|
+
export type { CalendarController, CalendarRootProps, CalendarViewportProps, CalendarToolbarProps, CalendarGridProps };
|