@foxford/ui 2.21.0 → 2.21.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"create-responsive-props.js","sources":["../../../src/mixins/create-responsive-props.ts"],"sourcesContent":["import type { CSSProperties } from 'react'\nimport { css } from 'styled-components'\nimport type { ThemedStyledProps, DefaultTheme, CSSObject, FlattenInterpolation, ThemeProps } from 'styled-components'\nimport { screenMinM, screenMaxM, screenMaxS, screenMinL, screenMaxL, screenMaxXs, screenMaxXxs } from 'mixins/screen'\nimport { getMediaQueryByResponsiveProp, desktopFirst } from 'mixins/shared'\nimport type { MediaQuery } from 'mixins/screen'\nimport type { Breakpoint } from 'shared/types'\n\ntype ResponsivePropKey = 'size' | keyof CSSProperties\n\ntype ResponsiveProps<K extends ResponsivePropKey, V> = {\n [key in K]?: V | [desktop: V, tablet: V, mobile: V] | [xl: V, l: V, m: V, s: V, xs: V, xxs: V]\n} & {\n [key in `${K}${Breakpoint}`]?: V\n}\n\ntype MediaFunction = ReturnType<ReturnType<MediaQuery>>\n\n/**\n *\n * Factory to create mixins to enable responsive interface for any set of props\n */\nfunction createResponsivePropsMixin<K extends ResponsivePropKey, V, P extends ResponsiveProps<K, V>>(\n propsKeys: K[],\n buildCSSObject: (propKey: K, propValue: V, props: ThemedStyledProps<P, DefaultTheme>) => CSSObject\n): (props: ThemedStyledProps<P, DefaultTheme>) => FlattenInterpolation<ThemeProps<DefaultTheme>> {\n const propsRegExp = new RegExp(`^(${propsKeys.join('|')})$`)\n const breakpointsPropsRegExp = new RegExp(`^(${propsKeys.join('|')})(XXS|XS|S|M|L|XL)$`)\n const breakpointsRegExp = /(XXS|XS|S|M|L|XL)$/\n\n const deviceQueries = [screenMinM, screenMaxM, screenMaxS]\n const breakpointsQueries = [screenMinL, screenMaxL, screenMaxM, screenMaxS, screenMaxXs, screenMaxXxs]\n\n return (props) => {\n const propsKeys = Object.keys(props).reduce(\n (groups, propKey) => {\n if (propsRegExp.test(propKey)) groups[0].push(propKey)\n else if (breakpointsPropsRegExp.test(propKey)) groups[1].push(propKey)\n\n return groups\n },\n [[], []] as [string[], string[]]\n )\n\n const interpolations = propsKeys[0].reduce((acc, propKey) => {\n const propValue: V | V[] = props[propKey]\n\n if (!Array.isArray(propValue)) {\n const cssObject = buildCSSObject(propKey as K, propValue, props)\n\n if (Object.keys(cssObject).length > 0) {\n acc.push(cssObject)\n }\n } else if (propValue.length > 0) {\n const mediaFunctions: MediaFunction[] = []\n const queries = propValue.length > deviceQueries.length ? breakpointsQueries : deviceQueries\n\n for (let i = 0; i < propValue.length; i++) {\n if (!queries[i]) break\n\n const cssObject = buildCSSObject(propKey as K, propValue[i], props)\n\n if (Object.keys(cssObject).length > 0) {\n mediaFunctions.push(queries[i]()`${cssObject}`)\n }\n }\n\n acc.push(...mediaFunctions)\n }\n\n return acc\n }, [] as (CSSObject | MediaFunction)[])\n\n const breakpointsInterpolations = propsKeys[1].sort(desktopFirst).reduce((acc, propKey) => {\n const cssObject = buildCSSObject(propKey.replace(breakpointsRegExp, '') as K, props[propKey], props)\n\n if (Object.keys(cssObject).length > 0) {\n acc.push(getMediaQueryByResponsiveProp(propKey)()`${cssObject}`)\n }\n\n return acc\n }, [] as MediaFunction[])\n\n return css`\n ${interpolations}\n ${breakpointsInterpolations}\n `\n }\n}\n\nexport type { ResponsiveProps }\n\nexport { createResponsivePropsMixin }\n"],"names":["createResponsivePropsMixin","propsKeys","buildCSSObject","propsRegExp","RegExp","concat","join","breakpointsPropsRegExp","breakpointsRegExp","deviceQueries","screenMinM","screenMaxM","screenMaxS","breakpointsQueries","screenMinL","screenMaxL","screenMaxXs","screenMaxXxs","props","Object","keys","reduce","groups","propKey","test","push","interpolations","acc","propValue","Array","isArray","length","mediaFunctions","queries","i","cssObject","_templateObject","_taggedTemplateLiteral","breakpointsInterpolations","sort","desktopFirst","replace","getMediaQueryByResponsiveProp","_templateObject2","css"],"mappings":"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MY,EAAYjC,EAAeqB,EAAQkB,QAAQjC,EAAmB,IAAUU,EAAMK,GAAUL,GAM9F,OAJIC,OAAOC,KAAKe,GAAWJ,OAAS,GAClCJ,EAAIF,KAAKiB,EAA8BnB,EAA9BmB,EAAAA,CAATC,IAAAA,EAAAN,EAAA,CAAA,GAAA,MAAoDF,IAG/CR,IACN,IAEH,OAAOiB,EAAP,CAAA,GAAA,IAAA,IACIlB,EACAY"}
1
+ {"version":3,"file":"create-responsive-props.js","sources":["../../../src/mixins/create-responsive-props.ts"],"sourcesContent":["import type { CSSProperties } from 'react'\nimport { css } from 'styled-components'\nimport type { ThemedStyledProps, DefaultTheme, CSSObject, FlattenInterpolation, ThemeProps } from 'styled-components'\nimport { screenMinM, screenMaxM, screenMaxS, screenMinL, screenMaxL, screenMaxXs, screenMaxXxs } from 'mixins/screen'\nimport { getMediaQueryByResponsiveProp, desktopFirst } from 'mixins/shared'\nimport type { MediaQuery } from 'mixins/screen'\nimport type { Breakpoint } from 'shared/types'\n\ntype ResponsivePropKey = 'size' | keyof CSSProperties\n\ntype ResponsiveProps<K extends ResponsivePropKey, V> = {\n [key in K]?: V | [DESKTOP: V, TABLET: V, MOBILE: V] | [XL: V, L: V, M: V, S: V, XS: V, XXS: V]\n} & {\n [key in `${K}${Breakpoint}`]?: V\n}\n\ntype MediaFunction = ReturnType<ReturnType<MediaQuery>>\n\n/**\n *\n * Factory to create mixins to enable responsive interface for any set of props\n */\nfunction createResponsivePropsMixin<K extends ResponsivePropKey, V, P extends ResponsiveProps<K, V>>(\n propsKeys: K[],\n buildCSSObject: (propKey: K, propValue: V, props: ThemedStyledProps<P, DefaultTheme>) => CSSObject\n): (props: ThemedStyledProps<P, DefaultTheme>) => FlattenInterpolation<ThemeProps<DefaultTheme>> {\n const propsRegExp = new RegExp(`^(${propsKeys.join('|')})$`)\n const breakpointsPropsRegExp = new RegExp(`^(${propsKeys.join('|')})(XXS|XS|S|M|L|XL)$`)\n const breakpointsRegExp = /(XXS|XS|S|M|L|XL)$/\n\n const deviceQueries = [screenMinM, screenMaxM, screenMaxS]\n const breakpointsQueries = [screenMinL, screenMaxL, screenMaxM, screenMaxS, screenMaxXs, screenMaxXxs]\n\n return (props) => {\n const propsKeys = Object.keys(props).reduce(\n (groups, propKey) => {\n if (propsRegExp.test(propKey)) groups[0].push(propKey)\n else if (breakpointsPropsRegExp.test(propKey)) groups[1].push(propKey)\n\n return groups\n },\n [[], []] as [string[], string[]]\n )\n\n const interpolations = propsKeys[0].reduce((acc, propKey) => {\n const propValue: V | V[] = props[propKey]\n\n if (!Array.isArray(propValue)) {\n const cssObject = buildCSSObject(propKey as K, propValue, props)\n\n if (Object.keys(cssObject).length > 0) {\n acc.push(cssObject)\n }\n } else if (propValue.length > 0) {\n const mediaFunctions: MediaFunction[] = []\n const queries = propValue.length > deviceQueries.length ? breakpointsQueries : deviceQueries\n\n for (let i = 0; i < propValue.length; i++) {\n if (!queries[i]) break\n\n const cssObject = buildCSSObject(propKey as K, propValue[i], props)\n\n if (Object.keys(cssObject).length > 0) {\n mediaFunctions.push(queries[i]()`${cssObject}`)\n }\n }\n\n acc.push(...mediaFunctions)\n }\n\n return acc\n }, [] as (CSSObject | MediaFunction)[])\n\n const breakpointsInterpolations = propsKeys[1].sort(desktopFirst).reduce((acc, propKey) => {\n const cssObject = buildCSSObject(propKey.replace(breakpointsRegExp, '') as K, props[propKey], props)\n\n if (Object.keys(cssObject).length > 0) {\n acc.push(getMediaQueryByResponsiveProp(propKey)()`${cssObject}`)\n }\n\n return acc\n }, [] as MediaFunction[])\n\n return css`\n ${interpolations}\n ${breakpointsInterpolations}\n `\n }\n}\n\nexport type { ResponsiveProps }\n\nexport { createResponsivePropsMixin }\n"],"names":["createResponsivePropsMixin","propsKeys","buildCSSObject","propsRegExp","RegExp","concat","join","breakpointsPropsRegExp","breakpointsRegExp","deviceQueries","screenMinM","screenMaxM","screenMaxS","breakpointsQueries","screenMinL","screenMaxL","screenMaxXs","screenMaxXxs","props","Object","keys","reduce","groups","propKey","test","push","interpolations","acc","propValue","Array","isArray","length","mediaFunctions","queries","i","cssObject","_templateObject","_taggedTemplateLiteral","breakpointsInterpolations","sort","desktopFirst","replace","getMediaQueryByResponsiveProp","_templateObject2","css"],"mappings":"sUAsBA,SAASA,EACPC,EACAC,GAEA,IAAMC,EAAc,IAAIC,OAAJ,KAAAC,OAAgBJ,EAAUK,KAAK,KAAnD,OACA,IAAMC,EAAyB,IAAIH,OAAJ,KAAAC,OAAgBJ,EAAUK,KAAK,KAA9D,wBACA,IAAME,EAAoB,qBAE1B,IAAMC,EAAgB,CAACC,EAAYC,EAAYC,GAC/C,IAAMC,EAAqB,CAACC,EAAYC,EAAYJ,EAAYC,EAAYI,EAAaC,GAEzF,OAAQC,IACN,IAAMjB,EAAYkB,OAAOC,KAAKF,GAAOG,QAAAA,CAClCC,EAAQC,KACHpB,EAAYqB,KAAKD,GAAUD,EAAO,GAAGG,KAAKF,GACrChB,EAAuBiB,KAAKD,IAAUD,EAAO,GAAGG,KAAKF,GAEvDD,IAET,CAAC,GAAI,KAGP,IAAMI,EAAiBzB,EAAU,GAAGoB,QAAAA,CAAQM,EAAKJ,KAC/C,IAAMK,EAAqBV,EAAMK,GAEjC,GAAKM,MAAMC,QAAQF,IAMZ,GAAIA,EAAUG,OAAS,EAAG,CAC/B,IAAMC,EAAkC,GACxC,IAAMC,EAAUL,EAAUG,OAAStB,EAAcsB,OAASlB,EAAqBJ,EAE/E,IAAK,IAAIyB,EAAI,EAAGA,EAAIN,EAAUG,QACvBE,EAAQC,GADuBA,IAAK,CAGzC,IAAMC,EAAYjC,EAAeqB,EAAcK,EAAUM,GAAIhB,GAEzDC,OAAOC,KAAKe,GAAWJ,OAAS,GAClCC,EAAeP,KAAKQ,EAAQC,IAARD,CAApBG,IAAAA,EAAAC,EAAA,CAAA,GAAA,MAAmCF,IAIvCR,EAAIF,QAAQO,QApBiB,CAC7B,IAAMG,EAAYjC,EAAeqB,EAAcK,EAAWV,GAEtDC,OAAOC,KAAKe,GAAWJ,OAAS,GAClCJ,EAAIF,KAAKU,GAmBb,OAAOR,IACN,IAEH,IAAMW,EAA4BrC,EAAU,GAAGsC,KAAKC,GAAcnB,QAAAA,CAAQM,EAAKJ,KAC7E,IAAMY,EAAYjC,EAAeqB,EAAQkB,QAAQjC,EAAmB,IAAUU,EAAMK,GAAUL,GAM9F,OAJIC,OAAOC,KAAKe,GAAWJ,OAAS,GAClCJ,EAAIF,KAAKiB,EAA8BnB,EAA9BmB,EAAAA,CAATC,IAAAA,EAAAN,EAAA,CAAA,GAAA,MAAoDF,IAG/CR,IACN,IAEH,OAAOiB,EAAP,CAAA,GAAA,IAAA,IACIlB,EACAY"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@foxford/ui",
3
- "version": "2.21.0",
3
+ "version": "2.21.1",
4
4
  "description": "UI components library",
5
5
  "main": "index.cjs.js",
6
6
  "module": "index.js",