@skyscanner/backpack-web 31.1.1 → 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.
- package/bpk-component-calendar/src/BpkCalendarContainer.d.ts +3 -0
- package/bpk-component-calendar/src/composeCalendar.d.ts +1 -0
- package/bpk-component-calendar/src/composeCalendar.js +2 -0
- package/bpk-component-card-button/src/BpkSaveButton.js +4 -2
- package/bpk-component-card-button/src/BpkSaveButton.module.css +1 -1
- package/bpk-component-scrollable-calendar/src/BpkScrollableCalendarGridList.d.ts +1 -0
- package/bpk-component-scrollable-calendar/src/BpkScrollableCalendarGridList.js +10 -8
- package/package.json +1 -1
|
@@ -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
|
});
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
import { useState } from 'react';
|
|
20
|
-
import { BpkButtonV2 } from "../../bpk-component-button
|
|
20
|
+
import { BpkButtonV2 } from "../../bpk-component-button";
|
|
21
21
|
// @ts-expect-error Untyped import. See `decisions/imports-ts-suppressions.md`.
|
|
22
22
|
import BpkHeartIcon from "../../bpk-component-icon/lg/heart";
|
|
23
23
|
// @ts-expect-error Untyped import. See `decisions/imports-ts-suppressions.md`.
|
|
@@ -60,8 +60,10 @@ const BpkSaveButton = ({
|
|
|
60
60
|
"aria-label": accessibilityLabel,
|
|
61
61
|
className: getClassName('bpk-save-button', smallSize && 'bpk-save-button__small', `bpk-save-button__${style}`),
|
|
62
62
|
onClick: e => {
|
|
63
|
-
setToggle(true);
|
|
64
63
|
onCheckedChange(e);
|
|
64
|
+
if (!checked) {
|
|
65
|
+
setToggle(true);
|
|
66
|
+
}
|
|
65
67
|
},
|
|
66
68
|
iconOnly: true,
|
|
67
69
|
children: [/*#__PURE__*/_jsx(HeartIcon, {
|
|
@@ -15,4 +15,4 @@
|
|
|
15
15
|
* See the License for the specific language governing permissions and
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/
|
|
18
|
-
@keyframes bpk-keyframe-spin{100%{transform:rotate(1turn)}}@keyframes heart-beat{0%,100%{transform:translate(-50%, -50%) scale(1)}10%{transform:translate(-50%, -50%) scale(1.4)}20%{transform:translate(-50%, -50%) scale(1.2)}30%{transform:translate(-50%, -50%) scale(1.3)}50%{transform:translate(-50%, -50%) scale(1.25)}70%{transform:translate(-50%, -50%) scale(1.25)}}.bpk-save-button{position:relative;width:2.5rem;height:2.5rem;padding:0.5rem;border-radius:50%;background-color:transparent}.bpk-no-touch-support .bpk-save-button:hover:not(:active):not(:disabled){background-color:transparent}:global(.bpk-no-touch-support) .bpk-save-button:hover:not(:active):not(:disabled){background-color:transparent}.bpk-save-button:active{background-color:transparent}.bpk-save-button__icon{position:absolute;top:50%;left:50%;transform:translate(-50%, -50%);color:#161616}.bpk-save-button__icon:hover{color:#161616}.bpk-save-button__heartOutlineIcon{z-index:1;opacity:1}.bpk-save-button__heartOutlineIcon--show:hover{transition:opacity 200ms ease-in-out;opacity:0}.bpk-save-button__heartOutlineIcon--hide{opacity:0}.bpk-save-button__heartOutlineIcon--onDark{color:#fff}.bpk-save-button__heartIcon{z-index:2;color:#0062e3;opacity:0}.bpk-save-button__heartIcon--toggle{animation:heart-beat 1s 0s 1 ease-out;animation-fill-mode:forwards}.bpk-save-button__heartIcon--show{opacity:1}.bpk-save-button__heartIcon--show:hover{color:#0062e3}.bpk-save-button__heartIcon--hide:hover{transition:opacity 200ms ease-in-out;color:#161616;opacity:1}.bpk-save-button__heartIcon--onDark{color:#fff}.bpk-save-button__heartIcon--onDark:hover{color:#fff}.bpk-save-button__small{width:2rem;height:2rem;min-height:2rem}.bpk-save-button__contained{background-color:rgba(255,255,255,0.8)}.bpk-no-touch-support .bpk-save-button__contained:hover:not(:active):not(:disabled){background-color:rgba(255,255,255,0.8)}:global(.bpk-no-touch-support) .bpk-save-button__contained:hover:not(:active):not(:disabled){background-color:rgba(255,255,255,0.8)}.bpk-save-button__contained:active{background-color:rgba(255,255,255,0.8)}
|
|
18
|
+
@keyframes bpk-keyframe-spin{100%{transform:rotate(1turn)}}@keyframes heart-beat{0%,100%{transform:translate(-50%, -50%) scale(1)}10%{transform:translate(-50%, -50%) scale(1.4)}20%{transform:translate(-50%, -50%) scale(1.2)}30%{transform:translate(-50%, -50%) scale(1.3)}50%{transform:translate(-50%, -50%) scale(1.25)}70%{transform:translate(-50%, -50%) scale(1.25)}}.bpk-save-button{position:relative;width:2.5rem;height:2.5rem;padding:0.5rem;border-radius:50%;background-color:transparent}.bpk-no-touch-support .bpk-save-button:hover:not(:active):not(:disabled){background-color:transparent}:global(.bpk-no-touch-support) .bpk-save-button:hover:not(:active):not(:disabled){background-color:transparent}.bpk-save-button:active{background-color:transparent}.bpk-save-button__icon{position:absolute;top:50%;left:50%;transform:translate(-50%, -50%);color:#161616}.bpk-no-touch-support .bpk-save-button__icon:hover:not(:active):not(:disabled){color:#161616}:global(.bpk-no-touch-support) .bpk-save-button__icon:hover:not(:active):not(:disabled){color:#161616}.bpk-save-button__heartOutlineIcon{z-index:1;opacity:1}.bpk-no-touch-support .bpk-save-button__heartOutlineIcon--show:hover:not(:active):not(:disabled){transition:opacity 200ms ease-in-out;opacity:0}:global(.bpk-no-touch-support) .bpk-save-button__heartOutlineIcon--show:hover:not(:active):not(:disabled){transition:opacity 200ms ease-in-out;opacity:0}.bpk-save-button__heartOutlineIcon--hide{opacity:0}.bpk-save-button__heartOutlineIcon--onDark{color:#fff}.bpk-save-button__heartIcon{z-index:2;color:#0062e3;opacity:0}.bpk-save-button__heartIcon--toggle{animation:heart-beat 1s 0s 1 ease-out;animation-fill-mode:forwards}.bpk-save-button__heartIcon--show{opacity:1}.bpk-no-touch-support .bpk-save-button__heartIcon--show:hover:not(:active):not(:disabled){color:#0062e3}:global(.bpk-no-touch-support) .bpk-save-button__heartIcon--show:hover:not(:active):not(:disabled){color:#0062e3}.bpk-no-touch-support .bpk-save-button__heartIcon--hide:hover:not(:active):not(:disabled){transition:opacity 200ms ease-in-out;color:#161616;opacity:1}:global(.bpk-no-touch-support) .bpk-save-button__heartIcon--hide:hover:not(:active):not(:disabled){transition:opacity 200ms ease-in-out;color:#161616;opacity:1}.bpk-save-button__heartIcon--onDark{color:#fff}.bpk-no-touch-support .bpk-save-button__heartIcon--onDark:hover:not(:active):not(:disabled){color:#fff}:global(.bpk-no-touch-support) .bpk-save-button__heartIcon--onDark:hover:not(:active):not(:disabled){color:#fff}.bpk-save-button__small{width:2rem;height:2rem;min-height:2rem}.bpk-save-button__contained{background-color:rgba(255,255,255,0.8)}.bpk-no-touch-support .bpk-save-button__contained:hover:not(:active):not(:disabled){background-color:rgba(255,255,255,0.8)}:global(.bpk-no-touch-support) .bpk-save-button__contained:hover:not(:active):not(:disabled){background-color:rgba(255,255,255,0.8)}.bpk-save-button__contained:active{background-color:rgba(255,255,255,0.8)}
|
|
@@ -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,
|
|
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] ||
|
|
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:
|
|
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:
|
|
119
|
+
estimatedItemSize: estimatedMonthItemHeight,
|
|
118
120
|
itemSize: getItemSize,
|
|
119
121
|
itemCount: months.length,
|
|
120
122
|
overscanCount: 1,
|