@layer wp-ui { @layer utilities, components, compositions, overrides; @layer components { .button, .is-unstyled { appearance: none; padding: 0; } .button { /* Internal variables */ --wp-ui-button-font-weight: var(--wpds-typography-font-weight-emphasis); --wp-ui-button-background-color: var(--wpds-color-background-interactive-brand-strong); --wp-ui-button-background-color-active: var(--wpds-color-background-interactive-brand-strong-active); --wp-ui-button-background-color-disabled: var(--wpds-color-background-interactive-brand-strong-disabled); --wp-ui-button-foreground-color: var(--wpds-color-foreground-interactive-brand-strong); --wp-ui-button-foreground-color-active: var(--wpds-color-foreground-interactive-brand-strong-active); --wp-ui-button-foreground-color-disabled: var(--wpds-color-foreground-interactive-brand-strong-disabled); --wp-ui-button-padding-block: var(--wpds-dimension-padding-xs); --wp-ui-button-padding-inline: var(--wpds-dimension-padding-md); --wp-ui-button-height: var(--wpds-dimension-size-lg); --wp-ui-button-aspect-ratio: auto; /* Useful for overrides such as icon buttons */ --wp-ui-button-font-size: var(--wpds-typography-font-size-md); --wp-ui-button-min-width: calc(4ch + 2 * var(--wp-ui-button-padding-inline)); /* Icons are rendered as 24px but need to occupy a 16px footprint */ --wp-ui-button-icon-margin: calc((var(--wpds-dimension-size-2xs) - var(--wpds-dimension-size-sm)) / 2); /* by default, borders have the same color as the background */ --wp-ui-button-border-color: var(--wp-ui-button-background-color); --wp-ui-button-border-color-active: var(--wp-ui-button-background-color-active); --wp-ui-button-border-color-disabled: var(--wp-ui-button-background-color-disabled); --_gcd-button-font-family: var(--wpds-typography-font-family-body); --_gcd-button-font-size: var(--wp-ui-button-font-size); --_gcd-button-font-weight: var(--wp-ui-button-font-weight); /* Styles */ position: relative; display: inline-flex; justify-content: center; align-items: center; gap: var(--wpds-dimension-gap-sm); aspect-ratio: var(--wp-ui-button-aspect-ratio); min-width: var(--wp-ui-button-min-width); max-width: 100%; min-height: var(--wp-ui-button-height); padding-block: var(--wp-ui-button-padding-block); padding-inline: var(--wp-ui-button-padding-inline); border-style: solid; border-width: 1px; border-color: var(--wp-ui-button-border-color); border-radius: var(--wpds-border-radius-sm); background-color: var(--wp-ui-button-background-color); background-clip: border-box; font-family: var(--wpds-typography-font-family-body); font-size: var(--wp-ui-button-font-size); font-weight: var(--wp-ui-button-font-weight); line-height: var(--wpds-typography-line-height-sm); text-align: center; text-decoration: none; color: var(--wp-ui-button-foreground-color); overflow-wrap: anywhere; &:not([data-disabled]) { cursor: var(--wpds-cursor-control); } @media not ( prefers-reduced-motion ) { transition: color 0.1s ease-out; * { transition: opacity 0.1s ease-out; } } /* Use pointer cursor for buttons that are links */ &[href] { /* stylelint-disable-next-line declaration-property-value-disallowed-list -- Links should always use pointer. */ cursor: pointer; } /* Make sure that links rendered as children of `Button` use button styles */ *[href] { color: inherit; text-decoration: inherit; } /* States — use property declarations (not variable reassignment) so that higher CSS layers can safely override the custom property values without breaking state handling. */ &:not([data-disabled]):is(:hover, :active, :focus) { /* hover/active/focus states apply when the button is not disabled. A non disabled, loading button will have hover/active/focus styles */ background-color: var(--wp-ui-button-background-color-active); color: var(--wp-ui-button-foreground-color-active); border-color: var(--wp-ui-button-border-color-active); } &[data-disabled]:not(.is-loading) { /* A loading button, even when disabled, won't "look" disabled */ background-color: var(--wp-ui-button-background-color-disabled); color: var(--wp-ui-button-foreground-color-disabled); border-color: var(--wp-ui-button-border-color-disabled); @media ( forced-colors: active ) { border-color: GrayText; color: GrayText; } } } .is-small { --wp-ui-button-padding-block: 0px; --wp-ui-button-padding-inline: var(--wpds-dimension-padding-sm); --wp-ui-button-height: var(--wpds-dimension-size-sm); } .icon { flex-shrink: 0; margin: var(--wp-ui-button-icon-margin); } /* Variants (`tone` + `variant`) overrides compared to default styles */ /* All outline buttons have a border */ .is-brand { /* no need to redefine variables for .is-brand.is-solid as it's the default variant */ /* Outline and minimal buttons use the same foreground color */ &.is-outline, &.is-minimal { --wp-ui-button-foreground-color: var(--wpds-color-foreground-interactive-brand); --wp-ui-button-foreground-color-active: var(--wpds-color-foreground-interactive-brand-active); --wp-ui-button-foreground-color-disabled: var(--wpds-color-foreground-interactive-brand-disabled); } &.is-outline { --wp-ui-button-background-color: var(--wpds-color-background-interactive-brand-weak); --wp-ui-button-background-color-active: var(--wpds-color-background-interactive-brand-weak-active); --wp-ui-button-background-color-disabled: var(--wpds-color-background-interactive-brand-weak-disabled); --wp-ui-button-border-color: var(--wpds-color-stroke-interactive-brand); --wp-ui-button-border-color-active: var(--wpds-color-stroke-interactive-brand-active); --wp-ui-button-border-color-disabled: var(--wpds-color-stroke-interactive-brand-disabled); } &.is-minimal { --wp-ui-button-background-color: var(--wpds-color-background-interactive-brand-weak); --wp-ui-button-background-color-active: var(--wpds-color-background-interactive-brand-weak-active); --wp-ui-button-background-color-disabled: var(--wpds-color-background-interactive-brand-weak-disabled); } } .is-neutral { /* Solid and pressed minimal share the strong appearance */ &.is-solid, &.is-minimal[aria-pressed="true"] { --wp-ui-button-background-color: var(--wpds-color-background-interactive-neutral-strong); --wp-ui-button-background-color-active: var(--wpds-color-background-interactive-neutral-strong-active); --wp-ui-button-background-color-disabled: var(--wpds-color-background-interactive-neutral-strong-disabled); --wp-ui-button-foreground-color: var(--wpds-color-foreground-interactive-neutral-strong); --wp-ui-button-foreground-color-active: var(--wpds-color-foreground-interactive-neutral-strong-active); --wp-ui-button-foreground-color-disabled: var(--wpds-color-foreground-interactive-neutral-strong-disabled); } /* Outline and unpressed minimal buttons use the same foreground color */ &.is-outline, &.is-minimal:not([aria-pressed="true"]) { --wp-ui-button-foreground-color: var(--wpds-color-foreground-interactive-neutral); --wp-ui-button-foreground-color-active: var(--wpds-color-foreground-interactive-neutral-active); --wp-ui-button-foreground-color-disabled: var(--wpds-color-foreground-interactive-neutral-disabled); } &.is-outline { --wp-ui-button-background-color: var(--wpds-color-background-interactive-neutral-weak); --wp-ui-button-background-color-active: var(--wpds-color-background-interactive-neutral-weak-active); --wp-ui-button-background-color-disabled: var(--wpds-color-background-interactive-neutral-weak-disabled); --wp-ui-button-border-color: var(--wpds-color-stroke-interactive-neutral); --wp-ui-button-border-color-active: var(--wpds-color-stroke-interactive-neutral-active); --wp-ui-button-border-color-disabled: var(--wpds-color-stroke-interactive-neutral-disabled); } &.is-minimal:not([aria-pressed="true"]) { --wp-ui-button-background-color: var(--wpds-color-background-interactive-neutral-weak); --wp-ui-button-background-color-active: var(--wpds-color-background-interactive-neutral-weak-active); --wp-ui-button-background-color-disabled: var(--wpds-color-background-interactive-neutral-weak-disabled); } /* Forced colors discard the strong background, so fill pressed buttons with the system selection colors instead. Opting out of color adjustment removes the text backplate, so the border and focus ring need explicit system colors too. */ &.is-minimal[aria-pressed="true"]:not(.is-loading) { @media ( forced-colors: active ) { forced-color-adjust: none; outline-color: CanvasText; background-color: SelectedItem; color: SelectedItemText; border-color: ButtonBorder; &[data-disabled] { background-color: GrayText; color: Canvas; border-color: GrayText; } } } } .is-unstyled { min-width: unset; border: none; background: none; } .is-compact { --wp-ui-button-height: var(--wpds-dimension-size-md); } .is-loading:not(.is-unstyled) { color: transparent; /* Keep text transparent when a loading button is hovered — needed because the hover state now sets `color` as a property declaration. */ &:not([data-disabled]):is(:hover, :active, :focus) { color: transparent; } @media ( forced-colors: active ) { color: ButtonFace; } > :not(.spinner) { opacity: 0; } } } @layer compositions { .spinner { position: absolute; inset: 0; margin: auto; width: var(--wp-ui-button-font-size); height: var(--wp-ui-button-font-size); color: var(--wp-ui-button-foreground-color); pointer-events: none; /* Heavier than the Spinner default to match the emphasized label weight. */ > * { stroke-width: 2.75; } @media ( prefers-reduced-motion ) { > * { animation: none; } } @media ( forced-colors: active ) { > * { stroke: ButtonText; } } } } }