@cdx-ui/components 0.2.5 → 0.3.1

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 (94) hide show
  1. package/coverage.svg +1 -1
  2. package/docs/components/bottom-sheet/content.md +2 -0
  3. package/docs/components/calendar/content.md +25 -1
  4. package/docs/components/carousel/content.md +1 -1
  5. package/docs/components/data-grid/content.md +50 -8
  6. package/docs/components/icon-button/content.md +23 -1
  7. package/docs/components/month-calendar/content.md +2 -0
  8. package/docs/components/range-calendar/content.md +3 -1
  9. package/docs/components/toast/content.md +23 -7
  10. package/docs/llms.txt +2 -0
  11. package/docs/resources/release-notes/0.2.5/content.md +25 -0
  12. package/docs/resources/release-notes/0.3.0/content.md +19 -0
  13. package/docs/resources/release-notes/content.md +2 -0
  14. package/lib/commonjs/components/BottomSheet/index.js +25 -1
  15. package/lib/commonjs/components/BottomSheet/index.js.map +1 -1
  16. package/lib/commonjs/components/BottomSheet/styles.js +8 -2
  17. package/lib/commonjs/components/BottomSheet/styles.js.map +1 -1
  18. package/lib/commonjs/components/Calendar/CalendarMonthHeader.js +15 -5
  19. package/lib/commonjs/components/Calendar/CalendarMonthHeader.js.map +1 -1
  20. package/lib/commonjs/components/Calendar/CalendarYearList.js +116 -0
  21. package/lib/commonjs/components/Calendar/CalendarYearList.js.map +1 -0
  22. package/lib/commonjs/components/Calendar/CalendarYearPickerGrid.js +58 -31
  23. package/lib/commonjs/components/Calendar/CalendarYearPickerGrid.js.map +1 -1
  24. package/lib/commonjs/components/Calendar/flashCalendarAdapter.js +22 -3
  25. package/lib/commonjs/components/Calendar/flashCalendarAdapter.js.map +1 -1
  26. package/lib/commonjs/components/Calendar/index.js +6 -2
  27. package/lib/commonjs/components/Calendar/index.js.map +1 -1
  28. package/lib/commonjs/components/Calendar/styles.js +16 -2
  29. package/lib/commonjs/components/Calendar/styles.js.map +1 -1
  30. package/lib/commonjs/components/IconButton/styles.js +107 -2
  31. package/lib/commonjs/components/IconButton/styles.js.map +1 -1
  32. package/lib/commonjs/components/MonthCalendar/index.js +39 -13
  33. package/lib/commonjs/components/MonthCalendar/index.js.map +1 -1
  34. package/lib/commonjs/components/RangeCalendar/index.js +6 -2
  35. package/lib/commonjs/components/RangeCalendar/index.js.map +1 -1
  36. package/lib/commonjs/components/Toast/index.js +5 -2
  37. package/lib/commonjs/components/Toast/index.js.map +1 -1
  38. package/lib/module/components/BottomSheet/index.js +27 -3
  39. package/lib/module/components/BottomSheet/index.js.map +1 -1
  40. package/lib/module/components/BottomSheet/styles.js +8 -2
  41. package/lib/module/components/BottomSheet/styles.js.map +1 -1
  42. package/lib/module/components/Calendar/CalendarMonthHeader.js +15 -5
  43. package/lib/module/components/Calendar/CalendarMonthHeader.js.map +1 -1
  44. package/lib/module/components/Calendar/CalendarYearList.js +112 -0
  45. package/lib/module/components/Calendar/CalendarYearList.js.map +1 -0
  46. package/lib/module/components/Calendar/CalendarYearPickerGrid.js +61 -34
  47. package/lib/module/components/Calendar/CalendarYearPickerGrid.js.map +1 -1
  48. package/lib/module/components/Calendar/flashCalendarAdapter.js +20 -2
  49. package/lib/module/components/Calendar/flashCalendarAdapter.js.map +1 -1
  50. package/lib/module/components/Calendar/index.js +7 -3
  51. package/lib/module/components/Calendar/index.js.map +1 -1
  52. package/lib/module/components/Calendar/styles.js +15 -1
  53. package/lib/module/components/Calendar/styles.js.map +1 -1
  54. package/lib/module/components/IconButton/styles.js +107 -2
  55. package/lib/module/components/IconButton/styles.js.map +1 -1
  56. package/lib/module/components/MonthCalendar/index.js +42 -15
  57. package/lib/module/components/MonthCalendar/index.js.map +1 -1
  58. package/lib/module/components/RangeCalendar/index.js +7 -3
  59. package/lib/module/components/RangeCalendar/index.js.map +1 -1
  60. package/lib/module/components/Toast/index.js +5 -2
  61. package/lib/module/components/Toast/index.js.map +1 -1
  62. package/lib/typescript/components/BottomSheet/index.d.ts +8 -0
  63. package/lib/typescript/components/BottomSheet/index.d.ts.map +1 -1
  64. package/lib/typescript/components/BottomSheet/styles.d.ts +5 -1
  65. package/lib/typescript/components/BottomSheet/styles.d.ts.map +1 -1
  66. package/lib/typescript/components/Calendar/CalendarMonthHeader.d.ts.map +1 -1
  67. package/lib/typescript/components/Calendar/CalendarYearList.d.ts +23 -0
  68. package/lib/typescript/components/Calendar/CalendarYearList.d.ts.map +1 -0
  69. package/lib/typescript/components/Calendar/CalendarYearPickerGrid.d.ts +5 -1
  70. package/lib/typescript/components/Calendar/CalendarYearPickerGrid.d.ts.map +1 -1
  71. package/lib/typescript/components/Calendar/flashCalendarAdapter.d.ts +8 -0
  72. package/lib/typescript/components/Calendar/flashCalendarAdapter.d.ts.map +1 -1
  73. package/lib/typescript/components/Calendar/index.d.ts.map +1 -1
  74. package/lib/typescript/components/Calendar/styles.d.ts +7 -1
  75. package/lib/typescript/components/Calendar/styles.d.ts.map +1 -1
  76. package/lib/typescript/components/IconButton/styles.d.ts +2 -2
  77. package/lib/typescript/components/IconButton/styles.d.ts.map +1 -1
  78. package/lib/typescript/components/MonthCalendar/index.d.ts.map +1 -1
  79. package/lib/typescript/components/RangeCalendar/index.d.ts.map +1 -1
  80. package/lib/typescript/components/Toast/index.d.ts.map +1 -1
  81. package/lib/typescript/components/ToggleButton/styles.d.ts +1 -1
  82. package/package.json +5 -5
  83. package/src/components/BottomSheet/index.tsx +174 -138
  84. package/src/components/BottomSheet/styles.ts +11 -3
  85. package/src/components/Calendar/CalendarMonthHeader.tsx +29 -22
  86. package/src/components/Calendar/CalendarYearList.tsx +136 -0
  87. package/src/components/Calendar/CalendarYearPickerGrid.tsx +60 -33
  88. package/src/components/Calendar/flashCalendarAdapter.ts +27 -2
  89. package/src/components/Calendar/index.tsx +8 -3
  90. package/src/components/Calendar/styles.ts +17 -1
  91. package/src/components/IconButton/styles.ts +111 -0
  92. package/src/components/MonthCalendar/index.tsx +55 -33
  93. package/src/components/RangeCalendar/index.tsx +8 -3
  94. package/src/components/Toast/index.tsx +13 -3
