Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions BREAKING_CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ The same applies to `Li`, which takes the Flex layout props.

- **Panel** no longer has a box shadow (Dropdown and Popover set their own elevation, so they are unaffected)
- **Badge** `alphaBg` uses the `A3` color step instead of `A6`
- **Badge** interactive hover and active backgrounds are stronger (8% and 15% instead of 5% and 10%), and lighten instead of darken in dark mode
- **Alert** `gray` variant ring uses `gray9` (the neutral tone) instead of `slate9`

---
Expand Down Expand Up @@ -532,6 +533,52 @@ globalStyle(`${monoInput} input`, { fontFamily: 'monospace' });

---

### State Backgrounds: Layers Instead of Pseudo-Elements

**Change:** Hover and active backgrounds are drawn as `background-image` layers on the element itself, over its `background-color`, instead of on `::before` and `::after`.

**Affected:** `AccordionTrigger`, interactive `Badge`, `Button`, `ButtonSwitch`, `Card` (and so `Alert`), `Checkbox` hover, highlighted `Combobox` option, `DropdownMenuItem` and `SelectItem`, `IconButton`, interactive `Li`, `SegmentedControlItem` hover, `SelectTrigger`, interactive and active `Tr`, the wrapper of `Input` and `Textarea` (and so `TextField` and `DateTimePickerInput`)

| | Before | After |
| ----------------------- | ----------------------------------------------- | ----------------------------------------------------------------------- |
| Hover and active colors | `::before`, plus a 5% primary tint on `::after` | `background-image` layers on the element |
| Primary tint | `primary` at `opacity: 0.05` | the `primaryTint` theme token |
| Invalid hover tint | `inputInvalidBorder` at `opacity: 0.05` | the `inputInvalidHoverTint` and `textareaInvalidHoverTint` theme tokens |
| Text over the state | covered by the semi-transparent layer | drawn above the background, unchanged color |
| Disabled invalid field | red hover tint | no hover, like any disabled field |
| `Card` state outline | on `::before` | on the element |
| `Alert` ring | inset `box-shadow` on `::before` | inset `box-shadow` on the element, before the elevation shadow |

The `Input` and `Textarea` wrappers also lose a `:focus-visible` background that never showed, since the wrapper cannot take focus. Their hover tint is now drawn under the inner control, so it no longer shows while the browser autofills the field or while a ghost field is focused, both of which paint an opaque background on the control.

On devices that can hover, `Button`, `IconButton`, interactive `Card` and interactive `Li` now show their pressed color while held, where the hover color used to win. An interactive `Card` with `active` keeps its active look on hover, and its focus ring only shows for keyboard focus (`:focus-visible`), so a mouse click no longer leaves it. The same goes for the interactive `Li` focus ring.

In Firefox, the `DateTimePickerInput` patch over the native picker button follows the field: a red hover tint when invalid, and dimmed with no hover and no click when disabled. These states need `:has()` (Firefox 121 and later).

An invalid `SelectTrigger` now gets the same red hover tint as an invalid `Input`, from the new `selectInvalidHoverTint` theme token, instead of the primary tint.

The `Checkbox` and `SegmentedControlItem` hover, the highlighted `Combobox` option, `DropdownMenuItem` and `SelectItem`, and the interactive and active `Tr` backgrounds were a `background-color` and are now layers too, so a custom background no longer hides them. The interactive `Badge`, `Tr` and `SegmentedControlItem` hovers now only apply on devices that can hover, and the `SegmentedControlItem` hover no longer fades in.

A `box-shadow` set on an `Alert` through `css` or `className` now replaces its ring too.

`Button` still uses `::after` for the `waiting` stripes, which no longer fade while the button has keyboard focus.

**Migration Guide:**

1. Move overrides that target `::before` or `::after` of these components to the element itself
2. Change the base color with `background-color`, through `css` or `className`: the state layers stay on top of it. Avoid the `background` shorthand in `css`, which would remove them
3. Change a state color with a `className` that sets `background-image` on `:hover` or `:active`, since `css` cannot target states

