@telus-uds/components-base 4.0.0-alpha.1 → 4.0.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/CHANGELOG.md +28 -1
- package/lib/cjs/Footnote/FootnoteLink.js +18 -17
- package/lib/cjs/Progress/Progress.js +30 -5
- package/lib/cjs/Scroll/Scroll.js +472 -0
- package/lib/cjs/Scroll/ScrollContext.js +55 -0
- package/lib/cjs/Scroll/ScrollItem.js +106 -0
- package/lib/cjs/Scroll/ScrollProgress.js +100 -0
- package/lib/cjs/Scroll/dictionary.js +18 -0
- package/lib/cjs/index.js +14 -0
- package/lib/cjs/utils/animation/useAnimatedValue.js +46 -0
- package/lib/cjs/utils/children.js +2 -1
- package/lib/esm/Footnote/FootnoteLink.js +18 -17
- package/lib/esm/Progress/Progress.js +30 -5
- package/lib/esm/Scroll/Scroll.js +465 -0
- package/lib/esm/Scroll/ScrollContext.js +46 -0
- package/lib/esm/Scroll/ScrollItem.js +100 -0
- package/lib/esm/Scroll/ScrollProgress.js +93 -0
- package/lib/esm/Scroll/dictionary.js +12 -0
- package/lib/esm/index.js +2 -0
- package/lib/esm/utils/animation/useAnimatedValue.js +38 -0
- package/lib/esm/utils/children.js +2 -1
- package/lib/package.json +2 -2
- package/package.json +2 -2
- package/src/Footnote/FootnoteLink.jsx +17 -12
- package/src/Progress/Progress.jsx +22 -3
- package/src/Scroll/Scroll.jsx +483 -0
- package/src/Scroll/ScrollContext.jsx +39 -0
- package/src/Scroll/ScrollItem.jsx +87 -0
- package/src/Scroll/ScrollProgress.jsx +74 -0
- package/src/Scroll/dictionary.js +12 -0
- package/src/index.js +2 -0
- package/src/utils/animation/useAnimatedValue.js +35 -0
- package/src/utils/children.jsx +4 -1
- package/types/Scroll.d.ts +66 -0
- package/types/index.d.ts +9 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const dictionary = {
|
|
2
|
+
en: {
|
|
3
|
+
accessibilityLabel: 'Scrollable content',
|
|
4
|
+
instructionText: 'Use Tab, arrow keys, or space bar to navigate',
|
|
5
|
+
progressBarLabel: 'Scroll position'
|
|
6
|
+
},
|
|
7
|
+
fr: {
|
|
8
|
+
accessibilityLabel: 'Contenu défilable',
|
|
9
|
+
instructionText: "Utilisez Tab, les touches fléchées ou la barre d'espace pour naviguer",
|
|
10
|
+
progressBarLabel: 'Position de défilement'
|
|
11
|
+
}
|
|
12
|
+
};
|
package/lib/esm/index.js
CHANGED
|
@@ -73,6 +73,8 @@ export { RadioGroup } from './Radio/RadioGroup';
|
|
|
73
73
|
export { RadioCard } from './RadioCard/RadioCard';
|
|
74
74
|
export { RadioCardGroup } from './RadioCard/RadioCardGroup';
|
|
75
75
|
export { Responsive } from './Responsive/Responsive';
|
|
76
|
+
export { Scroll } from './Scroll/Scroll';
|
|
77
|
+
export { ScrollItem } from './Scroll/ScrollItem';
|
|
76
78
|
export { Search } from './Search/Search';
|
|
77
79
|
export { Select } from './Select/Select';
|
|
78
80
|
export { SelectItem } from './Select/SelectItem';
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import Animated from "react-native-web/dist/exports/Animated";
|
|
3
|
+
import Easing from "react-native-web/dist/exports/Easing";
|
|
4
|
+
const ANIMATION_DURATION = 200;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Smoothly animates a numeric value to a new target using a quadratic ease-in-out
|
|
8
|
+
* curve. Returns the current interpolated value as a plain number so
|
|
9
|
+
* consumers can use it in non-Animated style props.
|
|
10
|
+
*
|
|
11
|
+
* @param {number} targetValue - The value to animate towards.
|
|
12
|
+
* @param {number} [duration=ANIMATION_DURATION] - Animation duration in ms.
|
|
13
|
+
*/
|
|
14
|
+
export const useAnimatedValue = function (targetValue) {
|
|
15
|
+
let duration = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ANIMATION_DURATION;
|
|
16
|
+
const [currentValue, setCurrentValue] = React.useState(targetValue);
|
|
17
|
+
const animatedValue = React.useRef(new Animated.Value(targetValue)).current;
|
|
18
|
+
React.useEffect(() => {
|
|
19
|
+
const id = animatedValue.addListener(_ref => {
|
|
20
|
+
let {
|
|
21
|
+
value
|
|
22
|
+
} = _ref;
|
|
23
|
+
return setCurrentValue(value);
|
|
24
|
+
});
|
|
25
|
+
return () => animatedValue.removeListener(id);
|
|
26
|
+
}, [animatedValue]);
|
|
27
|
+
React.useEffect(() => {
|
|
28
|
+
const animation = Animated.timing(animatedValue, {
|
|
29
|
+
toValue: targetValue,
|
|
30
|
+
duration,
|
|
31
|
+
easing: Easing.inOut(Easing.quad),
|
|
32
|
+
useNativeDriver: false
|
|
33
|
+
});
|
|
34
|
+
animation.start();
|
|
35
|
+
return () => animation.stop();
|
|
36
|
+
}, [targetValue, animatedValue, duration]);
|
|
37
|
+
return currentValue;
|
|
38
|
+
};
|
|
@@ -47,7 +47,8 @@ export const unpackFragment = child => {
|
|
|
47
47
|
};
|
|
48
48
|
const isStringOrNumber = child => typeof child === 'string' || typeof child === 'number';
|
|
49
49
|
// Wrap an A11yText with neighouring text strings so it doesn't split them into multiple <Text>s
|
|
50
|
-
|
|
50
|
+
// Check displayName first as it is explicitly set and reliable regardless of export style (named vs default)
|
|
51
|
+
const isWrapable = child => isStringOrNumber(child) || child.type === A11yText || child.type?.__UDS_COMPONENT_NAME__ === 'FootnoteLink';
|
|
51
52
|
const combineKeys = childrenArray => childrenArray.reduce((newKey, child) => `${newKey}${child.key || ''}`, '');
|
|
52
53
|
|
|
53
54
|
// Group wrappable children for one `<Text>` parent, merging adjacent text nodes
|
package/lib/package.json
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"@gorhom/portal": "^1.0.14",
|
|
13
13
|
"@react-native-picker/picker": "^2.11.4",
|
|
14
14
|
"@telus-uds/system-constants": "^4.0.0-alpha.0",
|
|
15
|
-
"@telus-uds/system-theme-tokens": "^5.0.0-alpha.
|
|
15
|
+
"@telus-uds/system-theme-tokens": "^5.0.0-alpha.2",
|
|
16
16
|
"css-mediaquery": "^0.1.2",
|
|
17
17
|
"expo-document-picker": "^14.0.8",
|
|
18
18
|
"expo-linear-gradient": "^15.0.8",
|
|
@@ -81,6 +81,6 @@
|
|
|
81
81
|
"standard-engine": {
|
|
82
82
|
"skip": true
|
|
83
83
|
},
|
|
84
|
-
"version": "4.0.0-alpha.
|
|
84
|
+
"version": "4.0.0-alpha.2",
|
|
85
85
|
"types": "types/index.d.ts"
|
|
86
86
|
}
|
package/package.json
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"@gorhom/portal": "^1.0.14",
|
|
13
13
|
"@react-native-picker/picker": "^2.11.4",
|
|
14
14
|
"@telus-uds/system-constants": "^4.0.0-alpha.0",
|
|
15
|
-
"@telus-uds/system-theme-tokens": "^5.0.0-alpha.
|
|
15
|
+
"@telus-uds/system-theme-tokens": "^5.0.0-alpha.2",
|
|
16
16
|
"css-mediaquery": "^0.1.2",
|
|
17
17
|
"expo-document-picker": "^14.0.8",
|
|
18
18
|
"expo-linear-gradient": "^15.0.8",
|
|
@@ -81,6 +81,6 @@
|
|
|
81
81
|
"standard-engine": {
|
|
82
82
|
"skip": true
|
|
83
83
|
},
|
|
84
|
-
"version": "4.0.0-alpha.
|
|
84
|
+
"version": "4.0.0-alpha.2",
|
|
85
85
|
"types": "types/index.d.ts"
|
|
86
86
|
}
|
|
@@ -13,22 +13,26 @@ import { useThemeTokens } from '../ThemeProvider/useThemeTokens'
|
|
|
13
13
|
|
|
14
14
|
const [selectProps, selectedSystemPropTypes] = selectSystemProps([htmlAttrs, viewProps])
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
16
|
+
const HALF_FONT_SIZE = 2
|
|
17
|
+
const QUARTER_FONT_SIZE = 4
|
|
18
|
+
const DEFAULT_LINE_HEIGHT = 1
|
|
19
|
+
const LINE_HEIGHT_MULTIPLIER = 2
|
|
20
|
+
|
|
21
|
+
const selectTextStyle = ({ fontSize, lineHeight }) =>
|
|
22
|
+
Platform.select({
|
|
23
|
+
native: {
|
|
24
|
+
fontSize: fontSize / HALF_FONT_SIZE,
|
|
25
|
+
lineHeight: fontSize,
|
|
26
|
+
position: 'relative',
|
|
27
|
+
top: -(fontSize * lineHeight) / HALF_FONT_SIZE
|
|
26
28
|
},
|
|
27
29
|
web: {
|
|
28
|
-
|
|
30
|
+
fontSize,
|
|
31
|
+
lineHeight:
|
|
32
|
+
lineHeight !== DEFAULT_LINE_HEIGHT ? lineHeight : fontSize * LINE_HEIGHT_MULTIPLIER,
|
|
33
|
+
top: -fontSize / QUARTER_FONT_SIZE
|
|
29
34
|
}
|
|
30
35
|
})
|
|
31
|
-
})
|
|
32
36
|
|
|
33
37
|
export const FootnoteLink = React.forwardRef(
|
|
34
38
|
({ copy = 'en', content = [], onClick, tokens, variant = {}, ...rest }, ref) => {
|
|
@@ -69,6 +73,7 @@ export const FootnoteLink = React.forwardRef(
|
|
|
69
73
|
)
|
|
70
74
|
|
|
71
75
|
FootnoteLink.displayName = 'FootnoteLink'
|
|
76
|
+
FootnoteLink.__UDS_COMPONENT_NAME__ = 'FootnoteLink'
|
|
72
77
|
|
|
73
78
|
const copyShape = PropTypes.shape({ a11yLabel: PropTypes.string.isRequired })
|
|
74
79
|
|
|
@@ -13,6 +13,9 @@ import { ProgressContext } from './ProgressContext'
|
|
|
13
13
|
|
|
14
14
|
const [selectProps, selectedSystemPropTypes] = selectSystemProps([a11yProps, viewProps])
|
|
15
15
|
|
|
16
|
+
const BORDER_SIDES = 2
|
|
17
|
+
const CENTER_DIVISOR = 2
|
|
18
|
+
|
|
16
19
|
const selectProgressStyles = ({
|
|
17
20
|
backgroundColor,
|
|
18
21
|
borderWidth,
|
|
@@ -29,6 +32,14 @@ const selectProgressStyles = ({
|
|
|
29
32
|
...applyShadowToken(shadow)
|
|
30
33
|
})
|
|
31
34
|
|
|
35
|
+
const selectBarWrapperStyles = ({ barHeight, borderRadius, borderWidth, height }) => ({
|
|
36
|
+
height: barHeight,
|
|
37
|
+
width: '100%',
|
|
38
|
+
position: 'absolute',
|
|
39
|
+
top: (height - borderWidth * BORDER_SIDES - barHeight) / CENTER_DIVISOR,
|
|
40
|
+
borderRadius
|
|
41
|
+
})
|
|
42
|
+
|
|
32
43
|
/**
|
|
33
44
|
* The `Progress` is a container for displaying one or several `ProgressBar`s.
|
|
34
45
|
*
|
|
@@ -41,10 +52,11 @@ const selectProgressStyles = ({
|
|
|
41
52
|
*
|
|
42
53
|
* - Use the following tokens to customize the appearance:
|
|
43
54
|
* - `backgroundColor` for the background color of the progress container,
|
|
55
|
+
* - `barHeight` to control the height of the progress bars displayed within the container,
|
|
44
56
|
* - `borderColor` to control the color of the border,
|
|
45
57
|
* - `borderRadius` for the rounded corners,
|
|
46
58
|
* - `borderWidth` to change the border width.
|
|
47
|
-
* - `height` to control the height of the progress
|
|
59
|
+
* - `height` to control the height of the progress bar container.
|
|
48
60
|
* - `shadow` to apply a box shadow to the progress bar container.
|
|
49
61
|
*
|
|
50
62
|
* ## Variants
|
|
@@ -67,8 +79,15 @@ const selectProgressStyles = ({
|
|
|
67
79
|
*/
|
|
68
80
|
export const Progress = React.forwardRef(({ children, tokens, variant, ...rest }, ref) => {
|
|
69
81
|
const themeTokens = useThemeTokens('Progress', tokens, variant)
|
|
70
|
-
// Default to false (vertical layout) to preserve existing behavior and avoid breaking changes
|
|
71
82
|
const layers = variant?.layers ?? false
|
|
83
|
+
const { barHeight, height } = themeTokens
|
|
84
|
+
|
|
85
|
+
const content =
|
|
86
|
+
barHeight && barHeight !== height ? (
|
|
87
|
+
<View style={selectBarWrapperStyles(themeTokens)}>{children}</View>
|
|
88
|
+
) : (
|
|
89
|
+
children
|
|
90
|
+
)
|
|
72
91
|
|
|
73
92
|
return (
|
|
74
93
|
<ProgressContext.Provider value={{ layers }}>
|
|
@@ -77,7 +96,7 @@ export const Progress = React.forwardRef(({ children, tokens, variant, ...rest }
|
|
|
77
96
|
style={[staticStyles.progressContainer, selectProgressStyles(themeTokens)]}
|
|
78
97
|
{...selectProps(rest)}
|
|
79
98
|
>
|
|
80
|
-
{
|
|
99
|
+
{content}
|
|
81
100
|
</View>
|
|
82
101
|
</ProgressContext.Provider>
|
|
83
102
|
)
|