From 28b47d58ebc83821060f0a091bf80de75d21a62f Mon Sep 17 00:00:00 2001 From: bang9 Date: Fri, 24 Jun 2022 11:00:24 +0900 Subject: [PATCH] feat(foundation): added typography option to themeFactory --- .../src/styles/themeFactory.ts | 19 ++++++++++++------- .../src/theme/Typography.ts | 3 ++- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/packages/uikit-react-native-foundation/src/styles/themeFactory.ts b/packages/uikit-react-native-foundation/src/styles/themeFactory.ts index ad97591b4..63efa578d 100644 --- a/packages/uikit-react-native-foundation/src/styles/themeFactory.ts +++ b/packages/uikit-react-native-foundation/src/styles/themeFactory.ts @@ -1,5 +1,5 @@ import Palette from '../theme/Palette'; -import { createTypography } from '../theme/Typography'; +import { TypographyOverrides, createTypography } from '../theme/Typography'; import type { UIKitColors, UIKitTheme } from '../types'; import createAppearanceHelper from './createAppearanceHelper'; import createScaleFactor from './createScaleFactor'; @@ -9,24 +9,29 @@ type Options = { appearance: UIKitTheme['appearance']; palette?: UIKitTheme['palette']; colors: (palette: UIKitTheme['palette']) => UIKitColors; + typography?: TypographyOverrides; scaleFactorOption?: { scaleFactor: UIKitTheme['scaleFactor']; applyToCreateStyleSheet: boolean; }; }; -const defaultScaleFactor = createScaleFactor(); - -export const themeFactory = ({ appearance, scaleFactorOption, palette = Palette, colors }: Options): UIKitTheme => { +export const themeFactory = ({ + appearance, + scaleFactorOption, + palette = Palette, + colors, + typography = { shared: { fontFamily: 'System' } }, +}: Options): UIKitTheme => { if (scaleFactorOption?.applyToCreateStyleSheet) createStyleSheet.updateScaleFactor(scaleFactorOption.scaleFactor); - const _scaleFactor = scaleFactorOption?.scaleFactor ?? defaultScaleFactor; + const scaleFactor = scaleFactorOption?.scaleFactor ?? createScaleFactor(); return { appearance, palette, select: createAppearanceHelper(appearance), colors: colors(palette), - scaleFactor: _scaleFactor, - typography: createTypography({ shared: { fontFamily: 'System' } }, _scaleFactor), + typography: createTypography(typography, scaleFactor), + scaleFactor, }; }; diff --git a/packages/uikit-react-native-foundation/src/theme/Typography.ts b/packages/uikit-react-native-foundation/src/theme/Typography.ts index 98ed874e1..b53c08023 100644 --- a/packages/uikit-react-native-foundation/src/theme/Typography.ts +++ b/packages/uikit-react-native-foundation/src/theme/Typography.ts @@ -1,8 +1,9 @@ import type { FontAttributes, Typography } from '../types'; -type TypographyOverrides = Partial & { +export type TypographyOverrides = Partial & { shared?: Partial; }; + export const createTypography = ( overrides: TypographyOverrides = {}, scaleFactor: (dp: number) => number,