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

Commit fa78e86

Browse files
Alexandru Buligamanajdov
Alexandru Buliga
authored and
manajdov
committed
feat(header): header and header description color prop (#628)
* feat(header): header and header description color prop * changelog * fixed examples * addressed PR comments
1 parent 1d8e168 commit fa78e86

File tree

10 files changed

+99
-17
lines changed

10 files changed

+99
-17
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
1919

2020
### Features
2121
- Add `color` prop to `Text` component @Bugaa92 ([#597](https://github.com/stardust-ui/react/pull/597))
22+
- Add `color` prop to `Header` and `HeaderDescription` components @Bugaa92 ([#628](https://github.com/stardust-ui/react/pull/628))
2223

2324
<!--------------------------------[ v0.15.0 ]------------------------------- -->
2425
## [v0.15.0](https://github.com/stardust-ui/react/tree/v0.15.0) (2018-12-17)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import React from 'react'
2+
import _ from 'lodash'
3+
import { Header, ProviderConsumer } from '@stardust-ui/react'
4+
5+
const HeaderExampleColor = () => (
6+
<ProviderConsumer
7+
render={({ siteVariables: { emphasisColors, naturalColors } }) =>
8+
_.keys({ ...emphasisColors, ...naturalColors }).map(color => (
9+
<Header
10+
key={color}
11+
as="h4"
12+
color={color}
13+
content={_.startCase(color)}
14+
description={{ content: `Description of ${_.lowerCase(color)} color`, color }}
15+
/>
16+
))
17+
}
18+
/>
19+
)
20+
21+
export default HeaderExampleColor
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from 'react'
2+
import _ from 'lodash'
3+
import { Header, ProviderConsumer } from '@stardust-ui/react'
4+
5+
const HeaderExampleColor = () => (
6+
<ProviderConsumer
7+
render={({ siteVariables: { emphasisColors, naturalColors } }) =>
8+
_.keys({ ...emphasisColors, ...naturalColors }).map(color => (
9+
<Header key={color} as="h4" color={color}>
10+
{_.startCase(color)}
11+
<Header.Description color={color}>
12+
{`Description of ${_.lowerCase(color)} color`}
13+
</Header.Description>
14+
</Header>
15+
))
16+
}
17+
/>
18+
)
19+
20+
export default HeaderExampleColor

docs/src/examples/components/Header/Variations/index.tsx

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ const Variations = () => (
1919
description="Headers may be aligned to the left, right, center or be justified."
2020
examplePath="components/Header/Variations/HeaderExampleTextAlign"
2121
/>
22+
<ComponentExample
23+
title="Color"
24+
description="Headers and descriptions can have colors."
25+
examplePath="components/Header/Variations/HeaderExampleColor"
26+
/>
2227
</ExampleSection>
2328
)
2429

src/components/Header/Header.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@ import {
99
ChildrenComponentProps,
1010
ContentComponentProps,
1111
commonPropTypes,
12+
ColorComponentProps,
1213
} from '../../lib'
1314
import HeaderDescription from './HeaderDescription'
1415
import { Extendable, ShorthandValue } from '../../../types/utils'
1516

1617
export interface HeaderProps
1718
extends UIComponentProps,
1819
ChildrenComponentProps,
19-
ContentComponentProps {
20+
ContentComponentProps,
21+
ColorComponentProps {
2022
/** Shorthand for Header.Description. */
2123
description?: ShorthandValue
2224

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

4244
static propTypes = {
43-
...commonPropTypes.createCommon(),
45+
...commonPropTypes.createCommon({ color: true }),
4446
description: customPropTypes.itemShorthand,
4547
textAlign: PropTypes.oneOf(['left', 'center', 'right', 'justified']),
4648
}

src/components/Header/HeaderDescription.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ import {
88
ChildrenComponentProps,
99
ContentComponentProps,
1010
commonPropTypes,
11+
ColorComponentProps,
1112
} from '../../lib'
1213
import { Extendable } from '../../../types/utils'
1314

1415
export interface HeaderDescriptionProps
1516
extends UIComponentProps,
1617
ChildrenComponentProps,
17-
ContentComponentProps {}
18+
ContentComponentProps,
19+
ColorComponentProps {}
1820

1921
/**
2022
* A header's description provides more detailed information.
@@ -27,7 +29,7 @@ class HeaderDescription extends UIComponent<Extendable<HeaderDescriptionProps>,
2729
static displayName = 'HeaderDescription'
2830

2931
static propTypes = {
30-
...commonPropTypes.createCommon(),
32+
...commonPropTypes.createCommon({ color: true }),
3133
}
3234

3335
static defaultProps = {
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1+
import * as _ from 'lodash'
2+
13
import { pxToRem } from '../../utils'
2-
import { ICSSInJSStyle } from '../../../types'
4+
import { ICSSInJSStyle, ComponentSlotStylesInput } from '../../../types'
5+
import { HeaderDescriptionProps } from '../../../../components/Header/HeaderDescription'
6+
import { HeaderDescriptionVariables } from './headerDescriptionVariables'
37

4-
export default {
5-
root: ({ variables: v }): ICSSInJSStyle => ({
8+
const headerStyles: ComponentSlotStylesInput<HeaderDescriptionProps, HeaderDescriptionVariables> = {
9+
root: ({ props: p, variables: v }): ICSSInJSStyle => ({
610
display: 'block',
11+
color: _.get(v.colors, p.color, v.color),
712
fontSize: pxToRem(22),
8-
color: v.color,
913
fontWeight: 400,
1014
}),
1115
}
16+
17+
export default headerStyles
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1-
export default siteVariables => ({
2-
color: siteVariables.gray04,
3-
})
1+
import { ColorValues } from '../../../types'
2+
import { mapColorsToScheme } from '../../../../lib'
3+
4+
export interface HeaderDescriptionVariables {
5+
colors: ColorValues<string>
6+
color: string
7+
}
8+
9+
export default (siteVariables: any): HeaderDescriptionVariables => {
10+
const colorVariant = 500
11+
return {
12+
colors: mapColorsToScheme(siteVariables, colorVariant),
13+
color: siteVariables.gray04,
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1-
import { ICSSInJSStyle } from '../../../types'
1+
import * as _ from 'lodash'
2+
import { TextAlignProperty } from 'csstype'
23

3-
export default {
4-
root: ({ props, variables: v }): ICSSInJSStyle => ({
5-
color: v.color,
6-
textAlign: props.textAlign,
4+
import { ICSSInJSStyle, ComponentSlotStylesInput } from '../../../types'
5+
import { HeaderProps } from '../../../../components/Header/Header'
6+
import { HeaderVariables } from './headerVariables'
7+
8+
const headerStyles: ComponentSlotStylesInput<HeaderProps, HeaderVariables> = {
9+
root: ({ props: p, variables: v }): ICSSInJSStyle => ({
710
display: 'block',
8-
...(props.description && { marginBottom: 0 }),
11+
color: _.get(v.colors, p.color, v.color),
12+
textAlign: p.textAlign as TextAlignProperty,
13+
...(p.description && { marginBottom: 0 }),
914
}),
1015
}
16+
17+
export default headerStyles

src/themes/teams/components/Header/headerVariables.ts

+6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1+
import { ColorValues } from '../../../types'
2+
import { mapColorsToScheme } from '../../../../lib'
3+
14
export interface HeaderVariables {
5+
colors: ColorValues<string>
26
color: string
37
descriptionColor: string
48
}
59

610
export default (siteVars: any): HeaderVariables => {
11+
const colorVariant = 500
712
return {
13+
colors: mapColorsToScheme(siteVars, colorVariant),
814
color: siteVars.black,
915
descriptionColor: undefined,
1016
}

0 commit comments

Comments
 (0)