@skyscanner/backpack-web 31.1.2 → 31.2.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.
@@ -41,6 +41,7 @@ export type Props = {
41
41
  initiallyFocusedDate?: Date | null;
42
42
  markToday?: boolean;
43
43
  markOutsideDays?: boolean;
44
+ customRowHeight?: number;
44
45
  };
45
46
  type InjectedProps = {
46
47
  onDateClick: ((date: Date) => void) | null;
@@ -105,6 +106,7 @@ declare const withCalendarState: <P extends object>(Calendar: ComponentType<P>)
105
106
  initiallyFocusedDate: null;
106
107
  markToday: boolean;
107
108
  markOutsideDays: boolean;
109
+ customRowHeight?: number;
108
110
  };
109
111
  contextType?: import("react").Context<any> | undefined;
110
112
  };
@@ -157,6 +159,7 @@ declare const _default: {
157
159
  initiallyFocusedDate: null;
158
160
  markToday: boolean;
159
161
  markOutsideDays: boolean;
162
+ customRowHeight?: number;
160
163
  };
161
164
  contextType?: import("react").Context<any> | undefined;
162
165
  };
@@ -71,6 +71,7 @@ export type Props = {
71
71
  preventKeyboardFocus?: boolean;
72
72
  selectionConfiguration?: SelectionConfiguration;
73
73
  gridClassName?: string | null;
74
+ customRowHeight?: number;
74
75
  /**
75
76
  * Key to be used to pick the desired weekDay format from the `daysOfWeek` object, for example: `nameAbbr` or `nameNarrow`.
76
77
  */
@@ -26,6 +26,7 @@ const composeCalendar = (Nav, GridHeader, Grid, CalendarDate) => {
26
26
  const BpkCalendar = ({
27
27
  changeMonthLabel = null,
28
28
  className = null,
29
+ customRowHeight,
29
30
  dateModifiers = {},
30
31
  dateProps = {},
31
32
  daysOfWeek,
@@ -116,6 +117,7 @@ const composeCalendar = (Nav, GridHeader, Grid, CalendarDate) => {
116
117
  className: gridClasses.join(' '),
117
118
  dateProps: dateProps,
118
119
  selectionConfiguration: selectionConfiguration,
120
+ customRowHeight: customRowHeight,
119
121
  ...gridProps
120
122
  })]
121
123
  });
@@ -29,6 +29,7 @@ type Props = Partial<BpkCalendarGridProps> & {
29
29
  focusedDate?: Date | null;
30
30
  selectionConfiguration?: SelectionConfiguration;
31
31
  className?: string | null;
32
+ customRowHeight?: number;
32
33
  };
33
34
  declare const BpkScrollableCalendarGridList: (props: Props) => JSX.Element;
34
35
  export default BpkScrollableCalendarGridList;
@@ -29,20 +29,17 @@ import { jsx as _jsx } from "react/jsx-runtime";
29
29
  const getClassName = cssModules(STYLES);
30
30
 
31
31
  // These constants are here to facilitate calculating the height
32
- // Row and month item heights are defined in rem to support text scaling
33
- const ROW_HEIGHT = 2.75;
34
32
  // This is the additional height of each grid without any rows.
35
33
  const BASE_MONTH_ITEM_HEIGHT = 8.125;
36
34
  const COLUMN_COUNT = 7;
37
35
  // Most browsers have by default 16px root font size
38
36
  const DEFAULT_ROOT_FONT_SIZE = 16;
39
- // Most calendar grids have 5 rows. Calculate height in px as this is what react-window expects.
40
- const ESTIMATED_MONTH_ITEM_HEIGHT = (BASE_MONTH_ITEM_HEIGHT + 5 * ROW_HEIGHT) * DEFAULT_ROOT_FONT_SIZE;
41
37
  // Minimum month item width (useful for server-side rendering. This value will be overridden with an accurate width after mounting)
42
38
  const ESTIMATED_MONTH_ITEM_WIDTH = BASE_MONTH_ITEM_HEIGHT * 7 * DEFAULT_ROOT_FONT_SIZE;
