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

Commit d5f5dc1

Browse files
author
Alexandru Buliga
authored
feat(segment): color prop (#632)
* feat(segment): color prop * changelog * fixed color again * simplified example * introduced fix to make segment inverted work without specifying color
1 parent e93076c commit d5f5dc1

File tree

8 files changed

+74
-28
lines changed

8 files changed

+74
-28
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
3333
- Add and export compose icons in Teams theme @joheredi ([#639](https://github.com/stardust-ui/react/pull/639))
3434
- Add `menu` prop to `MenuItem` @mnajdova ([#539](https://github.com/stardust-ui/react/pull/539))
3535
- Enable RTL for `FocusZone` @sophieH29 ([#646](https://github.com/stardust-ui/react/pull/646))
36+
- Add `color` prop to `Segment` component @Bugaa92 ([#632](https://github.com/stardust-ui/react/pull/632))
3637

3738
### Documentation
3839
- Add more accessibility descriptions to components and behaviors @jurokapsiar ([#648](https://github.com/stardust-ui/react/pull/648))
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import * as React from 'react'
2+
import * as _ from 'lodash'
3+
import { Segment, ProviderConsumer } from '@stardust-ui/react'
4+
5+
const SegmentExampleColor = () => (
6+
<ProviderConsumer
7+
render={({ siteVariables: { emphasisColors, naturalColors } }) =>
8+
_.keys({ ...emphasisColors, ...naturalColors }).map(color => (
9+
<Segment key={color} color={color} content={_.startCase(color)} inverted />
10+
))
11+
}
12+
/>
13+
)
14+
15+
export default SegmentExampleColor
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import * as React from 'react'
2+
import * as _ from 'lodash'
3+
import { Segment, ProviderConsumer } from '@stardust-ui/react'
4+
5+
const SegmentExampleColor = () => (
6+
<ProviderConsumer
7+
render={({ siteVariables: { emphasisColors, naturalColors } }) =>
8+
_.keys({ ...emphasisColors, ...naturalColors }).map(color => (
9+
<Segment key={color} color={color} inverted>
10+
{_.startCase(color)}
11+
</Segment>
12+
))
13+
}
14+
/>
15+
)
16+
17+
export default SegmentExampleColor

docs/src/examples/components/Segment/Variations/SegmentExampleInverted.shorthand.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { Segment } from '@stardust-ui/react'
33

44
const SegmentExampleInvertedShorthand = () => (
55
<div>
6-
<Segment content="Colored segment." color="purple" />
6+
<Segment content="Colored segment." color="red" />
77
<br />
8-
<Segment inverted content="Colored inverted segment" color="purple" />
8+
<Segment inverted content="Colored inverted segment." color="red" />
99
</div>
1010
)
1111

docs/src/examples/components/Segment/Variations/SegmentExampleInverted.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { Segment } from '@stardust-ui/react'
33

44
const SegmentExampleInvertedShorthand = () => (
55
<div>
6-
<Segment color="purple">Colored segment.</Segment>
6+
<Segment color="red">Colored segment.</Segment>
77
<br />
8-
<Segment inverted color="purple">
9-
Colored inverted segment
8+
<Segment inverted color="red">
9+
Colored inverted segment.
1010
</Segment>
1111
</div>
1212
)

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ const Variations = () => (
99
description="A segment can have its colors inverted for contrast."
1010
examplePath="components/Segment/Variations/SegmentExampleInverted"
1111
/>
12+
<ComponentExample
13+
title="Color"
14+
description="A segment can have different colors."
15+
examplePath="components/Segment/Variations/SegmentExampleColor"
16+
/>
1217
</ExampleSection>
1318
)
1419

src/themes/teams/components/Segment/segmentStyles.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
1+
import * as _ from 'lodash'
2+
13
import { SegmentProps } from '../../../../components/Segment/Segment'
24
import { ICSSInJSStyle, ComponentSlotStylesInput } from '../../../types'
35
import { SegmentVariables } from './segmentVariables'
46

57
const segmentStyles: ComponentSlotStylesInput<SegmentProps, SegmentVariables> = {
68
root: ({ props: p, variables: v }): ICSSInJSStyle => {
7-
const color = p.color || v.color
9+
const segmentColor = _.get(v.colors, p.color)
10+
811
return {
912
padding: v.padding,
10-
background: v.background,
13+
borderTop: `2px solid transparent`,
1114
borderRadius: v.borderRadius,
12-
boxShadow: '0 1px 1px 1px rgba(34,36,38,.15)',
13-
...(color &&
14-
(p.inverted
15-
? {
16-
background: color,
17-
color: '#eee',
18-
}
19-
: {
20-
borderTop: `2px solid ${color}`,
21-
})),
15+
boxShadow: `0 1px 1px 1px ${v.boxShadowColor}`,
16+
color: v.color,
17+
backgroundColor: v.backgroundColor,
18+
borderColor: segmentColor,
19+
...(p.inverted && {
20+
color: v.backgroundColor,
21+
backgroundColor: segmentColor || v.color,
22+
}),
2223
}
2324
},
2425
}
Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
1-
import { ComponentVariablesPrepared } from '@stardust-ui/react'
1+
import { ColorValues } from '../../../types'
2+
import { mapColorsToScheme } from '../../../../lib'
23

34
export interface SegmentVariables {
4-
padding: string
5-
background: string
6-
borderRadius: string
5+
colors: ColorValues<string>
76
color: string
7+
backgroundColor: string
8+
padding: string
9+
borderRadius: string | number
10+
boxShadowColor: string
811
}
912

10-
const segmentVariables: ComponentVariablesPrepared = siteVariables => ({
11-
padding: '1em',
12-
background: siteVariables.bodyBackground,
13-
borderRadius: 0,
14-
color: undefined,
15-
})
13+
export default (siteVariables): SegmentVariables => {
14+
const colorVariant = 500
1615

17-
export default segmentVariables
16+
return {
17+
colors: mapColorsToScheme(siteVariables, colorVariant),
18+
color: siteVariables.black,
19+
backgroundColor: siteVariables.bodyBackground,
20+
padding: '1em',
21+
borderRadius: 0,
22+
boxShadowColor: 'rgba(34,36,38,.15)',
23+
}
24+
}

0 commit comments

Comments
 (0)