@fluentui-react-native/text 0.12.1 → 0.13.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 (94) hide show
  1. package/CHANGELOG.json +16 -1
  2. package/CHANGELOG.md +10 -2
  3. package/lib/Text.d.ts +2 -3
  4. package/lib/Text.d.ts.map +1 -1
  5. package/lib/Text.js +79 -15
  6. package/lib/Text.js.map +1 -1
  7. package/lib/Text.types.d.ts +79 -13
  8. package/lib/Text.types.d.ts.map +1 -1
  9. package/lib/Text.types.js +1 -1
  10. package/lib/Text.types.js.map +1 -1
  11. package/lib/TextTokens.d.ts +3 -0
  12. package/lib/TextTokens.d.ts.map +1 -0
  13. package/lib/TextTokens.js +7 -0
  14. package/lib/TextTokens.js.map +1 -0
  15. package/lib/Variants.d.ts +14 -0
  16. package/lib/Variants.d.ts.map +1 -0
  17. package/lib/Variants.js +16 -0
  18. package/lib/Variants.js.map +1 -0
  19. package/lib/Variants.win32.d.ts +14 -0
  20. package/lib/Variants.win32.d.ts.map +1 -0
  21. package/lib/Variants.win32.js +41 -0
  22. package/lib/Variants.win32.js.map +1 -0
  23. package/lib/__tests__/Text.test.js +42 -40
  24. package/lib/__tests__/Text.test.js.map +1 -1
  25. package/lib/deprecated/Text.d.ts +5 -0
  26. package/lib/deprecated/Text.d.ts.map +1 -0
  27. package/lib/deprecated/Text.js +18 -0
  28. package/lib/deprecated/Text.js.map +1 -0
  29. package/lib/{Text.settings.d.ts → deprecated/Text.settings.d.ts} +0 -0
  30. package/lib/deprecated/Text.settings.d.ts.map +1 -0
  31. package/lib/{Text.settings.js → deprecated/Text.settings.js} +0 -0
  32. package/lib/deprecated/Text.settings.js.map +1 -0
  33. package/lib/deprecated/Text.types.d.ts +17 -0
  34. package/lib/deprecated/Text.types.d.ts.map +1 -0
  35. package/lib/deprecated/Text.types.js +2 -0
  36. package/lib/deprecated/Text.types.js.map +1 -0
  37. package/lib/index.d.ts +6 -3
  38. package/lib/index.d.ts.map +1 -1
  39. package/lib/index.js +5 -2
  40. package/lib/index.js.map +1 -1
  41. package/lib-commonjs/Text.d.ts +2 -3
  42. package/lib-commonjs/Text.d.ts.map +1 -1
  43. package/lib-commonjs/Text.js +82 -15
  44. package/lib-commonjs/Text.js.map +1 -1
  45. package/lib-commonjs/Text.types.d.ts +79 -13
  46. package/lib-commonjs/Text.types.d.ts.map +1 -1
  47. package/lib-commonjs/Text.types.js +1 -1
  48. package/lib-commonjs/Text.types.js.map +1 -1
  49. package/lib-commonjs/TextTokens.d.ts +3 -0
  50. package/lib-commonjs/TextTokens.d.ts.map +1 -0
  51. package/lib-commonjs/TextTokens.js +10 -0
  52. package/lib-commonjs/TextTokens.js.map +1 -0
  53. package/lib-commonjs/Variants.d.ts +14 -0
  54. package/lib-commonjs/Variants.d.ts.map +1 -0
  55. package/lib-commonjs/Variants.js +19 -0
  56. package/lib-commonjs/Variants.js.map +1 -0
  57. package/lib-commonjs/Variants.win32.d.ts +14 -0
  58. package/lib-commonjs/Variants.win32.d.ts.map +1 -0
  59. package/lib-commonjs/Variants.win32.js +44 -0
  60. package/lib-commonjs/Variants.win32.js.map +1 -0
  61. package/lib-commonjs/__tests__/Text.test.js +41 -39
  62. package/lib-commonjs/__tests__/Text.test.js.map +1 -1
  63. package/lib-commonjs/deprecated/Text.d.ts +5 -0
  64. package/lib-commonjs/deprecated/Text.d.ts.map +1 -0
  65. package/lib-commonjs/deprecated/Text.js +21 -0
  66. package/lib-commonjs/deprecated/Text.js.map +1 -0
  67. package/lib-commonjs/{Text.settings.d.ts → deprecated/Text.settings.d.ts} +0 -0
  68. package/lib-commonjs/deprecated/Text.settings.d.ts.map +1 -0
  69. package/lib-commonjs/{Text.settings.js → deprecated/Text.settings.js} +0 -0
  70. package/lib-commonjs/deprecated/Text.settings.js.map +1 -0
  71. package/lib-commonjs/deprecated/Text.types.d.ts +17 -0
  72. package/lib-commonjs/deprecated/Text.types.d.ts.map +1 -0
  73. package/lib-commonjs/deprecated/Text.types.js +5 -0
  74. package/lib-commonjs/deprecated/Text.types.js.map +1 -0
  75. package/lib-commonjs/index.d.ts +6 -3
  76. package/lib-commonjs/index.d.ts.map +1 -1
  77. package/lib-commonjs/index.js +21 -4
  78. package/lib-commonjs/index.js.map +1 -1
  79. package/package.json +5 -2
  80. package/src/Text.tsx +106 -16
  81. package/src/Text.types.ts +91 -15
  82. package/src/TextTokens.ts +10 -0
  83. package/src/Variants.ts +16 -0
  84. package/src/Variants.win32.ts +41 -0
  85. package/src/__tests__/Text.test.tsx +55 -60
  86. package/src/__tests__/__snapshots__/Text.test.tsx.snap +39 -4
  87. package/src/{Text.settings.ts → deprecated/Text.settings.ts} +0 -0
  88. package/src/deprecated/Text.tsx +19 -0
  89. package/src/deprecated/Text.types.ts +21 -0
  90. package/src/index.ts +22 -3
  91. package/lib/Text.settings.d.ts.map +0 -1
  92. package/lib/Text.settings.js.map +0 -1
  93. package/lib-commonjs/Text.settings.d.ts.map +0 -1
  94. package/lib-commonjs/Text.settings.js.map +0 -1
