diff --git a/docs/README.md b/docs/README.md index 50f3bca..a23c310 100644 --- a/docs/README.md +++ b/docs/README.md @@ -23,6 +23,29 @@ You can use **any** array of blocks as `flex-layout.row` and `flex-layout.col` c The props below support [`responsive-values`](https://github.com/vtex-apps/responsive-values), meaning that you can define to the same prop different values based on each device's screen size, such as mobile and desktop. +For example: +``` +{ + "flex-layout.row#row": { + "props": { + "marginBottom": { + "mobile": 2, + "desktop": 6 + }, + "width": { + "desktop": "33%", + "tablet": "50%", + "phone": "100%" + } + }, + "children": [ + "flex-layout.col#col1", + "flex-layout.col#col2", + ... + ] + } +``` + ### `flex-layout.row` | Prop name | Type | Description | Default value | diff --git a/react/hooks/responsiveWidth.ts b/react/hooks/responsiveWidth.ts index 3ab1f6c..7378699 100644 --- a/react/hooks/responsiveWidth.ts +++ b/react/hooks/responsiveWidth.ts @@ -81,6 +81,7 @@ export const useResponsiveWidth = ( const { device } = useDevice() const isPhone = device === 'phone' + const isTablet = device === 'tablet' const { preserveLayoutOnMobile = false, hideEmptyCols = false } = options || {} @@ -102,7 +103,7 @@ export const useResponsiveWidth = ( if (width && typeof width === 'object') { return { element: col, - width: isPhone ? width.mobile || 0 : width.desktop || 0, + width: isPhone ? width.phone || 0 : isTablet ? width.tablet || 0 : width.desktop || 0, hasDefinedWidth: true, isResponsive: true, } diff --git a/react/modules/valuesParser.ts b/react/modules/valuesParser.ts index b4fd13c..1f61617 100644 --- a/react/modules/valuesParser.ts +++ b/react/modules/valuesParser.ts @@ -5,6 +5,8 @@ type Group = { [key in keyof T]: U } type TachyonsInputGroup = Group interface ResponsiveInput { mobile: T + phone: T + tablet: T desktop: T } @@ -12,7 +14,7 @@ const MAX_TACHYONS_SCALE = 11 //eslint-disable-next-line @typescript-eslint/no-explicit-any const isResponsiveInput = (value: any): value is ResponsiveInput => - value && value.mobile != null && value.desktop != null + value && (value.mobile != null || value.phone != null || value.tablet != null) && value.desktop != null /** Takes a parser of units, and returns a parser that accepts either a * value or a responsive input of that same type of value @@ -21,10 +23,12 @@ const isResponsiveInput = (value: any): value is ResponsiveInput => */ export const parseResponsive = (parse: (value: T) => U) => ( value: T | ResponsiveInput -): null | U | { mobile: U; desktop: U } => { +): null | U | { mobile: U; phone: U; tablet: U; desktop: U } => { if (isResponsiveInput(value)) { return { mobile: parse(value.mobile), + phone: parse(value.phone), + tablet: parse(value.tablet), desktop: parse(value.desktop), } }