sdxc

[ @sdxc/u/effects ]

ringShadow

Draws a selection ring that stays visible for as long as a component applies it, for persistently-selected swatches, chips, and thumbnails.

import { ringShadow } from "@sdxc/u/effects";

Quick reference

Every documented call, beside the CSS it emits.

CallCSS
u.ringShadow("brand")css({ "--ui-box-shadow-ring": "0 0 0 2px var(--ui-brand-bg-solid)", boxShadow: "var(--ui-box-shadow-ring, 0 0 #0000), var(--ui-box-shadow-elevation, 0 0 #0000)" })
u.ringShadow("danger", 3)css({ "--ui-box-shadow-ring": "0 0 0 3px var(--ui-danger-bg-solid)", boxShadow: "var(--ui-box-shadow-ring, 0 0 #0000), var(--ui-box-shadow-elevation, 0 0 #0000)" })

Examples

Basic example

Use ringShadow(tone) to draw a solid ring around an element, like a persistently selected thumbnail:

ringShadow("brand")
ringShadow("success")
ringShadow("danger")
<div mix={[...]}>
	<div mix={[...]}>
		<img mix={[ringShadow("brand"), ...]} src={...} alt="" />
		<span mix={[...]}>ringShadow("brand")</span>
	</div>
	<div mix={[...]}>
		<img mix={[ringShadow("success"), ...]} src={...} alt="" />
		<span mix={[...]}>ringShadow("success")</span>
	</div>
	<div mix={[...]}>
		<img mix={[ringShadow("danger"), ...]} src={...} alt="" />
		<span mix={[...]}>ringShadow("danger")</span>
	</div>
</div>

Changing the width

Pass a width as the second argument, in pixels or any CSS length; it's 2 by default:

ringShadow("brand", 1)
ringShadow("brand", 4)
ringShadow("brand", "0.5rem")
<div mix={[...]}>
	<div mix={[...]}>
		<img mix={[ringShadow("brand", 1), ...]} src={...} alt="" />
		<span mix={[...]}>ringShadow("brand", 1)</span>
	</div>
	<div mix={[...]}>
		<img mix={[ringShadow("brand", 4), ...]} src={...} alt="" />
		<span mix={[...]}>ringShadow("brand", 4)</span>
	</div>
	<div mix={[...]}>
		<img mix={[ringShadow("brand", "0.5rem"), ...]} src={...} alt="" />
		<span mix={[...]}>ringShadow("brand", "0.5rem")</span>
	</div>
</div>

Combining with a shadow

The ring and shadow() write separate layers of one box-shadow, so an element can have both:

Selected plan
<div mix={[ringShadow("brand"), shadow("xl"), ...]}>Selected plan</div>

Marking the selected option

Combine it with has(":checked", …) to ring the option whose radio is checked. Pick an option:

<div mix={[...]}>
	<label mix={[has(":checked", ringShadow("brand")), ...]}>
		<input type="radio" name="plan" checked /> Monthly
	</label>
	<label mix={[has(":checked", ringShadow("brand")), ...]}>
		<input type="radio" name="plan" /> Yearly
	</label>
</div>

Applying on a state

Wrap the call in a state utility to scope it to one selector.

u.hover(u.ringShadow("brand"))

Responsive design

Wrap the call in a container query to scope it to one width.

u.at("md", u.ringShadow("brand"))

Customizing your theme

Customizing colors

Define a palette as --ui-color-{name}-{50..950} and map a tone onto it with the --ui-{tone}-* variables, the way theme.css maps the built-in ones:

:root {
	--ui-color-info-50: oklch(0.97 0.02 230);
	--ui-color-info-200: oklch(0.88 0.06 230);
	--ui-color-info-500: oklch(0.62 0.16 230);
	--ui-color-info-600: oklch(0.52 0.18 230);
	--ui-color-info-900: oklch(0.3 0.1 230);

	--ui-info-bg-tint: var(--ui-color-info-50);
	--ui-info-bg-solid: var(--ui-color-info-600);
	--ui-info-fg: var(--ui-color-info-600);
	--ui-info-fg-muted: var(--ui-color-info-500);
	--ui-info-fg-emphasis: var(--ui-color-info-900);
	--ui-info-fg-on-solid: white;
	--ui-info-border: var(--ui-color-info-200);
	--ui-info-border-strong: var(--ui-color-info-600);
	--ui-info-ring: var(--ui-color-info-500);
}
declare module "@sdxc/u" {
	interface ColorPalettes {
		info: true;
	}
	interface SemanticTones {
		info: true;
	}
}

The new name is then accepted wherever the scale is:

ringShadow("info")

Signature

u.ringShadow(value: ColorValue | (string & {}), width?: number | (string & {}))

Written by Sergio Xalambrí. Follow @sergiodxa for new packages, or sponsor the work.