Skip to content

Commit

Permalink
feat: add some stories
Browse files Browse the repository at this point in the history
  • Loading branch information
nahoc committed Aug 1, 2024
1 parent 66e932c commit 0a32ae9
Show file tree
Hide file tree
Showing 14 changed files with 410 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .ladle/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const Provider: GlobalProvider = ({ children, globalState }) => {
}, [globalState.theme, setTheme]);

return (
<div className="container bg-background font-sans" style={{ maxWidth: 800 }}>
<div className="container" style={{ maxWidth: 800 }}>
<ThemeProvider
attribute="class"
defaultTheme="light"
Expand Down
27 changes: 18 additions & 9 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
node_modules
# misc
.github
.husky
.gitignore
biome.jsonc
components.json
.husky
node_modules

# typescript
tsconfig.json
tsconfig.tsbuildinfo

# tests
*.test.*
*.spec.*
vitest.config.ts
setup-tests.ts
coverage
setup-tests.ts
vitest.config.ts

# stories
.ladle
tailwind.config.ts
postcss.config.cjs
stories
tsconfig.json

# config files only for risc0-ui
biome.jsonc
components.json
postcss.config.cjs
tailwind.config.ts
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ https://www.npmjs.com/package/@risc0/ui

| Statements | Branches | Functions | Lines |
| --------------------------- | ----------------------- | ------------------------- | ----------------- |
| ![Statements](https://img.shields.io/badge/statements-39.66%25-red.svg?style=flat) | ![Branches](https://img.shields.io/badge/branches-66.19%25-red.svg?style=flat) | ![Functions](https://img.shields.io/badge/functions-41.17%25-red.svg?style=flat) | ![Lines](https://img.shields.io/badge/lines-39.66%25-red.svg?style=flat) |
| ![Statements](https://img.shields.io/badge/statements-34.66%25-red.svg?style=flat) | ![Branches](https://img.shields.io/badge/branches-60.25%25-red.svg?style=flat) | ![Functions](https://img.shields.io/badge/functions-34.14%25-red.svg?style=flat) | ![Lines](https://img.shields.io/badge/lines-34.66%25-red.svg?style=flat) |
2 changes: 1 addition & 1 deletion button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ const Button = forwardRef<HTMLButtonElement, ButtonProps>(
<Loader2Icon
data-testid="loader-icon"
className={cn(
iconVariants({}),
"animate-spin",
!startIcon && "transition-all",
isLoading ? "mr-2 max-w-4 opacity-100" : "mr-0 max-w-0 opacity-0",
iconVariants({ size }),
)}
/>
{!isLoading &&
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@risc0/ui",
"version": "0.0.140",
"version": "0.0.142",
"private": false,
"sideEffects": false,
"type": "module",
Expand Down Expand Up @@ -36,8 +36,8 @@
"class-variance-authority": "0.7.1-canary.2",
"clsx": "2.1.1",
"cmdk": "1.0.0",
"lucide-react": "0.417.0",
"next": "15.0.0-canary.91",
"lucide-react": "0.418.0",
"next": "15.0.0-canary.95",
"next-themes": "0.3.0",
"radash": "12.1.0",
"react-hook-form": "7.52.1",
Expand All @@ -48,7 +48,7 @@
"tailwind-merge": "2.4.0",
"tailwindcss": "3.4.7",
"tailwindcss-animate": "1.0.7",
"typescript": "5.6.0-dev.20240730",
"typescript": "5.6.0-dev.20240801",
"vaul": "0.9.1"
},
"devDependencies": {
Expand All @@ -59,7 +59,7 @@
"@testing-library/react-hooks": "8.0.1",
"@types/jest": "29.5.12",
"@vitejs/plugin-react-swc": "3.7.0",
"@vitest/coverage-v8": "2.0.4",
"@vitest/coverage-v8": "2.0.5",
"deepmerge": "4.3.1",
"happy-dom": "14.12.3",
"istanbul-badges-readme": "1.9.0",
Expand Down
2 changes: 1 addition & 1 deletion slider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe("Slider", () => {
render(<Slider />);
const thumbElement = screen.getByTestId("slider-thumb");
expect(thumbElement).toHaveClass(
"block size-4 rounded-full border border-primary/50 bg-background shadow transition-colors disabled:pointer-events-none disabled:opacity-50 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",
"block size-4 rounded-full border border-primary/50 bg-background transition-colors disabled:pointer-events-none disabled:opacity-50 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",
);
});
});
2 changes: 1 addition & 1 deletion slider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const Slider = forwardRef<
</SliderPrimitive.Track>
<SliderPrimitive.Thumb
data-testid="slider-thumb"
className="block size-4 cursor-grab rounded-full border border-primary/50 bg-background shadow transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring active:cursor-grabbing disabled:pointer-events-none disabled:opacity-50"
className="block size-4 cursor-grab rounded-full border border-primary/50 bg-background transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring active:cursor-grabbing disabled:pointer-events-none disabled:opacity-50"
/>
</SliderPrimitive.Root>
));
Expand Down
44 changes: 44 additions & 0 deletions stories/breadcrumb.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import {
Breadcrumb,
BreadcrumbEllipsis,
BreadcrumbItem,
BreadcrumbLink,
BreadcrumbList,
BreadcrumbPage,
BreadcrumbSeparator,
} from "breadcrumb";
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "dropdown-menu";

export const Default = () => {
return (
<Breadcrumb>
<BreadcrumbList>
<BreadcrumbItem>
<BreadcrumbLink href="/?story=breadcrumb--default">Home</BreadcrumbLink>
</BreadcrumbItem>
<BreadcrumbSeparator />
<BreadcrumbItem>
<DropdownMenu>
<DropdownMenuTrigger className="flex items-center gap-1">
<BreadcrumbEllipsis className="h-4 w-4" />
<span className="sr-only">Toggle menu</span>
</DropdownMenuTrigger>
<DropdownMenuContent align="start">
<DropdownMenuItem>Documentation</DropdownMenuItem>
<DropdownMenuItem>Themes</DropdownMenuItem>
<DropdownMenuItem>GitHub</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</BreadcrumbItem>
<BreadcrumbSeparator />
<BreadcrumbItem>
<BreadcrumbLink href="/?story=breadcrumb--default">Components</BreadcrumbLink>
</BreadcrumbItem>
<BreadcrumbSeparator />
<BreadcrumbItem>
<BreadcrumbPage>Breadcrumb</BreadcrumbPage>
</BreadcrumbItem>
</BreadcrumbList>
</Breadcrumb>
);
};
179 changes: 179 additions & 0 deletions stories/button.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
import { Button, type ButtonProps } from "button";
import { Label } from "label";
import { RocketIcon } from "lucide-react";
import { RadioGroup, RadioGroupItem } from "radio-group";
import { useState } from "react";

export const All = () => {
const [variant, setVariant] = useState<ButtonProps["variant"]>("default");

return (
<>
<RadioGroup
// @ts-expect-error
onValueChange={setVariant}
defaultValue="default"
className="mb-8 flex flex-row gap-8"
>
<div className="flex items-center space-x-2">
<RadioGroupItem value="default" id="r1" />
<Label htmlFor="r1">Default</Label>
</div>
<div className="flex items-center space-x-2">
<RadioGroupItem value="secondary" id="r2" />
<Label htmlFor="r2">Secondary</Label>
</div>
<div className="flex items-center space-x-2">
<RadioGroupItem value="destructive" id="r3" />
<Label htmlFor="r3">Destructive</Label>
</div>
<div className="flex items-center space-x-2">
<RadioGroupItem value="outline" id="r4" />
<Label htmlFor="r4">Outline</Label>
</div>
<div className="flex items-center space-x-2">
<RadioGroupItem value="ghost" id="r5" />
<Label htmlFor="r5">Ghost</Label>
</div>
</RadioGroup>

<div className="flex flex-col items-start gap-8">
<div className="flex flex-row gap-5">
<Button variant={variant} size="sm">
Small
</Button>

<Button startIcon={<RocketIcon />} variant={variant} size="sm">
With Start Icon
</Button>

<Button endIcon={<RocketIcon />} variant={variant} size="sm">
With End Icon
</Button>

<Button variant={variant} size="sm" isLoading>
Loading
</Button>

<Button variant={variant} size="sm" disabled>
Disabled
</Button>

<Button variant={variant} isLoading size="sm" disabled>
Disabled Loading
</Button>
</div>

<div className="flex flex-row gap-5">
<Button variant={variant} size="default">
Medium
</Button>

<Button startIcon={<RocketIcon />} variant={variant} size="default">
With Start Icon
</Button>

<Button endIcon={<RocketIcon />} variant={variant} size="default">
With End Icon
</Button>

<Button variant={variant} size="default" isLoading>
Loading
</Button>

<Button variant={variant} size="default" disabled>
Disabled
</Button>

<Button variant={variant} isLoading size="default" disabled>
Disabled Loading
</Button>
</div>

<div className="flex flex-row gap-5">
<Button variant={variant} size="lg">
Large
</Button>

<Button startIcon={<RocketIcon />} variant={variant} size="lg">
With Start Icon
</Button>

<Button endIcon={<RocketIcon />} variant={variant} size="lg">
With End Icon
</Button>

<Button variant={variant} size="lg" isLoading>
Loading
</Button>

<Button variant={variant} size="lg" disabled>
Disabled
</Button>

<Button variant={variant} isLoading size="lg" disabled>
Disabled Loading
</Button>
</div>
</div>
</>
);
};

export const IconButtons = () => {
const [variant, setVariant] = useState<ButtonProps["variant"]>("default");

return (
<>
<RadioGroup
// @ts-expect-error
onValueChange={setVariant}
defaultValue="default"
className="mb-8 flex flex-row gap-8"
>
<div className="flex items-center space-x-2">
<RadioGroupItem value="default" id="r1" />
<Label htmlFor="r1">Default</Label>
</div>
<div className="flex items-center space-x-2">
<RadioGroupItem value="secondary" id="r2" />
<Label htmlFor="r2">Secondary</Label>
</div>
<div className="flex items-center space-x-2">
<RadioGroupItem value="destructive" id="r3" />
<Label htmlFor="r3">Destructive</Label>
</div>
<div className="flex items-center space-x-2">
<RadioGroupItem value="outline" id="r4" />
<Label htmlFor="r4">Outline</Label>
</div>
<div className="flex items-center space-x-2">
<RadioGroupItem value="ghost" id="r5" />
<Label htmlFor="r5">Ghost</Label>
</div>
</RadioGroup>

<div className="flex flex-col items-start gap-8">
<div className="flex flex-row gap-5">
<Button startIcon={<RocketIcon />} variant={variant} size="icon-sm" />

<Button startIcon={<RocketIcon />} variant={variant} size="icon-sm" isLoading />

<Button startIcon={<RocketIcon />} variant={variant} size="icon-sm" disabled />

<Button startIcon={<RocketIcon />} variant={variant} isLoading size="icon-sm" disabled />
</div>

<div className="flex flex-row gap-5">
<Button startIcon={<RocketIcon />} variant={variant} size="icon" />

<Button startIcon={<RocketIcon />} variant={variant} size="icon" isLoading />

<Button startIcon={<RocketIcon />} variant={variant} size="icon" disabled />

<Button startIcon={<RocketIcon />} variant={variant} isLoading size="icon" disabled />
</div>
</div>
</>
);
};
44 changes: 44 additions & 0 deletions stories/card.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Button } from "button";
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "card";
import { Input } from "input";
import { Label } from "label";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "select";

export const Default = () => {
return (
<Card className="w-[350px]">
<CardHeader>
<CardTitle>Create project</CardTitle>
<CardDescription>Deploy your new project in one-click</CardDescription>
</CardHeader>
<CardContent>
<form>
<div className="grid w-full items-center gap-4">
<div className="flex flex-col space-y-1.5">
<Label htmlFor="name">Name</Label>
<Input id="name" placeholder="Name of your project" />
</div>
<div className="flex flex-col space-y-1.5">
<Label htmlFor="framework">Framework</Label>
<Select>
<SelectTrigger id="framework">
<SelectValue placeholder="Select" />
</SelectTrigger>
<SelectContent position="popper">
<SelectItem value="next">Next.js</SelectItem>
<SelectItem value="sveltekit">SvelteKit</SelectItem>
<SelectItem value="astro">Astro</SelectItem>
<SelectItem value="nuxt">Nuxt.js</SelectItem>
</SelectContent>
</Select>
</div>
</div>
</form>
</CardContent>
<CardFooter className="flex justify-between">
<Button variant="outline">Cancel</Button>
<Button>Deploy</Button>
</CardFooter>
</Card>
);
};
Loading

0 comments on commit 0a32ae9

Please sign in to comment.