@telus-uds/components-base 1.69.0 → 1.71.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.
- package/CHANGELOG.md +21 -2
- package/jest.setup.js +7 -0
- package/lib/Autocomplete/Autocomplete.js +3 -13
- package/lib/Card/Card.js +68 -7
- package/lib/Card/PressableCardBase.js +2 -0
- package/lib/FlexGrid/Col/Col.js +50 -64
- package/lib/FlexGrid/FlexGrid.js +37 -40
- package/lib/FlexGrid/Row/Row.js +43 -44
- package/lib/Icon/IconText.js +9 -2
- package/lib/Link/LinkBase.js +10 -3
- package/lib/utils/index.js +12 -0
- package/lib/utils/ssr-media-query/create-stylesheet.js +76 -0
- package/lib/utils/ssr-media-query/hash.js +19 -0
- package/lib/utils/ssr-media-query/index.js +19 -0
- package/lib/utils/ssr-media-query/utils/common.js +25 -0
- package/lib/utils/ssr-media-query/utils/create-declaration-block.js +24 -0
- package/lib/utils/ssr-media-query/utils/create-media-query-styles.js +34 -0
- package/lib/utils/ssr-media-query/utils/hyphenate-style-name.js +19 -0
- package/lib/utils/ssr-media-query/utils/inject.js +49 -0
- package/lib/utils/ssr.js +2 -1
- package/lib-module/Autocomplete/Autocomplete.js +3 -13
- package/lib-module/Card/Card.js +71 -8
- package/lib-module/Card/PressableCardBase.js +2 -0
- package/lib-module/FlexGrid/Col/Col.js +51 -65
- package/lib-module/FlexGrid/FlexGrid.js +38 -41
- package/lib-module/FlexGrid/Row/Row.js +44 -45
- package/lib-module/Icon/IconText.js +9 -2
- package/lib-module/Link/LinkBase.js +10 -3
- package/lib-module/utils/index.js +1 -0
- package/lib-module/utils/ssr-media-query/create-stylesheet.js +68 -0
- package/lib-module/utils/ssr-media-query/hash.js +13 -0
- package/lib-module/utils/ssr-media-query/index.js +6 -0
- package/lib-module/utils/ssr-media-query/utils/common.js +15 -0
- package/lib-module/utils/ssr-media-query/utils/create-declaration-block.js +16 -0
- package/lib-module/utils/ssr-media-query/utils/create-media-query-styles.js +30 -0
- package/lib-module/utils/ssr-media-query/utils/hyphenate-style-name.js +12 -0
- package/lib-module/utils/ssr-media-query/utils/inject.js +39 -0
- package/lib-module/utils/ssr.js +3 -1
- package/package.json +3 -2
- package/src/Autocomplete/Autocomplete.jsx +14 -21
- package/src/Card/Card.jsx +73 -11
- package/src/Card/PressableCardBase.jsx +2 -0
- package/src/FlexGrid/Col/Col.jsx +48 -80
- package/src/FlexGrid/FlexGrid.jsx +36 -44
- package/src/FlexGrid/Row/Row.jsx +38 -56
- package/src/Icon/IconText.jsx +11 -1
- package/src/Link/ChevronLink.jsx +1 -0
- package/src/Link/LinkBase.jsx +16 -6
- package/src/utils/index.js +1 -1
- package/src/utils/ssr-media-query/create-stylesheet.js +61 -0
- package/src/utils/ssr-media-query/hash.js +16 -0
- package/src/utils/ssr-media-query/index.js +8 -0
- package/src/utils/ssr-media-query/utils/common.js +20 -0
- package/src/utils/ssr-media-query/utils/create-declaration-block.js +21 -0
- package/src/utils/ssr-media-query/utils/create-media-query-styles.js +31 -0
- package/src/utils/ssr-media-query/utils/hyphenate-style-name.js +15 -0
- package/src/utils/ssr-media-query/utils/inject.js +43 -0
- package/src/utils/ssr.jsx +3 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/* eslint-disable no-bitwise */
|
|
2
|
+
export default function hash(text) {
|
|
3
|
+
if (!text) {
|
|
4
|
+
return ''
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
let hashValue = 5381
|
|
8
|
+
let index = text.length - 1
|
|
9
|
+
|
|
10
|
+
while (index) {
|
|
11
|
+
hashValue = (hashValue * 33) ^ text.charCodeAt(index)
|
|
12
|
+
index -= 1
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return (hashValue >>> 0).toString(16)
|
|
16
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const isMedia = (query) => query.indexOf('@media') === 0
|
|
2
|
+
const isPseudo = (query) => query.indexOf(':') === 0
|
|
3
|
+
const isMediaOrPseudo = (query) => isMedia(query) || isPseudo(query)
|
|
4
|
+
|
|
5
|
+
const deepClone = (obj) => JSON.parse(JSON.stringify(obj))
|
|
6
|
+
|
|
7
|
+
const createCssRule = (query, stringHash, css) => {
|
|
8
|
+
let rule
|
|
9
|
+
const dataMediaSelector = `[data-media~="${stringHash}"]`
|
|
10
|
+
|
|
11
|
+
if (isMedia(query)) {
|
|
12
|
+
rule = `${query} {${dataMediaSelector} ${css}}`
|
|
13
|
+
} else {
|
|
14
|
+
rule = `${dataMediaSelector}${query} ${css}`
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return rule
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { isMedia, isPseudo, isMediaOrPseudo, deepClone, createCssRule }
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import createReactDOMStyle from 'react-native-web/dist/cjs/exports/StyleSheet/compiler/createReactDOMStyle'
|
|
2
|
+
import prefixStyles from 'react-native-web/dist/cjs/modules/prefixStyles'
|
|
3
|
+
import hyphenateStyleName from './hyphenate-style-name'
|
|
4
|
+
|
|
5
|
+
const createDeclarationBlock = (style) => {
|
|
6
|
+
const domStyle = prefixStyles(createReactDOMStyle(style))
|
|
7
|
+
const declarationsString = Object.keys(domStyle)
|
|
8
|
+
.map((property) => {
|
|
9
|
+
const value = domStyle[property]
|
|
10
|
+
const prop = hyphenateStyleName(property)
|
|
11
|
+
if (Array.isArray(value)) {
|
|
12
|
+
return value.map((v) => `${prop}:${v}`).join(';')
|
|
13
|
+
}
|
|
14
|
+
return `${prop}:${value} !important`
|
|
15
|
+
})
|
|
16
|
+
.sort()
|
|
17
|
+
.join(';')
|
|
18
|
+
return `{${declarationsString};}`
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export default createDeclarationBlock
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { viewports } from '@telus-uds/system-constants'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @typedef { Object } CssStyles
|
|
5
|
+
* @typedef { Record<"xs" | "sm" | "md" | "lg" | "xl", CssStyles> } ViewportStyles
|
|
6
|
+
* @typedef { Record<String, CssStyles> } MediaQueryStyles
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Generates media query styles based on specified viewport styles.
|
|
11
|
+
* @param {ViewportStyles} viewportStyles
|
|
12
|
+
* @returns { MediaQueryStyles }
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
function createMediaQueryStyles(viewportStyles) {
|
|
16
|
+
const viewportsArray = Object.keys(viewportStyles)
|
|
17
|
+
const mediaQueries = Object.entries(viewportStyles).reduce((acc, [viewport, styles]) => {
|
|
18
|
+
const minWidth = viewports.map.get(viewport)
|
|
19
|
+
const nextViewport = viewportsArray[viewportsArray.indexOf(viewport) + 1]
|
|
20
|
+
const maxWidth = viewports.map.get(nextViewport)
|
|
21
|
+
|
|
22
|
+
const mediaQuery = `@media (min-width: ${minWidth}px)${
|
|
23
|
+
maxWidth ? ` and (max-width: ${maxWidth}px)` : ''
|
|
24
|
+
}`
|
|
25
|
+
return { ...acc, [mediaQuery]: styles }
|
|
26
|
+
}, {})
|
|
27
|
+
|
|
28
|
+
return mediaQueries
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default createMediaQueryStyles
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const uppercasePattern = /[A-Z]/g
|
|
2
|
+
const msPattern = /^ms-/
|
|
3
|
+
const cache = {}
|
|
4
|
+
|
|
5
|
+
const toHyphenLower = (match) => `-${match.toLowerCase()}`
|
|
6
|
+
|
|
7
|
+
const hyphenateStyleName = (name) => {
|
|
8
|
+
if (Object.prototype.hasOwnProperty.call(cache, name)) {
|
|
9
|
+
return cache[name]
|
|
10
|
+
}
|
|
11
|
+
const hName = name.replace(uppercasePattern, toHyphenLower)
|
|
12
|
+
return cache[name] === msPattern.test(hName) ? `-${hName}` : hName
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default hyphenateStyleName
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { Platform } from 'react-native'
|
|
3
|
+
|
|
4
|
+
const rules = {}
|
|
5
|
+
let styleSheet
|
|
6
|
+
|
|
7
|
+
if (typeof window !== 'undefined' && typeof document !== 'undefined') {
|
|
8
|
+
styleSheet = (() => {
|
|
9
|
+
const style = document.createElement('style')
|
|
10
|
+
style.id = 'RNMQCSS'
|
|
11
|
+
style.appendChild(document.createTextNode(''))
|
|
12
|
+
document.head.appendChild(style)
|
|
13
|
+
return style.sheet
|
|
14
|
+
})()
|
|
15
|
+
}
|
|
16
|
+
export const hasCss = (id, text) => {
|
|
17
|
+
return !!rules[id] && !!rules[id].text?.includes?.(text)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const addCss = (id, text) => {
|
|
21
|
+
if (!hasCss(id, text)) {
|
|
22
|
+
rules[id] = rules?.[id] || {}
|
|
23
|
+
rules[id].text = (rules[id]?.text || '') + text
|
|
24
|
+
if (styleSheet) {
|
|
25
|
+
styleSheet.insertRule(text, Object.keys(rules).length - 1)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const flush = () => {
|
|
31
|
+
if (Platform.OS === 'web') {
|
|
32
|
+
return React.createElement('style', {
|
|
33
|
+
id: 'rnmq',
|
|
34
|
+
key: 'rnmq',
|
|
35
|
+
dangerouslySetInnerHTML: {
|
|
36
|
+
__html: Object.keys(rules)
|
|
37
|
+
.map((key) => rules[key].text)
|
|
38
|
+
.join('\n')
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
return {}
|
|
43
|
+
}
|
package/src/utils/ssr.jsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import { AppRegistry } from 'react-native'
|
|
3
|
+
import { flush } from './ssr-media-query/utils/inject'
|
|
3
4
|
/** @typedef {import('react').ComponentType} ReactComponent */
|
|
4
5
|
/** @typedef {import('react').ReactElement} ReactElement */
|
|
5
6
|
|
|
@@ -80,7 +81,8 @@ export const ssrStyles = (appName = 'UDS app', { styleGetters = [], collectStyle
|
|
|
80
81
|
*/
|
|
81
82
|
getStyles: (...existingStyles) => {
|
|
82
83
|
if (!hasAppRendered) throw new Error('Called getStyles before renderApp in ssrStyles')
|
|
83
|
-
|
|
84
|
+
|
|
85
|
+
return [...existingStyles, ...styleGetters.flatMap((getter) => getter()), flush()]
|
|
84
86
|
}
|
|
85
87
|
}
|
|
86
88
|
}
|