@a-type/ui 3.0.31 → 3.0.33

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 (49) hide show
  1. package/dist/cjs/components/datePicker/Calendar.d.ts +11 -0
  2. package/dist/cjs/components/datePicker/Calendar.js +37 -0
  3. package/dist/cjs/components/datePicker/Calendar.js.map +1 -0
  4. package/dist/cjs/components/datePicker/DatePicker.d.ts +42 -13
  5. package/dist/cjs/components/datePicker/DatePicker.js +31 -71
  6. package/dist/cjs/components/datePicker/DatePicker.js.map +1 -1
  7. package/dist/cjs/components/datePicker/DatePicker.stories.d.ts +36 -1
  8. package/dist/cjs/components/datePicker/DatePicker.stories.js +18 -2
  9. package/dist/cjs/components/datePicker/DatePicker.stories.js.map +1 -1
  10. package/dist/cjs/components/datePicker/DateRangePicker.d.ts +55 -0
  11. package/dist/cjs/components/datePicker/DateRangePicker.js +89 -0
  12. package/dist/cjs/components/datePicker/DateRangePicker.js.map +1 -0
  13. package/dist/cjs/components/datePicker/index.d.ts +2 -0
  14. package/dist/cjs/components/datePicker/index.js +1 -0
  15. package/dist/cjs/components/datePicker/index.js.map +1 -1
  16. package/dist/cjs/components/forms/EmojiField.js +5 -1
  17. package/dist/cjs/components/forms/EmojiField.js.map +1 -1
  18. package/dist/cjs/uno/preflights/fonts.d.ts +2 -2
  19. package/dist/cjs/uno/preflights/fonts.js +1 -3
  20. package/dist/cjs/uno/preflights/fonts.js.map +1 -1
  21. package/dist/css/main.css +1 -1
  22. package/dist/esm/components/datePicker/Calendar.d.ts +11 -0
  23. package/dist/esm/components/datePicker/Calendar.js +32 -0
  24. package/dist/esm/components/datePicker/Calendar.js.map +1 -0
  25. package/dist/esm/components/datePicker/DatePicker.d.ts +42 -13
  26. package/dist/esm/components/datePicker/DatePicker.js +32 -68
  27. package/dist/esm/components/datePicker/DatePicker.js.map +1 -1
  28. package/dist/esm/components/datePicker/DatePicker.stories.d.ts +36 -1
  29. package/dist/esm/components/datePicker/DatePicker.stories.js +19 -3
  30. package/dist/esm/components/datePicker/DatePicker.stories.js.map +1 -1
  31. package/dist/esm/components/datePicker/DateRangePicker.d.ts +55 -0
  32. package/dist/esm/components/datePicker/DateRangePicker.js +83 -0
  33. package/dist/esm/components/datePicker/DateRangePicker.js.map +1 -0
  34. package/dist/esm/components/datePicker/index.d.ts +2 -0
  35. package/dist/esm/components/datePicker/index.js +1 -0
  36. package/dist/esm/components/datePicker/index.js.map +1 -1
  37. package/dist/esm/components/forms/EmojiField.js +5 -1
  38. package/dist/esm/components/forms/EmojiField.js.map +1 -1
  39. package/dist/esm/uno/preflights/fonts.d.ts +2 -2
  40. package/dist/esm/uno/preflights/fonts.js +1 -3
  41. package/dist/esm/uno/preflights/fonts.js.map +1 -1
  42. package/package.json +1 -1
  43. package/src/components/datePicker/Calendar.tsx +83 -0
  44. package/src/components/datePicker/DatePicker.stories.tsx +37 -2
  45. package/src/components/datePicker/DatePicker.tsx +77 -222
  46. package/src/components/datePicker/DateRangePicker.tsx +161 -0
  47. package/src/components/datePicker/index.ts +2 -0
  48. package/src/components/forms/EmojiField.tsx +5 -1
  49. package/src/uno/preflights/fonts.ts +4 -7
