@skyscanner/backpack-web 34.7.1 → 34.8.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.
@@ -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 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:.5rem;border:0;border-radius:50%;background-color:rgba(0,0,0,0)}.bpk-save-button__icon{position:absolute;top:50%;left:50%;display:flex;transform:translate(-50%, -50%)}.bpk-save-button__heartOutlineIcon{z-index:1;opacity:1;composes:bpk-save-button__icon}.bpk-no-touch-support .bpk-save-button__heartOutlineIcon[data-show=true]:hover:not(:active):not(:disabled){transition:opacity 200ms ease-in-out;opacity:0}:global(.bpk-no-touch-support) .bpk-save-button__heartOutlineIcon[data-show=true]:hover:not(:active):not(:disabled){transition:opacity 200ms ease-in-out;opacity:0}.bpk-save-button__heartOutlineIcon[data-show=false]{opacity:0}.bpk-save-button__heartIcon{z-index:2;opacity:0;composes:bpk-save-button__icon}.bpk-save-button__heartIcon[data-show=true]{opacity:1}.bpk-no-touch-support .bpk-save-button__heartIcon[data-show=false]:hover:not(:active):not(:disabled){transition:opacity 200ms ease-in-out;opacity:1}:global(.bpk-no-touch-support) .bpk-save-button__heartIcon[data-show=false]:hover:not(:active):not(:disabled){transition:opacity 200ms ease-in-out;opacity:1}.bpk-save-button__heartIcon--clicked{animation:heart-beat 1s 0s 1 ease-out;animation-fill-mode:forwards}.bpk-save-button__heartIcon--onDark{fill:#fff}.bpk-no-touch-support .bpk-save-button__heartIcon--onDark:hover:not(:active):not(:disabled){fill:#fff}:global(.bpk-no-touch-support) .bpk-save-button__heartIcon--onDark:hover:not(:active):not(:disabled){fill:#fff}.bpk-save-button__heartIcon--default,.bpk-save-button__heartIcon--contained{fill:#0062e3}.bpk-no-touch-support .bpk-save-button__heartIcon--default:hover:not(:active):not(:disabled),.bpk-no-touch-support .bpk-save-button__heartIcon--contained:hover:not(:active):not(:disabled){fill:#161616}.bpk-no-touch-support .bpk-save-button__heartIcon--default:hover:not(:active):not(:disabled)[data-show=true],.bpk-no-touch-support .bpk-save-button__heartIcon--contained:hover:not(:active):not(:disabled)[data-show=true]{fill:#0062e3}:global(.bpk-no-touch-support) .bpk-save-button__heartIcon--default:hover:not(:active):not(:disabled),:global(.bpk-no-touch-support) .bpk-save-button__heartIcon--contained:hover:not(:active):not(:disabled){fill:#161616}:global(.bpk-no-touch-support) .bpk-save-button__heartIcon--default:hover:not(:active):not(:disabled)[data-show=true],:global(.bpk-no-touch-support) .bpk-save-button__heartIcon--contained:hover:not(:active):not(:disabled)[data-show=true]{fill:#0062e3}.bpk-save-button__small{width:2rem;height:2rem;min-height:2rem}.bpk-save-button__contained{background-color:rgba(255,255,255,.8)}
18
+ @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:.5rem;border:0;border-radius:50%;background-color:rgba(0,0,0,0);cursor:pointer}.bpk-save-button__icon{position:absolute;top:50%;left:50%;display:flex;transform:translate(-50%, -50%)}.bpk-save-button__heartOutlineIcon{z-index:1;opacity:1;composes:bpk-save-button__icon}.bpk-no-touch-support .bpk-save-button__heartOutlineIcon[data-show=true]:hover:not(:active):not(:disabled){transition:opacity 200ms ease-in-out;opacity:0}:global(.bpk-no-touch-support) .bpk-save-button__heartOutlineIcon[data-show=true]:hover:not(:active):not(:disabled){transition:opacity 200ms ease-in-out;opacity:0}.bpk-save-button__heartOutlineIcon[data-show=false]{opacity:0}.bpk-save-button__heartIcon{z-index:2;opacity:0;composes:bpk-save-button__icon}.bpk-save-button__heartIcon[data-show=true]{opacity:1}.bpk-no-touch-support .bpk-save-button__heartIcon[data-show=false]:hover:not(:active):not(:disabled){transition:opacity 200ms ease-in-out;opacity:1}:global(.bpk-no-touch-support) .bpk-save-button__heartIcon[data-show=false]:hover:not(:active):not(:disabled){transition:opacity 200ms ease-in-out;opacity:1}.bpk-save-button__heartIcon--clicked{animation:heart-beat 1s 0s 1 ease-out;animation-fill-mode:forwards}.bpk-save-button__heartIcon--onDark{fill:#fff}.bpk-no-touch-support .bpk-save-button__heartIcon--onDark:hover:not(:active):not(:disabled){fill:#fff}:global(.bpk-no-touch-support) .bpk-save-button__heartIcon--onDark:hover:not(:active):not(:disabled){fill:#fff}.bpk-save-button__heartIcon--default,.bpk-save-button__heartIcon--contained{fill:#0062e3}.bpk-no-touch-support .bpk-save-button__heartIcon--default:hover:not(:active):not(:disabled),.bpk-no-touch-support .bpk-save-button__heartIcon--contained:hover:not(:active):not(:disabled){fill:#161616}.bpk-no-touch-support .bpk-save-button__heartIcon--default:hover:not(:active):not(:disabled)[data-show=true],.bpk-no-touch-support .bpk-save-button__heartIcon--contained:hover:not(:active):not(:disabled)[data-show=true]{fill:#0062e3}:global(.bpk-no-touch-support) .bpk-save-button__heartIcon--default:hover:not(:active):not(:disabled),:global(.bpk-no-touch-support) .bpk-save-button__heartIcon--contained:hover:not(:active):not(:disabled){fill:#161616}:global(.bpk-no-touch-support) .bpk-save-button__heartIcon--default:hover:not(:active):not(:disabled)[data-show=true],:global(.bpk-no-touch-support) .bpk-save-button__heartIcon--contained:hover:not(:active):not(:disabled)[data-show=true]{fill:#0062e3}.bpk-save-button__small{width:2rem;height:2rem;min-height:2rem}.bpk-save-button__contained{background-color:rgba(255,255,255,.8)}
@@ -0,0 +1,5 @@
1
+ import BpkMultiSelectChipGroup, { type MultiSelectProps, type ChipItem, type SingleSelectChipItem, CHIP_COMPONENT, CHIP_GROUP_TYPES } from './src/BpkMultiSelectChipGroup';
2
+ import BpkSingleSelectChipGroup, { type SingleSelectProps } from './src/BpkSingleSelectChipGroup';
3
+ export type { ChipItem, MultiSelectProps, SingleSelectProps, SingleSelectChipItem, };
4
+ export { BpkSingleSelectChipGroup, CHIP_GROUP_TYPES, CHIP_COMPONENT, };
5
+ export default BpkMultiSelectChipGroup;
@@ -0,0 +1,22 @@
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 BpkMultiSelectChipGroup, { CHIP_COMPONENT, CHIP_GROUP_TYPES } from "./src/BpkMultiSelectChipGroup";
20
+ import BpkSingleSelectChipGroup from "./src/BpkSingleSelectChipGroup";
21
+ export { BpkSingleSelectChipGroup, CHIP_GROUP_TYPES, CHIP_COMPONENT };
22
+ export default BpkMultiSelectChipGroup;
@@ -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-chip-group-container{display:flex;margin:0 -0.25rem;align-items:center;white-space:nowrap}.bpk-chip-group{display:flex;margin:0;padding:.25rem;align-items:baseline;border:none;gap:.5rem}.bpk-chip-group--wrap{padding-top:0;padding-bottom:0;flex-wrap:wrap}.bpk-sticky-chip-container:first-child{margin-inline-start:.25rem}.bpk-sticky-chip-container{margin-inline-end:.25rem;padding-inline-end:.5rem;box-shadow:-1px 0 0 0 #c1c7cf inset}html[dir=rtl] .bpk-sticky-chip-container{box-shadow:1px 0 0 0 #c1c7cf inset}.bpk-sticky-chip-container--on-dark{box-shadow:-1px 0 0 0 rgba(255,255,255,.5) inset}html[dir=rtl] .bpk-sticky-chip-container--on-dark{box-shadow:1px 0 0 0 rgba(255,255,255,.5) inset}
@@ -0,0 +1,47 @@
1
+ import type { ReactNode } from 'react';
2
+ import { CHIP_TYPES } from '../../bpk-component-chip';
3
+ export declare const CHIP_GROUP_TYPES: {
4
+ readonly rail: "rail";
5
+ readonly wrap: "wrap";
6
+ };
7
+ export declare const CHIP_COMPONENT: {
8
+ readonly selectable: "selectable";
9
+ readonly dismissible: "dismissible";
10
+ readonly dropdown: "dropdown";
11
+ readonly icon: "icon";
12
+ };
13
+ export type ChipGroupType = (typeof CHIP_GROUP_TYPES)[keyof typeof CHIP_GROUP_TYPES];
14
+ export type ChipStyleType = (typeof CHIP_TYPES)[keyof typeof CHIP_TYPES];
15
+ export type ChipComponentType = (typeof CHIP_COMPONENT)[keyof typeof CHIP_COMPONENT];
16
+ export type SingleSelectChipItem = {
17
+ text: string;
18
+ accessibilityLabel?: string;
19
+ leadingAccessoryView?: ReactNode;
20
+ [rest: string]: any;
21
+ };
22
+ export type ChipItem = {
23
+ component?: ChipComponentType;
24
+ onClick?: (selected: boolean, index: number) => void;
25
+ selected?: boolean;
26
+ hidden?: boolean;
27
+ } & SingleSelectChipItem;
28
+ type CommonProps = {
29
+ label?: string;
30
+ ariaLabel?: string;
31
+ chipStyle?: ChipStyleType;
32
+ chips: ChipItem[];
33
+ ariaMultiselectable?: boolean;
34
+ };
35
+ type RailChipGroupProps = {
36
+ stickyChip?: ChipItem;
37
+ leadingNudgerLabel: string;
38
+ trailingNudgerLabel: string;
39
+ } & CommonProps;
40
+ type WrapChipGroupProps = {} & CommonProps;
41
+ export type MultiSelectProps = (RailChipGroupProps & {
42
+ type: typeof CHIP_GROUP_TYPES.rail;
43
+ } | WrapChipGroupProps & {
44
+ type: typeof CHIP_GROUP_TYPES.wrap;
45
+ });
46
+ declare const BpkMultiSelectChipGroup: (props: MultiSelectProps) => JSX.Element;
47
+ export default BpkMultiSelectChipGroup;
@@ -0,0 +1,186 @@
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 { useRef } from 'react';
20
+ import BpkBreakpoint, { BREAKPOINTS } from "../../bpk-component-breakpoint";
21
+ import BpkSelectableChip, { BpkDismissibleChip, BpkIconChip, BpkDropdownChip, CHIP_TYPES } from "../../bpk-component-chip";
22
+ import FilterIconSm from "../../bpk-component-icon/sm/filter";
23
+ // @ts-expect-error Untyped import. See `decisions/imports-ts-suppressions.md`.
24
+ import BpkMobileScrollContainer from "../../bpk-component-mobile-scroll-container";
25
+ import BpkText, { TEXT_STYLES } from "../../bpk-component-text/src/BpkText";
26
+ import { cssModules } from "../../bpk-react-utils";
27
+ import Nudger, { POSITION } from "./Nudger";
28
+ import STYLES from "./BpkChipGroup.module.css";
29
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
30
+ const getClassName = cssModules(STYLES);
31
+ export const CHIP_GROUP_TYPES = {
32
+ rail: 'rail',
33
+ wrap: 'wrap'
34
+ };
35
+ export const CHIP_COMPONENT = {
36
+ selectable: 'selectable',
37
+ dismissible: 'dismissible',
38
+ dropdown: 'dropdown',
39
+ icon: 'icon'
40
+ };
41
+ const CHIP_COMPONENT_MAP = {
42
+ [CHIP_COMPONENT.selectable]: BpkSelectableChip,
43
+ [CHIP_COMPONENT.dismissible]: BpkDismissibleChip,
44
+ [CHIP_COMPONENT.dropdown]: BpkDropdownChip,
45
+ [CHIP_COMPONENT.icon]: BpkIconChip
46
+ };
47
+ const Chip = ({
48
+ ariaMultiselectable,
49
+ chipIndex,
50
+ chipItem,
51
+ chipStyle
52
+ }) => {
53
+ const {
54
+ accessibilityLabel,
55
+ component = CHIP_COMPONENT.selectable,
56
+ hidden = false,
57
+ leadingAccessoryView = null,
58
+ onClick,
59
+ selected,
60
+ text,
61
+ ...rest
62
+ } = chipItem;
63
+ const Component = CHIP_COMPONENT_MAP[component];
64
+ return hidden ? null : /*#__PURE__*/_jsx(Component, {
65
+ selected: selected ?? false,
66
+ type: chipStyle,
67
+ accessibilityLabel: accessibilityLabel || text,
68
+ onClick: () => {
69
+ if (onClick) {
70
+ onClick(!selected, chipIndex);
71
+ }
72
+ },
73
+ role: ariaMultiselectable ? 'checkbox' : 'radio',
74
+ leadingAccessoryView: leadingAccessoryView,
75
+ ...rest,
76
+ children: text
77
+ });
78
+ };
79
+ const ChipGroupContent = ({
80
+ ariaLabel,
81
+ ariaMultiselectable,
82
+ chipGroupClassNames,
83
+ chipStyle,
84
+ chips,
85
+ label
86
+ }) => /*#__PURE__*/_jsxs("fieldset", {
87
+ className: chipGroupClassNames,
88
+ role: ariaMultiselectable ? 'group' : 'radiogroup',
89
+ children: [ariaLabel && /*#__PURE__*/_jsx("legend", {
90
+ className: "visually-hidden",
91
+ children: ariaLabel
92
+ }), label && /*#__PURE__*/_jsx(BpkText, {
93
+ textStyle: TEXT_STYLES.footnote,
94
+ "aria-hidden": true,
95
+ children: label
96
+ }), chips.map((chip, index) => /*#__PURE__*/_jsx(Chip, {
97
+ chipItem: chip,
98
+ chipStyle: chipStyle,
99
+ ariaMultiselectable: ariaMultiselectable,
100
+ chipIndex: index
101
+ }, chip.text))]
102
+ });
103
+ const RailChipGroup = ({
104
+ ariaLabel,
105
+ ariaMultiselectable = true,
106
+ chipStyle = CHIP_TYPES.default,
107
+ chips,
108
+ label,
109
+ leadingNudgerLabel,
110
+ stickyChip,
111
+ trailingNudgerLabel
112
+ }) => {
113
+ const scrollContainerRef = useRef(null);
114
+ const stickyChipContainerClassnames = getClassName('bpk-sticky-chip-container', `bpk-sticky-chip-container--${chipStyle}`);
115
+ const chipGroupClassNames = getClassName('bpk-chip-group', 'bpk-chip-group--rail');
116
+ return /*#__PURE__*/_jsxs(_Fragment, {
117
+ children: [/*#__PURE__*/_jsx(BpkBreakpoint, {
118
+ query: BREAKPOINTS.ABOVE_TABLET,
119
+ children: /*#__PURE__*/_jsx(Nudger, {
120
+ position: POSITION.leading,
121
+ ariaLabel: leadingNudgerLabel,
122
+ chipStyle: chipStyle,
123
+ scrollContainerRef: scrollContainerRef
124
+ })
125
+ }), stickyChip && /*#__PURE__*/_jsx("div", {
126
+ className: stickyChipContainerClassnames,
127
+ children: /*#__PURE__*/_jsx(BpkBreakpoint, {
128
+ query: BREAKPOINTS.ABOVE_TABLET,
129
+ children: isDesktop => /*#__PURE__*/_jsx(Chip, {
130
+ chipItem: {
131
+ role: 'button',
132
+ component: isDesktop ? CHIP_COMPONENT.selectable : CHIP_COMPONENT.icon,
133
+ leadingAccessoryView: /*#__PURE__*/_jsx(FilterIconSm, {}),
134
+ ...stickyChip
135
+ },
136
+ chipStyle: chipStyle,
137
+ ariaMultiselectable: ariaMultiselectable,
138
+ chipIndex: -1
139
+ })
140
+ })
141
+ }), /*#__PURE__*/_jsx(BpkMobileScrollContainer, {
142
+ scrollerRef: el => {
143
+ scrollContainerRef.current = el;
144
+ },
145
+ children: /*#__PURE__*/_jsx(ChipGroupContent, {
146
+ ariaLabel: ariaLabel,
147
+ ariaMultiselectable: ariaMultiselectable,
148
+ chipGroupClassNames: chipGroupClassNames,
149
+ chipStyle: chipStyle,
150
+ chips: chips,
151
+ label: label
152
+ })
153
+ }), /*#__PURE__*/_jsx(BpkBreakpoint, {
154
+ query: BREAKPOINTS.ABOVE_TABLET,
155
+ children: /*#__PURE__*/_jsx(Nudger, {
156
+ position: POSITION.trailing,
157
+ ariaLabel: trailingNudgerLabel,
158
+ chipStyle: chipStyle,
159
+ scrollContainerRef: scrollContainerRef
160
+ })
161
+ })]
162
+ });
163
+ };
164
+ const WrapChipGroup = ({
165
+ ariaLabel,
166
+ ariaMultiselectable = true,
167
+ chipStyle = CHIP_TYPES.default,
168
+ chips,
169
+ label
170
+ }) => /*#__PURE__*/_jsx(ChipGroupContent, {
171
+ ariaLabel: ariaLabel,
172
+ ariaMultiselectable: ariaMultiselectable,
173
+ chipGroupClassNames: getClassName('bpk-chip-group', 'bpk-chip-group--wrap'),
174
+ chipStyle: chipStyle,
175
+ chips: chips,
176
+ label: label
177
+ });
178
+ const BpkMultiSelectChipGroup = props => /*#__PURE__*/_jsx("div", {
179
+ className: getClassName('bpk-chip-group-container'),
180
+ children: props.type === CHIP_GROUP_TYPES.rail ? /*#__PURE__*/_jsx(RailChipGroup, {
181
+ ...props
182
+ }) : /*#__PURE__*/_jsx(WrapChipGroup, {
183
+ ...props
184
+ })
185
+ });
186
+ export default BpkMultiSelectChipGroup;
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ import { type SingleSelectChipItem, type MultiSelectProps } from './BpkMultiSelectChipGroup';
3
+ export type SingleSelectProps = {
4
+ chips: SingleSelectChipItem[];
5
+ onItemClick?: (item: SingleSelectChipItem, selected: boolean, index: number) => void;
6
+ selectedIndex?: number;
7
+ } & MultiSelectProps;
8
+ declare const BpkSingleSelectChipGroup: ({ chips, onItemClick, selectedIndex, ...rest }: SingleSelectProps) => JSX.Element;
9
+ export default BpkSingleSelectChipGroup;
@@ -0,0 +1,42 @@
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 BpkMultiSelectChipGroup from "./BpkMultiSelectChipGroup";
20
+ import { jsx as _jsx } from "react/jsx-runtime";
21
+ const BpkSingleSelectChipGroup = ({
22
+ chips,
23
+ onItemClick,
24
+ selectedIndex,
25
+ ...rest
26
+ }) => {
27
+ const chipsWithSelection = chips.map((chip, index) => chip && {
28
+ ...chip,
29
+ selected: index === selectedIndex,
30
+ onClick: (selected, clickedIndex) => {
31
+ if (onItemClick) {
32
+ onItemClick(chip, selected, clickedIndex);
33
+ }
34
+ }
35
+ });
36
+ return /*#__PURE__*/_jsx(BpkMultiSelectChipGroup, {
37
+ chips: chipsWithSelection,
38
+ ariaMultiselectable: false,
39
+ ...rest
40
+ });
41
+ };
42
+ export default BpkSingleSelectChipGroup;
@@ -0,0 +1,14 @@
1
+ import { type MutableRefObject } from 'react';
2
+ import type { ChipStyleType } from './BpkMultiSelectChipGroup';
3
+ export declare const POSITION: {
4
+ readonly leading: "leading";
5
+ readonly trailing: "trailing";
6
+ };
7
+ type Props = {
8
+ ariaLabel: string;
9
+ chipStyle?: ChipStyleType;
10
+ scrollContainerRef: MutableRefObject<HTMLElement | null>;
11
+ position: (typeof POSITION)[keyof typeof POSITION];
12
+ };
13
+ declare const Nudger: ({ ariaLabel, chipStyle, position, scrollContainerRef }: Props) => JSX.Element | null;
14
+ export default Nudger;
@@ -0,0 +1,92 @@
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 { useEffect, useState } from 'react';
20
+ import { BpkButtonV2, BUTTON_TYPES } from "../../bpk-component-button";
21
+ import { CHIP_TYPES } from "../../bpk-component-chip";
22
+ import { withButtonAlignment } from "../../bpk-component-icon/index";
23
+ import ArrowLeft from "../../bpk-component-icon/sm/long-arrow-left";
24
+ import ArrowRight from "../../bpk-component-icon/sm/long-arrow-right";
25
+ import { cssModules, isRTL } from "../../bpk-react-utils/index";
26
+ import STYLES from "./Nudger.module.css";
27
+ import { jsx as _jsx } from "react/jsx-runtime";
28
+ const getClassName = cssModules(STYLES);
29
+ const CHIP_STYLE_TO_BUTTON_STYLE = {
30
+ [CHIP_TYPES.default]: BUTTON_TYPES.secondary,
31
+ [CHIP_TYPES.onDark]: BUTTON_TYPES.secondaryOnDark,
32
+ [CHIP_TYPES.onImage]: BUTTON_TYPES.primaryOnDark
33
+ };
34
+ export const POSITION = {
35
+ leading: 'leading',
36
+ trailing: 'trailing'
37
+ };
38
+ const AlignedLeftArrowIcon = withButtonAlignment(ArrowLeft);
39
+ const AlignedRightArrowIcon = withButtonAlignment(ArrowRight);
40
+
41
+ // Chosen based on feeling good with the example stories
42
+ const SCROLL_DISTANCE = 150;
43
+ const Nudger = ({
44
+ ariaLabel,
45
+ chipStyle = CHIP_TYPES.default,
46
+ position,
47
+ scrollContainerRef
48
+ }) => {
49
+ const [show, setShow] = useState(false);
50
+ const [enabled, setEnabled] = useState(false);
51
+ const leading = position === POSITION.leading;
52
+ const rtl = isRTL();
53
+ const isLeft = leading && !rtl || !leading && rtl;
54
+ useEffect(() => {
55
+ const interval = setInterval(() => {
56
+ if (!scrollContainerRef.current) {
57
+ return;
58
+ }
59
+ const {
60
+ offsetWidth,
61
+ scrollLeft,
62
+ scrollWidth
63
+ } = scrollContainerRef.current;
64
+ const scrollValue = rtl ? -Math.floor(scrollLeft) : Math.ceil(scrollLeft);
65
+ const showLeading = scrollValue > 0;
66
+ const showTrailing = scrollValue < scrollWidth - offsetWidth;
67
+ setShow(showLeading || showTrailing);
68
+ setEnabled(leading && showLeading || !leading && showTrailing);
69
+ }, 100);
70
+ return () => clearInterval(interval);
71
+ }, [leading, rtl, scrollContainerRef]);
72
+ const classNames = getClassName('bpk-chip-group-nudger', `bpk-chip-group-nudger--${leading ? "leading" : "trailing"}`);
73
+ return show ? /*#__PURE__*/_jsx("div", {
74
+ className: classNames,
75
+ children: /*#__PURE__*/_jsx(BpkButtonV2, {
76
+ title: ariaLabel,
77
+ type: CHIP_STYLE_TO_BUTTON_STYLE[chipStyle],
78
+ iconOnly: true,
79
+ disabled: !enabled,
80
+ onClick: () => {
81
+ if (scrollContainerRef.current) {
82
+ scrollContainerRef.current.scrollBy({
83
+ left: isLeft ? -SCROLL_DISTANCE : SCROLL_DISTANCE,
84
+ behavior: 'smooth'
85
+ });
86
+ }
87
+ },
88
+ children: isLeft ? /*#__PURE__*/_jsx(AlignedLeftArrowIcon, {}) : /*#__PURE__*/_jsx(AlignedRightArrowIcon, {})
89
+ })
90
+ }) : null;
91
+ };
92
+ export default Nudger;
@@ -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-chip-group-nudger--leading{margin-inline-end:.5rem;margin-inline-start:.25rem}.bpk-chip-group-nudger--trailing{margin-inline-end:.25rem;margin-inline-start:.5rem}
@@ -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
- .bpk-price{display:flex;flex-direction:column;color:#626971}.bpk-price--right{text-align:right}html[dir=rtl] .bpk-price--right{text-align:left}.bpk-price__leading{display:flex;flex-direction:row}.bpk-price__leading--right{display:flex;flex-direction:row-reverse}.bpk-price__previous-price{display:flex;text-decoration-line:line-through}.bpk-price__separator{display:flex;margin:0 .25rem}.bpk-price__column-container{display:flex;flex-direction:column}.bpk-price__price{display:contents;color:#161616;word-break:break-all}.bpk-price__spacing::after{content:"";margin-right:.25rem}html[dir=rtl] .bpk-price__spacing::after{margin-right:unset;margin-left:.25rem}.bpk-price__trailing{display:contents;white-space:nowrap}
18
+ .bpk-price{display:flex;flex-direction:column;color:#626971}.bpk-price--right{text-align:right}html[dir=rtl] .bpk-price--right{text-align:left}.bpk-price__leading{display:flex;flex-direction:row}.bpk-price__leading--right{display:flex;flex-direction:row-reverse}.bpk-price__previous-price{display:flex;color:#e70866;text-decoration-line:line-through}.bpk-price__separator{display:flex;margin:0 .25rem}.bpk-price__column-container{display:flex;flex-direction:column}.bpk-price__price{display:contents;color:#161616;word-break:break-all}.bpk-price__spacing::after{content:"";margin-right:.25rem}html[dir=rtl] .bpk-price__spacing::after{margin-right:unset;margin-left:.25rem}.bpk-price__trailing{display:contents;white-space:nowrap}
@@ -0,0 +1,3 @@
1
+ import BpkSegmentedControl, { type Props as BpkSegmentControlProps } from './src/BpkSegmentedControl';
2
+ export type { BpkSegmentControlProps };
3
+ export default BpkSegmentedControl;
@@ -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 BpkSegmentedControl from "./src/BpkSegmentedControl";
20
+ export default BpkSegmentedControl;
@@ -0,0 +1,17 @@
1
+ import type { ReactNode } from 'react';
2
+ export declare const SEGMENT_TYPES: {
3
+ CanvasDefault: string;
4
+ CanvasContrast: string;
5
+ SurfaceDefault: string;
6
+ SurfaceContrast: string;
7
+ };
8
+ export type SegmentTypes = (typeof SEGMENT_TYPES)[keyof typeof SEGMENT_TYPES];
9
+ export type Props = {
10
+ buttonContents: string[] | ReactNode[];
11
+ type?: SegmentTypes;
12
+ onItemClick: (id: number) => void;
13
+ selectedIndex: number;
14
+ shadow?: boolean;
15
+ };
16
+ declare const BpkSegmentedControl: ({ buttonContents, onItemClick, selectedIndex, shadow, type, }: Props) => JSX.Element;
17
+ export default BpkSegmentedControl;
@@ -0,0 +1,63 @@
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 { cssModules } from "../../bpk-react-utils";
21
+ import STYLES from "./BpkSegmentedControl.module.css";
22
+ import { jsx as _jsx } from "react/jsx-runtime";
23
+ const getClassName = cssModules(STYLES);
24
+ export const SEGMENT_TYPES = {
25
+ CanvasDefault: 'canvas-default',
26
+ CanvasContrast: 'canvas-contrast',
27
+ SurfaceDefault: 'surface-default',
28
+ SurfaceContrast: 'surface-contrast'
29
+ };
30
+ const BpkSegmentedControl = ({
31
+ buttonContents,
32
+ onItemClick,
33
+ selectedIndex,
34
+ shadow = false,
35
+ type = SEGMENT_TYPES.CanvasDefault
36
+ }) => {
37
+ const [selectedButton, setSelectedButton] = useState(selectedIndex);
38
+ const handleButtonClick = id => {
39
+ if (id !== selectedButton) {
40
+ setSelectedButton(id);
41
+ onItemClick(id);
42
+ }
43
+ };
44
+ const containerStyling = getClassName('bpk-segmented-control-group', shadow && 'bpk-segmented-control-group-shadow');
45
+ return /*#__PURE__*/_jsx("div", {
46
+ role: "radiogroup",
47
+ className: containerStyling,
48
+ children: buttonContents.map((content, index) => {
49
+ const isSelected = index === selectedButton;
50
+ const rightOfOption = index === selectedButton + 1;
51
+ const buttonStyling = getClassName('bpk-segmented-control', `bpk-segmented-control--${type}`, isSelected && `bpk-segmented-control--${type}-selected`, rightOfOption && `bpk-segmented-control--${type}-rightOfOption`, shadow && isSelected && `bpk-segmented-control--${type}-selected-shadow`);
52
+ return /*#__PURE__*/_jsx("button", {
53
+ id: index.toString(),
54
+ type: "button",
55
+ onClick: () => handleButtonClick(index),
56
+ className: buttonStyling,
57
+ "aria-pressed": !!isSelected,
58
+ children: content
59
+ }, `index-${index.toString()}`);
60
+ })
61
+ });
62
+ };
63
+ export default BpkSegmentedControl;
@@ -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-segmented-control-group{display:flex;flex-wrap:nowrap;overflow:hidden;border-radius:.5rem}.bpk-segmented-control-group-shadow{box-shadow:0px 1px 3px 0px rgba(37,32,31,.3)}.bpk-segmented-control{min-height:2rem;padding:.5rem 1rem;flex:1;border:none;text-overflow:ellipsis;cursor:pointer;overflow:hidden;font-size:.875rem;line-height:1.25rem;font-weight:700}.bpk-segmented-control--canvas-default{background-color:#eff3f8;color:#161616}.bpk-segmented-control--canvas-default-selected{background-color:#05203c;color:#fff}.bpk-segmented-control--canvas-contrast{background-color:#fff;color:#161616}.bpk-segmented-control--canvas-contrast-selected{background-color:#05203c;color:#fff}.bpk-segmented-control--surface-default{background-color:#eff3f8;color:#161616}.bpk-segmented-control--surface-default-selected{background-color:#05203c;color:#fff}.bpk-segmented-control--surface-contrast{background-color:rgba(255,255,255,.1);color:#fff}.bpk-segmented-control--surface-contrast-selected{background-color:#024daf;color:#fff}.bpk-segmented-control:not(:first-of-type,[class*=selected]){border-left:.0625rem solid #c1c7cf}.bpk-segmented-control--surface-contrast:not(:first-of-type,[class*=selected]){border-left:.0625rem solid rgba(255,255,255,.5)}.bpk-segmented-control[class*=rightOfOption]{border-left:none}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skyscanner/backpack-web",
3
- "version": "34.7.1",
3
+ "version": "34.8.0",
4
4
  "description": "Backpack Design System web library",
5
5
  "repository": {
6
6
  "type": "git",