panelui-native 1.2.0 → 1.4.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.
- package/lib/module/components/area-chart/index.js +4 -1
- package/lib/module/components/area-chart/index.js.map +1 -1
- package/lib/module/components/bar-chart/index.js +4 -1
- package/lib/module/components/bar-chart/index.js.map +1 -1
- package/lib/module/components/bubble-chart/index.js +4 -1
- package/lib/module/components/bubble-chart/index.js.map +1 -1
- package/lib/module/components/bump-chart/index.js +4 -1
- package/lib/module/components/bump-chart/index.js.map +1 -1
- package/lib/module/components/calendar/index.js +15 -2
- package/lib/module/components/calendar/index.js.map +1 -1
- package/lib/module/components/candlestick-chart/index.js +4 -1
- package/lib/module/components/candlestick-chart/index.js.map +1 -1
- package/lib/module/components/checkbox/index.js +2 -1
- package/lib/module/components/checkbox/index.js.map +1 -1
- package/lib/module/components/combobox/index.js +28 -7
- package/lib/module/components/combobox/index.js.map +1 -1
- package/lib/module/components/heatmap-chart/index.js +4 -1
- package/lib/module/components/heatmap-chart/index.js.map +1 -1
- package/lib/module/components/line-chart/index.js +4 -1
- package/lib/module/components/line-chart/index.js.map +1 -1
- package/lib/module/components/live-line-chart/index.js +4 -1
- package/lib/module/components/live-line-chart/index.js.map +1 -1
- package/lib/module/components/mirror-area-chart/index.js +4 -1
- package/lib/module/components/mirror-area-chart/index.js.map +1 -1
- package/lib/module/components/plot/index.js +4 -1
- package/lib/module/components/plot/index.js.map +1 -1
- package/lib/module/components/pyramid-chart/index.js +4 -1
- package/lib/module/components/pyramid-chart/index.js.map +1 -1
- package/lib/module/components/questionnaire/index.js +1 -0
- package/lib/module/components/questionnaire/index.js.map +1 -1
- package/lib/module/components/radio-group/index.js +2 -1
- package/lib/module/components/radio-group/index.js.map +1 -1
- package/lib/module/components/scatter-chart/index.js +4 -1
- package/lib/module/components/scatter-chart/index.js.map +1 -1
- package/lib/module/components/scroll-blur/index.js +25 -7
- package/lib/module/components/scroll-blur/index.js.map +1 -1
- package/lib/module/components/scroll-header/index.js +44 -24
- package/lib/module/components/scroll-header/index.js.map +1 -1
- package/lib/module/components/search-bar/index.js +2 -1
- package/lib/module/components/search-bar/index.js.map +1 -1
- package/lib/module/components/section-progress/index.js +1 -1
- package/lib/module/components/section-progress/index.js.map +1 -1
- package/lib/module/components/section-rail/index.js +1 -1
- package/lib/module/components/section-rail/index.js.map +1 -1
- package/lib/module/components/select/index.js +28 -7
- package/lib/module/components/select/index.js.map +1 -1
- package/lib/module/components/switch/index.js +51 -15
- package/lib/module/components/switch/index.js.map +1 -1
- package/lib/module/components/table/index.js +17 -3
- package/lib/module/components/table/index.js.map +1 -1
- package/lib/module/components/toast/index.js +13 -3
- package/lib/module/components/toast/index.js.map +1 -1
- package/lib/module/components/waterfall-chart/index.js +4 -1
- package/lib/module/components/waterfall-chart/index.js.map +1 -1
- package/lib/module/components/week-hours-grid/index.js +187 -0
- package/lib/module/components/week-hours-grid/index.js.map +1 -0
- package/lib/module/components/week-strip/index.js +232 -0
- package/lib/module/components/week-strip/index.js.map +1 -0
- package/lib/module/index.js +3 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/primitives/scrim.js +50 -2
- package/lib/module/primitives/scrim.js.map +1 -1
- package/lib/module/theme/use-theme.js +55 -4
- package/lib/module/theme/use-theme.js.map +1 -1
- package/lib/typescript/src/components/area-chart/index.d.ts.map +1 -1
- package/lib/typescript/src/components/bar-chart/index.d.ts.map +1 -1
- package/lib/typescript/src/components/bubble-chart/index.d.ts.map +1 -1
- package/lib/typescript/src/components/bump-chart/index.d.ts.map +1 -1
- package/lib/typescript/src/components/calendar/index.d.ts.map +1 -1
- package/lib/typescript/src/components/candlestick-chart/index.d.ts.map +1 -1
- package/lib/typescript/src/components/combobox/index.d.ts +2 -1
- package/lib/typescript/src/components/combobox/index.d.ts.map +1 -1
- package/lib/typescript/src/components/heatmap-chart/index.d.ts.map +1 -1
- package/lib/typescript/src/components/line-chart/index.d.ts.map +1 -1
- package/lib/typescript/src/components/live-line-chart/index.d.ts.map +1 -1
- package/lib/typescript/src/components/mirror-area-chart/index.d.ts.map +1 -1
- package/lib/typescript/src/components/plot/index.d.ts.map +1 -1
- package/lib/typescript/src/components/pyramid-chart/index.d.ts.map +1 -1
- package/lib/typescript/src/components/questionnaire/index.d.ts.map +1 -1
- package/lib/typescript/src/components/radio-group/index.d.ts.map +1 -1
- package/lib/typescript/src/components/scatter-chart/index.d.ts.map +1 -1
- package/lib/typescript/src/components/scroll-blur/index.d.ts.map +1 -1
- package/lib/typescript/src/components/scroll-header/index.d.ts +4 -2
- package/lib/typescript/src/components/scroll-header/index.d.ts.map +1 -1
- package/lib/typescript/src/components/search-bar/index.d.ts +3 -0
- package/lib/typescript/src/components/search-bar/index.d.ts.map +1 -1
- package/lib/typescript/src/components/select/index.d.ts +2 -1
- package/lib/typescript/src/components/select/index.d.ts.map +1 -1
- package/lib/typescript/src/components/switch/index.d.ts +7 -0
- package/lib/typescript/src/components/switch/index.d.ts.map +1 -1
- package/lib/typescript/src/components/table/index.d.ts.map +1 -1
- package/lib/typescript/src/components/toast/index.d.ts +7 -2
- package/lib/typescript/src/components/toast/index.d.ts.map +1 -1
- package/lib/typescript/src/components/waterfall-chart/index.d.ts.map +1 -1
- package/lib/typescript/src/components/week-hours-grid/index.d.ts +56 -0
- package/lib/typescript/src/components/week-hours-grid/index.d.ts.map +1 -0
- package/lib/typescript/src/components/week-strip/index.d.ts +173 -0
- package/lib/typescript/src/components/week-strip/index.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +3 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/primitives/scrim.d.ts +56 -2
- package/lib/typescript/src/primitives/scrim.d.ts.map +1 -1
- package/lib/typescript/src/theme/use-theme.d.ts +32 -1
- package/lib/typescript/src/theme/use-theme.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/area-chart/index.tsx +3 -1
- package/src/components/bar-chart/index.tsx +3 -1
- package/src/components/bubble-chart/index.tsx +3 -1
- package/src/components/bump-chart/index.tsx +3 -1
- package/src/components/calendar/index.tsx +15 -3
- package/src/components/candlestick-chart/index.tsx +3 -1
- package/src/components/checkbox/index.tsx +1 -1
- package/src/components/combobox/index.tsx +27 -8
- package/src/components/heatmap-chart/index.tsx +3 -1
- package/src/components/line-chart/index.tsx +3 -1
- package/src/components/live-line-chart/index.tsx +3 -1
- package/src/components/mirror-area-chart/index.tsx +3 -1
- package/src/components/plot/index.tsx +3 -1
- package/src/components/pyramid-chart/index.tsx +3 -1
- package/src/components/questionnaire/index.tsx +1 -0
- package/src/components/radio-group/index.tsx +5 -1
- package/src/components/scatter-chart/index.tsx +3 -1
- package/src/components/scroll-blur/index.tsx +32 -4
- package/src/components/scroll-header/index.tsx +63 -25
- package/src/components/search-bar/index.tsx +1 -1
- package/src/components/section-progress/index.tsx +1 -1
- package/src/components/section-rail/index.tsx +1 -1
- package/src/components/select/index.tsx +27 -8
- package/src/components/switch/index.tsx +54 -5
- package/src/components/table/index.tsx +17 -3
- package/src/components/toast/index.tsx +24 -4
- package/src/components/waterfall-chart/index.tsx +3 -1
- package/src/components/week-hours-grid/index.tsx +238 -0
- package/src/components/week-strip/index.tsx +272 -0
- package/src/index.ts +16 -0
- package/src/primitives/scrim.tsx +56 -4
- package/src/theme/use-theme.ts +57 -4
- package/theme.css +5 -5
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WeekHoursGrid — a week of hours, one row per day.
|
|
3
|
+
*
|
|
4
|
+
* Each row is a bar across the visible hours, with the taken parts of the day
|
|
5
|
+
* filled in: the hours a trainer works, the sessions already booked in a room,
|
|
6
|
+
* a person's shift. Reading down the rows compares the days; reading along one
|
|
7
|
+
* shows where its gaps are.
|
|
8
|
+
*
|
|
9
|
+
* ```tsx
|
|
10
|
+
* <WeekHoursGrid
|
|
11
|
+
* from={6}
|
|
12
|
+
* to={22}
|
|
13
|
+
* ticks={[6, 10, 14, 18, 22]}
|
|
14
|
+
* rows={[{ key: 'mon', label: 'Mon', blocks: [{ start: 9, end: 12 }] }]}
|
|
15
|
+
* />
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* ## Hours, not times
|
|
19
|
+
*
|
|
20
|
+
* Positions are hours as numbers, so 9.5 is half past nine and the grid needs
|
|
21
|
+
* no date library. `from` and `to` set the visible range; a block reaching
|
|
22
|
+
* outside it is cut at the edge, and one wholly outside it is not drawn.
|
|
23
|
+
* Blocks are placed in percent, so the grid works at any width.
|
|
24
|
+
*
|
|
25
|
+
* ## Rows need not be days
|
|
26
|
+
*
|
|
27
|
+
* A row is a key, a label and its blocks, so the same grid holds a shift plan
|
|
28
|
+
* with one row per person. A row marked `off` is drawn faded with no blocks,
|
|
29
|
+
* and a `selected` row is outlined.
|
|
30
|
+
*
|
|
31
|
+
* ## Pressing a row
|
|
32
|
+
*
|
|
33
|
+
* With `onSelect` each row is a button, and a screen reader hears its label
|
|
34
|
+
* and every block read out as a range of times.
|
|
35
|
+
*/
|
|
36
|
+
import { forwardRef } from 'react';
|
|
37
|
+
import { Pressable, View, type ViewProps } from 'react-native';
|
|
38
|
+
import { tv } from 'tailwind-variants';
|
|
39
|
+
import { Text } from '../../primitives/text';
|
|
40
|
+
import { cn } from '../../utils/cn';
|
|
41
|
+
import type { ViewRef } from '../../primitives/refs';
|
|
42
|
+
|
|
43
|
+
/** The colour of a block, from the theme's roles. */
|
|
44
|
+
export type WeekHoursTone = 'primary' | 'muted' | 'success' | 'warning' | 'destructive' | 'info';
|
|
45
|
+
|
|
46
|
+
/** One filled stretch of a row. */
|
|
47
|
+
export interface WeekHoursBlock {
|
|
48
|
+
/** Where it starts, in hours: 9.5 is half past nine. */
|
|
49
|
+
start: number;
|
|
50
|
+
/** Where it ends, in hours. */
|
|
51
|
+
end: number;
|
|
52
|
+
/** Its colour. Default `primary`. Use `muted` for time taken by someone else. */
|
|
53
|
+
tone?: WeekHoursTone;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** One row of the grid: a day, a room or a person. */
|
|
57
|
+
export interface WeekHoursRow {
|
|
58
|
+
/** Identifies the row; it is what `onSelect` is called with. */
|
|
59
|
+
key: string;
|
|
60
|
+
/** The text at the start of the row, such as "Mon". */
|
|
61
|
+
label: string;
|
|
62
|
+
/** The filled stretches. */
|
|
63
|
+
blocks: WeekHoursBlock[];
|
|
64
|
+
/** Draws the row faded with no blocks, for a day that is not worked. */
|
|
65
|
+
off?: boolean;
|
|
66
|
+
/** Outlines the row, for the one being edited. */
|
|
67
|
+
selected?: boolean;
|
|
68
|
+
/** What a screen reader says for the row's label, when it differs from the text. */
|
|
69
|
+
accessibilityLabel?: string;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** One entry under the grid, explaining a tone. */
|
|
73
|
+
export interface WeekHoursLegendItem {
|
|
74
|
+
label: string;
|
|
75
|
+
/** The tone it explains. Default `primary`. */
|
|
76
|
+
tone?: WeekHoursTone;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const TONE: Record<WeekHoursTone, string> = {
|
|
80
|
+
primary: 'bg-primary',
|
|
81
|
+
muted: 'bg-muted-foreground/40',
|
|
82
|
+
success: 'bg-success',
|
|
83
|
+
warning: 'bg-warning',
|
|
84
|
+
destructive: 'bg-destructive',
|
|
85
|
+
info: 'bg-info',
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const weekHoursGridVariants = tv({
|
|
89
|
+
slots: {
|
|
90
|
+
root: 'w-full gap-2 self-stretch',
|
|
91
|
+
row: 'flex-row items-center gap-3 rounded-lg',
|
|
92
|
+
label: 'w-14 text-sm font-medium text-foreground',
|
|
93
|
+
bar: 'relative h-6 flex-1 overflow-hidden rounded-md border border-transparent bg-muted',
|
|
94
|
+
block: 'absolute inset-y-0 rounded-sm',
|
|
95
|
+
ticks: 'flex-row items-center gap-3',
|
|
96
|
+
tickSpacer: 'w-14',
|
|
97
|
+
tickRow: 'flex-1 flex-row justify-between',
|
|
98
|
+
tick: 'text-xs text-muted-foreground',
|
|
99
|
+
legend: 'flex-row flex-wrap items-center gap-x-4 gap-y-1 pt-1',
|
|
100
|
+
legendItem: 'flex-row items-center gap-1.5',
|
|
101
|
+
swatch: 'size-2.5 rounded-sm',
|
|
102
|
+
legendLabel: 'text-xs text-muted-foreground',
|
|
103
|
+
},
|
|
104
|
+
variants: {
|
|
105
|
+
off: {
|
|
106
|
+
true: { label: 'text-muted-foreground', bar: 'opacity-50' },
|
|
107
|
+
},
|
|
108
|
+
selected: {
|
|
109
|
+
true: { bar: 'border-primary' },
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
export interface WeekHoursGridProps extends Omit<ViewProps, 'children'> {
|
|
115
|
+
className?: string;
|
|
116
|
+
/** The rows, top to bottom. */
|
|
117
|
+
rows: WeekHoursRow[];
|
|
118
|
+
/** The first visible hour. Default 0. */
|
|
119
|
+
from?: number;
|
|
120
|
+
/** The last visible hour. Default 24. */
|
|
121
|
+
to?: number;
|
|
122
|
+
/**
|
|
123
|
+
* The labels under the bars, spread evenly from `from` to `to`. Numbers are
|
|
124
|
+
* written as two-digit hours; strings are shown as given.
|
|
125
|
+
*/
|
|
126
|
+
ticks?: (number | string)[];
|
|
127
|
+
/** The entries under the grid, explaining each tone. */
|
|
128
|
+
legend?: WeekHoursLegendItem[];
|
|
129
|
+
/** Makes each row a button, called with the row's `key`. */
|
|
130
|
+
onSelect?: (key: string) => void;
|
|
131
|
+
/** What a screen reader says for a row marked `off`. Default "off". */
|
|
132
|
+
offLabel?: string;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** 9.5 as "09:30". */
|
|
136
|
+
function clock(hours: number): string {
|
|
137
|
+
const whole = Math.floor(hours);
|
|
138
|
+
const minutes = Math.round((hours - whole) * 60);
|
|
139
|
+
const h = minutes === 60 ? whole + 1 : whole;
|
|
140
|
+
const m = minutes === 60 ? 0 : minutes;
|
|
141
|
+
return `${String(h).padStart(2, '0')}:${String(m).padStart(2, '0')}`;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export const WeekHoursGrid = forwardRef<ViewRef, WeekHoursGridProps>(
|
|
145
|
+
(
|
|
146
|
+
{ className, rows, from = 0, to = 24, ticks, legend, onSelect, offLabel = 'off', ...props },
|
|
147
|
+
ref
|
|
148
|
+
) => {
|
|
149
|
+
const span = Math.max(to - from, 1e-6);
|
|
150
|
+
const slots = weekHoursGridVariants();
|
|
151
|
+
|
|
152
|
+
return (
|
|
153
|
+
<View ref={ref} className={slots.root({ className })} {...props}>
|
|
154
|
+
{rows.map((row) => {
|
|
155
|
+
const styles = weekHoursGridVariants({ off: !!row.off, selected: !!row.selected });
|
|
156
|
+
const shown = row.off
|
|
157
|
+
? []
|
|
158
|
+
: row.blocks
|
|
159
|
+
.map((block) => ({
|
|
160
|
+
...block,
|
|
161
|
+
start: Math.max(block.start, from),
|
|
162
|
+
end: Math.min(block.end, to),
|
|
163
|
+
}))
|
|
164
|
+
.filter((block) => block.end > block.start);
|
|
165
|
+
const spoken = [
|
|
166
|
+
row.accessibilityLabel ?? row.label,
|
|
167
|
+
...(row.off
|
|
168
|
+
? [offLabel]
|
|
169
|
+
: shown.map((block) => `${clock(block.start)} to ${clock(block.end)}`)),
|
|
170
|
+
].join(', ');
|
|
171
|
+
|
|
172
|
+
const content = (
|
|
173
|
+
<>
|
|
174
|
+
<Text className={styles.label()} numberOfLines={1}>
|
|
175
|
+
{row.label}
|
|
176
|
+
</Text>
|
|
177
|
+
<View className={styles.bar()}>
|
|
178
|
+
{shown.map((block, index) => (
|
|
179
|
+
<View
|
|
180
|
+
key={index}
|
|
181
|
+
className={cn(styles.block(), TONE[block.tone ?? 'primary'])}
|
|
182
|
+
style={{
|
|
183
|
+
left: `${((block.start - from) / span) * 100}%`,
|
|
184
|
+
width: `${((block.end - block.start) / span) * 100}%`,
|
|
185
|
+
}}
|
|
186
|
+
/>
|
|
187
|
+
))}
|
|
188
|
+
</View>
|
|
189
|
+
</>
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
return onSelect ? (
|
|
193
|
+
<Pressable
|
|
194
|
+
key={row.key}
|
|
195
|
+
accessibilityRole="button"
|
|
196
|
+
accessibilityLabel={spoken}
|
|
197
|
+
accessibilityState={{ selected: !!row.selected }}
|
|
198
|
+
onPress={() => onSelect(row.key)}
|
|
199
|
+
className={styles.row()}
|
|
200
|
+
>
|
|
201
|
+
{content}
|
|
202
|
+
</Pressable>
|
|
203
|
+
) : (
|
|
204
|
+
<View key={row.key} accessible accessibilityLabel={spoken} className={styles.row()}>
|
|
205
|
+
{content}
|
|
206
|
+
</View>
|
|
207
|
+
);
|
|
208
|
+
})}
|
|
209
|
+
|
|
210
|
+
{ticks && ticks.length > 0 ? (
|
|
211
|
+
<View className={slots.ticks()} importantForAccessibility="no-hide-descendants" accessibilityElementsHidden>
|
|
212
|
+
<View className={slots.tickSpacer()} />
|
|
213
|
+
<View className={slots.tickRow()}>
|
|
214
|
+
{ticks.map((tick, index) => (
|
|
215
|
+
<Text key={index} className={slots.tick()}>
|
|
216
|
+
{typeof tick === 'number' ? String(tick).padStart(2, '0') : tick}
|
|
217
|
+
</Text>
|
|
218
|
+
))}
|
|
219
|
+
</View>
|
|
220
|
+
</View>
|
|
221
|
+
) : null}
|
|
222
|
+
|
|
223
|
+
{legend && legend.length > 0 ? (
|
|
224
|
+
<View className={slots.legend()}>
|
|
225
|
+
{legend.map((item) => (
|
|
226
|
+
<View key={item.label} className={slots.legendItem()}>
|
|
227
|
+
<View className={cn(slots.swatch(), TONE[item.tone ?? 'primary'])} />
|
|
228
|
+
<Text className={slots.legendLabel()}>{item.label}</Text>
|
|
229
|
+
</View>
|
|
230
|
+
))}
|
|
231
|
+
</View>
|
|
232
|
+
) : null}
|
|
233
|
+
</View>
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
);
|
|
237
|
+
|
|
238
|
+
WeekHoursGrid.displayName = 'WeekHoursGrid';
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WeekStrip — one row of days to pick from.
|
|
3
|
+
*
|
|
4
|
+
* A schedule screen usually starts with the days of the week across the top:
|
|
5
|
+
* press one and the list below it shows what is on that day. A month grid is
|
|
6
|
+
* the wrong shape for that, because it spends five rows on weeks the screen is
|
|
7
|
+
* not about.
|
|
8
|
+
*
|
|
9
|
+
* ```tsx
|
|
10
|
+
* <WeekStrip value={day} onValueChange={setDay} marks={(date) => marksFor(date)} />
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* ## Two layouts
|
|
14
|
+
*
|
|
15
|
+
* By default the strip is the seven days of one week, in seven equal cells
|
|
16
|
+
* that fill the row. `scroll` lays out a run of `length` days from `start`
|
|
17
|
+
* instead, in cells of a fixed width that scroll sideways, for a picker that
|
|
18
|
+
* reaches a few weeks ahead.
|
|
19
|
+
*
|
|
20
|
+
* ## What a day can say
|
|
21
|
+
*
|
|
22
|
+
* Every day is a rounded column with its weekday above its number. The
|
|
23
|
+
* selected day's column is filled, and today's is ringed. Beneath the number a day can carry up to three dots in
|
|
24
|
+
* different tones, or a short label in their place, and a small dot in its
|
|
25
|
+
* corner for something that needs attention.
|
|
26
|
+
*
|
|
27
|
+
* `disabled` days are faded and cannot be pressed. `faded` days are faded
|
|
28
|
+
* too but stay pressable: a day in the past that is still worth looking at is
|
|
29
|
+
* not the same thing as a day that is closed.
|
|
30
|
+
*
|
|
31
|
+
* The week starts where the locale says it does with `weekStartsOn="auto"`,
|
|
32
|
+
* the same way `Calendar` reads it, and the weekday names come from `locale`.
|
|
33
|
+
*/
|
|
34
|
+
import { forwardRef, useMemo } from 'react';
|
|
35
|
+
import { Pressable, ScrollView, View, type ViewProps } from 'react-native';
|
|
36
|
+
import { tv, type VariantProps } from 'tailwind-variants';
|
|
37
|
+
import { Text } from '../../primitives/text';
|
|
38
|
+
import { cn } from '../../utils/cn';
|
|
39
|
+
import {
|
|
40
|
+
addDays,
|
|
41
|
+
isSameDay,
|
|
42
|
+
localeWeekStart,
|
|
43
|
+
longDate,
|
|
44
|
+
normalizeWeekStart,
|
|
45
|
+
startOfDay,
|
|
46
|
+
weekdayNames,
|
|
47
|
+
type DateLocale,
|
|
48
|
+
} from '../../utils/date';
|
|
49
|
+
import type { ViewRef } from '../../primitives/refs';
|
|
50
|
+
|
|
51
|
+
/** The colour of a mark, from the theme's roles. */
|
|
52
|
+
export type WeekStripTone = 'primary' | 'success' | 'warning' | 'destructive' | 'info' | 'muted';
|
|
53
|
+
|
|
54
|
+
/** What a day shows beneath its number, and in its corner. */
|
|
55
|
+
export interface WeekStripMarks {
|
|
56
|
+
/** Up to three dots, one per kind of thing on the day. */
|
|
57
|
+
dots?: WeekStripTone[];
|
|
58
|
+
/** A short label in place of the dots, such as "3 free". Wins over `dots`. */
|
|
59
|
+
label?: string;
|
|
60
|
+
/** A small dot in the top corner, for a day that needs attention. */
|
|
61
|
+
corner?: WeekStripTone;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const TONE: Record<WeekStripTone, string> = {
|
|
65
|
+
primary: 'bg-primary',
|
|
66
|
+
success: 'bg-success',
|
|
67
|
+
warning: 'bg-warning',
|
|
68
|
+
destructive: 'bg-destructive',
|
|
69
|
+
info: 'bg-info',
|
|
70
|
+
muted: 'bg-muted-foreground',
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const weekStripVariants = tv({
|
|
74
|
+
slots: {
|
|
75
|
+
// Always the full row: seven equal columns need a width to share, and a
|
|
76
|
+
// strip sized to its contents squeezes the weekday names until they wrap.
|
|
77
|
+
root: 'w-full flex-row gap-1 self-stretch',
|
|
78
|
+
cell: 'relative flex-1 items-center rounded-2xl border border-transparent',
|
|
79
|
+
weekday: 'text-xs font-medium text-muted-foreground',
|
|
80
|
+
number: 'font-semibold text-foreground',
|
|
81
|
+
marks: 'h-3 flex-row items-center justify-center gap-1',
|
|
82
|
+
dot: 'size-1.5 rounded-full',
|
|
83
|
+
label: 'text-xs text-muted-foreground',
|
|
84
|
+
corner: 'absolute end-1.5 top-1.5 size-1.5 rounded-full',
|
|
85
|
+
},
|
|
86
|
+
variants: {
|
|
87
|
+
size: {
|
|
88
|
+
sm: { cell: 'gap-0.5 py-2', number: 'text-base' },
|
|
89
|
+
md: { cell: 'gap-1 py-2.5', number: 'text-lg' },
|
|
90
|
+
},
|
|
91
|
+
selected: {
|
|
92
|
+
true: {
|
|
93
|
+
cell: 'bg-primary',
|
|
94
|
+
weekday: 'text-primary-foreground opacity-70',
|
|
95
|
+
number: 'text-primary-foreground',
|
|
96
|
+
label: 'text-primary-foreground opacity-80',
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
today: {
|
|
100
|
+
true: { cell: 'border-border bg-muted' },
|
|
101
|
+
},
|
|
102
|
+
dim: {
|
|
103
|
+
true: { cell: 'opacity-40' },
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
defaultVariants: { size: 'md' },
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
/** How big the strip's days are. */
|
|
110
|
+
export type WeekStripSize = NonNullable<VariantProps<typeof weekStripVariants>['size']>;
|
|
111
|
+
|
|
112
|
+
/** The width of one day when the strip scrolls, per size. */
|
|
113
|
+
const SCROLL_CELL: Record<WeekStripSize, number> = { sm: 48, md: 56 };
|
|
114
|
+
|
|
115
|
+
export interface WeekStripProps extends Omit<ViewProps, 'children'> {
|
|
116
|
+
className?: string;
|
|
117
|
+
/** The selected day. */
|
|
118
|
+
value?: Date | null;
|
|
119
|
+
/** Called with the day that was pressed. */
|
|
120
|
+
onValueChange?: (day: Date) => void;
|
|
121
|
+
/**
|
|
122
|
+
* Which week to show, as any day inside it. Defaults to the week of `value`,
|
|
123
|
+
* or this week. Ignored when `scroll` is set.
|
|
124
|
+
*/
|
|
125
|
+
week?: Date;
|
|
126
|
+
/**
|
|
127
|
+
* Lay out `length` days from `start` in fixed-width cells that scroll
|
|
128
|
+
* sideways, instead of the seven days of one week filling the row.
|
|
129
|
+
*/
|
|
130
|
+
scroll?: boolean;
|
|
131
|
+
/** The first day of a scrolling strip. Defaults to today. */
|
|
132
|
+
start?: Date;
|
|
133
|
+
/** How many days a scrolling strip holds. Default 14. */
|
|
134
|
+
length?: number;
|
|
135
|
+
/**
|
|
136
|
+
* The first day of the week, 0 for Sunday to 6 for Saturday, or `auto` to
|
|
137
|
+
* ask the locale. Default 0.
|
|
138
|
+
*/
|
|
139
|
+
weekStartsOn?: number | 'auto';
|
|
140
|
+
/** The locale for weekday names and spoken dates. Defaults to the device's. */
|
|
141
|
+
locale?: DateLocale;
|
|
142
|
+
/** How big the days are. `sm` suits a header; `md` is the default. */
|
|
143
|
+
size?: WeekStripSize;
|
|
144
|
+
/** Days that cannot be picked. They are faded and do not respond. */
|
|
145
|
+
disabled?: (day: Date) => boolean;
|
|
146
|
+
/** Days that are faded but can still be picked, such as days in the past. */
|
|
147
|
+
faded?: (day: Date) => boolean;
|
|
148
|
+
/** What each day shows beneath its number and in its corner. */
|
|
149
|
+
marks?: (day: Date) => WeekStripMarks | undefined;
|
|
150
|
+
/** The day counted as today. Defaults to the current date. */
|
|
151
|
+
today?: Date;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export const WeekStrip = forwardRef<ViewRef, WeekStripProps>(
|
|
155
|
+
(
|
|
156
|
+
{
|
|
157
|
+
className,
|
|
158
|
+
value,
|
|
159
|
+
onValueChange,
|
|
160
|
+
week,
|
|
161
|
+
scroll = false,
|
|
162
|
+
start,
|
|
163
|
+
length = 14,
|
|
164
|
+
weekStartsOn = 0,
|
|
165
|
+
locale,
|
|
166
|
+
size = 'md',
|
|
167
|
+
disabled,
|
|
168
|
+
faded,
|
|
169
|
+
marks,
|
|
170
|
+
today: todayProp,
|
|
171
|
+
...props
|
|
172
|
+
},
|
|
173
|
+
ref
|
|
174
|
+
) => {
|
|
175
|
+
const first = weekStartsOn === 'auto' ? localeWeekStart(locale) : normalizeWeekStart(weekStartsOn);
|
|
176
|
+
const today = startOfDay(todayProp ?? new Date());
|
|
177
|
+
// Indexed by `getDay()`, so a day of any week finds its own name.
|
|
178
|
+
const names = useMemo(() => weekdayNames(locale, 0), [locale]);
|
|
179
|
+
|
|
180
|
+
const anchor = (week ?? value ?? today).getTime();
|
|
181
|
+
const startTime = (start ?? today).getTime();
|
|
182
|
+
const days = useMemo(() => {
|
|
183
|
+
if (scroll) {
|
|
184
|
+
const from = startOfDay(new Date(startTime));
|
|
185
|
+
return Array.from({ length: Math.max(1, Math.trunc(length)) }, (_unused, index) =>
|
|
186
|
+
addDays(from, index)
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
const day = startOfDay(new Date(anchor));
|
|
190
|
+
const back = (day.getDay() - first + 7) % 7;
|
|
191
|
+
const from = addDays(day, -back);
|
|
192
|
+
return Array.from({ length: 7 }, (_unused, index) => addDays(from, index));
|
|
193
|
+
}, [scroll, startTime, length, anchor, first]);
|
|
194
|
+
|
|
195
|
+
const slots = weekStripVariants({ size });
|
|
196
|
+
|
|
197
|
+
const cells = days.map((day) => {
|
|
198
|
+
const selected = isSameDay(day, value);
|
|
199
|
+
const isToday = isSameDay(day, today);
|
|
200
|
+
const off = disabled?.(day) ?? false;
|
|
201
|
+
const dim = off || (faded?.(day) ?? false);
|
|
202
|
+
const mark = marks?.(day);
|
|
203
|
+
const dots = (mark?.dots ?? []).slice(0, 3);
|
|
204
|
+
const styles = weekStripVariants({ size, selected, today: isToday && !selected, dim });
|
|
205
|
+
const spoken = [longDate(day, locale), mark?.label].filter(Boolean).join(', ');
|
|
206
|
+
|
|
207
|
+
return (
|
|
208
|
+
<Pressable
|
|
209
|
+
key={day.getTime()}
|
|
210
|
+
accessibilityRole="button"
|
|
211
|
+
accessibilityLabel={spoken}
|
|
212
|
+
accessibilityState={{ selected, disabled: off }}
|
|
213
|
+
disabled={off}
|
|
214
|
+
onPress={() => onValueChange?.(day)}
|
|
215
|
+
style={scroll ? { width: SCROLL_CELL[size] } : undefined}
|
|
216
|
+
className={cn(styles.cell(), scroll && 'flex-none')}
|
|
217
|
+
>
|
|
218
|
+
<Text numberOfLines={1} className={styles.weekday()}>
|
|
219
|
+
{names[day.getDay()]}
|
|
220
|
+
</Text>
|
|
221
|
+
<Text className={styles.number()}>{day.getDate()}</Text>
|
|
222
|
+
<View className={styles.marks()}>
|
|
223
|
+
{mark?.label ? (
|
|
224
|
+
<Text numberOfLines={1} className={styles.label()}>
|
|
225
|
+
{mark.label}
|
|
226
|
+
</Text>
|
|
227
|
+
) : (
|
|
228
|
+
dots.map((tone, index) => (
|
|
229
|
+
// On the selected fill a tone could vanish into it, so every
|
|
230
|
+
// dot takes the fill's own foreground there.
|
|
231
|
+
<View
|
|
232
|
+
key={index}
|
|
233
|
+
className={cn(styles.dot(), selected ? 'bg-primary-foreground' : TONE[tone])}
|
|
234
|
+
/>
|
|
235
|
+
))
|
|
236
|
+
)}
|
|
237
|
+
</View>
|
|
238
|
+
{mark?.corner ? (
|
|
239
|
+
<View
|
|
240
|
+
className={cn(styles.corner(), selected ? 'bg-primary-foreground' : TONE[mark.corner])}
|
|
241
|
+
/>
|
|
242
|
+
) : null}
|
|
243
|
+
</Pressable>
|
|
244
|
+
);
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
if (scroll) {
|
|
248
|
+
const selectedIndex = days.findIndex((day) => isSameDay(day, value));
|
|
249
|
+
return (
|
|
250
|
+
<View ref={ref} className={cn('w-full self-stretch', className)} {...props}>
|
|
251
|
+
<ScrollView
|
|
252
|
+
horizontal
|
|
253
|
+
showsHorizontalScrollIndicator={false}
|
|
254
|
+
// Opens with the selected day in view rather than at the far end.
|
|
255
|
+
contentOffset={{ x: Math.max(0, selectedIndex) * SCROLL_CELL[size], y: 0 }}
|
|
256
|
+
contentContainerClassName={slots.root()}
|
|
257
|
+
>
|
|
258
|
+
{cells}
|
|
259
|
+
</ScrollView>
|
|
260
|
+
</View>
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
return (
|
|
265
|
+
<View ref={ref} className={slots.root({ className })} {...props}>
|
|
266
|
+
{cells}
|
|
267
|
+
</View>
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
);
|
|
271
|
+
|
|
272
|
+
WeekStrip.displayName = 'WeekStrip';
|
package/src/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ export { PanelUIProvider, type PanelUIProviderProps } from './providers/panel-ui
|
|
|
5
5
|
export {
|
|
6
6
|
useTheme,
|
|
7
7
|
useThemeMode,
|
|
8
|
+
PanelUITheme,
|
|
8
9
|
PANEL_THEMES,
|
|
9
10
|
PANEL_THEME_NAMES,
|
|
10
11
|
PANEL_EXTRA_THEMES,
|
|
@@ -550,6 +551,21 @@ export {
|
|
|
550
551
|
type CalendarSelection,
|
|
551
552
|
type DateRange,
|
|
552
553
|
} from './components/calendar';
|
|
554
|
+
export {
|
|
555
|
+
WeekStrip,
|
|
556
|
+
type WeekStripProps,
|
|
557
|
+
type WeekStripMarks,
|
|
558
|
+
type WeekStripTone,
|
|
559
|
+
type WeekStripSize,
|
|
560
|
+
} from './components/week-strip';
|
|
561
|
+
export {
|
|
562
|
+
WeekHoursGrid,
|
|
563
|
+
type WeekHoursGridProps,
|
|
564
|
+
type WeekHoursRow,
|
|
565
|
+
type WeekHoursBlock,
|
|
566
|
+
type WeekHoursLegendItem,
|
|
567
|
+
type WeekHoursTone,
|
|
568
|
+
} from './components/week-hours-grid';
|
|
553
569
|
export { Card, type CardProps } from './components/card';
|
|
554
570
|
export { Checkbox, type CheckboxProps, type CheckboxSize } from './components/checkbox';
|
|
555
571
|
export {
|
package/src/primitives/scrim.tsx
CHANGED
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
* It fills its parent and does not intercept touches itself — the overlay layers
|
|
16
16
|
* its own dismiss `Pressable` over it — so it is purely the visual backdrop.
|
|
17
17
|
*/
|
|
18
|
-
import { useEffect, useState, type ComponentType } from 'react';
|
|
19
|
-
import { AccessibilityInfo, StyleSheet, View, type ViewProps } from 'react-native';
|
|
18
|
+
import { useEffect, useState, type ComponentType, type Ref, type RefObject } from 'react';
|
|
19
|
+
import { AccessibilityInfo, Platform, StyleSheet, View, type ViewProps } from 'react-native';
|
|
20
20
|
import Animated, {
|
|
21
21
|
FadeIn,
|
|
22
22
|
FadeOut,
|
|
@@ -52,6 +52,46 @@ const BlurView: ComponentType<BlurViewProps> | null = (() => {
|
|
|
52
52
|
/** True when a real blur can be drawn — for a caller that wants to know. */
|
|
53
53
|
export const hasBlur = BlurView !== null;
|
|
54
54
|
|
|
55
|
+
/**
|
|
56
|
+
* `expo-blur`'s BlurTargetView, or null when the installed version has none.
|
|
57
|
+
*
|
|
58
|
+
* Android cannot blur whatever happens to be behind a view. It blurs one view
|
|
59
|
+
* it has been pointed at, and that view has to be a BlurTargetView wrapping
|
|
60
|
+
* the content. A component that owns the content passing under its blur — a
|
|
61
|
+
* scroller under a header — wraps it in one and hands the ref to the blur.
|
|
62
|
+
*/
|
|
63
|
+
export const BlurTargetView: ComponentType<ViewProps & { ref?: Ref<View> }> | null = (() => {
|
|
64
|
+
if (Platform.OS !== 'android') return null;
|
|
65
|
+
try {
|
|
66
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
67
|
+
const mod = require('expo-blur');
|
|
68
|
+
return (mod?.BlurTargetView as ComponentType<ViewProps & { ref?: Ref<View> }>) ?? null;
|
|
69
|
+
} catch {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
})();
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Whether this device can draw a blur at all, given a target on Android. The
|
|
76
|
+
* Android blur is held to API 31 and later, where it runs on the GPU; below
|
|
77
|
+
* that it costs every frame of a scroll, and a component falls back to its
|
|
78
|
+
* plain surface instead.
|
|
79
|
+
*/
|
|
80
|
+
export const canBlurHere =
|
|
81
|
+
BlurView !== null &&
|
|
82
|
+
(Platform.OS !== 'android' ||
|
|
83
|
+
(BlurTargetView !== null && typeof Platform.Version === 'number' && Platform.Version >= 31));
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* The extra props a BlurView needs to blur on Android: the method, and the
|
|
87
|
+
* target it samples. Empty on every other platform, where the blur reads
|
|
88
|
+
* whatever is behind it.
|
|
89
|
+
*/
|
|
90
|
+
export function androidBlurProps(target: RefObject<View | null> | null | undefined) {
|
|
91
|
+
if (Platform.OS !== 'android' || !target) return {};
|
|
92
|
+
return { blurMethod: 'dimezisBlurViewSdk31Plus' as const, blurTarget: target };
|
|
93
|
+
}
|
|
94
|
+
|
|
55
95
|
/**
|
|
56
96
|
* The same view, able to take its `intensity` from the UI thread. The package
|
|
57
97
|
* names the native view as the one to animate, so the radius itself moves
|
|
@@ -157,6 +197,14 @@ function scrimMode(blur: boolean, canBlur: boolean, reduceTransparency: boolean
|
|
|
157
197
|
return canBlur ? 'blur' : 'dim';
|
|
158
198
|
}
|
|
159
199
|
|
|
200
|
+
/*
|
|
201
|
+
* A scrim covers the whole app from a portal, so there is no view of the app
|
|
202
|
+
* it could point an Android blur at. Without a target the platform draws only
|
|
203
|
+
* a faint tint, which leaves the screen behind fully legible. A dim is what
|
|
204
|
+
* `blur` promises when it cannot draw, so Android gets the dim.
|
|
205
|
+
*/
|
|
206
|
+
const scrimCanBlur = BlurView !== null && Platform.OS !== 'android';
|
|
207
|
+
|
|
160
208
|
function opaqueClassName(tint: BlurTint) {
|
|
161
209
|
if (tint === 'light') return 'bg-white';
|
|
162
210
|
if (tint === 'dark') return 'bg-black';
|
|
@@ -164,7 +212,11 @@ function opaqueClassName(tint: BlurTint) {
|
|
|
164
212
|
}
|
|
165
213
|
|
|
166
214
|
export interface ScrimProps extends Omit<ViewProps, 'children'> {
|
|
167
|
-
/**
|
|
215
|
+
/**
|
|
216
|
+
* Frost the backdrop instead of dimming it. Falls back to a dim where it
|
|
217
|
+
* can't: without `expo-blur`, and on Android, where an overlay has no view
|
|
218
|
+
* of the app behind it to point a blur at.
|
|
219
|
+
*/
|
|
168
220
|
blur?: boolean;
|
|
169
221
|
/** Blur strength, 0–100. */
|
|
170
222
|
intensity?: number;
|
|
@@ -196,7 +248,7 @@ export function Scrim({
|
|
|
196
248
|
...props
|
|
197
249
|
}: ScrimProps) {
|
|
198
250
|
const reduceTransparency = useReduceTransparency();
|
|
199
|
-
const mode = scrimMode(blur,
|
|
251
|
+
const mode = scrimMode(blur, scrimCanBlur, reduceTransparency);
|
|
200
252
|
|
|
201
253
|
if (progress) {
|
|
202
254
|
return (
|