@@ -0,0 +1,161 @@
1
+ import { Calendar, CalendarDays, useCalendarContext } from 'calendar-blocks';
2
+ import clsx from 'clsx';
3
+ import { ReactNode, useCallback, useState } from 'react';
4
+ import { withClassName } from '../../hooks.js';
5
+ import { PaletteName } from '../../uno/index.js';
6
+ import { Icon } from '../icon/Icon.js';
7
+ import {
8
+ CalendarDay,
9
+ CalendarGrid,
10
+ DayLabels,
11
+ MonthButton,
12
+ MonthLabel,
13
+ } from './Calendar.js';
14
+
15
+ const RangeLayout = withClassName(
16
+ 'div',
17
+ 'grid [grid-template-areas:"prevMonth_leftMonth_nextMonth""leftGrid_leftGrid_leftGrid"] [grid-template-columns:auto_1fr_auto]',
18
+ '[grid-template-rows:auto_1fr] gap-2',
19
+ 'sm:grid-areas-[prevMonth_leftMonth_rightMonth_nextMonth]-[leftGrid_leftGrid_rightGrid_rightGrid] sm:[grid-template-columns:auto_1fr_1fr_auto]',
20
+ );
21
+
22
+ function DateRangePickerMonthControls() {
23
+ const { setDisplayInfo, month, year } = useCalendarContext();
24
+ const monthLabel = new Date(year, month).toLocaleDateString('en-US', {
25
+ month: 'long',
26
+ year: 'numeric',
27
+ });
28
+ const nextMonth = new Date(year, month + 1);
29
+ const nextMonthLabel = nextMonth.toLocaleDateString('en-US', {
30
+ month: 'long',
31
+ year: 'numeric',
32
+ });
33
+ return (
34
+ <>
35
+ <MonthButton
36
+ emphasis="ghost"
37
+ className="[grid-area:prevMonth]"
38
+ onClick={() =>
39
+ setDisplayInfo({
40
+ month: month - 1,
41
+ year: year,
42
+ })
43
+ }
44
+ >
45
+ <Icon name="arrowLeft" />
46
+ </MonthButton>
47
+ <MonthLabel className="[grid-area:leftMonth]">{monthLabel}</MonthLabel>
48
+ <MonthLabel className="[grid-area:rightMonth] !hidden !sm:block">
49
+ {nextMonthLabel}
50
+ </MonthLabel>
51
+ <MonthButton
52
+ emphasis="ghost"
53
+ className="[grid-area:nextMonth]"
54
+ onClick={() =>
55
+ setDisplayInfo({
56
+ month: month + 1,
57
+ year: year,
58
+ })
59
+ }
60
+ >
61
+ <Icon name="arrowRight" />
62
+ </MonthButton>
63
+ </>
64
+ );
65
+ }
66
+
67
+ function DateRangePickerRoot({
68
+ children,
69
+ color,
70
+ value,
71
+ onChange,
72
+ className,
73
+ ...rest
74
+ }: DateRangePickerProps & {
75
+ children?: ReactNode;
76
+ }) {
77
+ const [{ month, year }, setDisplay] = useState(() => ({
78
+ month: new Date().getMonth(),
79
+ year: new Date().getFullYear(),
80
+ }));
81
+
82
+ const onDisplayChange = useCallback(
83
+ ({ month: newMonth, year: newYear }: { month: number; year: number }) => {
84
+ /**
85
+ * Important UX consideration:
86
+ *
87
+ * since we are displaying 2 months at once, we don't
88
+ * always want to change our view if the user's cursor
89
+ * date moves from one month to another. Specifically,
90
+ * if they move from the first visible month to the
91
+ * second visible month, we don't need to change the view,
92
+ * since they are still within the visible range.
93
+ * So, we write logic to ignore that case!
94
+ */
95
+ if (newMonth === month + 1 && newYear === year) {
96
+ return; // ignore movement from the first to the second frame
97
+ }
98
+
99
+ setDisplay({
100
+ month: newMonth,
101
+ year: newYear,
102
+ });
103
+ },
104
+ [month, year],
105
+ );
106
+
107
+ return (
108
+ <Calendar
109
+ displayMonth={month}
110
+ displayYear={year}
111
+ rangeValue={value}
112
+ onRangeChange={(range) => onChange(range)}
113
+ onDisplayChange={onDisplayChange}
114
+ className={clsx(
115
+ 'flex justify-center',
116
+ color && `palette-${color}`,
117
+ className,
118
+ )}
119
+ {...rest}
120
+ >
121
+ <RangeLayout>{children}</RangeLayout>
122
+ </Calendar>
123
+ );
124
+ }
125
+
126
+ export interface DateRangePickerProps {
127
+ value: { start: Date | null; end: Date | null };
128
+ onChange: (value: { start: Date | null; end: Date | null }) => void;
129
+ className?: string;
130
+ color?: PaletteName;
131
+ }
132
+
133
+ function DateRangePickerBase(props: DateRangePickerProps) {
134
+ return (
135
+ <DateRangePickerRoot {...props}>
136
+ <DateRangePickerMonthControls />
137
+ <CalendarGrid className="[grid-area:leftGrid]">
138
+ {(value) => <CalendarDay value={value} key={value.key} />}
139
+ </CalendarGrid>
140
+ <CalendarGrid
141
+ className="[grid-area:rightGrid] !hidden !sm:grid"
142
+ monthOffset={1}
143
+ >
144
+ {(value) => <CalendarDay value={value} key={value.key} />}
145
+ </CalendarGrid>
146
+ </DateRangePickerRoot>
147
+ );
148
+ }
149
+
150
+ export const DateRangePicker = Object.assign(DateRangePickerBase, {
151
+ Root: DateRangePickerRoot,
152
+ RangeLayout,
153
+ DayLabels,
154
+ CalendarDay,
155
+ Calendar,
156
+ CalendarGrid,
157
+ CalendarDays,
158
+ MonthControls: DateRangePickerMonthControls,
159
+ MonthButton,
160
+ MonthLabel,
161
+ });
@@ -1 +1,3 @@
1
+ export type * from 'calendar-blocks';
1
2
  export * from './DatePicker.js';
