From c79f808418bebe5d94de7f5fd1a6fa6ee749f222 Mon Sep 17 00:00:00 2001 From: hasparus Date: Thu, 7 Oct 2021 07:38:01 +0200 Subject: [PATCH] wip(typography): run overrideStyles and log it to console --- packages/typography/src/to-theme.ts | 30 +++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/packages/typography/src/to-theme.ts b/packages/typography/src/to-theme.ts index 71e6420ae..2cae40ef9 100644 --- a/packages/typography/src/to-theme.ts +++ b/packages/typography/src/to-theme.ts @@ -3,7 +3,10 @@ import verticalRhythm from 'compass-vertical-rhythm' import { Theme, Scale, ThemeStyles } from '@theme-ui/css' import ms from 'modularscale' import CSS from 'csstype' -import { TypographyOptions } from 'typography' +import { + TypographyOptions, + VerticalRhythm as TypographyJSVerticalRhythm, +} from 'typography' import { Merge } from 'type-fest' import styles from './styles' @@ -72,9 +75,10 @@ const defaults: CustomTypographyOptions = { export const toUnitless = parseFloat -export const getScale = (opts: CustomTypographyOptions) => ( - value: number -): number => ms(value, opts.scaleRatio) * opts.baseFontSize +export const getScale = + (opts: CustomTypographyOptions) => + (value: number): number => + ms(value, opts.scaleRatio) * opts.baseFontSize export type ThemeSpace = number[] export const getSpace = ( @@ -172,7 +176,6 @@ const pruneOptionsFromUnwanted = ( if (opts == null) { return opts } - const res = { ...opts } for (const k of unwantedTypographyOptions) { delete res[k] @@ -187,7 +190,7 @@ const toUnitlessOptions = ( // Or opts with nullish baseFontSize (intentional override) // Or opts with unset baseFontSize (just not defined) if (opts == null || opts.baseFontSize == null) { - return (opts as unknown) as Partial + return opts as unknown as Partial } return { @@ -228,6 +231,21 @@ export const toTheme = ( const rhythm: verticalRhythm.VerticalRhythm = verticalRhythm(rhythmOpts) + // typography.js types are outdated + const overrideStyles = options?.overrideStyles as any + if (overrideStyles) { + const overrides = overrideStyles( + { + adjustFontSizeTo: rhythm.adjustFontSizeTo, + rhythm: rhythm.rhythm, + scale: getScale(opts), + }, + options + ) + + console.log({ overrides }) + } + return { space: getSpace(rhythm, opts), fonts: getFonts(rhythm, opts),