Skip to content

Commit 734e9d4

Browse files
committed
input examples -> default, label, error
1 parent 7db6665 commit 734e9d4

File tree

10 files changed

+123
-5
lines changed

10 files changed

+123
-5
lines changed

config/components.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ export const componentConfig: {
4949
name: "dialog",
5050
filePath: "packages/ui/Dialog/Dialog.tsx",
5151
},
52+
input: {
53+
name: "input",
54+
filePath: "packages/ui/Input.tsx",
55+
},
5256
menu: {
5357
name: "menu",
5458
filePath: "packages/ui/Menu/Menu.tsx",
@@ -200,6 +204,18 @@ export const componentConfig: {
200204
filePath: "preview/components/input-style-default.tsx",
201205
preview: lazy(() => import("@/preview/components/input-style-default")),
202206
},
207+
"input-style-with-label": {
208+
name: "input-style-with-label",
209+
filePath: "preview/components/input-style-with-label.tsx",
210+
preview: lazy(
211+
() => import("@/preview/components/input-style-with-label")
212+
),
213+
},
214+
"input-style-error": {
215+
name: "input-style-error",
216+
filePath: "preview/components/input-style-error.tsx",
217+
preview: lazy(() => import("@/preview/components/input-style-error")),
218+
},
203219
"menu-style-default": {
204220
name: "menu-style-default",
205221
filePath: "preview/components/menu-style-default.tsx",

content/docs/components/input.mdx

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,36 @@
11
---
22
title: Input
33
description: This pretty input makes your users want to type stuff! ⌨️
4-
lastUpdated: 08 Oct, 2024
4+
lastUpdated: 04 Mar, 2024
55
---
66

7-
### Default
7+
<ComponentShowcase name="input-style-default" />
8+
<br />
9+
<br />
10+
11+
## Installation
812

9-
<hr />
13+
#### 1. Copy the code 👇 into your project:
14+
15+
<ComponentSource name="input" />
16+
<br />
1017
<br />
18+
19+
## Examples
20+
21+
### Default
22+
1123
<ComponentShowcase name="input-style-default" />
24+
<br />
25+
<br />
26+
27+
### With label
28+
29+
<ComponentShowcase name="input-style-with-label" />
30+
<br />
31+
<br />
32+
33+
### Error
34+
35+
<ComponentShowcase name="input-style-error" />
36+
<br />

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"@radix-ui/react-checkbox": "^1.1.4",
1616
"@radix-ui/react-dialog": "^1.1.2",
1717
"@radix-ui/react-dropdown-menu": "^2.1.2",
18+
"@radix-ui/react-label": "^2.1.2",
1819
"@radix-ui/react-radio-group": "^1.2.3",
1920
"@radix-ui/react-select": "^2.1.6",
2021
"@radix-ui/react-switch": "^1.1.3",

packages/ui/Form/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
export * from "./Input";
21
export * from "./Textarea";
32
export * from "./Checkbox";
43
export * from "./Radio";

packages/ui/Form/Input.tsx renamed to packages/ui/Input.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@ export const Input: React.FC<InputProps> = ({
1010
className = "",
1111
...props
1212
}) => {
13+
console.log(props);
1314
return (
1415
<input
1516
type={type}
1617
placeholder={placeholder}
17-
className={`px-4 py-2 w-full border-2 border-black shadow-md transition focus:outline-none focus:shadow-xs ${className}`}
18+
className={`px-4 py-2 w-full border-2 border-black shadow-md transition focus:outline-none focus:shadow-xs ${
19+
props["aria-invalid"]
20+
? "border-red-500 text-red-500 shadow-xs shadow-red-600"
21+
: ""
22+
} ${className}`}
1823
{...props}
1924
/>
2025
);

packages/ui/Label.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import * as React from "react";
2+
import * as LabelPrimitive from "@radix-ui/react-label";
3+
import { cva } from "class-variance-authority";
4+
5+
import { cn } from "@/lib/utils";
6+
7+
const labelVariants = cva(
8+
"leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
9+
);
10+
11+
const Label = ({
12+
className,
13+
...props
14+
}: React.ComponentProps<typeof LabelPrimitive.Root>) => (
15+
<LabelPrimitive.Root className={cn(labelVariants(), className)} {...props} />
16+
);
17+
18+
export { Label };

packages/ui/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ export * from "./Badges";
99
export * from "./Tabs";
1010
export * from "./Dialog";
1111
export * from "./Menu";
12+
export * from "./Input";
13+
export * from "./Label";

pnpm-lock.yaml

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Input, Label } from "@/packages/ui";
2+
3+
export default function InputStyleError() {
4+
return (
5+
<div className="grid w-full max-w-sm items-center gap-1.5">
6+
<Label htmlFor="pokemon">Favorite Pokemon</Label>
7+
<Input
8+
type="pokemon"
9+
id="pokemon"
10+
placeholder="Charmander"
11+
defaultValue="Son Goku"
12+
aria-invalid
13+
/>
14+
<p className="text-sm text-red-500">Please provide a valid pokemon!</p>
15+
</div>
16+
);
17+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { Input, Label } from "@/packages/ui";
2+
3+
export default function InputStyleWithLabel() {
4+
return (
5+
<div className="grid w-full max-w-sm items-center gap-1.5">
6+
<Label htmlFor="pokemon">Favorite Pokemon</Label>
7+
<Input type="pokemon" id="pokemon" placeholder="Charmander" />
8+
</div>
9+
);
10+
}

0 commit comments

Comments
 (0)