Skip to content

Commit

Permalink
docs: Primitive props documentation (#241)
Browse files Browse the repository at this point in the history
* docs: Primitive props documentation

* Add a composition guide
  • Loading branch information
Yonom authored Jun 19, 2024
1 parent 014ecbf commit 7b8dbb7
Show file tree
Hide file tree
Showing 16 changed files with 1,889 additions and 467 deletions.
52 changes: 52 additions & 0 deletions apps/www/components/docs/DataAttributesTable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Box, Code, Table, Text } from "@radix-ui/themes";
import React from "react";

type KeyboardDef = {
attribute: string;
values: string;
};

export function DataAttributesTable({ data }: { data: KeyboardDef[] }) {
return (
<Box my="5" asChild>
<Table.Root variant="surface">
<Table.Header>
<Table.Row>
<Table.ColumnHeaderCell style={{ width: "37%" }}>
Data attribute
</Table.ColumnHeaderCell>
<Table.ColumnHeaderCell>Values</Table.ColumnHeaderCell>
</Table.Row>
</Table.Header>

<Table.Body>
{data.map(({ attribute, values }, i) => {
const key = `${attribute}-${i}`;
return (
<Table.Row key={key}>
<Table.RowHeaderCell>
<Code size="2">{attribute}</Code>
</Table.RowHeaderCell>

<Table.Cell>
{Array.isArray(values) ? (
<Code size="2" color="gray">
{values.map(
(value, index) =>
`"${value}" ${values.length !== index + 1 ? " | " : ""}`,
)}
</Code>
) : (
<Text as="p" size="2">
{values}
</Text>
)}
</Table.Cell>
</Table.Row>
);
})}
</Table.Body>
</Table.Root>
</Box>
);
}
43 changes: 43 additions & 0 deletions apps/www/components/docs/KeyboardTable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Box, Flex, Kbd, Table } from "@radix-ui/themes";
import type React from "react";

type KeyboardDef = {
keys: string[];
description: React.ReactNode;
};

export function KeyboardTable({ data }: { data: KeyboardDef[] }) {
return (
<Box my="5" asChild>
<Table.Root variant="surface">
<Table.Header>
<Table.Row>
<Table.ColumnHeaderCell style={{ width: "37%" }}>
Key
</Table.ColumnHeaderCell>
<Table.ColumnHeaderCell>Description</Table.ColumnHeaderCell>
</Table.Row>
</Table.Header>

<Table.Body>
{data.map(({ keys, description }, i) => {
const key = `${description}-${i}`;
return (
<Table.Row key={key}>
<Table.Cell>
<Flex gap="2">
{keys.map((k) => (
<Kbd key={k}>{k}</Kbd>
))}
</Flex>
</Table.Cell>

<Table.Cell>{description}</Table.Cell>
</Table.Row>
);
})}
</Table.Body>
</Table.Root>
</Box>
);
}
168 changes: 168 additions & 0 deletions apps/www/components/docs/PropsTable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
import { AccessibleIcon } from "@radix-ui/react-accessible-icon";
import { DividerHorizontalIcon, InfoCircledIcon } from "@radix-ui/react-icons";
import {
Box,
Code,
Flex,
IconButton,
Inset,
Popover,
ScrollArea,
Table,
} from "@radix-ui/themes";
import type React from "react";

export type PropDef = {
name: string;
required?: boolean;
default?: string | boolean;
type?: string;
typeSimple: string;
description?: string | React.ReactNode;
};

