@skyscanner/backpack-web 35.0.1 → 35.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.
@@ -1,5 +1,5 @@
1
1
  import { Component } from 'react';
2
- import type { ReactElement } from 'react';
2
+ import type { ReactElement, RefObject } from 'react';
3
3
  import type { DaysOfWeek, ReactComponent, SelectionConfiguration } from '../../bpk-component-calendar';
4
4
  type Props = {
5
5
  changeMonthLabel: string;
@@ -49,7 +49,9 @@ type State = {
49
49
  isOpen: boolean;
50
50
  };
51
51
  declare class BpkDatepicker extends Component<Props, State> {
52
- inputRef: React.RefObject<HTMLInputElement>;
52
+ inputRef: (ref: HTMLInputElement) => void;
53
+ elementRef?: HTMLInputElement;
54
+ focusRef?: RefObject<HTMLInputElement>;
53
55
  static defaultProps: {
54
56
  calendarComponent: {
55
57
  new (props: Omit<import("../../bpk-component-calendar/src/composeCalendar").Props & import("../../bpk-component-calendar/src/BpkCalendarContainer").Props, keyof {
@@ -22,6 +22,7 @@ import { composeCalendar, BpkCalendarGridHeader, BpkCalendarGrid, BpkCalendarDat
22
22
  import BpkInput, { withOpenEvents } from "../../bpk-component-input";
23
23
  import BpkModal from "../../bpk-component-modal";
24
24
  import BpkPopover from "../../bpk-component-popover";
25
+ import { setNativeValue } from "../../bpk-react-utils";
25
26
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
26
27
  const Input = withOpenEvents(BpkInput);
27
28
  const DefaultCalendar = withCalendarState(composeCalendar(BpkCalendarNav, BpkCalendarGridHeader, BpkCalendarGrid, BpkCalendarDate));
@@ -55,7 +56,10 @@ class BpkDatepicker extends Component {
55
56
  this.state = {
56
57
  isOpen: props.isOpen
57
58
  };
58
- this.inputRef = /*#__PURE__*/createRef();
59
+ this.focusRef = /*#__PURE__*/createRef();
60
+ this.inputRef = ref => {
61
+ this.elementRef = ref;
62
+ };
59
63
  }
60
64
  componentDidUpdate(prevProps, prevState) {
61
65
  const {
@@ -147,7 +151,9 @@ class BpkDatepicker extends Component {
147
151
  const newEndDate = DateUtils.dateToBoundaries(endDate, DateUtils.startOfDay(minDate), DateUtils.startOfDay(maxDate));
148
152
  if (selectionConfiguration && selectionConfiguration.type === CALENDAR_SELECTION_TYPE.range && selectionConfiguration.startDate && !selectionConfiguration.endDate && (DateUtils.isAfter(newEndDate, selectionConfiguration.startDate) || DateUtils.isSameDay(newEndDate, selectionConfiguration.startDate))) {
149
153
  onDateSelect(selectionConfiguration.startDate, newEndDate);
154
+ this.elementRef && setNativeValue(this.elementRef, this.props.formatDate(newEndDate));
150
155
  } else {
156
+ this.elementRef && setNativeValue(this.elementRef, this.props.formatDate(newStartDate));
151
157
  onDateSelect(newStartDate);
152
158
  }
153
159
  }
@@ -188,8 +194,9 @@ class BpkDatepicker extends Component {
188
194
  delete rest.onOpenChange;
189
195
  delete rest.isOpen;
190
196
  const input = inputComponent || /*#__PURE__*/_jsx("div", {
191
- ref: this.inputRef,
197
+ ref: this.focusRef,
192
198
  children: /*#__PURE__*/_jsx(Input, {
199
+ inputRef: this.inputRef,
193
200
  id: id,
194
201
  name: `${id}_input`,
195
202
  value: this.getValue(selectionConfiguration, formatDate),
@@ -0,0 +1,3 @@
1
+ import BpkNavigationTabGroup, { type Props as BpkNavigationTabGroupProps } from './src/BpkNavigationTabGroup';
2
+ export type { BpkNavigationTabGroupProps };
3
+ export default BpkNavigationTabGroup;
@@ -0,0 +1,20 @@
1
+ /*
2
+ * Backpack - Skyscanner's Design System
3
+ *
4
+ * Copyright 2016 Skyscanner Ltd
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ import BpkNavigationTabGroup from "./src/BpkNavigationTabGroup";
20
+ export default BpkNavigationTabGroup;
@@ -0,0 +1,23 @@
1
+ import type { MouseEvent, FunctionComponent } from 'react';
2
+ export declare const NAVIGATION_TAB_GROUP_TYPES: {
3
+ CanvasDefault: string;
4
+ SurfaceContrast: string;
5
+ };
6
+ export type NavigationTabGroupTypes = (typeof NAVIGATION_TAB_GROUP_TYPES)[keyof typeof NAVIGATION_TAB_GROUP_TYPES];
7
+ type TabItem = {
8
+ id: string;
9
+ text: string;
10
+ icon?: FunctionComponent<any> | null;
11
+ href?: string;
12
+ [rest: string]: any;
13
+ };
14
+ export type Props = {
15
+ id: string;
16
+ tabs: TabItem[];
17
+ type?: NavigationTabGroupTypes;
18
+ onItemClick: (e: MouseEvent<HTMLButtonElement | HTMLAnchorElement>, tab: TabItem, index: number) => void;
19
+ selectedIndex: number;
20
+ ariaLabel: string;
21
+ };
22
+ declare const BpkNavigationTabGroup: ({ ariaLabel, id, onItemClick, selectedIndex, tabs, type, }: Props) => import("react/jsx-runtime").JSX.Element;
23
+ export default BpkNavigationTabGroup;
@@ -0,0 +1,99 @@
1
+ /*
2
+ * Backpack - Skyscanner's Design System
3
+ *
4
+ * Copyright 2016 Skyscanner Ltd
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ import { useState } from 'react';
20
+ import BpkText, { TEXT_STYLES } from "../../bpk-component-text";
21
+ import { cssModules } from "../../bpk-react-utils";
22
+ import STYLES from "./BpkNavigationTabGroup.module.css";
23
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
24
+ const getClassName = cssModules(STYLES);
25
+ export const NAVIGATION_TAB_GROUP_TYPES = {
26
+ CanvasDefault: 'canvas-default',
27
+ SurfaceContrast: 'surface-contrast'
28
+ };
29
+ const TabWrap = ({
30
+ children,
31
+ onClick,
32
+ selected,
33
+ tab,
34
+ type
35
+ }) => {
36
+ const tabStyling = getClassName('bpk-navigation-tab-wrap', `bpk-navigation-tab-wrap--${type}`, selected && `bpk-navigation-tab-wrap--${type}-selected`);
37
+ return tab.href ? /*#__PURE__*/_jsx("a", {
38
+ ...tab,
39
+ id: tab.id,
40
+ className: tabStyling,
41
+ href: tab.href,
42
+ onClick: e => onClick(e),
43
+ "aria-current": selected ? 'page' : false,
44
+ children: children
45
+ }) : /*#__PURE__*/_jsx("button", {
46
+ ...tab,
47
+ id: tab.id,
48
+ className: tabStyling,
49
+ type: "button",
50
+ onClick: e => onClick(e),
51
+ role: "link",
52
+ "aria-current": selected ? 'page' : false,
53
+ children: children
54
+ });
55
+ };
56
+ const BpkNavigationTabGroup = ({
57
+ ariaLabel,
58
+ id,
59
+ onItemClick,
60
+ selectedIndex,
61
+ tabs,
62
+ type = NAVIGATION_TAB_GROUP_TYPES.SurfaceContrast
63
+ }) => {
64
+ const [selectedTab, setSelectedTab] = useState(selectedIndex);
65
+ const handleButtonClick = (e, tab, index) => {
66
+ if (index !== selectedTab) {
67
+ setSelectedTab(index);
68
+ }
69
+ onItemClick(e, tab, index);
70
+ };
71
+ const containerStyling = getClassName('bpk-navigation-tab-group');
72
+ return /*#__PURE__*/_jsx("nav", {
73
+ id: id,
74
+ className: containerStyling,
75
+ role: "navigation",
76
+ "aria-label": ariaLabel,
77
+ children: tabs.map((tab, index) => {
78
+ const selected = index === selectedTab;
79
+ const Icon = tab.icon;
80
+ return /*#__PURE__*/_jsx(TabWrap, {
81
+ tab: tab,
82
+ selected: selected,
83
+ onClick: e => handleButtonClick(e, tab, index),
84
+ type: type,
85
+ children: /*#__PURE__*/_jsxs(_Fragment, {
86
+ children: [Icon && /*#__PURE__*/_jsx("span", {
87
+ className: getClassName('bpk-navigation-tab-icon', `bpk-navigation-tab-icon--${type}`, selected && `bpk-navigation-tab-icon--${type}-selected`),
88
+ children: /*#__PURE__*/_jsx(Icon, {})
89
+ }), /*#__PURE__*/_jsx(BpkText, {
90
+ tagName: "span",
91
+ textStyle: TEXT_STYLES.label2,
92
+ children: tab.text
93
+ })]
94
+ })
95
+ }, `index-${index.toString()}`);
96
+ })
97
+ });
98
+ };
99
+ export default BpkNavigationTabGroup;
@@ -0,0 +1,18 @@
1
+ /*
2
+ * Backpack - Skyscanner's Design System
3
+ *
4
+ * Copyright 2016 Skyscanner Ltd
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+ .bpk-navigation-tab-group{display:flex}.bpk-navigation-tab-group .bpk-navigation-tab-wrap{height:2.25rem;padding:0 1rem;border:none;border-radius:6.25rem;margin-inline-end:.25rem;display:flex;align-items:center;text-decoration:none;white-space:nowrap}.bpk-navigation-tab-group .bpk-navigation-tab-wrap--surface-contrast{background-color:rgba(0,0,0,0);color:#fff;box-shadow:0 0 0 1px #c1c7cf inset}.bpk-navigation-tab-group .bpk-navigation-tab-wrap--surface-contrast:hover{background-color:#154679;box-shadow:0 0 0 1px #154679 inset}.bpk-navigation-tab-group .bpk-navigation-tab-wrap--surface-contrast-selected{background-color:#0062e3;box-shadow:0 0 0 1px #0062e3 inset}.bpk-navigation-tab-group .bpk-navigation-tab-wrap--surface-contrast-selected:hover{background-color:#0062e3;box-shadow:0 0 0 1px #0062e3 inset}.bpk-navigation-tab-group .bpk-navigation-tab-wrap--canvas-default{background-color:rgba(0,0,0,0);color:#161616;box-shadow:0 0 0 1px #c1c7cf inset}.bpk-navigation-tab-group .bpk-navigation-tab-wrap--canvas-default:hover{color:#161616;box-shadow:0 0 0 1px #161616 inset}.bpk-navigation-tab-group .bpk-navigation-tab-wrap--canvas-default-selected{background-color:#0062e3;color:#fff;box-shadow:0 0 0 1px #0062e3 inset}.bpk-navigation-tab-group .bpk-navigation-tab-wrap--canvas-default-selected:hover{background-color:#0062e3;color:#fff;box-shadow:0 0 0 1px #0062e3 inset}.bpk-navigation-tab-group .bpk-navigation-tab-icon{height:1rem;margin-inline-end:.5rem}.bpk-navigation-tab-group .bpk-navigation-tab-icon--surface-contrast{fill:#fff}.bpk-navigation-tab-group .bpk-navigation-tab-icon--canvas-default-selected{fill:#fff}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skyscanner/backpack-web",
3
- "version": "35.0.1",
3
+ "version": "35.2.0",
4
4
  "description": "Backpack Design System web library",
5
5
  "repository": {
6
6
  "type": "git",