From 05ca9c93e339369829ad4c8dd05ec047fe974a07 Mon Sep 17 00:00:00 2001 From: Peter Kulko <93188219+PKulkoRaccoonGang@users.noreply.github.com> Date: Wed, 21 Dec 2022 10:24:00 +0200 Subject: [PATCH] refactor: refactoring Table on docs site --- www/src/pages/foundations/colors.tsx | 192 ++++--- .../{elevation.jsx => elevation.tsx} | 114 +++-- www/src/pages/foundations/typography.tsx | 467 +++++------------- 3 files changed, 310 insertions(+), 463 deletions(-) rename www/src/pages/foundations/{elevation.jsx => elevation.tsx} (84%) diff --git a/www/src/pages/foundations/colors.tsx b/www/src/pages/foundations/colors.tsx index 01dfb17ba03..0179f612328 100644 --- a/www/src/pages/foundations/colors.tsx +++ b/www/src/pages/foundations/colors.tsx @@ -8,7 +8,7 @@ import SEO from '../../components/SEO'; import MeasuredItem from '../../components/MeasuredItem'; import Layout from '../../components/PageLayout'; // @ts-ignore -import { Container } from '~paragon-react'; // eslint-disable-line +import { Container, DataTable } from '~paragon-react'; // eslint-disable-line const utilityClasses = { bg: (color: string, level: number) => (level ? `bg-${color}-${level}` : `bg-${color}`), @@ -36,6 +36,22 @@ const colors: IColors[] = [ const levels = [100, 200, 300, 400, 500, 600, 700, 800, 900]; +const elements = [ + 'background', + 'disabled-border', + 'border', + 'icon', + 'active-border', + 'focus', + 'graphic', + 'default', + 'light-text', + 'hover', + 'text', + 'active', + 'dark-text', +]; + export type ParseColorTypes = { [key: string]: string | null; }; @@ -122,6 +138,17 @@ export interface IColorsPage { }, } +export type DataTableTypes = { + row: { + original: { + color: string, + element: string, + level: string, + use: string, + } + }, +} + // eslint-disable-next-line react/prop-types export default function ColorsPage({ data }: IColorsPage) { parseColors(data.allCssUtilityClasses.nodes); // eslint-disable-line react/prop-types @@ -180,54 +207,48 @@ export default function ColorsPage({ data }: IColorsPage) { later upgrade paths easier. Paragon may begin to adopt CSS variables for theming and attempt to eliminate mixins from the public api.

- - - - - - - - - - - - -
- 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} - ))} -
+
+ { + return { + element: elements[index], + color: themeName, + level: levels[index], + } + }) + } + columns={[ + { + Header: 'Color Names', + Cell: ({ row }: DataTableTypes) => ( + + {row.original.color} + + ), + }, + { + Header: 'Elements', + Cell: ({ row }: DataTableTypes) => ( + + {row.original.element} + + ), + }, + { + Header: 'Levels', + Cell: ({ row }: DataTableTypes) => ( + + {row.original.level} + + ), + }, + ]} + > + + +

Example

@@ -253,37 +274,48 @@ export default function ColorsPage({ data }: IColorsPage) {

{'.{use}-{color}-{level}'}

- - - - - - - - - - - - - - - -
UseColorLevel
- bg- -
- border- -
- text- -
-
- {colors.map(({ themeName }) => ( - {themeName}- - ))} - - {levels.map(level => ( - {level} - ))} -
+
+ { + return { + use: Object.keys(utilityClasses)[index], + color: themeName, + level: levels[index], + } + }) + } + columns={[ + { + Header: 'Use', + Cell: ({ row }: DataTableTypes) => ( + + {row.original.use && `${row.original.use}-`} + + ), + }, + { + Header: 'Color', + Cell: ({ row }: DataTableTypes) => ( + + {row.original.color}- + + ), + }, + { + Header: 'Level', + Cell: ({ row }: DataTableTypes) => ( + + {row.original.level} + + ), + }, + ]} + > + + +

Background Fills

