@telus-uds/components-base 1.70.0 → 1.72.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/CHANGELOG.md +30 -2
  2. package/jest.setup.js +7 -0
  3. package/lib/Autocomplete/Autocomplete.js +3 -13
  4. package/lib/Card/Card.js +68 -7
  5. package/lib/Card/PressableCardBase.js +2 -0
  6. package/lib/ColourToggle/ColourBubble.js +135 -0
  7. package/lib/ColourToggle/ColourToggle.js +101 -0
  8. package/lib/ColourToggle/index.js +10 -0
  9. package/lib/FlexGrid/Col/Col.js +50 -64
  10. package/lib/FlexGrid/FlexGrid.js +37 -40
  11. package/lib/FlexGrid/Row/Row.js +43 -44
  12. package/lib/Icon/IconText.js +9 -2
  13. package/lib/Link/LinkBase.js +10 -3
  14. package/lib/Modal/ModalContent.js +4 -6
  15. package/lib/OrderedList/Item.js +180 -0
  16. package/lib/OrderedList/ItemBase.js +48 -0
  17. package/lib/OrderedList/OrderedList.js +71 -0
  18. package/lib/OrderedList/OrderedListBase.js +47 -0
  19. package/lib/OrderedList/index.js +10 -0
  20. package/lib/index.js +16 -0
  21. package/lib/utils/ssr-media-query/create-stylesheet/create-stylesheet-mobile.js +56 -0
  22. package/lib/utils/ssr-media-query/create-stylesheet/index.android.js +10 -0
  23. package/lib/utils/ssr-media-query/create-stylesheet/index.ios.js +10 -0
  24. package/lib/utils/ssr-media-query/create-stylesheet/index.js +44 -0
  25. package/lib/utils/ssr-media-query/utils/inject.js +13 -0
  26. package/lib-module/Autocomplete/Autocomplete.js +3 -13
  27. package/lib-module/Card/Card.js +71 -8
  28. package/lib-module/Card/PressableCardBase.js +2 -0
  29. package/lib-module/ColourToggle/ColourBubble.js +125 -0
  30. package/lib-module/ColourToggle/ColourToggle.js +92 -0
  31. package/lib-module/ColourToggle/index.js +2 -0
  32. package/lib-module/FlexGrid/Col/Col.js +51 -65
  33. package/lib-module/FlexGrid/FlexGrid.js +38 -41
  34. package/lib-module/FlexGrid/Row/Row.js +44 -45
  35. package/lib-module/Icon/IconText.js +9 -2
  36. package/lib-module/Link/LinkBase.js +10 -3
  37. package/lib-module/Modal/ModalContent.js +4 -6
  38. package/lib-module/OrderedList/Item.js +171 -0
  39. package/lib-module/OrderedList/ItemBase.js +37 -0
  40. package/lib-module/OrderedList/OrderedList.js +61 -0
  41. package/lib-module/OrderedList/OrderedListBase.js +36 -0
  42. package/lib-module/OrderedList/index.js +2 -0
  43. package/lib-module/index.js +2 -0
  44. package/lib-module/utils/ssr-media-query/create-stylesheet/create-stylesheet-mobile.js +48 -0
  45. package/lib-module/utils/ssr-media-query/create-stylesheet/index.android.js +2 -0
  46. package/lib-module/utils/ssr-media-query/create-stylesheet/index.ios.js +2 -0
  47. package/lib-module/utils/ssr-media-query/create-stylesheet/index.js +36 -0
  48. package/lib-module/utils/ssr-media-query/utils/inject.js +13 -0
  49. package/package.json +2 -2
  50. package/src/Autocomplete/Autocomplete.jsx +14 -21
  51. package/src/Card/Card.jsx +73 -11
  52. package/src/Card/PressableCardBase.jsx +2 -0
  53. package/src/ColourToggle/ColourBubble.jsx +111 -0
  54. package/src/ColourToggle/ColourToggle.jsx +83 -0
  55. package/src/ColourToggle/index.js +3 -0
  56. package/src/FlexGrid/Col/Col.jsx +48 -80
  57. package/src/FlexGrid/FlexGrid.jsx +36 -44
  58. package/src/FlexGrid/Row/Row.jsx +38 -56
  59. package/src/Icon/IconText.jsx +11 -1
  60. package/src/Link/ChevronLink.jsx +1 -0
  61. package/src/Link/LinkBase.jsx +16 -6
  62. package/src/Modal/ModalContent.jsx +4 -6
  63. package/src/OrderedList/Item.jsx +152 -0
  64. package/src/OrderedList/ItemBase.jsx +31 -0
  65. package/src/OrderedList/OrderedList.jsx +61 -0
  66. package/src/OrderedList/OrderedListBase.jsx +33 -0
  67. package/src/OrderedList/index.js +3 -0
  68. package/src/index.js +2 -0
  69. package/src/utils/ssr-media-query/create-stylesheet/create-stylesheet-mobile.js +41 -0
  70. package/src/utils/ssr-media-query/create-stylesheet/index.android.js +3 -0
  71. package/src/utils/ssr-media-query/create-stylesheet/index.ios.js +3 -0
  72. package/src/utils/ssr-media-query/create-stylesheet/index.js +33 -0
  73. package/src/utils/ssr-media-query/utils/inject.js +13 -0
  74. package/types/Badge.d.ts +28 -0
  75. package/types/Box.d.ts +52 -0
  76. package/types/ChevronLink.d.ts +47 -0
  77. package/types/Common.d.ts +106 -0
  78. package/types/Divider.d.ts +19 -0
  79. package/types/ExpandCollapse.d.ts +65 -0
  80. package/types/HorizontalScrollButton.d.ts +16 -0
  81. package/types/Icon.d.ts +21 -0
  82. package/types/Link.d.ts +48 -0
  83. package/types/List.d.ts +48 -0
  84. package/types/Search.d.ts +38 -0
  85. package/types/Select.d.ts +57 -0
  86. package/types/Spacer.d.ts +5 -0
  87. package/types/StackView.d.ts +28 -0
  88. package/types/Tabs.d.ts +46 -0
  89. package/types/TextButton.d.ts +11 -0
  90. package/types/ToggleSwitch.d.ts +54 -0
  91. package/types/ToolTip.d.ts +40 -0
  92. package/types/Typography.d.ts +39 -0
  93. package/types/index.d.ts +62 -0
  94. package/lib/utils/ssr-media-query/create-stylesheet.js +0 -76
  95. package/lib-module/utils/ssr-media-query/create-stylesheet.js +0 -68
  96. package/src/utils/ssr-media-query/create-stylesheet.js +0 -61
