From 1e2830dc88e8770b6561846f44342b4f50604ae1 Mon Sep 17 00:00:00 2001 From: Daniel da Silva Date: Fri, 3 Feb 2023 10:55:43 +0000 Subject: [PATCH] Convert theme to TS and update zIndex values --- app/scripts/components/common/nav-wrapper.js | 3 +- app/scripts/components/common/tip.ts | 2 +- app/scripts/styles/{theme.js => theme.ts} | 90 +++++++++++--------- types.d.ts | 16 ++++ 4 files changed, 71 insertions(+), 40 deletions(-) rename app/scripts/styles/{theme.js => theme.ts} (57%) create mode 100644 types.d.ts diff --git a/app/scripts/components/common/nav-wrapper.js b/app/scripts/components/common/nav-wrapper.js index 58f4183c4..7a3dbf843 100644 --- a/app/scripts/components/common/nav-wrapper.js +++ b/app/scripts/components/common/nav-wrapper.js @@ -1,6 +1,7 @@ import React from 'react'; import T from 'prop-types'; import styled, { css } from 'styled-components'; +import { themeVal } from '@devseed-ui/theme-provider'; import PageHeader from './page-header'; import { useSlidingStickyHeaderProps } from './layout-root'; @@ -15,7 +16,7 @@ const NavWrapper = styled.div` position: sticky; top: 0; width: 100%; - z-index: 900; + z-index: ${themeVal('zIndices.sticky')}; transition: top ${HEADER_TRANSITION_DURATION}ms ease-out; ${({ shouldSlideHeader, headerHeight }) => diff --git a/app/scripts/components/common/tip.ts b/app/scripts/components/common/tip.ts index 74b6e65c2..7eccb05a6 100644 --- a/app/scripts/components/common/tip.ts +++ b/app/scripts/components/common/tip.ts @@ -11,7 +11,7 @@ export const Tip = Typpy; export const reactTippyStyles = () => css` body { [data-tippy-root] { - z-index: 800 !important; + z-index: ${themeVal('zIndices.tooltip')} !important; } .tippy-box { diff --git a/app/scripts/styles/theme.js b/app/scripts/styles/theme.ts similarity index 57% rename from app/scripts/styles/theme.js rename to app/scripts/styles/theme.ts index cb1b030c0..651dbd28a 100644 --- a/app/scripts/styles/theme.js +++ b/app/scripts/styles/theme.ts @@ -2,45 +2,59 @@ import { createUITheme, media, themeVal } from '@devseed-ui/theme-provider'; import { createGlobalStyle } from 'styled-components'; import { reactTippyStyles } from '$components/common/tip'; -export default function themeOverrides() { - return createUITheme({ - color: { - base: '#2c3e50', - primary: '#2276ac', - infographicA: '#fcab10', - infographicB: '#f4442e', - infographicC: '#b62b6e', - infographicD: '#2ca58d', - infographicE: '#2276ac' - }, - type: { - base: { - leadSize: '1.25rem', - extrabold: '800', - // Increments to the type.base.size for each media breakpoint. - sizeIncrement: { - small: '0rem', - medium: '0rem', - large: '0.25rem', - xlarge: '0.25rem' - } - }, - heading: { - settings: '"wdth" 100, "wght" 700' +export const VEDA_OVERRIDE_THEME = { + zIndices: { + hide: -1, + docked: 10, + sticky: 900, + dropdown: 1000, + overlay: 1300, + modal: 1400, + popover: 1500, + skipLink: 1600, + toast: 1700, + tooltip: 1800 + }, + color: { + base: '#2c3e50', + primary: '#2276ac', + infographicA: '#fcab10', + infographicB: '#f4442e', + infographicC: '#b62b6e', + infographicD: '#2ca58d', + infographicE: '#2276ac' + }, + type: { + base: { + leadSize: '1.25rem', + extrabold: '800', + // Increments to the type.base.size for each media breakpoint. + sizeIncrement: { + small: '0rem', + medium: '0rem', + large: '0.25rem', + xlarge: '0.25rem' } }, - layout: { - min: '384px', - max: '1440px', - glspMultiplier: { - xsmall: 1, - small: 1, - medium: 1.5, - large: 2, - xlarge: 2 - } + heading: { + settings: '"wdth" 100, "wght" 700' + } + }, + layout: { + min: '384px', + max: '1440px', + glspMultiplier: { + xsmall: 1, + small: 1, + medium: 1.5, + large: 2, + xlarge: 2 } - }); + } +}; + +export default function themeOverrides() { + return createUITheme(VEDA_OVERRIDE_THEME); } /** @@ -51,7 +65,7 @@ export const GlobalStyles = createGlobalStyle` ${reactTippyStyles()} .tether-element.tether-element { - z-index: 700; + z-index: ${themeVal('zIndices.dropdown')}; } :root { @@ -85,4 +99,4 @@ export const GlobalStyles = createGlobalStyle` --base-space-multiplier: ${themeVal('layout.glspMultiplier.xlarge')}; } `} -`; +`; \ No newline at end of file diff --git a/types.d.ts b/types.d.ts new file mode 100644 index 000000000..49e548979 --- /dev/null +++ b/types.d.ts @@ -0,0 +1,16 @@ +import { VEDA_OVERRIDE_THEME } from "$styles/theme"; + +// Convert object keys to string paths. +type PropertyStringPath = { + [K in keyof T]: T[K] extends number | string + ? `${string & Prefix}${string & K}` + : PropertyStringPath; +}[keyof T]; + +declare module '@devseed-ui/theme-provider' { + type ThemeValPathExtend = + | ThemeValPath + | PropertyStringPath; + + function themeVal(path: ThemeValPathExtend): ThemeValReturn; +} \ No newline at end of file