@import url('../../theme/surface-frost.less'); @clickX: var(--ran-x, 0); @clickY: var(--ran-y, 0); // White ink on the solid danger fill: 5.3:1 against --ran-red-700 in both themes. It does // not flip with the theme, so it cannot borrow --ran-color-primary-text. @dangerInk: var(--ran-btn-warning-color, #fff); // Glass surface language: frost the default (secondary) chrome only. Primary, // warning and text stay solid so emphasis and a11y ink do not wash out. .ran-btn-glass-apply() { box-shadow: none; .ran-btn { .ran-frost-control(); .ran-frost-control-reduced(); } .ran-btn-content { border-color: var(--ran-btn-glass-border-color, var(--ran-surface-glass-border)); background-color: transparent; } } :host { box-sizing: var(--ran-btn-box-sizing, border-box); position: var(--ran-btn-position, relative); display: var(--ran-btn-display, inline-flex); // A button must hug its own content by default. Without this, a host that // places `r-button` in a `flex-direction: column` container (the standard // form layout — see docs/src/ranui/form) gets stretched by the parent's // default `align-items: stretch` to the container's full cross-axis width, // even though the *visible* `.ran-btn` surface inside still shrinks to fit // its text. The result: an invisible phantom box past the visible button // that still carries this host's own `box-shadow` (a stray shadow bar // trailing off to the right) and still receives clicks (since it's the // real, full-sized custom-element box). `flex-start` opts out of stretch on // both flex and grid parents (CSS Box Alignment defines it as a synonym for // `start` outside flex containers) while staying overridable for a // consumer that explicitly wants a full-width button. align-self: var(--ran-btn-align-self, flex-start); background-image: var(--ran-btn-background-image, none); box-shadow: var(--ran-btn-box-shadow, var(--ran-skin-raised-shadow, 0 2px #00000004)); // The raised shadow above is painted on THIS box, so it has to be shaped like // the surface it sits behind. Without this the host stays a rectangle: a // rounded button ends up inside a square shadow, whose bottom edge shows as a // straight line poking out past both corners. Invisible at a small default radius, // which is why it survived — a consumer rounding the button to a pill // (--ran-btn-border-radius: var(--ran-radius-full)) sees it immediately. // Same reasoning as the `.ran-btn` radius below, one box further out. border-radius: var(--ran-btn-border-radius, var(--ran-radius-sm, 8px)); cursor: var(--ran-btn-cursor, pointer); user-select: var(--ran-btn-user-select, none); touch-action: var(--ran-btn-touch-action, manipulation); overflow: var(--ran-btn-overflow, hidden); pointer-events: var(--ran-btn-pointer-events, auto); .ran-btn { box-sizing: var(--ran-btn-surface-box-sizing, border-box); position: var(--ran-btn-surface-position, relative); display: var(--ran-btn-surface-display, block); background-image: var(--ran-btn-surface-background-image, none); cursor: var(--ran-btn-surface-cursor, pointer); // Motion props only (opacity) — never palette props (background / color / // border-color / box-shadow). Palette transitions make every theme flip fade // component-by-component instead of switching with the host page in one // frame, which a general-purpose library must not impose on its consumers. // Hosts that want palette fades can opt in via --ran-btn-surface-transition. transition: var( --ran-btn-surface-transition, opacity var(--ran-motion-duration-base, 0.2s) var(--ran-motion-ease-standard, cubic-bezier(0.645, 0.045, 0.355, 1)) ); user-select: var(--ran-btn-surface-user-select, none); touch-action: var(--ran-btn-surface-touch-action, manipulation); // Round the elevated surface to match the content, so it can never poke out // at the corners behind the rounded content (was showing white corners in dark). border-radius: var(--ran-btn-border-radius, var(--ran-radius-sm, 8px)); background: var(--ran-btn-surface-background, var(--ran-color-bg-elevated, #ffffff)); } &, &(:active), &(:focus) { outline: 0; -webkit-tap-highlight-color: transparent; .ran-btn { outline: var(--ran-btn-surface-outline, 0); } } // The keyboard target is inside the closed root, so the host does not match // :focus-visible. Keep its ring inset: the host clips ripple overflow, so an // outside ring (or --ran-focus-ring's box-shadow) would be cut off. .ran-btn:focus-visible { outline: var(--ran-btn-focus-outline, 2px solid var(--ran-color-focus, #0a6cff)); outline-offset: var(--ran-btn-focus-outline-offset, -2px); } /* Primary = the monochrome action (Vercel/Geist): black-on-white ↔ white-on-black. Text/ripple use --ran-color-primary-text so the ink inverts with the surface. */ &([type="primary"]) { .ran-btn-content { background-color: var(--ran-btn-background, var(--ran-color-primary, #111113)); background-image: var(--ran-btn-content-background-image, none); border-color: var(--ran-btn-border-color, var(--ran-color-primary, #111113)); color: var(--ran-btn-color, var(--ran-color-primary-text, #ffffff)); } } &([type="primary"]:not([disabled])) { .ran-btn::after { background-image: var( --ran-btn-after-background-image, radial-gradient(circle, var(--ran-color-primary-text, #ffffff) 10%, transparent 10.01%) ); } } &([type="primary"]:not([disabled]):active) { .ran-btn-content { background-color: var(--ran-btn-active-background, var(--ran-color-primary-active, #3f3f46)); border-color: var(--ran-btn-active-border-color, var(--ran-color-primary-active, #3f3f46)); } } // (hover: hover), not a width breakpoint: a mouse in a narrow window still hovers, // and a touch screen never leaves a sticky hover behind. @media (hover: hover) { /* Default (secondary) hover — Geist border-darken, not accent-flip: border steps 400 → 500 on the gray ladder, text stays primary text. Text buttons keep their transparent border; only their ink responds. */ &(:not([disabled], [type='text']):hover) { .ran-btn-content { border-color: var(--ran-btn-hover-border-color, var(--ran-color-border-hover, #b8b8c0)); color: var(--ran-btn-hover-color, var(--ran-color-text, #111113)); } } &([type='text']:not([disabled]):hover) { .ran-btn-content { color: var(--ran-btn-hover-color, var(--ran-color-text, #111113)); } } &([type="primary"]:not([disabled]):hover) { .ran-btn-content { background-color: var(--ran-btn-hover-background, var(--ran-color-primary-hover, #2a2a2e)); border-color: var(--ran-btn-hover-border-color, var(--ran-color-primary-hover, #2a2a2e)); color: var(--ran-btn-hover-color, var(--ran-color-primary-text, #ffffff)); } } &([type="warning"]:not([disabled]):hover) { .ran-btn-content { border-color: var(--ran-btn-warning-border-color, var(--ran-color-danger, #d70f2f)); background-color: var(--ran-btn-warning-background, var(--ran-color-danger, #d70f2f)); color: @dangerInk; } } } &([type="warning"]) { .ran-btn-content { border-color: var(--ran-btn-warning-border-color, var(--ran-color-danger, #d70f2f)); background-color: var(--ran-btn-warning-background, var(--ran-color-danger, #d70f2f)); background-image: var(--ran-btn-content-background-image, none); color: @dangerInk; } } &([type="warning"]:not([disabled])) { .ran-btn::after { background-image: var( --ran-btn-after-background-image, radial-gradient(circle, @dangerInk 10%, transparent 10.01%) ); } } // Text buttons are chromeless: no raised shadow, no filled surface behind // the transparent content. Both of those live unconditionally on `:host` // and `.ran-btn` (the surface layer's own comment explains why it needs a // background at all — filling the anti-aliased gap behind a *rounded, // opaque* content box in dark mode) so every other type keeps them; `text` // is the one type whose content box is intentionally transparent, so the // surface backing behind it was showing straight through as an unwanted // white rectangle, with the host's shadow drawn under it. &([type="text"]) { box-shadow: var(--ran-btn-text-box-shadow, none); .ran-btn { background: var(--ran-btn-text-surface-background, transparent); } // A transparent 1px border, not none: every type is the same 32px tall. .ran-btn-content { border: var(--ran-btn-text-border, 1px solid transparent); } } // One disabled recipe: recessed surface, decorative border, disabled ink. No // opacity — the old host + surface layers multiplied to 0.36 and lost the label. // Declared after the types so it overrides their fills at equal specificity. &([disabled]) { cursor: var(--ran-btn-disabled-cursor, not-allowed); pointer-events: var(--ran-btn-disabled-pointer-events, all); opacity: var(--ran-btn-disabled-opacity, 1); box-shadow: var(--ran-btn-disabled-box-shadow, none); .ran-btn { cursor: var(--ran-btn-surface-disabled-cursor, not-allowed); pointer-events: var(--ran-btn-surface-disabled-pointer-events, all); opacity: var(--ran-btn-surface-disabled-opacity, 1); } .ran-btn-content { background-color: var(--ran-btn-disabled-background, var(--ran-color-bg-subtle, #f7f7f8)); border-color: var(--ran-btn-disabled-border-color, var(--ran-color-border, #e4e4e8)); color: var(--ran-btn-disabled-color, var(--ran-color-text-disabled, #8a8a94)); } } // A disabled text button stays chromeless; only its ink goes quiet. &([type='text'][disabled]) .ran-btn-content { background-color: var(--ran-btn-text-disabled-background, transparent); border-color: transparent; } &(:not([disabled]):active) { .ran-btn::after { transform: var(--ran-btn-after-transform, translate(-50%, -50%) scale(0)); opacity: var(--ran-btn-after-opacity, 0.3); transition: var(--ran-btn-after-transition, 0s); } // Tactile press: the visible surface shrinks and springs back on release. The // individual `scale` property, not `transform`, so a host's own transform survives. .ran-btn-content { scale: var(--ran-btn-active-scale, 0.96); } } @media (hover: hover) { // `[effect='false']`, not a bare `[effect]`: the ripple is on by default, so only an // explicit false turns it off (`effect="true"` used to turn it off too). &(:not([disabled], [effect='false'])) { .ran-btn::after { content: ''; display: block; position: absolute; width: 100%; height: 100%; left: @clickX; top: @clickY; pointer-events: none; background-image: radial-gradient(circle, var(--ran-gray-alpha-400, #00000014) 10%, transparent 10.01%); background-repeat: no-repeat; background-position: 50%; transform: translate(-50%, -50%) scale(10); opacity: 0; // Decoration, not feedback: the press itself is the 100ms scale. A slower spread and a // long fade read as a soft ripple; at 100ms/200ms it landed as a hard flash. transition: transform 0.3s, opacity 0.8s; } } } // The ripple is decoration; reduced motion shows the press through the surface colour alone. @media (prefers-reduced-motion: reduce) { .ran-btn::after { display: none; } } .slot { display: var(--ran-btn-slot-display, block); } } .ran-btn-content { display: var(--ran-btn-content-display, flex); justify-content: var(--ran-btn-content-justify-content, space-between); align-items: var(--ran-btn-align-items, center); // 8+8 padding + 14 line-height + 1+1 border = 32px, the --ran-size-7 control height. min-height: var(--ran-btn-height, var(--ran-size-7, 32px)); padding: var(--ran-btn-padding, var(--ran-space-2, 8px) var(--ran-space-4, 16px)); border: var(--ran-btn-border, 1px solid transparent); border-image-source: var(--ran-btn-border-image-source, none); border-image-slice: var(--ran-btn-border-image-slice, 8); border-image-width: var(--ran-btn-border-image-width, var(--ran-skin-border-image-width, 4px)); border-image-outset: 0; border-image-repeat: stretch; border-radius: var(--ran-btn-border-radius, var(--ran-radius-sm, 8px)); border-color: var(--ran-btn-border-color, var(--ran-color-border, #e4e4e8)); color: var(--ran-btn-color, var(--ran-color-text, #111113)); line-height: var(--ran-btn-line-height, var(--ran-text-button-line-height, 1)); font-size: var(--ran-btn-font-size, var(--ran-text-button-size, 14px)); font-weight: var(--ran-btn-font-weight, var(--ran-text-button-weight, 500)); font-family: var(--ran-btn-font-family, var(--ran-skin-font-family, inherit)); white-space: var(--ran-btn-white-space, nowrap); text-align: var(--ran-btn-text-align, center); box-sizing: var(--ran-btn-content-box-sizing, border-box); // Press feedback lands within 100ms, the guide's feedback budget, and settles without // overshoot as the press scale (see :active) relaxes. transition: var(--ran-btn-transition, scale 0.1s var(--ran-motion-ease-standard, cubic-bezier(0.2, 0, 0, 1))); .icon { margin-right: var(--ran-btn-icon-margin-right, var(--ran-space-1, 4px)); } } @media (prefers-reduced-motion: reduce) { .ran-btn-content { transition: none; } } :host([surface='glass']:not([type='primary'], [type='warning'], [type='text'], [disabled])) { .ran-btn-glass-apply(); } /* Chromium drops :host-context(...):not(...); keep every host check inside :host(). */ :host-context([data-ran-surface='glass']):host( :not([surface='solid']):not([type='primary']):not([type='warning']):not([type='text']):not([disabled]) ) { .ran-btn-glass-apply(); }