Moon Sphere
Moon sphere graphic: a single-element sphere lit on one limb, a radial gradient from the lower-left corner running transparent out to a warm rim color on the far edge. Used for moonrise effects over dark grounds.
import { cn } from "cn"
/**
* A sphere lit only on one limb, for a moon rising over a dark ground. A
* radial gradient from the lower-left corner runs transparent out to
* `moonColor` at the upper-right edge, so the rest of the disc shows the
* ground behind it. It is decorative and hidden from assistive tech.
*/
function MoonSphere({
className,
size = 256,
moonColor = "oklch(0.65 0.12 55)",
style,
...props
}: React.ComponentProps<"div"> & {
/** Diameter in px. */
size?: number
/** The rim light's color. */
moonColor?: string
}) {
return (
<div
aria-hidden="true"
data-slot="moon-sphere"
className={cn("block rounded-full", className)}
style={{
width: size,
maxWidth: "100%",
background: `radial-gradient(circle at 0% 100%, transparent 60%, ${moonColor} 100%)`,
...style,
height: "auto",
aspectRatio: "1 / 1",
flexShrink: 0,
}}
{...props}
/>
)
}
export { MoonSphere }
import { MoonSphere } from "@/components/orbs/moon-sphere"
// The default warm rim, and the same sphere with moonColor set.
export default function MoonSphereDemo() {
return (
<div className="flex flex-wrap items-center justify-center gap-16">
<MoonSphere size={320} />
<MoonSphere size={320} moonColor="oklch(0.72 0.11 232)" />
</div>
)
}
Installation
pnpm dlx shadcn@latest add @01orbital/moon-spherenpx shadcn@latest add @01orbital/moon-sphereyarn dlx shadcn@latest add @01orbital/moon-spherebunx --bun shadcn@latest add @01orbital/moon-sphereUsage
import { MoonSphere } from "@/components/orbs/moon-sphere"
// The default warm rim, and the same sphere with moonColor set.
export default function MoonSphereDemo() {
return (
<div className="flex flex-wrap items-center justify-center gap-16">
<MoonSphere size={320} />
<MoonSphere size={320} moonColor="oklch(0.72 0.11 232)" />
</div>
)
}This example installs with everything it uses:
pnpm dlx shadcn@latest add @01orbital/moon-sphere-demonpx shadcn@latest add @01orbital/moon-sphere-demoyarn dlx shadcn@latest add @01orbital/moon-sphere-demobunx --bun shadcn@latest add @01orbital/moon-sphere-demoExamples
Bluemoon-sphere-blue
Blue moon example showing MoonSphere with a blue rim on a dark ground.
import { MoonSphere } from "@/components/orbs/moon-sphere"
// The rim color: any CSS color works, oklch keeps the lightness even.
/** Moon Sphere with a blue rim, on a dark ground. */
export default function MoonSphereBlue() {
return (
<div className="dark grid min-h-full w-full flex-1 place-items-center bg-background p-10">
<MoonSphere size={280} moonColor="oklch(0.72 0.11 232)" />
</div>
)
}
import { cn } from "cn"
/**
* A sphere lit only on one limb, for a moon rising over a dark ground. A
* radial gradient from the lower-left corner runs transparent out to
* `moonColor` at the upper-right edge, so the rest of the disc shows the
* ground behind it. It is decorative and hidden from assistive tech.
*/
function MoonSphere({
className,
size = 256,
moonColor = "oklch(0.65 0.12 55)",
style,
...props
}: React.ComponentProps<"div"> & {
/** Diameter in px. */
size?: number
/** The rim light's color. */
moonColor?: string
}) {
return (
<div
aria-hidden="true"
data-slot="moon-sphere"
className={cn("block rounded-full", className)}
style={{
width: size,
maxWidth: "100%",
background: `radial-gradient(circle at 0% 100%, transparent 60%, ${moonColor} 100%)`,
...style,
height: "auto",
aspectRatio: "1 / 1",
flexShrink: 0,
}}
{...props}
/>
)
}
export { MoonSphere }
pnpm dlx shadcn@latest add @01orbital/moon-sphere-bluenpx shadcn@latest add @01orbital/moon-sphere-blueyarn dlx shadcn@latest add @01orbital/moon-sphere-bluebunx --bun shadcn@latest add @01orbital/moon-sphere-blueSilvermoon-sphere-silver
Moon Sphere color example with a silver rim on a dark ground.
import { MoonSphere } from "@/components/orbs/moon-sphere"
// The rim color: any CSS color works, oklch keeps the lightness even.
/** Moon Sphere with a silver rim, on a dark ground. */
export default function MoonSphereSilver() {
return (
<div className="dark grid min-h-full w-full flex-1 place-items-center bg-background p-10">
<MoonSphere size={280} moonColor="oklch(0.86 0.01 250)" />
</div>
)
}
import { cn } from "cn"
/**
* A sphere lit only on one limb, for a moon rising over a dark ground. A
* radial gradient from the lower-left corner runs transparent out to
* `moonColor` at the upper-right edge, so the rest of the disc shows the
* ground behind it. It is decorative and hidden from assistive tech.
*/
function MoonSphere({
className,
size = 256,
moonColor = "oklch(0.65 0.12 55)",
style,
...props
}: React.ComponentProps<"div"> & {
/** Diameter in px. */
size?: number
/** The rim light's color. */
moonColor?: string
}) {
return (
<div
aria-hidden="true"
data-slot="moon-sphere"
className={cn("block rounded-full", className)}
style={{
width: size,
maxWidth: "100%",
background: `radial-gradient(circle at 0% 100%, transparent 60%, ${moonColor} 100%)`,
...style,
height: "auto",
aspectRatio: "1 / 1",
flexShrink: 0,
}}
{...props}
/>
)
}
export { MoonSphere }
pnpm dlx shadcn@latest add @01orbital/moon-sphere-silvernpx shadcn@latest add @01orbital/moon-sphere-silveryarn dlx shadcn@latest add @01orbital/moon-sphere-silverbunx --bun shadcn@latest add @01orbital/moon-sphere-silverRisingmoon-sphere-rising
Hero section example with a Moon Sphere: a dark band with a centered heading and a line of copy, and a large glowing moon rising from the bottom edge like a planet on the horizon.
import { MoonSphere } from "@/components/orbs/moon-sphere"
// The copy: change text here, not in the markup.
const COPY = {
title: "Work that finishes overnight",
body: "Hand off the backlog at six and read the summary with your coffee.",
} as const
/**
* A Moon Sphere rising from the bottom edge of a dark section, under a
* centered heading. Only the top half of the disc shows; the section clips
* the rest.
*/
export default function MoonSphereRising() {
return (
<section className="dark relative isolate flex min-h-[28rem] w-full flex-1 flex-col items-center overflow-hidden bg-background px-6 pt-20 text-center text-foreground">
<h2 className="max-w-xl text-4xl font-medium tracking-tight text-balance sm:text-5xl">
{COPY.title}
</h2>
<p className="mt-4 max-w-md text-muted-foreground">{COPY.body}</p>
<MoonSphere
size={520}
className="absolute bottom-0 left-1/2 -z-10 -translate-x-1/2 translate-y-1/2"
/>
</section>
)
}
import { cn } from "cn"
/**
* A sphere lit only on one limb, for a moon rising over a dark ground. A
* radial gradient from the lower-left corner runs transparent out to
* `moonColor` at the upper-right edge, so the rest of the disc shows the
* ground behind it. It is decorative and hidden from assistive tech.
*/
function MoonSphere({
className,
size = 256,
moonColor = "oklch(0.65 0.12 55)",
style,
...props
}: React.ComponentProps<"div"> & {
/** Diameter in px. */
size?: number
/** The rim light's color. */
moonColor?: string
}) {
return (
<div
aria-hidden="true"
data-slot="moon-sphere"
className={cn("block rounded-full", className)}
style={{
width: size,
maxWidth: "100%",
background: `radial-gradient(circle at 0% 100%, transparent 60%, ${moonColor} 100%)`,
...style,
height: "auto",
aspectRatio: "1 / 1",
flexShrink: 0,
}}
{...props}
/>
)
}
export { MoonSphere }
pnpm dlx shadcn@latest add @01orbital/moon-sphere-risingnpx shadcn@latest add @01orbital/moon-sphere-risingyarn dlx shadcn@latest add @01orbital/moon-sphere-risingbunx --bun shadcn@latest add @01orbital/moon-sphere-risingSplitmoon-sphere-split
Quote section example with a Moon Sphere: a dark band with a testimonial and byline on the right and a glowing moon cropped by the left edge. On phones the moon steps aside to keep the quote readable.
import {
Byline,
BylineDescription,
BylineName,
} from "@/components/byline/byline"
import { MoonSphere } from "@/components/orbs/moon-sphere"
import { Quote, QuoteContent } from "@/components/quote/quote"
// The copy: change text here, not in the markup.
const COPY = {
quote:
"We stopped staying late to clear the queue. The morning summary tells us what changed and what still needs a person.",
name: "Pamela Melroy",
role: "Head of Support, Northfield",
} as const
/**
* A Moon Sphere cropped by the left edge of a dark band, with a quote on the
* right. On narrow screens the moon steps aside and the quote takes the
* width.
*/
export default function MoonSphereSplit() {
return (
<section className="dark relative isolate flex min-h-[30rem] w-full flex-1 items-center justify-end overflow-hidden bg-background px-6 py-24 text-foreground">
<MoonSphere
size={420}
className="absolute top-1/2 -left-48 -z-10 -translate-y-1/2 max-sm:hidden"
/>
<Quote className="max-w-md sm:mx-6">
<QuoteContent className="max-w-xl font-medium text-balance">
<p>{COPY.quote}</p>
</QuoteContent>
<Byline render={<figcaption />}>
<BylineName>{COPY.name}</BylineName>
<BylineDescription>{COPY.role}</BylineDescription>
</Byline>
</Quote>
</section>
)
}
import type { ComponentProps } from "react"
import { mergeProps } from "@base-ui/react/merge-props"
import { useRender } from "@base-ui/react/use-render"
import { cn } from "cn"
type BylineSize = "md" | "sm"
type BylineState = { slot: "byline"; size: BylineSize }
type BylineAvatarState = { slot: "byline-avatar" }
/**
* A person's byline: an optional `BylineAvatar`, then `BylineName` with a
* `BylineDescription` under it, as a `div`. With an avatar it becomes two
* columns: the avatar spans both lines, 16px from the text. Under a quote,
* pass `render={<figcaption />}`; in a centered quote add `w-fit text-left` so it shrinks to fit
* and keeps its text left-aligned.
*
* At `size="md"` (the default) the name is 16px/24px semibold and the
* description 14px/20px muted, 2px apart; a 40px avatar matches the two
* lines. At `size="sm"` both lines are 12px/20px, the name in regular weight,
* the byline of a card footer.
*/
function Byline({
className,
size = "md",
render,
...props
}: useRender.ComponentProps<"div", BylineState> & {
/** The type size: `md` (the default) 16px over 14px, `sm` 12px over 12px for a card footer. */
size?: BylineSize
}) {
return useRender({
defaultTagName: "div",
render,
state: { slot: "byline", size },
props: mergeProps<"div">(
{
className: cn(
"group/byline grid items-center gap-x-4 gap-y-0.5 text-sm/5 has-data-[slot=byline-avatar]:grid-cols-[auto_1fr] data-[size=sm]:text-xs/5",
className
),
},
props
),
})
}
/**
* Holds the person's picture beside the name and description: a stock
* `Avatar`, an orb avatar or an image, 40px recommended. Use
* `render={<div />}` when the artwork has a block root.
*/
function BylineAvatar({
className,
render,
...props
}: useRender.ComponentProps<"span", BylineAvatarState>) {
return useRender({
defaultTagName: "span",
render,
state: { slot: "byline-avatar" },
props: mergeProps<"span">(
{ className: cn("row-span-2 flex", className) },
props
),
})
}
/** The person's name, 16px/24px semibold, held close to the line below; 12px regular in a `sm` byline. */
function BylineName({ className, ...props }: ComponentProps<"span">) {
return (
<span
data-slot="byline-name"
className={cn(
"self-end text-base/6 font-semibold group-data-[size=sm]/byline:text-xs/5 group-data-[size=sm]/byline:font-normal",
className
)}
{...props}
/>
)
}
/**
* The second line under the name, such as a job title, a company, a handle
* or a date, in 14px/20px muted text; 12px in a `sm` byline.
*/
function BylineDescription({ className, ...props }: ComponentProps<"span">) {
return (
<span
data-slot="byline-description"
className={cn("self-start text-muted-foreground", className)}
{...props}
/>
)
}
export { Byline, BylineAvatar, BylineName, BylineDescription }
import { cn } from "cn"
/**
* A sphere lit only on one limb, for a moon rising over a dark ground. A
* radial gradient from the lower-left corner runs transparent out to
* `moonColor` at the upper-right edge, so the rest of the disc shows the
* ground behind it. It is decorative and hidden from assistive tech.
*/
function MoonSphere({
className,
size = 256,
moonColor = "oklch(0.65 0.12 55)",
style,
...props
}: React.ComponentProps<"div"> & {
/** Diameter in px. */
size?: number
/** The rim light's color. */
moonColor?: string
}) {
return (
<div
aria-hidden="true"
data-slot="moon-sphere"
className={cn("block rounded-full", className)}
style={{
width: size,
maxWidth: "100%",
background: `radial-gradient(circle at 0% 100%, transparent 60%, ${moonColor} 100%)`,
...style,
height: "auto",
aspectRatio: "1 / 1",
flexShrink: 0,
}}
{...props}
/>
)
}
export { MoonSphere }
import type { ComponentProps } from "react"
import { cn } from "cn"
/**
* A quote and its attribution, as a `figure`: a `QuoteContent`, then a
* `Byline` with `render={<figcaption />}`, 24px apart. It inherits the
* surrounding font and alignment. Layout around it (grids, columns, rules,
* panels) belongs to the block that places it.
*/
function Quote({ className, ...props }: ComponentProps<"figure">) {
return (
<figure
data-slot="quote"
className={cn("flex flex-col gap-6", className)}
{...props}
/>
)
}
/**
* The quoted words, as a `blockquote`, at 20px with 32px lines. Put the
* quotation marks in the copy. Pass one or more `p` children for several
* paragraphs; change the size with `className`.
*
* The opening mark sits inside the text edge. For a left-aligned quote whose
* mark should hang outside it, use `QuoteHangingContent` in its place.
*/
function QuoteContent({ className, ...props }: ComponentProps<"blockquote">) {
return (
<blockquote
data-slot="quote-content"
className={cn("grid gap-4 text-xl/8 text-pretty", className)}
{...props}
/>
)
}
/**
* The quoted words with the opening quotation mark hung outside the text
* edge, so the first letter lines up with the lines below it. Use it in
* place of `QuoteContent`; everything else about it is the same.
*
* Choose it only when all three hold. The quote is aligned to the start, not
* centered: a centered first line would shift off center. The copy starts
* with a quotation mark: the first line moves whether or not a mark is
* there. The box around the quote has padding on the start side at least as
* wide as the mark, about 7px at 20px text and 17px at 40px: the mark hangs
* into that padding, and a box that clips its contents with no padding cuts
* it off.
*
* The first line of the first paragraph is pulled back by `--quote-hang`,
* the width of the opening mark: 0.37em for Geist and Geist Serif
* (`font-serif`), and 0.44em when the element carries `font-display`. Set
* the variable through `className` for another font; a font with optical
* sizes changes the mark's width a little with the text size. It follows the
* text direction, so it hangs on the right in right-to-left text.
*/
function QuoteHangingContent({
className,
...props
}: ComponentProps<"blockquote">) {
return (
<blockquote
data-slot="quote-content"
data-hanging=""
className={cn(
"grid gap-4 text-xl/8 text-pretty",
"[--quote-hang:0.37em] [&.font-display]:[--quote-hang:0.44em]",
// Copy set straight in the blockquote hangs on the blockquote; copy in
// paragraphs hangs on the first one only, since later ones carry no mark.
"not-has-[p]:indent-[calc(var(--quote-hang)*-1)] *:[p]:first:indent-[calc(var(--quote-hang)*-1)]",
className
)}
{...props}
/>
)
}
export { Quote, QuoteContent, QuoteHangingContent }
pnpm dlx shadcn@latest add @01orbital/moon-sphere-splitnpx shadcn@latest add @01orbital/moon-sphere-splityarn dlx shadcn@latest add @01orbital/moon-sphere-splitbunx --bun shadcn@latest add @01orbital/moon-sphere-splitSleep Schedulemoon-sphere-sleep-schedule
Sleep tracker card example on deep indigo: a lilac Moon Sphere above the wind-down time and two sleep averages. Shows the glowing orb as a status graphic in a health or wellness dashboard widget.
The source comes with full access.
One payment of $149 opens the source right here and lets the CLI install every paid component, with lifetime updates.
pnpm dlx shadcn@latest add @01orbital/moon-sphere-sleep-schedulenpx shadcn@latest add @01orbital/moon-sphere-sleep-scheduleyarn dlx shadcn@latest add @01orbital/moon-sphere-sleep-schedulebunx --bun shadcn@latest add @01orbital/moon-sphere-sleep-scheduleGame Briefingmoon-sphere-game-briefing
Game chapter card example with a Moon Sphere: a large ember-rimmed moon glows in the corner of a near-black card beside a folded mission briefing. Shows the orb as moody artwork for game menus and story screens.
The source comes with full access.
One payment of $149 opens the source right here and lets the CLI install every paid component, with lifetime updates.
pnpm dlx shadcn@latest add @01orbital/moon-sphere-game-briefingnpx shadcn@latest add @01orbital/moon-sphere-game-briefingyarn dlx shadcn@latest add @01orbital/moon-sphere-game-briefingbunx --bun shadcn@latest add @01orbital/moon-sphere-game-briefingBlue Frostmoon-sphere-blue-frost
Frosted panel example showing a blue MoonSphere on a dark glass panel, with a small caption row above it and one line of text below.
"use client"
import { useEffect, useRef, useState } from "react"
import { cn } from "cn"
import { Eyebrow } from "@/components/eyebrow/eyebrow"
import { MoonSphere } from "@/components/orbs/moon-sphere"
// The copy: change text here, not in the markup.
const COPY = {
product: "Moon Sphere",
index: "01 / Blue",
caption: "A single lit limb, with the ground showing through.",
} as const
/** A blue Moon Sphere on a frosted dark panel, with a small caption row above it and one line of text below. */
export default function MoonSphereBlueFrost() {
return (
<div className="dark relative isolate w-full max-w-[606px] overflow-hidden rounded-[20px] bg-background text-foreground [--font-display:var(--font-serif)] max-[600px]:rounded-[14px]">
<div className="surface-frost relative isolate grid min-h-[420px] place-items-center content-center gap-7 overflow-hidden p-10 max-[600px]:min-h-[380px] max-[600px]:p-[28px_24px]">
<div className="relative z-2 flex w-full flex-wrap justify-between gap-3">
<Eyebrow variant="mono" className="text-current">
{COPY.product}
</Eyebrow>
<Eyebrow variant="mono" className="text-current">
{COPY.index}
</Eyebrow>
</div>
<Orb size={280} />
<p className="text-xs/5 text-muted-foreground">{COPY.caption}</p>
</div>
</div>
)
}
function Orb({
color = "oklch(0.75 0.12 232)",
size = 280,
grow = 1,
className,
}: {
color?: string
size?: number
grow?: number
className?: string
}) {
const { ref, width } = useWidth(Math.min(size, 240))
return (
<div
ref={ref}
aria-hidden="true"
className={cn("relative aspect-square shrink-0", className)}
style={{ width: "min(" + grow * 100 + "%, " + size + "px)" }}
>
<div className="relative size-full">
<MoonSphere size={width} moonColor={color} />
</div>
</div>
)
}
function useWidth(initial: number) {
const ref = useRef<HTMLDivElement>(null)
const [width, setWidth] = useState(initial)
useEffect(() => {
const node = ref.current
if (!node) return
const observer = new ResizeObserver(([entry]) => {
const next = Math.round(entry.contentRect.width)
if (next > 0) setWidth((current) => (current === next ? current : next))
})
observer.observe(node)
return () => observer.disconnect()
}, [])
return { ref, width }
}
import { mergeProps } from "@base-ui/react/merge-props"
import { useRender } from "@base-ui/react/use-render"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "cn"
const eyebrowVariants = cva("text-eyebrow", {
variants: {
/**
* `default` is a 14px/20px label. `icon` adds a row with a 16px icon
* and a 12px gap; put the icon first and give it `aria-hidden`.
* `mono` and `caps` are 12px/20px uppercase labels with 0.12em
* tracking, in the mono and inherited faces respectively.
*/
variant: {
default: "text-sm/5 font-medium text-eyebrow",
icon: "flex items-center gap-3 text-sm/5 font-medium [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
mono: "font-mono text-xs/5 font-medium tracking-[0.12em] uppercase",
caps: "text-xs/5 font-medium tracking-[0.12em] uppercase",
},
},
defaultVariants: { variant: "default" },
})
/**
* A short label above a heading, rendered as a `<p>` at weight 500.
* The default is 14px/20px in the kit's eyebrow color. The surrounding
* layout controls the space to the heading. Use `className` to customize
* the typography or color, and `render` to change the element.
*/
function Eyebrow({
className,
variant = "default",
render,
...props
}: useRender.ComponentProps<"p"> & VariantProps<typeof eyebrowVariants>) {
return useRender({
defaultTagName: "p",
render,
state: { slot: "eyebrow", variant },
props: mergeProps<"p">(
{ className: cn(eyebrowVariants({ variant }), className) },
props
),
})
}
export { Eyebrow, eyebrowVariants }
import { cn } from "cn"
/**
* A sphere lit only on one limb, for a moon rising over a dark ground. A
* radial gradient from the lower-left corner runs transparent out to
* `moonColor` at the upper-right edge, so the rest of the disc shows the
* ground behind it. It is decorative and hidden from assistive tech.
*/
function MoonSphere({
className,
size = 256,
moonColor = "oklch(0.65 0.12 55)",
style,
...props
}: React.ComponentProps<"div"> & {
/** Diameter in px. */
size?: number
/** The rim light's color. */
moonColor?: string
}) {
return (
<div
aria-hidden="true"
data-slot="moon-sphere"
className={cn("block rounded-full", className)}
style={{
width: size,
maxWidth: "100%",
background: `radial-gradient(circle at 0% 100%, transparent 60%, ${moonColor} 100%)`,
...style,
height: "auto",
aspectRatio: "1 / 1",
flexShrink: 0,
}}
{...props}
/>
)
}
export { MoonSphere }
pnpm dlx shadcn@latest add @01orbital/moon-sphere-blue-frostnpx shadcn@latest add @01orbital/moon-sphere-blue-frostyarn dlx shadcn@latest add @01orbital/moon-sphere-blue-frostbunx --bun shadcn@latest add @01orbital/moon-sphere-blue-frostAmber Papermoon-sphere-amber-paper
Moonrise example showing MoonSphere: warm paper holds an amber sphere at a modest size, with a short caption row and one line of note text.
"use client"
import { useEffect, useRef, useState } from "react"
import { cn } from "cn"
import { Eyebrow } from "@/components/eyebrow/eyebrow"
import { MoonSphere } from "@/components/orbs/moon-sphere"
// The copy: change text here, not in the markup.
const COPY = {
study: "Daylight study",
color: "Amber",
caption: "The same transparent moon, against a lighter ground.",
} as const
/** Warm paper holds an amber Moon Sphere at a modest size, with a short caption row and one line of note text. */
export default function MoonSphereAmberPaper() {
return (
<div className="theme-sand relative isolate w-full max-w-[606px] overflow-hidden rounded-[20px] bg-background text-foreground [--font-display:var(--font-serif)] max-[600px]:rounded-[14px]">
<div className="relative isolate grid min-h-[420px] place-items-center content-center gap-7 overflow-hidden p-10 max-[600px]:min-h-[380px] max-[600px]:p-[28px_24px]">
<div className="relative z-2 flex w-full flex-wrap justify-between gap-3">
<Eyebrow variant="mono" className="text-current">
{COPY.study}
</Eyebrow>
<Eyebrow variant="mono" className="text-current">
{COPY.color}
</Eyebrow>
</div>
<Orb color="oklch(0.77 0.14 65)" size={260} />
<p className="text-xs/5 text-muted-foreground">{COPY.caption}</p>
</div>
</div>
)
}
function Orb({
color = "oklch(0.75 0.12 232)",
size = 280,
grow = 1,
className,
}: {
color?: string
size?: number
grow?: number
className?: string
}) {
const { ref, width } = useWidth(Math.min(size, 240))
return (
<div
ref={ref}
aria-hidden="true"
className={cn("relative aspect-square shrink-0", className)}
style={{ width: "min(" + grow * 100 + "%, " + size + "px)" }}
>
<div className="relative size-full">
<MoonSphere size={width} moonColor={color} />
</div>
</div>
)
}
function useWidth(initial: number) {
const ref = useRef<HTMLDivElement>(null)
const [width, setWidth] = useState(initial)
useEffect(() => {
const node = ref.current
if (!node) return
const observer = new ResizeObserver(([entry]) => {
const next = Math.round(entry.contentRect.width)
if (next > 0) setWidth((current) => (current === next ? current : next))
})
observer.observe(node)
return () => observer.disconnect()
}, [])
return { ref, width }
}
import { mergeProps } from "@base-ui/react/merge-props"
import { useRender } from "@base-ui/react/use-render"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "cn"
const eyebrowVariants = cva("text-eyebrow", {
variants: {
/**
* `default` is a 14px/20px label. `icon` adds a row with a 16px icon
* and a 12px gap; put the icon first and give it `aria-hidden`.
* `mono` and `caps` are 12px/20px uppercase labels with 0.12em
* tracking, in the mono and inherited faces respectively.
*/
variant: {
default: "text-sm/5 font-medium text-eyebrow",
icon: "flex items-center gap-3 text-sm/5 font-medium [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
mono: "font-mono text-xs/5 font-medium tracking-[0.12em] uppercase",
caps: "text-xs/5 font-medium tracking-[0.12em] uppercase",
},
},
defaultVariants: { variant: "default" },
})
/**
* A short label above a heading, rendered as a `<p>` at weight 500.
* The default is 14px/20px in the kit's eyebrow color. The surrounding
* layout controls the space to the heading. Use `className` to customize
* the typography or color, and `render` to change the element.
*/
function Eyebrow({
className,
variant = "default",
render,
...props
}: useRender.ComponentProps<"p"> & VariantProps<typeof eyebrowVariants>) {
return useRender({
defaultTagName: "p",
render,
state: { slot: "eyebrow", variant },
props: mergeProps<"p">(
{ className: cn(eyebrowVariants({ variant }), className) },
props
),
})
}
export { Eyebrow, eyebrowVariants }
import { cn } from "cn"
/**
* A sphere lit only on one limb, for a moon rising over a dark ground. A
* radial gradient from the lower-left corner runs transparent out to
* `moonColor` at the upper-right edge, so the rest of the disc shows the
* ground behind it. It is decorative and hidden from assistive tech.
*/
function MoonSphere({
className,
size = 256,
moonColor = "oklch(0.65 0.12 55)",
style,
...props
}: React.ComponentProps<"div"> & {
/** Diameter in px. */
size?: number
/** The rim light's color. */
moonColor?: string
}) {
return (
<div
aria-hidden="true"
data-slot="moon-sphere"
className={cn("block rounded-full", className)}
style={{
width: size,
maxWidth: "100%",
background: `radial-gradient(circle at 0% 100%, transparent 60%, ${moonColor} 100%)`,
...style,
height: "auto",
aspectRatio: "1 / 1",
flexShrink: 0,
}}
{...props}
/>
)
}
export { MoonSphere }
pnpm dlx shadcn@latest add @01orbital/moon-sphere-amber-papernpx shadcn@latest add @01orbital/moon-sphere-amber-paperyarn dlx shadcn@latest add @01orbital/moon-sphere-amber-paperbunx --bun shadcn@latest add @01orbital/moon-sphere-amber-paperSilver Cropmoon-sphere-silver-crop
Cropped orb panel example: an oversized silver Moon Sphere pushed off the left edge of a midnight blue panel so only its lit limb shows. A bold crescent backdrop for banners and hero sections.
"use client"
import { useEffect, useRef, useState } from "react"
import { cn } from "cn"
import { MoonSphere } from "@/components/orbs/moon-sphere"
/** An oversized silver Moon Sphere pushed off the left edge of a midnight blue panel, so only its lit limb shows. */
export default function MoonSphereSilverCrop() {
return (
<div className="dark flex w-full justify-center">
<div className="theme-blue relative isolate w-full max-w-[606px] overflow-hidden rounded-[20px] bg-background text-foreground [--font-display:var(--font-serif)] max-[600px]:rounded-[14px]">
<div className="relative isolate min-h-[460px] overflow-hidden p-10 max-[600px]:min-h-[400px] max-[600px]:p-[28px_24px]">
<Orb
color="oklch(0.88 0.01 250)"
size={680}
grow={1.5}
className="absolute top-1/2 -left-[20%] -translate-y-1/2"
/>
</div>
</div>
</div>
)
}
function Orb({
color = "oklch(0.75 0.12 232)",
size = 280,
grow = 1,
className,
}: {
color?: string
size?: number
grow?: number
className?: string
}) {
const { ref, width } = useWidth(Math.min(size, 240))
return (
<div
ref={ref}
aria-hidden="true"
className={cn("relative aspect-square shrink-0", className)}
style={{ width: "min(" + grow * 100 + "%, " + size + "px)" }}
>
<div className="relative size-full">
<MoonSphere size={width} moonColor={color} />
</div>
</div>
)
}
function useWidth(initial: number) {
const ref = useRef<HTMLDivElement>(null)
const [width, setWidth] = useState(initial)
useEffect(() => {
const node = ref.current
if (!node) return
const observer = new ResizeObserver(([entry]) => {
const next = Math.round(entry.contentRect.width)
if (next > 0) setWidth((current) => (current === next ? current : next))
})
observer.observe(node)
return () => observer.disconnect()
}, [])
return { ref, width }
}
import { cn } from "cn"
/**
* A sphere lit only on one limb, for a moon rising over a dark ground. A
* radial gradient from the lower-left corner runs transparent out to
* `moonColor` at the upper-right edge, so the rest of the disc shows the
* ground behind it. It is decorative and hidden from assistive tech.
*/
function MoonSphere({
className,
size = 256,
moonColor = "oklch(0.65 0.12 55)",
style,
...props
}: React.ComponentProps<"div"> & {
/** Diameter in px. */
size?: number
/** The rim light's color. */
moonColor?: string
}) {
return (
<div
aria-hidden="true"
data-slot="moon-sphere"
className={cn("block rounded-full", className)}
style={{
width: size,
maxWidth: "100%",
background: `radial-gradient(circle at 0% 100%, transparent 60%, ${moonColor} 100%)`,
...style,
height: "auto",
aspectRatio: "1 / 1",
flexShrink: 0,
}}
{...props}
/>
)
}
export { MoonSphere }
pnpm dlx shadcn@latest add @01orbital/moon-sphere-silver-cropnpx shadcn@latest add @01orbital/moon-sphere-silver-cropyarn dlx shadcn@latest add @01orbital/moon-sphere-silver-cropbunx --bun shadcn@latest add @01orbital/moon-sphere-silver-cropJade Risemoon-sphere-jade-rise
Call to action section example with a Moon Sphere: a centered invitation sits above a large jade moon rising from the bottom edge of a dark panel. A glowing orb horizon for landing page closing sections.
"use client"
import { useEffect, useRef, useState } from "react"
import { cn } from "cn"
import { Eyebrow } from "@/components/eyebrow/eyebrow"
import { MoonSphere } from "@/components/orbs/moon-sphere"
import { buttonVariants } from "@/components/ui/button"
// The copy: change text here, not in the markup.
const COPY = {
eyebrow: "A place for the next idea",
title: "Start with something you want to make.",
body: "Find a scene, a surface, or a component that gives the next page its direction.",
cta: "Explore the library",
} as const
/** A centered invitation sits above a large jade Moon Sphere rising from the bottom edge of a dark, limned panel. */
export default function MoonSphereJadeRise() {
return (
<div className="dark relative isolate w-full max-w-[1240px] overflow-hidden rounded-[20px] bg-background text-foreground [--font-display:var(--font-serif)] max-[600px]:rounded-[14px]">
<div className="surface-limned relative isolate flex min-h-[620px] flex-col items-center justify-start overflow-hidden p-[64px_40px_260px] text-center [--limn-color:oklch(0.78_0.12_165)] max-[600px]:min-h-[570px] max-[600px]:p-[40px_24px_200px]">
<header className="relative z-2 grid max-w-[660px] min-w-0 items-center justify-items-center gap-6">
<Eyebrow variant="mono">{COPY.eyebrow}</Eyebrow>
<h4 className="font-display text-[length:clamp(34px,4vw,54px)] leading-[1.1] font-normal tracking-[-0.035em] text-balance max-[600px]:text-[36px]">
{COPY.title}
</h4>
<div className="max-w-[480px] text-base/7 text-muted-foreground">
<p>{COPY.body}</p>
</div>
</header>
<div className="relative z-2 mt-7 flex flex-wrap items-center justify-center gap-3">
<a
href="#"
data-slot="button"
className={cn(
buttonVariants({ size: "lg" }),
"h-auto min-h-10 max-w-full py-2.5 text-center whitespace-normal"
)}
>
{COPY.cta}
</a>
</div>
<Orb
color="oklch(0.78 0.12 165)"
size={600}
grow={1.5}
className="absolute bottom-0 left-1/2 [translate:-50%_48%]"
/>
</div>
</div>
)
}
function Orb({
color = "oklch(0.75 0.12 232)",
size = 280,
grow = 1,
className,
}: {
color?: string
size?: number
grow?: number
className?: string
}) {
const { ref, width } = useWidth(Math.min(size, 240))
return (
<div
ref={ref}
aria-hidden="true"
className={cn("relative aspect-square shrink-0", className)}
style={{ width: "min(" + grow * 100 + "%, " + size + "px)" }}
>
<div className="relative size-full">
<MoonSphere size={width} moonColor={color} />
</div>
</div>
)
}
function useWidth(initial: number) {
const ref = useRef<HTMLDivElement>(null)
const [width, setWidth] = useState(initial)
useEffect(() => {
const node = ref.current
if (!node) return
const observer = new ResizeObserver(([entry]) => {
const next = Math.round(entry.contentRect.width)
if (next > 0) setWidth((current) => (current === next ? current : next))
})
observer.observe(node)
return () => observer.disconnect()
}, [])
return { ref, width }
}
import { mergeProps } from "@base-ui/react/merge-props"
import { useRender } from "@base-ui/react/use-render"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "cn"
const eyebrowVariants = cva("text-eyebrow", {
variants: {
/**
* `default` is a 14px/20px label. `icon` adds a row with a 16px icon
* and a 12px gap; put the icon first and give it `aria-hidden`.
* `mono` and `caps` are 12px/20px uppercase labels with 0.12em
* tracking, in the mono and inherited faces respectively.
*/
variant: {
default: "text-sm/5 font-medium text-eyebrow",
icon: "flex items-center gap-3 text-sm/5 font-medium [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
mono: "font-mono text-xs/5 font-medium tracking-[0.12em] uppercase",
caps: "text-xs/5 font-medium tracking-[0.12em] uppercase",
},
},
defaultVariants: { variant: "default" },
})
/**
* A short label above a heading, rendered as a `<p>` at weight 500.
* The default is 14px/20px in the kit's eyebrow color. The surrounding
* layout controls the space to the heading. Use `className` to customize
* the typography or color, and `render` to change the element.
*/
function Eyebrow({
className,
variant = "default",
render,
...props
}: useRender.ComponentProps<"p"> & VariantProps<typeof eyebrowVariants>) {
return useRender({
defaultTagName: "p",
render,
state: { slot: "eyebrow", variant },
props: mergeProps<"p">(
{ className: cn(eyebrowVariants({ variant }), className) },
props
),
})
}
export { Eyebrow, eyebrowVariants }
import { cn } from "cn"
/**
* A sphere lit only on one limb, for a moon rising over a dark ground. A
* radial gradient from the lower-left corner runs transparent out to
* `moonColor` at the upper-right edge, so the rest of the disc shows the
* ground behind it. It is decorative and hidden from assistive tech.
*/
function MoonSphere({
className,
size = 256,
moonColor = "oklch(0.65 0.12 55)",
style,
...props
}: React.ComponentProps<"div"> & {
/** Diameter in px. */
size?: number
/** The rim light's color. */
moonColor?: string
}) {
return (
<div
aria-hidden="true"
data-slot="moon-sphere"
className={cn("block rounded-full", className)}
style={{
width: size,
maxWidth: "100%",
background: `radial-gradient(circle at 0% 100%, transparent 60%, ${moonColor} 100%)`,
...style,
height: "auto",
aspectRatio: "1 / 1",
flexShrink: 0,
}}
{...props}
/>
)
}
export { MoonSphere }
pnpm dlx shadcn@latest add @01orbital/moon-sphere-jade-risenpx shadcn@latest add @01orbital/moon-sphere-jade-riseyarn dlx shadcn@latest add @01orbital/moon-sphere-jade-risebunx --bun shadcn@latest add @01orbital/moon-sphere-jade-riseTwo Scalesmoon-sphere-two-scales
Orb size comparison example: two Moon Spheres on a plum ground, a small violet one and a larger silver one, each with a short caption. Shows how a single orb component scales for icons and hero art.
"use client"
import { useEffect, useRef, useState } from "react"
import { cn } from "cn"
import { MoonSphere } from "@/components/orbs/moon-sphere"
// The copy: change text here, not in the markup.
const COPY = {
smallCaption: "Violet / small",
largeCaption: "Silver / large",
} as const
/** Two Moon Spheres on a plum ground, a small violet one and a larger silver one, each with a short caption. */
export default function MoonSphereTwoScales() {
return (
<div className="dark flex w-full justify-center">
<div className="theme-plum relative isolate w-full max-w-[606px] overflow-hidden rounded-[20px] bg-background text-foreground [--font-display:var(--font-serif)] max-[600px]:rounded-[14px]">
<div className="relative isolate flex min-h-[420px] flex-wrap items-center justify-center gap-10 overflow-hidden p-10 max-[600px]:min-h-[360px] max-[600px]:gap-7 max-[600px]:p-[28px_24px]">
<div className="grid w-[120px] max-w-full min-w-0 justify-items-center gap-6">
<Orb color="oklch(0.76 0.13 295)" size={120} />
<p className="text-xs/5 text-muted-foreground">
{COPY.smallCaption}
</p>
</div>
<div className="grid w-[260px] max-w-full min-w-0 justify-items-center gap-6">
<Orb color="oklch(0.88 0.01 250)" size={260} />
<p className="text-xs/5 text-muted-foreground">
{COPY.largeCaption}
</p>
</div>
</div>
</div>
</div>
)
}
function Orb({
color = "oklch(0.75 0.12 232)",
size = 280,
grow = 1,
className,
}: {
color?: string
size?: number
grow?: number
className?: string
}) {
const { ref, width } = useWidth(Math.min(size, 240))
return (
<div
ref={ref}
aria-hidden="true"
className={cn("relative aspect-square shrink-0", className)}
style={{ width: "min(" + grow * 100 + "%, " + size + "px)" }}
>
<div className="relative size-full">
<MoonSphere size={width} moonColor={color} />
</div>
</div>
)
}
function useWidth(initial: number) {
const ref = useRef<HTMLDivElement>(null)
const [width, setWidth] = useState(initial)
useEffect(() => {
const node = ref.current
if (!node) return
const observer = new ResizeObserver(([entry]) => {
const next = Math.round(entry.contentRect.width)
if (next > 0) setWidth((current) => (current === next ? current : next))
})
observer.observe(node)
return () => observer.disconnect()
}, [])
return { ref, width }
}
import { cn } from "cn"
/**
* A sphere lit only on one limb, for a moon rising over a dark ground. A
* radial gradient from the lower-left corner runs transparent out to
* `moonColor` at the upper-right edge, so the rest of the disc shows the
* ground behind it. It is decorative and hidden from assistive tech.
*/
function MoonSphere({
className,
size = 256,
moonColor = "oklch(0.65 0.12 55)",
style,
...props
}: React.ComponentProps<"div"> & {
/** Diameter in px. */
size?: number
/** The rim light's color. */
moonColor?: string
}) {
return (
<div
aria-hidden="true"
data-slot="moon-sphere"
className={cn("block rounded-full", className)}
style={{
width: size,
maxWidth: "100%",
background: `radial-gradient(circle at 0% 100%, transparent 60%, ${moonColor} 100%)`,
...style,
height: "auto",
aspectRatio: "1 / 1",
flexShrink: 0,
}}
{...props}
/>
)
}
export { MoonSphere }
pnpm dlx shadcn@latest add @01orbital/moon-sphere-two-scalesnpx shadcn@latest add @01orbital/moon-sphere-two-scalesyarn dlx shadcn@latest add @01orbital/moon-sphere-two-scalesbunx --bun shadcn@latest add @01orbital/moon-sphere-two-scalesLetter Cardmoon-sphere-letter-card
Newsletter signup card example: a small amber Moon Sphere in an inset frame above a short headline and a working email form. Shows the orb as card artwork for a subscribe or waitlist prompt.
The source comes with full access.
One payment of $149 opens the source right here and lets the CLI install every paid component, with lifetime updates.
pnpm dlx shadcn@latest add @01orbital/moon-sphere-letter-cardnpx shadcn@latest add @01orbital/moon-sphere-letter-cardyarn dlx shadcn@latest add @01orbital/moon-sphere-letter-cardbunx --bun shadcn@latest add @01orbital/moon-sphere-letter-cardEmpty Statemoon-sphere-empty-state
404 page empty state example with a Moon Sphere: a message and two links sit on the left while a full blue moon fills the right. Shows how the glowing orb works as artwork on a not found or error screen.
"use client"
import { useEffect, useRef, useState } from "react"
import { cn } from "cn"
import { Eyebrow } from "@/components/eyebrow/eyebrow"
import { MoonSphere } from "@/components/orbs/moon-sphere"
import { buttonVariants } from "@/components/ui/button"
// The copy: change text here, not in the markup.
const COPY = {
eyebrow: "404 / Nothing at this address",
title: "The rest is still where you left it.",
body: "This page may have moved. You can find the collection back in Browse.",
primary: "Back to Browse",
secondary: "Go home",
} as const
/** A 404 style empty state with a message and two links on the left and a full blue Moon Sphere on the right. */
export default function MoonSphereEmptyState() {
return (
<div className="dark relative isolate w-full max-w-[1240px] overflow-hidden rounded-[20px] bg-background text-foreground [--font-display:var(--font-serif)] max-[600px]:rounded-[14px]">
<div className="relative isolate grid min-h-[500px] grid-cols-[1fr_1fr] items-center gap-14 overflow-hidden p-16 max-[950px]:gap-8 max-[950px]:p-10 max-[600px]:grid-cols-1 max-[600px]:gap-7 max-[600px]:p-[32px_24px]">
<div>
<header className="relative z-2 grid max-w-[540px] min-w-0 gap-6">
<Eyebrow variant="mono">{COPY.eyebrow}</Eyebrow>
<h4 className="font-display text-[36px] leading-[1.1] font-normal tracking-[-0.035em] text-balance min-[601px]:text-[44px] min-[950px]:text-[54px]">
{COPY.title}
</h4>
<div className="max-w-[480px] text-base/7 text-muted-foreground">
<p>{COPY.body}</p>
</div>
</header>
<div className="relative z-2 mt-7 flex flex-wrap items-center gap-3">
<a
href="#"
data-slot="button"
className={cn(
buttonVariants({ size: "lg" }),
"h-auto min-h-10 max-w-full py-2.5 text-center whitespace-normal"
)}
>
{COPY.primary}
</a>
<a
href="/"
data-slot="button"
className={cn(
buttonVariants({ variant: "outline", size: "lg" }),
"h-auto min-h-10 max-w-full py-2.5 text-center whitespace-normal"
)}
>
{COPY.secondary}
</a>
</div>
</div>
<div className="relative isolate grid h-full min-h-[320px] place-items-center max-[600px]:min-h-[280px]">
<Orb size={340} />
</div>
</div>
</div>
)
}
function Orb({
color = "oklch(0.75 0.12 232)",
size = 280,
grow = 1,
className,
}: {
color?: string
size?: number
grow?: number
className?: string
}) {
const { ref, width } = useWidth(Math.min(size, 240))
return (
<div
ref={ref}
aria-hidden="true"
className={cn("relative aspect-square shrink-0", className)}
style={{ width: "min(" + grow * 100 + "%, " + size + "px)" }}
>
<div className="relative size-full">
<MoonSphere size={width} moonColor={color} />
</div>
</div>
)
}
function useWidth(initial: number) {
const ref = useRef<HTMLDivElement>(null)
const [width, setWidth] = useState(initial)
useEffect(() => {
const node = ref.current
if (!node) return
const observer = new ResizeObserver(([entry]) => {
const next = Math.round(entry.contentRect.width)
if (next > 0) setWidth((current) => (current === next ? current : next))
})
observer.observe(node)
return () => observer.disconnect()
}, [])
return { ref, width }
}
import { mergeProps } from "@base-ui/react/merge-props"
import { useRender } from "@base-ui/react/use-render"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "cn"
const eyebrowVariants = cva("text-eyebrow", {
variants: {
/**
* `default` is a 14px/20px label. `icon` adds a row with a 16px icon
* and a 12px gap; put the icon first and give it `aria-hidden`.
* `mono` and `caps` are 12px/20px uppercase labels with 0.12em
* tracking, in the mono and inherited faces respectively.
*/
variant: {
default: "text-sm/5 font-medium text-eyebrow",
icon: "flex items-center gap-3 text-sm/5 font-medium [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
mono: "font-mono text-xs/5 font-medium tracking-[0.12em] uppercase",
caps: "text-xs/5 font-medium tracking-[0.12em] uppercase",
},
},
defaultVariants: { variant: "default" },
})
/**
* A short label above a heading, rendered as a `<p>` at weight 500.
* The default is 14px/20px in the kit's eyebrow color. The surrounding
* layout controls the space to the heading. Use `className` to customize
* the typography or color, and `render` to change the element.
*/
function Eyebrow({
className,
variant = "default",
render,
...props
}: useRender.ComponentProps<"p"> & VariantProps<typeof eyebrowVariants>) {
return useRender({
defaultTagName: "p",
render,
state: { slot: "eyebrow", variant },
props: mergeProps<"p">(
{ className: cn(eyebrowVariants({ variant }), className) },
props
),
})
}
export { Eyebrow, eyebrowVariants }
import { cn } from "cn"
/**
* A sphere lit only on one limb, for a moon rising over a dark ground. A
* radial gradient from the lower-left corner runs transparent out to
* `moonColor` at the upper-right edge, so the rest of the disc shows the
* ground behind it. It is decorative and hidden from assistive tech.
*/
function MoonSphere({
className,
size = 256,
moonColor = "oklch(0.65 0.12 55)",
style,
...props
}: React.ComponentProps<"div"> & {
/** Diameter in px. */
size?: number
/** The rim light's color. */
moonColor?: string
}) {
return (
<div
aria-hidden="true"
data-slot="moon-sphere"
className={cn("block rounded-full", className)}
style={{
width: size,
maxWidth: "100%",
background: `radial-gradient(circle at 0% 100%, transparent 60%, ${moonColor} 100%)`,
...style,
height: "auto",
aspectRatio: "1 / 1",
flexShrink: 0,
}}
{...props}
/>
)
}
export { MoonSphere }
pnpm dlx shadcn@latest add @01orbital/moon-sphere-empty-statenpx shadcn@latest add @01orbital/moon-sphere-empty-stateyarn dlx shadcn@latest add @01orbital/moon-sphere-empty-statebunx --bun shadcn@latest add @01orbital/moon-sphere-empty-stateRim Palettesmoon-sphere-rim-palettes
Interactive Moon Sphere example: a blue moon with six buttons that switch its rim color and a status line naming the current choice. A pattern for letting users pick an orb color or theme.
"use client"
import { useEffect, useRef, useState } from "react"
import { cn } from "cn"
import { MoonSphere } from "@/components/orbs/moon-sphere"
import {
SegmentedControl,
SegmentedControlItem,
} from "@/components/toggle/segmented-control"
// The copy: change text here, not in the markup.
const COPY = {
groupLabel: "Moon palette",
selected: "rim selected.",
} as const
const MOON_COLORS = {
blue: "oklch(0.75 0.12 232)",
amber: "oklch(0.77 0.14 65)",
silver: "oklch(0.88 0.01 250)",
rose: "oklch(0.78 0.13 350)",
jade: "oklch(0.78 0.12 165)",
violet: "oklch(0.76 0.13 295)",
}
/** A blue Moon Sphere with six buttons that switch its rim color, and a status line naming the current choice. */
export default function MoonSphereRimPalettes() {
return (
<div className="dark relative isolate w-full max-w-[606px] overflow-hidden rounded-[20px] bg-background text-foreground [--font-display:var(--font-serif)] max-[600px]:rounded-[14px]">
<div className="relative isolate min-h-[400px] overflow-hidden p-10 max-[600px]:min-h-[360px] max-[600px]:p-[28px_24px]">
<MoonPalette />
</div>
</div>
)
}
function Orb({
color = "oklch(0.75 0.12 232)",
size = 280,
grow = 1,
className,
}: {
color?: string
size?: number
grow?: number
className?: string
}) {
const { ref, width } = useWidth(Math.min(size, 240))
return (
<div
ref={ref}
aria-hidden="true"
className={cn("relative aspect-square shrink-0", className)}
style={{ width: "min(" + grow * 100 + "%, " + size + "px)" }}
>
<div className="relative size-full">
<MoonSphere size={width} moonColor={color} />
</div>
</div>
)
}
function useWidth(initial: number) {
const ref = useRef<HTMLDivElement>(null)
const [width, setWidth] = useState(initial)
useEffect(() => {
const node = ref.current
if (!node) return
const observer = new ResizeObserver(([entry]) => {
const next = Math.round(entry.contentRect.width)
if (next > 0) setWidth((current) => (current === next ? current : next))
})
observer.observe(node)
return () => observer.disconnect()
}, [])
return { ref, width }
}
function MoonPalette() {
const [color, setColor] = useState<keyof typeof MOON_COLORS>("blue")
return (
<>
<div className="relative grid h-[330px] w-full place-items-center max-[600px]:h-[280px]">
<Orb color={MOON_COLORS[color]} size={300} />
</div>
<SegmentedControl
aria-label={COPY.groupLabel}
value={[color]}
onValueChange={(next) => {
if (next[0] !== undefined) setColor(next[0] as typeof color)
}}
className="relative z-2 mx-auto mt-6 flex w-fit max-w-full flex-wrap justify-center rounded-3xl"
>
{(Object.keys(MOON_COLORS) as (keyof typeof MOON_COLORS)[]).map(
(name) => (
<SegmentedControlItem key={name} value={name}>
{name}
</SegmentedControlItem>
)
)}
</SegmentedControl>
<p
className="relative z-2 mt-3.5 text-center text-xs/5 text-muted-foreground"
role="status"
>
{color + " " + COPY.selected}
</p>
</>
)
}
import { cn } from "cn"
/**
* A sphere lit only on one limb, for a moon rising over a dark ground. A
* radial gradient from the lower-left corner runs transparent out to
* `moonColor` at the upper-right edge, so the rest of the disc shows the
* ground behind it. It is decorative and hidden from assistive tech.
*/
function MoonSphere({
className,
size = 256,
moonColor = "oklch(0.65 0.12 55)",
style,
...props
}: React.ComponentProps<"div"> & {
/** Diameter in px. */
size?: number
/** The rim light's color. */
moonColor?: string
}) {
return (
<div
aria-hidden="true"
data-slot="moon-sphere"
className={cn("block rounded-full", className)}
style={{
width: size,
maxWidth: "100%",
background: `radial-gradient(circle at 0% 100%, transparent 60%, ${moonColor} 100%)`,
...style,
height: "auto",
aspectRatio: "1 / 1",
flexShrink: 0,
}}
{...props}
/>
)
}
export { MoonSphere }
"use client"
import { createContext, useContext, useId, useMemo, useState } from "react"
import { Toggle as TogglePrimitive } from "@base-ui/react/toggle"
import { ToggleGroup as ToggleGroupPrimitive } from "@base-ui/react/toggle-group"
import { cn } from "cn"
import { LayoutGroup, motion, useReducedMotion } from "motion/react"
// value/onValueChange/defaultValue take arrays, per Base UI ToggleGroup.
// className is a string here, not Base UI's state callback: the styling is
// the kit's, and state comes through data-pressed and data-disabled.
type Styled<P> = Omit<P, "className"> & {
/**
* Extra classes, as a string only: Base UI's function form is not
* accepted. On `SegmentedControl` they land on the track, and on
* `SegmentedControlItem` on the toggle button.
*/
className?: string
}
// The group keeps the pressed values so each item knows whether it holds the
// thumb; a controlled value wins over the inner state.
const PressedContext = createContext<{
pressed: Set<string>
group: string
multiple: boolean
}>({ pressed: new Set(), group: "", multiple: false })
/**
* A row of toggle buttons on a rounded track. The pressed one sits on a
* raised thumb that slides over from the last one pressed. Put
* `SegmentedControlItem` parts inside.
*
* It is Base UI's `ToggleGroup`, so `value`, `defaultValue` and
* `onValueChange` use arrays of item values. Without `multiple`, one item is
* always on: pressing the active item again does nothing, and
* `onValueChange` is not called with an empty array. With `multiple`, every
* item can be turned off. It is horizontal only, and `className` takes a
* string.
*/
function SegmentedControl({
className,
value,
defaultValue,
onValueChange,
multiple = false,
...props
}: Styled<Omit<ToggleGroupPrimitive.Props, "orientation">>) {
const group = useId()
const [inner, setInner] = useState<string[]>(
(defaultValue as string[] | undefined) ?? []
)
const current = (value as string[] | undefined) ?? inner
const key = current.join("\u0000")
const context = useMemo(
() => ({
pressed: new Set(key ? key.split("\u0000") : []),
group,
multiple,
}),
[key, group, multiple]
)
return (
<PressedContext.Provider value={context}>
<LayoutGroup id={group}>
<ToggleGroupPrimitive
data-slot="segmented-control"
value={current}
multiple={multiple}
onValueChange={(next, event) => {
// One stays on: a press on the active item is ignored.
if (!multiple && next.length === 0) {
event.cancel()
return
}
// The consumer goes first: event.cancel() keeps the old value.
onValueChange?.(next, event)
if (!event.isCanceled) setInner(next as string[])
}}
className={cn(
// The track: a muted well; in dark a faint lit rim on its top edge.
"inline-flex items-center gap-1 rounded-full bg-muted p-1 ring-1 ring-border",
"dark:bg-foreground/6 dark:shadow-[inset_0_1px_0_rgba(255,255,255,0.05)] dark:ring-foreground/10",
className
)}
{...props}
/>
</LayoutGroup>
</PressedContext.Provider>
)
}
/**
* One option in a `SegmentedControl`, built on Base UI's `Toggle`. Give it a
* string `value`. It is square for one character or an icon and widens to
* fit a word.
*
* The pressed item sits on the thumb, a card-colored pill with a soft shadow
* (a light wash in dark mode) that glides over from the last item pressed;
* reduced motion moves it at once. The other items stay muted and come up
* to full ink on hover. When the control has `multiple`, each pressed item
* gets its own thumb, without the glide.
*/
function SegmentedControlItem({
className,
children,
value,
...props
}: Styled<TogglePrimitive.Props>) {
const { pressed, multiple } = useContext(PressedContext)
const reduce = useReducedMotion()
const on = typeof value === "string" && pressed.has(value)
return (
<TogglePrimitive
data-slot="segmented-control-item"
value={value}
className={cn(
"relative isolate flex h-8 min-w-8 items-center justify-center rounded-full px-2.5 text-sm font-medium text-muted-foreground tabular-nums",
"transition-colors duration-150 ease-out motion-reduce:transition-none",
"hover:text-foreground",
"focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-none",
"data-disabled:pointer-events-none data-disabled:opacity-50",
"data-pressed:text-foreground",
className
)}
{...props}
>
{/* The thumb: one shared element per group, so it glides to whichever
item is pressed instead of popping. With several pressed at once
each keeps its own, still. */}
{on && (
<motion.span
aria-hidden="true"
layoutId={multiple ? undefined : "thumb"}
transition={
reduce
? { duration: 0 }
: { type: "spring", stiffness: 520, damping: 42, mass: 0.8 }
}
className="absolute inset-0 -z-10 rounded-full bg-card shadow-xs dark:bg-foreground/15"
/>
)}
{children}
</TogglePrimitive>
)
}
export { SegmentedControl, SegmentedControlItem }
pnpm dlx shadcn@latest add @01orbital/moon-sphere-rim-palettesnpx shadcn@latest add @01orbital/moon-sphere-rim-palettesyarn dlx shadcn@latest add @01orbital/moon-sphere-rim-palettesbunx --bun shadcn@latest add @01orbital/moon-sphere-rim-palettesHue Slidermoon-sphere-hue-slider
Interactive Moon Sphere example on midnight blue with a range slider that sweeps the rim color through the full hue circle. Shows how one color value recolors the glowing orb live.
"use client"
import { useEffect, useId, useRef, useState } from "react"
import { cn } from "cn"
import { MoonSphere } from "@/components/orbs/moon-sphere"
import { Label } from "@/components/ui/label"
import { Slider } from "@/components/ui/slider"
// The copy: change text here, not in the markup.
const COPY = {
label: "Rim light hue",
} as const
/** A Moon Sphere on midnight blue with a range slider that moves its rim color through the full hue circle. */
export default function MoonSphereHueSlider() {
return (
<div className="dark flex w-full justify-center">
<div className="theme-blue relative isolate w-full max-w-[606px] overflow-hidden rounded-[20px] bg-background text-foreground [--font-display:var(--font-serif)] max-[600px]:rounded-[14px]">
<div className="relative isolate min-h-[400px] overflow-hidden p-10 max-[600px]:min-h-[360px] max-[600px]:p-[28px_24px]">
<HueControl />
</div>
</div>
</div>
)
}
function Orb({
color = "oklch(0.75 0.12 232)",
size = 280,
grow = 1,
className,
}: {
color?: string
size?: number
grow?: number
className?: string
}) {
const { ref, width } = useWidth(Math.min(size, 240))
return (
<div
ref={ref}
aria-hidden="true"
className={cn("relative aspect-square shrink-0", className)}
style={{ width: "min(" + grow * 100 + "%, " + size + "px)" }}
>
<div className="relative size-full">
<MoonSphere size={width} moonColor={color} />
</div>
</div>
)
}
function useWidth(initial: number) {
const ref = useRef<HTMLDivElement>(null)
const [width, setWidth] = useState(initial)
useEffect(() => {
const node = ref.current
if (!node) return
const observer = new ResizeObserver(([entry]) => {
const next = Math.round(entry.contentRect.width)
if (next > 0) setWidth((current) => (current === next ? current : next))
})
observer.observe(node)
return () => observer.disconnect()
}, [])
return { ref, width }
}
function HueControl() {
const id = useId()
const [hue, setHue] = useState(232)
const color = "oklch(0.79 0.13 " + hue + ")"
return (
<>
<div className="relative grid h-[330px] w-full place-items-center max-[600px]:h-[280px]">
<Orb color={color} size={300} />
</div>
<Label
id={id}
className="relative z-2 mx-auto mt-6 mb-3.5 flex w-full max-w-[360px] items-center justify-between gap-5 text-[12px]"
>
{COPY.label}
<span>{hue + "°"}</span>
</Label>
<Slider
aria-labelledby={id}
min={0}
max={360}
value={[hue]}
onValueChange={(next) => setHue(Array.isArray(next) ? next[0] : next)}
className="relative z-2 mx-auto block w-full max-w-[360px]"
/>
</>
)
}
import { cn } from "cn"
/**
* A sphere lit only on one limb, for a moon rising over a dark ground. A
* radial gradient from the lower-left corner runs transparent out to
* `moonColor` at the upper-right edge, so the rest of the disc shows the
* ground behind it. It is decorative and hidden from assistive tech.
*/
function MoonSphere({
className,
size = 256,
moonColor = "oklch(0.65 0.12 55)",
style,
...props
}: React.ComponentProps<"div"> & {
/** Diameter in px. */
size?: number
/** The rim light's color. */
moonColor?: string
}) {
return (
<div
aria-hidden="true"
data-slot="moon-sphere"
className={cn("block rounded-full", className)}
style={{
width: size,
maxWidth: "100%",
background: `radial-gradient(circle at 0% 100%, transparent 60%, ${moonColor} 100%)`,
...style,
height: "auto",
aspectRatio: "1 / 1",
flexShrink: 0,
}}
{...props}
/>
)
}
export { MoonSphere }
pnpm dlx shadcn@latest add @01orbital/moon-sphere-hue-slidernpx shadcn@latest add @01orbital/moon-sphere-hue-slideryarn dlx shadcn@latest add @01orbital/moon-sphere-hue-sliderbunx --bun shadcn@latest add @01orbital/moon-sphere-hue-sliderAPI reference
A sphere lit only on one limb, for a moon rising over a dark ground. A radial gradient from the lower-left corner runs transparent out to moonColor at the upper-right edge, so the rest of the disc shows the ground behind it. It is decorative and hidden from assistive tech.
Prop
Type
It also accepts the HTML attributes of the element it renders.
Dependencies
npm: cn. The CLI installs it for you.
Used in blocks
3 blocks are built with Moon Sphere:
Last updated on