diff --git a/www/src/pages/foundations/elevation.jsx b/www/src/pages/foundations/elevation.tsx similarity index 84% rename from www/src/pages/foundations/elevation.jsx rename to www/src/pages/foundations/elevation.tsx index f30e551467d..e32dfd26704 100644 --- a/www/src/pages/foundations/elevation.jsx +++ b/www/src/pages/foundations/elevation.tsx @@ -4,10 +4,12 @@ import SEO from '../../components/SEO'; import Layout from '../../components/PageLayout'; import { Button, Form, Container, - Toast, Icon, IconButtonWithTooltip, + Toast, Icon, IconButtonWithTooltip, DataTable, // eslint-disable-next-line import/no-unresolved +// @ts-ignore } from '~paragon-react'; // eslint-disable-next-line import/no-unresolved +// @ts-ignore import { Close, WbSunny, DoDisturb } from '~paragon-icons'; const boxShadowSides = ['down', 'up', 'right', 'left', 'centered']; @@ -22,10 +24,10 @@ const controlsProps = [ { key: 'color', name: 'Color' }, ]; -const BoxShadowNode = () => { +function BoxShadowNode() { const [showToast, setShowToast] = useState(false); - const isBoxShadowCopied = (level, side) => { + const isBoxShadowCopied = (level: number, side: string) => { navigator.clipboard.writeText(`@include pgn-box-shadow(${level}, "${side}");`); setShowToast(true); }; @@ -61,9 +63,28 @@ const BoxShadowNode = () => {
); -}; +} + +export interface IBoxShadowToolkit { + id: number, + updateBoxShadow: Function, + removeBoxShadowLayer: Function, + disableBoxShadowLayer: Function, + enableBoxShadowLayer: Function, + isDisabled: boolean, + canDelete: boolean, +} -const BoxShadowToolkit = ({ +export interface IBoxShadowModel { + x: number, + y: number, + blur: number, + spread: number, + color: string, + inset: boolean, +} + +function BoxShadowToolkit({ id, updateBoxShadow, removeBoxShadowLayer, @@ -71,8 +92,8 @@ const BoxShadowToolkit = ({ enableBoxShadowLayer, isDisabled, canDelete, -}) => { - const [boxShadowModel, setBoxShadowModel] = useState({ +}: IBoxShadowToolkit) { + const [boxShadowModel, setBoxShadowModel] = useState({ x: 0, y: 0, blur: 0, @@ -81,7 +102,7 @@ const BoxShadowToolkit = ({ inset: false, }); - const updateBoxShadowModel = (property, value) => { + const updateBoxShadowModel = (property: string, value: boolean | string) => { global.analytics.track('openedx.paragon.elevation.generator.updated', { property, value }); const newBoxShadowModel = { @@ -109,7 +130,7 @@ const BoxShadowToolkit = ({ max="100" type={key === 'color' ? 'color' : 'range'} defaultValue="0" - onChange={(e) => updateBoxShadowModel(key, e.target.value)} + onChange={(e: React.ChangeEvent) => updateBoxShadowModel(key, e.target.value)} disabled={isDisabled} /> @@ -162,7 +183,7 @@ const BoxShadowToolkit = ({ ); -}; +} BoxShadowToolkit.propTypes = { updateBoxShadow: PropTypes.func.isRequired, @@ -174,10 +195,10 @@ BoxShadowToolkit.propTypes = { canDelete: PropTypes.bool.isRequired, }; -const BoxShadowGenerator = () => { +function BoxShadowGenerator() { const [boxShadows, setBoxShadows] = useState([{ id: 1, enabled: true, style: DEFAULT_BOX_SHADOW }]); - const updateBoxShadow = (shadow, id) => { + const updateBoxShadow = (shadow: { x: string, y: string, blur: string, spread: string, color: string, inset: string }, id: number) => { setBoxShadows(boxShadows.map(item => { if (id === item.id) { return { @@ -199,12 +220,12 @@ const BoxShadowGenerator = () => { ]); }; - const removeBoxShadowLayer = (toolkitId) => { + const removeBoxShadowLayer = (toolkitId: number) => { global.analytics.track('openedx.paragon.elevation.shadow-generator.layer.removed'); setBoxShadows(boxShadows.filter((shadow) => shadow.id !== toolkitId)); }; - const disableBoxShadowLayer = (toolkitId) => { + const disableBoxShadowLayer = (toolkitId: number) => { global.analytics.track('openedx.paragon.elevation.shadow-generator.layer.disabled'); const updatedBoxShadows = boxShadows .map((shadow) => { @@ -216,7 +237,7 @@ const BoxShadowGenerator = () => { setBoxShadows(updatedBoxShadows); }; - const enableBoxShadowLayer = (toolkitId) => { + const enableBoxShadowLayer = (toolkitId: string | number) => { global.analytics.track('openedx.paragon.elevation.shadow-generator.layer.enabled'); const updatedBoxShadows = boxShadows .map((shadow) => { @@ -262,7 +283,16 @@ const BoxShadowGenerator = () => { ); -}; +} + +export type DataTableTypes = { + row: { + original: { + side: string, + level: string, + } + }, +} export default function ElevationPage() { const levelTitle = boxShadowLevels.map(level => ( @@ -310,32 +340,32 @@ export default function ElevationPage() { pgn-box-shadow($level, $side)
- - - - - - - - - - - -
- Direction name - - {boxShadowSides.map(side => ( - {side} - ))} -
- Levels -
-

Box-shadows elevation levels

-
- {boxShadowLevels.map(level => ( - {level} - ))} -
+
+ ({ side, level: boxShadowLevels[index] }))} + columns={[ + { + Header: 'Direction name', + Cell: ({ row }: DataTableTypes) => ( + + {row.original.side} + + ), + }, + { + Header: 'Levels', + Cell: ({ row }: DataTableTypes) => ( + + {row.original.level} + + ), + }, + ]} + > + + +

Example classes usage

diff --git a/www/src/pages/foundations/typography.tsx b/www/src/pages/foundations/typography.tsx index 87ca3e8d3fc..88e5594ad71 100644 --- a/www/src/pages/foundations/typography.tsx +++ b/www/src/pages/foundations/typography.tsx @@ -1,10 +1,11 @@ /* eslint-disable jsx-a11y/anchor-is-valid */ import React from 'react'; // @ts-ignore -import { Container } from '~paragon-react'; // eslint-disable-line +import { Container, DataTable } from '~paragon-react'; // eslint-disable-line import SEO from '../../components/SEO'; import MeasuredItem from '../../components/MeasuredItem'; import Layout from '../../components/PageLayout'; +import HipsterIpsum from '../../components/exampleComponents/HipsterIpsum'; export type WeightLabelsTypes = { [key: string]: string, @@ -20,6 +21,28 @@ const weightLabels: WeightLabelsTypes = { 800: 'Black', }; +const headingSizes = [1, 2, 3, 4, 5, 6]; + +const decorationAndEmphasisClassesAndDescriptions = [ + { className: 'text-lowercase', text: 'Lowercase text.' }, + { className: 'text-uppercase', text: 'uppercase text.' }, + { className: 'text-capitalize', text: 'capitalize text.' }, + { className: 'text-decoration-none', text: 'No decorations.' }, + { className: 'text-italic', text: 'Italic text.' }, + { className: 'font-weight-bold', text: 'Bold text.' }, + { className: 'font-weight-normal', text: 'Regular text.' }, + { className: 'text-muted', text: }, +]; + +const alignmentClassesAndDescriptions = [ + { className: 'text-left', text: 'left text.' }, + { className: 'text-right', text: 'right text.' }, + { className: 'text-center', text: 'center text.' }, + { className: 'text-justify', text: 'justify text.' }, + { className: 'text-wrap', text: 'wrap text.' }, + { className: 'text-nowrap', text: 'nowrap text.' }, +]; + const measuredTypeProps = { properties: ['font-size', 'line-height', 'font-family', 'font-weight'], renderAfter: (measurements: { [x: string]: string; }) => { @@ -42,6 +65,16 @@ const measuredTypeProps = { }, }; +export type DataTableTypes = { + row: { + original: { + size: string, + className: string, + text: string, + } + }, +} + export default function TypographyPage() { return ( @@ -49,349 +82,101 @@ export default function TypographyPage() { {/* eslint-disable-next-line react/jsx-pascal-case */}

Typography

- - - - - - - - - - - {[1, 2, 3, 4, 5, 6].map(headingSize => ( - - - - - - ))} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {[1, 2, 3, 4].map(displaySize => ( - - - - - - ))} - - - - - - - - - - - - - - - - - - - - - - -
-

Headings

-
DesktopMobileCSS Class
+

Headings

+
+ ({ size }))} + columns={[ + { + Header: 'Desktop', + Cell: ({ row }: DataTableTypes) => ( -

- Heading {headingSize} +

+ Heading {row.original.size}

-
- -

- Heading {headingSize} -

-
-
- .h{headingSize} -
- -

Heading Label

-
- A heading label is usually paired with and proceeds a Heading. -
- .heading-label -
-

Body

-
Desktop & MobileCSS Class
- -

Large Body

-
-
- .lead -
- -

Body

-
-
- -

Small Body

-
-
- .small -
- -

Extra Small Body

-
-
- .x-small -
- -

Micro Body

-
-
- .micro -
-

Display

-
DesktopMobileCSS Class
- -

- Display {displaySize} -

-
-
- -

- Display {displaySize} -

-
-
- .display-{displaySize} -
-

Links

-
- Standalone Link - - - The default style for a tags that don't appear in - a p tag. - -
-

- An{' '} - - inline link - {' '} - in a sentence. -

-
- - For links inside a p or with the{' '} - .inline-link class name. - -
- - Muted, Standalone Link - - - - .muted-link not in a p tag. - -
-

- An{' '} - - muted, inline link - {' '} - in a sentence. -

-
- - For .muted-link links inside a p or - with the .inline-link class name. - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-

Decoration and Emphasis

-
StyleCSS Class
-

Lowercase text.

-
- .text-lowercase -
-

uppercase text.

-
- .text-uppercase -
-

capitalize text.

-
- .text-capitalize -
-

No decorations.

-
- .text-decoration-none -
-

Italic text.

-
- .text-italic -
-

Bold text.

-
- .font-weight-bold -
-

Regular text.

-
- .font-weight-normal -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-

Alignment

-
StyleCSS Class
-

left text.

-
- .text-left -
-

right text.

-
- .text-right -
-

center text.

-
- .text-center -
-

justify text.

-

- At the edge of forever tendrils of gossamer clouds corpus - callosum culture Vangelis dispassionate extraterrestrial - observer. -

-
- .text-justify -
-

wrap text.

-
- .text-wrap -
-

nowrap text.

-
- .text-nowrap -
+ ), + }, + { + Header: 'Mobile', + Cell: ({ row }: DataTableTypes) => ( +
+ +

+ Heading {row.original.size} +

+
+
+ ), + }, + { + Header: 'CSS Class', + Cell: ({ row }: DataTableTypes) => ( + + .h{row.original.size} + + ), + }, + ]} + > + + + +

Decoration and Emphasis

+
+ ({ className, text }))} + columns={[ + { + Header: 'Style', + Cell: ({ row }: DataTableTypes) => ( +

+ {row.original.text} +

+ ), + }, + { + Header: 'CSS Class', + Cell: ({ row }: DataTableTypes) => ( + + .{row.original.className} + + ), + } + ]} + > + +
+
+

Alignment

+
+ ({ className, text }))} + columns={[ + { + Header: 'Style', + Cell: ({ row }: DataTableTypes) => ( +

+ {row.original.text} +

+ ), + }, + { + Header: 'CSS Class', + Cell: ({ row }: DataTableTypes) => ( + + .{row.original.className} + + ), + } + ]} + > + +
+
);