@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.
Files changed (36) hide show
  1. package/CHANGELOG.json +77 -8
  2. package/CHANGELOG.md +25 -8
  3. package/lib/Stack.tokens.d.ts.map +1 -1
  4. package/lib/Stack.tokens.js +6 -11
  5. package/lib/Stack.tokens.js.map +1 -1
  6. package/lib/Stack.types.d.ts +8 -5
  7. package/lib/Stack.types.d.ts.map +1 -1
  8. package/lib/Stack.types.js.map +1 -1
  9. package/lib/StackItem/StackItem.types.d.ts +3 -3
  10. package/lib/StackItem/StackItem.types.d.ts.map +1 -1
  11. package/lib/StackUtils.d.ts +9 -15
  12. package/lib/StackUtils.d.ts.map +1 -1
  13. package/lib/StackUtils.js +15 -32
  14. package/lib/StackUtils.js.map +1 -1
  15. package/lib/StackUtils.test.win32.js +0 -34
  16. package/lib/StackUtils.test.win32.js.map +1 -1
  17. package/lib-commonjs/Stack.tokens.d.ts.map +1 -1
  18. package/lib-commonjs/Stack.tokens.js +6 -11
  19. package/lib-commonjs/Stack.tokens.js.map +1 -1
  20. package/lib-commonjs/Stack.types.d.ts +8 -5
  21. package/lib-commonjs/Stack.types.d.ts.map +1 -1
  22. package/lib-commonjs/Stack.types.js.map +1 -1
  23. package/lib-commonjs/StackItem/StackItem.types.d.ts +3 -3
  24. package/lib-commonjs/StackItem/StackItem.types.d.ts.map +1 -1
  25. package/lib-commonjs/StackUtils.d.ts +9 -15
  26. package/lib-commonjs/StackUtils.d.ts.map +1 -1
  27. package/lib-commonjs/StackUtils.js +15 -32
  28. package/lib-commonjs/StackUtils.js.map +1 -1
  29. package/lib-commonjs/StackUtils.test.win32.js +0 -34
  30. package/lib-commonjs/StackUtils.test.win32.js.map +1 -1
  31. package/package.json +13 -12
  32. package/src/Stack.tokens.ts +6 -11
  33. package/src/Stack.types.ts +8 -5
  34. package/src/StackItem/StackItem.types.ts +3 -3
  35. package/src/StackUtils.test.win32.ts +0 -40
  36. 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: string, theme: Theme): string => {
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
- return spacing[space];
15
+ space = spacing[space];
16
16
  }
17
17
  }
18
- return space;
19
- };
20
18
 
21
- // Helper function that takes a gap as a string and converts it into a { value, unit } representation.
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
- const numericalString = isNaN(numericalPart) ? '' : numericalPart.toString();
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: { value: number; unit: string };
37
- columnGap: { value: number; unit: string };
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(gap: number | string | undefined, theme: Theme): IParseGapResult {
37
+ export function parseGap(
38
+ gap: number | SpacingGapValue | `${SpacingGapValue} ${SpacingGapValue}` | undefined,
39
+ theme: Theme,
40
+ ): IParseGapResult {
47
41
  const result: IParseGapResult = {
48
- rowGap: { value: 0, unit: 'px' },
49
- columnGap: { value: 0, unit: 'px' },
42
+ rowGap: 0,
43
+ columnGap: 0,
50
44
  };
51
45
  if (gap) {
52
46
  if (typeof gap === 'number') {
53
- result.rowGap.value = gap;
54
- result.columnGap.value = gap;
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 = _getValueUnitGap(_getThemedSpacing(splitGap[0], theme));
59
- result.columnGap = _getValueUnitGap(_getThemedSpacing(splitGap[1], theme));
52
+ result.rowGap = _getThemedSpacing(splitGap[0] as SpacingGapValue, theme);
53
+ result.columnGap = _getThemedSpacing(splitGap[1] as SpacingGapValue, theme);
60
54
  } else {
61
- const calculatedGap = _getValueUnitGap(_getThemedSpacing(gap, theme));
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", "10px 10px", etc.)
72
- * where the separate padding values can also be the key of a themed spacing value
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 | string | undefined, theme: Theme): number | string | undefined {
77
- if (padding === undefined || typeof padding === 'number' || padding === '') {
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 paddingValues.reduce((padding1: string, padding2: string) => {
87
- return _getThemedSpacing(padding1, theme) + ' ' + _getThemedSpacing(padding2, theme);
88
- });
73
+ return _getThemedSpacing(padding, theme);
89
74
  }