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: use "base" fontFamily in web #5648

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import { Text } from 'native-base';

export const Example = () => {
return (
<Text fontFamily="heading" italic>
This is Text.
</Text>
);
};
28 changes: 26 additions & 2 deletions example/storybook/stories/components/primitives/Text/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,36 @@ import { Example as ChangingFontSize } from './ChangingFontSize';
import { Example as Overriden } from './Overriden';
import { Example as Truncated } from './Truncated';
import { Example as Nested } from './Nested';
import { Example as ChangingFont } from './ChangingFont';
import { extendTheme } from '../../../../../../src/core';

const theme = extendTheme({
fontConfig: {
heading: {
400: {
normal: 'heading-Regular',
italic: 'heading-Italic',
},
500: {
normal: 'heading-Medium',
italic: 'heading-MediumItalic',
},
700: {
normal: 'heading-Bold',
italic: 'heading-BoldItalic',
},
},
},
});

storiesOf('Text', module)
.addDecorator(withKnobs)
.addDecorator((getStory: any) => <Wrapper>{getStory()}</Wrapper>)
.addDecorator((getStory: any) => (
<Wrapper theme={theme}>{getStory()}</Wrapper>
))
.add('Basic', () => <Basic />)
.add('Changing Font Size', () => <ChangingFontSize />)
.add('Truncated', () => <Truncated />)
.add('Overriden', () => <Overriden />)
.add('Nested', () => <Nested />);
.add('Nested', () => <Nested />)
.add('Changing Font', () => <ChangingFont />);
18 changes: 18 additions & 0 deletions src/hooks/useResolvedFontFamily.web.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { ITheme } from '../theme';
/**
*
* @param props
* @returns resolved fontFamily
* @description Combination of fontWeight, fontStyle and font family is fully supported on web but on Android we need to pass the exact font family.
* for e.g. If we load Roboto-Light-Italic.ttf using css, we can use fontFamily: Roboto, fontWeight: 300, fontStyle: italic on web, but same may not work on all the platforms. Other platform needs to set fontFamily: Roboto-Light-Italic in order to work.
* So this function's purpose is to intake styles like fontFamily: Roboto, fontWeight: 300, fontStyle: Italic and return fontFamily: Roboto-Light-Italic depending upon the fontConfig token in typography theme.
* This function depends upon fontConfig token in typography for mapping.
*/
export function useResolvedFontFamily(props: {
fontFamily?: keyof ITheme['fonts'];
fontStyle?: string;
fontWeight?: keyof ITheme['fontWeights'];
}) {
const { fontFamily, fontStyle, fontWeight } = props;
return { fontFamily, fontStyle, fontWeight };
}