1 Run the shadcn CLI
npx shadcn@latest add https://toggles.dev/r/eclipse 2 Import and use
import { Eclipse } from "@/components/ui/eclipse";
export default function App() {
return <Eclipse />;
} 1 Install the package
▾
npm install @theme-toggles/react pnpm add @theme-toggles/react yarn add @theme-toggles/react bun add @theme-toggles/react 2 Import and use
import { Eclipse } from "@theme-toggles/react";
import "@theme-toggles/react/styles/eclipse.css";
export default function App() {
return <Eclipse />;
} 1 Copy the component
import { type ButtonHTMLAttributes, type CSSProperties, useId } from "react";
export interface EclipseProps extends Omit<
ButtonHTMLAttributes<HTMLButtonElement>,
"children"
> {
duration?: number;
[key: `data-${string}`]: string | number | boolean | null | undefined;
}
export function Eclipse({
duration = 500,
className,
type = "button",
title = "Toggle theme",
"aria-label": ariaLabel = "Toggle theme",
...props
}: EclipseProps) {
const toggleId = useId();
const clipMainId = `toggles.dev-eclipse-main-${toggleId}`;
return (
<button
type={type}
title={title}
aria-label={ariaLabel}
className={className}
{...props}
>
<svg
width="1em"
height="1em"
viewBox="0 0 32 32"
aria-hidden="true"
fill={"currentColor"}
style={
{ "--toggles-eclipse--duration": `${duration}ms` } as CSSProperties
}
>
<defs>
<clipPath id={clipMainId}>
<path
d={"M0 0h64v32h-64zm38 16a1 1 0 0020 0 1 1 0 00-20 0"}
className="origin-center transition-[d,translate] [transition-duration:var(--toggles-eclipse--duration)] [transition-timing-function:cubic-bezier(0,0,0.05,1.15)] [transition-delay:0s] dark:[d:path('M-16_-16h64v64h-64zm22_32a1_1_0_0020_0_1_1_0_00-20_0')] dark:not-supports-[d:path('M0_0')]:-translate-x-[32px] dark:[transition-duration:calc(var(--toggles-eclipse--duration)_*_0.8)] dark:[transition-delay:calc(var(--toggles-eclipse--duration)_*_0.2)]"
/>
</clipPath>
</defs>
<g clipPath={`url(#${clipMainId})`}>
<circle
cx={16}
cy={16}
r={16}
className="[transform-origin:center] [transition-property:transform] [transition-duration:var(--toggles-eclipse--duration)] [transition-timing-function:cubic-bezier(0,0,0.05,1.15)]"
/>
</g>
</svg>
</button>
);
} 1 Install the package
▾
npm install @theme-toggles/svelte pnpm add @theme-toggles/svelte yarn add @theme-toggles/svelte bun add @theme-toggles/svelte 2 Import and use
<script>
import { Eclipse } from "@theme-toggles/svelte";
import "@theme-toggles/svelte/styles/eclipse.css";
</script>
<Eclipse /> 1 Copy the component
<script context="module" lang="ts">
let nextId = 0;
</script>
<script lang="ts">
import type { HTMLButtonAttributes } from "svelte/elements";
interface $$Props extends Omit<HTMLButtonAttributes, "children"> {
duration?: number;
ariaLabel?: string;
class?: string;
}
export let duration = 500;
export let type: HTMLButtonAttributes["type"] = "button";
export let title = "Toggle theme";
export let ariaLabel = "Toggle theme";
let className = "";
export { className as class };
const toggleId = `eclipse-${++nextId}`;
const clipMainId = `toggles.dev-eclipse-main-${toggleId}`;
</script>
<button
{type}
{title}
aria-label={ariaLabel}
class={className}
on:click
{...$$restProps}
>
<svg
width="1em"
height="1em"
viewBox="0 0 32 32"
aria-hidden="true"
fill={"currentColor"}
style={`--toggles-eclipse--duration: ${duration}ms`}
>
<defs>
<clipPath id={clipMainId}>
<path
d={"M0 0h64v32h-64zm38 16a1 1 0 0020 0 1 1 0 00-20 0"}
class={"origin-center transition-[d,translate] [transition-duration:var(--toggles-eclipse--duration)] [transition-timing-function:cubic-bezier(0,0,0.05,1.15)] [transition-delay:0s] dark:[d:path('M-16_-16h64v64h-64zm22_32a1_1_0_0020_0_1_1_0_00-20_0')] dark:not-supports-[d:path('M0_0')]:-translate-x-[32px] dark:[transition-duration:calc(var(--toggles-eclipse--duration)_*_0.8)] dark:[transition-delay:calc(var(--toggles-eclipse--duration)_*_0.2)]"}
/>
</clipPath>
</defs>
<g clip-path={`url(#${clipMainId})`}>
<circle
cx={16}
cy={16}
r={16}
class={"[transform-origin:center] [transition-property:transform] [transition-duration:var(--toggles-eclipse--duration)] [transition-timing-function:cubic-bezier(0,0,0.05,1.15)]"}
/>
</g>
</svg>
</button> 1 Install the package
▾
npm install @theme-toggles/vue pnpm add @theme-toggles/vue yarn add @theme-toggles/vue bun add @theme-toggles/vue 2 Import and use
<script setup lang="ts">
import { Eclipse } from "@theme-toggles/vue";
import "@theme-toggles/vue/styles/eclipse.css";
</script>
<template>
<Eclipse />
</template> 1 Copy the component
<script lang="ts">
let nextId = 0;
</script>
<script setup lang="ts">
import { useAttrs } from "vue";
interface Props {
duration?: number;
type?: "button" | "submit" | "reset";
title?: string;
ariaLabel?: string;
}
const props = withDefaults(defineProps<Props>(), {
duration: 500,
type: "button",
title: "Toggle theme",
ariaLabel: "Toggle theme",
});
const attrs = useAttrs();
const toggleId = `eclipse-${++nextId}`;
const clipMainId = `toggles.dev-eclipse-main-${toggleId}`;
</script>
<template>
<button
v-bind="attrs"
:type="props.type"
:title="props.title"
:aria-label="props.ariaLabel"
>
<svg
width="1em"
height="1em"
viewBox="0 0 32 32"
aria-hidden="true"
:fill="'currentColor'"
:style="{ '--toggles-eclipse--duration': `${props.duration}ms` }"
>
<defs>
<clipPath :id="clipMainId">
<path
:d="'M0 0h64v32h-64zm38 16a1 1 0 0020 0 1 1 0 00-20 0'"
:class="'origin-center transition-[d,translate] [transition-duration:var(--toggles-eclipse--duration)] [transition-timing-function:cubic-bezier(0,0,0.05,1.15)] [transition-delay:0s] dark:[d:path(\'M-16_-16h64v64h-64zm22_32a1_1_0_0020_0_1_1_0_00-20_0\')] dark:not-supports-[d:path(\'M0_0\')]:-translate-x-[32px] dark:[transition-duration:calc(var(--toggles-eclipse--duration)_*_0.8)] dark:[transition-delay:calc(var(--toggles-eclipse--duration)_*_0.2)]'"
/>
</clipPath>
</defs>
<g :clip-path="`url(#${clipMainId})`">
<circle
:cx="16"
:cy="16"
:r="16"
:class="'[transform-origin:center] [transition-property:transform] [transition-duration:var(--toggles-eclipse--duration)] [transition-timing-function:cubic-bezier(0,0,0.05,1.15)]'"
/>
</g>
</svg>
</button>
</template>