@@ -1,4 +1,4 @@
1
- import { forwardRef, useCallback, useMemo, type ReactNode } from 'react';
1
+ import { forwardRef, useCallback, useState, type ReactNode } from 'react';
2
2
  import { Pressable, Text, View, type ViewProps } from 'react-native';
3
3
  import {
4
4
  dataAttributes,
@@ -21,6 +21,7 @@ import { cn } from '@cdx-ui/utils';
21
21
  import { ChevronLeft, ChevronRight, KeyboardArrowDown } from '@cdx-ui/icons';
22
22
  import { Icon } from '../Icon';
23
23
  import { IconButton } from '../IconButton';
24
+ import { CalendarYearList, getYearRange, YEAR_ROW_HEIGHT } from '../Calendar/CalendarYearList';
24
25
  import {
25
26
  calendarMonthHeaderIconVariants,
26
27
  calendarMonthHeaderLabelVariants,
@@ -31,8 +32,16 @@ import {
31
32
  calendarPillCellVariants,
32
33
  calendarRootVariants,
33
34
  calendarYearPickerGridVariants,
35
+ calendarYearPickerListVariants,
34
36
  } from '../Calendar/styles';
35
37
 
38
+ // The month grid's four rows of pill cells, so the year view matches its height.
39
+ const MONTH_GRID_HEIGHT = 4 * YEAR_ROW_HEIGHT;
40
+
41
+ function renderYearCell(year: number) {
42
+ return <MonthCalendarYearCell year={year} />;
43
+ }
44
+
36
45
  export interface MonthCalendarProps
37
46
  extends Omit<MonthCalendarRootProps, 'children'>, Omit<ViewProps, 'children'> {
38
47
  className?: string;
@@ -109,28 +118,35 @@ const MonthCalendarHeader = forwardRef<View, ViewProps>(({ className, style, ...
109
118
  />
110
119
  </Pressable>
111
120
 
112
- {!isYearView ? (
113
- <View className={calendarMonthHeaderNavVariants()}>
114
- <IconButton
115
- as={ChevronLeft}
116
- variant="ghost"
117
- color="neutral"
118
- size="small"
119
- accessibilityLabel={labels.previousYear}
120
- isDisabled={disabled}
121
- onPress={() => shiftYear(-1)}
122
- />
123
- <IconButton
124
- as={ChevronRight}
125
- variant="ghost"
126
- color="neutral"
127
- size="small"
128
- accessibilityLabel={labels.nextYear}
129
- isDisabled={disabled}
130
- onPress={() => shiftYear(1)}
131
- />
132
- </View>
133
- ) : null}
121
+ {/* Stays mounted in the year view so the header keeps its height and the label does not move. */}
122
+ <View
123
+ className={calendarMonthHeaderNavVariants({ hidden: isYearView })}
124
+ pointerEvents={isYearView ? 'none' : 'auto'}
125
+ accessibilityElementsHidden={isYearView}
126
+ importantForAccessibility={isYearView ? 'no-hide-descendants' : 'auto'}
127
+ {...(isYearView ? { 'aria-hidden': true } : {})}
128
+ >
129
+ <IconButton
130
+ as={ChevronLeft}
131
+ variant="ghost"
132
+ color="neutral"
133
+ size="small"
134
+ accessibilityLabel={labels.previousYear}
135
+ isDisabled={disabled || isYearView}
136
+ focusable={!isYearView}
137
+ onPress={() => shiftYear(-1)}
138
+ />
139
+ <IconButton
140
+ as={ChevronRight}
141
+ variant="ghost"
142
+ color="neutral"
143
+ size="small"
144
+ accessibilityLabel={labels.nextYear}
145
+ isDisabled={disabled || isYearView}
146
+ focusable={!isYearView}
147
+ onPress={() => shiftYear(1)}
148
+ />
149
+ </View>
134
150
  </View>
135
151
  );
136
152
  });
@@ -138,25 +154,31 @@ const MonthCalendarHeader = forwardRef<View, ViewProps>(({ className, style, ...
138
154
  MonthCalendarHeader.displayName = 'MonthCalendar.Header';
139
155
 
140
156
  const MonthCalendarGrid = forwardRef<View, ViewProps>(({ className, style, ...props }, ref) => {
141
- const { view, visibleYear } = useMonthCalendarContext();
142
-
143
- const years = useMemo(
144
- () => Array.from({ length: 12 }, (_, i) => visibleYear - 5 + i),
145
- [visibleYear],
146
- );
157
+ const { view, visibleYear, minValue, maxValue } = useMonthCalendarContext();
158
+ const [todayYear] = useState(() => new Date().getFullYear());
147
159
 
148
160
  if (view === 'year') {
161
+ const { first, last } = getYearRange(
162
+ minValue ? parseMonthId(minValue)?.year : undefined,
163
+ maxValue ? parseMonthId(maxValue)?.year : undefined,
164
+ visibleYear,
165
+ todayYear,
166
+ );
149
167
  return (
150
168
  <View
151
169
  ref={ref}
152
- className={cn(calendarYearPickerGridVariants(), className)}
170
+ className={cn(calendarYearPickerListVariants(), className)}
153
171
  style={style}
154
172
  accessibilityRole="none"
155
173
  {...props}
156
174
  >
157
- {years.map((year) => (
158
- <MonthCalendarYearCell key={year} year={year} />
159
- ))}
175
+ <CalendarYearList
176
+ first={first}
177
+ last={last}
178
+ selectedYear={visibleYear}
179
+ height={MONTH_GRID_HEIGHT}
180
+ renderYear={renderYearCell}
181
+ />
160
182
  </View>
161
183
  );
162
184
  }
@@ -14,6 +14,8 @@ import { CalendarYearPickerGrid } from '../Calendar/CalendarYearPickerGrid';
14
14
  import {
15
15
  FLASH_CALENDAR_DAY_HEIGHT,
16
16
  FLASH_CALENDAR_RANGE_DAY_SPACING,
17
+ FLASH_CALENDAR_ROW_VERTICAL_SPACING,
18
+ FLASH_CALENDAR_WEEK_HEADER_HEIGHT,
17
19
  formatFlashCalendarWeekdayShort,
18
20
  toCalendarDateId,
19
21
  useFlashCalendarRangeTheme,
@@ -78,12 +80,15 @@ RangeCalendarHeader.displayName = 'RangeCalendar.Header';
78
80
 
79
81
  const RangeCalendarYearPicker = forwardRef<View, ViewProps>(
80
82
  ({ className, style, ...props }, ref) => {
81
- const { monthId, onMonthIdChange, disabled, setView, labels } = useRangeCalendarContext();
83
+ const { monthId, onMonthIdChange, minValue, maxValue, disabled, setView, labels } =
84
+ useRangeCalendarContext();
82
85
  return (
83
86
  <CalendarYearPickerGrid
84
87
  ref={ref}
85
88
  monthId={monthId}
86
89
  onMonthIdChange={onMonthIdChange}
90
+ minValue={minValue}
91
+ maxValue={maxValue}
87
92
  disabled={disabled}
88
93
  onViewChange={setView}
89
94
  labels={labels}
@@ -137,8 +142,8 @@ const RangeCalendarGrid = forwardRef<View, ViewProps>(({ className, style, ...pr
137
142
  calendarMaxDateId={maxValue}
138
143
  calendarMonthHeaderHeight={0}
139
144
  calendarDayHeight={FLASH_CALENDAR_DAY_HEIGHT}
140
- calendarWeekHeaderHeight={28}
141
- calendarRowVerticalSpacing={4}
145
+ calendarWeekHeaderHeight={FLASH_CALENDAR_WEEK_HEADER_HEIGHT}
146
+ calendarRowVerticalSpacing={FLASH_CALENDAR_ROW_VERTICAL_SPACING}
142
147
  calendarRowHorizontalSpacing={FLASH_CALENDAR_RANGE_DAY_SPACING}
143
148
  getCalendarMonthFormat={() => ''}
144
149
  getCalendarWeekDayFormat={formatWeekday}
@@ -441,9 +441,18 @@ const ToastAction = forwardRef<View, ToastActionProps>((props, ref) => {
441
441
  // --------------------------------------------------
442
442
 
443
443
  const ToastClose = forwardRef<View, ToastCloseProps>((props, ref) => {
444
- const { children, size = 'small', className, onPress, iconClassName, ...restProps } = props;
444
+ const {
445
+ children,
446
+ size = 'small',
447
+ className,
448
+ onPress,
449
+ iconClassName,
450
+ color: colorProp,
451
+ as = CloseIcon,
452
+ ...restProps
453
+ } = props;
445
454
  const { hide, id, color: toastColor } = useToastStyleContext();
446
- const usesNeutralStandIn = toastColor === 'neutral';
455
+ const usesNeutralStandIn = toastColor === 'neutral' && colorProp == null;
447
456
 
448
457
  /**
449
458
  * Handle close button press
@@ -463,12 +472,13 @@ const ToastClose = forwardRef<View, ToastCloseProps>((props, ref) => {
463
472
  <IconButton
464
473
  ref={ref}
465
474
  variant="ghost"
475
+ color={colorProp ?? toastColor}
466
476
  size={size}
467
477
  aria-label="Close"
468
478
  className={cn(usesNeutralStandIn ? toastCloseRootVariants() : undefined, className)}
469
479
  iconClassName={cn(usesNeutralStandIn ? toastCloseIconVariants() : undefined, iconClassName)}
470
480
  onPress={handlePress}
471
- as={CloseIcon}
481
+ as={as}
472
482
  {...restProps}
473
483
  />
474
484
  );