From 65b3e2e43d1423d31bf866cc8f3e5c36f2e3334b Mon Sep 17 00:00:00 2001 From: Maria Navarro Date: Fri, 29 Apr 2022 16:15:54 -0500 Subject: [PATCH] feat(docs): update colors page to use new layout --- .../docs/components/ColorCards/ColorCard.tsx | 84 +++++++++++ .../docs/components/ColorCards/ColorCards.tsx | 23 +++ .../components/ColorCards/availableColors.ts | 106 ++++++++++++++ packages/docs/components/ColorCards/index.ts | 2 + packages/docs/components/index.tsx | 1 + packages/docs/pages/colors.tsx | 138 ++++++++---------- 6 files changed, 278 insertions(+), 76 deletions(-) create mode 100644 packages/docs/components/ColorCards/ColorCard.tsx create mode 100644 packages/docs/components/ColorCards/ColorCards.tsx create mode 100644 packages/docs/components/ColorCards/availableColors.ts create mode 100644 packages/docs/components/ColorCards/index.ts diff --git a/packages/docs/components/ColorCards/ColorCard.tsx b/packages/docs/components/ColorCards/ColorCard.tsx new file mode 100644 index 000000000..72e84e94a --- /dev/null +++ b/packages/docs/components/ColorCards/ColorCard.tsx @@ -0,0 +1,84 @@ +import { Flex, Link, Small, Text } from '@bigcommerce/big-design'; +import React, { useContext } from 'react'; +import styled, { ThemeContext } from 'styled-components'; + +import { ColorDetails } from './availableColors'; + +const StyledColor = styled(Flex)` + height: ${({ theme }) => theme.helpers.remCalc(160)}; + width: ${({ theme }) => theme.helpers.remCalc(184)}; + border-radius: ${({ theme }) => theme.borderRadius.normal}; +`; + +interface ColorCardProps { + colorCard: ColorDetails; +} + +const ColorCard: React.FC = ({ colorCard }) => { + const { colors } = useContext(ThemeContext); + const { description } = colorCard; + const colorValue = colors[colorCard.name]; + const hasHexColor = colorValue.startsWith('#'); + const hasSecondaryTextColor = colorCard.secondaryTextColor !== undefined; + + const renderContrast = () => { + if (hasSecondaryTextColor) { + return ( + + + {colorCard.contrast} + + + {colorCard.contrast} + + + ); + } + + return ( + + {colorCard.contrast} + + ); + }; + + return ( + + + {getColorLabel(colorCard.name)} + + + {description && ( + + {description?.text}{' '} + {description?.href && ( + + Read more + + )} + + )} + + {hasHexColor && ( + + + {colorValue} + + + {renderContrast()} + + )} + + ); +}; + +function getColorLabel(color: string) { + return color.includes('40') ? `${color} / ${color.replace('40', '')}` : color; +} + +export default ColorCard; diff --git a/packages/docs/components/ColorCards/ColorCards.tsx b/packages/docs/components/ColorCards/ColorCards.tsx new file mode 100644 index 000000000..a09b77dad --- /dev/null +++ b/packages/docs/components/ColorCards/ColorCards.tsx @@ -0,0 +1,23 @@ +import { Flex, FlexItem } from '@bigcommerce/big-design'; +import React from 'react'; + +import { ColorDetails } from './availableColors'; +import ColorCard from './ColorCard'; + +interface ColorCardsProps { + colorCards: ColorDetails[]; +} + +export const ColorCards: React.FC = ({ colorCards }) => ( + + {colorCards.map((colorCard) => { + return ( + + + + ); + })} + +); + +export default ColorCards; diff --git a/packages/docs/components/ColorCards/availableColors.ts b/packages/docs/components/ColorCards/availableColors.ts new file mode 100644 index 000000000..48e62d863 --- /dev/null +++ b/packages/docs/components/ColorCards/availableColors.ts @@ -0,0 +1,106 @@ +import { ThemeInterface } from '@bigcommerce/big-design-theme'; + +type Colors = ThemeInterface['colors']; +type Color = keyof Colors; + +export interface ColorDetails { + contrast?: 'AAA' | 'AA' | 'A'; + description?: { + text: string; + href?: string; + }; + name: Color; + secondaryTextColor?: Color; + textColor: Color; +} + +export const accentColors: ColorDetails[] = [ + { contrast: 'AA', name: 'primary40', textColor: 'white' }, + { contrast: 'AAA', name: 'primary10', textColor: 'secondary70' }, + { contrast: 'AAA', name: 'primary20', textColor: 'secondary70' }, + { contrast: 'AAA', name: 'primary30', textColor: 'secondary70' }, + { contrast: 'AA', name: 'primary50', textColor: 'white' }, + { contrast: 'AAA', name: 'primary60', textColor: 'white' }, + { contrast: 'AAA', name: 'primary70', textColor: 'white' }, +]; + +export const typeColors: ColorDetails[] = [ + { contrast: 'AAA', name: 'secondary70', textColor: 'white' }, + { contrast: 'AA', name: 'secondary60', textColor: 'white' }, + { contrast: 'A', name: 'secondary50', secondaryTextColor: 'secondary70', textColor: 'white' }, + { contrast: 'AAA', name: 'white', textColor: 'secondary70' }, +]; + +export const fillsAndStrokesColors: ColorDetails[] = [ + { contrast: 'AAA', name: 'white', textColor: 'secondary70' }, + { contrast: 'AAA', name: 'secondary10', textColor: 'secondary70' }, + { contrast: 'AA', name: 'secondary20', textColor: 'secondary70' }, + { contrast: 'A', name: 'secondary30', textColor: 'secondary70' }, + { contrast: 'A', name: 'secondary40', textColor: 'secondary70' }, +]; + +export const statusSuccessColors: ColorDetails[] = [ + { contrast: 'AA', name: 'success40', textColor: 'white' }, + { contrast: 'AAA', name: 'success10', textColor: 'secondary70' }, + { contrast: 'AAA', name: 'success20', textColor: 'secondary70' }, + { contrast: 'AAA', name: 'success30', textColor: 'secondary70' }, + { contrast: 'AA', name: 'success50', textColor: 'white' }, + { contrast: 'AAA', name: 'success60', textColor: 'white' }, + { contrast: 'AAA', name: 'success70', textColor: 'white' }, +]; + +export const statusDangerColors: ColorDetails[] = [ + { contrast: 'AA', name: 'danger40', textColor: 'white' }, + { contrast: 'AAA', name: 'danger10', textColor: 'secondary70' }, + { contrast: 'AAA', name: 'danger20', textColor: 'secondary70' }, + { contrast: 'AAA', name: 'danger30', textColor: 'secondary70' }, + { contrast: 'AA', name: 'danger50', textColor: 'white' }, + { contrast: 'AAA', name: 'danger60', textColor: 'white' }, + { contrast: 'AAA', name: 'danger70', textColor: 'white' }, +]; + +export const statusWarningColors: ColorDetails[] = [ + { contrast: 'AA', name: 'warning40', textColor: 'secondary70' }, + { contrast: 'AAA', name: 'warning10', textColor: 'secondary70' }, + { contrast: 'AAA', name: 'warning20', textColor: 'secondary70' }, + { contrast: 'AAA', name: 'warning30', textColor: 'secondary70' }, + { contrast: 'AA', name: 'warning50', textColor: 'secondary70' }, + { contrast: 'AAA', name: 'warning60', textColor: 'secondary70' }, + { contrast: 'A', name: 'warning70', secondaryTextColor: 'white', textColor: 'secondary70' }, +]; + +export const additionalColors: ColorDetails[] = [ + { + description: { + text: 'Current value of an element’s color property.', + href: 'https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#currentcolor_keyword', + }, + name: 'currentColor', + textColor: 'white', + }, + { + description: { + text: 'Element inherits value from parent element.', + href: 'https://developer.mozilla.org/en-US/docs/Web/CSS/inherit', + }, + name: 'inherit', + textColor: 'secondary70', + }, + { + description: { + text: 'Renders background behind colored item completely visible.', + href: 'https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#transparent_keyword', + }, + name: 'transparent', + textColor: 'secondary70', + }, + { + contrast: 'AA', + description: { + text: 'Used by BigCommerce branded assets.', + href: '', + }, + name: 'brand', + textColor: 'white', + }, +]; diff --git a/packages/docs/components/ColorCards/index.ts b/packages/docs/components/ColorCards/index.ts new file mode 100644 index 000000000..d7655d02f --- /dev/null +++ b/packages/docs/components/ColorCards/index.ts @@ -0,0 +1,2 @@ +export * from './availableColors'; +export * from './ColorCards'; diff --git a/packages/docs/components/index.tsx b/packages/docs/components/index.tsx index 1f083e254..897aa6407 100644 --- a/packages/docs/components/index.tsx +++ b/packages/docs/components/index.tsx @@ -2,6 +2,7 @@ export * from './BetaRibbon'; export * from './Code'; export * from './CodePreview'; export * from './CodeSnippet'; +export * from './ColorCards'; export * from './Collapsible'; export * from './ContentRoutingTabs'; export * from './GuidelinesTable'; diff --git a/packages/docs/pages/colors.tsx b/packages/docs/pages/colors.tsx index 034ffa5ef..09c6f6c43 100644 --- a/packages/docs/pages/colors.tsx +++ b/packages/docs/pages/colors.tsx @@ -1,91 +1,77 @@ -import { Box, Flex, H1, Panel, Text } from '@bigcommerce/big-design'; -import { ThemeInterface } from '@bigcommerce/big-design-theme'; -import React, { useContext } from 'react'; -import styled, { ThemeContext } from 'styled-components'; +import { H1, Panel, Text } from '@bigcommerce/big-design'; +import React, { Fragment } from 'react'; -import { CodePreview, PageNavigation } from '../components'; +import { ColorCards } from '../components'; +import { + accentColors, + additionalColors, + fillsAndStrokesColors, + statusDangerColors, + statusSuccessColors, + statusWarningColors, + typeColors, +} from '../components/ColorCards'; -const COLORS_TO_OMIT = ['primary', 'secondary', 'danger', 'warning', 'success']; -type Colors = ThemeInterface['colors']; -type Color = keyof Colors; +const ColorsPage = () => { + return ( + <> +

Colors

-const StyledColor = styled(Box)` - height: ${({ theme }) => theme.helpers.remCalc(30)}; - width: ${({ theme }) => theme.helpers.remCalc(300)}; -`; + + + The BigDesign color system has five palette types named semantically for their use across the application. The + color system is derived from the BigCommerce brand and provides a consistent user experience for our merchants + and partners. + + + BigDesign uses color tokens to manage colors within each palette and are named for their role or hierarchy in + the palette. Color tokens improve communication between design and development and establish an organized use + of color in the BigCommerce application. + + -const ColorsPage = () => { - const { colors } = useContext(ThemeContext); + + + Accent colors are used for interactions or to denote an interaction has taken place. Common accent uses + include buttons, icons, navigation, links and selections. Use accent colors sparingly to avoid confusion. + - const items = [ - { - id: 'examples', - title: 'Examples', - render: () => ( - <> - - Colors can be used directly on some of our components that expect a color as a prop. + + - - {/* jsx-to-string:start */} - - Box example - - {/* jsx-to-string:end */} - - - - You can also use the colors directly from the theme to style other components, for example: + + Type colors are used for text, iconography, and foreground elements in BigDesign interfaces. - - {/* jsx-to-string:start */} - {function Example() { - const StyledBox = styled(Box)(({ theme }) => ({ - backgroundColor: theme.colors.secondary20, - padding: theme.spacing.medium, - })); + + - return StyledBox Example; - }} - {/* jsx-to-string:end */} - - - - ), - }, - { - id: 'colors', - title: 'Available colors', - render: () => ( - - - {getFilteredColors(colors).map((color) => ( - - - {getColorLabel(color)} - - ))} - - - ), - }, - ]; + + + Fills and strokes are used as the building blocks of BigDesign interfaces. They are used in combination to + create layering of backgrounds, panels, overlays and hierarchical UI elements. + - return ( - <> -

Colors

+ +
+ + + + Status colors are reserved to indicate a system status such as errors, success or warnings. These colors + should be used sparingly and only for imformative purposes. + + + + + + - + + Additional colors exist in the BigDesign color palette for edge cases and BigCommerce branding. + + + ); }; -function getFilteredColors(colors: Colors) { - return Object.keys(colors).filter((color) => !COLORS_TO_OMIT.includes(color)); -} - -function getColorLabel(color: string) { - return color.includes('40') ? `${color} / ${color.replace('40', '')}` : color; -} - export default ColorsPage;