Skip to content

Commit

Permalink
added typography section in Semantic token section
Browse files Browse the repository at this point in the history
  • Loading branch information
Francis Thibault committed Oct 30, 2023
1 parent b7e2bbd commit 0f7531e
Show file tree
Hide file tree
Showing 11 changed files with 2,059 additions and 1,949 deletions.
29 changes: 0 additions & 29 deletions apps/docs/components/preview/Preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ interface PreviewElemProps {
const Preview = ({ category, name, value }: PreviewProps) => {
let preview: PreviewElemProps = {};

const sampleText = "Aa";
const dimensionPaddingKeywords = ["inset"];
const dimensionInlineKeywords = ["inline"];
const dimensionStackKeywords = ["stack"];
Expand All @@ -25,34 +24,6 @@ const Preview = ({ category, name, value }: PreviewProps) => {
const matchingInlineKeyword = name ? dimensionInlineKeywords.find(keyword => name.includes(keyword)) : "";

switch (category) {
case "fontFamily":
preview = {
style: { fontFamily: value },
className: "hd-preview--font",
content: sampleText
};
break;
case "fontWeight":
preview = {
style: { fontWeight: value },
className: "hd-preview--font",
content: sampleText
};
break;
case "fontSize":
preview = {
style: { fontSize: value },
className: "hd-preview--font",
content: sampleText
};
break;
case "lineHeight":
preview = {
style: { lineHeight: value },
className: "hd-preview--font hd-preview--line-height",
content: <>{sampleText}<br />{sampleText}</>
};
break;
case "mediaQuery":
case "zIndex":
preview = {
Expand Down
36 changes: 36 additions & 0 deletions apps/docs/components/preview/TypographyPreview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import "@hopper-ui/tokens/fonts.css";
import "./preview.css";

interface TypographyPreviewProps {
values?: TypographyValues;
}

interface TypographyValues {
lineHeight?: string;
fontWeight?: string;
fontSize?: string;
fontFamily?: string;
}

interface TypographyPreviewElemProps {
className?: string;
content?: React.ReactNode;
style?: React.CSSProperties;
}

const TypographyPreview = ({ values }: TypographyPreviewProps) => {
let TypographyPreviewElem: TypographyPreviewElemProps = {};

const sampleText = "Aa";
console.log(values);

TypographyPreviewElem = {
style: { lineHeight: values?.lineHeight, fontWeight: values?.fontWeight, fontSize: values?.fontSize, fontFamily: values?.fontFamily },
className: "hd-preview--font hd-preview--typography",
content: <>{sampleText}</>
};

return <div className={`hd-preview ${TypographyPreviewElem.className}`} style={TypographyPreviewElem.style}>{TypographyPreviewElem.content}</div>;
};

export default TypographyPreview;
2 changes: 2 additions & 0 deletions apps/docs/components/ui/mdx/Mdx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Card from "@/components/ui/card/Card";
import Pre from "@/components/ui/pre/Pre";
import Title from "@/components/ui/title/Title";
import Table from "@/components/ui/table/Table";
import TypographyTable from "@/components/ui/table/TypographyTable";
import Tabs from "@/components/tabs/Tabs";

type HeadingProps = React.DetailedHTMLProps<HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>;
Expand All @@ -15,6 +16,7 @@ const components = {
Image: NextImage,
pre: Pre,
Table: Table,
TypographyTable: TypographyTable,
Tabs: Tabs,
h1: (props: HeadingProps) => {
return <Title {...props} as="h1" />;
Expand Down
146 changes: 146 additions & 0 deletions apps/docs/components/ui/table/TypographyTable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
"use client";

import TypographyPreview from "@/components/preview/TypographyPreview";
import Code from "@/components/ui/code/Code";
import tokens from "../../../datas/tokens.json";

import "./table.css";

interface TypographyTableProps {
type: string;
data: {
[key: string]: {
"font-family": { $value: string };
"font-size": { $type: string; $value: string };
"font-weight": { $type: string; $value: string };
"line-height": { $type: string; $value: string };
};
};
}

const TypographyTable = ({ type, data }: TypographyTableProps) => {
const headings = Object.keys(data);

const listItems = headings.map(heading => {
const {
"font-family": fontFamily,
"font-size": fontSize,
"font-weight": fontWeight,
"line-height": lineHeight
} = data[heading];

const lineHeightTokens = tokens.core.lineHeight;
const fontFamilyTokens = tokens.core.fontFamily;
const fontWeightTokens = tokens.core.fontWeight;
const fontSizeTokens = tokens.core.fontSize;

const getFontSize = (value: string) => {
const lastPart = value.match(/\.(\d+)(?=\})/);

if (lastPart) {
return lastPart[1];
}
};

const getFontWeight = (value: string) => {
const lastPart = value.match(/\.(\d+)(?=\})/);

if (lastPart) {
return lastPart[1];
}
};

const getlineHeight = (value: string) => {
const lastPart = value.match(/\.([\d-]+)(?=\})/);

if (lastPart) {
return lastPart[1];
}
};

const getFontFamily = (value: string) => {
const lastPart = value.match(/\.([^\s.}]+)(?=\})/);

if (lastPart) {
return lastPart[1];
}
};

const fontSizeValue = fontSizeTokens.find(item => item.name === `hop-font-size-${getFontSize(fontSize.$value)}`)?.value;
const fontWeightValue = fontWeightTokens.find(item => item.name === `hop-font-weight-${getFontWeight(fontWeight.$value)}`)?.value;
const fontFamilyValue = fontFamilyTokens.find(item => item.name === `hop-font-family-${getFontFamily(fontFamily.$value)}`)?.value;
const lineHeightValue = lineHeightTokens.find(item => item.name === `hop-line-height-${getlineHeight(lineHeight.$value)}`)?.value;

return (
<>
<tr key={heading} className="hd-typo__row">
<td className="hd-table__cell hd-typo__cell" rowSpan={4}>{heading}</td>
<td className="hd-table__cell hd-typo__cell" colSpan={3}>
Font Size
</td>
<td className="hd-table__cell hd-typo__cell">
<Code value={`--hop-${type}-${heading}-font-size`}>{`--hop-${type}-${heading}-font-size`}</Code>
</td>
<td className="hd-table__cell hd-typo__cell">
{fontSizeValue}
</td>
<td className="hd-table__cell hd-typo__cell" rowSpan={4}>
<TypographyPreview values={{ lineHeight: lineHeightValue, fontSize: fontSizeValue, fontWeight: fontWeightValue, fontFamily: fontFamilyValue }} />
</td>
</tr>
<tr>
<td className="hd-table__cell hd-typo__cell" colSpan={3}>
Font Weight
</td>
<td className="hd-table__cell hd-typo__cell">
<Code value={`--hop-${type}-${heading}-font-weight`}>{`--hop-${type}-${heading}-font-weight`}</Code>
</td>
<td className="hd-table__cell hd-typo__cell">
{fontWeightValue}
</td>
</tr>
<tr>
<td className="hd-table__cell hd-typo__cell" colSpan={3}>
Line Height
</td>
<td className="hd-table__cell hd-typo__cell">
<Code value={`--hop-${type}-${heading}-line-height`}>{`--hop-${type}-${heading}-line-height`}</Code>
</td>
<td className="hd-table__cell hd-typo__cell">
{lineHeightValue}
</td>
</tr>
<tr>
<td className="hd-table__cell hd-typo__cell" colSpan={3}>
Font-Family
</td>
<td className="hd-table__cell hd-typo__cell">
<Code value={`--hop-${type}-${heading}-font-family`}>{`--hop-${type}-${heading}-font-family`}</Code>
</td>
<td className="hd-table__cell hd-typo__cell">
{fontFamilyValue}
</td>
</tr>
</>
);
});

return (
<>
<table className="hd-table" aria-label="Tokens">
<thead>
<tr>
<th className="hd-table__column">Name</th>
<th className="hd-table__column" colSpan={5}>Values</th>
<th className="hd-table__column">Preview</th>
</tr>
</thead>
<tbody>
{listItems}
</tbody>
</table>
</>
);
};

export default TypographyTable;
16 changes: 15 additions & 1 deletion apps/docs/components/ui/table/table.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@
.hd-table__cell {
font-family: var(--hd-mono-font-family);
font-size: 0.8125rem;
padding-block: var(--hd-space-1);
padding: var(--hd-space-1);
border-bottom: var(--hd-border-size) solid var(--hd-color-neutral-border);
}

.hd-table__cell:first-child {
padding-left: 0;
}

/* TypoTable */
.hd-table__cell.hd-typo__cell {
text-align: left;
border-bottom: 0;
}

.hd-table .hd-typo__row .hd-table__cell {
border-top: var(--hd-border-size) solid var(--hd-color-neutral-border);
}
11 changes: 0 additions & 11 deletions apps/docs/content/tokens/semantic/font-family.mdx

This file was deleted.

11 changes: 0 additions & 11 deletions apps/docs/content/tokens/semantic/font-size.mdx

This file was deleted.

11 changes: 0 additions & 11 deletions apps/docs/content/tokens/semantic/font-weight.mdx

This file was deleted.

11 changes: 0 additions & 11 deletions apps/docs/content/tokens/semantic/line-height.mdx

This file was deleted.

29 changes: 29 additions & 0 deletions apps/docs/content/tokens/semantic/typography.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
title: Typography
description: Getting started with Workleap Design Tokens
---
import tokens from '../../../../../packages/tokens/src/tokens/semantic/light/fonts.tokens.json';

# Typography

export const categoryKey = "typography";

Typography tokens are composite tokens, meaning they are made up of multiple other tokens. This allows us to create a consistent typographic scale across our products.

## Heading

Headings are used to create a hierarchy of content. They are used to help users scan and understand the content on a page.

<TypographyTable category={categoryKey} type="heading" data={tokens["heading"]} />

## Body

Body text is used to communicate the main content of a page.

<TypographyTable category={categoryKey} type="body" data={tokens["body"]} />

## Accent

Accent text is used to highlight important information on a page.

<TypographyTable category={categoryKey} type="accent" data={tokens["accent"]} />
Loading

0 comments on commit 0f7531e

Please sign in to comment.