A button that shows only an icon.
The icon is the block you pass in, so it works with whatever icon source you
use: inline SVGs, ember-fontawesome's FaIcon, or your own components. It
takes the same sizes, colors and variants as
Button
. It is a circle, as tall as a Button of
the same size.
import { IconButton } from 'frontile';
Put the icon in the block and name the button with @label. The label is
required.
import { IconButton } from 'frontile';
import { DeleteIcon } from 'site/components/icons';
<template>
<IconButton @label='Delete item'><DeleteIcon /></IconButton>
</template>
@size takes xs, sm, md, lg, xl and 2xl, the same names as Button.
The default is md. An IconButton lines up with a Button of the same size, and
its icon is sized to the button's text, so it grows with the button.
import { IconButton } from 'frontile';
import { EditIcon } from 'site/components/icons';
<template>
<div class='flex items-center gap-3'>
<IconButton @label='Edit' @size='xs'><EditIcon /></IconButton>
<IconButton @label='Edit' @size='sm'><EditIcon /></IconButton>
<IconButton @label='Edit'><EditIcon /></IconButton>
<IconButton @label='Edit' @size='lg'><EditIcon /></IconButton>
<IconButton @label='Edit' @size='xl'><EditIcon /></IconButton>
<IconButton @label='Edit' @size='2xl'><EditIcon /></IconButton>
</div>
</template>
An IconButton is as tall as a Button of the same @size, so the two line up in
a row.
import { Button, IconButton } from 'frontile';
import { DeleteIcon } from 'site/components/icons';
<template>
<div class='flex items-center gap-2'>
<Button @size='md'>Delete</Button>
<IconButton @size='md' @label='Delete'><DeleteIcon /></IconButton>
</div>
</template>
@color and @variant take the same values as Button.
import { IconButton } from 'frontile';
import { DeleteIcon, DuplicateIcon, ShareIcon } from 'site/components/icons';
<template>
<div class='flex items-center gap-3'>
<IconButton @label='Delete' @color='danger'><DeleteIcon /></IconButton>
<IconButton @label='Copy' @variant='outline'><DuplicateIcon /></IconButton>
<IconButton @label='Share' @variant='ghost' @color='primary'><ShareIcon
/></IconButton>
</div>
</template>
@isLoading swaps the icon for a spinner and disables the button. The button
keeps its name. Use the native disabled attribute to disable it otherwise.
import { IconButton } from 'frontile';
import { DownloadIcon } from 'site/components/icons';
<template>
<div class='flex items-center gap-3'>
<IconButton @label='Download' @isLoading={{true}}><DownloadIcon
/></IconButton>
<IconButton @label='Download' disabled><DownloadIcon /></IconButton>
</div>
</template>
@onPress works as it does on Button and fires for mouse, touch and keyboard.
import { IconButton } from 'frontile';
import { ArchiveIcon } from 'site/components/icons';
<template>
<IconButton @label='Archive' @onPress={{this.archive}}><ArchiveIcon
/></IconButton>
</template>
An icon has no text, so @label is required and must not be empty. It becomes
the button's aria-label. Name the action ("Delete item"), not the picture
("Trash can"). Hide the icon from assistive technology with aria-hidden="true"
so it is not announced as well.
The button is a native <button>. It takes focus with Tab and activates with
Enter or Space, and it shows the same focus ring as Button. While loading it
is disabled and reports aria-busy.
Element: HTMLButtonElement
| Name | Type | Default | Description |
|---|---|---|---|
label
*
|
string
|
- |
The accessible name. An icon-only button has no text, so this is
required and must not be empty; it becomes the button's aria-label.
|
class
|
string
|
- | Custom class name, it will override the default ones using Tailwind Merge library. |
color
|
enum
|
- | The color of the button. Same values as Button. |
isLoading
|
boolean
|
false
|
Renders a spinner in place of the icon and disables the button. |
onPress
|
function
|
- | Callback for when the button is pressed. |
size
|
enum
|
'md'
|
The size of the button. Same names as Button, and the same height, so an IconButton lines up with a Button of that size. |
type
|
enum
|
- | The HTML type of the button. |
variant
|
enum
|
- | The button variant. Same values as Button. |
| Name | Type | Default | Description |
|---|---|---|---|
default
*
|
Array
|
- |
The icon, for example an inline <svg>. Sized to the button's text.
|