export function PropsTable({
data,
propHeaderFixedWidth = true,
}: {
data: PropDef[];
propHeaderFixedWidth?: boolean;
}) {
return (
<Box my="5" asChild>
<Table.Root variant="surface">
<Table.Header>
<Table.Row>
<Table.ColumnHeaderCell
style={{ width: propHeaderFixedWidth ? "37%" : "auto" }}
>
Prop
</Table.ColumnHeaderCell>
<Table.ColumnHeaderCell>Type</Table.ColumnHeaderCell>
<Table.ColumnHeaderCell>Default</Table.ColumnHeaderCell>
</Table.Row>
</Table.Header>

<Table.Body>
{data.map(
(
{
name,
type,
typeSimple,
required,
default: defaultValue,
description,
},
i,
) => {
const key = `${name}-${i}`;
return (
<Table.Row key={key} style={{ whiteSpace: "nowrap" }}>
<Table.RowHeaderCell>
<Flex display="inline-flex" align="center" gap="2">
<Box>
<Code size="2">
{name}
{required ? "*" : null}
</Code>
</Box>
{description && (
<Popover.Root>
<Popover.Trigger>
<IconButton variant="ghost" size="1" color="gray">
<AccessibleIcon label="Prop description">
<InfoCircledIcon />
</AccessibleIcon>
</IconButton>
</Popover.Trigger>
<Popover.Content
side="top"
align="center"
style={{ maxWidth: 350 }}
className="radix-themes-custom-fonts"
onOpenAutoFocus={(event) => {
event.preventDefault();
(event.currentTarget as HTMLElement)?.focus();
}}
>
<div className="text-sm">{description}</div>
</Popover.Content>
</Popover.Root>
)}
</Flex>
</Table.RowHeaderCell>
<Table.Cell>
<Flex display="inline-flex" align="center" gap="2">
<Box>
<Code color="gray" size="2">
{typeSimple ? typeSimple : type}
</Code>
</Box>
{Boolean(typeSimple) && Boolean(type) && (
<Popover.Root>
<Popover.Trigger>
<IconButton variant="ghost" color="gray" size="1">
<AccessibleIcon label="See full type">
<InfoCircledIcon />
</AccessibleIcon>
</IconButton>
</Popover.Trigger>
<Popover.Content
side="top"
align="center"
style={{ maxWidth: "min(1240px, 95vw)" }}
>
<Inset>
<ScrollArea type="auto">
<Box
style={{
paddingTop: "var(--inset-padding-top)",
paddingRight: "var(--inset-padding-right)",
paddingBottom:
"var(--inset-padding-bottom)",
paddingLeft: "var(--inset-padding-left)",
}}
>
<Code
color="gray"
variant="ghost"
size="2"
style={{
whiteSpace: "pre",
display: "block",
}}
>
{type}
</Code>
</Box>
</ScrollArea>
</Inset>
</Popover.Content>
</Popover.Root>
)}
</Flex>
</Table.Cell>

<Table.Cell>
{defaultValue ? (
<Code size="2" color="gray">
{defaultValue}
</Code>
) : (
<AccessibleIcon label="No default value">
<DividerHorizontalIcon
style={{ color: "var(--gray-8)" }}
/>
</AccessibleIcon>
)}
</Table.Cell>
</Table.Row>
);
},
)}
</Table.Body>
</Table.Root>
</Box>
);
}
3 changes: 3 additions & 0 deletions apps/www/components/docs/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { PropsTable } from "./PropsTable";
export { KeyboardTable } from "./KeyboardTable";
export { DataAttributesTable } from "./DataAttributesTable";
4 changes: 3 additions & 1 deletion apps/www/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
"@ai-sdk/react": "^0.0.2",
"@assistant-ui/react": "workspace:*",
"@assistant-ui/react-ai-sdk": "workspace:*",
"assistant-ui": "workspace:*",
"@calcom/embed-react": "^1.5.0",
"@fortawesome/fontawesome-svg-core": "^6.5.2",
"@fortawesome/free-solid-svg-icons": "^6.5.2",
"@fortawesome/react-fontawesome": "^0.2.2",
"@radix-ui/react-accessible-icon": "^1.0.3",
"@radix-ui/react-avatar": "^1.0.4",
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-dropdown-menu": "^2.0.6",
Expand All @@ -27,7 +27,9 @@
"@radix-ui/react-select": "^2.0.0",
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-tooltip": "^1.0.7",
"@radix-ui/themes": "^3.0.5",
"ai": "^3.1.36",
"assistant-ui": "workspace:*",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"lucide-react": "^0.395.0",
Expand Down
11 changes: 8 additions & 3 deletions apps/www/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import React from "react";
import "./styles.css";
import { TooltipProvider } from "@/components/ui/tooltip";
import type { AppProps } from "next/app";
import Head from "next/head";
import React from "react";

import "./styles.css";
import "@radix-ui/themes/styles.css";
import { Theme } from "@radix-ui/themes";

export default function MyApp({ Component, pageProps }: AppProps) {
return (
Expand All @@ -12,7 +15,9 @@ export default function MyApp({ Component, pageProps }: AppProps) {
<link rel="icon" type="image/svg+xml" href="/favicon/favicon.svg" />
<link rel="icon" type="image/png" href="/favicon/favicon.png" />
</Head>
<Component {...pageProps} />
<Theme>
<Component {...pageProps} />
</Theme>
</TooltipProvider>
</>
);
Expand Down
Loading

0 comments on commit 7b8dbb7

Please sign in to comment.