SearchCtrlK

  • ↑↓navigate
  • ↵open
  • escclose

Can’t find it? Contact us

opacity

Applies opacity from a 0-100 integer.

tsx
import { opacity } from "@sdxc/u/effects";

Quick reference

Every documented call, beside the CSS it emits.

CallCSS
u.opacity(50)css({ opacity: 0.5 })

Examples

Basic example

Use opacity(n) with a value from 0 to 100 to make an element and everything inside it see-through:

opacity(100)
opacity(75)
opacity(50)
opacity(25)
tsx
<div mix={[...]}>
	<div mix={[opacity(100), ...]}>opacity(100)</div>
	<div mix={[opacity(75), ...]}>opacity(75)</div>
	<div mix={[opacity(50), ...]}>opacity(50)</div>
	<div mix={[opacity(25), ...]}>opacity(25)</div>
</div>

Fading disabled controls

Combine it with disabled() to fade a control while it can't be used:

tsx
<div mix={[...]}>
	<button type="button" mix={[disabled(opacity(50)), ...]}>
		Save
	</button>
	<button type="button" disabled mix={[disabled(opacity(50)), ...]}>
		Save
	</button>
</div>

Using a custom value

Every scale argument also takes a raw CSS value, which passes through untouched.

typescript
u.opacity("2.75rem")

Applying on a state

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

typescript
u.hover(u.opacity(50))

Responsive design

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

typescript
u.at("md", u.opacity(50))

Signature

typescript
u.opacity(value: number)
@sdxc/u

Can’t find it? Contact us