@shopgate/engage 7.28.0-beta.6 → 7.29.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/category/components/CategoryImage/index.js +1 -1
- package/category/components/CategoryList/index.js +7 -3
- package/category/components/CategoryList/style.js +1 -1
- package/components/ResponsiveContainer/breakpoints.js +2 -2
- package/components/SheetList/components/Item/index.js +7 -7
- package/components/Typography/Typography.d.ts +132 -0
- package/components/Typography/Typography.js +11 -0
- package/components/Typography/index.js +1 -0
- package/components/View/components/Content/style.js +1 -1
- package/components/View/context.js +1 -1
- package/components/index.js +1 -1
- package/core/constants/index.js +7 -1
- package/core/contexts/ThemeResourcesContext.d.ts +10 -1
- package/core/contexts/ThemeResourcesContext.js +1 -1
- package/core/helpers/scrollContainer.js +2 -2
- package/core/hocs/withThemeResources.js +4 -1
- package/core/hooks/events/index.js +1 -1
- package/core/hooks/events/usePressHandler.js +38 -0
- package/core/hooks/useThemeResources.js +6 -5
- package/core/providers/ThemeResourcesProvider.js +9 -5
- package/locations/subscriptions.js +2 -2
- package/package.json +9 -7
- package/page/action-creators/index.js +22 -0
- package/page/components/Widgets/Overlay.js +51 -0
- package/page/components/Widgets/Tooltip.js +22 -0
- package/page/components/Widgets/Widget.js +17 -0
- package/page/components/Widgets/WidgetContext.d.ts +42 -0
- package/page/components/Widgets/WidgetContext.js +9 -0
- package/page/components/Widgets/WidgetProvider.js +8 -0
- package/page/components/Widgets/Widgets.js +11 -0
- package/page/components/Widgets/WidgetsPreviewContext.js +9 -0
- package/page/components/Widgets/WidgetsPreviewProvider.js +8 -0
- package/page/components/Widgets/constants.js +4 -0
- package/page/components/Widgets/events.js +23 -0
- package/page/components/Widgets/helpers.js +23 -0
- package/page/components/Widgets/hooks.js +69 -0
- package/page/components/Widgets/index.js +1 -0
- package/page/components/Widgets/types.d.ts +132 -0
- package/page/components/index.js +1 -1
- package/page/constants/actionTypes.js +1 -0
- package/page/constants/index.js +5 -1
- package/page/helpers/index.d.ts +47 -0
- package/page/helpers/index.js +12 -0
- package/page/hooks/index.d.ts +60 -0
- package/page/hooks/index.js +25 -0
- package/page/index.js +1 -2
- package/page/reducers/index.js +15 -0
- package/page/selectors/index.js +48 -2
- package/page/subscriptions/index.js +4 -0
- package/page/widgets/CategoryList/CategoryList.js +4 -0
- package/page/widgets/CategoryList/hooks.js +14 -0
- package/page/widgets/CategoryList/index.js +1 -0
- package/page/widgets/CategoryList/selectors.js +8 -0
- package/page/widgets/HTML/HTML.js +5 -0
- package/page/widgets/HTML/hooks.js +12 -0
- package/page/widgets/HTML/index.js +1 -0
- package/page/widgets/Headline/Headline.js +5 -0
- package/page/widgets/Headline/hooks.js +8 -0
- package/page/widgets/Headline/index.js +1 -0
- package/page/widgets/Placeholder/Placeholder.js +5 -0
- package/page/widgets/Placeholder/hooks.js +12 -0
- package/page/widgets/Placeholder/index.js +1 -0
- package/page/widgets/ProductList/ProductList.js +5 -0
- package/page/widgets/ProductList/hooks.js +19 -0
- package/page/widgets/ProductList/index.js +1 -0
- package/page/widgets/ProductSlider/ProductSlider.js +5 -0
- package/page/widgets/ProductSlider/hooks.js +22 -0
- package/page/widgets/ProductSlider/index.js +1 -0
- package/page/widgets/index.js +1 -0
- package/page/widgets/widgets.json +20 -0
- package/product/components/ProductCard/index.js +1 -1
- package/product/components/ProductGrid/components/Item/components/ItemDetails/index.js +8 -0
- package/product/components/ProductGrid/components/Item/components/ItemDetails/spec.js +1 -0
- package/product/components/ProductGrid/components/Item/components/ItemDiscount/index.js +5 -0
- package/product/components/ProductGrid/components/Item/components/ItemFavoritesButton/index.js +5 -0
- package/product/components/ProductGrid/components/Item/components/ItemFavoritesButton/spec.js +1 -0
- package/product/components/ProductGrid/components/Item/components/ItemImage/index.js +5 -0
- package/product/components/ProductGrid/components/Item/components/ItemImage/spec.js +1 -0
- package/product/components/ProductGrid/components/Item/components/ItemName/index.js +5 -0
- package/product/components/ProductGrid/components/Item/components/ItemName/spec.js +1 -0
- package/product/components/ProductGrid/components/Item/components/ItemPrice/index.js +5 -0
- package/product/components/ProductGrid/components/Item/components/ItemPrice/spec.js +1 -0
- package/product/components/ProductGrid/components/Item/index.js +7 -0
- package/product/components/ProductGrid/components/Iterator/index.js +5 -0
- package/product/components/ProductGrid/components/Layout/index.js +5 -0
- package/product/components/ProductGrid/index.js +22 -0
- package/product/components/ProductGrid/spec.js +1 -0
- package/product/components/ProductGridPrice/index.js +1 -1
- package/product/components/ProductSlider/index.js +4 -4
- package/product/components/index.js +1 -1
- package/styles/helpers/color.js +23 -0
- package/styles/helpers/index.js +1 -1
- package/styles/helpers/setPageBackgroundColor.js +2 -2
- package/styles/index.d.ts +17 -0
- package/styles/index.js +1 -1
- package/styles/theme/createTheme/createBreakpoints.d.ts +114 -0
- package/styles/theme/createTheme/createBreakpoints.js +41 -0
- package/styles/theme/createTheme/createPalette.d.ts +36 -0
- package/styles/theme/createTheme/createPalette.js +4 -0
- package/styles/theme/createTheme/createSpacing.d.ts +23 -0
- package/styles/theme/createTheme/createSpacing.js +14 -0
- package/styles/theme/createTheme/createTypography.d.ts +55 -0
- package/styles/theme/createTheme/createTypography.js +23 -0
- package/styles/theme/createTheme/index.d.ts +41 -0
- package/styles/theme/createTheme/index.js +5 -0
- package/styles/theme/createTheme/transitions.d.ts +100 -0
- package/styles/theme/createTheme/transitions.js +26 -0
- package/styles/theme/createTheme/zIndex.d.ts +12 -0
- package/styles/theme/createTheme/zIndex.js +3 -0
- package/styles/theme/hooks/index.d.ts +4 -0
- package/styles/theme/hooks/index.js +1 -0
- package/styles/theme/hooks/useActiveBreakpoint.d.ts +18 -0
- package/styles/theme/hooks/useActiveBreakpoint.js +4 -0
- package/styles/theme/hooks/useMediaQuery.d.ts +33 -0
- package/styles/theme/hooks/useMediaQuery.js +20 -0
- package/styles/theme/hooks/useResponsiveValue.d.ts +27 -0
- package/styles/theme/hooks/useResponsiveValue.js +4 -0
- package/styles/theme/hooks/useTheme.d.ts +8 -0
- package/styles/theme/hooks/useTheme.js +4 -0
- package/styles/theme/index.d.ts +8 -0
- package/styles/theme/index.js +1 -0
- package/styles/theme/providers/ActiveBreakpointProvider.d.ts +21 -0
- package/styles/theme/providers/ActiveBreakpointProvider.js +13 -0
- package/styles/theme/providers/ThemeProvider.d.ts +18 -0
- package/styles/theme/providers/ThemeProvider.js +7 -0
- package/styles/tss/index.js +3 -0
- package/tracking/selectors/cookieConsent.js +2 -2
|
@@ -2,5 +2,5 @@ import React,{Fragment}from'react';import PropTypes from'prop-types';import{Grid
|
|
|
2
2
|
* The ProductGridPrice component is supposed to be used to display prices at product grids. It
|
|
3
3
|
* renders a row with the current price and a strike price when present. As same as the price info.
|
|
4
4
|
* @param {Object} product A product entity.
|
|
5
|
-
* @return {JSX}
|
|
5
|
+
* @return {JSX.Element}
|
|
6
6
|
*/var ProductGridPrice=function ProductGridPrice(_ref){var product=_ref.product;var price=product.price;return React.createElement(Fragment,null,React.createElement(Grid,{className:"".concat(styles.priceWrapper," engage__product__product-grid-price"),wrap:true},React.createElement(Grid.Item,{grow:1},React.createElement(Price,{currency:price.currency,discounted:!!price.discount,unitPrice:price.unitPrice,unitPriceMin:price.unitPriceMin})),price.msrp>0&&price.unitPrice!==price.msrp&&React.createElement(Grid.Item,null,React.createElement(PriceStriked,{className:styles.strikedPrice,value:price.msrp,currency:price.currency})),!price.msrp&&price.unitPriceStriked>0&&price.unitPrice!==price.unitPriceStriked&&React.createElement(Grid.Item,null,React.createElement(PriceStriked,{className:styles.strikedPrice,value:price.unitPriceStriked,currency:price.currency}))),React.createElement(PriceInfo,{product:product,className:styles.basicPrice,wrapper:function wrapper(children){return React.createElement(Grid,null,React.createElement(Grid.Item,null,children));}}));};export default withPriceCalculation(ProductGridPrice);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}import React from'react';import PropTypes from'prop-types';import{useWidgetSettings}from'@shopgate/engage/core';import{useThemeComponents}from'@shopgate/engage/core/hooks';import{Swiper}from'@shopgate/engage/components';import{ProductListTypeProvider,ProductListEntryProvider}from'@shopgate/engage/product/providers';import{container,items}from"./style";export var WIDGET_ID='@shopgate/engage/product/ProductSlider';/**
|
|
1
|
+
var _excluded=["autoplay","className","delay","productIds","snap","scope","meta","productItemProps","item"];function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}function _objectWithoutProperties(source,excluded){if(source==null)return{};var target=_objectWithoutPropertiesLoose(source,excluded);var key,i;if(Object.getOwnPropertySymbols){var sourceSymbolKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceSymbolKeys.length;i++){key=sourceSymbolKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key];}}return target;}function _objectWithoutPropertiesLoose(source,excluded){if(source==null)return{};var target={};var sourceKeys=Object.keys(source);var key,i;for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;target[key]=source[key];}return target;}import React from'react';import PropTypes from'prop-types';import{useWidgetSettings}from'@shopgate/engage/core';import{useThemeComponents}from'@shopgate/engage/core/hooks';import{Swiper}from'@shopgate/engage/components';import{ProductListTypeProvider,ProductListEntryProvider}from'@shopgate/engage/product/providers';import{container,items}from"./style";export var WIDGET_ID='@shopgate/engage/product/ProductSlider';/**
|
|
2
2
|
* @param {Object} props The component props.
|
|
3
|
-
* @returns {JSX}
|
|
4
|
-
*/function ProductSlider(props){var autoplay=props.autoplay,className=props.className,delay=props.delay,productIds=props.productIds,snap=props.snap,scope=props.scope,meta=props.meta;var widgetSettings=useWidgetSettings(WIDGET_ID)||{};var _ref=props.slidesPerView?props:widgetSettings,_ref$slidesPerView=_ref.slidesPerView,slidesPerView=_ref$slidesPerView===void 0?2.3:_ref$slidesPerView;// ProductSlider items are rendered with the ProductCard component provided by the theme.
|
|
5
|
-
var _useThemeComponents=useThemeComponents(),ProductCard=_useThemeComponents.ProductCard;var Item=
|
|
3
|
+
* @returns {JSX.Element}
|
|
4
|
+
*/function ProductSlider(props){var autoplay=props.autoplay,className=props.className,delay=props.delay,productIds=props.productIds,snap=props.snap,scope=props.scope,meta=props.meta,productItemProps=props.productItemProps,item=props.item,swiperProps=_objectWithoutProperties(props,_excluded);var widgetSettings=useWidgetSettings(WIDGET_ID)||{};var _ref=props.slidesPerView?props:widgetSettings,_ref$slidesPerView=_ref.slidesPerView,slidesPerView=_ref$slidesPerView===void 0?2.3:_ref$slidesPerView;// ProductSlider items are rendered with the ProductCard component provided by the theme.
|
|
5
|
+
var _useThemeComponents=useThemeComponents(),ProductCard=_useThemeComponents.ProductCard;var Item=item||ProductCard;return React.createElement(ProductListTypeProvider,{type:"productSlider",subType:scope,meta:meta},React.createElement(Swiper,_extends({},autoplay&&{autoplay:{delay:delay}},{className:"".concat(className," engage__product__product-slider"),controls:false,indicators:false,freeMode:!snap},swiperProps,{slidesPerView:slidesPerView}),productIds.map(function(id){return React.createElement(Swiper.Item,{key:id,className:container},React.createElement(ProductListEntryProvider,{productId:id},React.createElement(Item,_extends({productId:id,style:items},productItemProps))));})));}ProductSlider.WIDGET_ID=WIDGET_ID;ProductSlider.defaultProps={autoplay:false,className:null,delay:10,item:null,meta:null,productItemProps:null,scope:null,slidesPerView:null,snap:false};export default ProductSlider;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export*from"./Availability";export{default as Characteristics}from"./Characteristics";export{default as Description}from"./Description";export{default as EffectivityDates}from"./EffectivityDates";export{default as MapPriceHint}from"./MapPriceHint";export*from"./Media";export{default as MediaSlider}from"./MediaSlider";export{default as Options}from"./Options";export{SelectOption,TextOption}from"./Options";export{default as OrderQuantityHint}from"./OrderQuantityHint";export{default as PriceDifference}from"./PriceDifference";export*from"./PriceInfo";export{default as ProductBadges}from"./ProductBadges";export{default as ProductCard}from"./ProductCard";export{default as ProductCharacteristics}from"./ProductCharacteristics";export{default as ProductDiscountBadge}from"./ProductDiscountBadge";export{default as ProductGridPrice}from"./ProductGridPrice";export{default as ProductImage}from"./ProductImage";export{default as ProductList}from"./ProductList";export*from"./ProductName";export{default as ProductProperties}from"./ProductProperties/ProductProperties";export{default as ProductSlider}from"./ProductSlider";export*from"./ProductVariants";export{default as QuantityPicker}from"./QuantityPicker";export{default as Rating}from"./Rating";export*from"./RelationsSlider";export*from"./Swatch";export*from"./Swatches";export*from"./UnitQuantityPicker";export{default as FilterBar}from"./FilterBar";export{default as ProductFilters}from"./ProductFilters";
|
|
1
|
+
export*from"./Availability";export{default as Characteristics}from"./Characteristics";export{default as Description}from"./Description";export{default as EffectivityDates}from"./EffectivityDates";export{default as MapPriceHint}from"./MapPriceHint";export*from"./Media";export{default as MediaSlider}from"./MediaSlider";export{default as Options}from"./Options";export{SelectOption,TextOption}from"./Options";export{default as OrderQuantityHint}from"./OrderQuantityHint";export{default as PriceDifference}from"./PriceDifference";export*from"./PriceInfo";export{default as ProductBadges}from"./ProductBadges";export{default as ProductCard}from"./ProductCard";export{default as ProductCharacteristics}from"./ProductCharacteristics";export{default as ProductDiscountBadge}from"./ProductDiscountBadge";export{default as ProductGrid}from"./ProductGrid";export{default as ProductGridPrice}from"./ProductGridPrice";export{default as ProductImage}from"./ProductImage";export{default as ProductList}from"./ProductList";export*from"./ProductName";export{default as ProductProperties}from"./ProductProperties/ProductProperties";export{default as ProductSlider}from"./ProductSlider";export*from"./ProductVariants";export{default as QuantityPicker}from"./QuantityPicker";export{default as Rating}from"./Rating";export*from"./RelationsSlider";export*from"./Swatch";export*from"./Swatches";export*from"./UnitQuantityPicker";export{default as FilterBar}from"./FilterBar";export{default as ProductFilters}from"./ProductFilters";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Import the Color constructor from the color.js package
|
|
2
|
+
import Color from'color';/**
|
|
3
|
+
* Converts any valid input color to an RGBA CSS string.
|
|
4
|
+
* If the input color already contains an alpha channel (< 1), that alpha is preserved.
|
|
5
|
+
* Otherwise, the provided `opacity` is applied.
|
|
6
|
+
*
|
|
7
|
+
* @param {string} inputColor any CSS‐valid color string (hex, rgb(), hsl(), etc.)
|
|
8
|
+
* @param {number} [opacity=1] fallback alpha (0–1) to use if `inputColor` has no alpha
|
|
9
|
+
* @returns {string} "rgba(r, g, b, a)" string
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* toRgba('#ff0000') // → "rgba(255, 0, 0, 1)"
|
|
13
|
+
* toRgba('#ff0000', 0.5) // → "rgba(255, 0, 0, 0.5)"
|
|
14
|
+
* toRgba('rgba(10,20,30,0.2)', 0.9) // → "rgba(10, 20, 30, 0.2)"
|
|
15
|
+
* toRgba('hsl(120, 100%, 50%)') // → "rgba(0, 255, 0, 1)"
|
|
16
|
+
* toRgba('blue', 0.3) // → "rgba(0, 0, 255, 0.3)"
|
|
17
|
+
*/export function colorToRgba(inputColor){var opacity=arguments.length>1&&arguments[1]!==undefined?arguments[1]:1;// Parse the input into a Color instance
|
|
18
|
+
var parsed=Color(inputColor);// Extract the alpha channel from the parsed color (default is 1 if none was provided)
|
|
19
|
+
var inputAlpha=parsed.alpha();// Determine which alpha to use:
|
|
20
|
+
// - If the parsed color already had alpha < 1, keep that.
|
|
21
|
+
// - Otherwise, use the provided opacity value.
|
|
22
|
+
var finalAlpha=inputAlpha<1?inputAlpha:opacity;// Set the computed alpha and return as "rgba(r, g, b, a)" string
|
|
23
|
+
return parsed.alpha(finalAlpha).rgb().string();}
|
package/styles/helpers/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{getCSSCustomProp,setCSSCustomProp}from"./cssCustomProperties";export{updatePageInsets}from"./updatePageInsets";export{setPageBackgroundColor}from"./setPageBackgroundColor";export{setPageContentWidth}from"./setPageContentWidth";export{setViewportHeight}from"./setViewportHeight";export{toggleBodyScroll}from"./toggleBodyScroll";export{initCSSCustomProps,initCSSCustomPropsFallback}from"./initCSSCustomProperties";export{loadCustomStyles}from"./loadCustomStyles";export{responsiveMediaQuery}from"../../components/ResponsiveContainer/mediaQuery";export{responsiveCondition}from"../../components/ResponsiveContainer/condition";
|
|
1
|
+
export{getCSSCustomProp,setCSSCustomProp}from"./cssCustomProperties";export{updatePageInsets}from"./updatePageInsets";export{setPageBackgroundColor}from"./setPageBackgroundColor";export{setPageContentWidth}from"./setPageContentWidth";export{setViewportHeight}from"./setViewportHeight";export{toggleBodyScroll}from"./toggleBodyScroll";export{initCSSCustomProps,initCSSCustomPropsFallback}from"./initCSSCustomProperties";export{loadCustomStyles}from"./loadCustomStyles";export*from"./color";export{responsiveMediaQuery}from"../../components/ResponsiveContainer/mediaQuery";export{responsiveCondition}from"../../components/ResponsiveContainer/condition";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import{themeConfig}from'@shopgate/pwa-common/helpers/config';import{hasWebBridge}from'@shopgate/engage/core/helpers';import{setCSSCustomProp}from"./cssCustomProperties";var defaultBackgroundColor=themeConfig.colors.light;/**
|
|
1
|
+
import{themeConfig}from'@shopgate/pwa-common/helpers/config';import{hasWebBridge}from'@shopgate/engage/core/helpers';import{IS_PAGE_PREVIEW_ACTIVE}from'@shopgate/engage/page/constants';import{setCSSCustomProp}from"./cssCustomProperties";var defaultBackgroundColor=themeConfig.colors.light;/**
|
|
2
2
|
* Updates the page background color.
|
|
3
3
|
* @param {string} color The new background color.
|
|
4
4
|
*/export var setPageBackgroundColor=function setPageBackgroundColor(){var color=arguments.length>0&&arguments[0]!==undefined?arguments[0]:defaultBackgroundColor;// Curbside website changes never its background color
|
|
5
|
-
if(!hasWebBridge()){setCSSCustomProp('--page-background-color',color);}};
|
|
5
|
+
if(!hasWebBridge()||IS_PAGE_PREVIEW_ACTIVE){setCSSCustomProp('--page-background-color',color);}};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export * from './helpers';
|
|
2
|
+
export {
|
|
3
|
+
ThemeProvider,
|
|
4
|
+
createTheme,
|
|
5
|
+
useActiveBreakpoint,
|
|
6
|
+
useMediaQuery,
|
|
7
|
+
useResponsiveValue,
|
|
8
|
+
useTheme,
|
|
9
|
+
Theme,
|
|
10
|
+
} from './theme';
|
|
11
|
+
export {
|
|
12
|
+
makeStyles,
|
|
13
|
+
withStyles,
|
|
14
|
+
tss,
|
|
15
|
+
GlobalStyles,
|
|
16
|
+
keyframes,
|
|
17
|
+
} from './tss';
|
package/styles/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export*from"./helpers";
|
|
1
|
+
export*from"./helpers";export{ThemeProvider,createTheme,useActiveBreakpoint,useMediaQuery,useResponsiveValue,useTheme}from"./theme";export{makeStyles,withStyles,tss,GlobalStyles,keyframes}from"./tss";
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
export type Breakpoint = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
2
|
+
export const keys: Breakpoint[];
|
|
3
|
+
|
|
4
|
+
export interface Breakpoints {
|
|
5
|
+
keys: Breakpoint[];
|
|
6
|
+
/**
|
|
7
|
+
* Each breakpoint (a key) matches with a fixed screen width (a value).
|
|
8
|
+
* @default
|
|
9
|
+
* {
|
|
10
|
+
* // extra-small
|
|
11
|
+
* xs: 0,
|
|
12
|
+
* // small
|
|
13
|
+
* sm: 600,
|
|
14
|
+
* // medium
|
|
15
|
+
* md: 900,
|
|
16
|
+
* // large
|
|
17
|
+
* lg: 1200,
|
|
18
|
+
* // extra-large
|
|
19
|
+
* xl: 1536,
|
|
20
|
+
* }
|
|
21
|
+
*/
|
|
22
|
+
values: { [key in Breakpoint]: number };
|
|
23
|
+
/**
|
|
24
|
+
* @param key - A breakpoint key (`xs`, `sm`, etc.) or a screen width number in px.
|
|
25
|
+
* @returns A media query string which matches screen widths greater than the screen size given by the breakpoint key (inclusive).
|
|
26
|
+
* @example
|
|
27
|
+
* ```js
|
|
28
|
+
* const styles = (theme) => ({
|
|
29
|
+
* root: {
|
|
30
|
+
* backgroundColor: 'blue',
|
|
31
|
+
* // Matches "md" and above
|
|
32
|
+
* [theme.breakpoints.up('md')]: {
|
|
33
|
+
* backgroundColor: 'red',
|
|
34
|
+
* }
|
|
35
|
+
* }
|
|
36
|
+
* })
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
up: (key: Breakpoint | number) => string;
|
|
40
|
+
/**
|
|
41
|
+
* @param key - A breakpoint key (`xs`, `sm`, etc.) or a screen width number in px.
|
|
42
|
+
* @returns A media query string which matches screen widths less than the screen size given by the breakpoint key (exclusive).
|
|
43
|
+
* @example
|
|
44
|
+
* ```js
|
|
45
|
+
* const styles = (theme) => ({
|
|
46
|
+
* root: {
|
|
47
|
+
* backgroundColor: 'blue',
|
|
48
|
+
* // Matches "xs" and "sm"
|
|
49
|
+
* [theme.breakpoints.down('md')]: {
|
|
50
|
+
* backgroundColor: 'red',
|
|
51
|
+
* }
|
|
52
|
+
* }
|
|
53
|
+
* })
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
down: (key: Breakpoint | number) => string;
|
|
57
|
+
/**
|
|
58
|
+
* @param start - A breakpoint key (`xs`, `sm`, etc.) or a screen width number in px.
|
|
59
|
+
* @param end - A breakpoint key (`xs`, `sm`, etc.) or a screen width number in px.
|
|
60
|
+
* @returns A media query string which matches screen widths greater than
|
|
61
|
+
* the screen size given by the breakpoint key in the first argument (inclusive) and less than the screen size given by the breakpoint key in the second argument (exclusive).
|
|
62
|
+
* @example
|
|
63
|
+
* ```js
|
|
64
|
+
* const styles = (theme) => ({
|
|
65
|
+
* root: {
|
|
66
|
+
* backgroundColor: 'blue',
|
|
67
|
+
* // Matches "sm" and "md"
|
|
68
|
+
* [theme.breakpoints.between('sm', 'lg')]: {
|
|
69
|
+
* backgroundColor: 'red',
|
|
70
|
+
* }
|
|
71
|
+
* }
|
|
72
|
+
* })
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
between: (start: Breakpoint | number, end: Breakpoint | number) => string;
|
|
76
|
+
/**
|
|
77
|
+
* @param key - A breakpoint key (`xs`, `sm`, etc.) or a screen width number in px.
|
|
78
|
+
* @returns A media query string which matches screen widths starting from
|
|
79
|
+
* the screen size given by the breakpoint key (inclusive) and stopping at the screen size given by the next breakpoint key (exclusive).
|
|
80
|
+
* @example
|
|
81
|
+
* ```js
|
|
82
|
+
* const styles = (theme) => ({
|
|
83
|
+
* root: {
|
|
84
|
+
* backgroundColor: 'blue',
|
|
85
|
+
* // Matches "sm"
|
|
86
|
+
* [theme.breakpoints.only('sm')]: {
|
|
87
|
+
* backgroundColor: 'red',
|
|
88
|
+
* }
|
|
89
|
+
* }
|
|
90
|
+
* })
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
only: (key: Breakpoint) => string;
|
|
94
|
+
/**
|
|
95
|
+
* @param key - A breakpoint key (`xs`, `sm`, etc.).
|
|
96
|
+
* @returns A media query string which matches screen widths stopping at
|
|
97
|
+
* the screen size given by the breakpoint key (exclusive) and starting at the screen size given by the next breakpoint key (inclusive).
|
|
98
|
+
* @example
|
|
99
|
+
* ```js
|
|
100
|
+
* const styles = (theme) => ({
|
|
101
|
+
* root: {
|
|
102
|
+
* backgroundColor: 'blue',
|
|
103
|
+
* // Matches "xs", "md", "lg", and "xl"
|
|
104
|
+
* [theme.breakpoints.not('sm')]: {
|
|
105
|
+
* backgroundColor: 'red',
|
|
106
|
+
* }
|
|
107
|
+
* }
|
|
108
|
+
* })
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
not: (key: Breakpoint) => string;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export default function createBreakpoints(): Breakpoints;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}/* eslint-disable valid-jsdoc */ // Possible breakpoints for responsive design
|
|
2
|
+
/** @type {import('./createBreakpoints').Breakpoint[]} */export var breakpointKeys=['xs','sm','md','lg','xl'];/**
|
|
3
|
+
* Sorts an object of breakpoints by their numeric values in ascending order.
|
|
4
|
+
*
|
|
5
|
+
* This is useful in responsive design systems to ensure breakpoints
|
|
6
|
+
* are applied in the correct order.
|
|
7
|
+
*
|
|
8
|
+
* @param {Object.<string, number>} values - An object where keys are breakpoint names
|
|
9
|
+
* (e.g., 'xs', 'sm', 'md') and values are numeric pixel values.
|
|
10
|
+
* @returns {Object.<string, number>} A new object with the same key-value pairs, sorted by
|
|
11
|
+
* ascending numeric values.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const breakpoints = { md: 960, xs: 0, sm: 600 };
|
|
15
|
+
* const sorted = sortBreakpointsValues(breakpoints);
|
|
16
|
+
* console.log(sorted); // { xs: 0, sm: 600, md: 960 }
|
|
17
|
+
*/var sortBreakpointsValues=function sortBreakpointsValues(values){var breakpointsAsArray=Object.keys(values).map(function(key){return{key:key,val:values[key]};})||[];breakpointsAsArray.sort(function(breakpoint1,breakpoint2){return breakpoint1.val-breakpoint2.val;});return breakpointsAsArray.reduce(function(acc,obj){return _extends({},acc,_defineProperty({},obj.key,obj.val));},{});};var unit='px';var step=5;/**
|
|
18
|
+
* Creates a set of media query functions based on the provided breakpoints.
|
|
19
|
+
*/var createBreakpoints=function createBreakpoints(){/** @type {import('./createBreakpoints').Breakpoints['values]} */var values={// Extra small – all mobile phones
|
|
20
|
+
xs:0,// Small – large phones in landscape
|
|
21
|
+
sm:480,// Medium – tablets
|
|
22
|
+
md:768,// Large – small laptops
|
|
23
|
+
lg:1024,// Extra large – desktops
|
|
24
|
+
xl:1280};var sortedValues=sortBreakpointsValues(values);var keys=Object.keys(sortedValues);/**
|
|
25
|
+
* @param {import('./createBreakpoints').Breakpoint | number} key Breakpoint key or pixel value
|
|
26
|
+
* @returns {string} A media query string for the specified breakpoint
|
|
27
|
+
*/function up(key){var value=typeof values[key]==='number'?values[key]:key;return"@media (min-width:".concat(value).concat(unit,")");}/**
|
|
28
|
+
* @param {import('./createBreakpoints').Breakpoint | number} key Breakpoint key or pixel value
|
|
29
|
+
* @returns {string} A media query string for the specified breakpoint
|
|
30
|
+
*/function down(key){/** @type {number} */var value=typeof values[key]==='number'?values[key]:key;return"@media (max-width:".concat(value-step/100).concat(unit,")");}/**
|
|
31
|
+
* @param {import('./createBreakpoints').Breakpoint | number} start Breakpoint key or pixel value
|
|
32
|
+
* @param {import('./createBreakpoints').Breakpoint | number} end Breakpoint key or pixel value
|
|
33
|
+
* @returns {string} A media query string for the specified breakpoint
|
|
34
|
+
*/function between(start,end){var endIndex=keys.indexOf(end);return"@media (min-width:".concat(typeof values[start]==='number'?values[start]:start).concat(unit,") and ")+"(max-width:".concat((endIndex!==-1&&typeof values[keys[endIndex]]==='number'?values[keys[endIndex]]:end)-step/100).concat(unit,")");}/**
|
|
35
|
+
* @param {import('./createBreakpoints').Breakpoint} key Breakpoint key or pixel value
|
|
36
|
+
* @returns {string} A media query string for the specified breakpoint
|
|
37
|
+
*/function only(key){if(keys.indexOf(key)+1<keys.length){return between(key,keys[keys.indexOf(key)+1]);}return up(key);}/**
|
|
38
|
+
* @param {import('./createBreakpoints').Breakpoint} key Breakpoint key or pixel value
|
|
39
|
+
* @returns {string} A media query string for the specified breakpoint
|
|
40
|
+
*/function not(key){// handle first and last key separately, for better readability
|
|
41
|
+
var keyIndex=keys.indexOf(key);if(keyIndex===0){return up(keys[1]);}if(keyIndex===keys.length-1){return down(keys[keyIndex]);}return between(key,keys[keys.indexOf(key)+1]).replace('@media','@media not all and');}return{keys:keys,values:sortedValues,up:up,down:down,between:between,only:only,not:not};};export default createBreakpoints;/* eslint-enable valid-jsdoc */
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
type ColorPartialKeys =
|
|
2
|
+
| 50 | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900
|
|
3
|
+
| 'A100' | 'A200' | 'A400' | 'A700';
|
|
4
|
+
|
|
5
|
+
type ColorPartial = Record<ColorPartialKeys, string>;
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
interface TypeText {
|
|
9
|
+
primary: string;
|
|
10
|
+
secondary: string;
|
|
11
|
+
tertiary: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface BasePaletteColor {
|
|
15
|
+
main: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface PaletteColorWithContrast extends PaletteColor {
|
|
19
|
+
contrast: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
type PaletteColor<WithContrast extends boolean = false> =
|
|
23
|
+
BasePaletteColor & (WithContrast extends true ? { contrast: string } : {});
|
|
24
|
+
|
|
25
|
+
export interface Palette {
|
|
26
|
+
primary: PaletteColor<true>;
|
|
27
|
+
secondary: PaletteColor<true>;
|
|
28
|
+
error: PaletteColor;
|
|
29
|
+
warning: PaletteColor;
|
|
30
|
+
success: PaletteColor;
|
|
31
|
+
cta: PaletteColor<true>;
|
|
32
|
+
text: TypeText;
|
|
33
|
+
grey: ColorPartial;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export default function createPalette(): Palette;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}var grey={50:'#fafafa',100:'#f5f5f5',200:'#eeeeee',300:'#e0e0e0',400:'#bdbdbd',500:'#9e9e9e',600:'#757575',700:'#616161',800:'#424242',900:'#212121',A100:'#f5f5f5',A200:'#eeeeee',A400:'#bdbdbd',A700:'#616161'};/**
|
|
2
|
+
* Creates a palette object for the theme.
|
|
3
|
+
* @returns {Object} The palette object.
|
|
4
|
+
*/var createPalette=function createPalette(){var palette={primary:{main:'var(--color-primary)',contrast:'var(--color-primary-contrast)'},secondary:{main:'var(--color-secondary)',contrast:'var(--color-secondary-contrast)'},error:{main:'var(--color-state-alert)'},warning:{main:'var(--color-state-warning)'},success:{main:'var(--color-state-ok)'},cta:{main:'var(--color-button-cta)',contrast:'var(--color-button-cta-contrast)'},text:{primary:'var(--color-text-high-emphasis)',secondary:'var(--color-text-medium-emphasis)',tertiary:'var(--color-text-low-emphasis)'}};return _extends({},palette,{grey:grey});};export default createPalette;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/* tslint:disable:unified-signatures */
|
|
2
|
+
|
|
3
|
+
export type SpacingArgument = number | string;
|
|
4
|
+
|
|
5
|
+
export interface Spacing {
|
|
6
|
+
/**
|
|
7
|
+
* The spacing helper can be used to create consistent spacing between UI element.
|
|
8
|
+
*
|
|
9
|
+
* It accepts 0 to 4 spacing arguments, which can be numbers or strings like `auto`,
|
|
10
|
+
*/
|
|
11
|
+
(): number;
|
|
12
|
+
(value: number): number;
|
|
13
|
+
(topBottom: SpacingArgument, rightLeft: SpacingArgument): string;
|
|
14
|
+
(top: SpacingArgument, rightLeft: SpacingArgument, bottom: SpacingArgument): string;
|
|
15
|
+
(
|
|
16
|
+
top: SpacingArgument,
|
|
17
|
+
right: SpacingArgument,
|
|
18
|
+
bottom: SpacingArgument,
|
|
19
|
+
left: SpacingArgument
|
|
20
|
+
): string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default function createSpacing(): Spacing;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import{isDev}from'@shopgate/engage/core/helpers';var spacingUnit=8;/**
|
|
2
|
+
* Create the spacing function of the theme
|
|
3
|
+
* @returns {function(...(number | string)): string} A function that takes one or more spacing
|
|
4
|
+
* arguments
|
|
5
|
+
*/var createSpacing=function createSpacing(){/**
|
|
6
|
+
*
|
|
7
|
+
* @param {number|string} input The input
|
|
8
|
+
* @returns {string|number} The result
|
|
9
|
+
*/var transform=function transform(input){if(typeof input==='number'){return input*spacingUnit;}return input;};/**
|
|
10
|
+
* @param {...(number | string)} args - 0 to 4 spacing arguments, which can be numbers
|
|
11
|
+
* or strings like 'auto',
|
|
12
|
+
* @returns {string} A space-separated string of pixel values or other transformed values
|
|
13
|
+
*/var spacing=function spacing(){for(var _len=arguments.length,args=new Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key];}if(isDev){if(!(args.length<=4)){// eslint-disable-next-line no-console
|
|
14
|
+
console.error("Too many arguments passed. Expected between 0 and 4 arguments, got ".concat(args.length,"."));}}if(args.length===0){return transform(1);}if(args.length===1){return transform(args[0]);}return args.slice(0,4).map(function(argument){var output=transform(argument);return typeof output==='number'?"".concat(output,"px"):output;}).join(' ');};return spacing;};export default createSpacing;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { type CSSObject } from 'tss-react';
|
|
3
|
+
import { type Palette } from './createPalette';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export type Variant =
|
|
7
|
+
| 'h1'
|
|
8
|
+
| 'h2'
|
|
9
|
+
| 'h3'
|
|
10
|
+
| 'h4'
|
|
11
|
+
| 'h5'
|
|
12
|
+
| 'h6'
|
|
13
|
+
| 'subtitle1'
|
|
14
|
+
| 'subtitle2'
|
|
15
|
+
| 'body1'
|
|
16
|
+
| 'body2'
|
|
17
|
+
| 'caption'
|
|
18
|
+
| 'button'
|
|
19
|
+
| 'overline';
|
|
20
|
+
|
|
21
|
+
export interface FontStyle
|
|
22
|
+
extends Required<{
|
|
23
|
+
fontFamily: React.CSSProperties['fontFamily'];
|
|
24
|
+
fontSize: number;
|
|
25
|
+
fontWeightLight: React.CSSProperties['fontWeight'];
|
|
26
|
+
fontWeightRegular: React.CSSProperties['fontWeight'];
|
|
27
|
+
fontWeightMedium: React.CSSProperties['fontWeight'];
|
|
28
|
+
fontWeightBold: React.CSSProperties['fontWeight'];
|
|
29
|
+
}> {}
|
|
30
|
+
|
|
31
|
+
export interface FontStyleOptions extends Partial<FontStyle> {
|
|
32
|
+
allVariants?: React.CSSProperties;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export type TypographyStyle = CSSObject;
|
|
36
|
+
export interface TypographyStyleOptions extends TypographyStyle {}
|
|
37
|
+
|
|
38
|
+
export interface TypographyUtils {
|
|
39
|
+
/**
|
|
40
|
+
* Calculates a rem value for a passed pixel value.
|
|
41
|
+
* @param size The source value in pixels.
|
|
42
|
+
* @returns The result value in rem.
|
|
43
|
+
*/
|
|
44
|
+
pxToRem: (px: number) => string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface Typography extends Record<Variant, TypographyStyle>, FontStyle, TypographyUtils {}
|
|
48
|
+
|
|
49
|
+
export interface TypographyOptions
|
|
50
|
+
extends Partial<Record<Variant, TypographyStyleOptions> & FontStyleOptions> {}
|
|
51
|
+
|
|
52
|
+
export default function createTypography(
|
|
53
|
+
palette: Palette,
|
|
54
|
+
typography: TypographyOptions | ((palette: Palette) => TypographyOptions)
|
|
55
|
+
): Typography;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import _merge from"lodash/merge";var _excluded=["fontFamily","fontSize","fontWeightLight","fontWeightRegular","fontWeightMedium","fontWeightBold","allVariants","pxToRem"];function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}function _objectWithoutProperties(source,excluded){if(source==null)return{};var target=_objectWithoutPropertiesLoose(source,excluded);var key,i;if(Object.getOwnPropertySymbols){var sourceSymbolKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceSymbolKeys.length;i++){key=sourceSymbolKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key];}}return target;}function _objectWithoutPropertiesLoose(source,excluded){if(source==null)return{};var target={};var sourceKeys=Object.keys(source);var key,i;for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;target[key]=source[key];}return target;}import{isDev}from'@shopgate/engage/core/helpers';/**
|
|
2
|
+
* Round a number to a fixed precision of five decimal places.
|
|
3
|
+
* @param {number} value The value to round.
|
|
4
|
+
* @returns {number} The rounded value.
|
|
5
|
+
*/function round(value){return Math.round(value*1e5)/1e5;}var caseAllCaps={textTransform:'uppercase'};var defaultFontFamily='"Roboto", "Helvetica", "Arial", sans-serif';/**
|
|
6
|
+
* Creates the typography object for the theme.
|
|
7
|
+
* @param {Object} palette The theme palette.
|
|
8
|
+
* @param {Object|Function} typography The typography options or a function that returns them.
|
|
9
|
+
* @returns {Object} The typography object.
|
|
10
|
+
* @see @link{https://material.io/design/typography/the-type-system.html}
|
|
11
|
+
* @see @link{https://material.io/design/typography/understanding-typography.html}
|
|
12
|
+
*/export default function createTypography(palette,typography){var _ref=typeof typography==='function'?typography(palette):typography,_ref$fontFamily=_ref.fontFamily,fontFamily=_ref$fontFamily===void 0?defaultFontFamily:_ref$fontFamily,_ref$fontSize=_ref.fontSize,fontSize=_ref$fontSize===void 0?16:_ref$fontSize,_ref$fontWeightLight=_ref.fontWeightLight,fontWeightLight=_ref$fontWeightLight===void 0?300:_ref$fontWeightLight,_ref$fontWeightRegula=_ref.fontWeightRegular,fontWeightRegular=_ref$fontWeightRegula===void 0?400:_ref$fontWeightRegula,_ref$fontWeightMedium=_ref.fontWeightMedium,fontWeightMedium=_ref$fontWeightMedium===void 0?500:_ref$fontWeightMedium,_ref$fontWeightBold=_ref.fontWeightBold,fontWeightBold=_ref$fontWeightBold===void 0?700:_ref$fontWeightBold,allVariants=_ref.allVariants,pxToRem2=_ref.pxToRem,other=_objectWithoutProperties(_ref,_excluded);if(isDev){if(typeof fontSize!=='number'){console.error('Shopgate Theme: `fontSize` is required to be a number.');}}/**
|
|
13
|
+
* Calculates a rem value for a passed pixel value.
|
|
14
|
+
* @param {number} size The source value in pixels.
|
|
15
|
+
* @returns {string} The result value in rem.
|
|
16
|
+
*/var pxToRem=function pxToRem(size){return"".concat(round(size/fontSize),"rem");};/**
|
|
17
|
+
* Creates a typography variant object.
|
|
18
|
+
* @param {number} fontWeight The font weight to use for the variant.
|
|
19
|
+
* @param {number} size Font size in pixels.
|
|
20
|
+
* @param {number} lineHeight Line height as a unitless number.
|
|
21
|
+
* @param {Object} casing Casing styles to apply, e.g. textTransform.
|
|
22
|
+
* @returns {Object} The typography variant object.
|
|
23
|
+
*/var buildVariant=function buildVariant(fontWeight,size,lineHeight,casing){return _extends({fontFamily:fontFamily,fontWeight:fontWeight,fontSize:pxToRem(size),lineHeight:lineHeight},casing,{},allVariants);};var variants={h1:buildVariant(fontWeightBold,34,1.15),h2:buildVariant(fontWeightBold,22,1.3),h3:buildVariant(fontWeightMedium,20,1.35),h4:buildVariant(fontWeightMedium,18,1.4),h5:buildVariant(fontWeightMedium,16,1.5),h6:buildVariant(fontWeightMedium,14,1.5),subtitle1:buildVariant(fontWeightRegular,16,1.75),subtitle2:buildVariant(fontWeightMedium,14,1.57),body1:buildVariant(fontWeightRegular,16,1.5),body2:buildVariant(fontWeightRegular,14,1.43),button:buildVariant(fontWeightMedium,14,1.75,caseAllCaps),caption:buildVariant(fontWeightRegular,12,1.66),overline:buildVariant(fontWeightRegular,12,2.66,caseAllCaps)};return _merge(_extends({pxToRem:pxToRem,fontFamily:fontFamily,fontSize:fontSize,fontWeightLight:fontWeightLight,fontWeightRegular:fontWeightRegular,fontWeightMedium:fontWeightMedium,fontWeightBold:fontWeightBold},variants),other);}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type Palette } from './createPalette'
|
|
2
|
+
import { type Typography, type TypographyOptions } from './createTypography';
|
|
3
|
+
import { type Breakpoints } from './createBreakpoints';
|
|
4
|
+
import { type Spacing } from './createSpacing';
|
|
5
|
+
import { type Transitions } from './transitions';
|
|
6
|
+
import { type ZIndex } from './zIndex';
|
|
7
|
+
|
|
8
|
+
export { type Breakpoint } from './createBreakpoints'
|
|
9
|
+
|
|
10
|
+
export interface ThemeOptions {
|
|
11
|
+
typography?: TypographyOptions | ((palette: Palette) => TypographyOptions);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface Theme {
|
|
15
|
+
/**
|
|
16
|
+
* The palette defines the theme colors.
|
|
17
|
+
*/
|
|
18
|
+
palette: Palette;
|
|
19
|
+
/**
|
|
20
|
+
* API to simplify the use of media queries.
|
|
21
|
+
*/
|
|
22
|
+
breakpoints: Breakpoints;
|
|
23
|
+
/**
|
|
24
|
+
* Use the spacing function to create consistent spacing.
|
|
25
|
+
*/
|
|
26
|
+
spacing: Spacing;
|
|
27
|
+
/**
|
|
28
|
+
* API to simplify the creation of transitions
|
|
29
|
+
*/
|
|
30
|
+
transitions: Transitions;
|
|
31
|
+
/**
|
|
32
|
+
* Font styles for multiple typography variants.
|
|
33
|
+
*/
|
|
34
|
+
typography: Typography;
|
|
35
|
+
/**
|
|
36
|
+
* Reference to z-index values for multiple components.
|
|
37
|
+
*/
|
|
38
|
+
zIndex: ZIndex;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function createTheme(options?: ThemeOptions): Theme;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import createPalette from"./createPalette";import createBreakpoints from"./createBreakpoints";import createTypography from"./createTypography";import createSpacing from"./createSpacing";import transitions from"./transitions";import zIndex from"./zIndex";// eslint-disable-next-line valid-jsdoc
|
|
2
|
+
/**
|
|
3
|
+
* Creates a theme object for the ThemeProvider.
|
|
4
|
+
* @returns The theme object
|
|
5
|
+
*/export var createTheme=function createTheme(){var options=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var _options$typography=options.typography,typographyInput=_options$typography===void 0?{}:_options$typography;var palette=createPalette();var breakpoints=createBreakpoints();var spacing=createSpacing();var typography=createTypography(palette,typographyInput);return{palette:palette,typography:typography,breakpoints:breakpoints,spacing:spacing,transitions:transitions,zIndex:zIndex};};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
export interface Easing {
|
|
2
|
+
/**
|
|
3
|
+
* This is the most common easing curve.
|
|
4
|
+
*/
|
|
5
|
+
easeInOut: string;
|
|
6
|
+
/**
|
|
7
|
+
* Objects enter the screen at full velocity from off-screen and slowly decelerate to a resting
|
|
8
|
+
* point.
|
|
9
|
+
*/
|
|
10
|
+
easeOut: string;
|
|
11
|
+
/**
|
|
12
|
+
* Objects leave the screen at full velocity. They do not decelerate when off-screen.
|
|
13
|
+
*/
|
|
14
|
+
easeIn: string;
|
|
15
|
+
/**
|
|
16
|
+
* The sharp curve is used by objects that may return to the screen at any time.
|
|
17
|
+
*/
|
|
18
|
+
sharp: string;
|
|
19
|
+
}
|
|
20
|
+
export const easing: Easing;
|
|
21
|
+
|
|
22
|
+
export interface Duration {
|
|
23
|
+
shortest: number;
|
|
24
|
+
shorter: number;
|
|
25
|
+
short: number;
|
|
26
|
+
/**
|
|
27
|
+
* Most basic recommended timing
|
|
28
|
+
*/
|
|
29
|
+
standard: number;
|
|
30
|
+
/**
|
|
31
|
+
* This is to be used in complex animations
|
|
32
|
+
*/
|
|
33
|
+
complex: number;
|
|
34
|
+
/**
|
|
35
|
+
* Recommended when something is entering screen
|
|
36
|
+
*/
|
|
37
|
+
enteringScreen: number;
|
|
38
|
+
/**
|
|
39
|
+
* Recommended when something is leaving screen
|
|
40
|
+
*/
|
|
41
|
+
leavingScreen: number;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export const duration: Duration;
|
|
45
|
+
|
|
46
|
+
export function formatMs(milliseconds: number): string;
|
|
47
|
+
|
|
48
|
+
export interface Transitions {
|
|
49
|
+
/**
|
|
50
|
+
* Easing functions for transitions.
|
|
51
|
+
*/
|
|
52
|
+
easing: Easing;
|
|
53
|
+
/**
|
|
54
|
+
* Presets for transition durations.
|
|
55
|
+
*/
|
|
56
|
+
duration: Duration;
|
|
57
|
+
/**
|
|
58
|
+
* Creates a CSS transition string based on the provided properties and options.
|
|
59
|
+
*/
|
|
60
|
+
create(
|
|
61
|
+
/**
|
|
62
|
+
* The CSS properties to apply the transition to.
|
|
63
|
+
* Can be a single property or an array of properties.
|
|
64
|
+
*/
|
|
65
|
+
props: string | string[],
|
|
66
|
+
options?: Partial<{
|
|
67
|
+
/**
|
|
68
|
+
* Duration of the transition as a number in milliseconds or a string with a
|
|
69
|
+
* CSS time unit (e.g., '500ms', '0.5s').
|
|
70
|
+
*/
|
|
71
|
+
duration: number | string;
|
|
72
|
+
/**
|
|
73
|
+
* Easing function to use for the transition.
|
|
74
|
+
*/
|
|
75
|
+
easing: string;
|
|
76
|
+
/**
|
|
77
|
+
* Delay before the transition starts, as a number in milliseconds or a string with a
|
|
78
|
+
* CSS time unit (e.g., '500ms', '0.5s').
|
|
79
|
+
*/
|
|
80
|
+
delay: number | string
|
|
81
|
+
}>
|
|
82
|
+
): string;
|
|
83
|
+
/**
|
|
84
|
+
* Calculates an appropriate animation duration (in milliseconds) for a height-based
|
|
85
|
+
* transition effect. The duration increases with height but in a sub-linear fashion,
|
|
86
|
+
* providing a smooth and visually pleasing animation speed for expanding/collapsing UI elements.
|
|
87
|
+
*
|
|
88
|
+
* @param {number} height - The height (in pixels) of the element being animated.
|
|
89
|
+
* @returns {number} The calculated duration in milliseconds. Returns 0 if height is 0 or falsy.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* getAutoHeightDuration(72); // returns ~222
|
|
93
|
+
*/
|
|
94
|
+
getAutoHeightDuration(height: number): number;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// export type TransitionsOptions = DeepPartial<Transitions>;
|
|
98
|
+
|
|
99
|
+
declare const transitions: Transitions;
|
|
100
|
+
export default transitions;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
var _excluded=["duration","easing","delay"];function _objectWithoutProperties(source,excluded){if(source==null)return{};var target=_objectWithoutPropertiesLoose(source,excluded);var key,i;if(Object.getOwnPropertySymbols){var sourceSymbolKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceSymbolKeys.length;i++){key=sourceSymbolKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key];}}return target;}function _objectWithoutPropertiesLoose(source,excluded){if(source==null)return{};var target={};var sourceKeys=Object.keys(source);var key,i;for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;target[key]=source[key];}return target;}import{isDev}from'@shopgate/engage/core/helpers';// Follow https://material.google.com/motion/duration-easing.html#duration-easing-natural-easing-curves
|
|
2
|
+
// to learn the context in which each easing should be used.
|
|
3
|
+
export var easing={// This is the most common easing curve.
|
|
4
|
+
easeInOut:'cubic-bezier(0.4, 0, 0.2, 1)',// Objects enter the screen at full velocity from off-screen and
|
|
5
|
+
// slowly decelerate to a resting point.
|
|
6
|
+
easeOut:'cubic-bezier(0.0, 0, 0.2, 1)',// Objects leave the screen at full velocity. They do not decelerate when off-screen.
|
|
7
|
+
easeIn:'cubic-bezier(0.4, 0, 1, 1)',// The sharp curve is used by objects that may return to the screen at any time.
|
|
8
|
+
sharp:'cubic-bezier(0.4, 0, 0.6, 1)'};// Follow https://material.io/guidelines/motion/duration-easing.html#duration-easing-common-durations
|
|
9
|
+
// to learn when use what timing
|
|
10
|
+
export var duration={shortest:150,shorter:200,"short":250,// most basic recommended timing
|
|
11
|
+
standard:300,// this is to be used in complex animations
|
|
12
|
+
complex:375,// recommended when something is entering screen
|
|
13
|
+
enteringScreen:225,// recommended when something is leaving screen
|
|
14
|
+
leavingScreen:195};/**
|
|
15
|
+
* Converts milliseconds to a string representation.
|
|
16
|
+
* @param {number} milliseconds Input in milliseconds.
|
|
17
|
+
* @returns {string}
|
|
18
|
+
*/function formatMs(milliseconds){return"".concat(Math.round(milliseconds),"ms");}/**
|
|
19
|
+
* @param {string|Array} props
|
|
20
|
+
* @param {object} param
|
|
21
|
+
* @param {string} param.prop
|
|
22
|
+
* @param {number} param.duration
|
|
23
|
+
* @param {string} param.easing
|
|
24
|
+
* @param {number} param.delay
|
|
25
|
+
*/export default{easing:easing,duration:duration,create:function create(){var props=arguments.length>0&&arguments[0]!==undefined?arguments[0]:['all'];var options=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var _options$duration=options.duration,durationOption=_options$duration===void 0?duration.standard:_options$duration,_options$easing=options.easing,easingOption=_options$easing===void 0?easing.easeInOut:_options$easing,_options$delay=options.delay,delay=_options$delay===void 0?0:_options$delay,other=_objectWithoutProperties(options,_excluded);if(isDev){/* eslint-disable require-jsdoc */var isString=function isString(value){return typeof value==='string';};var isNumber=function isNumber(value){return!Number.isNaN(parseFloat(value));};/* eslint-enable require-jsdoc */if(!isString(props)&&!Array.isArray(props)){console.error('Shopgate Theme: Argument "props" must be a string or Array.');}if(!isNumber(durationOption)&&!isString(durationOption)){console.error("Shopgate Theme: Argument \"duration\" must be a number or a string but found ".concat(durationOption,"."));}if(!isString(easingOption)){console.error('Shopgate Theme: Argument "easing" must be a string.');}if(!isNumber(delay)&&!isString(delay)){console.error('Shopgate Theme: Argument "delay" must be a number or a string.');}if(Object.keys(other).length!==0){console.error("Shopgate Theme: Unrecognized argument(s) [".concat(Object.keys(other).join(','),"]."));}}return(Array.isArray(props)?props:[props]).map(function(animatedProp){return"".concat(animatedProp," ").concat(typeof durationOption==='string'?durationOption:formatMs(durationOption)," ").concat(easingOption," ").concat(typeof delay==='string'?delay:formatMs(delay));}).join(',');},getAutoHeightDuration:function getAutoHeightDuration(height){if(!height){return 0;}var constant=height/36;// https://www.wolframalpha.com/input/?i=(4+%2B+15+*+(x+%2F+36+)+**+0.25+%2B+(x+%2F+36)+%2F+5)+*+10
|
|
26
|
+
return Math.round((4+15*Math.pow(constant,0.25)+constant/5)*10);}};
|