diff --git a/package-lock.json b/package-lock.json index a67edd9d39..633392e64b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7809,27 +7809,6 @@ "@types/tern": "*" } }, - "node_modules/@types/color": { - "version": "3.0.3", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/color-convert": "*" - } - }, - "node_modules/@types/color-convert": { - "version": "2.0.0", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/color-name": "*" - } - }, - "node_modules/@types/color-name": { - "version": "1.1.1", - "dev": true, - "license": "MIT" - }, "node_modules/@types/common-tags": { "version": "1.8.1", "license": "MIT" @@ -39663,7 +39642,6 @@ "analytics-node": "^6.0.0", "axios": "^0.27.2", "classnames": "^2.3.1", - "color": "^4.2.3", "gatsby": "^4.23.1", "gatsby-plugin-manifest": "^4.17.0", "gatsby-plugin-mdx": "^3.17.0", @@ -39700,7 +39678,6 @@ "@babel/preset-typescript": "^7.16.7", "@edx/eslint-config": "^3.1.0", "@svgr/webpack": "6.5.1", - "@types/color": "^3.0.3", "@types/mdx": "^2.0.3", "@types/mdx-js__react": "^1.5.5", "@types/react-helmet": "^6.1.6", diff --git a/www/package.json b/www/package.json index d559b4b689..4ff5b3e99c 100644 --- a/www/package.json +++ b/www/package.json @@ -11,7 +11,6 @@ "analytics-node": "^6.0.0", "axios": "^0.27.2", "classnames": "^2.3.1", - "color": "^4.2.3", "gatsby": "^4.23.1", "gatsby-plugin-manifest": "^4.17.0", "gatsby-plugin-mdx": "^3.17.0", @@ -37,8 +36,8 @@ "rehype-slug": "^4.0.1", "sass": "^1.53.0", "sass-loader": "12.6.0", - "uuid": "^9.0.0", - "slugify": "^1.6.5" + "slugify": "^1.6.5", + "uuid": "^9.0.0" }, "keywords": [ "paragon", @@ -69,7 +68,6 @@ "@babel/preset-typescript": "^7.16.7", "@edx/eslint-config": "^3.1.0", "@svgr/webpack": "6.5.1", - "@types/color": "^3.0.3", "@types/mdx": "^2.0.3", "@types/mdx-js__react": "^1.5.5", "@types/react-helmet": "^6.1.6", diff --git a/www/src/components/PageLayout.tsx b/www/src/components/PageLayout.tsx index 440e9f4577..a5e1375819 100644 --- a/www/src/components/PageLayout.tsx +++ b/www/src/components/PageLayout.tsx @@ -27,11 +27,6 @@ import { SettingsContext } from '../context/SettingsContext'; import LeaveFeedback from './LeaveFeedback'; import AutoToc from './AutoToc'; -if (process.env.NODE_ENV === 'development') { - /* eslint-disable-next-line global-require */ - require('~paragon-style/scss/core/core.scss'); -} - export interface ILayout { children: React.ReactNode, showMinimizedTitle: boolean, diff --git a/www/src/components/_doc-elements.scss b/www/src/components/_doc-elements.scss index e2c29574f2..94d3e937cd 100644 --- a/www/src/components/_doc-elements.scss +++ b/www/src/components/_doc-elements.scss @@ -324,3 +324,9 @@ .pgn-doc__box-shadow-toolkit--controls-box--remove-btn svg { color: var(--pgn-color-white); } + +.color-palette { + display: grid; + grid-template-columns: repeat(auto-fit, minmax(19rem, 1fr)); + grid-row-gap: 2rem; +} diff --git a/www/src/pages/foundations/colors.tsx b/www/src/pages/foundations/colors.tsx index c0da271087..695243d62d 100644 --- a/www/src/pages/foundations/colors.tsx +++ b/www/src/pages/foundations/colors.tsx @@ -2,10 +2,8 @@ import React, { useContext } from 'react'; import { graphql } from 'gatsby'; import PropTypes from 'prop-types'; import classNames from 'classnames'; -import Color from 'color'; import { Container, DataTable } from '~paragon-react'; import SEO from '../../components/SEO'; -import MeasuredItem from '../../components/MeasuredItem'; import Layout from '../../components/PageLayout'; import { SettingsContext } from '../../context/SettingsContext'; @@ -52,36 +50,36 @@ function parseColors(cssSelectors: { selector: string; declarations: string; }[] }); } +export type CSSStyleDeclarationType = CSSStyleDeclaration | null; + export interface ISwatch { name: string, colorClassName: string, isUnused?: boolean, + styles: CSSStyleDeclarationType, } -function Swatch({ name, colorClassName, isUnused }: ISwatch) { +function Swatch({ + name, colorClassName, isUnused, styles, +}: ISwatch) { + const computedValue = styles?.getPropertyValue(name); + return (
- ( -
- - {name} - - {measurements['background-color'] && ( - - {Color(measurements['background-color']).hex()} - - )} -
- )} - > -
- +
+
+ + {`var(${name})`} + + + + {computedValue} + +
); } @@ -96,18 +94,18 @@ Swatch.defaultProps = { isUnused: false, }; -const renderColorRamp = (themeName: string, unusedLevels: number[]) => ( +const renderColorRamp = (themeName: string, unusedLevels: number[], styles: CSSStyleDeclarationType) => (

{themeName}

{levels.map(level => ( ))}
@@ -124,6 +122,8 @@ export interface IColorsPage { // eslint-disable-next-line react/prop-types export default function ColorsPage({ data }: IColorsPage) { const { settings } = useContext(SettingsContext); + const styles = typeof window !== 'undefined' ? getComputedStyle(document.body) : null; + parseColors(data.allCssUtilityClasses.nodes); // eslint-disable-line react/prop-types return ( @@ -132,123 +132,45 @@ export default function ColorsPage({ data }: IColorsPage) {

Colors

-
+
{colors .slice(0, 3) - .map(({ themeName, unusedLevels }) => renderColorRamp(themeName, unusedLevels))} -
+ .map(({ themeName, unusedLevels }) => renderColorRamp(themeName, unusedLevels, styles))} + {colors + .slice(3) + .map(({ themeName, unusedLevels }) => renderColorRamp(themeName, unusedLevels, styles))} +

accents

- - + +
- - {colors - .slice(3) - .map(({ themeName, unusedLevels }) => renderColorRamp(themeName, unusedLevels))}
-

SCSS Color Usage

-

Include these colors in scss files in one of two ways:

+

CSS Color Usage

Variable name

- {'// $color_name-level '} + {'// var(--pgn-color-name-level) '}
- $primary-100 + var(--pgn-color-primary-100)
- $primary-200 + var(--pgn-color-primary-200)
- $brand-100 + var(--pgn-color-brand-100)
- $brand-200 -
- -

Mixin (deprecated)

- - theme-color($color-name, $variant) + var(--pgn-color-brand-200) +

With default value

- Using the variable name instead of the theme-color mixin will make - later upgrade paths easier. Paragon may begin to adopt CSS variables - for theming and attempt to eliminate mixins from the public api. + Using a default value in CSS variables allows to set a default value for a variable, + which will be used if the primary value of the variable is not defined or not available.

- - - - - - - - - - - - -
- Color Name -
A theme color -
- {colors.map(({ themeName }) => ( - - {themeName} - - ))} -
- Variant -
-

A number level or element type

-
- Levels - {levels.map((level) => ( - - {level} - - ))} -
- Element types - {[ - 'background', - 'disabled-border', - 'border', - 'icon', - 'active-border', - 'focus', - 'graphic', - 'default', - 'light-text', - 'hover', - 'text', - 'active', - 'dark-text', - ].map((element) => ( - - {element} - - ))} -
- -

Example

- - border: solid 1px $gray-300; - - - - border: solid 1px{' '} - theme-color(“gray”, “border”) - ; - - - - border: solid 1px{' '} - theme-color(“gray”, 300); + + {'// var(--pgn-color-name-level), default variable '} +
+ var(--pgn-color-brand-100, var(--pgn-color-primary-200))

CSS Class Utilities