Download Trigger
A shadcn-style download trigger utility built with Ark UI primitives.
import { DownloadIcon } from "lucide-react";
import { DownloadTrigger } from "@/components/ui/download-trigger";
const payload = JSON.stringify(
{
generatedAt: "2026-04-16T12:00:00.000Z",
kind: "ark-cn-demo",
utilities: ["download-trigger", "locale", "presence"],
},
null,
2,
);
const DownloadTriggerDemo = () => (
<DownloadTrigger
data={() => new Blob([payload], { type: "application/json" })}
fileName="ark-cn-demo.json"
mimeType="application/json"
variant="outline"
>
<DownloadIcon className="size-4" />
Download JSON
</DownloadTrigger>
);
export default DownloadTriggerDemo;
Installation
npx shadcn@latest add @ark-cn/download-triggerInstall the dependency required by this utility:
npm install @ark-ui/react class-variance-authorityCopy the utility source into your app:
TSXcomponents/ui/download-trigger.tsx
"use client";
import {
DownloadTrigger as DownloadTriggerPrimitive,
type DownloadTriggerProps as DownloadTriggerPrimitiveProps,
} from "@ark-ui/react/download-trigger";
import type { VariantProps } from "class-variance-authority";
import { buttonVariants } from "@/components/ui/button";
import { cn } from "@/lib/utils";
export type DownloadTriggerProps = DownloadTriggerPrimitiveProps & {
size?: VariantProps<typeof buttonVariants>["size"];
variant?: VariantProps<typeof buttonVariants>["variant"];
};
export const DownloadTrigger = ({
className,
size = "default",
variant = "default",
...props
}: DownloadTriggerProps) => (
<DownloadTriggerPrimitive
className={cn(buttonVariants({ variant, size, className }))}
data-slot="download-trigger"
{...props}
/>
);
Copy the shared button source if you want the default ark-cn trigger styling:
TSXcomponents/ui/button.tsx
"use client";
import { ark } from "@ark-ui/react/factory";
import { cva, type VariantProps } from "class-variance-authority";
import type { ComponentProps } from "react";
import { Spinner } from "@/components/ui/spinner";
import { cn } from "@/lib/utils";
const buttonVariants = cva(
"relative inline-flex shrink-0 cursor-pointer items-center justify-center gap-2 whitespace-nowrap rounded-lg border font-medium text-base outline-none transition-shadow before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-lg)-1px)] pointer-coarse:after:absolute pointer-coarse:after:size-full pointer-coarse:after:min-h-11 pointer-coarse:after:min-w-11 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background data-invalid:border-destructive/36 data-invalid:focus-visible:border-destructive/64 data-invalid:focus-visible:ring-destructive/20 dark:data-invalid:border-destructive/50 dark:data-invalid:focus-visible:ring-destructive/40 disabled:pointer-events-none disabled:opacity-64 data-loading:select-none data-loading:text-transparent sm:text-sm [&_svg:not([class*='opacity-'])]:opacity-80 [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:-mx-0.5 [&_svg]:shrink-0",
{
defaultVariants: {
size: "default",
variant: "default",
},
variants: {
size: {
default: "h-9 px-[calc(--spacing(3)-1px)] sm:h-8",
icon: "size-9 sm:size-8",
"icon-lg": "size-10 sm:size-9",
"icon-sm": "size-8 sm:size-7",
"icon-xl":
"size-11 sm:size-10 [&_svg:not([class*='size-'])]:size-5 sm:[&_svg:not([class*='size-'])]:size-4.5",
"icon-xs":
"size-7 rounded-md before:rounded-[calc(var(--radius-md)-1px)] sm:size-6 not-in-data-[slot=input-group]:[&_svg:not([class*='size-'])]:size-4 sm:not-in-data-[slot=input-group]:[&_svg:not([class*='size-'])]:size-3.5",
lg: "h-10 px-[calc(--spacing(3.5)-1px)] sm:h-9",
sm: "h-8 gap-1.5 px-[calc(--spacing(2.5)-1px)] sm:h-7",
xl: "h-11 px-[calc(--spacing(4)-1px)] text-lg sm:h-10 sm:text-base [&_svg:not([class*='size-'])]:size-5 sm:[&_svg:not([class*='size-'])]:size-4.5",
xs: "h-7 gap-1 rounded-md px-[calc(--spacing(2)-1px)] text-sm before:rounded-[calc(var(--radius-md)-1px)] sm:h-6 sm:text-xs [&_svg:not([class*='size-'])]:size-4 sm:[&_svg:not([class*='size-'])]:size-3.5",
},
variant: {
default:
"not-disabled:inset-shadow-[0_1px_--theme(--color-white/16%)] border-primary bg-primary text-primary-foreground shadow-primary/24 shadow-xs hover:bg-primary/90 data-pressed:bg-primary/90 *:data-[slot=button-loading-indicator]:text-primary-foreground [:active,[data-pressed]]:inset-shadow-[0_1px_--theme(--color-black/8%)] [:disabled,:active,[data-pressed]]:shadow-none",
destructive:
"not-disabled:inset-shadow-[0_1px_--theme(--color-white/16%)] border-destructive bg-destructive text-white shadow-destructive/24 shadow-xs hover:bg-destructive/90 data-pressed:bg-destructive/90 *:data-[slot=button-loading-indicator]:text-white [:active,[data-pressed]]:inset-shadow-[0_1px_--theme(--color-black/8%)] [:disabled,:active,[data-pressed]]:shadow-none",
"destructive-outline":
"border-input bg-popover not-dark:bg-clip-padding text-destructive-foreground shadow-xs/5 not-disabled:not-active:not-data-pressed:before:shadow-[0_1px_--theme(--color-black/4%)] hover:border-destructive/32 hover:bg-destructive/4 data-pressed:border-destructive/32 data-pressed:bg-destructive/4 *:data-[slot=button-loading-indicator]:text-foreground dark:bg-input/32 dark:not-disabled:before:shadow-[0_-1px_--theme(--color-white/2%)] dark:not-disabled:not-active:not-data-pressed:before:shadow-[0_-1px_--theme(--color-white/6%)] [:disabled,:active,[data-pressed]]:shadow-none",
ghost:
"border-transparent text-foreground hover:bg-accent data-pressed:bg-accent *:data-[slot=button-loading-indicator]:text-foreground",
link: "border-transparent text-foreground underline-offset-4 hover:underline data-pressed:underline *:data-[slot=button-loading-indicator]:text-foreground",
outline:
"border-input bg-popover not-dark:bg-clip-padding text-foreground shadow-xs/5 not-disabled:not-active:not-data-pressed:before:shadow-[0_1px_--theme(--color-black/4%)] hover:bg-accent/50 data-pressed:bg-accent/50 *:data-[slot=button-loading-indicator]:text-foreground dark:bg-input/32 dark:data-pressed:bg-input/64 dark:hover:bg-input/64 dark:not-disabled:before:shadow-[0_-1px_--theme(--color-white/2%)] dark:not-disabled:not-active:not-data-pressed:before:shadow-[0_-1px_--theme(--color-white/6%)] [:disabled,:active,[data-pressed]]:shadow-none",
secondary:
"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/90 data-pressed:bg-secondary/90 *:data-[slot=button-loading-indicator]:text-secondary-foreground [:active,[data-pressed]]:bg-secondary/80",
},
},
},
);
interface ButtonProps extends ComponentProps<typeof ark.button> {
variant?: VariantProps<typeof buttonVariants>["variant"];
size?: VariantProps<typeof buttonVariants>["size"];
loading?: boolean;
}
const Button = ({
className,
variant = "default",
size = "default",
children,
loading = false,
...props
}: ButtonProps) => {
return (
<ark.button
data-slot="button"
className={cn(buttonVariants({ variant, size, className }))}
aria-disabled={loading || undefined}
data-loading={loading ? "" : undefined}
{...props}
>
{children}
{loading && (
<Spinner
className="pointer-events-none absolute"
data-slot="button-loading-indicator"
/>
)}
</ark.button>
);
};
export { Button, buttonVariants };
Usage
import { DownloadTrigger } from "@/components/ui/download-trigger"Examples
Default
import { DownloadIcon } from "lucide-react";
import { DownloadTrigger } from "@/components/ui/download-trigger";
const payload = JSON.stringify(
{
generatedAt: "2026-04-16T12:00:00.000Z",
kind: "ark-cn-demo",
utilities: ["download-trigger", "locale", "presence"],
},
null,
2,
);
const DownloadTriggerDemo = () => (
<DownloadTrigger
data={() => new Blob([payload], { type: "application/json" })}
fileName="ark-cn-demo.json"
mimeType="application/json"
variant="outline"
>
<DownloadIcon className="size-4" />
Download JSON
</DownloadTrigger>
);
export default DownloadTriggerDemo;
API reference
This utility mirrors Ark UI's DownloadTrigger and adds ark-cn-only variant and size props for button styling.
See the ARK UI documentation for the full API.