Overview
The Button component is a highly customizable, accessible button element that supports multiple visual variants, sizes, and states. It’s built with TypeScript and forwards refs for advanced use cases. Source:src/shared/ui/button/Button.tsx
Basic Usage
Props
The Button component extends all standard HTML button attributes and includes these additional props:The visual style variant of the button.Options:
"primary" | "secondary" | "danger" | "outline"primary: Main call-to-action buttonssecondary: Secondary actionsdanger: Destructive actions (e.g., delete)outline: Outlined style for subtle actions
Controls the size of the button.Options:
"sm" | "md" | "lg"sm: Small buttons for compact spacesmd: Default medium sizelg: Large buttons for prominent actions
When
true, the button stretches to fill its container’s full width.Useful for mobile layouts and full-width CTAs.Disables the button, preventing user interaction and applying disabled styling.
Additional CSS class names to apply to the button for custom styling.
The content to display inside the button (text, icons, or other elements).
HTML button type attribute.Options:
"button" | "submit" | "reset"Variants
Primary Button
The default variant for primary actions:Secondary Button
For secondary or alternative actions:Danger Button
For destructive actions that require user attention:Outline Button
For subtle actions with an outlined style:Sizes
Small
Medium (Default)
Large
Block Width
Full-width buttons that stretch to fill their container:Disabled State
Real-World Examples
Form Submit Button
Confirmation Dialog
Action Group
With Icons
TypeScript Types
The Button component is fully typed for TypeScript users:Accessibility
- The Button component uses semantic
<button>HTML elements - Properly handles the
disabledstate with visual and functional feedback - Supports keyboard navigation (Enter and Space keys)
- Forwards refs for advanced accessibility features (e.g., focus management)
Best Practices
Use appropriate variants
Use appropriate variants
- Use
primaryfor the main action on a page - Use
secondaryfor alternative actions - Reserve
dangerfor destructive actions - Use
outlinefor tertiary actions
Button text guidelines
Button text guidelines
Loading states
Loading states
- Disable buttons during async operations
- Update button text to indicate loading (“Saving…”)
- Consider adding a loading spinner for longer operations
Related Components
TextField
Often used together in forms
CardContainer
Buttons frequently appear in card layouts