@@ -0,0 +1,17 @@
1
+ import { FontTokens, FontVariantTokens, IForegroundColorTokens, IColorTokens } from '@fluentui-react-native/tokens';
2
+ import { ITextProps as INativeTextProps } from '@fluentui-react-native/adapters';
3
+ export declare const textName = "RNFText";
4
+ /**
5
+ * Properties for fabric native text field, these extend the default props for text
6
+ */
7
+ export declare type ITextProps<TBase = INativeTextProps> = TBase & FontVariantTokens & IForegroundColorTokens & {
8
+ disabled?: boolean;
9
+ };
10
+ export declare type ITextType<TBase = INativeTextProps> = {
11
+ props: ITextProps<TBase>;
12
+ tokens: FontTokens & IColorTokens;
13
+ slotProps: {
14
+ root: TBase;
15
+ };
16
+ };
17
+ //# sourceMappingURL=Text.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Text.types.d.ts","sourceRoot":"","sources":["../../src/deprecated/Text.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AACpH,OAAO,EAAE,UAAU,IAAI,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAEjF,eAAO,MAAM,QAAQ,YAAY,CAAC;AAElC;;GAEG;AACH,oBAAY,UAAU,CAAC,KAAK,GAAG,gBAAgB,IAAI,KAAK,GACtD,iBAAiB,GACjB,sBAAsB,GAAG;IACvB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEJ,oBAAY,SAAS,CAAC,KAAK,GAAG,gBAAgB,IAAI;IAChD,KAAK,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC;IACzB,MAAM,EAAE,UAAU,GAAG,YAAY,CAAC;IAClC,SAAS,EAAE;QACT,IAAI,EAAE,KAAK,CAAC;KACb,CAAC;CACH,CAAC"}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.textName = void 0;
4
+ exports.textName = 'RNFText';
5
+ //# sourceMappingURL=Text.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Text.types.js","sourceRoot":"","sources":["../../src/deprecated/Text.types.ts"],"names":[],"mappings":";;;AAGa,QAAA,QAAQ,GAAG,SAAS,CAAC"}
@@ -1,4 +1,7 @@
1
- export { textName } from './Text.types';
2
- export type { ITextProps, ITextType } from './Text.types';
3
- export { Text } from './Text';
1
+ export { Text as TextV1 } from './Text';
2
+ export type { textName as textNameV1, TextProps, TextTokens } from './Text.types';
3
+ export { Caption1, Body1, Body1Strong, Body2, Body2Strong, Subtitle1, Subtitle1Strong, Subtitle2, Subtitle2Strong, Title1, Title1Strong, LargeTitle, Display, } from './Variants';
4
+ export { textName } from './deprecated/Text.types';
5
+ export type { ITextProps, ITextType } from './deprecated/Text.types';
6
+ export { Text } from './deprecated/Text';
4
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,IAAI,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,YAAY,EAAE,QAAQ,IAAI,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAClF,OAAO,EACL,QAAQ,EACR,KAAK,EACL,WAAW,EACX,KAAK,EACL,WAAW,EACX,SAAS,EACT,eAAe,EACf,SAAS,EACT,eAAe,EACf,MAAM,EACN,YAAY,EACZ,UAAU,EACV,OAAO,GACR,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACrE,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC"}
@@ -1,8 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Text = exports.textName = void 0;
4
- var Text_types_1 = require("./Text.types");
5
- Object.defineProperty(exports, "textName", { enumerable: true, get: function () { return Text_types_1.textName; } });
3
+ exports.Text = exports.textName = exports.Display = exports.LargeTitle = exports.Title1Strong = exports.Title1 = exports.Subtitle2Strong = exports.Subtitle2 = exports.Subtitle1Strong = exports.Subtitle1 = exports.Body2Strong = exports.Body2 = exports.Body1Strong = exports.Body1 = exports.Caption1 = exports.TextV1 = void 0;
6
4
  var Text_1 = require("./Text");