43
39
  const BpkScrollableCalendarGridList = props => {
44
40
  const {
45
41
  className = null,
42
+ customRowHeight = 2.75,
46
43
  focusedDate = null,
47
44
  minDate,
48
45
  selectionConfiguration,
@@ -52,13 +49,18 @@ const BpkScrollableCalendarGridList = props => {
52
49
  const startDate = startOfDay(startOfMonth(minDate));
53
50
  const endDate = startOfDay(startOfMonth(rest.maxDate));
54
51
  const monthsCount = DateUtils.differenceInCalendarMonths(endDate, startDate);
52
+
53
+ // Row and month item heights are defined in rem to support text scaling
54
+ const rowHeight = customRowHeight;
55
+ // Most calendar grids have 5 rows. Calculate height in px as this is what react-window expects.
56
+ const estimatedMonthItemHeight = (BASE_MONTH_ITEM_HEIGHT + 5 * rowHeight) * DEFAULT_ROOT_FONT_SIZE;
55
57
  const getInitialRootFontSize = () => parseFloat(getComputedStyle(document.documentElement).fontSize) || DEFAULT_ROOT_FONT_SIZE;
56
58
 
57
59
  // The `react-window` API requires the height in pixels to be specified
58
60
  // To be able to scale text size, we use rem and then we get the root font size so that we can calculate the final value in px
59
61
  const [rootFontSize, setRootFontSize] = useState(getInitialRootFontSize);
60
62
  const months = useMemo(() => getMonthsArray(startDate, monthsCount), [minDate, monthsCount]);
61
- const monthItemHeights = useMemo(() => getMonthItemHeights(months, rest.weekStartsOn, COLUMN_COUNT, ROW_HEIGHT * rootFontSize, BASE_MONTH_ITEM_HEIGHT * rootFontSize), [rootFontSize, months, rest.weekStartsOn]);
63
+ const monthItemHeights = useMemo(() => getMonthItemHeights(months, rest.weekStartsOn, COLUMN_COUNT, rowHeight * rootFontSize, BASE_MONTH_ITEM_HEIGHT * rootFontSize), [rootFontSize, months, rest.weekStartsOn]);
62
64
  useEffect(() => {
63
65
  // this is required by the react-window library in order to re-render the list whenever an item's size changes
64
66
  if (listRef.current) {
@@ -66,7 +68,7 @@ const BpkScrollableCalendarGridList = props => {
66
68
  }
67
69
  }, [monthItemHeights]);
68
70
  const getHtmlElement = () => typeof document !== 'undefined' ? document.querySelector('html') : {};
69
- const getItemSize = index => monthItemHeights[index] || ESTIMATED_MONTH_ITEM_HEIGHT;
71
+ const getItemSize = index => monthItemHeights[index] || estimatedMonthItemHeight;
70
72
  const rowRenderer = ({
71
73
  index,
72
74
  style
@@ -103,7 +105,7 @@ const BpkScrollableCalendarGridList = props => {
103
105
  className: getClassName('bpk-scrollable-calendar-grid-list', className),
104
106
  children: /*#__PURE__*/_jsx(AutoSizer, {
105
107
  onResize: onResize,
106
- defaultHeight: ESTIMATED_MONTH_ITEM_HEIGHT,
108
+ defaultHeight: estimatedMonthItemHeight,
107
109
  defaultWidth: ESTIMATED_MONTH_ITEM_WIDTH,
108
110
  children: ({
109
111
  height,
@@ -114,7 +116,7 @@ const BpkScrollableCalendarGridList = props => {
114
116
  } : {},
115
117
  width: width,
116
118
  height: height,
117
- estimatedItemSize: ESTIMATED_MONTH_ITEM_HEIGHT,
119
+ estimatedItemSize: estimatedMonthItemHeight,
118
120
  itemSize: getItemSize,
119
121
  itemCount: months.length,
120
122
  overscanCount: 1,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skyscanner/backpack-web",
3
- "version": "31.1.2",
3
+ "version": "31.2.0",
4
4
  "description": "Backpack Design System web library",
5
5
  "repository": {
6
6
  "type": "git",