@shopgate/engage 7.32.0-beta.7 → 7.32.0-beta.9

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.
Files changed (188) hide show
  1. package/account/components/Profile/Profile.provider.d.ts +1 -1
  2. package/account/components/Profile/ProfileAddressBook.d.ts.map +1 -1
  3. package/account/components/Profile/ProfileAddressBook.js +13 -22
  4. package/account/components/Profile/ProfileAddressCard.d.ts.map +1 -1
  5. package/account/components/Profile/ProfileAddressCard.js +8 -18
  6. package/account/components/Profile/ProfileForm.d.ts.map +1 -1
  7. package/account/components/Profile/ProfileForm.js +15 -42
  8. package/account/components/ProfileContact/ProfileContact.js +13 -21
  9. package/admin-preview/components/FrontendSettingsPreviewBridge/FrontendSettingsPreviewBridge.d.ts.map +1 -1
  10. package/admin-preview/components/FrontendSettingsPreviewBridge/FrontendSettingsPreviewBridge.js +41 -7
  11. package/admin-preview/components/FrontendSettingsPreviewBridge/types.d.ts +7 -0
  12. package/admin-preview/components/FrontendSettingsPreviewBridge/types.d.ts.map +1 -1
  13. package/admin-preview/initialization/_internal/initialFrontendSettings.d.ts +32 -0
  14. package/admin-preview/initialization/_internal/initialFrontendSettings.d.ts.map +1 -0
  15. package/admin-preview/initialization/_internal/initialFrontendSettings.js +43 -0
  16. package/admin-preview/initialization/awaitInitialFrontendSettings.d.ts +22 -0
  17. package/admin-preview/initialization/awaitInitialFrontendSettings.d.ts.map +1 -0
  18. package/admin-preview/initialization/awaitInitialFrontendSettings.js +84 -0
  19. package/back-in-stock/components/BackInStockButton/index.js +5 -5
  20. package/cart/components/CartItem/CartItemProductLayout.js +1 -0
  21. package/cart/components/CartItem/CartItemProductLayoutWideRemoveItem.js +7 -14
  22. package/cart/components/CartItem/CartItemQuantityPicker.js +1 -0
  23. package/cart/components/CartItems/CartItemCardReservationLabelChangeStore.js +6 -24
  24. package/cart/components/CartSummaryWide/CartSummaryWide.js +2 -2
  25. package/cart/components/CartSummaryWide/CartSummaryWideCheckoutButton.js +9 -23
  26. package/cart/components/PaymentBar/PaymentBarCheckoutButton.js +8 -30
  27. package/cart/components/PaymentBar/testUtils/mockFactories.js +4 -11
  28. package/category/components/CategoryImage/index.js +13 -2
  29. package/checkout/components/AddressBook/AddressList.js +14 -23
  30. package/checkout/components/Checkout/CheckoutActions.js +4 -3
  31. package/checkout/components/Checkout/CheckoutAddress.js +8 -0
  32. package/checkout/components/Checkout/CheckoutSection.js +6 -2
  33. package/checkout/components/CheckoutConfirmation/CheckoutConfirmation.js +6 -7
  34. package/checkout/components/ResponsiveBackButton/ResponsiveBackButton.js +7 -17
  35. package/components/Badge/spec.js +6 -29
  36. package/components/Card/Card.js +1 -1
  37. package/components/ChipLayout/index.js +2 -4
  38. package/components/NavigationHandler/connector.js +1 -1
  39. package/components/NavigationHandler/index.d.ts +2 -2
  40. package/components/NavigationHandler/spec.js +10 -1
  41. package/components/Paper/Paper.d.ts +1 -2
  42. package/components/Paper/Paper.d.ts.map +1 -1
  43. package/components/Paper/spec.js +5 -22
  44. package/components/Tabs/components/Tab.d.ts.map +1 -1
  45. package/components/Tabs/components/Tab.js +14 -16
  46. package/components/Typography/Typography.d.ts +1 -1
  47. package/components/v2/Button/Button.d.ts +24 -13
  48. package/components/v2/Button/Button.d.ts.map +1 -1
  49. package/components/v2/Button/Button.js +139 -41
  50. package/components/v2/ButtonBase/ButtonBase.d.ts +50 -10
  51. package/components/v2/ButtonBase/ButtonBase.d.ts.map +1 -1
  52. package/components/v2/ButtonBase/ButtonBase.js +192 -17
  53. package/components/v2/ButtonBase/hooks.d.ts +0 -1
  54. package/components/v2/ButtonBase/hooks.d.ts.map +1 -1
  55. package/components/v2/ButtonBase/hooks.js +36 -12
  56. package/components/v2/ButtonGroup/ButtonGroup.d.ts +11 -5
  57. package/components/v2/ButtonGroup/ButtonGroup.d.ts.map +1 -1
  58. package/components/v2/ButtonGroup/ButtonGroup.js +49 -26
  59. package/components/v2/CircularProgress/CircularProgress.d.ts.map +1 -1
  60. package/components/v2/CircularProgress/CircularProgress.js +10 -5
  61. package/core/hooks/useNavigation.d.ts +10 -2
  62. package/core/hooks/useNavigation.d.ts.map +1 -1
  63. package/core/hooks/useNavigation.js +1 -2
  64. package/core/initialization/index.d.ts.map +1 -1
  65. package/core/initialization/index.js +24 -5
  66. package/core/router/conductor.d.ts +9 -0
  67. package/core/router/helpers.d.ts +28 -15
  68. package/core/router/helpers.d.ts.map +1 -1
  69. package/core/router/helpers.js +8 -8
  70. package/development/components/DevelopmentSettings/DevelopmentSettings.js +3 -3
  71. package/favorites/components/FavoriteButtonWide/FavoriteButtonWide.js +7 -17
  72. package/favorites/components/List/List.d.ts.map +1 -1
  73. package/favorites/components/List/List.js +0 -1
  74. package/favorites/components/List/ListContent.js +4 -5
  75. package/favorites/components/Lists/Lists.js +4 -5
  76. package/filter/components/FilterPageContent/components/ApplyButton/index.js +8 -10
  77. package/filter/components/FilterPageContent/components/ResetButton/index.js +8 -6
  78. package/locations/components/ChangeLocationButton/ChangeLocationButton.js +10 -14
  79. package/locations/components/FulfillmentSlotSwitcher/FulfillmentSlotDialog.js +4 -8
  80. package/locations/components/FulfillmentSlotSwitcher/FulfillmentSlotSwitcher.js +1 -1
  81. package/locations/components/FulfillmentSlotSwitcher/FulfillmentSlotSwitcherBar.js +8 -13
  82. package/locations/components/FulfillmentSlotSwitcher/FulfillmentSlotSwitcherDefault.js +10 -10
  83. package/locations/components/GlobalLocationSwitcher/GlobalLocationSwitcherBar.js +8 -14
  84. package/locations/components/GlobalLocationSwitcher/GlobalLocationSwitcherDefault.js +9 -10
  85. package/locations/components/ReserveForm/ReserveForm.js +6 -7
  86. package/locations/components/StoreDetails/components/GetDirectionsButton.js +2 -4
  87. package/locations/components/StoreDetails/components/StoreDetails.js +5 -10
  88. package/locations/components/StoreDetails/components/StoresNearbyListItem.js +13 -21
  89. package/locations/components/StoreFinder/StoreFinderSelectLocationButton.js +5 -11
  90. package/locations/components/StoreFinder/StoreFinderStoreInfoButton.js +5 -11
  91. package/locations/components/StoreList/StoreListSearch.js +1 -0
  92. package/locations/components/StoreList/StoreSelectLocationButton.js +5 -11
  93. package/login/components/ForgotPassword/ForgotPassword.js +11 -23
  94. package/orders/components/OrderDetails/OrderDetailsAuthenticate.js +5 -7
  95. package/package.json +7 -7
  96. package/page/components/NotFound.d.ts.map +1 -1
  97. package/page/components/NotFound.js +7 -6
  98. package/page/components/ResponsiveWidgetImage/ResponsiveWidgetImage.d.ts +1 -1
  99. package/page/components/ResponsiveWidgetImage/ResponsiveWidgetImage.js +2 -2
  100. package/page/components/WidgetVideo/WidgetVideo.d.ts +1 -1
  101. package/page/components/WidgetVideo/WidgetVideo.d.ts.map +1 -1
  102. package/page/helpers/index.d.ts +5 -2
  103. package/page/helpers/index.d.ts.map +1 -1
  104. package/page/helpers/index.js +8 -5
  105. package/page/widgets/Button/Button.js +2 -3
  106. package/page/widgets/NestedCategoryFilter/NestedCategoryFilter.js +8 -8
  107. package/page/widgets/ProductList/ProductList.js +18 -14
  108. package/page/widgets/Video/hooks.d.ts +2 -2
  109. package/product/components/ProductCard/index.js +7 -1
  110. package/product/components/ProductGrid/components/Item/components/ItemDetails/index.js +6 -1
  111. package/product/components/ProductGrid/components/Item/components/ItemImage/index.js +1 -11
  112. package/product/components/ProductGrid/components/Item/index.js +3 -2
  113. package/product/components/ProductGrid/components/Layout/index.js +2 -1
  114. package/product/components/ProductGridPrice/index.js +0 -1
  115. package/product/components/ProductImage/ProductImage.d.ts.map +1 -1
  116. package/product/components/ProductImage/ProductImage.js +7 -2
  117. package/product/components/ProductImage/ProductImagePlaceholder.js +3 -3
  118. package/product/components/ProductSlider/index.js +1 -1
  119. package/product/components/UnitQuantityPicker/UnitQuantityPicker.d.ts.map +1 -1
  120. package/product/components/UnitQuantityPicker/UnitQuantityPicker.js +15 -33
  121. package/push-opt-in/components/PushOptInModal/index.js +4 -4
  122. package/registration/components/Registration/RegistrationFormActions.js +4 -4
  123. package/reviews/components/Reviews/components/AllReviewsLink/index.js +6 -6
  124. package/reviews/components/Reviews/components/Header/components/WriteReviewLink/index.js +4 -3
  125. package/reviews/components/Reviews/components/Header/components/WriteReviewLink/spec.js +28 -22
  126. package/reviews/components/Reviews/spec.js +5 -6
  127. package/settings/reducers/appSettings.d.ts.map +1 -1
  128. package/settings/reducers/appSettings.js +18 -2
  129. package/settings/selectors/appSettings.d.ts +37 -2
  130. package/settings/selectors/appSettings.d.ts.map +1 -1
  131. package/settings/selectors/appSettings.js +30 -1
  132. package/settings/types/appSettings.d.ts +42 -2
  133. package/settings/types/appSettings.d.ts.map +1 -1
  134. package/settings/types/appSettings.js +124 -1
  135. package/styles/helpers/index.d.ts +1 -0
  136. package/styles/helpers/index.js +1 -0
  137. package/styles/helpers/loadFontCss.d.ts +22 -0
  138. package/styles/helpers/loadFontCss.d.ts.map +1 -0
  139. package/styles/helpers/loadFontCss.js +138 -0
  140. package/styles/helpers/loadThemeCss.d.ts.map +1 -1
  141. package/styles/helpers/loadThemeCss.js +11 -0
  142. package/styles/index.d.ts +1 -1
  143. package/styles/index.d.ts.map +1 -1
  144. package/styles/theme/createDefaultThemeOptions/index.d.ts.map +1 -1
  145. package/styles/theme/createDefaultThemeOptions/index.js +94 -3
  146. package/styles/theme/createTheme/createComponents.types.d.ts +25 -0
  147. package/styles/theme/createTheme/createComponents.types.d.ts.map +1 -1
  148. package/styles/theme/createTheme/createComponents.types.js +28 -3
  149. package/styles/theme/createTheme/createShape.d.ts +2 -3
  150. package/styles/theme/createTheme/createShape.d.ts.map +1 -1
  151. package/styles/theme/createTheme/createShape.js +1 -2
  152. package/styles/theme/createTheme/createThemeFromColorScheme.d.ts +3 -1
  153. package/styles/theme/createTheme/createThemeFromColorScheme.d.ts.map +1 -1
  154. package/styles/theme/createTheme/createThemeFromColorScheme.js +4 -2
  155. package/styles/theme/createTheme/createTypography.d.ts +2 -1
  156. package/styles/theme/createTheme/createTypography.js +58 -18
  157. package/styles/theme/createTheme/index.d.ts +2 -2
  158. package/styles/theme/createTheme/index.d.ts.map +1 -1
  159. package/styles/theme/createTheme/index.js +2 -2
  160. package/styles/theme/createTheme/types.d.ts +9 -2
  161. package/styles/theme/createTheme/types.d.ts.map +1 -1
  162. package/styles/theme/createTheme/types.js +6 -0
  163. package/styles/theme/hooks/useColorScheme.d.ts +2 -2
  164. package/styles/theme/hooks/useColorScheme.d.ts.map +1 -1
  165. package/styles/theme/hooks/useColorScheme.js +1 -1
  166. package/styles/theme/hooks/useMediaQuery.d.ts +7 -0
  167. package/styles/theme/hooks/useMediaQuery.d.ts.map +1 -1
  168. package/styles/theme/hooks/useMediaQuery.js +5 -5
  169. package/styles/theme/hooks/useTheme.js +1 -1
  170. package/styles/theme/index.d.ts +3 -1
  171. package/styles/theme/index.d.ts.map +1 -1
  172. package/styles/theme/providers/ColorSchemeContext.d.ts +30 -9
  173. package/styles/theme/providers/ColorSchemeContext.d.ts.map +1 -1
  174. package/styles/theme/providers/ColorSchemeContext.js +8 -0
  175. package/styles/theme/providers/ThemeContext.d.ts +3 -0
  176. package/styles/theme/providers/ThemeContext.d.ts.map +1 -0
  177. package/styles/theme/providers/ThemeContext.js +2 -0
  178. package/styles/theme/providers/ThemeProvider.d.ts +2 -2
  179. package/styles/theme/providers/ThemeProvider.d.ts.map +1 -1
  180. package/styles/theme/providers/ThemeProvider.js +58 -16
  181. package/styles/theme/utils/color.d.ts +12 -12
  182. package/styles/theme/utils/color.d.ts.map +1 -1
  183. package/tracking/components/CookieConsentModal/index.js +3 -4
  184. package/tracking/components/PrivacySettings/index.js +3 -3
  185. package/cart/components/PaymentBar/PaymentBarReserveButton.connector.js +0 -6
  186. package/cart/components/PaymentBar/PaymentBarReserveButton.js +0 -71
  187. package/locations/components/StoreFinder/StoreFinderGetDirectionsButton.connector.js +0 -16
  188. package/locations/components/StoreFinder/StoreFinderGetDirectionsButton.js +0 -52
