diff --git a/CHANGELOG.md b/CHANGELOG.md index 84684eb453..2a58b930da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Add and export compose icons in Teams theme @joheredi ([#639](https://github.com/stardust-ui/react/pull/639)) - Add `menu` prop to `MenuItem` @mnajdova ([#539](https://github.com/stardust-ui/react/pull/539)) - Enable RTL for `FocusZone` @sophieH29 ([#646](https://github.com/stardust-ui/react/pull/646)) +- Add `color` prop to `Segment` component @Bugaa92 ([#632](https://github.com/stardust-ui/react/pull/632)) ### Documentation - Add more accessibility descriptions to components and behaviors @jurokapsiar ([#648](https://github.com/stardust-ui/react/pull/648)) diff --git a/docs/src/examples/components/Segment/Variations/SegmentExampleColor.shorthand.tsx b/docs/src/examples/components/Segment/Variations/SegmentExampleColor.shorthand.tsx new file mode 100644 index 0000000000..5609b9f606 --- /dev/null +++ b/docs/src/examples/components/Segment/Variations/SegmentExampleColor.shorthand.tsx @@ -0,0 +1,15 @@ +import * as React from 'react' +import * as _ from 'lodash' +import { Segment, ProviderConsumer } from '@stardust-ui/react' + +const SegmentExampleColor = () => ( + + _.keys({ ...emphasisColors, ...naturalColors }).map(color => ( + + )) + } + /> +) + +export default SegmentExampleColor diff --git a/docs/src/examples/components/Segment/Variations/SegmentExampleColor.tsx b/docs/src/examples/components/Segment/Variations/SegmentExampleColor.tsx new file mode 100644 index 0000000000..e6ec7bfff9 --- /dev/null +++ b/docs/src/examples/components/Segment/Variations/SegmentExampleColor.tsx @@ -0,0 +1,17 @@ +import * as React from 'react' +import * as _ from 'lodash' +import { Segment, ProviderConsumer } from '@stardust-ui/react' + +const SegmentExampleColor = () => ( + + _.keys({ ...emphasisColors, ...naturalColors }).map(color => ( + + {_.startCase(color)} + + )) + } + /> +) + +export default SegmentExampleColor diff --git a/docs/src/examples/components/Segment/Variations/SegmentExampleInverted.shorthand.tsx b/docs/src/examples/components/Segment/Variations/SegmentExampleInverted.shorthand.tsx index 8127ca0feb..0dc2e78f56 100644 --- a/docs/src/examples/components/Segment/Variations/SegmentExampleInverted.shorthand.tsx +++ b/docs/src/examples/components/Segment/Variations/SegmentExampleInverted.shorthand.tsx @@ -3,9 +3,9 @@ import { Segment } from '@stardust-ui/react' const SegmentExampleInvertedShorthand = () => (
- +
- +
) diff --git a/docs/src/examples/components/Segment/Variations/SegmentExampleInverted.tsx b/docs/src/examples/components/Segment/Variations/SegmentExampleInverted.tsx index 60267632ad..733ead610f 100644 --- a/docs/src/examples/components/Segment/Variations/SegmentExampleInverted.tsx +++ b/docs/src/examples/components/Segment/Variations/SegmentExampleInverted.tsx @@ -3,10 +3,10 @@ import { Segment } from '@stardust-ui/react' const SegmentExampleInvertedShorthand = () => (
- Colored segment. + Colored segment.
- - Colored inverted segment + + Colored inverted segment.
) diff --git a/docs/src/examples/components/Segment/Variations/index.tsx b/docs/src/examples/components/Segment/Variations/index.tsx index e1c24e5602..3aae84cc3b 100644 --- a/docs/src/examples/components/Segment/Variations/index.tsx +++ b/docs/src/examples/components/Segment/Variations/index.tsx @@ -9,6 +9,11 @@ const Variations = () => ( description="A segment can have its colors inverted for contrast." examplePath="components/Segment/Variations/SegmentExampleInverted" /> + ) diff --git a/src/themes/teams/components/Segment/segmentStyles.ts b/src/themes/teams/components/Segment/segmentStyles.ts index bd814100a9..a15b1a2498 100644 --- a/src/themes/teams/components/Segment/segmentStyles.ts +++ b/src/themes/teams/components/Segment/segmentStyles.ts @@ -1,24 +1,25 @@ +import * as _ from 'lodash' + import { SegmentProps } from '../../../../components/Segment/Segment' import { ICSSInJSStyle, ComponentSlotStylesInput } from '../../../types' import { SegmentVariables } from './segmentVariables' const segmentStyles: ComponentSlotStylesInput = { root: ({ props: p, variables: v }): ICSSInJSStyle => { - const color = p.color || v.color + const segmentColor = _.get(v.colors, p.color) + return { padding: v.padding, - background: v.background, + borderTop: `2px solid transparent`, borderRadius: v.borderRadius, - boxShadow: '0 1px 1px 1px rgba(34,36,38,.15)', - ...(color && - (p.inverted - ? { - background: color, - color: '#eee', - } - : { - borderTop: `2px solid ${color}`, - })), + boxShadow: `0 1px 1px 1px ${v.boxShadowColor}`, + color: v.color, + backgroundColor: v.backgroundColor, + borderColor: segmentColor, + ...(p.inverted && { + color: v.backgroundColor, + backgroundColor: segmentColor || v.color, + }), } }, } diff --git a/src/themes/teams/components/Segment/segmentVariables.ts b/src/themes/teams/components/Segment/segmentVariables.ts index d49881e3f6..ebb3fb80bf 100644 --- a/src/themes/teams/components/Segment/segmentVariables.ts +++ b/src/themes/teams/components/Segment/segmentVariables.ts @@ -1,17 +1,24 @@ -import { ComponentVariablesPrepared } from '@stardust-ui/react' +import { ColorValues } from '../../../types' +import { mapColorsToScheme } from '../../../../lib' export interface SegmentVariables { - padding: string - background: string - borderRadius: string + colors: ColorValues color: string + backgroundColor: string + padding: string + borderRadius: string | number + boxShadowColor: string } -const segmentVariables: ComponentVariablesPrepared = siteVariables => ({ - padding: '1em', - background: siteVariables.bodyBackground, - borderRadius: 0, - color: undefined, -}) +export default (siteVariables): SegmentVariables => { + const colorVariant = 500 -export default segmentVariables + return { + colors: mapColorsToScheme(siteVariables, colorVariant), + color: siteVariables.black, + backgroundColor: siteVariables.bodyBackground, + padding: '1em', + borderRadius: 0, + boxShadowColor: 'rgba(34,36,38,.15)', + } +}