Skip to content

Commit

Permalink
adds popover (#82)
Browse files Browse the repository at this point in the history
* adds popover component

* adds table docs

* adds inline-code docs
  • Loading branch information
cody-dot-js authored Dec 2, 2023
1 parent bfd6845 commit 16f1b2f
Show file tree
Hide file tree
Showing 15 changed files with 339 additions and 8 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
run: | # Run the prepublish hook to ensure the package is publishable
pnpm run prepublishOnly
- name: Diff Remix Routes 🕵️
run: | # Diff the remix routes
pnpm run gen:remix-routes
- name: Diff Docs Routes Codegen 🕵️
run: | # Diff the docs routes codegen
pnpm run gen:docs-routes
git diff --exit-code
13 changes: 11 additions & 2 deletions app/components/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,26 @@ function Navigation({ className, style }: WithStyleProps) {
<NavLink to="/components/card">Card</NavLink>
</li>
<li>
<NavLink to="/components/code-block">Code Block</NavLink>
<NavLink to="/components/code-block">CodeBlock</NavLink>
</li>
<li>
<NavLink to="/components/inline-code">InlineCode</NavLink>
</li>
<li>
<NavLink to="/components/input">Input</NavLink>
</li>
<li>
<NavLink to="/components/media-object">Media Object</NavLink>
<NavLink to="/components/media-object">MediaObject</NavLink>
</li>
<li>
<NavLink to="/components/popover">Popover</NavLink>
</li>
<li>
<NavLink to="/components/skeleton">Skeleton</NavLink>
</li>
<li>
<NavLink to="/components/table">Table</NavLink>
</li>
</ul>
</ul>
</nav>
Expand Down
2 changes: 1 addition & 1 deletion app/routes/components.code-block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const meta: MetaFunction = () => {
export default function Page() {
return (
<div>
<h1 className="text-5xl font-medium">Code Block</h1>
<h1 className="text-5xl font-medium">CodeBlock</h1>
<p className="mt-4 text-xl text-gray-600">Code blocks render and apply syntax highlighting to blocks of code.</p>

{/* <h2 className="mt-8 text-3xl font-medium">Examples</h2>
Expand Down
31 changes: 31 additions & 0 deletions app/routes/components.inline-code.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { CodeBlock, CodeBlockBody, CodeBlockCode, CodeBlockCopyButton } from "@/code-block";
import { code } from "@/code-block/code";
import { InlineCode } from "@/inline-code";
import type { MetaFunction } from "@vercel/remix";
import { Example } from "~/components/example";

export const meta: MetaFunction = () => {
return [
{ title: "@ngrok/mantle — InlineCode" },
{ name: "description", content: "mantle is ngrok's UI library and design system" },
];
};

export default function Page() {
return (
<div>
<h1 className="text-5xl font-medium">InlineCode</h1>
<p className="mt-4 text-xl text-gray-600">Marks text to signify a short fragment of inline computer code.</p>

<Example className="mt-4">
<InlineCode>npm install @ngrok/mantle</InlineCode>
</Example>
<CodeBlock className="rounded-t-none rounded-b-lg">
<CodeBlockBody>
<CodeBlockCopyButton />
<CodeBlockCode language="tsx">{code`<InlineCode>npm install @ngrok/mantle</InlineCode>`}</CodeBlockCode>
</CodeBlockBody>
</CodeBlock>
</div>
);
}
2 changes: 1 addition & 1 deletion app/routes/components.media-object.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const meta: MetaFunction = () => {
export default function Page() {
return (
<div>
<h1 className="text-5xl font-medium">Media Object</h1>
<h1 className="text-5xl font-medium">MediaObject</h1>
<p className="my-4 text-xl text-gray-600">
The Media Object is an image/icon (media) to the left, with descriptive content (title and subtitle/description)
to the right.
Expand Down
78 changes: 78 additions & 0 deletions app/routes/components.popover.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { Button } from "@/button";
import { CodeBlock, CodeBlockBody, CodeBlockCode, CodeBlockCopyButton } from "@/code-block";
import { code } from "@/code-block/code";
import { Input } from "@/input";
import { Popover, PopoverContent, PopoverTrigger } from "@/popover";
import type { MetaFunction } from "@vercel/remix";
import { Example } from "~/components/example";

export const meta: MetaFunction = () => {
return [
{ title: "@ngrok/mantle — Popover" },
{ name: "description", content: "mantle is ngrok's UI library and design system" },
];
};

export default function Page() {
return (
<div>
<h1 className="text-5xl font-medium">Popover</h1>
<p className="mt-4 text-xl text-gray-600">Displays rich content in a portal, triggered by a button.</p>
<Example className="mt-4 gap-2">
<Popover>
<PopoverTrigger asChild>
<Button>Open popover</Button>
</PopoverTrigger>
<PopoverContent className="w-80">
<form
className="grid gap-4"
onSubmit={(event) => {
event.preventDefault();
}}
>
<div className="space-y-2">
<h4 className="font-medium leading-none">Dimensions</h4>
<p className="text-sm text-muted-foreground">Set the dimensions for the layer.</p>
</div>
<div className="grid gap-2">
<div className="grid grid-cols-3 items-center gap-4">
<label htmlFor="width">Width</label>
<Input id="width" defaultValue="100%" className="col-span-2 h-8" />
</div>
<div className="grid grid-cols-3 items-center gap-4">
<label htmlFor="maxWidth">Max. width</label>
<Input id="maxWidth" defaultValue="300px" className="col-span-2 h-8" />
</div>
<div className="grid grid-cols-3 items-center gap-4">
<label htmlFor="height">Height</label>
<Input id="height" defaultValue="25px" className="col-span-2 h-8" />
</div>
<div className="grid grid-cols-3 items-center gap-4">
<label htmlFor="maxHeight">Max. height</label>
<Input id="maxHeight" defaultValue="none" className="col-span-2 h-8" />
</div>
</div>
</form>
</PopoverContent>
</Popover>
</Example>
<CodeBlock className="rounded-t-none rounded-b-lg">
<CodeBlockBody>
<CodeBlockCopyButton />
<CodeBlockCode language="tsx">
{code`
<Popover>
<PopoverTrigger asChild>
<Button>Open popover</Button>
</PopoverTrigger>
<PopoverContent className="w-80">
<p>Reprehenderit veniam excepteur incididunt et ut eu.</p>
</PopoverContent>
</Popover>
`}
</CodeBlockCode>
</CodeBlockBody>
</CodeBlock>
</div>
);
}
139 changes: 139 additions & 0 deletions app/routes/components.table.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import { CodeBlock, CodeBlockBody, CodeBlockCode, CodeBlockCopyButton } from "@/code-block";
import { code } from "@/code-block/code";
import { Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow } from "@/table";
import type { MetaFunction } from "@vercel/remix";
import { Example } from "~/components/example";

export const meta: MetaFunction = () => {
return [
{ title: "@ngrok/mantle — Table" },
{ name: "description", content: "mantle is ngrok's UI library and design system" },
];
};

export default function Page() {
return (
<div>
<h1 className="text-5xl font-medium">Table</h1>
<p className="mt-4 text-xl text-gray-600">A responsive table component.</p>
<Example className="mt-4 gap-2">
<ExampleTable />
</Example>
<CodeBlock className="rounded-t-none rounded-b-lg">
<CodeBlockBody>
<CodeBlockCopyButton />
<CodeBlockCode language="tsx">
{code`
<Table>
<TableCaption>A list of your recent invoices.</TableCaption>
<TableHeader>
<TableRow>
<TableHead className="w-[100px]">Invoice</TableHead>
<TableHead>Status</TableHead>
<TableHead>Method</TableHead>
<TableHead className="text-right">Amount</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{invoices.map((invoice) => (
<TableRow key={invoice.invoice}>
<TableCell className="font-medium">{invoice.invoice}</TableCell>
<TableCell>{invoice.paymentStatus}</TableCell>
<TableCell>{invoice.paymentMethod}</TableCell>
<TableCell className="text-right">{invoice.totalAmount}</TableCell>
</TableRow>
))}
</TableBody>
<TableFooter>
<TableRow>
<TableCell colSpan={3}>Total</TableCell>
<TableCell className="text-right">$2,500.00</TableCell>
</TableRow>
</TableFooter>
</Table>
`}
</CodeBlockCode>
</CodeBlockBody>
</CodeBlock>
</div>
);
}

const ExampleTable = () => {
const invoices = [
{
invoice: "INV001",
paymentStatus: "Paid",
totalAmount: "$250.00",
paymentMethod: "Credit Card",
},
{
invoice: "INV002",
paymentStatus: "Pending",
totalAmount: "$150.00",
paymentMethod: "PayPal",
},
{
invoice: "INV003",
paymentStatus: "Unpaid",
totalAmount: "$350.00",
paymentMethod: "Bank Transfer",
},
{
invoice: "INV004",
paymentStatus: "Paid",
totalAmount: "$450.00",
paymentMethod: "Credit Card",
},
{
invoice: "INV005",
paymentStatus: "Paid",
totalAmount: "$550.00",
paymentMethod: "PayPal",
},
{
invoice: "INV006",
paymentStatus: "Pending",
totalAmount: "$200.00",
paymentMethod: "Bank Transfer",
},
{
invoice: "INV007",
paymentStatus: "Unpaid",
totalAmount: "$300.00",
paymentMethod: "Credit Card",
},
];

return (
<div className="mt-4 rounded-lg border border-gray-300 overflow-hidden z-10">
<Table>
<TableCaption>A list of your recent invoices.</TableCaption>
<TableHeader>
<TableRow>
<TableHead className="w-[100px]">Invoice</TableHead>
<TableHead>Status</TableHead>
<TableHead>Method</TableHead>
<TableHead className="text-right">Amount</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{invoices.map((invoice) => (
<TableRow key={invoice.invoice}>
<TableCell className="font-medium">{invoice.invoice}</TableCell>
<TableCell>{invoice.paymentStatus}</TableCell>
<TableCell>{invoice.paymentMethod}</TableCell>
<TableCell className="text-right">{invoice.totalAmount}</TableCell>
</TableRow>
))}
</TableBody>
<TableFooter>
<TableRow>
<TableCell colSpan={3}>Total</TableCell>
<TableCell className="text-right">$2,500.00</TableCell>
</TableRow>
</TableFooter>
</Table>
</div>
);
};
6 changes: 6 additions & 0 deletions app/types/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ export const routePatterns = [
"/components/button",
"/components/card",
"/components/code-block",
"/components/inline-code",
"/components/input",
"/components/media-object",
"/components/popover",
"/components/skeleton",
"/components/table",
] as const;

export type RoutePattern = (typeof routePatterns)[number];
Expand All @@ -28,9 +31,12 @@ export const routes = [
"/components/button",
"/components/card",
"/components/code-block",
"/components/inline-code",
"/components/input",
"/components/media-object",
"/components/popover",
"/components/skeleton",
"/components/table",
] as const;

export type Route = (typeof routes)[number];
Expand Down
1 change: 1 addition & 0 deletions components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export {
export { InlineCode } from "./inline-code";
export { Input } from "./input";
export { MediaObject, MediaObjectMedia, MediaObjectContent } from "./media-object";
export { Popover, PopoverTrigger, PopoverContent } from "./popover";
export {
Select,
SelectContent,
Expand Down
28 changes: 28 additions & 0 deletions components/popover/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import * as PopoverPrimitive from "@radix-ui/react-popover";
import { ComponentPropsWithoutRef, ElementRef, forwardRef } from "react";
import { cx } from "../cx";

const Popover = PopoverPrimitive.Root;

const PopoverTrigger = PopoverPrimitive.Trigger;

const PopoverContent = forwardRef<
ElementRef<typeof PopoverPrimitive.Content>,
ComponentPropsWithoutRef<typeof PopoverPrimitive.Content>
>(({ className, align = "center", sideOffset = 4, ...props }, ref) => (
<PopoverPrimitive.Portal>
<PopoverPrimitive.Content
ref={ref}
align={align}
sideOffset={sideOffset}
className={cx(
"z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
className,
)}
{...props}
/>
</PopoverPrimitive.Portal>
));
PopoverContent.displayName = PopoverPrimitive.Content.displayName;

export { Popover, PopoverTrigger, PopoverContent };
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"docs:serve": "remix-serve ./build/index.js",
"fmt:check": "prettier --cache --check .",
"fmt": "prettier --write --cache .",
"gen:remix-routes": "tsx scripts/gen-remix-routes",
"gen:docs-routes": "tsx scripts/gen-docs-routes",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"prepublishOnly": "rm -rf dist && rollup -c",
"storybook": "pnpm run cmd:storybook dev -p 6006",
Expand All @@ -49,6 +49,7 @@
"@radix-ui/react-dialog": "1.0.5",
"@radix-ui/react-dropdown-menu": "2.0.6",
"@radix-ui/react-icons": "1.3.0",
"@radix-ui/react-popover": "1.0.7",
"@radix-ui/react-select": "2.0.0",
"@radix-ui/react-slot": "1.0.2",
"@radix-ui/react-tooltip": "1.0.7",
Expand Down
Loading

1 comment on commit 16f1b2f

@vercel
Copy link

@vercel vercel bot commented on 16f1b2f Dec 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.