Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

fix(css-variables): improve robustness and developer warnings #449

Merged
merged 6 commits into from
Sep 24, 2019
9 changes: 5 additions & 4 deletions src/CssVariables.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import propTypes from 'prop-types'
import propTypes from '@dhis2/prop-types'
import * as theme from './theme.js'

const toPrefixedThemeSection = themeSectionKey =>
Expand All @@ -22,10 +22,11 @@ const toCustomPropertyString = themeSection =>
* @example import { CssVariables } from @dhis2/ui-core
* @see Live demo: {@link /demo/?path=/story/cssvariables--default|Storybook}
*/
const CssVariables = props => {
const variables = Object.keys(props)
const CssVariables = ({ colors, theme, layers, spacers, elevations }) => {
const allowedProps = { colors, theme, layers, spacers, elevations }
const variables = Object.keys(allowedProps)
// Filter all props that are false
.filter(prop => props[prop])
.filter(prop => allowedProps[prop])
// Map props to corresponding theme section and prefixes keys with section name
.map(toPrefixedThemeSection)
// Map each section to a single string of css custom property declarations
Expand Down