@@ -1 +1 @@
1
- {"version":3,"file":"createThemeFromColorScheme.d.ts","sourceRoot":"","sources":["../../../../styles/theme/createTheme/createThemeFromColorScheme.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAcpE;;;;;GAKG;AACH,eAAO,MAAM,KAAK,GAChB,OAAO,MAAM,EACb,aAAa,MAAM,GAAG,MAAM,KAC3B,MAAkH,CAAC;AAEtH;;;;;GAKG;AACH,eAAO,MAAM,OAAO,GAClB,OAAO,MAAM,EACb,cAAa,MAAM,GAAG,MAAY,KACjC,MAAuF,CAAC;AAE3F;;;;;GAKG;AACH,eAAO,MAAM,MAAM,GACjB,OAAO,MAAM,EACb,cAAa,MAAM,GAAG,MAAY,KACjC,MAAuF,CAAC;AAE3F;;;;;GAKG;AACH,eAAO,MAAM,aAAa,GACxB,OAAO,MAAM,KACZ,MAA4D,CAAC;AAEhE;;;;GAIG;AACH,QAAA,MAAM,0BAA0B,GAAI,aAAa,kBAAkB,KAAG,gBA4BrE,CAAC;AAEF,eAAe,0BAA0B,CAAC"}
1
+ {"version":3,"file":"createThemeFromColorScheme.d.ts","sourceRoot":"","sources":["../../../../styles/theme/createTheme/createThemeFromColorScheme.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAcpE;;;;;GAKG;AACH,eAAO,MAAM,KAAK,GAChB,OAAO,MAAM,EACb,aAAa,MAAM,GAAG,MAAM,KAC3B,MAAkH,CAAC;AAEtH;;;;;GAKG;AACH,eAAO,MAAM,OAAO,GAClB,OAAO,MAAM,EACb,cAAa,MAAM,GAAG,MAAY,KACjC,MAAuF,CAAC;AAE3F;;;;;GAKG;AACH,eAAO,MAAM,MAAM,GACjB,OAAO,MAAM,EACb,cAAa,MAAM,GAAG,MAAY,KACjC,MAAuF,CAAC;AAE3F;;;;;GAKG;AACH,eAAO,MAAM,aAAa,GACxB,OAAO,MAAM,KACZ,MAA4D,CAAC;AAEhE;;;;;;GAMG;AACH,QAAA,MAAM,0BAA0B,GAC9B,aAAa,kBAAkB,EAC/B,eAAe,MAAM,KACpB,gBA4BF,CAAC;AAEF,eAAe,0BAA0B,CAAC"}
@@ -50,9 +50,11 @@ export const contrastColor = color => `oklch(from ${color} var(--__l) 0 h / var(
50
50
  /**
51
51
  * Creates a theme object for a given color scheme (light or dark).
52
52
  * @param colorScheme The color scheme options.
53
+ * @param cssVarPrefix The theme's css variable prefix. Typography references some of the properties
54
+ * that are generated from it later, so it has to compose the same names.
53
55
  * @returns A theme object for the given color scheme.
54
56
  */
55
- const createThemeFromColorScheme = colorScheme => {
57
+ const createThemeFromColorScheme = (colorScheme, cssVarPrefix) => {
56
58
  const {
57
59
  palette: paletteInput = {},
58
60
  typography: typographyInput = {},
@@ -60,7 +62,7 @@ const createThemeFromColorScheme = colorScheme => {
60
62
  shape: shapeInput = {}
61
63
  } = colorScheme;
62
64
  const palette = createPalette(paletteInput);
63
- const typography = createTypography(palette, typographyInput);
65
+ const typography = createTypography(palette, typographyInput, cssVarPrefix);
64
66
  const components = createComponents(componentsInput);
65
67
  const shape = createShape(shapeInput);
66
68
  const theme = {
@@ -51,5 +51,6 @@ export interface TypographyOptions
51
51
 
52
52
  export default function createTypography(
53
53
  palette: Palette,
54
- typography: TypographyOptions | ((palette: Palette) => TypographyOptions)
54
+ typography: TypographyOptions | ((palette: Palette) => TypographyOptions),
55
+ cssVarPrefix?: string
55
56
  ): Typography;
@@ -1,19 +1,41 @@
1
1
  import _merge from "lodash/merge";
2
- import { isDev } from '@shopgate/engage/core/helpers';
2
+ // Imported from the defining modules rather than a barrel: this module runs at import time in
3
+ // every spec that touches the theme, and specs that replace a barrel with a partial mock would
4
+ // leave these undefined.
5
+ import { isDev } from '@shopgate/pwa-common/helpers/environment';
6
+ import { themeConfig } from '@shopgate/pwa-common/helpers/config';
7
+ const {
8
+ fontWeight: buttonFontWeight = 600,
9
+ textTransform: buttonTextTransform
10
+ } = themeConfig?.variables?.buttonBase ?? {};
3
11
  const caseAllCaps = {
4
12
  textTransform: 'uppercase'
5
13
  };
14
+ const caseButton = {
15
+ textTransform: buttonTextTransform === 'uppercase' ? 'uppercase' : 'none'
16
+ };
6
17
  const defaultFontFamily = '"Roboto", "Helvetica", "Arial", sans-serif';
7
18
 
19
+ /**
20
+ * Builds the prefix of the custom properties that cssVarsParser derives from the `typography` keys.
21
+ * Mirrors how the parser composes a name, so a theme configured with a different `cssVarPrefix`
22
+ * references the properties it actually emits.
23
+ * @param {string} cssVarPrefix The theme's css variable prefix.
24
+ * @returns {string} The prefix, e.g. `--sg-typography`.
25
+ */
26
+ const typographyVarPrefix = cssVarPrefix => `--${cssVarPrefix ? `${cssVarPrefix}-` : ''}typography`;
27
+
8
28
  /**
9
29
  * Creates the typography object for the theme.
10
30
  * @param {Object} palette The theme palette.
11
31
  * @param {Object|Function} typography The typography options or a function that returns them.
32
+ * @param {string} [cssVarPrefix] The theme's css variable prefix, matching the one cssVarsParser
33
+ * generates the properties with. Defaults to the `sg` default of createTheme.
12
34
  * @returns {Object} The typography object.
13
35
  * @see @link{https://material.io/design/typography/the-type-system.html}
14
36
  * @see @link{https://material.io/design/typography/understanding-typography.html}
15
37
  */
16
- export default function createTypography(palette, typography) {
38
+ export default function createTypography(palette, typography, cssVarPrefix = 'sg') {
17
39
  const {
18
40
  fontFamily = defaultFontFamily,
19
41
  // The default font size of the Material Specification.
@@ -37,6 +59,23 @@ export default function createTypography(palette, typography) {
37
59
  }
38
60
  }
39
61
  const coef = fontSize / 14;
62
+ const fontWeights = {
63
+ fontWeightLight,
64
+ fontWeightRegular,
65
+ fontWeightMedium,
66
+ fontWeightBold
67
+ };
68
+
69
+ /**
70
+ * Builds a reference to one of the shared font weight custom properties. The property itself is
71
+ * emitted by cssVarsParser from `typography.fontWeight*`, so overriding it on `:root` (admin css,
72
+ * live preview, an extension) cascades into every variant that uses that token. The resolved
73
+ * weight stays as the fallback, so the variant still renders when the property is absent.
74
+ * @param {string} token One of `fontWeightLight`, `fontWeightRegular`, `fontWeightMedium`,
75
+ * `fontWeightBold`.
76
+ * @returns {string} The css var reference.
77
+ */
78
+ const fontWeightVar = token => `var(${typographyVarPrefix(cssVarPrefix)}-${token}, ${fontWeights[token]})`;
40
79
 
41
80
  /**
42
81
  * Calculates a rem value for a passed pixel value.
@@ -47,34 +86,35 @@ export default function createTypography(palette, typography) {
47
86
 
48
87
  /**
49
88
  * Creates a typography variant object.
50
- * @param {number} fontWeight The font weight to use for the variant.
89
+ * @param {string} fontWeightToken The name of the shared font weight token to use, e.g.
90
+ * `fontWeightBold`. The variant references it as a custom property instead of inlining its value.
51
91
  * @param {number} size Font size in pixels.
52
92
  * @param {number} lineHeight Line height as a unitless number.
53
93
  * @param {Object} casing Casing styles to apply, e.g. textTransform.
54
94
  * @returns {Object} The typography variant object.
55
95
  */
56
- const buildVariant = (fontWeight, size, lineHeight, casing) => ({
96
+ const buildVariant = (fontWeightToken, size, lineHeight, casing) => ({
57
97
  fontFamily,
58
- fontWeight,
98
+ fontWeight: fontWeightVar(fontWeightToken),
59
99
  fontSize: pxToRem(size),
60
100
  lineHeight,
61
101
  ...casing,
62
102
  ...allVariants
63
103
  });
64
104
  const variants = {
65
- h1: buildVariant(fontWeightBold, 34, 1.15),
66
- h2: buildVariant(fontWeightBold, 22, 1.3),
67
- h3: buildVariant(fontWeightMedium, 20, 1.35),
68
- h4: buildVariant(fontWeightMedium, 18, 1.4),
69
- h5: buildVariant(fontWeightMedium, 16, 1.5),
70
- h6: buildVariant(fontWeightMedium, 14, 1.5),
71
- subtitle1: buildVariant(fontWeightRegular, 16, 1.75),
72
- subtitle2: buildVariant(fontWeightMedium, 14, 1.57),
73
- body1: buildVariant(fontWeightRegular, 16, 1.5),
74
- body2: buildVariant(fontWeightRegular, 14, 1.43),
75
- button: buildVariant(fontWeightMedium, 14, 1.75, caseAllCaps),
76
- caption: buildVariant(fontWeightRegular, 12, 1.66),
77
- overline: buildVariant(fontWeightRegular, 12, 2.66, caseAllCaps)
105
+ h1: buildVariant('fontWeightBold', 34, 1.15),
106
+ h2: buildVariant('fontWeightBold', 22, 1.3),
107
+ h3: buildVariant('fontWeightMedium', 20, 1.35),
108
+ h4: buildVariant('fontWeightMedium', 18, 1.4),
109
+ h5: buildVariant('fontWeightMedium', 16, 1.5),
110
+ h6: buildVariant('fontWeightMedium', 14, 1.5),
111
+ subtitle1: buildVariant('fontWeightRegular', 16, 1.75),
112
+ subtitle2: buildVariant('fontWeightMedium', 14, 1.57),
113
+ body1: buildVariant('fontWeightRegular', 16, 1.5),
114
+ body2: buildVariant('fontWeightRegular', 14, 1.43),
115
+ button: buildVariant(buttonFontWeight > fontWeightMedium ? 'fontWeightBold' : 'fontWeightMedium', 16, 1.75, caseButton),
116
+ caption: buildVariant('fontWeightRegular', 12, 1.66),
117
+ overline: buildVariant('fontWeightRegular', 12, 2.66, caseAllCaps)
78
118
  };
79
119
  return _merge({
80
120
  pxToRem,
@@ -1,6 +1,6 @@
1
1
  import { type ThemeOptions, type ThemeInternal } from './types';
2
- export type { Theme, BaseTheme, ThemeInternal, ThemeOptions, Breakpoint, ColorSchemeName, ColorSchemeSelectorType, PaletteColorsWithMain, } from './types';
3
- export { COLOR_SCHEME_NAMES } from './types';
2
+ export type { Theme, BaseTheme, ThemeInternal, ThemeOptions, Breakpoint, ColorSchemeName, ColorSchemeMode, ColorSchemeSelectorType, PaletteColorsWithMain, } from './types';
3
+ export { COLOR_SCHEME_NAMES, COLOR_SCHEME_SYSTEM } from './types';
4
4
  /**
5
5
  * Creates a theme object for the ThemeProvider.
6
6
  * @param options The theme options.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../styles/theme/createTheme/index.ts"],"names":[],"mappings":"AAUA,OAAO,EACL,KAAK,YAAY,EAGjB,KAAK,aAAa,EACnB,MAAM,SAAS,CAAC;AAEjB,YAAY,EACV,KAAK,EACL,SAAS,EACT,aAAa,EACb,YAAY,EACZ,UAAU,EACV,eAAe,EACf,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAE7C;;;;GAIG;AACH,eAAO,MAAM,WAAW,GAAI,UAAS,YAAiB,KAAG,aAkExD,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../styles/theme/createTheme/index.ts"],"names":[],"mappings":"AAUA,OAAO,EACL,KAAK,YAAY,EAGjB,KAAK,aAAa,EACnB,MAAM,SAAS,CAAC;AAEjB,YAAY,EACV,KAAK,EACL,SAAS,EACT,aAAa,EACb,YAAY,EACZ,UAAU,EACV,eAAe,EACf,eAAe,EACf,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAElE;;;;GAIG;AACH,eAAO,MAAM,WAAW,GAAI,UAAS,YAAiB,KAAG,aAkExD,CAAC"}
@@ -9,7 +9,7 @@ import createThemeFromColorScheme from "./createThemeFromColorScheme";
9
9
  import createCssVarsForColorSchemeThemes from "./createCssVarsForColorSchemeThemes";
10
10
  import applyStyles from "./applyStyles";
11
11
  import { createGetColorSchemeSelector, createSetActiveColorScheme } from "./helpers";
12
- export { COLOR_SCHEME_NAMES } from "./types";
12
+ export { COLOR_SCHEME_NAMES, COLOR_SCHEME_SYSTEM } from "./types";
13
13
 
14
14
  /**
15
15
  * Creates a theme object for the ThemeProvider.
@@ -38,7 +38,7 @@ export const createTheme = (options = {}) => {
38
38
  palette: {
39
39
  mode: type
40
40
  }
41
- }, defaultScheme, scheme));
41
+ }, defaultScheme, scheme), cssVarPrefix);
42
42
  return acc;
43
43
  }, {});
44
44
  const getColorSchemeSelector = createGetColorSchemeSelector(colorSchemeSelector);
@@ -15,6 +15,11 @@ export type { Breakpoint } from './createBreakpoints';
15
15
  export type { PaletteColorsWithMain } from './createPalette';
16
16
  export declare const COLOR_SCHEME_NAMES: readonly ["light", "dark"];
17
17
  export type ColorSchemeName = (typeof COLOR_SCHEME_NAMES)[number];
18
+ export declare const COLOR_SCHEME_SYSTEM = "system";
19
+ /**
20
+ * A selectable color scheme: one the theme provides, or `system` to follow the operating system.
21
+ */
22
+ export type ColorSchemeMode = ColorSchemeName | typeof COLOR_SCHEME_SYSTEM;
18
23
  declare const selectorTypes: readonly ["data", "class"];
19
24
  export type ColorSchemeSelectorType = (typeof selectorTypes)[number];
20
25
  type DeepPartial<T> = T extends object ? {
@@ -28,7 +33,8 @@ type DeepPartial<T> = T extends object ? {
28
33
  export type ColorSchemeOptions = Pick<ThemeOptions, 'palette' | 'typography' | 'components' | 'shape'>;
29
34
  export interface ThemeOptions {
30
35
  /**
31
- * The default color scheme to use when the user has not specified a preference.
36
+ * The color scheme to fall back to when the configured mode resolves to a scheme this theme does
37
+ * not style. The scheme the app starts in comes from the app settings.
32
38
  * @default 'light'
33
39
  */
34
40
  defaultColorScheme?: ColorSchemeName;
@@ -129,7 +135,8 @@ export interface BaseTheme {
129
135
  }
130
136
  export interface Theme extends BaseTheme {
131
137
  /**
132
- * The default color scheme to use when the user has not specified a preference.
138
+ * The color scheme to fall back to when the configured mode resolves to a scheme this theme does
139
+ * not style. The scheme the app starts in comes from the app settings.
133
140
  */
134
141
  defaultColorScheme?: ColorSchemeName;
135
142
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../styles/theme/createTheme/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACvF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iB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A4C,EAAE,qBAAqB,CAAC,GAAG;IAC9E;;OAEG;IACH,sBAAsB,EAAE,sBAAsB,CAAC;IAC/C;;OAEG;IACH,oBAAoB,EAAE,yBAAyB,CAAC;CACjD,CAAC"}
@@ -1,4 +1,10 @@
1
1
  export const COLOR_SCHEME_NAMES = ['light', 'dark'];
2
+ export const COLOR_SCHEME_SYSTEM = 'system';
3
+
4
+ /**
5
+ * A selectable color scheme: one the theme provides, or `system` to follow the operating system.
6
+ */
7
+
2
8
  const selectorTypes = ['data', 'class'];
3
9
 
4
10
  /**
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * Provides access to the color scheme context.
3
3
  * @returns The color scheme context value, containing the current `mode`, a `setMode` function to
4
- * update it, and the list of `modes` the active theme actually provides.
4
+ * update it, and the `modes` that can be set.
5
5
  */
6
- declare const useColorScheme: () => import("../providers/ColorSchemeContext").ColorSchemeContextValue;
6
+ declare const useColorScheme: () => import("..").ColorSchemeContextValue;
7
7
  export default useColorScheme;
8
8
  //# sourceMappingURL=useColorScheme.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useColorScheme.d.ts","sourceRoot":"","sources":["../../../../styles/theme/hooks/useColorScheme.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,QAAA,MAAM,cAAc,yEAAuC,CAAC;AAE5D,eAAe,cAAc,CAAC"}
1
+ {"version":3,"file":"useColorScheme.d.ts","sourceRoot":"","sources":["../../../../styles/theme/hooks/useColorScheme.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,QAAA,MAAM,cAAc,4CAAuC,CAAC;AAE5D,eAAe,cAAc,CAAC"}
@@ -4,7 +4,7 @@ import { ColorSchemeContext } from "../providers/ColorSchemeContext";
4
4
  /**
5
5
  * Provides access to the color scheme context.
6
6
  * @returns The color scheme context value, containing the current `mode`, a `setMode` function to
7
- * update it, and the list of `modes` the active theme actually provides.
7
+ * update it, and the `modes` that can be set.
8
8
  */
9
9
  const useColorScheme = () => useContext(ColorSchemeContext);
10
10
  export default useColorScheme;
@@ -1,4 +1,11 @@
1
1
  import { type Theme } from '..';
2
+ /**
3
+ * React hook to check if a media query matches the current viewport. Independent of the theme
4
+ * context, so it can be used by the provider that establishes it.
5
+ * @param query A media query string, e.g. '(min-width: 600px)'
6
+ * @returns Returns true if the media query matches, false otherwise.
7
+ */
8
+ export declare const useMatchMedia: (query: string) => boolean;
2
9
  /**
3
10
  * @callback ThemeFn
4
11
  * @param {Theme} theme The current theme object.
@@ -1 +1 @@
1
- {"version":3,"file":"useMediaQuery.d.ts","sourceRoot":"","sources":["../../../../styles/theme/hooks/useMediaQuery.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,IAAI,CAAC;AA8BhC;;;GAGG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,QAAA,MAAM,aAAa,GAAI,YAAY,MAAM,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,KAAK,MAAM,CAAC,KAAG,OASxE,CAAC;AAEF,eAAe,aAAa,CAAC"}
1
+ {"version":3,"file":"useMediaQuery.d.ts","sourceRoot":"","sources":["../../../../styles/theme/hooks/useMediaQuery.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,IAAI,CAAC;AAEhC;;;;;GAKG;AACH,eAAO,MAAM,aAAa,GAAI,OAAO,MAAM,KAAG,OAoB7C,CAAC;AAEF;;;GAGG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,QAAA,MAAM,aAAa,GAAI,YAAY,MAAM,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,KAAK,MAAM,CAAC,KAAG,OASxE,CAAC;AAEF,eAAe,aAAa,CAAC"}
@@ -2,12 +2,12 @@ import "core-js/modules/es.string.replace.js";
2
2
  import { useState, useEffect } from 'react';
3
3
  import useTheme from "./useTheme";
4
4
  /**
5
- * React hook to check if a media query matches the current viewport.
6
- * Doesn't accept media query strings that start with '@media'.
5
+ * React hook to check if a media query matches the current viewport. Independent of the theme
6
+ * context, so it can be used by the provider that establishes it.
7
7
  * @param query A media query string, e.g. '(min-width: 600px)'
8
8
  * @returns Returns true if the media query matches, false otherwise.
9
9
  */
10
- const useMediaQueryInternal = query => {
10
+ export const useMatchMedia = query => {
11
11
  const [match, setMatch] = useState(() => window.matchMedia(query).matches);
12
12
  useEffect(() => {
13
13
  const queryList = window.matchMedia(query);
@@ -60,9 +60,9 @@ const useMediaQueryInternal = query => {
60
60
  const useMediaQuery = queryInput => {
61
61
  const theme = useTheme();
62
62
  let query = typeof queryInput === 'function' ? queryInput(theme) : queryInput;
63
- // Remove the '@media' prefix if it exists, as useMediaQueryInternal expects a plain media query.
63
+ // Remove the '@media' prefix if it exists, as useMatchMedia expects a plain media query.
64
64
  query = query.replace(/^@media( ?)/m, '');
65
- const match = useMediaQueryInternal(query);
65
+ const match = useMatchMedia(query);
66
66
  return match;
67
67
  };
68
68
  export default useMediaQuery;
@@ -1,5 +1,5 @@
1
1
  import { useContext } from 'react';
2
- import { ThemeContext } from "../providers/ThemeProvider";
2
+ import { ThemeContext } from "../providers/ThemeContext";
3
3
 
4
4
  /**
5
5
  * Returns the theme object.
@@ -1,7 +1,9 @@
1
1
  export { default as ThemeProvider } from './providers/ThemeProvider';
2
2
  export { createTheme } from './createTheme';
3
3
  export { type ShadowSize } from './createTheme/shadows';
4
- export type { Theme, Breakpoint, PaletteColorsWithMain, ColorSchemeName, } from './createTheme';
4
+ export type { Variant as TypographyVariant } from './createTheme/createTypography';
5
+ export type { Theme, Breakpoint, PaletteColorsWithMain, ColorSchemeName, ColorSchemeMode, } from './createTheme';
5
6
  export { useActiveBreakpoint, useMediaQuery, useResponsiveValue, useTheme, useColorScheme, } from './hooks';
6
7
  export { withTheme, type WithThemeProps } from './hocs';
8
+ export type { ColorSchemeContextValue } from './providers/ColorSchemeContext';
7
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../styles/theme/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,YAAY,EACV,KAAK,EAAE,UAAU,EAAE,qBAAqB,EAAE,eAAe,GAC1D,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,kBAAkB,EAClB,QAAQ,EACR,cAAc,GACf,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,SAAS,EAAE,KAAK,cAAc,EAAE,MAAM,QAAQ,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../styles/theme/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,YAAY,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnF,YAAY,EACV,KAAK,EAAE,UAAU,EAAE,qBAAqB,EAAE,eAAe,EAAE,eAAe,GAC3E,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,kBAAkB,EAClB,QAAQ,EACR,cAAc,GACf,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,SAAS,EAAE,KAAK,cAAc,EAAE,MAAM,QAAQ,CAAC;AACxD,YAAY,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC"}
@@ -1,19 +1,40 @@
1
- import { type Dispatch, type SetStateAction } from 'react';
2
- import { type ColorSchemeName } from '../createTheme';
1
+ import { type ColorSchemeMode, type ColorSchemeName } from '../createTheme';
2
+ /**
3
+ * A new mode, or an updater that receives the effective one. Null clears the visitor's pick.
4
+ */
5
+ export type SetColorSchemeMode = ColorSchemeMode | null | ((current: ColorSchemeMode) => ColorSchemeMode | null);
3
6
  export interface ColorSchemeContextValue {
4
7
  /**
5
- * The current color scheme (e.g., 'light' or 'dark')
8
+ * The mode in effect: the one the visitor picked, or the configured default while they picked
9
+ * none.
6
10
  */
7
- mode: ColorSchemeName | null;
11
+ mode: ColorSchemeMode;
8
12
  /**
9
- * Function to update the color scheme
13
+ * The mode that applies while the visitor picked none, as configured within the app settings.
10
14
  */
11
- setMode: Dispatch<SetStateAction<ColorSchemeName | null>>;
15
+ defaultMode: ColorSchemeMode;
12
16
  /**
13
- * The modes the active theme actually provides. Only these can be set - passing anything else
14
- * to setMode has no effect.
17
+ * The color scheme that is applied - the mode resolved against the operating system and the
18
+ * configured default. Components style against this one.
15
19
  */
16
- modes: ColorSchemeName[];
20
+ activeColorScheme: ColorSchemeName | null;
21
+ /**
22
+ * Whether visitors may pick a color scheme themselves. False while the app settings configure a
23
+ * binding color scheme, in which case a stored pick is ignored. Always true in development
24
+ * builds, which have no app settings to configure. A picker should render only where this is
25
+ * true.
26
+ */
27
+ canSelectColorScheme: boolean;
28
+ /**
29
+ * Updates the color scheme. Setting null clears the visitor's pick, so the configured default
30
+ * applies again. Takes effect only while `canSelectColorScheme` is true.
31
+ */
32
+ setMode: (value: SetColorSchemeMode) => void;
33
+ /**
34
+ * Everything that can be set: the color schemes the active theme styles, plus 'system'. Passing
35
+ * anything else to setMode has no effect.
36
+ */
37
+ modes: ColorSchemeMode[];
17
38
  }
18
39
  export declare const ColorSchemeContext: import("react").Context<ColorSchemeContextValue>;
19
40
  //# sourceMappingURL=ColorSchemeContext.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ColorSchemeContext.d.ts","sourceRoot":"","sources":["../../../../styles/theme/providers/ColorSchemeContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,QAAQ,EAAE,KAAK,cAAc,EAAE,MAAM,OAAO,CAAC;AAC1E,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEtD,MAAM,WAAW,uBAAuB;IACtC;;OAEG;IACH,IAAI,EAAE,eAAe,GAAG,IAAI,CAAC;IAC7B;;OAEG;IACH,OAAO,EAAE,QAAQ,CAAC,cAAc,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC,CAAC;IAC1D;;;OAGG;IACH,KAAK,EAAE,eAAe,EAAE,CAAC;CAC1B;AAED,eAAO,MAAM,kBAAkB,kDAI7B,CAAC"}
1
+ {"version":3,"file":"ColorSchemeContext.d.ts","sourceRoot":"","sources":["../../../../styles/theme/providers/ColorSchemeContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,eAAe,EAAE,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAE5E;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAC1B,eAAe,GACf,IAAI,GACJ,CAAC,CAAC,OAAO,EAAE,eAAe,KAAK,eAAe,GAAG,IAAI,CAAC,CAAC;AAE3D,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,IAAI,EAAE,eAAe,CAAC;IACtB;;OAEG;IACH,WAAW,EAAE,eAAe,CAAC;IAC7B;;;OAGG;IACH,iBAAiB,EAAE,eAAe,GAAG,IAAI,CAAC;IAC1C;;;;;OAKG;IACH,oBAAoB,EAAE,OAAO,CAAC;IAC9B;;;OAGG;IACH,OAAO,EAAE,CAAC,KAAK,EAAE,kBAAkB,KAAK,IAAI,CAAC;IAC7C;;;OAGG;IACH,KAAK,EAAE,eAAe,EAAE,CAAC;CAC1B;AAED,eAAO,MAAM,kBAAkB,kDAO7B,CAAC"}
@@ -1,6 +1,14 @@
1
1
  import { createContext } from 'react';
2
+
3
+ /**
4
+ * A new mode, or an updater that receives the effective one. Null clears the visitor's pick.
5
+ */
6
+
2
7
  export const ColorSchemeContext = /*#__PURE__*/createContext({
3
8
  mode: 'light',
9
+ defaultMode: 'light',
10
+ activeColorScheme: 'light',
11
+ canSelectColorScheme: false,
4
12
  setMode: () => undefined,
5
13
  modes: ['light']
6
14
  });
@@ -0,0 +1,3 @@
1
+ import { type Theme } from '../createTheme';
2
+ export declare const ThemeContext: import("react").Context<Theme>;
3
+ //# sourceMappingURL=ThemeContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ThemeContext.d.ts","sourceRoot":"","sources":["../../../../styles/theme/providers/ThemeContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAE5C,eAAO,MAAM,YAAY,gCAAqC,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { createContext } from 'react';
2
+ export const ThemeContext = /*#__PURE__*/createContext({});
@@ -1,6 +1,6 @@
1
- import { type Theme, type ThemeInternal } from '../createTheme';
1
+ import { type ThemeInternal } from '../createTheme';
2
2
  export { ColorSchemeContext, type ColorSchemeContextValue } from './ColorSchemeContext';
3
- export declare const ThemeContext: import("react").Context<Theme>;
3
+ export { ThemeContext } from './ThemeContext';
4
4
  type ThemeProviderProps = {
5
5
  /**
6
6
  * The theme object to provide to the context.
@@ -1 +1 @@
1
- {"version":3,"file":"ThemeProvider.d.ts","sourceRoot":"","sources":["../../../../styles/theme/providers/ThemeProvider.tsx"],"names":[],"mappings":"AAUA,OAAO,EACL,KAAK,KAAK,EAAE,KAAK,aAAa,EAC/B,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,kBAAkB,EAAE,KAAK,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAExF,eAAO,MAAM,YAAY,gCAAqC,CAAC;AAwE/D,KAAK,kBAAkB,GAAG;IACxB;;OAEG;IACH,KAAK,EAAE,aAAa,CAAC;IACrB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,CAAA;mFAtEE,kBAAkB;AAwErB,wBAAmC"}
1
+ {"version":3,"file":"ThemeProvider.d.ts","sourceRoot":"","sources":["../../../../styles/theme/providers/ThemeProvider.tsx"],"names":[],"mappings":"AAgBA,OAAO,EACgB,KAAK,aAAa,EACxC,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,kBAAkB,EAAE,KAAK,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AACxF,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAuH9C,KAAK,kBAAkB,GAAG;IACxB;;OAEG;IACH,KAAK,EAAE,aAAa,CAAC;IACrB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,CAAA;mFArHE,kBAAkB;AAuHrB,wBAAmC"}
@@ -1,15 +1,22 @@
1
1
  import "core-js/modules/es.array.includes.js";
2
- import { createContext, memo, useCallback, useMemo, useLayoutEffect } from 'react';
2
+ import { memo, useCallback, useEffect, useMemo, useLayoutEffect } from 'react';
3
+ import { useSelector } from 'react-redux';
3
4
  import useLocalStorage from '@shopgate/engage/core/hooks/useLocalStorage';
4
5
  import { logger } from '@shopgate/engage/core/helpers';
5
6
  import { GlobalStyles } from '@shopgate/engage/styles';
6
7
  import { isFrontendSettingsAdminPreviewActive } from '@shopgate/engage/admin-preview/helpers';
7
8
  import { FrontendSettingsPreviewBridge } from '@shopgate/engage/admin-preview/components';
9
+ // Imported via its module path rather than a settings barrel, to keep this module out of an import
10
+ // cycle - the settings types reach back into the "styles/theme" barrel, which exports this file.
11
+ import { getCanSelectColorScheme, getDefaultColorSchemeMode } from '@shopgate/engage/settings/selectors/appSettings';
8
12
  import ActiveBreakpointProvider from "./ActiveBreakpointProvider";
9
13
  import { ColorSchemeContext } from "./ColorSchemeContext";
14
+ import { ThemeContext } from "./ThemeContext";
15
+ import { useMatchMedia } from "../hooks/useMediaQuery";
16
+ import { COLOR_SCHEME_SYSTEM } from "../createTheme";
10
17
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
18
  export { ColorSchemeContext } from "./ColorSchemeContext";
12
- export const ThemeContext = /*#__PURE__*/createContext({});
19
+ export { ThemeContext } from "./ThemeContext";
13
20
 
14
21
  /**
15
22
  * The ThemeProvider component provides the theme context to its children.
@@ -19,36 +26,71 @@ const ThemeProvider = ({
19
26
  theme
20
27
  }) => {
21
28
  // The color schemes the active theme actually provides. createTheme() can be configured with only
22
- // a subset of the possible schemes (it defaults to just `light`), so `modes` and the validation
29
+ // a subset of the possible schemes (it defaults to just `light`), so this list and the validation
23
30
  // below are derived from the resolved theme rather than the full COLOR_SCHEME_NAMES tuple.
24
31
  // Otherwise the provider could expose and accept a scheme (e.g. `dark`) the theme doesn't style,
25
32
  // and setActiveColorScheme would flip the root selector to an unstyled scheme.
26
- const modes = useMemo(() => Object.keys(theme.colorSchemes), [theme]);
27
- const [activeColorScheme, setActiveColorScheme] = useLocalStorage('persistedColorScheme', {
28
- initialValue: theme.defaultColorScheme,
33
+ const colorSchemes = useMemo(() => Object.keys(theme.colorSchemes), [theme]);
34
+ const defaultMode = useSelector(getDefaultColorSchemeMode);
35
+ const isColorSchemeSelectable = useSelector(getCanSelectColorScheme);
36
+
37
+ // Whether the merchant lets visitors choose. A binding `light` or `dark` rules a pick out, so one
38
+ // left over from when selecting still was allowed does not keep overriding it. Development builds
39
+ // have no app settings to configure at all, so both schemes stay reachable there.
40
+ const canSelectColorScheme = isColorSchemeSelectable || process.env.NODE_ENV === 'development';
41
+ const prefersDarkColorScheme = useMatchMedia('(prefers-color-scheme: dark)');
42
+ const systemColorScheme = prefersDarkColorScheme ? 'dark' : 'light';
43
+ const [pickedMode, setPersistedMode] = useLocalStorage('persistedColorScheme', {
29
44
  // The frontend settings preview runs the app in an iframe on the shop origin. Persisting the
30
45
  // color scheme there would write the admin's preview choice into the visitor's own storage and
31
46
  // outlive the preview, so the scheme is kept in memory only while previewing.
32
47
  persist: !isFrontendSettingsAdminPreviewActive()
33
48
  });
34
49
 
50
+ // The preview forces a scheme through the same setter to show the admin either appearance, which
51
+ // has to work regardless of what the previewed settings configure. It stays out of
52
+ // `canSelectColorScheme`, so the previewed shop offers a picker exactly where visitors get one.
53
+ const isPickApplied = canSelectColorScheme || isFrontendSettingsAdminPreviewActive();
54
+
55
+ // The mode the visitor picked wins where it applies, otherwise the configured one does. Resolving
56
+ // that on every render rather than seeding the storage with it keeps `system` following the
57
+ // operating system and lets the preview apply the merchant's edits live.
58
+ const mode = isPickApplied && pickedMode || defaultMode;
59
+ const resolvedColorScheme = useMemo(() => mode === COLOR_SCHEME_SYSTEM ? systemColorScheme : mode, [mode, systemColorScheme]);
60
+ const isSupportedColorScheme = colorSchemes.includes(resolvedColorScheme);
61
+ const activeColorScheme = isSupportedColorScheme ? resolvedColorScheme : theme.defaultColorScheme ?? null;
62
+ useEffect(() => {
63
+ if (isSupportedColorScheme) return;
64
+ logger.warn(`ThemeProvider: "${resolvedColorScheme}" is not a supported color scheme.`);
65
+ }, [isSupportedColorScheme, resolvedColorScheme]);
66
+
67
+ // What a picker can offer and what setMode accepts. 'system' is not a scheme the theme styles -
68
+ // it resolves to one above - so it is added here rather than derived from the theme.
69
+ const modes = useMemo(() => [].concat(colorSchemes, [COLOR_SCHEME_SYSTEM]), [colorSchemes]);
70
+
35
71
  // Wraps the raw storage setter, so an unsupported mode is rejected before it is persisted.
36
- // Setting null is allowed and clears the stored preference.
72
+ // Setting null is allowed and clears the stored preference, which returns to the configured one.
37
73
  const setMode = useCallback(value => {
38
- setActiveColorScheme(currentColorScheme => {
39
- const nextColorScheme = typeof value === 'function' ? value(currentColorScheme) : value;
40
- if (nextColorScheme !== null && !modes.includes(nextColorScheme)) {
41
- logger.warn(`ThemeProvider: "${nextColorScheme}" is not a supported color scheme.`);
42
- return currentColorScheme;
74
+ setPersistedMode(currentMode => {
75
+ // An updater is resolved the same way `mode` is, so it sees what the context exposes rather
76
+ // than the storage behind it - which holds no value yet, or one that is currently ignored.
77
+ const effectiveMode = isPickApplied && currentMode || defaultMode;
78
+ const nextMode = typeof value === 'function' ? value(effectiveMode) : value;
79
+ if (nextMode !== null && !modes.includes(nextMode)) {
80
+ logger.warn(`ThemeProvider: "${nextMode}" is not a supported color scheme.`);
81
+ return currentMode;
43
82
  }
44
- return nextColorScheme;
83
+ return nextMode;
45
84
  });
46
- }, [modes, setActiveColorScheme]);
85
+ }, [defaultMode, isPickApplied, modes, setPersistedMode]);
47
86
  const colorSchemeContextValue = useMemo(() => ({
48
- mode: activeColorScheme,
87
+ mode,
88
+ defaultMode,
89
+ activeColorScheme,
90
+ canSelectColorScheme,
49
91
  setMode,
50
92
  modes
51
- }), [activeColorScheme, modes, setMode]);
93
+ }), [mode, defaultMode, activeColorScheme, canSelectColorScheme, modes, setMode]);
52
94
  useLayoutEffect(() => {
53
95
  if (!activeColorScheme) return;
54
96
  theme.setActiveColorScheme(activeColorScheme);