Skip to content

Commit

Permalink
Feature/hop-37 - Feature/hop-30 (#80)
Browse files Browse the repository at this point in the history
Co-authored-by: Francis Thibault <[email protected]>
  • Loading branch information
fraincs and Francis Thibault authored Nov 8, 2023
1 parent 5e22da7 commit 4b1127f
Show file tree
Hide file tree
Showing 18 changed files with 404 additions and 86 deletions.
1 change: 1 addition & 0 deletions apps/docs/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"globals": {
"Card": true,
"Table": true,
"TypographyTable": true,
"Tabs": true,
"TableSection": true
}
Expand Down
7 changes: 6 additions & 1 deletion apps/docs/app/layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ main {

p {
font-size: 1rem;
line-height: 1.5rem;
line-height: 1.5;
}

p:not(:last-child) {
Expand All @@ -58,3 +58,8 @@ p:not(:last-child) {
p + * {
margin-block-start: var(--hd-space-3);
}

article ul {
line-height: 1.5rem;
padding-left: 1rem;
}
10 changes: 9 additions & 1 deletion apps/docs/components/copyButton/copyButton.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
background-color: transparent;
border: none;
stroke: var(--hd-icon-button-color);
width: var(--hd-space-4);
aspect-ratio: 1/1;
width: var(--hd-space-4);
border-radius: var(--hd-space-1);
cursor: pointer;
}
Expand All @@ -27,3 +27,11 @@
.hd-copy-button--inlined {
background: var(--hd-color-neutral-surface);
}

.hd-copy-button--on-dark {
stroke: var(--hd-neutral-20);
}

.hd-copy-button--on-dark:hover {
stroke: var(--hd-neutral-900);
}
21 changes: 21 additions & 0 deletions apps/docs/components/preview/TypographyPreview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import "@hopper-ui/tokens/fonts.css";
import "./preview.css";

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

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

const TypographyPreview = ({ values, style }: TypographyPreviewProps) => {
return <div className="hd-preview hd-preview--font hd-preview--typography" style={{ lineHeight: values?.lineHeight, fontWeight: values?.fontWeight, fontSize: values?.fontSize, fontFamily: values?.fontFamily, ...style }}>Aa</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";
import TableSection from "@/components/tableSection/TableSection";

Expand All @@ -16,6 +17,7 @@ const components = {
Image: NextImage,
pre: Pre,
Table: Table,
TypographyTable: TypographyTable,
Tabs: Tabs,
TableSection: TableSection,
h1: (props: HeadingProps) => {
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/components/ui/pre/Pre.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const Pre = ({ children, title, "data-language": dataLanguage, raw, ...props }:
}
<span className="hd-pre-header__title">{title}</span>
</div>
{raw && <CopyButton text={raw} />}
{raw && <CopyButton text={raw} className="hd-copy-button--on-dark" />}
</div>
{children}
</pre>
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/components/ui/table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const Table = ({ category, data }: TableProps) => {
const { name, value } = token;

return (
<Row key={name}>
<Row key={name} className="hd-table__row">
<Cell className="hd-table__cell">
<Code value={`--${name}`}>{`--${name}`}</Code>
</Cell>
Expand Down
164 changes: 164 additions & 0 deletions apps/docs/components/ui/table/TypographyTable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
"use client";

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

import "./table.css";

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

const Sizes = ["3xl", "2xl", "xl", "lg", "md", "sm", "xs"] as const;

const FontProperties = ["fontFamily", "fontSize", "fontWeight", "lineHeight"] as const;

type GroupedItems = Record<typeof Sizes[number], Record<typeof FontProperties[number], string>>;

interface TokenData {
[category: string]: { name: string; value: string }[];
}

function transformDataToTokenData(inputData: Record<string, { name: string; value: string }[]>): TokenData {
const tokenData: TokenData = {};

for (const propertyKey in inputData) {
const items = inputData[propertyKey];

if (Array.isArray(items)) {
tokenData[propertyKey] = items;
}
}

return tokenData;
}

function groupItemsByPropertiesAndSizes(tokenData: TokenData, itemType: string): GroupedItems {
const groupedItems: GroupedItems = {} as GroupedItems;

Sizes.forEach(size => {
const sizeKey = size as typeof Sizes[number];
groupedItems[sizeKey] = {} as Record<typeof FontProperties[number], string>;

FontProperties.forEach(property => {
const propertyKey = property;

if (!tokenData[propertyKey]) {
return;
}

const matchingItem = tokenData[propertyKey].find(item => {
const nameParts = item.name.split("-");

return nameParts.includes(itemType === "overline" ? "md" : itemType) && nameParts.includes(size);
});

if (matchingItem) {
groupedItems[sizeKey][propertyKey] = matchingItem.value;
}
});

if (Object.values(groupedItems[sizeKey]).every(value => !value)) {
delete groupedItems[sizeKey];
}
});

return groupedItems;
}

const TypographyTable = ({ type, data }: TypographyTableProps) => {
const tokenData = transformDataToTokenData(data);
const filteredData = groupItemsByPropertiesAndSizes(tokenData, type);

const listItems = Object.keys(filteredData).map(size => {
const {
fontFamily,
fontSize,
fontWeight,
lineHeight
} = filteredData[size as typeof Sizes[number]];

// If the itemType is 'overline', set displaySize to an empty string
let displaySize = `-${size}`;
let previewAdditionalStyles = {};

if (type === "overline") {
displaySize = "";
previewAdditionalStyles = {
textTransform: "uppercase"
};
}

return (
<React.Fragment key={`${type}${size}`}>
<tr className="hd-typo__row hd-top__row">
{type !== "overline" && <td className="hd-table__cell hd-typo__cell" rowSpan={4}>{size}</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}${displaySize}-font-size`}>{`--hop-${type}${displaySize}-font-size`}</Code>
</td>
<td className="hd-table__cell hd-typo__cell">
{fontSize}
</td>
<td className="hd-table__cell hd-typo__cell" rowSpan={4}>
<TypographyPreview style={{ ...previewAdditionalStyles }} values={{ lineHeight, fontSize, fontWeight, fontFamily }} />
</td>
</tr>
<tr className="hd-typo__row">
<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}${displaySize}-font-weight`}>{`--hop-${type}${displaySize}-font-weight`}</Code>
</td>
<td className="hd-table__cell hd-typo__cell">
{fontWeight}
</td>
</tr>
<tr className="hd-typo__row">
<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}${displaySize}-line-height`}>{`--hop-${type}${displaySize}-line-height`}</Code>
</td>
<td className="hd-table__cell hd-typo__cell">
{lineHeight}
</td>
</tr>
<tr className="hd-typo__row">
<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}${displaySize}-font-family`}>{`--hop-${type}${displaySize}-font-family`}</Code>
</td>
<td className="hd-table__cell hd-typo__cell">
{fontFamily}
</td>
</tr>
</React.Fragment>
);
});

return (
<table className="hd-table hd-typo-table" aria-label="Tokens">
<thead>
<tr>
{type !== "overline" && <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;
31 changes: 29 additions & 2 deletions apps/docs/components/ui/table/table.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
}

.hd-table__column {
padding-block: var(--hd-space-2);
padding: var(--hd-space-2) var(--hd-space-1);
text-align: left;
color: var(--hd-color-neutral-text-weakest);
font-size: 0.8125rem;
Expand All @@ -15,6 +15,10 @@
line-height: 0.8125rem;
}

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

.hd-table__column:last-child,
.hd-table__cell:last-child {
text-align: right;
Expand All @@ -23,6 +27,29 @@
.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__row > .hd-table__cell:first-child {
padding-left: 0;
}

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

.hd-top__row .hd-table__cell {
border-top: var(--hd-border-size) solid var(--hd-color-neutral-border);
}

.hd-typo__row:has(> :nth-child(5)) .hd-typo__cell:first-child {
padding-left: 0;
}

.hd-typo__row:has(> :nth-child(3)) > .hd-typo__cell,
.hd-typo__row:has(> :nth-child(4)) > .hd-typo__cell {
padding-left: 0;
}
22 changes: 20 additions & 2 deletions apps/docs/content/tokens/getting-started/installation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@ order: 2

# Installation

At the heart of Workleap Design language are tokens, which drive its functionality. They are the key ingredients to everything UI. Workleap brand is dissected into design tokens, they live in the Hopper Design System.
## Package manager

## Command Line
Using your package manager of choice, run the following command to install the tokens package.

### Pnpm

```shell
pnpm add @hopper-ui/tokens
```

### Yarn

```shell
yarn add @hopper-ui/tokens
```

### With Npm

```shell
npm add @hopper-ui/tokens
```
Loading

0 comments on commit 4b1127f

Please sign in to comment.