Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: set default font properties for Text component without variant #3409

Merged
merged 1 commit into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/components/Typography/Text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from 'react-native';

import { useTheme } from '../../core/theming';
import { tokens } from '../../styles/themes/v3/tokens';
import { Font, MD3TypescaleKey, ThemeProp } from '../../types';

export type Props = React.ComponentProps<typeof NativeText> & {
Expand Down Expand Up @@ -128,7 +129,13 @@ const Text: React.ForwardRefRenderFunction<{}, Props> = (
/>
);
} else {
const font = !theme.isV3 ? theme.fonts?.regular : {};
const { brandRegular, weightRegular } = tokens.md.ref.typeface;
const font = theme.isV3
? {
fontFamily: brandRegular,
fontWeight: weightRegular,
}
: theme.fonts?.regular;
const textStyle = {
...font,
color: theme.isV3 ? theme.colors?.onSurface : theme.colors.text,
Expand Down
18 changes: 16 additions & 2 deletions src/components/__tests__/Typography/Text.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import * as React from 'react';

import { render } from '@testing-library/react-native';
import renderer from 'react-test-renderer';

import { tokens } from '../../../styles/themes/v3/tokens';
import Text from '../../Typography/Text.tsx';

it('renders every variant of Text with children as content', () => {
const content = 'Something rendered as a child content';
const content = 'Something rendered as a child content';

it('renders every variant of Text with children as content', () => {
const variants = (
<>
<Text variant="displayLarge">{content}</Text>
Expand Down Expand Up @@ -35,3 +37,15 @@ it('renders every variant of Text with children as content', () => {

expect(tree).toMatchSnapshot();
});

it('renders v3 Text component without variant with default fontWeight and fontFamily', () => {
const { getByTestId } = render(
<Text testID="text-without-variant">{content}</Text>
);
const { brandRegular, weightRegular } = tokens.md.ref.typeface;

expect(getByTestId('text-without-variant')).toHaveStyle({
fontFamily: brandRegular,
fontWeight: weightRegular,
});
});
8 changes: 8 additions & 0 deletions src/components/__tests__/__snapshots__/Avatar.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ exports[`renders avatar with text 1`] = `
},
Object {
"color": "rgba(28, 27, 31, 1)",
"fontFamily": "System",
"fontWeight": "400",
},
Object {
"writingDirection": "ltr",
Expand Down Expand Up @@ -190,6 +192,8 @@ exports[`renders avatar with text and custom background color 1`] = `
},
Object {
"color": "rgba(28, 27, 31, 1)",
"fontFamily": "System",
"fontWeight": "400",
},
Object {
"writingDirection": "ltr",
Expand Down Expand Up @@ -241,6 +245,8 @@ exports[`renders avatar with text and custom colors 1`] = `
},
Object {
"color": "rgba(28, 27, 31, 1)",
"fontFamily": "System",
"fontWeight": "400",
},
Object {
"writingDirection": "ltr",
Expand Down Expand Up @@ -292,6 +298,8 @@ exports[`renders avatar with text and custom size 1`] = `
},
Object {
"color": "rgba(28, 27, 31, 1)",
"fontFamily": "System",
"fontWeight": "400",
},
Object {
"writingDirection": "ltr",
Expand Down
12 changes: 12 additions & 0 deletions src/components/__tests__/__snapshots__/Banner.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ exports[`render visible banner, with custom theme 1`] = `
},
Object {
"color": "rgba(28, 27, 31, 1)",
"fontFamily": "System",
"fontWeight": "400",
},
Object {
"writingDirection": "ltr",
Expand Down Expand Up @@ -368,6 +370,8 @@ exports[`renders hidden banner, without action buttons and without image 1`] = `
},
Object {
"color": "rgba(28, 27, 31, 1)",
"fontFamily": "System",
"fontWeight": "400",
},
Object {
"writingDirection": "ltr",
Expand Down Expand Up @@ -494,6 +498,8 @@ exports[`renders visible banner, with action buttons and with image 1`] = `
},
Object {
"color": "rgba(28, 27, 31, 1)",
"fontFamily": "System",
"fontWeight": "400",
},
Object {
"writingDirection": "ltr",
Expand Down Expand Up @@ -760,6 +766,8 @@ exports[`renders visible banner, with action buttons and without image 1`] = `
},
Object {
"color": "rgba(28, 27, 31, 1)",
"fontFamily": "System",
"fontWeight": "400",
},
Object {
"writingDirection": "ltr",
Expand Down Expand Up @@ -1167,6 +1175,8 @@ exports[`renders visible banner, without action buttons and with image 1`] = `
},
Object {
"color": "rgba(28, 27, 31, 1)",
"fontFamily": "System",
"fontWeight": "400",
},
Object {
"writingDirection": "ltr",
Expand Down Expand Up @@ -1292,6 +1302,8 @@ exports[`renders visible banner, without action buttons and without image 1`] =
},
Object {
"color": "rgba(28, 27, 31, 1)",
"fontFamily": "System",
"fontWeight": "400",
},
Object {
"writingDirection": "ltr",
Expand Down
24 changes: 24 additions & 0 deletions src/components/__tests__/__snapshots__/DataTable.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ exports[`renders data table cell 1`] = `
},
Object {
"color": "rgba(28, 27, 31, 1)",
"fontFamily": "System",
"fontWeight": "400",
},
Object {
"writingDirection": "ltr",
Expand Down Expand Up @@ -107,6 +109,8 @@ exports[`renders data table header 1`] = `
},
Object {
"color": "rgba(28, 27, 31, 1)",
"fontFamily": "System",
"fontWeight": "400",
},
Object {
"writingDirection": "ltr",
Expand Down Expand Up @@ -170,6 +174,8 @@ exports[`renders data table header 1`] = `
},
Object {
"color": "rgba(28, 27, 31, 1)",
"fontFamily": "System",
"fontWeight": "400",
},
Object {
"writingDirection": "ltr",
Expand Down Expand Up @@ -225,6 +231,8 @@ exports[`renders data table pagination 1`] = `
},
Object {
"color": "rgba(28, 27, 31, 1)",
"fontFamily": "System",
"fontWeight": "400",
},
Object {
"writingDirection": "ltr",
Expand Down Expand Up @@ -500,6 +508,8 @@ exports[`renders data table pagination with fast-forward buttons 1`] = `
},
Object {
"color": "rgba(28, 27, 31, 1)",
"fontFamily": "System",
"fontWeight": "400",
},
Object {
"writingDirection": "ltr",
Expand Down Expand Up @@ -999,6 +1009,8 @@ exports[`renders data table pagination with label 1`] = `
},
Object {
"color": "rgba(28, 27, 31, 1)",
"fontFamily": "System",
"fontWeight": "400",
},
Object {
"writingDirection": "ltr",
Expand Down Expand Up @@ -1286,6 +1298,8 @@ exports[`renders data table pagination with options select 1`] = `
},
Object {
"color": "rgba(28, 27, 31, 1)",
"fontFamily": "System",
"fontWeight": "400",
},
Object {
"writingDirection": "ltr",
Expand Down Expand Up @@ -1496,6 +1510,8 @@ exports[`renders data table pagination with options select 1`] = `
},
Object {
"color": "rgba(28, 27, 31, 1)",
"fontFamily": "System",
"fontWeight": "400",
},
Object {
"writingDirection": "ltr",
Expand Down Expand Up @@ -2041,6 +2057,8 @@ exports[`renders data table title with press handler 1`] = `
},
Object {
"color": "rgba(28, 27, 31, 1)",
"fontFamily": "System",
"fontWeight": "400",
},
Object {
"writingDirection": "ltr",
Expand Down Expand Up @@ -2141,6 +2159,8 @@ exports[`renders data table title with sort icon 1`] = `
},
Object {
"color": "rgba(28, 27, 31, 1)",
"fontFamily": "System",
"fontWeight": "400",
},
Object {
"writingDirection": "ltr",
Expand Down Expand Up @@ -2211,6 +2231,8 @@ exports[`renders right aligned data table cell 1`] = `
},
Object {
"color": "rgba(28, 27, 31, 1)",
"fontFamily": "System",
"fontWeight": "400",
},
Object {
"writingDirection": "ltr",
Expand Down Expand Up @@ -2264,6 +2286,8 @@ exports[`renders right aligned data table title 1`] = `
},
Object {
"color": "rgba(28, 27, 31, 1)",
"fontFamily": "System",
"fontWeight": "400",
},
Object {
"writingDirection": "ltr",
Expand Down
16 changes: 16 additions & 0 deletions src/components/__tests__/__snapshots__/ListAccordion.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ exports[`renders expanded accordion 1`] = `
},
Object {
"color": "rgba(28, 27, 31, 1)",
"fontFamily": "System",
"fontWeight": "400",
},
Object {
"writingDirection": "ltr",
Expand Down Expand Up @@ -182,6 +184,8 @@ exports[`renders expanded accordion 1`] = `
},
Object {
"color": "rgba(28, 27, 31, 1)",
"fontFamily": "System",
"fontWeight": "400",
},
Object {
"writingDirection": "ltr",
Expand Down Expand Up @@ -313,6 +317,8 @@ exports[`renders list accordion with children 1`] = `
},
Object {
"color": "rgba(28, 27, 31, 1)",
"fontFamily": "System",
"fontWeight": "400",
},
Object {
"writingDirection": "ltr",
Expand Down Expand Up @@ -440,6 +446,8 @@ exports[`renders list accordion with custom title and description styles 1`] = `
},
Object {
"color": "rgba(28, 27, 31, 1)",
"fontFamily": "System",
"fontWeight": "400",
},
Object {
"writingDirection": "ltr",
Expand Down Expand Up @@ -470,6 +478,8 @@ exports[`renders list accordion with custom title and description styles 1`] = `
},
Object {
"color": "rgba(28, 27, 31, 1)",
"fontFamily": "System",
"fontWeight": "400",
},
Object {
"writingDirection": "ltr",
Expand Down Expand Up @@ -638,6 +648,8 @@ exports[`renders list accordion with left items 1`] = `
},
Object {
"color": "rgba(28, 27, 31, 1)",
"fontFamily": "System",
"fontWeight": "400",
},
Object {
"writingDirection": "ltr",
Expand Down Expand Up @@ -765,6 +777,8 @@ exports[`renders multiline list accordion 1`] = `
},
Object {
"color": "rgba(28, 27, 31, 1)",
"fontFamily": "System",
"fontWeight": "400",
},
Object {
"writingDirection": "ltr",
Expand Down Expand Up @@ -793,6 +807,8 @@ exports[`renders multiline list accordion 1`] = `
},
Object {
"color": "rgba(28, 27, 31, 1)",
"fontFamily": "System",
"fontWeight": "400",
},
Object {
"writingDirection": "ltr",
Expand Down
Loading