Button

A highly customizable button component with built-in state management for loading, success, and error feedback.

This component requires the FyskProvider. See Quick Start →

Preview

Button
TypeScript

With Text

With Icon

Installation

bash
bash
1
npx shadcn@latest add https://fysk.dev/r/button.json

Usage

tsx
tsx
1
import { Button } from "@/components/ui"
2
3
<Button variant="default">Click Me</Button>

Examples

Variants

Buttons come in several visual variants to establish hierarchy and context.

Component
TypeScript

Size

Adjust the button size to fit different contexts.

Component
TypeScript

For Icons

For Text

Action States

Built-in handling for loading, success, and error states.

Component
TypeScript

Icons

Add icons at the start or end of the button label.

Component
TypeScript

As Child

Compose with other components using the asChild prop.

Component
TypeScript

Features

  • Variants: Different styles to suit various contexts.

  • Size: Adjust the button size to fit different contexts.

  • State Management: Integrated `loading`, `success`, and `error` states with customizable text and icons.

  • Hierarchical Icons: Automatically resolves icons from the global `FyskProvider` context if not provided locally.

  • Composition: Supports the `asChild` pattern for seamless integration with framework routers (like Next.js Link).

  • Auto State Variant: Automatically switches the button variant based on the state (e.g., to `success-outline` when successful).

Props

PropTypeDefaultDescription
variant"default" | "secondary" | "destructive" | "success" | "warning" | "info" | "outline" | "ghost" | "link" | "glass" | "success-outline" | "warning-outline" | "info-outline" | "destructive-outline""default"The visual style of the button.
size"default" | "xs" | "sm" | "md" | "lg" | "xl" | "icon" | "icon-xs" | "icon-sm" | "icon-lg""default"The size of the button.
state"idle" | "loading" | "success" | "error""idle"The current interaction state of the button.
autoStateVariantbooleanfalseIf true, automatically switches variants based on the current state.
asChildbooleanfalseIf true, the button will render as its child element.
loadingTextstring-Text to display during the loading state.
successTextstring-Text to display during the success state.
errorTextstring-Text to display during the error state.
iconReact.ReactNode-Icon to display in the idle state.
iconLoadingReact.ReactNode-Custom icon for the loading state.
iconSuccessReact.ReactNode-Custom icon for the success state.
iconErrorReact.ReactNode-Custom icon for the error state.
iconPosition"start" | "end""start"Position of the icon relative to the text.

Built with 💖 | Created by Yashraj