Skip to content

Commit

Permalink
feat(foundation): added typography option to themeFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
bang9 committed Jun 24, 2022
1 parent 4bfdfde commit 28b47d5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
19 changes: 12 additions & 7 deletions packages/uikit-react-native-foundation/src/styles/themeFactory.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,
};
};
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { FontAttributes, Typography } from '../types';

type TypographyOverrides = Partial<Typography> & {
export type TypographyOverrides = Partial<Typography> & {
shared?: Partial<FontAttributes>;
};

export const createTypography = (
overrides: TypographyOverrides = {},
scaleFactor: (dp: number) => number,
Expand Down

0 comments on commit 28b47d5

Please sign in to comment.