7
- Object.defineProperty(exports, "Text", { enumerable: true, get: function () { return Text_1.Text; } });
5
+ Object.defineProperty(exports, "TextV1", { enumerable: true, get: function () { return Text_1.Text; } });
6
+ var Variants_1 = require("./Variants");
7
+ Object.defineProperty(exports, "Caption1", { enumerable: true, get: function () { return Variants_1.Caption1; } });
8
+ Object.defineProperty(exports, "Body1", { enumerable: true, get: function () { return Variants_1.Body1; } });
9
+ Object.defineProperty(exports, "Body1Strong", { enumerable: true, get: function () { return Variants_1.Body1Strong; } });
10
+ Object.defineProperty(exports, "Body2", { enumerable: true, get: function () { return Variants_1.Body2; } });
11
+ Object.defineProperty(exports, "Body2Strong", { enumerable: true, get: function () { return Variants_1.Body2Strong; } });
12
+ Object.defineProperty(exports, "Subtitle1", { enumerable: true, get: function () { return Variants_1.Subtitle1; } });
13
+ Object.defineProperty(exports, "Subtitle1Strong", { enumerable: true, get: function () { return Variants_1.Subtitle1Strong; } });
14
+ Object.defineProperty(exports, "Subtitle2", { enumerable: true, get: function () { return Variants_1.Subtitle2; } });
15
+ Object.defineProperty(exports, "Subtitle2Strong", { enumerable: true, get: function () { return Variants_1.Subtitle2Strong; } });
16
+ Object.defineProperty(exports, "Title1", { enumerable: true, get: function () { return Variants_1.Title1; } });
17
+ Object.defineProperty(exports, "Title1Strong", { enumerable: true, get: function () { return Variants_1.Title1Strong; } });
18
+ Object.defineProperty(exports, "LargeTitle", { enumerable: true, get: function () { return Variants_1.LargeTitle; } });
19
+ Object.defineProperty(exports, "Display", { enumerable: true, get: function () { return Variants_1.Display; } });
20
+ /* deprecated */
21
+ var Text_types_1 = require("./deprecated/Text.types");
22
+ Object.defineProperty(exports, "textName", { enumerable: true, get: function () { return Text_types_1.textName; } });
23
+ var Text_2 = require("./deprecated/Text");
24
+ Object.defineProperty(exports, "Text", { enumerable: true, get: function () { return Text_2.Text; } });
8
25
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,2CAAwC;AAA/B,sGAAA,QAAQ,OAAA;AAEjB,+BAA8B;AAArB,4FAAA,IAAI,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,+BAAwC;AAA/B,8FAAA,IAAI,OAAU;AAEvB,uCAcoB;AAblB,oGAAA,QAAQ,OAAA;AACR,iGAAA,KAAK,OAAA;AACL,uGAAA,WAAW,OAAA;AACX,iGAAA,KAAK,OAAA;AACL,uGAAA,WAAW,OAAA;AACX,qGAAA,SAAS,OAAA;AACT,2GAAA,eAAe,OAAA;AACf,qGAAA,SAAS,OAAA;AACT,2GAAA,eAAe,OAAA;AACf,kGAAA,MAAM,OAAA;AACN,wGAAA,YAAY,OAAA;AACZ,sGAAA,UAAU,OAAA;AACV,mGAAA,OAAO,OAAA;AAGT,gBAAgB;AAChB,sDAAmD;AAA1C,sGAAA,QAAQ,OAAA;AAEjB,0CAAyC;AAAhC,4FAAA,IAAI,OAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluentui-react-native/text",
3
- "version": "0.12.1",
3
+ "version": "0.13.0",
4
4
  "description": "A cross-platform Text component using the Fluent Design System",