@@ -0,0 +1,48 @@
1
+ import { TextAlign } from '@telus-uds/components-web/types/common'
2
+ import { ReactElement, ReactNode } from 'react'
3
+
4
+ type ListVariants = {
5
+ size?: 'small' | 'medium' | 'large'
6
+ compact?: boolean
7
+ }
8
+
9
+ type ListTokens = {
10
+ interItemMargin?: number
11
+ interItemMarginWithDivider?: number
12
+ dividerColor?: string
13
+ dividerSize?: number
14
+ itemBulletContainerWidth?: number
15
+ itemBulletContainerAlign?: TextAlign
16
+ itemBulletWidth?: number
17
+ itemBulletHeight?: number
18
+ itemBulletColor?: string
19
+ itemIconSize?: number
20
+ itemIconColor?: string
21
+ listGutter?: number
22
+ }
23
+
24
+ export interface ListProps {
25
+ tokens?: ListTokens
26
+ variant?: ListVariants
27
+ children: ReactNode | ReactElement
28
+ showDivider?: boolean
29
+ testID?: string
30
+ }
31
+
32
+ export interface ListItemProps {
33
+ tokens?: ListItemTokens
34
+ children: ReactNode | ReactElement
35
+ icon?: ReactNode | string
36
+ iconColor?: string
37
+ iconSize?: number
38
+ title?: string
39
+ testID?: string
40
+ }
41
+
42
+ export interface ListItemTokens {
43
+ iconMarginTop?: number
44
+ itemFontWeight?: number
45
+ itemFontSize?: number
46
+ itemLineHeight?: number
47
+ itemFontName?: string
48
+ }
@@ -0,0 +1,38 @@
1
+ import { CopyType, Size } from './Common'
2
+
3
+ export type SearchTokens = {
4
+ backgroundColor?: string
5
+ color?: string
6
+ borderWidth?: number
7
+ borderColor?: string
8
+ borderRadius?: number
9
+ paddingTop?: Size
10
+ paddingBottom?: Size
11
+ paddingLeft?: Size
12
+ paddingRight?: Size
13
+ outerBackgroundColor?: string
14
+ outerBorderWidth?: number
15
+ outerBorderColor?: string
16
+ outerBorderRadius?: number
17
+ fontName?: string
18
+ fontWeight?: number
19
+ fontSize?: Size
20
+ lineHeight?: number
21
+ placeholderColor?: string
22
+ buttonsGap?: Size
23
+ clearButtonIcon?: React.ReactNode
24
+ submitButtonIcon?: React.ReactNode
25
+ }
26
+
27
+ export interface SearchProps {
28
+ testID?: string
29
+ copy?: CopyType
30
+ initialValue?: string
31
+ placeholder?: string
32
+ inactive?: boolean
33
+ onChange?: (value: string) => void
34
+ onSubmit?: (value: string) => void
35
+ onClear?: () => void
36
+ onFocus?: () => void
37
+ tokens?: SearchTokens
38
+ }
@@ -0,0 +1,57 @@
1
+ import React from 'react'
2
+ import { IconProps } from './Icon'
3
+
4
+ export type SelectTokens = {
5
+ backgroundColor?: string
6
+ color?: string
7
+ borderWidth?: number | string
8
+ borderColor?: string
9
+ borderRadius?: number | string
10
+ paddingTop?: number | string
11
+ paddingBottom?: number | string
12
+ paddingLeft?: number | string
13
+ paddingRight?: number | string
14
+ height?: number | string
15
+ outerBackgroundColor?: string
16
+ outerBorderWidth?: number | string
17
+ outerBorderColor?: string
18
+ fontSize?: number
19
+ fontName?: string
20
+ fontWeight?: number
21
+ icon?: IconProps
22
+ iconSize?: number | string
23
+ iconColor?: string
24
+ validationIcon?: IconProps
25
+ validationIconSize?: number | string
26
+ validationIconColor?: string
27
+ feedbackBackgroundColor?: string
28
+ }
29
+
30
+ export interface SelectProps {
31
+ children: string | React.ReactNode
32
+ label: string
33
+ initialValue?: string
34
+ feedback?: string
35
+ validation?: string
36
+ value?: string
37
+ onChange?: () => void
38
+ nativeID?: string
39
+ hint?: string
40
+ hintPosition?: string
41
+ tooltip?: string
42
+ inactive?: boolean
43
+ readOnly?: boolean
44
+ placeholder?: string
45
+ tokens?: SelectTokens
46
+ testID?: string
47
+ }
48
+
49
+ export interface SelectItemProps {
50
+ children: string | React.ReactNode
51
+ value: string
52
+ }
53
+
54
+ export interface SelectGroupProps {
55
+ children: string | React.ReactNode
56
+ label: string
57
+ }
@@ -0,0 +1,5 @@
1
+ export interface SpacerProps {
2
+ space?: number
3
+ direction?: 'column' | 'row'
4
+ testID?: string
5
+ }
@@ -0,0 +1,28 @@
1
+ import { ReactNode } from 'react'
2
+ import {
3
+ Direction,
4
+ FlexAlign,
5
+ FlexJustify,
6
+ ResponsiveSpacing,
7
+ ResponsiveDirection,
8
+ SemanticTag
9
+ } from './Common'
10
+ import { DividerProps } from './Divider'
11
+
12
+ type StackViewTokens = {
13
+ alignItems?: FlexAlign
14
+ justifyContent?: FlexJustify
15
+ flexGrow?: number
16
+ flexShrink?: number
17
+ width?: number
18
+ }
19
+
20
+ export interface StackViewProps {
21
+ space?: ResponsiveSpacing | number
22
+ direction?: Direction | ResponsiveDirection
23
+ tokens?: StackViewTokens
24
+ divider?: boolean | DividerProps
25
+ tag?: SemanticTag
26
+ children: ReactNode
27
+ testID?: string
28
+ }
@@ -0,0 +1,46 @@
1
+ import { Size } from './Common'
2
+ import { IconProps } from './Icon'
3
+ import { TypographyVariants, TypographyTokens } from './Typography'
4
+ import { HorizontalScrollButtonTokens } from './HorizontalScrollButton'
5
+
6
+ type TabsItem = {
7
+ label: string
8
+ href: string
9
+ id: string
10
+ }
11
+
12
+ type TabsVariant = {
13
+ equalWidth?: string
14
+ inverse?: boolean
15
+ }
16
+
17
+ export interface TabsProps {
18
+ items: Array<TabsItem>
19
+ value?: string
20
+ initialValue?: string
21
+ onChange?: () => void
22
+ itemTokens?: TabsItem
23
+ scrollButtonTokens?: HorizontalScrollButtonTokens
24
+ variant?: TabsVariant
25
+ }
26
+
27
+ export type TabsTokens = {
28
+ nextIcon?: IconProps
29
+ previousIcon?: IconProps
30
+ space?: number
31
+ buttonClearance?: Size
32
+ gutter?: Size
33
+ borderBottomColor?: string
34
+ borderBottomWidth?: number
35
+ }
36
+
37
+ export interface TabSelectorProps {
38
+ items: TabsItem[]
39
+ initialValue?: string
40
+ value?: string
41
+ onChange?: (value: string) => void
42
+ labelVariant?: TypographyVariants
43
+ labelTokens?: TypographyTokens
44
+ testID?: string
45
+ selectedTestID?: string
46
+ }
@@ -0,0 +1,11 @@
1
+ import React from 'react'
2
+ import { LinkTokens, LinkAndTextButtonVariants } from './Link'
3
+
4
+ export interface TextButtonProps {
5
+ onPress: () => void
6
+ accessibilityLabel: string
7
+ children: string | React.ReactNode
8
+ variant?: LinkAndTextButtonVariants
9
+ tokens?: LinkTokens
10
+ testID?: string
11
+ }
@@ -0,0 +1,54 @@
1
+ import { CopyType } from './Common'
2
+
3
+ type ToggleSwitchTokens = {
4
+ borderColor?: string
5
+ borderWidth?: number
6
+ borderRadius?: number
7
+ outerBorderColor?: string
8
+ outerBorderWidth?: number
9
+ outerBorderGap?: number
10
+ outerBackgroundColor?: string
11
+ backgroundColor?: string
12
+ opacity?: number
13
+ paddingLeft?: number
14
+ paddingRight?: number
15
+ paddingTop?: number
16
+ paddingBottom?: number
17
+ shadow?: string
18
+ alignSelf?: string
19
+ space?: number
20
+ icon?: React.ReactNode
21
+ trackHeight?: number
22
+ outerBorderGapButton?: number
23
+ width?: number
24
+ trackBorderWidth?: number
25
+ trackBorderColor?: string
26
+ trackBorderRadius?: number
27
+ iconSize?: number
28
+ iconColor?: string
29
+ labelColor?: string
30
+ labelFontName?: string
31
+ labelFontWeight?: number
32
+ labelLineHeight?: number
33
+ labelMarginLeft?: number
34
+ switchSize?: number
35
+ switchColor?: string
36
+ switchBorderColor?: string
37
+ switchBorderWidth?: number
38
+ switchBorderRadius?: number
39
+ switchShadow?: string
40
+ }
41
+
42
+ export interface ToggleSwitchProps {
43
+ label?: string
44
+ initialValue?: boolean
45
+ value?: boolean
46
+ onChange?: (value: boolean) => void
47
+ accessibilityLabel?: string
48
+ tooltip?: string
49
+ inactive?: boolean
50
+ copy?: CopyType
51
+ id?: string
52
+ testID?: string
53
+ tokens?: ToggleSwitchTokens
54
+ }
@@ -0,0 +1,40 @@
1
+ import { ReactNode } from 'react'
2
+ import { CopyType, Position } from './Common'
3
+
4
+ type TooltipTokens = {
5
+ backgroundColor?: string
6
+ paddingTop?: number
7
+ paddingBottom?: number
8
+ paddingLeft?: number
9
+ paddingRight?: number
10
+ borderRadius?: number
11
+ shadow?: string
12
+ color?: string
13
+ fontSize?: number
14
+ lineHeight?: number
15
+ fontName?: string
16
+ fontWeight?: number
17
+ arrowWidth?: number
18
+ arrowBorderRadius?: number
19
+ arrowOffset?: number
20
+ }
21
+
22
+ type TooltipVariants = {
23
+ inverse?: boolean
24
+ }
25
+
26
+ export interface TooltipProps {
27
+ children?: ReactNode
28
+ content: string | ReactNode
29
+ copy?: CopyType
30
+ position?: Position
31
+ inline?: boolean
32
+ onPress?: () => void
33
+ nativeID?: string
34
+ tokens?: TooltipTokens
35
+ variant?: TooltipVariants
36
+ accessibilityRole?: string
37
+ accessibilityLabel?: string
38
+ accessible?: boolean
39
+ testID?: string
40
+ }
@@ -0,0 +1,39 @@
1
+ import { LetterSpacing, TextTransform } from './Common'
2
+
3
+ export interface TypographyProps {
4
+ tag?: tagType | string
5
+ block?: boolean
6
+ align?: alignType | string
7
+ strikeThrough?: boolean
8
+ tokens?: TypographyTokens
9
+ variant?: TypographyVariants
10
+ heading?: headingType | string
11
+ accessible?: boolean
12
+ accessibilityLabel?: string
13
+ children?: React.ReactNode
14
+ }
15
+
16
+ export type TypographyVariants = {
17
+ color?: string
18
+ secondColor?: string
19
+ animationDuration?: number
20
+ size?: number | string
21
+ radius?: number
22
+ baseWidth?: number
23
+ characters?: number
24
+ spaceBetweenLines?: number
25
+ squareRadius?: number
26
+ inverse?: boolean
27
+ }
28
+
29
+ export type TypographyTokens = {
30
+ fontName?: string
31
+ superScriptFontSize?: number
32
+ fontWeight?: number
33
+ fontSize?: number
34
+ color?: string
35
+ lineHeight?: number
36
+ textTransform?: TextTransform
37
+ fontScaleCap?: number
38
+ letterSpacing?: LetterSpacing
39
+ }
@@ -0,0 +1,62 @@
1
+ export { default as Badge } from './Badge'
2
+ export type { BadgeProps, BadgeVariants, BadgeTokens } from './Badge'
3
+
4
+ export { default as Box } from './Box'
5
+ export type { BoxVariants, BoxTokens, BoxProps } from './Box'
6
+
7
+ export { default as ChevronLink } from './ChevronLink'
8
+ export { ChevronLinkTokens, ChevronLinkProps, HrefProps } from './ChevronLink'
9
+
10
+ export { default as Divider } from './Divider'
11
+ export { DividerVariants, DividerProps, DividerTokens } from './Divider'
12
+
13
+ export { default as ExpandCollapse } from './ExpandCollapse'
14
+ export {
15
+ ExpandCollapseVariants,
16
+ ExpandCollapseTokens,
17
+ ExpandCollapseControlTokens,
18
+ ExpandFnProps,
19
+ ExpandCollapseProps,
20
+ ExpandCollapsePanelProps
21
+ } from './ExpandCollapse'
22
+
23
+ export { default as HorizontalScrollButton } from './HorizontalScrollButton'
24
+ export { HorizontalScrollButtonTokens } from './HorizontalScrollButton'
25
+
26
+ export { default as Icon } from './Icon'
27
+ export { IconProps, IconTokens, IconVariant, IconPositionLeftRight } from './Icon'
28
+
29
+ export { default as Link } from './Link'
30
+ export { LinkProps, LinkSize, LinkAndTextButtonVariants, LinkTokens } from './Link'
31
+
32
+ export { default as List } from './List'
33
+ export { ListVariants, ListTokens, ListProps, ListItemProps, ListItemTokens } from './List'
34
+
35
+ export { default as Search } from './Search'
36
+ export { SearchTokens, SearchProps } from './Search'
37
+
38
+ export { default as Select } from './Select'
39
+ export { SelectTokens, SelectProps, SelectItemProps, SelectGroupProps } from './Select'
40
+
41
+ export { default as Spacer } from './Spacer'
42
+ export { SpacerProps } from './Spacer'
43
+
44
+ export { default as StackView } from './StackView'
45
+ export { StackViewTokens, StackViewProps } from './StackView'
46
+
47
+ export { default as Tabs } from './Tabs'
48
+ export { TabsProps, TabsTokens, TabSelectorProps, TabsVariant, TabsItem } from './Tabs'
49
+
50
+ export { default as TextButton } from './TextButton'
51
+ export { TextButtonProps } from './TextButton'
52
+
53
+ export { default as ToggleSwitch } from './ToggleSwitch'
54
+ export { ToggleSwitchTokens, ToggleSwitchProps } from './ToggleSwitch'
55
+
56
+ export { default as Tooltip } from './ToolTip'
57
+ export { TooltipTokens, TooltipVariants, TooltipProps } from './ToolTip'
58
+
59
+ export { default as Typography } from './Typography'
60
+ export { TypographyProps, TypographyVariants, TypographyTokens } from './Typography'
61
+
62
+ export * from './Common'
@@ -1,76 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _cssMediaquery = _interopRequireDefault(require("css-mediaquery"));
8
- var _Dimensions = _interopRequireDefault(require("react-native-web/dist/cjs/exports/Dimensions"));
9
- var _Platform = _interopRequireDefault(require("react-native-web/dist/cjs/exports/Platform"));
10
- var _inject = require("./utils/inject");
11
- var _createDeclarationBlock = _interopRequireDefault(require("./utils/create-declaration-block"));
12
- var _hash = _interopRequireDefault(require("./hash"));
13
- var _common = require("./utils/common");
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
- const createStyleSheet = stylesWithQuery => {
16
- if (!stylesWithQuery) return {
17
- ids: {},
18
- styles: {},
19
- fullStyles: {}
20
- };
21
- let cleanStyles;
22
- let ids = {};
23
- Object.keys(stylesWithQuery).forEach(key => {
24
- if (!(stylesWithQuery !== null && stylesWithQuery !== void 0 && stylesWithQuery[key])) return;
25
- const mediaQueriesAndPseudoClasses = Object.keys(stylesWithQuery[key]).filter(_common.isMediaOrPseudo);
26
- if (_Platform.default.OS === 'web') {
27
- cleanStyles = (0, _common.deepClone)(stylesWithQuery);
28
- mediaQueriesAndPseudoClasses.forEach(query => {
29
- var _ids;
30
- const css = (0, _createDeclarationBlock.default)(stylesWithQuery[key][query]);
31
- const stringHash = `rnmq-${(0, _hash.default)(`${key}${query}${css}`)}`;
32
- const rule = (0, _common.createCssRule)(query, stringHash, css);
33
- (0, _inject.addCss)(`${stringHash}`, rule);
34
- delete cleanStyles[key][query];
35
- ids = {
36
- ...ids,
37
- [key]: `${(_ids = ids) !== null && _ids !== void 0 && _ids[key] ? `${ids[key]} ` : ''}${stringHash}`
38
- };
39
- });
40
- } else {
41
- cleanStyles = JSON.parse(JSON.stringify(stylesWithQuery));
42
- mediaQueriesAndPseudoClasses.forEach(str => {
43
- if ((0, _common.isMedia)(str)) {
44
- const mqStr = str.replace('@media', '');
45
- const {
46
- width,
47
- height
48
- } = _Dimensions.default.get('window');
49
- const isMatchingMediaQuery = _cssMediaquery.default.match(mqStr, {
50
- width,
51
- height,
52
- orientation: width > height ? 'landscape' : 'portrait',
53
- 'aspect-ratio': width / height
54
- });
55
- if (isMatchingMediaQuery) {
56
- cleanStyles = {
57
- ...cleanStyles,
58
- [key]: {
59
- ...cleanStyles[key],
60
- ...stylesWithQuery[key][str]
61
- }
62
- };
63
- }
64
- }
65
- delete cleanStyles[key][str];
66
- });
67
- }
68
- });
69
- return {
70
- ids,
71
- styles: cleanStyles,
72
- fullStyles: stylesWithQuery
73
- };
74
- };
75
- var _default = createStyleSheet;
76
- exports.default = _default;
@@ -1,68 +0,0 @@
1
- import mediaQuery from 'css-mediaquery';
2
- import Dimensions from "react-native-web/dist/exports/Dimensions";
3
- import Platform from "react-native-web/dist/exports/Platform";
4
- import { addCss } from './utils/inject';
5
- import createDeclarationBlock from './utils/create-declaration-block';
6
- import hash from './hash';
7
- import { isMediaOrPseudo, isMedia, deepClone, createCssRule } from './utils/common';
8
- const createStyleSheet = stylesWithQuery => {
9
- if (!stylesWithQuery) return {
10
- ids: {},
11
- styles: {},
12
- fullStyles: {}
13
- };
14
- let cleanStyles;
15
- let ids = {};
16
- Object.keys(stylesWithQuery).forEach(key => {
17
- if (!(stylesWithQuery !== null && stylesWithQuery !== void 0 && stylesWithQuery[key])) return;
18
- const mediaQueriesAndPseudoClasses = Object.keys(stylesWithQuery[key]).filter(isMediaOrPseudo);
19
- if (Platform.OS === 'web') {
20
- cleanStyles = deepClone(stylesWithQuery);
21
- mediaQueriesAndPseudoClasses.forEach(query => {
22
- var _ids;
23
- const css = createDeclarationBlock(stylesWithQuery[key][query]);
24
- const stringHash = `rnmq-${hash(`${key}${query}${css}`)}`;
25
- const rule = createCssRule(query, stringHash, css);
26
- addCss(`${stringHash}`, rule);
27
- delete cleanStyles[key][query];
28
- ids = {
29
- ...ids,
30
- [key]: `${(_ids = ids) !== null && _ids !== void 0 && _ids[key] ? `${ids[key]} ` : ''}${stringHash}`
31
- };
32
- });
33
- } else {
34
- cleanStyles = JSON.parse(JSON.stringify(stylesWithQuery));
35
- mediaQueriesAndPseudoClasses.forEach(str => {
36
- if (isMedia(str)) {
37
- const mqStr = str.replace('@media', '');
38
- const {
39
- width,
40
- height
41
- } = Dimensions.get('window');
42
- const isMatchingMediaQuery = mediaQuery.match(mqStr, {
43
- width,
44
- height,
45
- orientation: width > height ? 'landscape' : 'portrait',
46
- 'aspect-ratio': width / height
47
- });
48
- if (isMatchingMediaQuery) {
49
- cleanStyles = {
50
- ...cleanStyles,
51
- [key]: {
52
- ...cleanStyles[key],
53
- ...stylesWithQuery[key][str]
54
- }
55
- };
56
- }
57
- }
58
- delete cleanStyles[key][str];
59
- });
60
- }
61
- });
62
- return {
63
- ids,
64
- styles: cleanStyles,
65
- fullStyles: stylesWithQuery
66
- };
67
- };
68
- export default createStyleSheet;
@@ -1,61 +0,0 @@
1
- import mediaQuery from 'css-mediaquery'
2
- import { Dimensions, Platform } from 'react-native'
3
- import { addCss } from './utils/inject'
4
- import createDeclarationBlock from './utils/create-declaration-block'
5
- import hash from './hash'
6
- import { isMediaOrPseudo, isMedia, deepClone, createCssRule } from './utils/common'
7
-
8
- const createStyleSheet = (stylesWithQuery) => {
9
- if (!stylesWithQuery) return { ids: {}, styles: {}, fullStyles: {} }
10
- let cleanStyles
11
- let ids = {}
12
- Object.keys(stylesWithQuery).forEach((key) => {
13
- if (!stylesWithQuery?.[key]) return
14
-
15
- const mediaQueriesAndPseudoClasses = Object.keys(stylesWithQuery[key]).filter(isMediaOrPseudo)
16
- if (Platform.OS === 'web') {
17
- cleanStyles = deepClone(stylesWithQuery)
18
- mediaQueriesAndPseudoClasses.forEach((query) => {
19
- const css = createDeclarationBlock(stylesWithQuery[key][query])
20
- const stringHash = `rnmq-${hash(`${key}${query}${css}`)}`
21
- const rule = createCssRule(query, stringHash, css)
22
-
23
- addCss(`${stringHash}`, rule)
24
- delete cleanStyles[key][query]
25
-
26
- ids = {
27
- ...ids,
28
- [key]: `${ids?.[key] ? `${ids[key]} ` : ''}${stringHash}`
29
- }
30
- })
31
- } else {
32
- cleanStyles = JSON.parse(JSON.stringify(stylesWithQuery))
33
- mediaQueriesAndPseudoClasses.forEach((str) => {
34
- if (isMedia(str)) {
35
- const mqStr = str.replace('@media', '')
36
- const { width, height } = Dimensions.get('window')
37
-
38
- const isMatchingMediaQuery = mediaQuery.match(mqStr, {
39
- width,
40
- height,
41
- orientation: width > height ? 'landscape' : 'portrait',
42
- 'aspect-ratio': width / height
43
- })
44
-
45
- if (isMatchingMediaQuery) {
46
- cleanStyles = {
47
- ...cleanStyles,
48
- [key]: { ...cleanStyles[key], ...stylesWithQuery[key][str] }
49
- }
50
- }
51
- }
52
-
53
- delete cleanStyles[key][str]
54
- })
55
- }
56
- })
57
-
58
- return { ids, styles: cleanStyles, fullStyles: stylesWithQuery }
59
- }
60
-
61
- export default createStyleSheet