Directory
- Welcome
Button Component
The Button component provides acts as the foundation for many of the components in this library. It supports multiple variants, sizes, and can function as either a button or link.
Key Features
-
Flexible Variants: Seventeen distinct styles for different contexts
-
Responsive Sizing: Five size options to fit any layout
-
Icon Support: Seamless integration with icons
-
Link Capability: Functions as both button and link
Variants
Variant Use Cases
- Default: Primary actions and main calls-to-action
- Secondary: Alternative or complementary actions
- Input: Styled to look like an input field, used for select, dropdown, datepicker, etc.
- Destructive: Actions that require caution or delete operations
- Transparent: Subtle interactions within content
- Link: Text-based navigation while maintaining button behavior
- Icon: Compact, icon-only actions
Size Options
Buttons come in five sizes to fit different contexts:
Input variant styling
To style the input variant, pass the inputVariant
prop either true
to have the default input styling or an object to have the input variant styling. It matches the input variants from the input component.
Disabled State
The disabled state is applied to the button when the disabled
prop is set to true
.
Code Example
---import Button from '@/components/NST-components/UI/button/Button.astro';import close from '@/assets/icons/close.svg?raw';---
<!-- Standard Button --><Button variant="default" size="default"> Click Me </Button>
<!-- Link Button --><Button variant="link" href="/about"> About Us </Button>
<!-- Icon Button --><Button variant="icon" icon={close} size="lg" />
<!-- Disabled State --><Button variant="default" disabled> Unavailable </Button>
<Button inputVariant disabled> Input Style </Button>
Button Component Props API
Prop | Type | Default | Description |
---|---|---|---|
disabled | boolean | false | Disables button interaction |
href | string | url | null | Optional URL for link functionality | |
icon | string | SVG string for icon content | |
iconPosition | left | right | left | Position of the icon |
iconProps | Omit<IconProps, "svg"> | Props for the Icon component | |
inputVariant | boolean | Partial<VariantProps<typeof inputVariants>> | Input variant for the button | |
size | fit | sm | md | default | lg | default | Size of the button |
target | HTMLAttributeAnchorTarget | Link target attribute | |
variant | default | secondary | destructive | transparent | link | icon | gradient | frost | neon | push | outlineGlow | retro | pulse | shine | magnetic | elegant | soft | modern | default | Visual style of the button |
Advanced Features
Icon Integration
Add icons to enhance button clarity:
<Button variant="default" iconPosition="right" iconProps={{ class: 'ml-1' }} icon={arrowRight}> Next</Button>
/>
Link Functionality
Buttons with href
attribute will use the <a> anchor element while maintaining button styling:
Best Practices
-
Button Text
- Use action verbs
- Keep text concise
- Be descriptive
- Maintain consistency
-
Visual Hierarchy
- Use primary variant for main actions
- Limit destructive buttons
- Group related buttons
- Maintain adequate spacing
-
Responsive Design
- Consider mobile touch targets
- Adapt size to viewport
- Ensure readable text
- Test across devices
Common Applications
Form submissions
Navigation triggers
Modal controls
Action confirmations
Toggle operations
Download triggers
Social sharing
Settings controls
Limited Time Launch Sale
Build professional interfaces faster with our pre-built Button component. Get the AstroJS starter template now and access a complete UI toolkit.
GET 60% OFF!