sdxc

[ @sdxc/u/transform ]

rotate

Rotates the element in its own 2D plane.

import { rotate } from "@sdxc/u/transform";

Quick reference

Every documented call, beside the CSS it emits.

CallCSS
u.rotate(45)css({ "--ui-rotate": "45deg", transform: "... rotate(var(--ui-rotate, 0deg)) ..." })

Examples

Basic example

Use rotate(n) with a number of degrees, like rotate(45) or rotate(90), to turn an element in its own plane:

rotate(45)
rotate(90)
rotate(210)
<div mix={[...]}>
	<div mix={[...]}>
		<div mix={[rotate(45), ...]}>rotate(45)</div>
	</div>
	<div mix={[...]}>
		<div mix={[rotate(90), ...]}>rotate(90)</div>
	</div>
	<div mix={[...]}>
		<div mix={[rotate(210), ...]}>rotate(210)</div>
	</div>
</div>

Using negative values

Pass a negative number, like rotate(-15), to turn an element counterclockwise:

rotate(-15)
rotate(-45)
rotate(15)
<div mix={[...]}>
	<div mix={[...]}>
		<div mix={[rotate(-15), ...]}>rotate(-15)</div>
	</div>
	<div mix={[...]}>
		<div mix={[rotate(-45), ...]}>rotate(-45)</div>
	</div>
	<div mix={[...]}>
		<div mix={[rotate(15), ...]}>rotate(15)</div>
	</div>
</div>

Using other angle units

Pass a string to use any CSS angle unit, like rotate("0.125turn") or rotate("1rad"):

rotate("0.125turn")
rotate("1rad")
rotate("50grad")
<div mix={[...]}>
	<div mix={[...]}>
		<div mix={[rotate("0.125turn"), ...]}>rotate("0.125turn")</div>
	</div>
	<div mix={[...]}>
		<div mix={[rotate("1rad"), ...]}>rotate("1rad")</div>
	</div>
	<div mix={[...]}>
		<div mix={[rotate("50grad"), ...]}>rotate("50grad")</div>
	</div>
</div>

Applying on hover

Wrap it in hover() and add a transition("transform") to turn an element when the pointer is over it. Hover the tile to try it:

hover me
<div mix={[...]}>
	<div mix={[...]}>
		<div mix={[hover(rotate(12)), transition("transform"), ...]}>hover me</div>
	</div>
</div>

Using a custom value

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

u.rotate("2.75rem")

Applying on a state

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

u.hover(u.rotate(45))

Responsive design

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

u.at("md", u.rotate(45))

Signature

u.rotate(value: AngleValue)

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