UNPKG

vcc-ui

Version:

A React library for building user interfaces at Volvo Cars

45 lines 1.1 kB
import PropTypes from 'prop-types'; import React, { useContext } from 'react'; import { ThemeProvider as FelaThemeProvider, ThemeContext } from 'react-fela'; import { useConfig } from '../config/use-config'; import { getTheme } from '../themes/getTheme'; export const ThemePicker = _ref => { let { direction, variant, children } = _ref; const { locale } = useConfig(); const currentTheme = useContext(ThemeContext); let theme; if (variant) { theme = getTheme({ variant, locale, direction: direction || currentTheme?.direction }); } else if (currentTheme) { theme = direction ? { ...currentTheme, direction } : currentTheme; } else { theme = getTheme({ variant: 'light', locale, direction }); } return /*#__PURE__*/React.createElement(FelaThemeProvider, { theme: theme, overwrite: false }, children); }; ThemePicker.propTypes = { direction: PropTypes.oneOf(['ltr', 'rtl']), variant: PropTypes.oneOf(['light', 'dark']), // @ts-ignore children: PropTypes.node.isRequired };