3
+ export * from './DateRangePicker.js';
@@ -1,5 +1,6 @@
1
1
  import clsx from 'clsx';
2
2
  import { useField } from 'formik';
3
+ import { useState } from 'react';
3
4
  import { useIdOrGenerated } from '../../hooks/useIdOrGenerated.js';
4
5
  import { Box } from '../box/Box.js';
5
6
  import { Button, ButtonProps } from '../button/Button.js';
@@ -24,9 +25,10 @@ export function EmojiField({
24
25
  }: EmojiFieldProps) {
25
26
  const [props, _, tools] = useField({ name });
26
27
  const id = useIdOrGenerated(providedId);
28
+ const [open, setOpen] = useState(false);
27
29
  return (
28
30
  <Box gap="sm" className={className}>
29
- <Popover>
31
+ <Popover open={open} onOpenChange={setOpen}>
30
32
  <Popover.Trigger asChild>
31
33
  <Button
32
34
  id={id}
@@ -44,12 +46,14 @@ export function EmojiField({
44
46
  <EmojiPicker
45
47
  onValueChange={(v) => {
46
48
  tools.setValue(v);
49
+ setOpen(false);
47
50
  }}
48
51
  onClear={
49
52
  required
50
53
  ? undefined
51
54
  : () => {
52
55
  tools.setValue('');
56
+ setOpen(false);
53
57
  }
54
58
  }
55
59
  id={id}
@@ -1,15 +1,12 @@
1
1
  import { preflight } from './_util.js';
2
2
 
3
3
  export interface FontsPreflightOptions {
4
- interFontLocation: string;
4
+ interFontLocation?: string;
5
5
  }
6
6
 
7
- export const fontsPreflight = (
8
- { interFontLocation }: FontsPreflightOptions = {
9
- interFontLocation:
10
- 'https://resources.biscuits.club/fonts/Inter-VariableFont_slnt,wght.ttf',
11
- },
12
- ) =>
7
+ export const fontsPreflight = ({
8
+ interFontLocation = 'https://resources.biscuits.club/fonts/Inter-VariableFont_slnt,wght.ttf',
9
+ }: FontsPreflightOptions = {}) =>
13
10
  preflight({
14
11
  getCSS: () => `
15
12
  @font-face {