Use this example to create user-friendly buttons with icon for your Tailwind CSS and Angular project.
Below we present you our Angular Icon Button example crafted with Tailwind CSS that will help you build enterprise-level applications with ease. Customize the component or add it directly to your project!
You first need to import the DUIIconButton Module into your application module
Code
import { DUIIconButton } from "david-ui-angular"; @NgModule({ declarations: [AppComponent], imports: [BrowserModule, DUIIconButton], providers: [], bootstrap: [AppComponent], }) export class AppModule {}
Preview
Code
import { faHeart } from '@fortawesome/free-solid-svg-icons'; heartIcon = faHeart; <!-- Use DUI Button in html file --> <dui-icon-button color="gray"> <fa-icon [icon]="heartIcon"></fa-icon> </dui-icon-button>
You can use different variants of the button component by manipulating the variant attribute of the component.
Preview
Code
import { faHeart } from '@fortawesome/free-solid-svg-icons'; heartIcon = faHeart; <!-- Use DUI Button in html file --> <dui-icon-button size="md" variant="filled" color="gray"> <fa-icon [icon]="heartIcon"></fa-icon> </dui-icon-button> <dui-icon-button size="md" variant="outlined" color="gray"> <fa-icon [icon]="heartIcon"></fa-icon> </dui-icon-button> <dui-icon-button size="md" variant="text" color="gray"> <fa-icon [icon]="heartIcon"></fa-icon> </dui-icon-button> <dui-icon-button size="md" variant="gradient" color="gray"> <fa-icon [icon]="heartIcon"></fa-icon> </dui-icon-button>
You can use different sizes of the button component by manipulating the size attribute of the component
Preview
Code
import { faHeart } from '@fortawesome/free-solid-svg-icons'; heartIcon = faHeart; <!-- Use DUI Button in html file --> <dui-icon-button size="sm" color="gray"> <fa-icon [icon]="heartIcon"></fa-icon> </dui-icon-button> <dui-icon-button size="md" color="gray"> <fa-icon [icon]="heartIcon"></fa-icon> </dui-icon-button> <dui-icon-button size="lg" color="gray"> <fa-icon [icon]="heartIcon"></fa-icon> </dui-icon-button>
You can use different colors of the button component by manipulating the color attribute of the component
Preview
Code
<div class="flex items-center gap-4"> <dui-icon-button color="gray"> <fa-icon [icon]="heartIcon"></fa-icon> </dui-icon-button> <dui-icon-button color="blue"> <fa-icon [icon]="heartIcon"></fa-icon> </dui-icon-button> <dui-icon-button color="red"> <fa-icon [icon]="heartIcon"></fa-icon> </dui-icon-button> <dui-icon-button color="yellow"> <fa-icon [icon]="heartIcon"></fa-icon> </dui-icon-button> <dui-icon-button color="green"> <fa-icon [icon]="heartIcon"></fa-icon> </dui-icon-button> </div>
You can use rounded
attribute of IconButton
component to create rounded buttons.
Preview
Code
<div class="flex items-center gap-4"> <dui-icon-button [rounded]="true" color="gray" variant="filled" > <fa-icon [icon]="heartIcon"></fa-icon> </dui-icon-button> <dui-icon-button [rounded]="true" color="gray" variant="outlined" > <fa-icon [icon]="heartIcon"></fa-icon> </dui-icon-button> <dui-icon-button [rounded]="true" color="gray" variant="text" > <fa-icon [icon]="heartIcon"></fa-icon> </dui-icon-button> <dui-icon-button [rounded]="true" color="gray" variant="gradient" > <fa-icon [icon]="heartIcon"></fa-icon> </dui-icon-button> </div>
You can turn on/off the ripple effect for the IconButton
Component using ripple
attribute.
Preview
Code
<dui-icon-button [ripple]="true" color="gray" variant="filled" > <fa-icon [icon]="heartIcon"></fa-icon> </dui-icon-button> <dui-icon-button [ripple]="false" color="gray" variant="filled" > <fa-icon [icon]="heartIcon"></fa-icon> </dui-icon-button>
The following properties are available for dui-icon-button
Attribute | Type | Description | Default |
---|---|---|---|
variant | Variant | change button variant | filled |
color | Color | change button color | gray |
className | string | Add custom className for button | '' |
size | boolean | Change button size | md |
fullWidth | boolean | Block level button | false |
rounded | boolean | Rounded button | false |
ripple | boolean | Toggle ripple effect in button | true |
Code
type variant = 'filled' | 'outlined' | 'gradient' | 'text';
Code
type size = 'sm' | 'md' | 'lg';
Code
type colors = | "blue-gray" | "gray" | "brown" | "deep-orange" | "orange" | "amber" | "yellow" | "lime" | "light-green" | "green" | "teal" | "cyan" | "light-blue" | "blue" | "indigo" | "deep-purple" | "purple" | "pink" | "red";