@fluentui-react-native/stack 0.8.15 → 0.9.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.json +77 -8
- package/CHANGELOG.md +25 -8
- package/lib/Stack.tokens.d.ts.map +1 -1
- package/lib/Stack.tokens.js +6 -11
- package/lib/Stack.tokens.js.map +1 -1
- package/lib/Stack.types.d.ts +8 -5
- package/lib/Stack.types.d.ts.map +1 -1
- package/lib/Stack.types.js.map +1 -1
- package/lib/StackItem/StackItem.types.d.ts +3 -3
- package/lib/StackItem/StackItem.types.d.ts.map +1 -1
- package/lib/StackUtils.d.ts +9 -15
- package/lib/StackUtils.d.ts.map +1 -1
- package/lib/StackUtils.js +15 -32
- package/lib/StackUtils.js.map +1 -1
- package/lib/StackUtils.test.win32.js +0 -34
- package/lib/StackUtils.test.win32.js.map +1 -1
- package/lib-commonjs/Stack.tokens.d.ts.map +1 -1
- package/lib-commonjs/Stack.tokens.js +6 -11
- package/lib-commonjs/Stack.tokens.js.map +1 -1
- package/lib-commonjs/Stack.types.d.ts +8 -5
- package/lib-commonjs/Stack.types.d.ts.map +1 -1
- package/lib-commonjs/Stack.types.js.map +1 -1
- package/lib-commonjs/StackItem/StackItem.types.d.ts +3 -3
- package/lib-commonjs/StackItem/StackItem.types.d.ts.map +1 -1
- package/lib-commonjs/StackUtils.d.ts +9 -15
- package/lib-commonjs/StackUtils.d.ts.map +1 -1
- package/lib-commonjs/StackUtils.js +15 -32
- package/lib-commonjs/StackUtils.js.map +1 -1
- package/lib-commonjs/StackUtils.test.win32.js +0 -34
- package/lib-commonjs/StackUtils.test.win32.js.map +1 -1
- package/package.json +13 -12
- package/src/Stack.tokens.ts +6 -11
- package/src/Stack.types.ts +8 -5
- package/src/StackItem/StackItem.types.ts +3 -3
- package/src/StackUtils.test.win32.ts +0 -40
- package/src/StackUtils.ts +27 -42
package/src/StackUtils.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Theme } from '@fluentui-react-native/framework';
|
|
1
|
+
import type { Spacing, Theme } from '@fluentui-react-native/framework';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Functions used by Stack components to simplify style-related computations
|
|
@@ -8,57 +8,51 @@ import type { Theme } from '@fluentui-react-native/framework';
|
|
|
8
8
|
const _spacingKey = 'spacing';
|
|
9
9
|
|
|
10
10
|
// Helper function that converts a themed spacing key (if given) to the corresponding themed spacing value.
|
|
11
|
-
const _getThemedSpacing = (space:
|
|
11
|
+
const _getThemedSpacing = (space: `${number}` | `${number}px` | keyof Spacing, theme: Theme): number => {
|
|
12
12
|
const spacing = theme[_spacingKey];
|
|
13
|
-
if (spacing && typeof spacing === 'object') {
|
|
13
|
+
if (spacing && typeof spacing === 'object' && typeof space === 'string') {
|
|
14
14
|
if (spacing.hasOwnProperty(space)) {
|
|
15
|
-
|
|
15
|
+
space = spacing[space];
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
-
return space;
|
|
19
|
-
};
|
|
20
18
|
|
|
21
|
-
|
|
22
|
-
const _getValueUnitGap = (gap: string): { value: number; unit: string } => {
|
|
23
|
-
const numericalPart = parseFloat(gap);
|
|
19
|
+
const numericalPart = parseFloat(space);
|
|
24
20
|
const numericalValue = isNaN(numericalPart) ? 0 : numericalPart;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const unitPart = gap.substring(numericalString.toString().length);
|
|
28
|
-
|
|
29
|
-
return {
|
|
30
|
-
value: numericalValue,
|
|
31
|
-
unit: unitPart || 'px',
|
|
32
|
-
};
|
|
21
|
+
return numericalValue;
|
|
33
22
|
};
|
|
34
23
|
|
|
35
24
|
export interface IParseGapResult {
|
|
36
|
-
rowGap:
|
|
37
|
-
columnGap:
|
|
25
|
+
rowGap: number;
|
|
26
|
+
columnGap: number;
|
|
38
27
|
}
|
|
39
28
|
|
|
29
|
+
type SpacingGapValue = `${number}px` | `${number}` | keyof Spacing;
|
|
30
|
+
|
|
40
31
|
/**
|
|
41
32
|
* Takes in a gap size in either a CSS-style format (e.g. 10 or "10px")
|
|
42
33
|
* or a key of a themed spacing value (e.g. "s1").
|
|
43
34
|
* Returns the separate numerical value of the padding (e.g. 10)
|
|
44
35
|
* and the CSS unit (e.g. "px").
|
|
45
36
|
*/
|
|
46
|
-
export function parseGap(
|
|
37
|
+
export function parseGap(
|
|
38
|
+
gap: number | SpacingGapValue | `${SpacingGapValue} ${SpacingGapValue}` | undefined,
|
|
39
|
+
theme: Theme,
|
|
40
|
+
): IParseGapResult {
|
|
47
41
|
const result: IParseGapResult = {
|
|
48
|
-
rowGap:
|
|
49
|
-
columnGap:
|
|
42
|
+
rowGap: 0,
|
|
43
|
+
columnGap: 0,
|
|
50
44
|
};
|
|
51
45
|
if (gap) {
|
|
52
46
|
if (typeof gap === 'number') {
|
|
53
|
-
result.rowGap
|
|
54
|
-
result.columnGap
|
|
47
|
+
result.rowGap = gap;
|
|
48
|
+
result.columnGap = gap;
|
|
55
49
|
} else {
|
|
56
50
|
const splitGap = gap.split(' ');
|
|
57
51
|
if (splitGap.length === 2) {
|
|
58
|
-
result.rowGap =
|
|
59
|
-
result.columnGap =
|
|
52
|
+
result.rowGap = _getThemedSpacing(splitGap[0] as SpacingGapValue, theme);
|
|
53
|
+
result.columnGap = _getThemedSpacing(splitGap[1] as SpacingGapValue, theme);
|
|
60
54
|
} else {
|
|
61
|
-
const calculatedGap =
|
|
55
|
+
const calculatedGap = _getThemedSpacing(gap as SpacingGapValue, theme);
|
|
62
56
|
result.rowGap = calculatedGap;
|
|
63
57
|
result.columnGap = calculatedGap;
|
|
64
58
|
}
|
|
@@ -68,22 +62,13 @@ export function parseGap(gap: number | string | undefined, theme: Theme): IParse
|
|
|
68
62
|
}
|
|
69
63
|
|
|
70
64
|
/**
|
|
71
|
-
* Takes in a padding in a CSS-style format (e.g. 10, "10px",
|
|
72
|
-
*
|
|
73
|
-
* (e.g. "s1 m", "10px l1 20px l2", etc.).
|
|
74
|
-
* Returns a CSS-style padding.
|
|
65
|
+
* Takes in a padding in a CSS-style format (e.g. 10, "10px"), or a key of a themed spacing value
|
|
66
|
+
* (e.g. "s1")
|
|
75
67
|
*/
|
|
76
|
-
export function parsePadding(padding: number |
|
|
77
|
-
if (padding === undefined || typeof padding === 'number'
|
|
78
|
-
return padding;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const paddingValues = padding.split(' ');
|
|
82
|
-
if (paddingValues.length < 2) {
|
|
83
|
-
return _getThemedSpacing(padding, theme);
|
|
68
|
+
export function parsePadding(padding: keyof Spacing | number | `${number}px` | undefined, theme: Theme): number | undefined {
|
|
69
|
+
if (padding === undefined || typeof padding === 'number') {
|
|
70
|
+
return padding as undefined | number;
|
|
84
71
|
}
|
|
85
72
|
|
|
86
|
-
return
|
|
87
|
-
return _getThemedSpacing(padding1, theme) + ' ' + _getThemedSpacing(padding2, theme);
|
|
88
|
-
});
|
|
73
|
+
return _getThemedSpacing(padding, theme);
|
|
89
74
|
}
|