Skip to content

Commit

Permalink
feat: adds spacing array to the theme
Browse files Browse the repository at this point in the history
  • Loading branch information
jongomez committed Oct 11, 2023
1 parent 0ff0bbc commit efa4792
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/lsd-react/.storybook/themes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const themeProps: CreateThemeProps = {
breakpoints: {},
palette: {},
typographyGlobal: {},
spacing: [],
}

const createThemes = () => {
Expand Down
1 change: 1 addition & 0 deletions packages/lsd-react/src/components/Theme/baseTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ export const baseTheme: Theme = {
secondary: '255, 255, 255',
},
},
spacing: [4, 8, 16, 24, 32, 40, 64, 80, 96, 120],
globalStyles: css``,
cssVars: '',
}
Expand Down
1 change: 1 addition & 0 deletions packages/lsd-react/src/components/Theme/createTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export const createTheme = (
palette: createPaletteStyles(props, from),
globalStyles: css``,
cssVars: '',
spacing: props.spacing.length ? props.spacing : from.spacing,
}

const { cssVars, globalStyles } = createThemeGlobalStyles(theme)
Expand Down
2 changes: 2 additions & 0 deletions packages/lsd-react/src/components/Theme/defaultThemes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const lightTheme = createTheme(
typography: {},
typographyGlobal: {},
palette: {},
spacing: [],
},
baseTheme,
)
Expand All @@ -22,6 +23,7 @@ const darkTheme = createTheme(
primary: '255, 255, 255',
secondary: '0, 0, 0',
},
spacing: [],
},
lightTheme,
)
Expand Down
8 changes: 8 additions & 0 deletions packages/lsd-react/src/components/Theme/globalStyles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ const generateThemeGlobalStyles = (theme: Theme) => {
)
}

// Spacing-related CSS variable definitions
{
theme.spacing.map((spacingValue) => {
const varName = cssUtils.vars.lsd('spacing', spacingValue.toString())
vars.push(cssUtils.define(varName, `${spacingValue}px`))
})
}

THEME_BREAKPOINTS.map((breakpoint, index) => {
styles.push(`@media (min-width: ${theme.breakpoints[breakpoint].width}px) {
:root {
Expand Down
2 changes: 2 additions & 0 deletions packages/lsd-react/src/components/Theme/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export type Theme = {
palette: ThemePalette
globalStyles: SerializedStyles
cssVars: string
spacing: number[]
}

export type ThemeOptionBreakpointStyles = Partial<
Expand All @@ -100,6 +101,7 @@ export type CreateThemeProps = {
typography: ThemeOptionTypography
typographyGlobal: Partial<GlobalTypographyStyles>
palette: ThemeOptionPalette
spacing: number[]
}

export type ThemeContext = {
Expand Down

0 comments on commit efa4792

Please sign in to comment.