diff --git a/src/Background/Background.style.ts b/src/Background/Background.style.ts index 0aa30e3be..bfaf982b7 100644 --- a/src/Background/Background.style.ts +++ b/src/Background/Background.style.ts @@ -2,12 +2,8 @@ import styled from 'styled-components' import { theme } from '../theme' -export const BackgroundContainer = styled.div<{ - backgroundColor: string -}>` +export const BackgroundContainer = styled.div` &:not([data-simulated='true']) { - background-color: ${theme.color('primary', { - valuePropName: 'backgroundColor', - })}; + background-color: ${theme.color('background')}; } ` diff --git a/src/Background/Background.tsx b/src/Background/Background.tsx index e09b4628b..68cf76ceb 100644 --- a/src/Background/Background.tsx +++ b/src/Background/Background.tsx @@ -33,12 +33,7 @@ export const Background = React.forwardRef( return ( - + ) } diff --git a/src/Card/Card.tsx b/src/Card/Card.tsx index 48d229244..dd6d46921 100644 --- a/src/Card/Card.tsx +++ b/src/Card/Card.tsx @@ -1,16 +1,19 @@ import * as React from 'react' +import { useCurrentBackground } from '../useCurrentBackground' + import { CardProps } from './Card.interface' import { CardContainer } from './Card.style' export const Card = React.forwardRef( (props, ref) => { + const defaultBackgroundColor = useCurrentBackground() const { animated, flat, children, spacing, - backgroundColor = '#FFFFFF', + backgroundColor = defaultBackgroundColor, ...rest } = props diff --git a/src/HeaderBar/HeaderBar.interface.ts b/src/HeaderBar/HeaderBar.interface.ts index 2b1ece03f..d83873089 100644 --- a/src/HeaderBar/HeaderBar.interface.ts +++ b/src/HeaderBar/HeaderBar.interface.ts @@ -1,10 +1,11 @@ import { BackgroundProps } from '../Background' +import { Color } from '../color' export interface HeaderBarProps extends Omit { progress?: number small?: boolean large?: boolean - backgroundColor?: string + backgroundColor?: Color sticky?: boolean } diff --git a/src/Layout/Layout.interface.ts b/src/Layout/Layout.interface.ts index 40a3f9236..beaf82be4 100644 --- a/src/Layout/Layout.interface.ts +++ b/src/Layout/Layout.interface.ts @@ -1,7 +1,8 @@ import { BackgroundProps } from '../Background' +import { Color } from '../color' export interface LayoutProps extends Omit { - backgroundColor?: string + backgroundColor?: Color } export enum LayoutChild { diff --git a/src/LightBox/LightBox.tsx b/src/LightBox/LightBox.tsx index 7419a5d1b..9eefc927f 100644 --- a/src/LightBox/LightBox.tsx +++ b/src/LightBox/LightBox.tsx @@ -5,6 +5,7 @@ import * as ReactDOM from 'react-dom' import { isFunction } from '../_internal/data' import { isClientSide } from '../_internal/ssr' import { ANIMATION_DURATIONS } from '../animations' +import { useCurrentBackground } from '../useCurrentBackground' import { withTriggerElement } from '../withTriggerElement' import { LightBoxInnerProps } from './LightBox.interface' @@ -30,10 +31,12 @@ const InnerLightBox = React.forwardRef( animationDuration: ANIMATION_DURATIONS.l, }) + const backgroundColor = useCurrentBackground({ useRootTheme: true }) + const content = ( ( } ) -export const LightBox = withTriggerElement()< - LightBoxInnerProps ->(InnerLightBox) +export const LightBox = withTriggerElement()( + InnerLightBox +) diff --git a/src/Menu/Menu.style.ts b/src/Menu/Menu.style.ts index e08153cf2..63bbf8d25 100644 --- a/src/Menu/Menu.style.ts +++ b/src/Menu/Menu.style.ts @@ -1,10 +1,8 @@ import styled from 'styled-components' -import { Background } from '../Background' import { theme } from '../theme' -export const FloatingMenuContainer = styled(Background)` - background-color: ${theme.color('background', { useRootTheme: true })}; +export const FloatingMenuContainer = styled.div` box-shadow: ${theme.shadow()}; border-radius: 4px; ` diff --git a/src/Menu/Menu.tsx b/src/Menu/Menu.tsx index 68b0283fb..3dc1a1506 100644 --- a/src/Menu/Menu.tsx +++ b/src/Menu/Menu.tsx @@ -6,7 +6,6 @@ import { buildUseOnlyOpenedInstanceHook } from '../_internal/useOnlyOpenedInstan import { useWindowSize } from '../_internal/useWindowSize' import { breakpoints } from '../breakpoints' import { TogglePanel, TogglePanelProps } from '../TogglePanel' -import { useCurrentBackground } from '../useCurrentBackground' import { withTriggerElement } from '../withTriggerElement' import { MenuContext } from './Menu.context' @@ -38,7 +37,6 @@ export const InnerMenu = React.forwardRef( useOnlyOneMenuOpened({ open, onClose }) const size = useWindowSize() - const background = useCurrentBackground({ useRootTheme: true }) const getChildren = React.useCallback( (modal: Modal) => { @@ -49,7 +47,7 @@ export const InnerMenu = React.forwardRef( {fullScreenOnMobile && size.width < breakpoints.raw.phone ? ( {content} ) : ( - + {content} @@ -58,14 +56,7 @@ export const InnerMenu = React.forwardRef( ) }, - [ - background, - children, - fullScreenOnMobile, - onClose, - scrollable, - size.width, - ] + [children, fullScreenOnMobile, onClose, scrollable, size.width] ) const setStyle = React.useCallback['setStyle']>( diff --git a/src/Modal/Modal.tsx b/src/Modal/Modal.tsx index f4fb4e579..efeafdd6e 100644 --- a/src/Modal/Modal.tsx +++ b/src/Modal/Modal.tsx @@ -4,6 +4,7 @@ import * as ReactDOM from 'react-dom' import { isFunction } from '../_internal/data' import { isClientSide } from '../_internal/ssr' +import { useCurrentBackground } from '../useCurrentBackground' import { withTriggerElement } from '../withTriggerElement' import { ModalInnerProps } from './Modal.interface' @@ -42,10 +43,12 @@ const InnerModal = React.forwardRef( animationDuration: ANIMATION_DURATION, }) + const backgroundColor = useCurrentBackground({ useRootTheme: true }) + const content = ( @@ -92,7 +92,7 @@ export const SelectContainer = styled.div` } &[data-light='true'] { - --select-background-color: #fff; + --select-background-color: ${theme.color('background')}; font-size: ${fontScale.mars.size}px; padding: 0 12px; @@ -143,7 +143,7 @@ export const SelectContainer = styled.div` } &:not([data-light='true']) { - background-color: #fff; + background-color: ${theme.neutralColor(100)}; } } diff --git a/src/TextInput/TextInput.style.ts b/src/TextInput/TextInput.style.ts index da0f8eee3..98b61dd7c 100644 --- a/src/TextInput/TextInput.style.ts +++ b/src/TextInput/TextInput.style.ts @@ -53,8 +53,8 @@ export const inputStyle = css` } &[data-background='true'] { - background-color: #fff; - border-color: #fff; + background-color: ${theme.neutralColor(100)}; + border-color: ${theme.neutralColor(300)}; } &[data-error='true'] { diff --git a/src/ThemeProvider/ThemeProvider.interface.ts b/src/ThemeProvider/ThemeProvider.interface.ts index b515b8807..0d2cc5c44 100644 --- a/src/ThemeProvider/ThemeProvider.interface.ts +++ b/src/ThemeProvider/ThemeProvider.interface.ts @@ -1,6 +1,5 @@ import * as React from 'react' -import { Color } from '../color' import { ThemeVariant } from '../theme' type PartialRecursive = T extends object @@ -8,12 +7,12 @@ type PartialRecursive = T extends object : T export interface DesignSystemThemePatch { - backgroundColor?: Color light?: PartialRecursive dark?: PartialRecursive } export interface ThemeProviderProps { - theme: DesignSystemThemePatch + theme?: DesignSystemThemePatch + preset?: 'dark' | 'light' children?: React.ReactNode } diff --git a/src/ThemeProvider/ThemeProvider.style.ts b/src/ThemeProvider/ThemeProvider.style.ts new file mode 100644 index 000000000..b4880cb3e --- /dev/null +++ b/src/ThemeProvider/ThemeProvider.style.ts @@ -0,0 +1,7 @@ +import styled from 'styled-components' + +import { theme } from '../theme' + +export const ThemeProviderContainer = styled.div` + background-color: ${theme.color('background')}; +` diff --git a/src/ThemeProvider/ThemeProvider.tsx b/src/ThemeProvider/ThemeProvider.tsx index d046da766..c30f20667 100644 --- a/src/ThemeProvider/ThemeProvider.tsx +++ b/src/ThemeProvider/ThemeProvider.tsx @@ -5,7 +5,6 @@ import { ThemeContext, } from 'styled-components' -import { isColorDark } from '../color' import { DesignSystemTheme, DesignSystemProviderValue, @@ -15,9 +14,11 @@ import { import { ThemeVariant } from '../theme' import { ThemeProviderProps } from './ThemeProvider.interface' +import { ThemeProviderContainer } from './ThemeProvider.style' export const ThemeProvider: React.FunctionComponent = ({ theme, + preset = 'light', children, }) => { const styledTheme = React.useContext(ThemeContext) @@ -28,30 +29,37 @@ export const ThemeProvider: React.FunctionComponent = ({ const newLightVariant: ThemeVariant = merge.recursive( true, currentTheme.light, - theme.light ?? {} + theme?.light ?? {} ) const newDarkVariant: ThemeVariant = merge.recursive( true, currentTheme.dark, - theme.dark ?? {} + theme?.dark ?? {} ) - const newBackgroundColor = - theme.backgroundColor ?? currentTheme.backgroundColor - const newTheme: DesignSystemTheme = { light: newLightVariant, dark: newDarkVariant, - isDark: isColorDark(newBackgroundColor), - backgroundColor: newBackgroundColor, + isDark: preset === 'dark', + backgroundColor: + preset === 'dark' + ? newDarkVariant.defaultBackground + : newLightVariant.defaultBackground, } return { value: newTheme, rootValue: newTheme, } - }, [currentTheme, theme]) + }, [ + currentTheme.backgroundColor, + currentTheme.dark, + currentTheme.light, + preset, + theme?.dark, + theme?.light, + ]) const newStyledTheme = React.useMemo( () => ({ @@ -63,7 +71,7 @@ export const ThemeProvider: React.FunctionComponent = ({ return ( - {children} + {children} ) } diff --git a/src/TogglePanel/TogglePanel.style.ts b/src/TogglePanel/TogglePanel.style.ts index 9455187d1..629e4a9be 100644 --- a/src/TogglePanel/TogglePanel.style.ts +++ b/src/TogglePanel/TogglePanel.style.ts @@ -2,8 +2,9 @@ import styled from 'styled-components' import { zIndex } from '../_internal/theme/zIndex' import { animations } from '../animations' +import { Background } from '../Background' -export const Container = styled.div` +export const Container = styled(Background)` position: fixed; opacity: 1; z-index: ${zIndex.dropDowns}; diff --git a/src/TogglePanel/TogglePanel.tsx b/src/TogglePanel/TogglePanel.tsx index 1bce24333..68651e4c2 100644 --- a/src/TogglePanel/TogglePanel.tsx +++ b/src/TogglePanel/TogglePanel.tsx @@ -8,6 +8,7 @@ import { useWindowSize } from '../_internal/useWindowSize' import { ANIMATION_DURATIONS } from '../animations' import { breakpoints } from '../breakpoints' import { Modal } from '../Modal' +import { useCurrentBackground } from '../useCurrentBackground' import { withTriggerElement } from '../withTriggerElement' import { InnerTogglePanelProps } from './TogglePanel.interface' @@ -100,6 +101,8 @@ const InnerTogglePanel = React.forwardRef< const parent = React.useContext(Context) + const backgroundColor = useCurrentBackground({ useRootTheme: true }) + if (!isClientSide) { return null } @@ -121,6 +124,7 @@ const InnerTogglePanel = React.forwardRef< {withOverlay && modal.state === 'opened' && }