mirror of https://github.com/acid-info/lsd.git
fix(lsd-react): use theme's name as the cache key when generating global styles
This commit is contained in:
parent
28e42de46c
commit
6fd888078e
|
@ -17,7 +17,7 @@ const createThemes = () => {
|
||||||
const themes = fonts.map((font) => [
|
const themes = fonts.map((font) => [
|
||||||
createTheme(
|
createTheme(
|
||||||
{
|
{
|
||||||
name: `${defaultThemes.light.name} (${font})`,
|
// name: `${defaultThemes.light.name} (${font})`,
|
||||||
...themeProps,
|
...themeProps,
|
||||||
typographyGlobal: {
|
typographyGlobal: {
|
||||||
genericFontFamily: font,
|
genericFontFamily: font,
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { css } from '@emotion/react'
|
import { css } from '@emotion/react'
|
||||||
|
import { createCounter } from '../../utils/counter.util'
|
||||||
import { pairs } from '../../utils/object.utils'
|
import { pairs } from '../../utils/object.utils'
|
||||||
import { baseTheme } from './baseTheme'
|
import { baseTheme } from './baseTheme'
|
||||||
import { THEME_BREAKPOINTS, THEME_TYPOGRAPHY_VARIANTS } from './constants'
|
import { THEME_BREAKPOINTS, THEME_TYPOGRAPHY_VARIANTS } from './constants'
|
||||||
|
@ -13,6 +14,9 @@ import type {
|
||||||
VariantThemeProperties,
|
VariantThemeProperties,
|
||||||
} from './types'
|
} from './types'
|
||||||
|
|
||||||
|
const counter = createCounter()
|
||||||
|
const generateName = (prefix: string) => `${prefix}-${counter()}`
|
||||||
|
|
||||||
const createTypographyStyles = (theme: CreateThemeProps, defaultTheme: Theme) =>
|
const createTypographyStyles = (theme: CreateThemeProps, defaultTheme: Theme) =>
|
||||||
pairs<TypographyVariants>(THEME_TYPOGRAPHY_VARIANTS, (variant) => ({
|
pairs<TypographyVariants>(THEME_TYPOGRAPHY_VARIANTS, (variant) => ({
|
||||||
...defaultTheme.typography[variant],
|
...defaultTheme.typography[variant],
|
||||||
|
@ -130,7 +134,7 @@ export const createTheme = (
|
||||||
from = baseTheme,
|
from = baseTheme,
|
||||||
): Theme => {
|
): Theme => {
|
||||||
const theme: Theme = {
|
const theme: Theme = {
|
||||||
name: props.name ?? from.name,
|
name: props.name ?? generateName(from.name),
|
||||||
typography: createTypographyStyles(props, from),
|
typography: createTypographyStyles(props, from),
|
||||||
typographyGlobal: createTypographyGlobalStyles(props, from),
|
typographyGlobal: createTypographyGlobalStyles(props, from),
|
||||||
breakpoints: createBreakpointStyles(props, from),
|
breakpoints: createBreakpointStyles(props, from),
|
||||||
|
|
|
@ -117,7 +117,7 @@ export const createThemeGlobalStyles = (() => {
|
||||||
const cache: any = {}
|
const cache: any = {}
|
||||||
|
|
||||||
return (theme: Theme): ReturnType<typeof generateThemeGlobalStyles> => {
|
return (theme: Theme): ReturnType<typeof generateThemeGlobalStyles> => {
|
||||||
const key = theme as any as string
|
const key = theme.name
|
||||||
|
|
||||||
if (
|
if (
|
||||||
cache[key] &&
|
cache[key] &&
|
||||||
|
|
Loading…
Reference in New Issue