Skip to content

Commit

Permalink
refactor(webapp): extract z-indexes to variables
Browse files Browse the repository at this point in the history
This should make it easier to manage the growing number of z-index
usages.
  • Loading branch information
JoosepAlviste committed Sep 24, 2023
1 parent c0a4fce commit cb90cd5
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 71 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { globalStyle, style } from '@vanilla-extract/css'

import { iconColorVar } from '#/styles/cssVariables'
import { responsive, vars } from '#/styles/theme.css'
import { responsive, vars, zIndex } from '#/styles/theme.css'

export const ANIMATION_DURATION_MS = 200

Expand All @@ -14,7 +14,7 @@ export const mobileMenu = style({
top: 80,
background: vars.color.pageBackground,
padding: '1.5rem',
zIndex: 2,
zIndex: zIndex.layout.header,

'@media': {
[responsive.m]: {
Expand Down
4 changes: 2 additions & 2 deletions apps/webapp/src/components/HomePage/HomePage.css.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { style } from '@vanilla-extract/css'

import { responsive, vars } from '#/styles/theme.css'
import { responsive, vars, zIndex } from '#/styles/theme.css'

export const container = style({
display: 'flex',
Expand Down Expand Up @@ -52,7 +52,7 @@ export const titleHighlight = style({
export const background = style({
position: 'fixed',
inset: 0,
zIndex: -1,
zIndex: zIndex.homePage.background,
background: `radial-gradient(circle at 77% 100%, rgba(99,102,241,0.2) 0%, rgba(99,102,241,0) 60%)`,

'@media': {
Expand Down
3 changes: 2 additions & 1 deletion apps/webapp/src/components/Select/Select.css.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { style } from '@vanilla-extract/css'

import { iconColorVar } from '#/styles/cssVariables'
import { vars } from '#/styles/theme.css'
import { vars, zIndex } from '#/styles/theme.css'

export const trigger = style({
display: 'flex',
Expand All @@ -27,6 +27,7 @@ export const content = style({
borderRadius: vars.radii.s,
paddingTop: '0.25rem',
paddingBottom: '0.25rem',
zIndex: zIndex.layout.select,
})

export const item = style({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { style } from '@vanilla-extract/css'

import { responsive, vars } from '#/styles/theme.css'
import { responsive, vars, zIndex } from '#/styles/theme.css'

export const container = style({
display: 'flex',
Expand Down Expand Up @@ -43,7 +43,7 @@ export const separatorText = style({
background: vars.color.pageBackground,
paddingLeft: '0.5rem',
paddingRight: '0.5rem',
zIndex: 1,
zIndex: zIndex.authLayout.separator,
})

export const otherActionContainer = style({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { style } from '@vanilla-extract/css'

import { vars } from '#/styles/theme.css'
import { vars, zIndex } from '#/styles/theme.css'

export const container = style({
display: 'flex',
Expand Down Expand Up @@ -60,7 +60,7 @@ export const popoverContent = style({
width: '30rem',
maxWidth: '100vw',
overflowY: 'auto',
zIndex: 2,
zIndex: zIndex.search.popover,
})

export const searchTitle = style({
Expand Down
17 changes: 0 additions & 17 deletions apps/webapp/src/hooks/useToast/useToast.css.ts

This file was deleted.

4 changes: 3 additions & 1 deletion apps/webapp/src/providers/ToastProvider/ToastProvider.css.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { style } from '@vanilla-extract/css'

import { zIndex } from '#/styles/theme.css'

export const viewport = style({
display: 'flex',
flexDirection: 'column',
Expand All @@ -13,5 +15,5 @@ export const viewport = style({
maxWidth: '100vw',
listStyle: 'none',
outline: 'none',
zIndex: 2147483647,
zIndex: zIndex.layout.toast,
})
100 changes: 56 additions & 44 deletions apps/webapp/src/styles/theme.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,33 @@ const colors = {
yellow500: '#eab308',
}

const generalVariables = {
fontWeight: {
regular: '400',
medium: '500',
bold: '700',
},

radii: {
s: '0.5rem',
m: '0.75rem',
xl: '1.25rem',
},

shadow: {
md: 'rgba(0, 0, 0, 0.2) 0px 18px 50px -10px',
xl: '0 5px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1)',
'2xl': '0 25px 50px -12px rgb(0 0 0 / 0.25)',
},

easing: {
base: 'cubic-bezier(0.1, 0.9, 0, 1.2)',
},
}

export const [lightThemeClass, vars] = createTheme({
...generalVariables,

color: {
...colors,

Expand Down Expand Up @@ -101,31 +127,11 @@ export const [lightThemeClass, vars] = createTheme({
pillBackground: colors.indigo100,
pillText: colors.indigo500,
},

fontWeight: {
regular: '400',
medium: '500',
bold: '700',
},

radii: {
s: '0.5rem',
m: '0.75rem',
xl: '1.25rem',
},

shadow: {
md: 'rgba(0, 0, 0, 0.2) 0px 18px 50px -10px',
xl: '0 5px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1)',
'2xl': '0 25px 50px -12px rgb(0 0 0 / 0.25)',
},

easing: {
base: 'cubic-bezier(0.1, 0.9, 0, 1.2)',
},
})

export const darkThemeClass = createTheme(vars, {
...generalVariables,

color: {
...colors,

Expand Down Expand Up @@ -186,32 +192,38 @@ export const darkThemeClass = createTheme(vars, {
pillBackground: colors.indigo950,
pillText: colors.indigo400,
},

fontWeight: {
regular: '400',
medium: '500',
bold: '700',
},

radii: {
s: '0.5rem',
m: '0.75rem',
xl: '1.25rem',
},

shadow: {
md: 'rgba(0, 0, 0, 0.2) 0px 18px 50px -10px',
xl: '0 5px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1)',
'2xl': '0 25px 50px -12px rgb(0 0 0 / 0.25)',
},

easing: {
base: 'cubic-bezier(0.1, 0.9, 0, 1.2)',
},
})

export const responsive = {
s: 'screen and (max-width: 320px)',
m: 'screen and (max-width: 768px)',
l: 'screen and (max-width: 1200px)',
}

const base = 1
const above = 1
const below = -1

const zLayoutHeader = above + base
const zLayoutToast = above + zLayoutHeader
const zLayoutSelect = above + zLayoutHeader
const zHomePageBackground = below + base
const zAuthLayoutSeparator = base
const zSearchPopover = above + zLayoutHeader

export const zIndex = {
layout: {
header: zLayoutHeader,
toast: zLayoutToast,
select: zLayoutSelect,
},
homePage: {
background: zHomePageBackground,
},
authLayout: {
separator: zAuthLayoutSeparator,
},
search: {
popover: zSearchPopover,
},
}

0 comments on commit cb90cd5

Please sign in to comment.