Skip to content

Commit

Permalink
added a font-weight variation in typography documentation (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
fraincs authored Mar 1, 2024
2 parents 7378ba7 + 0f909d8 commit 7e0f489
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 0 deletions.
1 change: 1 addition & 0 deletions apps/docs/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"Card": true,
"Table": true,
"TypographyTable": true,
"TypographyVariantTable": true,
"Tabs": true,
"TableSection": true,
"Switcher": true,
Expand Down
18 changes: 18 additions & 0 deletions apps/docs/components/preview/FontWeightPreview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import "@hopper-ui/tokens/fonts.css";
import "./preview.css";

interface FontWeightPreviewProps {
values?: TypographyValues;
style?: React.CSSProperties;
}

interface TypographyValues {
fontWeight?: string;
}

const FontWeightPreview = ({ values, style }: FontWeightPreviewProps) => {
return <div className="hd-preview hd-preview--font hd-preview--typography" style={{ fontWeight: values?.fontWeight, ...style }}>Aa</div>;
};

export default FontWeightPreview;

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 @@ -10,6 +10,7 @@ import Switcher from "@/components/ui/switcher/Switcher";
import Title from "@/components/ui/title/Title";
import Table from "@/components/ui/table/Table";
import TypographyTable from "@/components/ui/table/TypographyTable";
import TypographyVariantTable from "@/components/ui/table/TypographyVariantTable";
import Tabs from "@/components/tabs/Tabs";
import TableSection from "@/components/tableSection/TableSection";

Expand All @@ -21,6 +22,7 @@ const components = {
pre: Pre,
Table: Table,
TypographyTable: TypographyTable,
TypographyVariantTable: TypographyVariantTable,
IconTable: IconTable,
IconSpecTable: IconSpecTable,
Tabs: Tabs,
Expand Down
64 changes: 64 additions & 0 deletions apps/docs/components/ui/table/TypographyVariantTable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"use client";

import React from "react";
import TypographyPreview from "@/components/preview/TypographyPreview";
import Code from "@/components/ui/code/Code";

import "./table.css";

interface TypographyVariantTableProps {
data: Record<string, { name: string; value: string }[]>;
type: string;
}

const TypographyVariantTable = ({ type, data }: TypographyVariantTableProps) => {
const tokenData = data["fontWeight"];

const filteredDataByType: Array<{ name: string; value: string }> = tokenData.filter(item =>
item.name.includes(type)
);

const filteredDataByWeightVariation: Array<{ name: string; value: string }> = filteredDataByType.filter(item =>
item.name.includes("bold") ||
item.name.includes("semibold") ||
item.name.includes("medium")
);

const listItems = filteredDataByWeightVariation.map(item => {
const fontWeight = item.value;

return (
<React.Fragment key={`${item.name}`}>
<tr className="hd-typo__row hd-top__row">
<td className="hd-table__cell hd-typo__cell">{item.name}</td>
<td className="hd-table__cell hd-typo__cell rowSpan={2}">
<Code value={`--${item.name}`}>{`--${item.name}`}</Code>
</td>
<td className="hd-table__cell hd-typo__cell">
{item.value}
</td>
<td className="hd-table__cell hd-typo__cell">
<TypographyPreview values={{ fontWeight }} />
</td>
</tr>
</React.Fragment>
);
});

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

export default TypographyVariantTable;
9 changes: 9 additions & 0 deletions apps/docs/content/tokens/semantic/typography.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ Headings are used to create a hierarchy of content. They are used to help users

<TypographyTable type="heading" data={tokens.semantic} />

### Variations

<TypographyVariantTable type="heading" data={tokens.semantic} />

## Overline

Used to introduce a headline.
Expand All @@ -45,8 +49,13 @@ Body text is used to communicate the main content of a page.

<TypographyTable type="body" data={tokens.semantic} />

### Variations

<TypographyVariantTable type="body" data={tokens.semantic} />

## Accent

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

<TypographyTable type="accent" data={tokens.semantic} />

0 comments on commit 7e0f489

Please sign in to comment.