Skip to content

Commit

Permalink
feat: toggle (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
severinlandolt authored Feb 8, 2025
1 parent aa19605 commit e7d7442
Show file tree
Hide file tree
Showing 6 changed files with 309 additions and 0 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
"@radix-ui/react-switch": "^1.1.1",
"@radix-ui/react-tabs": "^1.1.1",
"@radix-ui/react-toast": "^1.2.2",
"@radix-ui/react-toggle": "^1.1.1",
"@radix-ui/react-toggle-group": "^1.1.1",
"@radix-ui/react-tooltip": "^1.1.4",
"@react-aria/datepicker": "^3.12.0",
"@react-stately/datepicker": "^3.11.0",
Expand Down
171 changes: 171 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 72 additions & 0 deletions src/components/Toggle/Toggle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Tremor Toggle [v0.0.0]
"use client"

import React from "react"
import * as TogglePrimitive from "@radix-ui/react-toggle"
import * as ToggleGroupPrimitive from "@radix-ui/react-toggle-group"

import { cx } from "../../utils/cx"
import { focusRing } from "../../utils/focusRing"

const toggleStyles = [
// base
"group inline-flex h-9 min-w-9 items-center justify-center gap-2 rounded-md border px-2 text-sm font-medium shadow-sm transition-all duration-100 ease-in-out",
"border-gray-300 dark:border-gray-800",
// text color
"text-gray-700 dark:text-gray-300",
// background color
"bg-white dark:bg-gray-950",
//hover color
"hover:bg-gray-50 dark:hover:bg-gray-900/60",
// disabled
"disabled:pointer-events-none disabled:text-gray-400 disabled:dark:text-gray-600",
"data-[state=on]:bg-gray-100 data-[state=on]:text-gray-900 dark:data-[state=on]:bg-gray-800 dark:data-[state=on]:text-gray-50",
focusRing,
]

const Toggle = React.forwardRef<
React.ElementRef<typeof TogglePrimitive.Root>,
React.ComponentPropsWithoutRef<typeof TogglePrimitive.Root>
>(({ className, ...props }, ref) => (
<TogglePrimitive.Root
ref={ref}
className={cx(toggleStyles, className)}
{...props}
/>
))

Toggle.displayName = TogglePrimitive.Root.displayName

export { Toggle }

const ToggleGroup = React.forwardRef<
React.ElementRef<typeof ToggleGroupPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof ToggleGroupPrimitive.Root>
>(({ className, children, ...props }, ref) => (
<ToggleGroupPrimitive.Root
ref={ref}
className={cx("flex items-center justify-center gap-1 flex-nowrap", className)}
{...props}
>
{children}
</ToggleGroupPrimitive.Root>
))

ToggleGroup.displayName = ToggleGroupPrimitive.Root.displayName

const ToggleGroupItem = React.forwardRef<
React.ElementRef<typeof ToggleGroupPrimitive.Item>,
React.ComponentPropsWithoutRef<typeof ToggleGroupPrimitive.Item>
>(({ className, children, ...props }, ref) => (
<ToggleGroupPrimitive.Item
ref={ref}
className={cx(toggleStyles, className)}
{...props}
>
{children}
</ToggleGroupPrimitive.Item>
))

ToggleGroupItem.displayName = ToggleGroupPrimitive.Item.displayName

export { ToggleGroup, ToggleGroupItem }
1 change: 1 addition & 0 deletions src/components/Toggle/changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Tremor Toggle Changelog
12 changes: 12 additions & 0 deletions src/components/Toggle/toggle.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { expect, test } from "@playwright/test"

test.describe("Expect Toggle", () => {
test("to render TableRoot", async ({ page }) => {
await page.goto("http://localhost:6006/?path=/story/ui-toggle--default")
await expect(
page
.frameLocator('iframe[title="storybook-preview-iframe"]').getByLabel('Toggle star')
).toBeVisible()
})

})
Loading

0 comments on commit e7d7442

Please sign in to comment.