@skyscanner/backpack-web 35.0.1 → 35.1.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-navigation-tab-group/index.d.ts +3 -0
- package/bpk-component-navigation-tab-group/index.js +20 -0
- package/bpk-component-navigation-tab-group/src/BpkNavigationTabGroup.d.ts +20 -0
- package/bpk-component-navigation-tab-group/src/BpkNavigationTabGroup.js +93 -0
- package/bpk-component-navigation-tab-group/src/BpkNavigationTabGroup.module.css +18 -0
- package/package.json +1 -1
|
@@ -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,20 @@
|
|
|
1
|
+
import type { 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
|
+
text: string;
|
|
9
|
+
icon?: FunctionComponent<any> | null;
|
|
10
|
+
href?: string;
|
|
11
|
+
};
|
|
12
|
+
export type Props = {
|
|
13
|
+
tabs: TabItem[];
|
|
14
|
+
type?: NavigationTabGroupTypes;
|
|
15
|
+
onItemClick: (tab: TabItem, index: number) => void;
|
|
16
|
+
selectedIndex: number;
|
|
17
|
+
ariaLabel: string;
|
|
18
|
+
};
|
|
19
|
+
declare const BpkNavigationTabGroup: ({ ariaLabel, onItemClick, selectedIndex, tabs, type, }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
20
|
+
export default BpkNavigationTabGroup;
|
|
@@ -0,0 +1,93 @@
|
|
|
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
|
+
className: tabStyling,
|
|
39
|
+
href: tab.href,
|
|
40
|
+
onClick: onClick,
|
|
41
|
+
"aria-current": selected ? 'page' : false,
|
|
42
|
+
children: children
|
|
43
|
+
}) : /*#__PURE__*/_jsx("button", {
|
|
44
|
+
className: tabStyling,
|
|
45
|
+
type: "button",
|
|
46
|
+
onClick: onClick,
|
|
47
|
+
"aria-current": selected ? 'page' : false,
|
|
48
|
+
role: "link",
|
|
49
|
+
children: children
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
const BpkNavigationTabGroup = ({
|
|
53
|
+
ariaLabel,
|
|
54
|
+
onItemClick,
|
|
55
|
+
selectedIndex,
|
|
56
|
+
tabs,
|
|
57
|
+
type = NAVIGATION_TAB_GROUP_TYPES.SurfaceContrast
|
|
58
|
+
}) => {
|
|
59
|
+
const [selectedTab, setSelectedTab] = useState(selectedIndex);
|
|
60
|
+
const handleButtonClick = (tab, index) => {
|
|
61
|
+
if (index !== selectedTab) {
|
|
62
|
+
setSelectedTab(index);
|
|
63
|
+
}
|
|
64
|
+
onItemClick(tab, index);
|
|
65
|
+
};
|
|
66
|
+
const containerStyling = getClassName('bpk-navigation-tab-group');
|
|
67
|
+
return /*#__PURE__*/_jsx("nav", {
|
|
68
|
+
className: containerStyling,
|
|
69
|
+
role: "navigation",
|
|
70
|
+
"aria-label": ariaLabel,
|
|
71
|
+
children: tabs.map((tab, index) => {
|
|
72
|
+
const selected = index === selectedTab;
|
|
73
|
+
const Icon = tab.icon;
|
|
74
|
+
return /*#__PURE__*/_jsx(TabWrap, {
|
|
75
|
+
tab: tab,
|
|
76
|
+
selected: selected,
|
|
77
|
+
onClick: () => handleButtonClick(tab, index),
|
|
78
|
+
type: type,
|
|
79
|
+
children: /*#__PURE__*/_jsxs(_Fragment, {
|
|
80
|
+
children: [Icon && /*#__PURE__*/_jsx("span", {
|
|
81
|
+
className: getClassName('bpk-navigation-tab-icon', `bpk-navigation-tab-icon--${type}`, selected && `bpk-navigation-tab-icon--${type}-selected`),
|
|
82
|
+
children: /*#__PURE__*/_jsx(Icon, {})
|
|
83
|
+
}), /*#__PURE__*/_jsx(BpkText, {
|
|
84
|
+
tagName: "span",
|
|
85
|
+
textStyle: TEXT_STYLES.label2,
|
|
86
|
+
children: tab.text
|
|
87
|
+
})]
|
|
88
|
+
})
|
|
89
|
+
}, `index-${index.toString()}`);
|
|
90
|
+
})
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
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}
|