Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

💄 Shift the primary button shade on hover instead of fading its opacity (#3212)

Luke Vellae30a831d4d4b
diff --git a/packages/tailwind-config/shared-styles.css b/packages/tailwind-config/shared-styles.css
index 59748c5e9..fd5a247a7 100644
--- a/packages/tailwind-config/shared-styles.css
+++ b/packages/tailwind-config/shared-styles.css
@@ -12,6 +12,7 @@
--radius: 0.625rem;
--primary: var(--primary-light, var(--color-indigo-600));
--primary-foreground: var(--primary-light-foreground, var(--color-white));
+ --state-shade: black;
--button-outline: rgba(0, 0, 0, 0.1);
--menu-item-outline: rgba(0, 0, 0, 0.05);
@@ -69,6 +70,7 @@
--primary: var(--primary-dark, var(--color-indigo-500));
--primary-foreground: var(--primary-dark-foreground, var(--color-white));
+ --state-shade: white;
--sidebar: var(--color-gray-900);
--sidebar-foreground: var(--color-gray-100);
@@ -125,6 +127,21 @@
@theme inline {
--color-primary: var(--primary);
--color-primary-foreground: var(--primary-foreground);
+ /*
+ * Interaction states shift the shade of the opaque brand colour (darker on
+ * light, lighter on dark) instead of fading it. Mixed at the element so
+ * nested --primary overrides (white-label, branding preview) pick them up.
+ */
+ --color-primary-hover: color-mix(
+ in oklch,
+ var(--primary),
+ var(--state-shade) 8%
+ );
+ --color-primary-active: color-mix(
+ in oklch,
+ var(--primary),
+ var(--state-shade) 14%
+ );
--color-button-outline: var(--button-outline);
--color-menu-item-outline: var(--menu-item-outline);
@@ -139,6 +156,16 @@
--color-destructive: var(--destructive);
--color-destructive-foreground: var(--destructive-foreground);
+ --color-destructive-hover: color-mix(
+ in oklch,
+ var(--destructive),
+ var(--state-shade) 8%
+ );
+ --color-destructive-active: color-mix(
+ in oklch,
+ var(--destructive),
+ var(--state-shade) 14%
+ );
--color-background: var(--background);
--color-foreground: var(--foreground);
diff --git a/packages/ui/src/button-variants.ts b/packages/ui/src/button-variants.ts
index 3fec55974..429d2d7a7 100644
--- a/packages/ui/src/button-variants.ts
+++ b/packages/ui/src/button-variants.ts
@@ -4,21 +4,21 @@ import { cn } from "./lib/utils";
export const buttonVariants = cva(
cn(
- "group inline-flex shrink-0 items-center justify-center whitespace-nowrap font-normal transition-colors active:opacity-80 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg]:opacity-90",
+ "group inline-flex shrink-0 items-center justify-center whitespace-nowrap font-normal transition-[background-color,color,transform] ease-out disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg]:opacity-90",
),
{
variants: {
variant: {
primary:
- "bg-primary/90 text-primary-foreground ring-1 ring-button-outline ring-inset hover:bg-primary dark:bg-primary/80 dark:hover:bg-primary",
+ "bg-primary text-primary-foreground ring-1 ring-button-outline ring-inset hover:bg-primary-hover active:scale-[.98] active:bg-primary-active motion-reduce:active:scale-100",
destructive:
- "bg-destructive text-destructive-foreground ring-1 ring-button-outline ring-inset hover:bg-destructive/90 dark:bg-destructive/80",
+ "bg-destructive text-destructive-foreground ring-1 ring-button-outline ring-inset hover:bg-destructive-hover active:scale-[.98] active:bg-destructive-active motion-reduce:active:scale-100",
default:
- "bg-background/80 ring-1 ring-button-outline ring-inset backdrop-blur-lg hover:bg-accent data-[state=open]:bg-accent dark:bg-foreground/5",
+ "bg-background/80 ring-1 ring-button-outline ring-inset backdrop-blur-lg hover:bg-accent active:scale-[.98] data-popup-open:bg-accent motion-reduce:active:scale-100 dark:bg-foreground/5",
ghost:
- "border-transparent bg-transparent text-foreground ring-1 ring-transparent ring-inset hover:bg-accent data-[state=open]:bg-accent [&>svg]:opacity-75",
+ "border-transparent bg-transparent text-foreground ring-1 ring-transparent ring-inset hover:bg-accent active:scale-[.98] data-popup-open:bg-accent motion-reduce:active:scale-100 [&>svg]:opacity-75",
actionBar:
- "border-transparent bg-action-bar text-action-bar-foreground hover:bg-action-bar-foreground/10 data-[state=open]:bg-action-bar-foreground/20",
+ "border-transparent bg-action-bar text-action-bar-foreground hover:bg-action-bar-foreground/10 active:scale-[.98] data-popup-open:bg-action-bar-foreground/20 motion-reduce:active:scale-100",
link: "border-transparent text-primary underline-offset-4 hover:underline",
},
size: {
diff --git a/packages/ui/src/select.tsx b/packages/ui/src/select.tsx
index 8931982ff..60c5f3ede 100644
--- a/packages/ui/src/select.tsx
+++ b/packages/ui/src/select.tsx
@@ -3,7 +3,6 @@
import { Select as SelectPrimitive } from "@base-ui/react/select";
import { CheckIcon, ChevronsUpDownIcon } from "lucide-react";
-import { buttonVariants } from "./button-variants";
import { cn } from "./lib/utils";
function Select<Value, Multiple extends boolean | undefined = false>(
@@ -36,8 +35,9 @@ function SelectTrigger({
<SelectPrimitive.Trigger
data-slot="select-trigger"
className={cn(
- buttonVariants({ variant: "default" }),
- "shadow-none",
+ "inline-flex h-9 shrink-0 items-center gap-x-2.5 whitespace-nowrap rounded-lg bg-background/80 px-2.5 text-sm outline-none ring-1 ring-button-outline ring-inset backdrop-blur-lg transition-[background-color,color,box-shadow] hover:bg-accent disabled:pointer-events-none disabled:opacity-50 data-popup-open:bg-accent dark:bg-foreground/5 [&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0",
+ "focus-visible:ring-[3px] focus-visible:ring-ring/50",
+ "data-invalid:ring-destructive",
className,
)}
{...props}
diff --git a/packages/ui/src/sidebar.tsx b/packages/ui/src/sidebar.tsx
index 6f3060f33..6ee8566b2 100644
--- a/packages/ui/src/sidebar.tsx
+++ b/packages/ui/src/sidebar.tsx
@@ -507,7 +507,7 @@ const SidebarMenuItem = React.forwardRef<
SidebarMenuItem.displayName = "SidebarMenuItem";
const sidebarMenuButtonVariants = cva(
- "peer/menu-button flex w-full items-center gap-2.5 overflow-hidden rounded-lg p-2 text-left text-sm transition-[width,height,padding] active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 group-has-data-[sidebar=menu-action]/menu-item:pr-8 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[active=true]:bg-sidebar-accent data-[active=true]:text-sidebar-accent-foreground data-[state=open]:hover:bg-sidebar-accent data-[state=open]:hover:text-sidebar-accent-foreground group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:p-2! [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0",
+ "peer/menu-button flex w-full items-center gap-2.5 overflow-hidden rounded-lg p-2 text-left text-sm transition-[width,height,padding] active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 group-has-data-[sidebar=menu-action]/menu-item:pr-8 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[active=true]:bg-sidebar-accent data-[active=true]:text-sidebar-accent-foreground data-popup-open:hover:bg-sidebar-accent data-popup-open:hover:text-sidebar-accent-foreground group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:p-2! [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0",
{
variants: {
variant: {
@@ -605,7 +605,7 @@ function SidebarMenuAction({
"peer-data-[size=lg]/menu-button:top-2.5",
"group-data-[collapsible=icon]:hidden",
showOnHover &&
- "group-focus-within/menu-item:opacity-100 group-hover/menu-item:opacity-100 data-[state=open]:opacity-100 peer-data-[active=true]/menu-button:text-sidebar-accent-foreground md:opacity-0",
+ "group-focus-within/menu-item:opacity-100 group-hover/menu-item:opacity-100 data-popup-open:opacity-100 peer-data-[active=true]/menu-button:text-sidebar-accent-foreground md:opacity-0",
className,
),
} as React.ComponentProps<"button">,