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

feat: add font docs #39

Merged
merged 4 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Overview
description: Design tokens overview
draft: false
draft: true
---

Overview
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Colours
title: Colour
description: Colour information
draft: true
status: in-development
Expand Down
26 changes: 26 additions & 0 deletions apps/docs/content/2-foundations/1-design-tokens/3-font.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
title: Font
description: Font information
draft: true
status: in-development
---

## Font family

<FontFamilyTable />

## Font sizes

<FontSizeTable />

## Font weights

<FontWeightTable />

## Line heights

<LineHeightTable />

## Letter spacing

<LetterSpacingTable />
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@ draft: true
status: in-development
---

## Font Sizes

<FontSizesTable />

## Font Weights

<FontWeightsTable />

## Typography

<Typography />
14 changes: 9 additions & 5 deletions apps/docs/src/app/[...slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { notFound } from 'next/navigation';
import { Mdx } from '@/components/document/mdx';
import * as documents from '@/lib/documents/documents';
import { DocumentStatus } from '@/components/document/document-status';
import { Draft } from '@/components/document/draft';

type DocPageProps = {
params: {
Expand All @@ -18,11 +19,14 @@ export default function DocPage({ params }: DocPageProps) {

return (
<section className="flex flex-col gap-2xl grow">
{document.status !== 'stable' ? (
<div>
<DocumentStatus status={document.status} />
</div>
) : null}
<div className="flex justify-between items-center">
{document.status !== 'stable' ? (
<div>
<DocumentStatus status={document.status} />
</div>
) : null}
{document.draft ? <Draft /> : null}
</div>
{document.status !== 'coming-soon' ? (
<div>
<Mdx code={document.body.code} />
Expand Down
14 changes: 14 additions & 0 deletions apps/docs/src/components/document/draft.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { cn } from '@/lib/cn';

export function Draft() {
return (
<span
className={cn(
`px-lg py-xs text-sm font-semibold rounded`,
'text-gray-700 bg-gray-100',
)}
>
Draft
</span>
);
}
14 changes: 10 additions & 4 deletions apps/docs/src/components/document/mdx.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { useMDXComponent } from 'next-contentlayer/hooks';
import { Heading } from '../typography/heading';
import { ColorPrimitives } from '@/components/document/color/color-primitives';
import { FontSizesTable } from './typography/font-sizes-table';
import { FontWeightsTable } from './typography/font-weights-table';
import { FontFamilyTable } from './typography/font-family-table';
import { FontSizeTable } from './typography/font-size-table';
import { FontWeightTable } from './typography/font-weight-table';
import { LineHeightTable } from './typography/line-height-table';
import { LetterSpacingTable } from './typography/letter-spacing-table';
import { Typography } from './typography/typography';

export type MdxProps = {
Expand All @@ -17,8 +20,11 @@ export function Mdx({ code }: MdxProps) {
components={{
h2: ({ children }) => <Heading as="h2">{children}</Heading>,
ColorPrimitives: () => <ColorPrimitives />,
FontSizesTable: () => <FontSizesTable />,
FontWeightsTable: () => <FontWeightsTable />,
FontFamilyTable: () => <FontFamilyTable />,
FontSizeTable: () => <FontSizeTable />,
FontWeightTable: () => <FontWeightTable />,
LineHeightTable: () => <LineHeightTable />,
LetterSpacingTable: () => <LetterSpacingTable />,
Typography: () => <Typography />,
}}
/>
Expand Down
15 changes: 15 additions & 0 deletions apps/docs/src/components/document/typography/font-family-table.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { meta } from '@govie-ds/theme-govie';
import { FontTable } from './font-table';

export function FontFamilyTable() {
return (
<FontTable<string[]>
name="font-family"
tokens={meta.light.resolved.primitive.font.family}
renderValue={(value) => value.join(', ')}
renderExample={(value) => (
<span style={{ fontFamily: value.join(', ') }}>Sample text</span>
)}
/>
);
}
15 changes: 15 additions & 0 deletions apps/docs/src/components/document/typography/font-size-table.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { meta } from '@govie-ds/theme-govie';
import { FontTable } from './font-table';

export function FontSizeTable() {
return (
<FontTable<string>
name="font-size"
tokens={meta.light.resolved.primitive.font.size}
renderValue={(value) => value}
renderExample={(value) => (
<span style={{ fontSize: value }}>Sample text</span>
)}
/>
);
}
26 changes: 0 additions & 26 deletions apps/docs/src/components/document/typography/font-sizes-table.tsx

This file was deleted.

35 changes: 35 additions & 0 deletions apps/docs/src/components/document/typography/font-table.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Table, Td } from './table';
import { TokenName } from '../color/token-name';
import { objectKeys } from 'ts-extras';

export function FontTable<TValue>({
name,
tokens,
renderValue,
renderExample,
}: {
name: string;
tokens: Record<string, { $value: TValue }>;
renderValue: (value: TValue) => React.ReactNode;
renderExample: (value: TValue) => React.ReactNode;
}) {
return (
<Table
headers={['Token', 'Value', 'Example']}
ids={objectKeys(tokens)}
renderRow={(id) => {
const { $value: value } = tokens[id];

return (
<tr key={id}>
<Td className="whitespace-nowrap w-[1px] text-sm">
<TokenName name={`${name}/${id}`} />
</Td>
<Td className="text-sm">{renderValue(value)}</Td>
<Td>{renderExample(value)}</Td>
</tr>
);
}}
/>
);
}
15 changes: 15 additions & 0 deletions apps/docs/src/components/document/typography/font-weight-table.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { meta } from '@govie-ds/theme-govie';
import { FontTable } from './font-table';

export function FontWeightTable() {
return (
<FontTable<string>
name="font-weight"
tokens={meta.light.resolved.primitive.font.size}
renderValue={(value) => value}
renderExample={(value) => (
<span style={{ fontWeight: value }}>Sample text</span>
)}
/>
);
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { meta } from '@govie-ds/theme-govie';
import { FontTable } from './font-table';

export function LetterSpacingTable() {
return (
<FontTable<string>
name="letter-spacing"
tokens={meta.light.resolved.primitive.font.letterSpacing}
renderValue={(value) => value}
renderExample={(value) => (
<span style={{ letterSpacing: value }}>Sample text</span>
)}
/>
);
}
15 changes: 15 additions & 0 deletions apps/docs/src/components/document/typography/line-height-table.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { meta } from '@govie-ds/theme-govie';
import { FontTable } from './font-table';

export function LineHeightTable() {
return (
<FontTable<number>
name="line-height"
tokens={meta.light.resolved.primitive.font.lineHeight}
renderValue={(value) => value}
renderExample={(value) => (
<span style={{ lineHeight: value }}>Sample text</span>
)}
/>
);
}
Loading