@skyscanner/backpack-web 42.26.0-dev-v27664212356.1 → 42.27.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,4 +1,4 @@
1
- export { BpkProvider, BpkEmotionCacheContext } from './src/BpkProvider';
1
+ export { BpkProvider } from './src/BpkProvider';
2
2
  export { BpkBox } from './src/BpkBox';
3
3
  export { BpkVessel } from './src/BpkVessel';
4
4
  export { BpkFlex } from './src/BpkFlex';
@@ -16,7 +16,7 @@
16
16
  * limitations under the License.
17
17
  */
18
18
 
19
- export { BpkProvider, BpkEmotionCacheContext } from "./src/BpkProvider";
19
+ export { BpkProvider } from "./src/BpkProvider";
20
20
  export { BpkBox } from "./src/BpkBox";
21
21
  export { BpkVessel } from "./src/BpkVessel";
22
22
  export { BpkFlex } from "./src/BpkFlex";
@@ -1,14 +1,11 @@
1
- import type { ReactNode, ReactElement } from 'react';
2
- import type { EmotionCache } from '@emotion/cache';
1
+ import type { ReactElement, ReactNode } from 'react';
3
2
  export interface BpkProviderProps {
4
3
  children: ReactNode;
5
4
  }
6
- export declare const BpkEmotionCacheContext: import("react").Context<EmotionCache | null>;
7
5
  /**
8
6
  * BpkProvider - Provides context for Backpack layout and Ark-based components.
9
7
  *
10
8
  * Wraps children with:
11
- * - Emotion CacheProvider (own cache, or external cache injected via BpkEmotionCacheContext)
12
9
  * - Chakra UI system context (for layout components: BpkFlex, BpkGrid, etc.)
13
10
  * - Ark UI LocaleProvider (for Ark-based components: BpkCheckboxV2, BpkSegmentedControlV2, etc.)
14
11
  *
@@ -16,11 +13,6 @@ export declare const BpkEmotionCacheContext: import("react").Context<EmotionCach
16
13
  * the appropriate locale to Ark's LocaleProvider. All Ark-based components in the
17
14
  * tree render correctly in RTL without requiring additional wrapping or prop changes.
18
15
  *
19
- * External cache injection: host apps can supply an Emotion cache via
20
- * BpkEmotionCacheContext. When a non-null value is provided, BpkProvider uses it
21
- * directly and skips creating its own cache. This allows the host to swap in a
22
- * fresh cache after a hydration error so all Backpack styles are re-injected.
23
- *
24
16
  * @param {BpkProviderProps} props - The provider props.
25
17
  * @returns {ReactElement} The provider wrapping its children with Chakra and Ark context.
26
18
  */
@@ -23,12 +23,6 @@ import createCache from '@emotion/cache';
23
23
  import { CacheProvider } from '@emotion/react';
24
24
  import { createBpkConfig } from "./theme";
25
25
  import { jsx as _jsx } from "react/jsx-runtime";
26
- // Exported so host apps can inject an externally-managed Emotion cache into
27
- // BpkProvider (e.g. to force re-injection after a hydration error recovery).
28
- // When a non-null value is provided via this context, BpkProvider operates in
29
- // "nested" mode: it skips creating its own cache and delegates to the external one.
30
- export const BpkEmotionCacheContext = /*#__PURE__*/createContext(null);
31
-
32
26
  /**
33
27
  * Creates a Chakra UI system with Backpack token mappings.
34
28
  *
@@ -43,14 +37,6 @@ const bpkSystem = createSystem(defaultBaseConfig, createBpkConfig());
43
37
  // Force speedy:false + recreate after mount in Cypress. Remove once Emotion /
44
38
  // React Router 7 provide a cleaner hydration story. Ported from hotels-website#12025.
45
39
 
46
- // `'css'` is shared with Chakra v3's internal key on purpose — keeps this
47
- // boundary in front of Chakra's auto-created cache.
48
- const createBpkEmotionCache = speedy => createCache(speedy === undefined ? {
49
- key: 'css'
50
- } : {
51
- key: 'css',
52
- speedy
53
- });
54
40
  const isCypressEnv = () => {
55
41
  if (typeof window === 'undefined') return false;
56
42
  const win = window;
@@ -63,6 +49,16 @@ const isCypressEnv = () => {
63
49
  return false; // cross-origin parent frame
64
50
  }
65
51
  };
52
+
53
+ // `'css'` is shared with Chakra v3's internal key on purpose — keeps this
54
+ // boundary in front of Chakra's auto-created cache.
55
+ const createBpkEmotionCache = speedy => createCache(speedy === undefined ? {
56
+ key: 'css'
57
+ } : {
58
+ key: 'css',
59
+ speedy
60
+ });
61
+ const BpkEmotionCacheContext = /*#__PURE__*/createContext(null);
66
62
  // Fallback locale mapping used when no explicit locale is available on the document.
67
63
  // Maps DOM direction to minimal BCP 47 locales understood by Ark's isRTL() utility.