5
5
  "main": "lib-commonjs/index.js",
6
6
  "module": "lib/index.js",
@@ -24,7 +24,10 @@
24
24
  "dependencies": {
25
25
  "@uifabricshared/foundation-compose": "^1.12.1",
26
26
  "@fluentui-react-native/adapters": ">=0.9.0 <1.0.0",
27
- "@fluentui-react-native/tokens": ">=0.16.0 <1.0.0"
27
+ "@fluentui-react-native/framework": "0.8.0",
28
+ "@fluentui-react-native/theme-tokens": ">=0.19.0 <1.0.0",
29
+ "@fluentui-react-native/tokens": ">=0.16.0 <1.0.0",
30
+ "tslib": "^2.3.1"
28
31
  },
29
32
  "devDependencies": {
30
33
  "@fluentui-react-native/eslint-config-rules": "^0.1.1",
package/src/Text.tsx CHANGED
@@ -1,19 +1,109 @@
1
- import { textName, ITextType } from './Text.types';
2
- import { compose } from '@uifabricshared/foundation-compose';
3
- import { Text as RNText } from 'react-native';
4
- import { filterTextProps } from '@fluentui-react-native/adapters';
5
- import { foregroundColorTokens, textTokens } from '@fluentui-react-native/tokens';
6
- import { settings } from './Text.settings';
1
+ /** @jsx withSlots */
2
+ import {
3
+ fontStyles,
4
+ withSlots,
5
+ UseTokens,
6
+ useFluentTheme,
7
+ mergeStyles,
8
+ compressible,
9
+ patchTokens,
10
+ FontWeightValue,
11
+ } from '@fluentui-react-native/framework';
12
+ import { globalTokens } from '@fluentui-react-native/theme-tokens';
13
+ import { I18nManager, Platform, Text as RNText } from 'react-native';
14
+ import { textName, TextProps, TextTokens } from './Text.types';
15
+ import { useTextTokens } from './TextTokens';
16
+ import React from 'react';
7
17
 
8
- export const Text = compose<ITextType>({
9
- displayName: textName,
10
- settings,
11
- slots: {
12
- root: { slotType: RNText, filter: filterTextProps },
13
- },
14
- styles: {
15
- root: [textTokens, foregroundColorTokens],
16
- },
17
- });
18
+ export const Text = compressible<TextProps, TextTokens>((props: TextProps, useTokens: UseTokens<TextTokens>) => {
19
+ // split out color and variant from props
20
+ const {
21
+ align,
22
+ block,
23
+ color,
24
+ font,
25
+ italic,
26
+ onAccessibilityTap,
27
+ onKeyDown,
28
+ onPress,
29
+ size,
30
+ strikethrough,
31
+ style,
32
+ truncate = false,
33
+ underline,
34
+ variant,
35
+ weight,
36
+ wrap = true,
37
+ ...rest
38
+ } = props;
39
+ const theme = useFluentTheme();
40
+ // get the tokens from the theme
41
+ let [tokens, cache] = useTokens(theme);
42
+
43
+ const textAlign = I18nManager.isRTL
44
+ ? align === 'start'
45
+ ? 'right'
46
+ : align === 'end'
47
+ ? 'left'
48
+ : align
49
+ : align === 'start'
50
+ ? 'left'
51
+ : align === 'end'
52
+ ? 'right'
53
+ : align;
54
+
55
+ const onAccTap = React.useCallback(
56
+ (event?) => {
57
+ onAccessibilityTap ? onAccessibilityTap() : onPress(event);
58
+ },
59
+ [onPress, onAccessibilityTap],
60
+ );
61
+
62
+ // override tokens from props
63
+ [tokens, cache] = patchTokens(tokens, cache, {
64
+ color,
65
+ variant,
66
+ fontFamily: font == 'base' ? 'primary' : font,
67
+ fontSize: globalTokens.font.size[size],
68
+ fontWeight: globalTokens.font.weight[weight] as FontWeightValue,
69
+ // leave it undefined for tokens to be set by user
70
+ fontStyle: italic ? 'italic' : undefined,
71
+ textAlign: textAlign,
72
+ textDecorationLine:
73
+ underline && strikethrough ? 'underline line-through' : underline ? 'underline' : strikethrough ? 'line-through' : undefined,
74
+ });
75
+
76
+ // now build the text style from tokens that can be shared between different Text instances
77
+ const [tokenStyle] = cache(
78
+ () => ({
79
+ margin: 0,
80
+ color: tokens.color,
81
+ fontStyle: tokens.fontStyle,
82
+ textAlign: tokens.textAlign,
83
+ textDecorationLine: tokens.textDecorationLine,
84
+ ...fontStyles.from(tokens, theme),
85
+ }),
86
+ ['color', 'fontStyle', 'textAlign', 'textDecorationLine', ...fontStyles.keys],
87
+ );
88
+
89
+ // return a continuation function that allows this text to be compressed
90
+ return (extra: TextProps, children: React.ReactNode) => {
91
+ const mergedProps = {
92
+ numberOfLines: truncate || !wrap ? 1 : 0,
93
+ onKeyDown: Platform.OS === (('win32' as any) || 'windows') ? onKeyDown : undefined,
94
+ ...(Platform.OS === (('win32' as any) || 'windows') && { onAccessibilityTap: onAccTap }),
95
+ onPress,
96
+ ...rest,
97
+ ...extra,
98
+ style: mergeStyles(tokenStyle, props.style, extra?.style),
99
+ };
100
+ return (
101
+ <RNText ellipsizeMode={!wrap && !truncate ? 'clip' : 'tail'} {...mergedProps}>
102
+ {children}
103
+ </RNText>
104
+ );
105
+ };
106
+ }, useTextTokens);
107
+ Text.displayName = textName;
18
108
 
19
109
  export default Text;
package/src/Text.types.ts CHANGED
@@ -1,21 +1,97 @@
1
- import { FontTokens, FontVariantTokens, IForegroundColorTokens, IColorTokens } from '@fluentui-react-native/tokens';
2
- import { ITextProps as INativeTextProps } from '@fluentui-react-native/adapters';
1
+ import { FontTokens, FontVariantTokens, IForegroundColorTokens } from '@fluentui-react-native/framework';
2
+ import { ITextProps } from '@fluentui-react-native/adapters';
3
+ import { ColorValue, TextStyle } from 'react-native';
3
4
 
4
- export const textName = 'RNFText';
5
+ export const textName = 'Text';
5
6
 
6
7
  /**
7
- * Properties for fabric native text field, these extend the default props for text
8
+ * Text tokens, these are the internally configurable values for Text elements. In particular these
9
+ * drive decisions on how to build the styles
8
10
  */
9
- export type ITextProps<TBase = INativeTextProps> = TBase &
10
- FontVariantTokens &
11
- IForegroundColorTokens & {
12
- disabled?: boolean;
13
- };
11
+ export type TextTokens = Omit<FontTokens, 'fontFamily'> & IForegroundColorTokens & Omit<TextStyle, 'fontSize' | 'fontWeight' | 'color'>;
12
+
13
+ export type TextAlign = 'start' | 'center' | 'end' | 'justify';
14
+ export type TextFont = 'base' | 'monospace' | 'numeric';
15
+ export type TextSize = 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | 1000;
16
+ export type TextWeight = 'regular' | 'medium' | 'semibold' | 'bold';
17
+
18
+ /**
19
+ * Text props, based off of the standard react-native TextProps with some new extensions
20
+ */
21
+ export type TextProps<TBase = ITextProps> = TBase &
22
+ FontVariantTokens & {
23
+ /**
24
+ * foreground text color
25
+ */
26
+ color?: ColorValue;
27
+
28
+ /**
29
+ * Aligns text based on the parent container.
30
+ *
31
+ * @defaultValue start
32
+ */
33
+ align?: TextAlign;
34
+
35
+ /**
36
+ * Applies a block display for the content.
37
+ *
38
+ * @defaultValue false
39
+ */
40
+ block?: boolean;
41
+
42
+ /**
43
+ * Applies the font family to the content.
44
+ *
45
+ * @defaultValue base
46
+ */
47
+ font?: TextFont;
48
+
49
+ /**
50
+ * Applies the italic font style to the content.
51
+ *
52
+ * @defaultValue false
53
+ */
54
+ italic?: boolean;
55
+
56
+ /**
57
+ * Applies the strikethrough text decoration to the content.
58
+ *
59
+ * @defaultValue false
60
+ */
61
+ strikethrough?: boolean;
62
+
63
+ /**
64
+ * Applies font size and line height based on the theme tokens.
65
+ *
66
+ * @defaultValue 300
67
+ */
68
+ size?: TextSize;
69
+
70
+ /**
71
+ * Truncate overflowing text for block displays.
72
+ *
73
+ * @defaultValue false
74
+ */
75
+ truncate?: boolean;
76
+
77
+ /**
78
+ * Applies the underline text decoration to the content.
79
+ *
80
+ * @defaultValue false
81
+ */
82
+ underline?: boolean;
83
+
84
+ /**
85
+ * Applies font weight to the content.
86
+ *
87
+ * @defaultValue regular
88
+ */
89
+ weight?: TextWeight;
14
90
 
15
- export type ITextType<TBase = INativeTextProps> = {
16
- props: ITextProps<TBase>;
17
- tokens: FontTokens & IColorTokens;
18
- slotProps: {
19
- root: TBase;
91
+ /**
92
+ * Wraps the text content on white spaces.
93
+ *
94
+ * @defaultValue true
95
+ */
96
+ wrap?: boolean;
20
97
  };
21
- };
@@ -0,0 +1,10 @@
1
+ import { buildUseTokens } from '@fluentui-react-native/framework';
2
+ import { textName, TextTokens } from './Text.types';
3
+
4
+ export const useTextTokens = buildUseTokens<TextTokens>(
5
+ (t) => ({
6
+ variant: 'secondaryStandard',
7
+ color: t.colors.bodyText,
8
+ }),
9
+ textName,
10
+ );
@@ -0,0 +1,16 @@
1
+ import { Text } from './Text';
2
+
3
+ // stubbed out for other platforms for which variant alias tokens aren't defined
4
+ export const Caption1 = Text;
5
+ export const Body1 = Text;
6
+ export const Body1Strong = Text;
7
+ export const Body2 = Text;
8
+ export const Body2Strong = Text;
9
+ export const Subtitle1 = Text;
10
+ export const Subtitle1Strong = Text;
11
+ export const Subtitle2 = Text;
12
+ export const Subtitle2Strong = Text;
13
+ export const Title1 = Text;
14
+ export const Title1Strong = Text;
15
+ export const LargeTitle = Text;
16
+ export const Display = Text;
@@ -0,0 +1,41 @@
1
+ import { Text } from './Text';
2
+
3
+ export const Caption1 = Text.customize({
4
+ variant: 'caption1',
5
+ });
6
+ export const Body1 = Text.customize({
7
+ variant: 'body1',
8
+ });
9
+ export const Body1Strong = Text.customize({
10
+ variant: 'body1Strong',
11
+ });
12
+ export const Body2 = Text.customize({
13
+ variant: 'body2',
14
+ });
15
+ export const Body2Strong = Text.customize({
16
+ variant: 'body2Strong',
17
+ });
18
+ export const Subtitle1 = Text.customize({
19
+ variant: 'subtitle1',
20
+ });
21
+ export const Subtitle1Strong = Text.customize({
22
+ variant: 'subtitle1Strong',
23
+ });
24
+ export const Subtitle2 = Text.customize({
25
+ variant: 'subtitle2',
26
+ });
27
+ export const Subtitle2Strong = Text.customize({
28
+ variant: 'subtitle2Strong',
29
+ });
30
+ export const Title1 = Text.customize({
31
+ variant: 'title1',
32
+ });
33
+ export const Title1Strong = Text.customize({
34
+ variant: 'title1Strong',
35
+ });
36
+ export const LargeTitle = Text.customize({
37
+ variant: 'largeTitle',
38
+ });
39
+ export const Display = Text.customize({
40
+ variant: 'display',
41
+ });
@@ -1,74 +1,69 @@
1
1
  import * as React from 'react';
2
- import { Text } from '..';
2
+ import { Text } from '../Text';
3
3
  import * as renderer from 'react-test-renderer';
4
- import { checkReRender, checkRenderConsistency } from '@fluentui-react-native/test-tools';
4
+ import { checkRenderConsistency, checkReRender } from '@fluentui-react-native/test-tools';
5
5
 
6
- it('Text default', () => {
7
- const tree = renderer.create(<Text>Text default</Text>).toJSON();
8
- expect(tree).toMatchSnapshot();
9
- });
6
+ describe('Text component tests', () => {
7
+ it('Text default', () => {
8
+ const tree = renderer.create(<Text>Text default</Text>).toJSON();
9
+ expect(tree).toMatchSnapshot();
10
+ });
10
11
 
11
- it('Text all props', () => {
12
- const tree = renderer
13
- .create(
14
- <Text disabled variant="bodyStandard">
15
- All props
16
- </Text>,
17
- )
18
- .toJSON();
19
- expect(tree).toMatchSnapshot();
20
- });
12
+ it('Text all props', () => {
13
+ const tree = renderer.create(<Text variant="bodyStandard">All props</Text>).toJSON();
14
+ expect(tree).toMatchSnapshot();
15
+ });
21
16
 
22
- it('Text all tokens', () => {
23
- const BoldText = Text.customize({
24
- tokens: {
17
+ it('Text all tokens', () => {
18
+ const BoldText = Text.customize({
25
19
  fontFamily: 'Wingdings',
26
20
  fontWeight: '900',
27
21
  fontSize: 20,
28
- },
22
+ });
23
+ const tree = renderer.create(<BoldText>All tokens</BoldText>).toJSON();
24
+ expect(tree).toMatchSnapshot();
29
25
  });
30
- const tree = renderer.create(<BoldText>All tokens</BoldText>).toJSON();
31
- expect(tree).toMatchSnapshot();
32
- });
33
26
 
34
- it('Text simple rendering does not invalidate styling', () => {
35
- checkRenderConsistency(() => <Text>Default</Text>);
36
- checkRenderConsistency(() => <Text disabled>Default</Text>);
37
- checkRenderConsistency(() => <Text variant="headerStandard">Default</Text>);
38
- });
27
+ it('Text simple rendering does not invalidate styling', () => {
28
+ checkRenderConsistency(() => <Text>Default</Text>);
29
+ checkRenderConsistency(() => <Text variant="headerStandard">Default</Text>);
30
+ });
39
31
 
40
- it('Text re-renders correctly', () => {
41
- checkReRender(() => <Text>Default</Text>);
42
- checkReRender(() => <Text disabled>Default</Text>);
43
- checkReRender(() => <Text variant="headerStandard">Default</Text>);
44
- });
32
+ it('Text re-renders correctly', () => {
33
+ checkReRender(() => <Text>Default</Text>);
34
+ checkReRender(() => <Text variant="headerStandard">Default</Text>);
35
+ });
45
36
 
46
- it('Text shares produced styles across multiple renders', () => {
47
- const style = { color: 'black' };
48
- checkRenderConsistency(() => <Text style={style}>Default</Text>);
49
- checkRenderConsistency(() => (
50
- <Text style={style} disabled>
51
- Default
52
- </Text>
53
- ));
54
- checkRenderConsistency(() => (
55
- <Text style={style} variant="headerStandard">
56
- Default
57
- </Text>
58
- ));
59
- });
37
+ it('Text shares produced styles across multiple renders', () => {
38
+ const style = { color: 'black' };
39
+ checkRenderConsistency(() => <Text style={style}>Default</Text>);
40
+ checkRenderConsistency(() => (
41
+ <Text style={style} variant="headerStandard">
42
+ Default
43
+ </Text>
44
+ ));
45
+ });
60
46
 
61
- it('Text re-renders correctly with style', () => {
62
- const style = { color: 'blue' };
63
- checkReRender(() => <Text style={style}>Default</Text>);
64
- checkReRender(() => (
65
- <Text style={style} disabled>
66
- Default
67
- </Text>
68
- ));
69
- checkReRender(() => (
70
- <Text style={style} variant="headerStandard">
71
- Default
72
- </Text>
73
- ));
47
+ it('Text re-renders correctly with style', () => {
48
+ const style = { color: 'blue' };
49
+ checkReRender(() => <Text style={style}>Default</Text>);
50
+ checkReRender(() => (
51
+ <Text style={style} variant="headerStandard">
52
+ Default
53
+ </Text>
54
+ ));
55
+ });
56
+
57
+ it('Text variants render correctly with style', () => {
58
+ const style = {
59
+ marginBottom: 8,
60
+ marginTop: 4,
61
+ };
62
+ const tree = renderer.create(
63
+ <Text variant="heroLargeSemibold" color="blue" style={style}>
64
+ Header Text
65
+ </Text>,
66
+ );
67
+ expect(tree).toMatchSnapshot();
68
+ });
74
69
  });
@@ -1,14 +1,19 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
- exports[`Text all props 1`] = `
3
+ exports[`Text component tests Text all props 1`] = `
4
4
  <Text
5
+ ellipsizeMode="tail"
6
+ numberOfLines={0}
5
7
  style={
6
8
  Object {
7
- "color": "#a19f9d",
9
+ "color": "#323130",
8
10
  "fontFamily": "Segoe UI",
9
11
  "fontSize": 14,
12
+ "fontStyle": undefined,
10
13
  "fontWeight": "400",
11
14
  "margin": 0,
15
+ "textAlign": undefined,
16
+ "textDecorationLine": undefined,
12
17
  }
13
18
  }
14
19
  >
@@ -16,15 +21,20 @@ exports[`Text all props 1`] = `
16
21
  </Text>
17
22
  `;
18
23
 
19
- exports[`Text all tokens 1`] = `
24
+ exports[`Text component tests Text all tokens 1`] = `
20
25
  <Text
26
+ ellipsizeMode="tail"
27
+ numberOfLines={0}
21
28
  style={
22
29
  Object {
23
30
  "color": "#323130",
24
31
  "fontFamily": "Wingdings",
25
32
  "fontSize": 20,
33
+ "fontStyle": undefined,
26
34
  "fontWeight": "900",
27
35
  "margin": 0,
36
+ "textAlign": undefined,
37
+ "textDecorationLine": undefined,
28
38
  }
29
39
  }
30
40
  >
@@ -32,18 +42,43 @@ exports[`Text all tokens 1`] = `
32
42
  </Text>
33
43
  `;
34
44
 
35
- exports[`Text default 1`] = `
45
+ exports[`Text component tests Text default 1`] = `
36
46
  <Text
47
+ ellipsizeMode="tail"
48
+ numberOfLines={0}
37
49
  style={
38
50
  Object {
39
51
  "color": "#323130",
40
52
  "fontFamily": "Segoe UI",
41
53
  "fontSize": 12,
54
+ "fontStyle": undefined,
42
55
  "fontWeight": "400",
43
56
  "margin": 0,
57
+ "textAlign": undefined,
58
+ "textDecorationLine": undefined,
44
59
  }
45
60
  }
46
61
  >
47
62
  Text default
48
63
  </Text>
49
64
  `;
65
+
66
+ exports[`Text component tests Text variants render correctly with style 1`] = `
67
+ <Text
68
+ ellipsizeMode="tail"
69
+ numberOfLines={0}
70
+ style={
71
+ Object {
72
+ "color": "blue",
73
+ "fontFamily": "Segoe UI",
74
+ "fontSize": 40,
75
+ "fontWeight": "600",
76
+ "margin": 0,
77
+ "marginBottom": 8,
78
+ "marginTop": 4,
79
+ }
80
+ }
81
+ >
82
+ Header Text
83
+ </Text>
84
+ `;
@@ -0,0 +1,19 @@
1
+ import { textName, ITextType } from './Text.types';
2
+ import { compose } from '@uifabricshared/foundation-compose';
3
+ import { Text as RNText } from 'react-native';
4
+ import { filterTextProps } from '@fluentui-react-native/adapters';
5
+ import { foregroundColorTokens, textTokens } from '@fluentui-react-native/tokens';
6
+ import { settings } from './Text.settings';
7
+
8
+ export const Text = compose<ITextType>({
9
+ displayName: textName,
10
+ settings,
11
+ slots: {
12
+ root: { slotType: RNText, filter: filterTextProps },
13
+ },
14
+ styles: {
15
+ root: [textTokens, foregroundColorTokens],
16
+ },
17
+ });
18
+
19
+ export default Text;