Skip to content

Commit f00e0b5

Browse files
committed
switch component ✅
1 parent a068cd1 commit f00e0b5

File tree

11 files changed

+151
-3
lines changed

11 files changed

+151
-3
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
Checkbox,
1010
Menu,
1111
Select,
12+
Switch,
1213
Tabs,
1314
TabsContent,
1415
TabsPanels,
@@ -58,6 +59,10 @@ export default function page() {
5859
</Select>
5960
</div>
6061

62+
<div className="space-x-4">
63+
<Switch />
64+
</div>
65+
6166
<div className="flex items-center space-x-4">
6267
<Avatar>
6368
<Avatar.Image src="/images/avatar.jpeg" alt="Arif Logs" />

config/components.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ export const componentConfig: {
5959
},
6060
select: {
6161
name: "select",
62-
filePath: "packages/ui/Form/Select.tsx",
62+
filePath: "packages/ui/Form/select.tsx",
63+
},
64+
switch: {
65+
name: "switch",
66+
filePath: "packages/ui/Form/switch.tsx",
6367
},
6468
text: {
6569
name: "text",
@@ -221,6 +225,16 @@ export const componentConfig: {
221225
filePath: "preview/components/select-style-default.tsx",
222226
preview: lazy(() => import("@/preview/components/select-style-default")),
223227
},
228+
"switch-style-default": {
229+
name: "switch-style-default",
230+
filePath: "preview/components/switch-style-default.tsx",
231+
preview: lazy(() => import("@/preview/components/switch-style-default")),
232+
},
233+
"switch-style-disabled": {
234+
name: "switch-style-disabled",
235+
filePath: "preview/components/switch-style-disabled.tsx",
236+
preview: lazy(() => import("@/preview/components/switch-style-disabled")),
237+
},
224238
"textarea-style-default": {
225239
name: "textarea-style-default",
226240
filePath: "preview/components/textarea-style-default.tsx",

config/navigation.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export const navConfig: INavigationConfig = {
2929
{ title: "Menu", href: `${componentsRoute}/menu` },
3030
{ title: "Radio", href: `${componentsRoute}/radio` },
3131
{ title: "Select", href: `${componentsRoute}/select`, tag: "New" },
32+
{ title: "Switch", href: `${componentsRoute}/switch`, tag: "New" },
3233
{ title: "Tab", href: `${componentsRoute}/tab` },
3334
{ title: "Textarea", href: `${componentsRoute}/textarea` },
3435
{ title: "Text", href: `${componentsRoute}/text` },

content/docs/components/switch.mdx

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
title: Switch
3+
description: Let users to turn on or off your marketing emails or notifications.
4+
lastUpdated: 20 Feb, 2024
5+
links:
6+
api_reference: https://www.radix-ui.com/primitives/docs/components/switch#api-reference
7+
source: https://github.com/Logging-Stuff/RetroUI/blob/main/packages/ui/Form/switch.tsx
8+
---
9+
10+
<ComponentShowcase name="switch-style-default" />
11+
<br />
12+
<br />
13+
14+
## Installation
15+
16+
#### 1. Install dependencies:
17+
18+
```sh
19+
npm install @radix-ui/react-switch
20+
```
21+
22+
<br />
23+
24+
#### 2. Copy the code 👇 into your project:
25+
26+
<ComponentSource name="switch" />
27+
<br />
28+
<br />
29+
30+
## Examples
31+
32+
### Default
33+
34+
<ComponentShowcase name="switch-style-default" />
35+
<br />
36+
<br />
37+
38+
### Disabled
39+
40+
<ComponentShowcase name="switch-style-disabled" />
41+
<br />
42+
<br />

content/docs/utils/cn.mdx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@ This enables you to construct className strings conditionally without having to
1212

1313
## Installation
1414

15-
#### 1. Copy the code 👇 into your `lib/utils.ts` file:
15+
#### 1. Install the dependencies:
16+
17+
```sh
18+
npm install clsx tailwind-merge
19+
```
20+
21+
<br />
22+
23+
#### 2. Copy the code 👇 into your `lib/utils.ts` file:
1624

1725
```ts
1826
import clsx from "clsx";

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"@radix-ui/react-dropdown-menu": "^2.1.2",
1818
"@radix-ui/react-radio-group": "^1.2.3",
1919
"@radix-ui/react-select": "^2.1.6",
20+
"@radix-ui/react-switch": "^1.1.3",
2021
"@radix-ui/react-visually-hidden": "^1.1.0",
2122
"class-variance-authority": "^0.7.0",
2223
"clsx": "^2.1.1",

packages/ui/Form/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ export * from "./Input";
22
export * from "./Textarea";
33
export * from "./Checkbox";
44
export * from "./Radio";
5-
export * from "./Select";
5+
export * from "./select";
6+
export * from "./switch";

packages/ui/Form/switch.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"use client";
2+
3+
import * as React from "react";
4+
import * as SwitchPrimitives from "@radix-ui/react-switch";
5+
6+
import { cn } from "@/lib/utils";
7+
8+
const Switch = ({ className, ...props }: SwitchPrimitives.SwitchProps) => (
9+
<SwitchPrimitives.Root
10+
className={cn(
11+
"peer inline-flex h-6 w-11 shrink-0 cursor-pointer border-2 border-foreground items-center disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary-400",
12+
className
13+
)}
14+
{...props}
15+
>
16+
<SwitchPrimitives.Thumb
17+
className={cn(
18+
"pointer-events-none block h-4 w-4 bg-primary-500 border-2 mx-0.5 border-foreground shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0 data-[state=checked]:bg-background"
19+
)}
20+
/>
21+
</SwitchPrimitives.Root>
22+
);
23+
24+
export { Switch };

pnpm-lock.yaml

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Switch } from "@/packages/ui";
2+
import React from "react";
3+
4+
export default function SwitchStyleDefault() {
5+
return (
6+
<div className="flex items-center space-x-2">
7+
<Switch id="notification" />
8+
<label htmlFor="notification">Email Notifications</label>
9+
</div>
10+
);
11+
}

0 commit comments

Comments
 (0)