68
64
  // 'ar-SA' is the minimal RTL locale — Ark only uses it to derive dir='rtl'.
@@ -142,7 +138,6 @@ const useArkLocale = () => {
142
138
  * BpkProvider - Provides context for Backpack layout and Ark-based components.
143
139
  *
144
140
  * Wraps children with:
145
- * - Emotion CacheProvider (own cache, or external cache injected via BpkEmotionCacheContext)
146
141
  * - Chakra UI system context (for layout components: BpkFlex, BpkGrid, etc.)
147
142
  * - Ark UI LocaleProvider (for Ark-based components: BpkCheckboxV2, BpkSegmentedControlV2, etc.)
148
143
  *
@@ -150,21 +145,16 @@ const useArkLocale = () => {
150
145
  * the appropriate locale to Ark's LocaleProvider. All Ark-based components in the
151
146
  * tree render correctly in RTL without requiring additional wrapping or prop changes.
152
147
  *
153
- * External cache injection: host apps can supply an Emotion cache via
154
- * BpkEmotionCacheContext. When a non-null value is provided, BpkProvider uses it
155
- * directly and skips creating its own cache. This allows the host to swap in a
156
- * fresh cache after a hydration error so all Backpack styles are re-injected.
157
- *
158
148
  * @param {BpkProviderProps} props - The provider props.
159
149
  * @returns {ReactElement} The provider wrapping its children with Chakra and Ark context.
160
150
  */
161
151
  export const BpkProvider = ({
162
152
  children
163
153
  }) => {
164
- const externalCache = useContext(BpkEmotionCacheContext);
165
- const isNested = externalCache !== null;
154
+ const parentCache = useContext(BpkEmotionCacheContext);
155
+ const isNested = parentCache !== null;
166
156
  const [isCypress] = useState(isCypressEnv);
167
- const [ownCache, setOwnCache] = useState(() => isNested ? externalCache : createBpkEmotionCache(isCypress ? false : undefined));
157
+ const [ownCache, setOwnCache] = useState(() => isNested ? parentCache : createBpkEmotionCache(isCypress ? false : undefined));
168
158
  const hasRecreated = useRef(false);
169
159
  const locale = useArkLocale();
170
160
 
@@ -178,13 +168,6 @@ export const BpkProvider = ({
178
168
  setOwnCache(createBpkEmotionCache(false));
179
169
  // eslint-disable-next-line react-hooks/exhaustive-deps
180
170
  }, []);
181
-
182
- // NOTE: if externalCache changes from non-null to null at runtime, ownCache
183
- // will still hold the value it was initialised with (the old external cache).
184
- // This is intentional: BpkEmotionCacheContext.Provider is expected to be
185
- // mounted for the lifetime of the app once set — toggling it off is not a
186
- // supported use case. The state initialiser runs only once per mount.
187
- const activeCache = isNested ? externalCache : ownCache;
188
171
  const inner = /*#__PURE__*/_jsx(ChakraProvider, {
189
172
  value: bpkSystem,
190
173
  children: /*#__PURE__*/_jsx(LocaleProvider, {
@@ -192,10 +175,13 @@ export const BpkProvider = ({
192
175
  children: children
193
176
  })
194
177
  });
178
+ if (isNested) {
179
+ return inner;
180
+ }
195
181
  return /*#__PURE__*/_jsx(BpkEmotionCacheContext.Provider, {
196
- value: activeCache,
182
+ value: ownCache,
197
183
  children: /*#__PURE__*/_jsx(CacheProvider, {
198
- value: activeCache,
184
+ value: ownCache,
199
185
  children: inner
200
186
  })
201
187
  });
@@ -3,6 +3,19 @@ import type StackOptionKeys from './BpkStack.constant';
3
3
  import type { BpkCommonLayoutProps } from './commonProps';
4
4
  import type { BpkSpacingValue, BpkResponsiveValue, BpkBasisValue } from './tokens';
5
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
+ * onClick is handled via BpkCommonLayoutProps; onFocus/onBlur are reintroduced
9
+ * on BpkBoxProps only.
10
+ */
11
+ type LayoutEventProps = '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';
6
19
  /**
7
20
  * Flexbox & grid layout props that we explicitly support on Backpack layout
8
21
  * components. These are a curated subset of the underlying Box flex/grid API
@@ -66,10 +79,17 @@ type BpkBoxResponsiveLayoutProps = {
66
79
  };
67
80
  type BpkBoxResponsiveLayoutPropKeys = keyof BpkBoxResponsiveLayoutProps;
68
81
  /**
69
- * Component-specific props for BpkBox.
70
- * Explicit allowlist does NOT inherit from Chakra BoxProps.
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
71
91
  */
72
- export interface BpkBoxSpecificProps extends BpkBoxResponsiveLayoutProps, Omit<BpkFlexGridProps, BpkBoxResponsiveLayoutPropKeys> {
92
+ export interface BpkBoxSpecificProps extends Omit<RemoveCommonProps<BoxProps>, BpkBoxResponsiveLayoutPropKeys>, BpkBoxResponsiveLayoutProps, Omit<BpkFlexGridProps, BpkBoxResponsiveLayoutPropKeys> {
73
93
  }
74
94
  /**
75
95
  * Props for BpkBox component
@@ -127,10 +147,10 @@ export type BpkVesselProps = {
127
147
  as?: VesselElement;
128
148
  } & HTMLAttributes<HTMLElement>;
129
149
  /**
130
- * Component-specific props for BpkFlex.
131
- * Explicit allowlist does NOT inherit from Chakra FlexProps.
150
+ * Component-specific props for BpkFlex
151
+ * Includes all Flex props except those in BpkCommonLayoutProps
132
152
  */
133
- export interface BpkFlexSpecificProps {
153
+ export interface BpkFlexSpecificProps extends RemoveCommonProps<FlexProps> {
134
154
  direction?: BpkResponsiveValue<FlexProps['flexDirection']>;
135
155
  justify?: BpkResponsiveValue<FlexProps['justifyContent']>;
136
156
  align?: BpkResponsiveValue<FlexProps['alignItems']>;
@@ -148,10 +168,10 @@ export interface BpkFlexProps extends BpkCommonLayoutProps, BpkFlexSpecificProps
148
168
  children?: ReactNode;
149
169
  }
150
170
  /**
151
- * Component-specific props for BpkGrid.
152
- * Explicit allowlist does NOT inherit from Chakra GridProps.
171
+ * Component-specific props for BpkGrid
172
+ * Includes all Grid props except those in BpkCommonLayoutProps
153
173
  */
154
- export interface BpkGridSpecificProps {
174
+ export interface BpkGridSpecificProps extends RemoveCommonProps<GridProps> {
155
175
  justify?: BpkResponsiveValue<GridProps['justifyContent']>;
156
176
  align?: BpkResponsiveValue<GridProps['alignItems']>;
157
177
  templateColumns?: BpkResponsiveValue<GridProps['gridTemplateColumns']>;
@@ -174,10 +194,10 @@ export interface BpkGridProps extends BpkCommonLayoutProps, BpkGridSpecificProps
174
194
  children?: ReactNode;
175
195
  }
176
196
  /**
177
- * Component-specific props for BpkGridItem.
178
- * Explicit allowlist does NOT inherit from Chakra GridItemProps.
197
+ * Component-specific props for BpkGridItem
198
+ * Includes all GridItem props except those in BpkCommonLayoutProps
179
199
  */
180
- export interface BpkGridItemSpecificProps {
200
+ export interface BpkGridItemSpecificProps extends RemoveCommonProps<GridItemProps> {
181
201
  area?: GridItemProps['area'];
182
202
  colEnd?: GridItemProps['colEnd'];
183
203
  colStart?: GridItemProps['colStart'];
@@ -201,17 +221,13 @@ type BpkStackOptions = {
201
221
  [K in StackOptionKeysType]?: K extends keyof StackProps ? BpkResponsiveValue<StackProps[K]> | StackProps[K] : never;
202
222
  };
203
223
  /**
204
- * Component-specific props for BpkStack.
205
- * Explicit allowlist does NOT inherit from Chakra StackProps.
224
+ * Component-specific props for BpkStack
225
+ * Includes all Stack props except those in BpkCommonLayoutProps
206
226
  * Overrides StackOptions to support BpkResponsiveValue.
207
227
  * `alignItems` and `justifyContent` are accepted as semantic aliases for `align` and `justify`.
208
228
  * If both are provided, `align`/`justify` take precedence.
209
- *
210
- * `alignItems` and `justifyContent` are explicitly omitted from `BpkFlexGridProps` here so
211
- * that the responsive alias declarations below (which match BpkStackOptions) unambiguously
212
- * replace the non-responsive `BoxProps` variants from `BpkFlexGridProps`.
213
229
  */
214
- export interface BpkStackSpecificProps extends BpkStackOptions, Omit<BpkFlexGridProps, 'alignItems' | 'justifyContent'> {
230
+ export interface BpkStackSpecificProps extends Omit<RemoveCommonProps<StackProps>, StackOptionKeysType>, BpkStackOptions, Omit<BpkFlexGridProps, 'alignItems' | 'justifyContent'> {
215
231
  /** Alias for `align`. Maps to CSS `align-items`. Responsive — replaces the non-responsive BpkFlexGridProps.alignItems. */
216
232
  alignItems?: BpkStackOptions['align'];
217
233
  /** Alias for `justify`. Maps to CSS `justify-content`. Responsive — replaces the non-responsive BpkFlexGridProps.justifyContent. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skyscanner/backpack-web",
3
- "version": "42.26.0-dev-v27664212356.1",
3
+ "version": "42.27.0",
4
4
  "description": "Backpack Design System web library",
5
5
  "repository": {
6
6
  "type": "git",