diff --git a/CHANGELOG.md b/CHANGELOG.md index e2293b5161..721a2c2f48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Features - Add `color` prop to `Text` component @Bugaa92 ([#597](https://github.com/stardust-ui/react/pull/597)) +- Add `color` prop to `Header` and `HeaderDescription` components @Bugaa92 ([#628](https://github.com/stardust-ui/react/pull/628)) ## [v0.15.0](https://github.com/stardust-ui/react/tree/v0.15.0) (2018-12-17) diff --git a/docs/src/examples/components/Header/Variations/HeaderExampleColor.shorthand.tsx b/docs/src/examples/components/Header/Variations/HeaderExampleColor.shorthand.tsx new file mode 100644 index 0000000000..0ddbdd56f3 --- /dev/null +++ b/docs/src/examples/components/Header/Variations/HeaderExampleColor.shorthand.tsx @@ -0,0 +1,21 @@ +import React from 'react' +import _ from 'lodash' +import { Header, ProviderConsumer } from '@stardust-ui/react' + +const HeaderExampleColor = () => ( + + _.keys({ ...emphasisColors, ...naturalColors }).map(color => ( +
+ )) + } + /> +) + +export default HeaderExampleColor diff --git a/docs/src/examples/components/Header/Variations/HeaderExampleColor.tsx b/docs/src/examples/components/Header/Variations/HeaderExampleColor.tsx new file mode 100644 index 0000000000..9bd112cd00 --- /dev/null +++ b/docs/src/examples/components/Header/Variations/HeaderExampleColor.tsx @@ -0,0 +1,20 @@ +import React from 'react' +import _ from 'lodash' +import { Header, ProviderConsumer } from '@stardust-ui/react' + +const HeaderExampleColor = () => ( + + _.keys({ ...emphasisColors, ...naturalColors }).map(color => ( +
+ {_.startCase(color)} + + {`Description of ${_.lowerCase(color)} color`} + +
+ )) + } + /> +) + +export default HeaderExampleColor diff --git a/docs/src/examples/components/Header/Variations/index.tsx b/docs/src/examples/components/Header/Variations/index.tsx index ca7a86be9c..346dfbbfc2 100644 --- a/docs/src/examples/components/Header/Variations/index.tsx +++ b/docs/src/examples/components/Header/Variations/index.tsx @@ -19,6 +19,11 @@ const Variations = () => ( description="Headers may be aligned to the left, right, center or be justified." examplePath="components/Header/Variations/HeaderExampleTextAlign" /> + ) diff --git a/src/components/Header/Header.tsx b/src/components/Header/Header.tsx index d9ade9af52..a563d68fca 100644 --- a/src/components/Header/Header.tsx +++ b/src/components/Header/Header.tsx @@ -9,6 +9,7 @@ import { ChildrenComponentProps, ContentComponentProps, commonPropTypes, + ColorComponentProps, } from '../../lib' import HeaderDescription from './HeaderDescription' import { Extendable, ShorthandValue } from '../../../types/utils' @@ -16,7 +17,8 @@ import { Extendable, ShorthandValue } from '../../../types/utils' export interface HeaderProps extends UIComponentProps, ChildrenComponentProps, - ContentComponentProps { + ContentComponentProps, + ColorComponentProps { /** Shorthand for Header.Description. */ description?: ShorthandValue @@ -40,7 +42,7 @@ class Header extends UIComponent, any> { static displayName = 'Header' static propTypes = { - ...commonPropTypes.createCommon(), + ...commonPropTypes.createCommon({ color: true }), description: customPropTypes.itemShorthand, textAlign: PropTypes.oneOf(['left', 'center', 'right', 'justified']), } diff --git a/src/components/Header/HeaderDescription.tsx b/src/components/Header/HeaderDescription.tsx index 1943948043..adc25a6209 100644 --- a/src/components/Header/HeaderDescription.tsx +++ b/src/components/Header/HeaderDescription.tsx @@ -8,13 +8,15 @@ import { ChildrenComponentProps, ContentComponentProps, commonPropTypes, + ColorComponentProps, } from '../../lib' import { Extendable } from '../../../types/utils' export interface HeaderDescriptionProps extends UIComponentProps, ChildrenComponentProps, - ContentComponentProps {} + ContentComponentProps, + ColorComponentProps {} /** * A header's description provides more detailed information. @@ -27,7 +29,7 @@ class HeaderDescription extends UIComponent, static displayName = 'HeaderDescription' static propTypes = { - ...commonPropTypes.createCommon(), + ...commonPropTypes.createCommon({ color: true }), } static defaultProps = { diff --git a/src/themes/teams/components/Header/headerDescriptionStyles.ts b/src/themes/teams/components/Header/headerDescriptionStyles.ts index b49c56d101..9efcdd2d67 100644 --- a/src/themes/teams/components/Header/headerDescriptionStyles.ts +++ b/src/themes/teams/components/Header/headerDescriptionStyles.ts @@ -1,11 +1,17 @@ +import * as _ from 'lodash' + import { pxToRem } from '../../utils' -import { ICSSInJSStyle } from '../../../types' +import { ICSSInJSStyle, ComponentSlotStylesInput } from '../../../types' +import { HeaderDescriptionProps } from '../../../../components/Header/HeaderDescription' +import { HeaderDescriptionVariables } from './headerDescriptionVariables' -export default { - root: ({ variables: v }): ICSSInJSStyle => ({ +const headerStyles: ComponentSlotStylesInput = { + root: ({ props: p, variables: v }): ICSSInJSStyle => ({ display: 'block', + color: _.get(v.colors, p.color, v.color), fontSize: pxToRem(22), - color: v.color, fontWeight: 400, }), } + +export default headerStyles diff --git a/src/themes/teams/components/Header/headerDescriptionVariables.ts b/src/themes/teams/components/Header/headerDescriptionVariables.ts index 3de2fffb02..c41a19513c 100644 --- a/src/themes/teams/components/Header/headerDescriptionVariables.ts +++ b/src/themes/teams/components/Header/headerDescriptionVariables.ts @@ -1,3 +1,15 @@ -export default siteVariables => ({ - color: siteVariables.gray04, -}) +import { ColorValues } from '../../../types' +import { mapColorsToScheme } from '../../../../lib' + +export interface HeaderDescriptionVariables { + colors: ColorValues + color: string +} + +export default (siteVariables: any): HeaderDescriptionVariables => { + const colorVariant = 500 + return { + colors: mapColorsToScheme(siteVariables, colorVariant), + color: siteVariables.gray04, + } +} diff --git a/src/themes/teams/components/Header/headerStyles.ts b/src/themes/teams/components/Header/headerStyles.ts index 668937a72d..ecf3789006 100644 --- a/src/themes/teams/components/Header/headerStyles.ts +++ b/src/themes/teams/components/Header/headerStyles.ts @@ -1,10 +1,17 @@ -import { ICSSInJSStyle } from '../../../types' +import * as _ from 'lodash' +import { TextAlignProperty } from 'csstype' -export default { - root: ({ props, variables: v }): ICSSInJSStyle => ({ - color: v.color, - textAlign: props.textAlign, +import { ICSSInJSStyle, ComponentSlotStylesInput } from '../../../types' +import { HeaderProps } from '../../../../components/Header/Header' +import { HeaderVariables } from './headerVariables' + +const headerStyles: ComponentSlotStylesInput = { + root: ({ props: p, variables: v }): ICSSInJSStyle => ({ display: 'block', - ...(props.description && { marginBottom: 0 }), + color: _.get(v.colors, p.color, v.color), + textAlign: p.textAlign as TextAlignProperty, + ...(p.description && { marginBottom: 0 }), }), } + +export default headerStyles diff --git a/src/themes/teams/components/Header/headerVariables.ts b/src/themes/teams/components/Header/headerVariables.ts index 2147b544b9..7891afe646 100644 --- a/src/themes/teams/components/Header/headerVariables.ts +++ b/src/themes/teams/components/Header/headerVariables.ts @@ -1,10 +1,16 @@ +import { ColorValues } from '../../../types' +import { mapColorsToScheme } from '../../../../lib' + export interface HeaderVariables { + colors: ColorValues color: string descriptionColor: string } export default (siteVars: any): HeaderVariables => { + const colorVariant = 500 return { + colors: mapColorsToScheme(siteVars, colorVariant), color: siteVars.black, descriptionColor: undefined, }