@fluentui-react-native/text 0.12.0 → 0.14.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 +46 -1
- package/CHANGELOG.md +26 -2
- package/MIGRATION.md +98 -0
- package/README.md +5 -0
- package/SPEC.md +235 -0
- package/assets/Text_example_block_win32.png +0 -0
- package/assets/Text_example_customized_win32.png +0 -0
- package/assets/Text_example_inline_win32.png +0 -0
- package/assets/Text_example_pressable_win32.png +0 -0
- package/assets/Text_example_underlined_win32.png +0 -0
- package/assets/Text_example_variants_win32.png +0 -0
- package/lib/Text.d.ts +2 -3
- package/lib/Text.d.ts.map +1 -1
- package/lib/Text.js +79 -15
- package/lib/Text.js.map +1 -1
- package/lib/Text.types.d.ts +79 -13
- package/lib/Text.types.d.ts.map +1 -1
- package/lib/Text.types.js +1 -1
- package/lib/Text.types.js.map +1 -1
- package/lib/TextTokens.d.ts +3 -0
- package/lib/TextTokens.d.ts.map +1 -0
- package/lib/TextTokens.js +7 -0
- package/lib/TextTokens.js.map +1 -0
- package/lib/Variants.d.ts +14 -0
- package/lib/Variants.d.ts.map +1 -0
- package/lib/Variants.js +16 -0
- package/lib/Variants.js.map +1 -0
- package/lib/Variants.win32.d.ts +14 -0
- package/lib/Variants.win32.d.ts.map +1 -0
- package/lib/Variants.win32.js +41 -0
- package/lib/Variants.win32.js.map +1 -0
- package/lib/__tests__/Text.test.js +42 -40
- package/lib/__tests__/Text.test.js.map +1 -1
- package/lib/deprecated/Text.d.ts +5 -0
- package/lib/deprecated/Text.d.ts.map +1 -0
- package/lib/deprecated/Text.js +18 -0
- package/lib/deprecated/Text.js.map +1 -0
- package/lib/{Text.settings.d.ts → deprecated/Text.settings.d.ts} +0 -0
- package/lib/deprecated/Text.settings.d.ts.map +1 -0
- package/lib/{Text.settings.js → deprecated/Text.settings.js} +0 -0
- package/lib/deprecated/Text.settings.js.map +1 -0
- package/lib/deprecated/Text.types.d.ts +17 -0
- package/lib/deprecated/Text.types.d.ts.map +1 -0
- package/lib/deprecated/Text.types.js +2 -0
- package/lib/deprecated/Text.types.js.map +1 -0
- package/lib/index.d.ts +6 -3
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +5 -2
- package/lib/index.js.map +1 -1
- package/lib-commonjs/Text.d.ts +2 -3
- package/lib-commonjs/Text.d.ts.map +1 -1
- package/lib-commonjs/Text.js +82 -15
- package/lib-commonjs/Text.js.map +1 -1
- package/lib-commonjs/Text.types.d.ts +79 -13
- package/lib-commonjs/Text.types.d.ts.map +1 -1
- package/lib-commonjs/Text.types.js +1 -1
- package/lib-commonjs/Text.types.js.map +1 -1
- package/lib-commonjs/TextTokens.d.ts +3 -0
- package/lib-commonjs/TextTokens.d.ts.map +1 -0
- package/lib-commonjs/TextTokens.js +10 -0
- package/lib-commonjs/TextTokens.js.map +1 -0
- package/lib-commonjs/Variants.d.ts +14 -0
- package/lib-commonjs/Variants.d.ts.map +1 -0
- package/lib-commonjs/Variants.js +19 -0
- package/lib-commonjs/Variants.js.map +1 -0
- package/lib-commonjs/Variants.win32.d.ts +14 -0
- package/lib-commonjs/Variants.win32.d.ts.map +1 -0
- package/lib-commonjs/Variants.win32.js +44 -0
- package/lib-commonjs/Variants.win32.js.map +1 -0
- package/lib-commonjs/__tests__/Text.test.js +41 -39
- package/lib-commonjs/__tests__/Text.test.js.map +1 -1
- package/lib-commonjs/deprecated/Text.d.ts +5 -0
- package/lib-commonjs/deprecated/Text.d.ts.map +1 -0
- package/lib-commonjs/deprecated/Text.js +21 -0
- package/lib-commonjs/deprecated/Text.js.map +1 -0
- package/lib-commonjs/{Text.settings.d.ts → deprecated/Text.settings.d.ts} +0 -0
- package/lib-commonjs/deprecated/Text.settings.d.ts.map +1 -0
- package/lib-commonjs/{Text.settings.js → deprecated/Text.settings.js} +0 -0
- package/lib-commonjs/deprecated/Text.settings.js.map +1 -0
- package/lib-commonjs/deprecated/Text.types.d.ts +17 -0
- package/lib-commonjs/deprecated/Text.types.d.ts.map +1 -0
- package/lib-commonjs/deprecated/Text.types.js +5 -0
- package/lib-commonjs/deprecated/Text.types.js.map +1 -0
- package/lib-commonjs/index.d.ts +6 -3
- package/lib-commonjs/index.d.ts.map +1 -1
- package/lib-commonjs/index.js +21 -4
- package/lib-commonjs/index.js.map +1 -1
- package/package.json +6 -3
- package/src/Text.tsx +106 -16
- package/src/Text.types.ts +91 -15
- package/src/TextTokens.ts +10 -0
- package/src/Variants.ts +16 -0
- package/src/Variants.win32.ts +41 -0
- package/src/__tests__/Text.test.tsx +55 -60
- package/src/__tests__/__snapshots__/Text.test.tsx.snap +39 -4
- package/src/{Text.settings.ts → deprecated/Text.settings.ts} +0 -0
- package/src/deprecated/Text.tsx +19 -0
- package/src/deprecated/Text.types.ts +21 -0
- package/src/index.ts +22 -3
- package/lib/Text.settings.d.ts.map +0 -1
- package/lib/Text.settings.js.map +0 -1
- package/lib-commonjs/Text.settings.d.ts.map +0 -1
- package/lib-commonjs/Text.settings.js.map +0 -1
package/src/Text.tsx
CHANGED
|
@@ -1,19 +1,109 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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 =
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
|
2
|
-
import { ITextProps
|
|
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 = '
|
|
5
|
+
export const textName = 'Text';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
|
-
*
|
|
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
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
+
);
|
package/src/Variants.ts
ADDED
|
@@ -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 {
|
|
4
|
+
import { checkRenderConsistency, checkReRender } from '@fluentui-react-native/test-tools';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
13
|
-
.
|
|
14
|
-
|
|
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
|
-
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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": "#
|
|
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
|
+
`;
|
|
File without changes
|
|
@@ -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;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { FontTokens, FontVariantTokens, IForegroundColorTokens, IColorTokens } from '@fluentui-react-native/tokens';
|
|
2
|
+
import { ITextProps as INativeTextProps } from '@fluentui-react-native/adapters';
|
|
3
|
+
|
|
4
|
+
export const textName = 'RNFText';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Properties for fabric native text field, these extend the default props for text
|
|
8
|
+
*/
|
|
9
|
+
export type ITextProps<TBase = INativeTextProps> = TBase &
|
|
10
|
+
FontVariantTokens &
|
|
11
|
+
IForegroundColorTokens & {
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type ITextType<TBase = INativeTextProps> = {
|
|
16
|
+
props: ITextProps<TBase>;
|
|
17
|
+
tokens: FontTokens & IColorTokens;
|
|
18
|
+
slotProps: {
|
|
19
|
+
root: TBase;
|
|
20
|
+
};
|
|
21
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export type {
|
|
3
|
-
export {
|
|
1
|
+
export { Text as TextV1 } from './Text';
|
|
2
|
+
export type { textName as textNameV1, TextProps, TextTokens } from './Text.types';
|
|
3
|
+
export {
|
|
4
|
+
Caption1,
|
|
5
|
+
Body1,
|
|
6
|
+
Body1Strong,
|
|
7
|
+
Body2,
|
|
8
|
+
Body2Strong,
|
|
9
|
+
Subtitle1,
|
|
10
|
+
Subtitle1Strong,
|
|
11
|
+
Subtitle2,
|
|
12
|
+
Subtitle2Strong,
|
|
13
|
+
Title1,
|
|
14
|
+
Title1Strong,
|
|
15
|
+
LargeTitle,
|
|
16
|
+
Display,
|
|
17
|
+
} from './Variants';
|
|
18
|
+
|
|
19
|
+
/* deprecated */
|
|
20
|
+
export { textName } from './deprecated/Text.types';
|
|
21
|
+
export type { ITextProps, ITextType } from './deprecated/Text.types';
|
|
22
|
+
export { Text } from './deprecated/Text';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Text.settings.d.ts","sourceRoot":"","sources":["../src/Text.settings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,SAAS,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAEtE,eAAO,MAAM,QAAQ,EAAE,gBAAgB,CAAC,SAAS,CAqBhD,CAAC"}
|
package/lib/Text.settings.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Text.settings.js","sourceRoot":"","sources":["../src/Text.settings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAa,MAAM,cAAc,CAAC;AAInD,MAAM,CAAC,IAAM,QAAQ,GAAgC;IACnD;QACE,MAAM,EAAE;YACN,OAAO,EAAE,mBAAmB;YAC5B,KAAK,EAAE,UAAU;SAClB;QACD,IAAI,EAAE;YACJ,KAAK,EAAE;gBACL,MAAM,EAAE,CAAC;aACG;SACf;QACD,UAAU,EAAE;YACV,QAAQ,EAAE;gBACR,MAAM,EAAE;oBACN,KAAK,EAAE,cAAc;iBACtB;aACF;SACF;QACD,WAAW,EAAE,CAAC,UAAU,CAAC;KAC1B;IACD,QAAQ;CACT,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Text.settings.d.ts","sourceRoot":"","sources":["../src/Text.settings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,SAAS,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAEtE,eAAO,MAAM,QAAQ,EAAE,gBAAgB,CAAC,SAAS,CAqBhD,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Text.settings.js","sourceRoot":"","sources":["../src/Text.settings.ts"],"names":[],"mappings":";;;AAAA,2CAAmD;AAItC,QAAA,QAAQ,GAAgC;IACnD;QACE,MAAM,EAAE;YACN,OAAO,EAAE,mBAAmB;YAC5B,KAAK,EAAE,UAAU;SAClB;QACD,IAAI,EAAE;YACJ,KAAK,EAAE;gBACL,MAAM,EAAE,CAAC;aACG;SACf;QACD,UAAU,EAAE;YACV,QAAQ,EAAE;gBACR,MAAM,EAAE;oBACN,KAAK,EAAE,cAAc;iBACtB;aACF;SACF;QACD,WAAW,EAAE,CAAC,UAAU,CAAC;KAC1B;IACD,qBAAQ;CACT,CAAC"}
|