@skyscanner/backpack-web 41.6.0 → 41.7.0-beta-v1

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.
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Backpack Design Tokens for Layout Components
3
+ *
4
+ * This file provides token mappings from Backpack design tokens to Chakra UI theme.
5
+ * All tokens are sourced from @skyscanner/bpk-foundations-web
6
+ */
7
+ /**
8
+ * Backpack Spacing Tokens
9
+ * Use these constants to ensure type safety when passing spacing props
10
+ */
11
+ export declare const BpkSpacing: {
12
+ readonly None: "bpk-spacing-none";
13
+ readonly XS: "bpk-spacing-xs";
14
+ readonly SM: "bpk-spacing-sm";
15
+ readonly Base: "bpk-spacing-base";
16
+ readonly MD: "bpk-spacing-md";
17
+ readonly LG: "bpk-spacing-lg";
18
+ readonly XL: "bpk-spacing-xl";
19
+ readonly XXL: "bpk-spacing-xxl";
20
+ };
21
+ export type BpkSpacingToken = typeof BpkSpacing[keyof typeof BpkSpacing];
22
+ /**
23
+ * Backpack Breakpoint Tokens
24
+ * Use these constants to ensure type safety when defining responsive overrides
25
+ * These map to the simplified keys defined in the Chakra theme
26
+ */
27
+ export declare const BpkBreakpoint: {
28
+ readonly SmallMobile: "small-mobile";
29
+ readonly Mobile: "mobile";
30
+ readonly SmallTablet: "small-tablet";
31
+ readonly Tablet: "tablet";
32
+ readonly Desktop: "desktop";
33
+ };
34
+ export type BpkBreakpointToken = typeof BpkBreakpoint[keyof typeof BpkBreakpoint];
35
+ export type ChakraBreakpointKey = 'base' | 'sm' | 'md' | 'lg' | 'xl' | '2xl';
36
+ export declare const BpkBreakpointToChakraKey: Record<BpkBreakpointToken, ChakraBreakpointKey>;
37
+ /**
38
+ * Helper type for values that can be Backpack tokens or percentages
39
+ * but NOT px/rem values
40
+ */
41
+ export type BpkSpacingValue = BpkSpacingToken | `${number}%`;
42
+ export type BpkBreakpointValue = BpkBreakpointToken;
43
+ /**
44
+ * Helper type for size props that can use rem, percentages or semantic values.
45
+ * This is intentionally separate from BpkSpacingValue to avoid encouraging
46
+ * spacing tokens for explicit sizes.
47
+ */
48
+ export type BpkSizeValue = `${number}rem` | `${number}%` | 'auto' | 'full' | 'fit-content';
49
+ /**
50
+ * Helper type for position props that can use rem or percentages.
51
+ * We intentionally do not allow semantic values like 'auto' here.
52
+ */
53
+ export type BpkPositionValue = `${number}rem` | `${number}%`;
54
+ /**
55
+ * Helper type for flex-basis prop that can use rem, percentages or semantic values.
56
+ * Excludes 'px' values to enforce design system constraints.
57
+ */
58
+ export type BpkBasisValue = `${number}rem` | `${number}%` | 'auto' | 'content' | 'fit-content' | 'max-content' | 'min-content' | 'initial' | 'inherit';
59
+ /**
60
+ * Helper type for responsive values based on Backpack breakpoints.
61
+ *
62
+ * We intentionally only support:
63
+ * - a single scalar value (non-responsive)
64
+ * - an object keyed by Backpack breakpoint tokens (and optional base)
65
+ *
66
+ * We do NOT support array-based responsive values in the public API.
67
+ */
68
+ export type BpkResponsiveValue<T> = T | Partial<Record<BpkBreakpointToken | 'base', T>>;
69
+ /**
70
+ * Validates if a value is a percentage string
71
+ *
72
+ * @param {string} value - The value to validate
73
+ * @returns {boolean} True if the value is a valid percentage string
74
+ */
75
+ export declare function isPercentage(value: string): boolean;
76
+ /**
77
+ * Validates if a spacing value is valid (token or percentage)
78
+ *
79
+ * @param {string} value - The spacing value to validate
80
+ * @returns {boolean} True if the value is a valid Backpack spacing token or percentage
81
+ */
82
+ export declare function isValidSpacingValue(value: string): boolean;
83
+ /**
84
+ * Validates if a size value is valid
85
+ *
86
+ * @param {string} value - The size value to validate
87
+ * @returns {boolean} True if the value is a valid rem/percentage/semantic size
88
+ */
89
+ export declare function isValidSizeValue(value: string): boolean;
90
+ /**
91
+ * Validates if a position value is valid
92
+ *
93
+ * @param {string} value - The position value to validate
94
+ * @returns {boolean} True if the value is a valid rem or percentage
95
+ */
96
+ export declare function isValidPositionValue(value: string): boolean;
@@ -0,0 +1,138 @@
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
+ /**
20
+ * Backpack Design Tokens for Layout Components
21
+ *
22
+ * This file provides token mappings from Backpack design tokens to Chakra UI theme.
23
+ * All tokens are sourced from @skyscanner/bpk-foundations-web
24
+ */
25
+
26
+ /**
27
+ * Backpack Spacing Tokens
28
+ * Use these constants to ensure type safety when passing spacing props
29
+ */
30
+ export const BpkSpacing = {
31
+ None: 'bpk-spacing-none',
32
+ XS: 'bpk-spacing-xs',
33
+ SM: 'bpk-spacing-sm',
34
+ Base: 'bpk-spacing-base',
35
+ MD: 'bpk-spacing-md',
36
+ LG: 'bpk-spacing-lg',
37
+ XL: 'bpk-spacing-xl',
38
+ XXL: 'bpk-spacing-xxl'
39
+ };
40
+ /**
41
+ * Backpack Breakpoint Tokens
42
+ * Use these constants to ensure type safety when defining responsive overrides
43
+ * These map to the simplified keys defined in the Chakra theme
44
+ */
45
+ export const BpkBreakpoint = {
46
+ SmallMobile: 'small-mobile',
47
+ Mobile: 'mobile',
48
+ SmallTablet: 'small-tablet',
49
+ Tablet: 'tablet',
50
+ Desktop: 'desktop'
51
+ };
52
+ export const BpkBreakpointToChakraKey = {
53
+ // Keep this mapping in sync with the breakpoints configured in `theme.ts`.
54
+ // `base` is reserved for "default value" and is not a breakpoint token.
55
+ 'small-mobile': 'sm',
56
+ mobile: 'md',
57
+ 'small-tablet': 'lg',
58
+ tablet: 'xl',
59
+ desktop: '2xl'
60
+ };
61
+
62
+ /**
63
+ * Helper type for values that can be Backpack tokens or percentages
64
+ * but NOT px/rem values
65
+ */
66
+
67
+ /**
68
+ * Helper type for size props that can use rem, percentages or semantic values.
69
+ * This is intentionally separate from BpkSpacingValue to avoid encouraging
70
+ * spacing tokens for explicit sizes.
71
+ */
72
+
73
+ /**
74
+ * Helper type for position props that can use rem or percentages.
75
+ * We intentionally do not allow semantic values like 'auto' here.
76
+ */
77
+
78
+ /**
79
+ * Helper type for flex-basis prop that can use rem, percentages or semantic values.
80
+ * Excludes 'px' values to enforce design system constraints.
81
+ */
82
+
83
+ /**
84
+ * Helper type for responsive values based on Backpack breakpoints.
85
+ *
86
+ * We intentionally only support:
87
+ * - a single scalar value (non-responsive)
88
+ * - an object keyed by Backpack breakpoint tokens (and optional base)
89
+ *
90
+ * We do NOT support array-based responsive values in the public API.
91
+ */
92
+
93
+ /**
94
+ * Validates if a value is a percentage string
95
+ *
96
+ * @param {string} value - The value to validate
97
+ * @returns {boolean} True if the value is a valid percentage string
98
+ */
99
+ export function isPercentage(value) {
100
+ return /^\d+(\.\d+)?%$/.test(value);
101
+ }
102
+
103
+ /**
104
+ * Validates if a spacing value is valid (token or percentage)
105
+ *
106
+ * @param {string} value - The spacing value to validate
107
+ * @returns {boolean} True if the value is a valid Backpack spacing token or percentage
108
+ */
109
+ export function isValidSpacingValue(value) {
110
+ return Object.values(BpkSpacing).includes(value) || isPercentage(value);
111
+ }
112
+
113
+ /**
114
+ * Validates if a size value is valid
115
+ *
116
+ * @param {string} value - The size value to validate
117
+ * @returns {boolean} True if the value is a valid rem/percentage/semantic size
118
+ */
119
+ export function isValidSizeValue(value) {
120
+ return /^-?\d+(\.\d+)?rem$/.test(value) ||
121
+ // rem values
122
+ isPercentage(value) ||
123
+ // percentage values
124
+ value === 'auto' || value === 'full' || value === 'fit-content';
125
+ }
126
+
127
+ /**
128
+ * Validates if a position value is valid
129
+ *
130
+ * @param {string} value - The position value to validate
131
+ * @returns {boolean} True if the value is a valid rem or percentage
132
+ */
133
+ export function isValidPositionValue(value) {
134
+ return /^-?\d+(\.\d+)?rem$/.test(value) ||
135
+ // rem values
136
+ isPercentage(value) // percentage values
137
+ ;
138
+ }
@@ -0,0 +1,194 @@
1
+ import type { ReactNode } from 'react';
2
+ import type StackOptionKeys from './BpkStack.constant';
3
+ import type { BpkCommonLayoutProps } from './commonProps';
4
+ import type { BpkSpacingValue, BpkResponsiveValue, BpkBasisValue } from './tokens';
5
+ import type { BoxProps, FlexProps, GridProps, GridItemProps, StackProps } from '@chakra-ui/react';
6
+ /**
7
+ * Layout-level event props that should not be exposed on layout components
8
+ * by default. BpkBox will reintroduce a minimal subset (onClick, onFocus,
9
+ * onBlur) explicitly on its own props type.
10
+ */
11
+ type LayoutEventProps = 'onClick' | 'onMouseEnter' | 'onMouseLeave' | 'onMouseOver' | 'onMouseOut' | 'onMouseDown' | 'onMouseUp' | 'onFocus' | 'onBlur' | 'onKeyDown' | 'onKeyUp' | 'onKeyPress';
12
+ /**
13
+ * Shorthand props from the underlying layout system that we do NOT expose on
14
+ * Backpack layout components. These mostly mirror longer-form spacing,
15
+ * sizing and visual props that we already model explicitly via
16
+ * BpkCommonLayoutProps and BpkFlexGridProps.
17
+ */
18
+ type DisallowedShorthandProps = 'p' | 'pt' | 'pr' | 'pb' | 'pl' | 'px' | 'py' | 'm' | 'mt' | 'mr' | 'mb' | 'ml' | 'mx' | 'my' | 'w' | 'h' | 'minW' | 'maxW' | 'minH' | 'maxH' | 'bg' | 'rounded' | 'shadow';
19
+ /**
20
+ * Flexbox & grid layout props that we explicitly support on Backpack layout
21
+ * components. These are a curated subset of the underlying Box flex/grid API
22
+ * that are useful for structural layout.
23
+ */
24
+ export interface BpkFlexGridProps {
25
+ display?: BoxProps['display'];
26
+ flexDirection?: BoxProps['flexDirection'];
27
+ flexWrap?: BoxProps['flexWrap'];
28
+ justifyContent?: BoxProps['justifyContent'];
29
+ alignItems?: BoxProps['alignItems'];
30
+ alignContent?: BoxProps['alignContent'];
31
+ flex?: BoxProps['flex'];
32
+ flexGrow?: BoxProps['flexGrow'];
33
+ flexShrink?: BoxProps['flexShrink'];
34
+ flexBasis?: BoxProps['flexBasis'];
35
+ order?: BoxProps['order'];
36
+ alignSelf?: BoxProps['alignSelf'];
37
+ justifySelf?: BoxProps['justifySelf'];
38
+ gridTemplateColumns?: BoxProps['gridTemplateColumns'];
39
+ gridTemplateRows?: BoxProps['gridTemplateRows'];
40
+ gridTemplateAreas?: BoxProps['gridTemplateAreas'];
41
+ gridAutoFlow?: BoxProps['gridAutoFlow'];
42
+ gridAutoRows?: BoxProps['gridAutoRows'];
43
+ gridAutoColumns?: BoxProps['gridAutoColumns'];
44
+ rowGap?: BoxProps['rowGap'];
45
+ columnGap?: BoxProps['columnGap'];
46
+ }
47
+ export type FlexGridPropKeys = keyof BpkFlexGridProps;
48
+ /**
49
+ * Curated subset of Box layout props that support Backpack responsive values.
50
+ *
51
+ * NOTE:
52
+ * - These are structural layout props (flex/grid/display) that we want to allow
53
+ * on `BpkBox`, but using Backpack breakpoint keys rather than Chakra's
54
+ * array syntax or Chakra breakpoint keys.
55
+ * - Spacing/size/position props are handled separately via `BpkCommonLayoutProps`.
56
+ */
57
+ type BpkBoxResponsiveLayoutProps = {
58
+ display?: BpkResponsiveValue<BoxProps['display']>;
59
+ flexDirection?: BpkResponsiveValue<BoxProps['flexDirection']>;
60
+ flexWrap?: BpkResponsiveValue<BoxProps['flexWrap']>;
61
+ justifyContent?: BpkResponsiveValue<BoxProps['justifyContent']>;
62
+ alignItems?: BpkResponsiveValue<BoxProps['alignItems']>;
63
+ alignContent?: BpkResponsiveValue<BoxProps['alignContent']>;
64
+ flex?: BpkResponsiveValue<BoxProps['flex']>;
65
+ flexGrow?: BpkResponsiveValue<BoxProps['flexGrow']>;
66
+ flexShrink?: BpkResponsiveValue<BoxProps['flexShrink']>;
67
+ flexBasis?: BpkResponsiveValue<BoxProps['flexBasis']>;
68
+ order?: BpkResponsiveValue<BoxProps['order']>;
69
+ alignSelf?: BpkResponsiveValue<BoxProps['alignSelf']>;
70
+ justifySelf?: BpkResponsiveValue<BoxProps['justifySelf']>;
71
+ gridTemplateColumns?: BpkResponsiveValue<BoxProps['gridTemplateColumns']>;
72
+ gridTemplateRows?: BpkResponsiveValue<BoxProps['gridTemplateRows']>;
73
+ gridTemplateAreas?: BpkResponsiveValue<BoxProps['gridTemplateAreas']>;
74
+ gridAutoFlow?: BpkResponsiveValue<BoxProps['gridAutoFlow']>;
75
+ gridAutoRows?: BpkResponsiveValue<BoxProps['gridAutoRows']>;
76
+ gridAutoColumns?: BpkResponsiveValue<BoxProps['gridAutoColumns']>;
77
+ gridColumn?: BpkResponsiveValue<BoxProps['gridColumn']>;
78
+ gridRow?: BpkResponsiveValue<BoxProps['gridRow']>;
79
+ };
80
+ type BpkBoxResponsiveLayoutPropKeys = keyof BpkBoxResponsiveLayoutProps;
81
+ /**
82
+ * Base type that removes common layout props, reserved props (className,
83
+ * children) and all layout-level event props from Chakra UI props.
84
+ *
85
+ * These will be replaced with Backpack-specific types.
86
+ */
87
+ export type RemoveCommonProps<T> = Omit<T, keyof BpkCommonLayoutProps | 'className' | 'children' | LayoutEventProps | FlexGridPropKeys | DisallowedShorthandProps>;
88
+ /**
89
+ * Component-specific props for BpkBox
90
+ * Includes all Box props except those in BpkCommonLayoutProps
91
+ */
92
+ export interface BpkBoxSpecificProps extends Omit<RemoveCommonProps<BoxProps>, BpkBoxResponsiveLayoutPropKeys>, BpkBoxResponsiveLayoutProps, Omit<BpkFlexGridProps, BpkBoxResponsiveLayoutPropKeys> {
93
+ }
94
+ /**
95
+ * Props for BpkBox component
96
+ * Combines Box-specific props with Backpack common layout props
97
+ * and reintroduces a minimal set of interaction props.
98
+ */
99
+ type BoxEventProps = Pick<BoxProps, 'onClick' | 'onFocus' | 'onBlur'>;
100
+ export interface BpkBoxProps extends BpkCommonLayoutProps, BpkBoxSpecificProps {
101
+ children?: ReactNode;
102
+ onClick?: BoxEventProps['onClick'];
103
+ onFocus?: BoxEventProps['onFocus'];
104
+ onBlur?: BoxEventProps['onBlur'];
105
+ }
106
+ /**
107
+ * Component-specific props for BpkFlex
108
+ * Includes all Flex props except those in BpkCommonLayoutProps
109
+ */
110
+ export interface BpkFlexSpecificProps extends RemoveCommonProps<FlexProps> {
111
+ direction?: BpkResponsiveValue<FlexProps['flexDirection']>;
112
+ justify?: BpkResponsiveValue<FlexProps['justifyContent']>;
113
+ align?: BpkResponsiveValue<FlexProps['alignItems']>;
114
+ wrap?: BpkResponsiveValue<FlexProps['flexWrap']>;
115
+ grow?: BpkResponsiveValue<FlexProps['flexGrow']>;
116
+ shrink?: BpkResponsiveValue<FlexProps['flexShrink']>;
117
+ basis?: BpkResponsiveValue<BpkBasisValue>;
118
+ inline?: boolean;
119
+ }
120
+ /**
121
+ * Props for BpkFlex component
122
+ * Combines Flex-specific props with Backpack common layout props
123
+ */
124
+ export interface BpkFlexProps extends BpkCommonLayoutProps, BpkFlexSpecificProps {
125
+ children?: ReactNode;
126
+ }
127
+ /**
128
+ * Component-specific props for BpkGrid
129
+ * Includes all Grid props except those in BpkCommonLayoutProps
130
+ */
131
+ export interface BpkGridSpecificProps extends RemoveCommonProps<GridProps> {
132
+ justify?: BpkResponsiveValue<GridProps['justifyContent']>;
133
+ align?: BpkResponsiveValue<GridProps['alignItems']>;
134
+ templateColumns?: BpkResponsiveValue<GridProps['gridTemplateColumns']>;
135
+ templateRows?: BpkResponsiveValue<GridProps['gridTemplateRows']>;
136
+ templateAreas?: BpkResponsiveValue<GridProps['gridTemplateAreas']>;
137
+ autoFlow?: BpkResponsiveValue<GridProps['gridAutoFlow']>;
138
+ autoRows?: BpkResponsiveValue<GridProps['gridAutoRows']>;
139
+ autoColumns?: BpkResponsiveValue<GridProps['gridAutoColumns']>;
140
+ rowGap?: BpkResponsiveValue<BpkSpacingValue>;
141
+ columnGap?: BpkResponsiveValue<BpkSpacingValue>;
142
+ column?: BpkResponsiveValue<GridProps['gridColumn']>;
143
+ row?: BpkResponsiveValue<GridProps['gridRow']>;
144
+ inline?: boolean;
145
+ }
146
+ /**
147
+ * Props for BpkGrid component
148
+ * Combines Grid-specific props with Backpack common layout props
149
+ */
150
+ export interface BpkGridProps extends BpkCommonLayoutProps, BpkGridSpecificProps {
151
+ children?: ReactNode;
152
+ }
153
+ /**
154
+ * Component-specific props for BpkGridItem
155
+ * Includes all GridItem props except those in BpkCommonLayoutProps
156
+ */
157
+ export interface BpkGridItemSpecificProps extends RemoveCommonProps<GridItemProps> {
158
+ area?: GridItemProps['area'];
159
+ colEnd?: GridItemProps['colEnd'];
160
+ colStart?: GridItemProps['colStart'];
161
+ colSpan?: GridItemProps['colSpan'];
162
+ rowEnd?: GridItemProps['rowEnd'];
163
+ rowStart?: GridItemProps['rowStart'];
164
+ rowSpan?: GridItemProps['rowSpan'];
165
+ }
166
+ /**
167
+ * Props for BpkGridItem component
168
+ * Combines GridItem-specific props with Backpack common layout props
169
+ */
170
+ export interface BpkGridItemProps extends BpkCommonLayoutProps, BpkGridItemSpecificProps {
171
+ children?: ReactNode;
172
+ }
173
+ type StackOptionKeysType = typeof StackOptionKeys[number];
174
+ /**
175
+ * Overrides StackOptions to support BpkResponsiveValue
176
+ */
177
+ type BpkStackOptions = {
178
+ [K in StackOptionKeysType]?: K extends keyof StackProps ? BpkResponsiveValue<StackProps[K]> | StackProps[K] : never;
179
+ };
180
+ /**
181
+ * Component-specific props for BpkStack
182
+ * Includes all Stack props except those in BpkCommonLayoutProps
183
+ * Overrides StackOptions to support BpkResponsiveValue
184
+ */
185
+ export interface BpkStackSpecificProps extends Omit<RemoveCommonProps<StackProps>, StackOptionKeysType>, BpkStackOptions, BpkFlexGridProps {
186
+ }
187
+ /**
188
+ * Props for BpkStack component
189
+ * Combines Stack-specific props with Backpack common layout props
190
+ */
191
+ export interface BpkStackProps extends BpkCommonLayoutProps, BpkStackSpecificProps {
192
+ children?: ReactNode;
193
+ }
194
+ export type { BpkCommonLayoutProps };
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skyscanner/backpack-web",
3
- "version": "41.6.0",
3
+ "version": "41.7.0-beta-v1",
4
4
  "description": "Backpack Design System web library",
5
5
  "repository": {
6
6
  "type": "git",
@@ -22,6 +22,7 @@
22
22
  "access": "public"
23
23
  },
24
24
  "dependencies": {
25
+ "@chakra-ui/react": "^3.30.0",
25
26
  "@floating-ui/react": "^0.26.12",
26
27
  "@popperjs/core": "^2.11.8",
27
28
  "@radix-ui/react-compose-refs": "^1.1.1",