Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

feat(header): header and header description color prop #628

Merged
merged 4 commits into from
Dec 18, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]------------------------------- -->
## [v0.15.0](https://github.com/stardust-ui/react/tree/v0.15.0) (2018-12-17)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react'
import _ from 'lodash'
import { Header, ProviderConsumer } from '@stardust-ui/react'

const HeaderExampleColor = () => (
<ProviderConsumer
render={({ siteVariables: { emphasisColors, naturalColors } }) =>
_.keys({ ...emphasisColors, ...naturalColors }).map(color => (
<Header
key={color}
as="h4"
color={color}
content={_.startCase(color)}
description={{ content: `Description of ${_.lowerCase(color)} color`, color }}
/>
))
}
/>
)

export default HeaderExampleColor
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react'
import _ from 'lodash'
import { Header, ProviderConsumer } from '@stardust-ui/react'

const HeaderExampleColor = () => (
<ProviderConsumer
render={({ siteVariables: { emphasisColors, naturalColors } }) =>
_.keys({ ...emphasisColors, ...naturalColors }).map(color => (
<Header key={color} as="h4" color={color}>
{_.startCase(color)}
<Header.Description color={color}>
{`Description of ${_.lowerCase(color)} color`}
</Header.Description>
</Header>
))
}
/>
)

export default HeaderExampleColor
5 changes: 5 additions & 0 deletions docs/src/examples/components/Header/Variations/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ const Variations = () => (
description="Headers may be aligned to the left, right, center or be justified."
examplePath="components/Header/Variations/HeaderExampleTextAlign"
/>
<ComponentExample
title="Color"
description="Headers and descriptions can have colors."
examplePath="components/Header/Variations/HeaderExampleColor"
/>
</ExampleSection>
)

Expand Down
6 changes: 4 additions & 2 deletions src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ import {
ChildrenComponentProps,
ContentComponentProps,
commonPropTypes,
ColorComponentProps,
} from '../../lib'
import HeaderDescription from './HeaderDescription'
import { Extendable, ShorthandValue } from '../../../types/utils'

export interface HeaderProps
extends UIComponentProps,
ChildrenComponentProps,
ContentComponentProps {
ContentComponentProps,
ColorComponentProps {
/** Shorthand for Header.Description. */
description?: ShorthandValue

Expand All @@ -40,7 +42,7 @@ class Header extends UIComponent<Extendable<HeaderProps>, any> {
static displayName = 'Header'

static propTypes = {
...commonPropTypes.createCommon(),
...commonPropTypes.createCommon({ color: true }),
description: customPropTypes.itemShorthand,
textAlign: PropTypes.oneOf(['left', 'center', 'right', 'justified']),
}
Expand Down
6 changes: 4 additions & 2 deletions src/components/Header/HeaderDescription.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -27,7 +29,7 @@ class HeaderDescription extends UIComponent<Extendable<HeaderDescriptionProps>,
static displayName = 'HeaderDescription'

static propTypes = {
...commonPropTypes.createCommon(),
...commonPropTypes.createCommon({ color: true }),
}

static defaultProps = {
Expand Down
14 changes: 10 additions & 4 deletions src/themes/teams/components/Header/headerDescriptionStyles.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import * as _ from 'lodash'

import { pxToRem } from '../../utils'
import { ICSSInJSStyle } from '../../../types'
import { ICSSInJSStyle, ComponentSlotStylesInput } from '../../../types'
import { HeaderProps } from '../../../../components/Header/Header'
import { HeaderVariables } from './headerVariables'

export default {
root: ({ variables: v }): ICSSInJSStyle => ({
const headerStyles: ComponentSlotStylesInput<HeaderProps, HeaderVariables> = {
root: ({ props: p, variables: v }): ICSSInJSStyle => ({
display: 'block',
color: _.get(v.colors, p.color, v.color),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what we can do there, but this line looks very confusing 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed, but not sure what we can do either.. 😢

fontSize: pxToRem(22),
color: v.color,
fontWeight: 400,
}),
}

export default headerStyles
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
export default siteVariables => ({
color: siteVariables.gray04,
})
import { ColorValues } from '../../../types'
import { mapColorsToScheme } from '../../../../lib'

export interface HeaderDescriptionVariables {
colors: ColorValues<string>
color: string
}

export default (siteVariables: any): HeaderDescriptionVariables => {
const colorVariant = 500
return {
colors: mapColorsToScheme(siteVariables, colorVariant),
color: siteVariables.gray04,
}
}
19 changes: 13 additions & 6 deletions src/themes/teams/components/Header/headerStyles.ts
Original file line number Diff line number Diff line change
@@ -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<HeaderProps, HeaderVariables> = {
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
6 changes: 6 additions & 0 deletions src/themes/teams/components/Header/headerVariables.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import { ColorValues } from '../../../types'
import { mapColorsToScheme } from '../../../../lib'

export interface HeaderVariables {
colors: ColorValues<string>
color: string
descriptionColor: string
}

export default (siteVars: any): HeaderVariables => {
const colorVariant = 500
return {
colors: mapColorsToScheme(siteVars, colorVariant),
color: siteVars.black,
descriptionColor: undefined,
}
Expand Down