**Rationale:**

- A custom base color keeps the hover and active states
- Overriding a state is one rule on the element, not on an internal pseudo-element
- Frees `::before` and `::after` for consumers

**Impact:** Low - Visual only, unless an app styles these pseudo-elements

---

## Components Supporting Polymorphic `as` Prop

### Layout Components
Expand Down Expand Up @@ -886,6 +933,12 @@ Release notes are generated by semantic-release; use this as the body of the bre
- **Removed:** `elevation` on `NavigationMenuTrigger`, which had no effect
- See [Migration Guide](./BREAKING_CHANGES.md#navigationmenu-as-on-every-part-and-scoped-list-styles)

#### State Backgrounds

- **Changed:** `AccordionTrigger`, interactive `Badge`, `Button`, `ButtonSwitch`, `Card`, `Alert`, `Checkbox`, `Combobox` options, `DropdownMenuItem`, `IconButton`, interactive `Li`, `SegmentedControlItem`, `SelectItem`, `SelectTrigger`, `Tr` and the `Input` and `Textarea` wrappers draw hover and active backgrounds as `background-image` layers instead of `::before`/`::after`; `Card` outlines and the `Alert` ring move to the element
- Migration: move pseudo-element overrides to the element itself
- See [Migration Guide](./BREAKING_CHANGES.md#state-backgrounds-layers-instead-of-pseudo-elements)

#### Theme Provider

- **Changed:** Requires `VanillaExtractThemeProvider` at the app root
Expand Down
12 changes: 2 additions & 10 deletions components/Accordion/Accordion.vanilla.css.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { keyframes, style } from '@vanilla-extract/css';
import { recipe } from '@vanilla-extract/recipes';

import { stateLayers } from '@/styles/stateLayers';
import { tokens } from '@/styles/tokens.css';

import { elevationVariants } from '@/components/Elevation/Elevation.vanilla.css';
Expand Down Expand Up @@ -82,13 +83,6 @@ export const accordionTriggerRecipe = recipe({
transition: 'opacity 200ms ease-out',

selectors: {
'&::before': {
borderRadius: 'inherit',
boxSizing: 'border-box',
content: '""',
position: 'absolute',
inset: 0,
},
'&:focus': {
boxShadow: `inset 0 0 0 1px ${tokens.colors.accordionActiveShadow}`,
},
Expand All @@ -99,9 +93,7 @@ export const accordionTriggerRecipe = recipe({
selectors: {
'&:not([disabled]):hover': {
cursor: 'pointer',
},
'&:not([disabled]):hover::before': {
backgroundColor: tokens.colors.accordionHoverShadow,
backgroundImage: stateLayers(tokens.colors.accordionHoverShadow),
},
},
},
Expand Down
7 changes: 3 additions & 4 deletions components/Alert/Alert.vanilla.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import { recipe } from '@vanilla-extract/recipes';

import { tokens } from '@/styles/tokens.css';

// CardVanilla's `::before` overlay carries the ring, leaving the element's box-shadow to elevation.
import { cardRing } from '@/components/Card/Card.vanilla.css';

const ring = (color: string) => ({
'::before': {
boxShadow: `inset 0 0 0 1px ${color}`,
},
vars: { [cardRing]: `inset 0 0 0 1px ${color}` },
});

export const alertRecipe = recipe({
Expand Down
8 changes: 4 additions & 4 deletions components/Badge/Badge.theme.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Plain TypeScript color tokens (no vanilla-extract)
// Can be safely imported by colors/index.ts for Stitches
export const badgeLightTheme = {
badgeInteractiveBackgroundHover: 'hsla(0, 0%, 0%, 0.05)',
badgeInteractiveBackgroundActive: 'hsla(0, 0%, 0%, 0.1)',
badgeInteractiveBackgroundHover: 'hsla(0, 0%, 0%, 0.08)',
badgeInteractiveBackgroundActive: 'hsla(0, 0%, 0%, 0.15)',
};

export const badgeDarkTheme = {
badgeInteractiveBackgroundHover: 'hsla(0, 0%, 0%, 0.1)',
badgeInteractiveBackgroundActive: 'hsla(0, 0%, 0%, 0.2)',
badgeInteractiveBackgroundHover: 'hsla(0, 0%, 100%, 0.08)',
badgeInteractiveBackgroundActive: 'hsla(0, 0%, 100%, 0.15)',
};
32 changes: 18 additions & 14 deletions components/Badge/Badge.vanilla.css.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { style } from '@vanilla-extract/css';
import { recipe } from '@vanilla-extract/recipes';

import { breakpoints } from '@/styles/breakpoints.css';
import { stateLayers } from '@/styles/stateLayers';
import { tokens } from '@/styles/tokens.css';

const baseBadge = style({
Expand Down Expand Up @@ -37,25 +39,27 @@ const baseBadge = style({
const interactiveBadge = style([
baseBadge,
{
// The layers fill the padding box only, so they don't tint the border; the base color still does.
backgroundRepeat: 'no-repeat',

selectors: {
'&::before': {
boxSizing: 'border-box',
content: '""',
position: 'absolute',
inset: 0,
borderRadius: 'inherit',
},
'&:focus-visible': {
outline: `2px solid ${tokens.colors.primary}`,
},
'&:hover': {
cursor: 'pointer',
},
'&:hover::before': {
backgroundColor: tokens.colors.badgeInteractiveBackgroundHover,
// `:hover:active` outranks the hover rule, which comes later inside its media query.
'&:active, &:hover:active': {
backgroundImage: stateLayers(tokens.colors.badgeInteractiveBackgroundActive),
},
'&:active::before': {
backgroundColor: tokens.colors.badgeInteractiveBackgroundActive,
},

'@media': {
[breakpoints.hover]: {
selectors: {
'&:hover': {
cursor: 'pointer',
backgroundImage: stateLayers(tokens.colors.badgeInteractiveBackgroundHover),
},
},
},
},
},
Expand Down
60 changes: 17 additions & 43 deletions components/Button/Button.vanilla.css.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { keyframes, style } from '@vanilla-extract/css';
import { recipe, RecipeVariants } from '@vanilla-extract/recipes';

import { stateLayers } from '@/styles/stateLayers';
import { tokens } from '@/styles/tokens.css';

// Background size constants for waiting animation
const BG_SIZES = {
small: tokens.sizes['8'],
medium: tokens.sizes['9'],
large: tokens.sizes['10'],
};

// Keyframe animation for waiting state
const backgroundSlide = keyframes({
'100%': { transform: `translateX(${tokens.sizes['9']})` },
});
Expand All @@ -23,7 +22,9 @@ const backgroundSlideLarge = keyframes({
'100%': { transform: `translateX(${tokens.sizes['10']})` },
});

// Base button styles
const HOVER_LAYER = 'rgba(255, 255, 255, 0.15)';
const PRESSED_LAYER = 'rgba(0, 0, 0, 0.15)';

const baseButton = style({
// Reset
appearance: 'none',
Expand All @@ -46,35 +47,18 @@ const baseButton = style({
fontVariantNumeric: 'tabular-nums',
lineHeight: '1',

// Pseudo-elements for hover/active effects
selectors: {
'&::before': {
boxSizing: 'border-box',
content: '""',
position: 'absolute',
inset: 0,
},
'&::after': {
boxSizing: 'border-box',
content: '""',
position: 'absolute',
inset: 0,
},
'&:disabled': {
pointerEvents: 'none',
opacity: 0.5,
},
'&:focus-visible': {
boxShadow: `inset 0 0 0 2px ${tokens.colors.focusOutline}`,
backgroundImage: stateLayers(HOVER_LAYER),
},
'&:focus-visible::before': {
backgroundColor: 'rgba(255, 255, 255, 0.15)',
},
'&:focus-visible::after': {
opacity: 0.15,
},
'&:active::before': {
backgroundColor: 'rgba(0, 0, 0, 0.15)',
// `:hover:active` outranks the hover rules, which come later inside their media query.
'&:active, &:hover:active': {
backgroundImage: stateLayers(PRESSED_LAYER),
},
},

Expand All @@ -83,12 +67,7 @@ const baseButton = style({
selectors: {
'&:hover': {
cursor: 'pointer',
},
'&:hover::before': {
backgroundColor: 'rgba(255, 255, 255, 0.15)',
},
'&:hover::after': {
opacity: 0.05,
backgroundImage: stateLayers(HOVER_LAYER),
},
},
},
Expand Down Expand Up @@ -137,8 +116,8 @@ export const buttonRecipe = recipe({
'@media': {
'(hover: hover)': {
selectors: {
'&:hover::after': {
backgroundColor: tokens.colors.primary,
'&:hover': {
backgroundImage: stateLayers(tokens.colors.primaryTint, HOVER_LAYER),
},
},
},
Expand All @@ -159,8 +138,8 @@ export const buttonRecipe = recipe({
'@media': {
'(hover: hover)': {
selectors: {
'&:hover::after': {
backgroundColor: tokens.colors.primary,
'&:hover': {
backgroundImage: stateLayers(tokens.colors.primaryTint, HOVER_LAYER),
},
},
},
Expand Down Expand Up @@ -194,6 +173,10 @@ export const buttonRecipe = recipe({
pointerEvents: 'none',
selectors: {
'&::after': {
content: '""',
position: 'absolute',
top: 0,
bottom: 0,
left: '-100%',
width: '200%',
backgroundSize: BG_SIZES.medium,
Expand Down Expand Up @@ -231,7 +214,6 @@ export const buttonRecipe = recipe({
},

compoundVariants: [
// Primary + Ghost
{
variants: { variant: 'primary', ghost: true },
style: {
Expand All @@ -249,7 +231,6 @@ export const buttonRecipe = recipe({
},
},
},
// Primary + Active
{
variants: { variant: 'primary', state: 'active' },
style: {
Expand All @@ -258,15 +239,13 @@ export const buttonRecipe = recipe({
boxShadow: 'inset 0 0 0 2px white',
},
},
// Secondary + Waiting
{
variants: { variant: 'secondary', state: 'waiting' },
style: {
backgroundColor: tokens.colors.deepBlue['3'],
color: 'transparent',
},
},
// Secondary + Ghost
{
variants: { variant: 'secondary', ghost: true },
style: {
Expand All @@ -275,15 +254,13 @@ export const buttonRecipe = recipe({
boxShadow: 'none',
},
},
// Red + Waiting
{
variants: { variant: 'red', state: 'waiting' },
style: {
backgroundColor: tokens.colors.deepBlue['3'],
color: 'transparent',
},
},
// Red + Active
{
variants: { variant: 'red', state: 'active' },
style: {
Expand All @@ -292,7 +269,6 @@ export const buttonRecipe = recipe({
boxShadow: 'inset 0 0 0 2px white',
},
},
// Red + Ghost
{
variants: { variant: 'red', ghost: true },
style: {
Expand All @@ -310,7 +286,6 @@ export const buttonRecipe = recipe({
},
},
},
// Small + Waiting (specific animation)
{
variants: { size: 'small', state: 'waiting' },
style: {
Expand All @@ -322,7 +297,6 @@ export const buttonRecipe = recipe({
},
},
},
// Large + Waiting (specific animation)
{
variants: { size: 'large', state: 'waiting' },
style: {
Expand Down
Loading
Loading