Skip to content

Add support for defining fonts in the theme #233

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

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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## Next

- Add support for defining fonts in the theme. [#232](https://github.com/Shopify/restyle/pull/232) by [ergenekonyigit](https://github.com/ergenekonyigit) & [gokselpirnal](https://github.com/gokselpirnal)
- Fixed: clean up the project configuration for RN0.71, aligning some packages to the right version [#271](https://github.com/Shopify/restyle/pull/271) by [kelset](https://github.com/kelset) & [tido64](https://github.com/tido64)

## 2.4.2 - 2023-03-30
Expand All @@ -27,6 +28,7 @@ and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
- Renamed gap shorthands to be lowercase [#218](https://github.com/Shopify/restyle/pull/218) by [mlecoq](https://github.com/mlecoq)
- Better TypeScript type support [#216](https://github.com/Shopify/restyle/pull/216) by [FranzMoreno](https://github.com/FranzMoreno) & [fortmarek](https://github.com/fortmarek)


## 2.2.0 - 2023-01-24

- Upgrade React Native to 0.71 in [#207](https://github.com/Shopify/restyle/pull/207) by [mattfrances](https://github.com/mattfrances)
Expand Down
3 changes: 2 additions & 1 deletion documentation/docs/fundamentals/restyle-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ The Restyle library comes with a number of predefined Restyle functions for your
| shadow | shadowColor | colors |
| textShadow | textShadowOffset, textShadowRadius | _none_ |
| textShadow | textShadowColor | colors |
| typography | fontFamily, fontSize, fontStyle, fontWeight, includeFontPadding, fontVariant, letterSpacing, lineHeight, textAlign, textAlignVertical, textDecorationColor, textDecorationLine, textDecorationStyle, textTransform, verticalAlign, writingDirection | _none_ |
| typography | fontSize, fontStyle, fontWeight, includeFontPadding, fontVariant, letterSpacing, lineHeight, textAlign, textAlignVertical, textDecorationColor, textDecorationLine, textDecorationStyle, textTransform, verticalAlign, writingDirection | _none_ |
| typography | fontFamily | fonts |

## Custom Restyle functions

Expand Down
2 changes: 2 additions & 0 deletions documentation/docs/guides/dark-mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const theme = createTheme({
primaryCardText: palette.white,
secondaryCardText: palette.black,
},
breakpoints: {},
fonts: {},
textVariants: {
defaults: {},
body: {
Expand Down
22 changes: 16 additions & 6 deletions src/restyleFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ const spacingPropertiesShorthand = {
};

const typographyProperties = {
fontFamily: true,
fontSize: true,
fontStyle: true,
fontWeight: true,
Expand Down Expand Up @@ -199,11 +198,17 @@ export const spacingShorthand = getKeys(spacingPropertiesShorthand).map(
},
);

export const typography = getKeys(typographyProperties).map(property => {
return createRestyleFunction({
property,
});
});
export const typography = [
...getKeys(typographyProperties).map(property => {
return createRestyleFunction({
property,
});
}),
createRestyleFunction({
property: 'fontFamily',
themeKey: 'fonts',
}),
];

export const layout = getKeys(layoutProperties).map(property => {
return createRestyleFunction({
Expand Down Expand Up @@ -327,6 +332,11 @@ export type TypographyProps<Theme extends BaseTheme> = {
TextStyle[Key],
Theme['breakpoints']
>;
} & {
fontFamily?: ResponsiveValue<
Theme['fonts'] extends object ? keyof Theme['fonts'] : string,
Theme['breakpoints']
>;
};

export type LayoutProps<Theme extends BaseTheme> = {
Expand Down
3 changes: 3 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ export interface KnownBaseTheme {
zIndices?: {
[key: string]: number;
};
fonts?: {
[key: string]: string;
};
borderRadii?: {
[key: string]: number;
};
Expand Down