Skip to content

Commit a068cd1

Browse files
authored
Merge pull request #40 from Logging-Stuff/select
Select
2 parents 386f116 + bf7bef4 commit a068cd1

File tree

14 files changed

+555
-36
lines changed

14 files changed

+555
-36
lines changed

app/(sink)/demo/components/page.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
Button,
99
Checkbox,
1010
Menu,
11+
Select,
1112
Tabs,
1213
TabsContent,
1314
TabsPanels,
@@ -43,11 +44,18 @@ export default function page() {
4344
</div>
4445

4546
<div className="space-x-4">
46-
<RadioGroup>
47-
<RadioGroup.Item value="1">Option 1</RadioGroup.Item>
48-
<RadioGroup.Item value="2">Option 2</RadioGroup.Item>
49-
<RadioGroup.Item value="3">Option 3</RadioGroup.Item>
50-
</RadioGroup>
47+
<Select>
48+
<Select.Trigger>
49+
<Select.Value placeholder="Select an option" />
50+
</Select.Trigger>
51+
<Select.Content>
52+
<Select.Group>
53+
<Select.Item value="1">Option 1</Select.Item>
54+
<Select.Item value="2">Option 2</Select.Item>
55+
<Select.Item value="3">Option 3</Select.Item>
56+
</Select.Group>
57+
</Select.Content>
58+
</Select>
5159
</div>
5260

5361
<div className="flex items-center space-x-4">

app/global.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@
44

55
:root {
66
--muted: #606067;
7+
--background: #fff;
8+
--foreground: #000;
9+
--primary-50: #fffef0;
10+
--primary-100: #fffac2;
11+
--primary-200: #fff299;
12+
--primary-300: #ffe766;
13+
--primary-400: #ffdb33;
14+
--primary-500: #ffcc00;
15+
--primary-600: #ffb700;
16+
--primary-700: #ff9f00;
17+
--primary-800: #e68a00;
18+
--primary-900: #b36b00;
719
}
820

921
.text-outlined {

components/SideNav.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import Link from "next/link";
55
export default function SideNav() {
66
return (
77
<div
8-
className={`fixed right-auto border-r-2 border-black h-full transition-transform transform md:translate-x-0 w-64 bg-white flex md:justify-start justify-center py-14 md:py-8`}
8+
className={`fixed right-auto border-r-2 border-black h-full overflow-y-scroll transition-transform transform md:translate-x-0 w-64 bg-white flex flex-col justify-center md:justify-start py-14 md:py-8`}
99
>
10-
<nav className="flex flex-col items-start pr-6 space-y-4">
10+
<nav className="flex flex-col items-start pr-6 pb-16 space-y-4">
1111
{navConfig.sideNavItems.map((item) => (
1212
<div key={item.title}>
1313
<Text as="h6">{item.title}</Text>

config/components.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ export const componentConfig: {
5757
name: "radio",
5858
filePath: "packages/ui/Form/Radio.tsx",
5959
},
60+
select: {
61+
name: "select",
62+
filePath: "packages/ui/Form/Select.tsx",
63+
},
6064
text: {
6165
name: "text",
6266
filePath: "packages/ui/Text/Text.tsx",
@@ -212,6 +216,11 @@ export const componentConfig: {
212216
filePath: "preview/components/radio-style-sizes.tsx",
213217
preview: lazy(() => import("@/preview/components/radio-style-sizes")),
214218
},
219+
"select-style-default": {
220+
name: "select-style-default",
221+
filePath: "preview/components/select-style-default.tsx",
222+
preview: lazy(() => import("@/preview/components/select-style-default")),
223+
},
215224
"textarea-style-default": {
216225
name: "textarea-style-default",
217226
filePath: "preview/components/textarea-style-default.tsx",

config/navigation.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const navConfig: INavigationConfig = {
1212
sideNavItems: [
1313
{
1414
title: "Getting Started",
15-
children: [{ title: "Introduction", href: "/docs" }],
15+
children: [{ title: "Introduction", href: "/docs", tag: "Updated" }],
1616
},
1717
{
1818
title: "Components",
@@ -23,11 +23,12 @@ export const navConfig: INavigationConfig = {
2323
{ title: "Badge", href: `${componentsRoute}/badge` },
2424
{ title: "Button", href: `${componentsRoute}/button` },
2525
{ title: "Card", href: `${componentsRoute}/card` },
26-
{ title: "Checkbox", href: `${componentsRoute}/checkbox`, tag: "New" },
26+
{ title: "Checkbox", href: `${componentsRoute}/checkbox` },
2727
{ title: "Dialog", href: `${componentsRoute}/dialog` },
2828
{ title: "Input", href: `${componentsRoute}/input` },
2929
{ title: "Menu", href: `${componentsRoute}/menu` },
30-
{ title: "Radio", href: `${componentsRoute}/radio`, tag: "New" },
30+
{ title: "Radio", href: `${componentsRoute}/radio` },
31+
{ title: "Select", href: `${componentsRoute}/select`, tag: "New" },
3132
{ title: "Tab", href: `${componentsRoute}/tab` },
3233
{ title: "Textarea", href: `${componentsRoute}/textarea` },
3334
{ title: "Text", href: `${componentsRoute}/text` },

content/docs/components/select.mdx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
title: Select
3+
description: Let your users pick what they want.
4+
lastUpdated: 1 Mar, 2024
5+
links:
6+
api_reference: https://www.radix-ui.com/primitives/docs/components/select#api-reference
7+
source: https://github.com/Logging-Stuff/RetroUI/blob/main/packages/ui/Form/Select.tsx
8+
---
9+
10+
<ComponentShowcase name="select-style-default" />
11+
<br />
12+
<br />
13+
14+
## Installation
15+
16+
#### 1. Install dependencies:
17+
18+
```sh
19+
npm install @radix-ui/react-select class-variance-authority
20+
```
21+
22+
<br />
23+
24+
#### 2. Copy the code 👇 into your project:
25+
26+
<ComponentSource name="select" />
27+
<br />
28+
<br />
29+
30+
## Examples
31+
32+
### Default
33+
34+
<ComponentShowcase name="select-style-default" />

content/docs/index.mdx

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Getting Started
33
description: This guide will help you get started with RetroUI, a retro styled UI library based on Tailwind CSS.
4-
lastUpdated: 08 Oct, 2024
4+
lastUpdated: 1 Mar, 2024
55
---
66

77
### 1. Add the fonts
@@ -32,40 +32,78 @@ Save the fonts in `global.css`:
3232

3333
<br />
3434

35-
### 2. Add the theme to your tailwind.config.js file.
35+
### 2. Add your theme.
36+
37+
Save your theme as CSS variables in `global.css`:
38+
39+
```css
40+
:root {
41+
--muted: #606067;
42+
--background: #fff;
43+
--foreground: #000;
44+
--primary-50: #fffef0;
45+
--primary-100: #fffac2;
46+
--primary-200: #fff299;
47+
--primary-300: #ffe766;
48+
--primary-400: #ffdb33;
49+
--primary-500: #ffcc00;
50+
--primary-600: #ffb700;
51+
--primary-700: #ff9f00;
52+
--primary-800: #e68a00;
53+
--primary-900: #b36b00;
54+
}
55+
```
56+
57+
<br />
58+
59+
Connect your theme to Tailwind in `tailwind.config.ts`:
3660

3761
```ts
3862
import type { Config } from "tailwindcss";
3963

40-
const config = {
64+
const config: Config = {
65+
content: [
66+
"./pages/**/*.{js,ts,jsx,tsx,mdx}",
67+
"./packages/**/*.{js,ts,jsx,tsx,mdx}",
68+
"./components/**/*.{js,ts,jsx,tsx,mdx}",
69+
"./preview/**/*.{js,ts,jsx,tsx,mdx}",
70+
"./app/**/*.{js,ts,jsx,tsx,mdx}",
71+
],
4172
theme: {
4273
extend: {
74+
textColor: {
75+
muted: "var(--muted)",
76+
},
4377
fontFamily: {
4478
head: ["var(--font-head)"],
4579
sans: ["var(--font-sans)"],
4680
},
4781
boxShadow: {
4882
xs: "1px 1px 0 0 #000",
83+
sm: "2px 2px 0 0 #000",
4984
md: "3px 3px 0 0 #000",
50-
"3xl": "10px 10px 0 0 #000",
5185
},
5286
colors: {
87+
background: "var(--background)",
88+
foreground: "var(--foreground)",
5389
primary: {
54-
50: "#FFFEF0",
55-
100: "#FFFAC2",
56-
200: "#FFF299",
57-
300: "#FFE766",
58-
400: "#FFDB33",
59-
500: "#FFCC00",
60-
600: "#FFB700",
61-
700: "#FF9F00",
62-
800: "#E68A00",
63-
900: "#B36B00",
90+
50: "var(--primary-50)",
91+
100: "var(--primary-100)",
92+
200: "var(--primary-200)",
93+
300: "var(--primary-300)",
94+
400: "var(--primary-400)",
95+
500: "var(--primary-500)",
96+
600: "var(--primary-600)",
97+
700: "var(--primary-700)",
98+
800: "var(--primary-800)",
99+
900: "var(--primary-900)",
64100
},
65101
},
66102
},
67103
},
104+
plugins: [require("tailwindcss-animate")],
68105
};
106+
69107
export default config;
70108
```
71109

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"@radix-ui/react-dialog": "^1.1.2",
1717
"@radix-ui/react-dropdown-menu": "^2.1.2",
1818
"@radix-ui/react-radio-group": "^1.2.3",
19+
"@radix-ui/react-select": "^2.1.6",
1920
"@radix-ui/react-visually-hidden": "^1.1.0",
2021
"class-variance-authority": "^0.7.0",
2122
"clsx": "^2.1.1",

packages/ui/Form/Select.tsx

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
"use client";
2+
3+
import { cn } from "@/lib/utils";
4+
import * as SelectPrimitive from "@radix-ui/react-select";
5+
import { Check, ChevronDown } from "lucide-react";
6+
import React from "react";
7+
8+
const Select = SelectPrimitive.Root;
9+
10+
const SelectTrigger = ({
11+
className,
12+
children,
13+
...props
14+
}: SelectPrimitive.SelectTriggerProps) => {
15+
return (
16+
<SelectPrimitive.Trigger
17+
className={cn(
18+
"flex h-10 min-w-40 items-center shadow-md justify-between border-2 border-input border-black bg-transparent px-4 py-2 ring-offset-background placeholder:text-muted-foreground focus:outline-none disabled:cursor-not-allowed disabled:opacity-50",
19+
className
20+
)}
21+
{...props}
22+
>
23+
{children}
24+
<SelectPrimitive.Icon asChild>
25+
<ChevronDown className="ml-2 h-4 w-4" />
26+
</SelectPrimitive.Icon>
27+
</SelectPrimitive.Trigger>
28+
);
29+
};
30+
31+
const SelectValue = SelectPrimitive.Value;
32+
33+
const SelectIcon = SelectPrimitive.Icon;
34+
35+
const SelectContent = ({
36+
className,
37+
children,
38+
position = "popper",
39+
...props
40+
}: SelectPrimitive.SelectContentProps) => {
41+
return (
42+
<SelectPrimitive.Portal>
43+
<SelectPrimitive.Content
44+
className={cn(
45+
"relative z-50 min-w-[8rem] overflow-hidden border border-black bg-white text-popover-foreground shadow-md 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",
46+
position === "popper" &&
47+
"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",
48+
className
49+
)}
50+
position={position}
51+
{...props}
52+
>
53+
<SelectPrimitive.Viewport
54+
className={cn(
55+
position === "popper" &&
56+
"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"
57+
)}
58+
>
59+
{children}
60+
</SelectPrimitive.Viewport>
61+
</SelectPrimitive.Content>
62+
</SelectPrimitive.Portal>
63+
);
64+
};
65+
66+
const SelectGroup = SelectPrimitive.Group;
67+
68+
const SelectItem = ({
69+
className,
70+
children,
71+
...props
72+
}: SelectPrimitive.SelectItemProps) => (
73+
<SelectPrimitive.Item
74+
className={cn(
75+
"relative flex w-full cursor-default select-none items-center py-1.5 px-2 outline-none hover:bg-primary-400 data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
76+
className
77+
)}
78+
{...props}
79+
>
80+
<SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
81+
82+
<span className="absolute right-2 flex h-3.5 w-3.5 items-center justify-center">
83+
<SelectPrimitive.ItemIndicator>
84+
<Check className="h-4 w-4 text-foreground" />
85+
</SelectPrimitive.ItemIndicator>
86+
</span>
87+
</SelectPrimitive.Item>
88+
);
89+
const SelectLabel = SelectPrimitive.Label;
90+
const SelectSeparator = SelectPrimitive.Separator;
91+
92+
const SelectObj = Object.assign(Select, {
93+
Trigger: SelectTrigger,
94+
Value: SelectValue,
95+
Icon: SelectIcon,
96+
Content: SelectContent,
97+
Group: SelectGroup,
98+
Item: SelectItem,
99+
Label: SelectLabel,
100+
Separator: SelectSeparator,
101+
});
102+
103+
export { SelectObj as Select };

packages/ui/Form/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export * from "./Input";
22
export * from "./Textarea";
33
export * from "./Checkbox";
44
export * from "./Radio";
5+
export * from "./Select";

0 commit comments

Comments
 (0)