diff --git a/docs/src/examples/components/Divider/Variations/DividerExampleColor.shorthand.tsx b/docs/src/examples/components/Divider/Variations/DividerExampleColor.shorthand.tsx new file mode 100644 index 0000000000..294d638169 --- /dev/null +++ b/docs/src/examples/components/Divider/Variations/DividerExampleColor.shorthand.tsx @@ -0,0 +1,27 @@ +import _ from 'lodash' +import React from 'react' +import { Divider } from '@stardust-ui/react' + +const colors = [ + 'primary', + 'secondary', + 'red', + 'orange', + 'yellow', + 'olive', + 'green', + 'teal', + 'blue', + 'violet', + 'purple', + 'pink', + 'brown', + 'grey', + 'black', + 'white', +] + +const DividerExampleColorShorthand = () => + _.map(colors, color => ) + +export default DividerExampleColorShorthand diff --git a/docs/src/examples/components/Divider/Variations/DividerExampleColor.tsx b/docs/src/examples/components/Divider/Variations/DividerExampleColor.tsx new file mode 100644 index 0000000000..1bef9bfd51 --- /dev/null +++ b/docs/src/examples/components/Divider/Variations/DividerExampleColor.tsx @@ -0,0 +1,31 @@ +import _ from 'lodash' +import React from 'react' +import { Divider } from '@stardust-ui/react' + +const colors = [ + 'primary', + 'secondary', + 'red', + 'orange', + 'yellow', + 'olive', + 'green', + 'teal', + 'blue', + 'violet', + 'purple', + 'pink', + 'brown', + 'grey', + 'black', + 'white', +] + +const DividerExampleColor = () => + _.map(colors, color => ( + + {_.startCase(color)} + + )) + +export default DividerExampleColor diff --git a/docs/src/examples/components/Divider/Variations/DividerExampleSize.shorthand.tsx b/docs/src/examples/components/Divider/Variations/DividerExampleSize.shorthand.tsx index 4dafd3f733..3b9f6e3144 100644 --- a/docs/src/examples/components/Divider/Variations/DividerExampleSize.shorthand.tsx +++ b/docs/src/examples/components/Divider/Variations/DividerExampleSize.shorthand.tsx @@ -2,11 +2,11 @@ import _ from 'lodash' import React from 'react' import { Divider } from '@stardust-ui/react' -const DividerExampleSize = () => +const DividerExampleSizeShorthand = () => _.times(11, i => { const size = i return }) -export default DividerExampleSize +export default DividerExampleSizeShorthand diff --git a/docs/src/examples/components/Divider/Variations/index.tsx b/docs/src/examples/components/Divider/Variations/index.tsx index b5eb43aba6..43151f0cdc 100644 --- a/docs/src/examples/components/Divider/Variations/index.tsx +++ b/docs/src/examples/components/Divider/Variations/index.tsx @@ -4,6 +4,11 @@ import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' const Variations = () => ( + , any> { static className = 'ui-divider' static propTypes = { + /** An element type to render as (string or function). */ as: customPropTypes.as, /** @@ -40,13 +42,36 @@ class Divider extends UIComponent, any> { /** Additional CSS class name(s) to apply. */ className: PropTypes.string, + /** A divider can have different colors. */ + color: PropTypes.oneOfType([ + PropTypes.oneOf([ + 'primary', + 'secondary', + 'red', + 'orange', + 'yellow', + 'olive', + 'green', + 'teal', + 'blue', + 'violet', + 'purple', + 'pink', + 'brown', + 'grey', + 'black', + 'white', + ]), + PropTypes.string, + ]), + /** Shorthand for primary content. */ content: customPropTypes.contentShorthand, /** A divider can be fitted, without any space above or below it. */ fitted: PropTypes.bool, - /** Size multiplier (default 0) * */ + /** Size multiplier (default 0). */ size: PropTypes.number, /** A Divider can be formatted to show different levels of emphasis. */ @@ -55,7 +80,7 @@ class Divider extends UIComponent, any> { /** A divider can appear more important and draw the user's attention. */ important: PropTypes.bool, - /** Additional CSS styles to apply to the component instance. */ + /** Additional CSS styles to apply to the component instance. */ styles: PropTypes.oneOfType([PropTypes.object, PropTypes.func]), /** Override for theme site variables to allow modifications of component styling via themes. */ diff --git a/src/lib/getColorValue.ts b/src/lib/getColorValue.ts new file mode 100644 index 0000000000..2c547993cd --- /dev/null +++ b/src/lib/getColorValue.ts @@ -0,0 +1,5 @@ +import { ColorPalette, ComponentColors } from '@stardust-ui/react' + +const getColorValue = (colors: ColorPalette, color: ComponentColors) => colors[color] || color + +export default getColorValue diff --git a/src/lib/index.ts b/src/lib/index.ts index 8a06f59b93..bffd22345f 100644 --- a/src/lib/index.ts +++ b/src/lib/index.ts @@ -11,6 +11,7 @@ export * from './factories' export { default as callable } from './callable' export { default as constants } from './constants' export { default as getClasses } from './getClasses' +export { default as getColorValue } from './getColorValue' export { default as getElementType } from './getElementType' export { default as getUnhandledProps } from './getUnhandledProps' export { default as mergeThemes } from './mergeThemes' diff --git a/src/themes/teams-dark/components/Divider/dividerVariables.ts b/src/themes/teams-dark/components/Divider/dividerVariables.ts index 6178d5f597..12e49bb143 100644 --- a/src/themes/teams-dark/components/Divider/dividerVariables.ts +++ b/src/themes/teams-dark/components/Divider/dividerVariables.ts @@ -2,6 +2,8 @@ import { DividerVariables } from '../../../teams/components/Divider/dividerVaria import { Partial } from 'types/utils' export default (siteVars: any): Partial => ({ - primaryColor: siteVars.brand06, + colors: { + primary: siteVars.brand06, + }, textColor: siteVars.gray02, }) diff --git a/src/themes/teams-high-contrast/components/Divider/dividerVariables.ts b/src/themes/teams-high-contrast/components/Divider/dividerVariables.ts index 193a92452d..7d3217de75 100644 --- a/src/themes/teams-high-contrast/components/Divider/dividerVariables.ts +++ b/src/themes/teams-high-contrast/components/Divider/dividerVariables.ts @@ -2,7 +2,9 @@ import { DividerVariables } from '../../../teams/components/Divider/dividerVaria import { Partial } from 'types/utils' export default (siteVars: any): Partial => ({ + colors: { + primary: siteVars.white, + }, dividerColor: siteVars.white, textColor: siteVars.white, - primaryColor: siteVars.white, }) diff --git a/src/themes/teams/components/Divider/dividerStyles.ts b/src/themes/teams/components/Divider/dividerStyles.ts index 5dae860af6..98e7bf3606 100644 --- a/src/themes/teams/components/Divider/dividerStyles.ts +++ b/src/themes/teams/components/Divider/dividerStyles.ts @@ -1,4 +1,4 @@ -import { childrenExist, pxToRem } from '../../../../lib' +import { childrenExist, getColorValue, pxToRem } from '../../../../lib' import { ComponentSlotStylesInput, ICSSInJSStyle, ICSSPseudoElementStyle } from '../../../types' import { DividerPropsWithDefaults } from '../../../../components/Divider/Divider' @@ -7,18 +7,21 @@ const dividerBorderStyle = (size, color): ICSSInJSStyle => ({ background: color, }) -const beforeAndAfter = (size, type, variables): ICSSPseudoElementStyle => ({ +const beforeAndAfter = (color, size, type, variables): ICSSPseudoElementStyle => ({ content: '""', flex: 1, ...dividerBorderStyle(size, variables.dividerColor), ...(type === 'primary' && { - ...dividerBorderStyle(size, variables.primaryColor), + ...dividerBorderStyle(size, variables.colors.primary), + }), + ...(color && { + ...dividerBorderStyle(size, getColorValue(variables.colors, color)), }), }) const dividerStyles: ComponentSlotStylesInput = { root: ({ props, variables }): ICSSInJSStyle => { - const { children, fitted, size, type, important, content } = props + const { children, color, fitted, size, type, important, content } = props return { color: variables.textColor, display: 'flex', @@ -28,7 +31,10 @@ const dividerStyles: ComponentSlotStylesInput = { paddingBottom: variables.dividerPadding, }), ...(type === 'primary' && { - color: variables.primaryColor, + color: variables.colors.primary, + }), + ...(color && { + color: getColorValue(variables.colors, color), }), ...(important && { fontWeight: variables.importantFontWeight, @@ -39,17 +45,17 @@ const dividerStyles: ComponentSlotStylesInput = { fontSize: pxToRem(12 + size), lineHeight: variables.textLineHeight, '::before': { - ...beforeAndAfter(size, type, variables), + ...beforeAndAfter(color, size, type, variables), marginRight: pxToRem(20), }, '::after': { - ...beforeAndAfter(size, type, variables), + ...beforeAndAfter(color, size, type, variables), marginLeft: pxToRem(20), }, } : { '::before': { - ...beforeAndAfter(size, type, variables), + ...beforeAndAfter(color, size, type, variables), }, }), } diff --git a/src/themes/teams/components/Divider/dividerVariables.ts b/src/themes/teams/components/Divider/dividerVariables.ts index b363fbd31f..1120c2c36d 100644 --- a/src/themes/teams/components/Divider/dividerVariables.ts +++ b/src/themes/teams/components/Divider/dividerVariables.ts @@ -1,23 +1,22 @@ import { pxToRem } from '../../../../lib' +import { ColorPalette } from '../../../types' export interface DividerVariables { + colors: Partial dividerColor: string textColor: string textFontSize: string textLineHeight: string - primaryColor: string importantFontWeight: string dividerPadding: string } -export default (siteVars: any): DividerVariables => { - return { - dividerColor: siteVars.gray09, - textColor: siteVars.gray03, - textFontSize: siteVars.fontSizeSmall, - textLineHeight: siteVars.lineHeightSmall, - primaryColor: siteVars.brand, - importantFontWeight: siteVars.fontWeightBold, - dividerPadding: pxToRem(4), - } -} +export default (siteVars: any): DividerVariables => ({ + colors: siteVars.colors, + dividerColor: siteVars.gray09, + textColor: siteVars.gray03, + textFontSize: siteVars.fontSizeSmall, + textLineHeight: siteVars.lineHeightSmall, + importantFontWeight: siteVars.fontWeightBold, + dividerPadding: pxToRem(4), +}) diff --git a/src/themes/teams/siteVariables.ts b/src/themes/teams/siteVariables.ts index 78703a3bab..e8a6211b9f 100644 --- a/src/themes/teams/siteVariables.ts +++ b/src/themes/teams/siteVariables.ts @@ -1,4 +1,5 @@ import { pxToRem } from '../../lib' +import { ColorPalette } from '../types' // // VARIABLES @@ -38,6 +39,26 @@ export const yellow = '#F8D22A' export const green = '#92C353' export const green04 = '#237b4b' +export const colors: ColorPalette = { + primary: brand, + secondary: gray02, // ?? + + black, + blue: 'blue', // ?? + brown: 'brown', // ?? + green, + gray: gray02, // ?? + olive: 'olive', // ?? + orange: orange04, + pink: magenta, // ?? + purple: orchid, // ?? + red, + teal: 'teal', // ?? + violet: brand02, // ?? + white, + yellow, +} + // // SHADOW LEVELS // diff --git a/src/themes/types.ts b/src/themes/types.ts index 1392d18259..0ed806f120 100644 --- a/src/themes/types.ts +++ b/src/themes/types.ts @@ -312,6 +312,32 @@ export interface ThemeComponentVariablesPrepared { export interface Renderer extends FelaRenderer {} +// ======================================================== +// Colors +// ======================================================== + +export interface ColorPalette { + primary: string + secondary: string + + black: string + brown: string + blue: string + green: string + gray: string + olive: string + orange: string + pink: string + purple: string + teal: string + red: string + violet: string + white: string + yellow: string +} + +export type ComponentColors = keyof ColorPalette | string + // ======================================================== // Fonts // ========================================================