Skip to content

Commit

Permalink
fix: set default font properties for Text component without variant (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
lukewalczak authored and hurali97 committed Oct 17, 2022
1 parent 74659c6 commit 278366d
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 3 deletions.
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 @@ -372,6 +374,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 @@ -498,6 +502,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 @@ -768,6 +774,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 @@ -1183,6 +1191,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 @@ -1308,6 +1318,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 @@ -44,6 +44,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 @@ -111,6 +113,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 @@ -174,6 +178,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 @@ -229,6 +235,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 @@ -518,6 +526,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 @@ -1045,6 +1055,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 @@ -1346,6 +1358,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 @@ -1560,6 +1574,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 @@ -2133,6 +2149,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 @@ -2233,6 +2251,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 @@ -2307,6 +2327,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 @@ -2360,6 +2382,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 @@ -76,6 +76,8 @@ exports[`renders expanded accordion 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 expanded accordion 1`] = `
},
Object {
"color": "rgba(28, 27, 31, 1)",
"fontFamily": "System",
"fontWeight": "400",
},
Object {
"writingDirection": "ltr",
Expand Down Expand Up @@ -325,6 +329,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 @@ -456,6 +462,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 @@ -486,6 +494,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 @@ -658,6 +668,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 @@ -789,6 +801,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 @@ -817,6 +831,8 @@ exports[`renders multiline list accordion 1`] = `
},
Object {
"color": "rgba(28, 27, 31, 1)",
"fontFamily": "System",
"fontWeight": "400",
},
Object {
"writingDirection": "ltr",
Expand Down
Loading

0 comments on commit 278366d

Please sign in to comment.