Skip to main content
Version: 1.0.3

Button With Icon

Overview

The ButtonWithIcon component extends the base Button component with comprehensive icon support. It allows you to position icons on the left or right of text, create icon-only buttons, and display loading spinners. This component is perfect for creating intuitive and visually appealing user interfaces.

Preview

Installation

ignix add component button-with-icon

Usage

Import the component:

import { ButtonWithIcon } from './components/ui';

Basic Usage

import { ButtonWithIcon } from './components/ui';
import { Download } from 'lucide-react';

function BasicButtonWithIcon() {
return (
<ButtonWithIcon icon={<Download />}>
Download
</ButtonWithIcon>
);
}

Props

PropTypeDefaultDescription
iconReact.ReactNodeundefinedIcon component to display (from lucide-react or any React component)
iconPosition'left' | 'right' | 'only''left'Position of the icon relative to text
loadingbooleanfalseShow loading spinner and disable button
iconSizenumber16Size of the icon in pixels
variantstring'default'Visual variant of the button (inherited from Button)
sizestring'md'Size of the button (inherited from Button)
disabledbooleanfalseDisable the button
childrenReact.ReactNodeundefinedButton text content

All other props from the base Button component are also supported.

Examples

Icon Left (Default)

The icon appears before the text. This is the most common pattern for buttons with icons.

<ButtonWithIcon icon={<Download />} iconPosition="left">
Download
</ButtonWithIcon>

Icon Right

The icon appears after the text. Useful for actions like "Next" or "Continue" where the icon indicates direction.

<ButtonWithIcon icon={<Send />} iconPosition="right">
Send
</ButtonWithIcon>

Icon Only

Icon-only buttons are compact and space-efficient. Perfect for toolbars, action menus, or when space is limited.

<ButtonWithIcon icon={<Settings />} iconPosition="only" />

Loading State

The loading state automatically disables the button and shows a spinner. Useful for async operations like form submissions or API calls.

<ButtonWithIcon loading={true}>
Processing
</ButtonWithIcon>

Form Submission with Loading

import { useState } from 'react';
import { ButtonWithIcon } from './components/ui';
import { Save } from 'lucide-react';

function FormExample() {
const [isSubmitting, setIsSubmitting] = useState(false);

const handleSubmit = async () => {
setIsSubmitting(true);
// Simulate API call
await new Promise(resolve => setTimeout(resolve, 2000));
setIsSubmitting(false);
};

return (
<ButtonWithIcon
icon={<Save />}
loading={isSubmitting}
onClick={handleSubmit}
variant="primary"
>
Save Changes
</ButtonWithIcon>
);
}