Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BD-46] docs: replaced SCSS variables with CSS variables on the Colors page #2376

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions www/src/components/PageLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions www/src/components/_doc-elements.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
164 changes: 40 additions & 124 deletions www/src/pages/foundations/colors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
import { CodeCell } from '../../components/TableCells';
Expand Down Expand Up @@ -57,30 +55,27 @@ export interface ISwatch {
isUnused?: boolean,
}

const styles = typeof window !== 'undefined' ? getComputedStyle(document.body) : null;
viktorrusakov marked this conversation as resolved.
Show resolved Hide resolved

function Swatch({ name, colorClassName, isUnused }: ISwatch) {
const computedValue = styles?.getPropertyValue(name);

return (
<div className="d-flex align-items-center mb-2">
<MeasuredItem
properties={['background-color']}
renderAfter={(measurements: { [x: string]: JSX.Element; }) => (
<div style={{ lineHeight: 1 }} className="small">
<code className="mb-0 d-block text-lowercase text-dark-700">
{name}
</code>
{measurements['background-color'] && (
<code style={{ fontSize: '65%' }} className="text-muted">
{Color(measurements['background-color']).hex()}
</code>
)}
</div>
)}
>
<div
className={classNames('p-3 mr-2 rounded', colorClassName, {
'unused-level': isUnused,
})}
/>
</MeasuredItem>
<div
className={classNames('p-3 mr-2 rounded', colorClassName, {
'unused-level': isUnused,
})}
/>
<div style={{ lineHeight: 1 }} className="small">
<code className="mb-0 d-block text-lowercase text-dark-700">
{`var(${name})`}
</code>

<code style={{ fontSize: '65%' }} className="text-muted">
{computedValue}
</code>
</div>
</div>
);
}
Expand All @@ -98,13 +93,12 @@ Swatch.defaultProps = {
const renderColorRamp = (themeName: string, unusedLevels: number[]) => (
<div
key={`${themeName}`}
style={{ flexBasis: '24%', marginRight: '1%', marginBottom: '2rem' }}
>
<p className="h5">{themeName}</p>
{levels.map(level => (
<Swatch
key={`$${themeName}-${level}`}
name={`$${themeName}-${level}`}
key={`${themeName}-${level}`}
name={`--pgn-color-${themeName}-${level}`}
colorClassName={utilityClasses.bg(themeName, level)}
isUnused={unusedLevels.includes(level)}
/>
Expand All @@ -131,123 +125,45 @@ export default function ColorsPage({ data }: IColorsPage) {
<SEO title="Colors" />
<Container size={settings.containerWidth} className="py-5">
<h1>Colors</h1>
<div className="d-flex flex-wrap">
<div className="color-palette mb-3">
{colors
.slice(0, 3)
.map(({ themeName, unusedLevels }) => renderColorRamp(themeName, unusedLevels))}
<div
style={{
flexBasis: '19%',
marginRight: '1%',
marginBottom: '2rem',
}}
>
<p className="h5">accents</p>

<Swatch name="$accent-a" colorClassName="bg-accent-a" />
<Swatch name="$accent-b" colorClassName="bg-accent-b" />
</div>

{colors
.slice(3)
.map(({ themeName, unusedLevels }) => renderColorRamp(themeName, unusedLevels))}
<div>
<p className="h5">accents</p>

<Swatch name="--pgn-color-accent-a" colorClassName="bg-accent-a" />
<Swatch name="--pgn-color-accent-b" colorClassName="bg-accent-b" />
</div>
</div>

<h3>SCSS Color Usage</h3>
<p>Include these colors in scss files in one of two ways:</p>
<h3>CSS Color Usage</h3>

<h4>Variable name</h4>
<code className="d-block mb-4 lead bg-gray-100 p-3">
{'// $color_name-level '}
{'// var(--pgn-color-name-level) '}
<br />
$primary-100
var(--pgn-color-primary-100)
<br />
$primary-200
var(--pgn-color-primary-200)
<br />
$brand-100
var(--pgn-color-brand-100)
<br />
$brand-200
</code>

<h4>Mixin (deprecated)</h4>
<code className="d-block mb-4 lead bg-gray-100 p-3">
theme-color($color-name, $variant)
var(--pgn-color-brand-200)
</code>

<h4>With default value</h4>
<p>
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.
</p>

<table className="pgn-doc__table mb-2">
<tbody>
<tr>
<td className="p-3">
<strong>Color Name</strong>
<br />A theme color
</td>
<td className="p-3 align-baseline">
{colors.map(({ themeName }) => (
<code key={themeName} className="mr-2">
{themeName}
</code>
))}
</td>
</tr>
<tr>
<td className="p-3 align-baseline">
<strong>Variant</strong>
<br />
<p>A number level or element type</p>
</td>
<td className="p-3">
<strong className="d-block">Levels </strong>
{levels.map((level) => (
<code key={level} className="mr-2">
{level}
</code>
))}
<br />
<strong className="d-block">Element types </strong>
{[
'background',
'disabled-border',
'border',
'icon',
'active-border',
'focus',
'graphic',
'default',
'light-text',
'hover',
'text',
'active',
'dark-text',
].map((element) => (
<code key={element} className="mr-2">
{element}
</code>
))}
</td>
</tr>
</tbody>
</table>

<h4>Example</h4>
<code className="d-block mb-2 bg-gray-100 p-3">
border: solid 1px <strong>$gray-300</strong>;
</code>

<code className="d-block mb-2 bg-gray-100 p-3">
border: solid 1px{' '}
<strong>theme-color(&ldquo;gray&rdquo;, &ldquo;border&rdquo;)</strong>
;
</code>

<code className="d-block mb-4 bg-gray-100 p-3">
border: solid 1px{' '}
<strong>theme-color(&ldquo;gray&rdquo;, 300)</strong>;
<code className="d-block mb-4 lead bg-gray-100 p-3">
{'// var(--pgn-color-name-level), default variable '}
<br />
var(--pgn-color-brand-100, var(--pgn-color-primary-200))
</code>

<h3>CSS Class Utilities</h3>
Expand Down
Loading