Skip to main content

Button

The Button component provides a flexible and accessible way to create styled buttons with support for variants, sizes, icons, full-width layout, and custom colors. Built using Tailwind CSS and designed to be reused across your UI.

📦 Import

import { Button } from "@sahilphondekar/react-component-library";

🧱 Props

NameTypeDefaultDescription
variant"primary" | "secondary" | "transparent" | "danger" | string"primary"Button style variant
size"small" | "medium" | "large""medium"Size of the button
iconstring (for SVG icon name) | elementType (React component)Optional icon (before label/children)
labelstringOptional label text (alternative to children)
classNamestring""Additional class names
disabledboolfalseDisables the button
fullWidthboolfalseMakes button span full width of its container
customColorsobject { base, hover, focus, active }Custom Tailwind classes to override default variant styles
childrennodeButton content (text or JSX)
onClickfunctionClick event handler

🎨 Variants

VariantDescription
primarySolid blue button with white text
secondaryLight gray button with dark text
transparentTransparent with blue border and text
dangerRed button for destructive actions

📏 Sizes

SizePaddingFont SizeIcon Size
smallpy-1.5 px-3text-sm16px
mediumpy-2.5 px-5text-base20px
largepy-3 px-6text-lg24px

🚀 Examples

Basic Usage

<Button onClick={() => alert("Clicked!")}>Click Me</Button>

With Icon and Label

<Button icon="check" label="Confirm" variant="primary" />

Custom Color Variant

<Button
customColors={{
base: "bg-green-600 text-white",
hover: "hover:bg-green-700",
focus: "focus:ring-green-500",
active: "active:bg-green-800",
}}
>
Success
</Button>

Full Width Button

<Button fullWidth>Submit</Button>

💡 Best Practices

  • Use semantic actions and clear labeling for accessibility.
  • Avoid placing too much content inside a button.
  • Use icon along with a label or children for clear visual indicators.