Icon button2.0
Ads by Tryg Careers
Installation
npm i @tryg/vue-ui-libraryUsage
Install the component library as a Vue plugin. This globally registers all Anchor components.
import { createApp } from 'vue';
import { ComponentLibrary } from '@tryg/vue-ui-library';
import App from './App.vue';
const app = createApp(App);
app.use(ComponentLibrary);
app.mount('#app');<template>
<anchor-icon-button button-title="Close">
<anchor-icon slot="icon" name="x" size="small" />
</anchor-icon-button>
</template>Import only the components you need for optimal bundle size.
<script setup>
import { AnchorIconButton, AnchorIcon } from '@tryg/vue-ui-library';
</script>
<template>
<anchor-icon-button button-title="Close">
<anchor-icon slot="icon" name="x" size="small" />
</anchor-icon-button>
</template>Disabled
<script setup>
import { AnchorIconButton, AnchorIcon } from '@tryg/vue-ui-library';
</script>
<template>
<anchor-icon-button button-title="Close" disabled>
<anchor-icon slot="icon" name="x" size="small" />
</anchor-icon-button>
</template>On dark
<script setup>
import { AnchorIconButton, AnchorIcon } from '@tryg/vue-ui-library';
</script>
<template>
<anchor-icon-button button-title="Close" theme="on-dark">
<anchor-icon slot="icon" name="x" size="small" />
</anchor-icon-button>
</template>Slot
- icon: The icon to display inside the button.
The Icon Button does not display an Icon on it's own. The Icon is implemented as a slot to allow total freedom.
Use the attribute slot="icon" to show an Icon in Icon Button.
Example of using Icon with Icon Button:
<script setup>
import { AnchorIconButton, AnchorIcon } from '@tryg/vue-ui-library';
</script>
<template>
<anchor-icon-button button-title="Close">
<anchor-icon slot="icon" name="x" size="small" />
</anchor-icon-button>
</template>Notice that the Icon Button is designed to use an Icon in size="small".
Props
- theme: The theme of the button. Can be "default" or "on-dark". Defaults to "default". Use "on-dark" when the Icon Button is placed on a dark background.
- buttonTitle: The text to display when the user hovers over the button.
States
- default: The default state of the button.
- hover: The state of the button when the user hovers over it.
- pressed: The state of the button when the user clicks on it.
- focus: The state of the button when it has focus.
Accessibility
- Renders as a native
<button>element by default, inheriting standard button semantics including role and keyboard behavior. - Keyboard support: Enter and Space activate the button when it has focus.
- Always provide an
ariaLabelprop to give screen readers a meaningful description, since icon-only buttons lack visible text. - The
buttonTitleprop sets thetitleattribute on the button, providing a tooltip on hover for visual users. - When disabled, the button receives the native
disabledattribute, making it both non-interactive and skipped by keyboard navigation.
CSS variables
The following CSS custom properties are exposed:
| Variable | Description |
|---|---|
--focus-ring-color | Changes the color of the outline for the component |
--focus-ring-offset | Changes the offset of the outline for the component |
--focus-ring-style | Changes the style of the outline for the component |
--focus-ring-width | Changes the size of the outline for the component |
--icon-button-background | Set the background color of the <anchor-icon-button> |
--icon-button-background-hover | Set the hover background color of the <anchor-icon-button> |
--icon-button-background-on-dark | Set the background color on-dark of the <anchor-icon-button> |
--icon-button-background-on-dark-hover | Set the hover background color on-dark of the <anchor-icon-button> |
--icon-button-background-on-dark-pressed | Set the pressed background color on-dark of the <anchor-icon-button> |
--icon-button-background-ressed | Set the pressed background color of the <anchor-icon-button> |
--icon-button-border-radius | Set the border radius of the <anchor-icon-button> |
--icon-button-color | This is the color of the icon itself |
--icon-button-color-active | This is the hover color of the icon itself |
--icon-button-color-hover | This is the hover color of the icon itself |
--icon-button-color-on-dark | Set the color on-dark of the <anchor-icon-button> |
--icon-button-color-on-dark-hover | Set the hover color on-dark of the <anchor-icon-button> |
--icon-button-color-on-dark-pressed | Set the pressed color on-dark of the <anchor-icon-button> |
--icon-button-padding | Set the padding for <anchor-icon-button> |
--icon-button-size | Set the size of the <anchor-icon-button> |
--outline-override | Shorthand for changing the outline for the component |
API
anchor-icon-button
Properties
| Property | Attribute | Description | Type | Default |
|---|---|---|---|---|
ariaLabel | aria-label | aria-label attribute for the button - used for accessibility. | string | undefined |
buttonTitle | button-title | The title text that appears on hover. | string | undefined |
disabled | disabled | Set whether or not the icon button should be disabled | boolean | false |
tag | tag | Overrides the root tag element of the component. | string | undefined |
theme | theme | The theme of the button. Can be "default" or "on". | "default" | "on-dark" | 'default' |
CSS Custom Properties
| Name | Description |
|---|---|
--focus-ring-color | Changes the color of the outline for the component |
--focus-ring-offset | Changes the offset of the outline for the component |
--focus-ring-style | Changes the style of the outline for the component |
--focus-ring-width | Changes the size of the outline for the component |
--icon-button-background | Set the background color of the |
--icon-button-background-hover | Set the hover background color of the |
--icon-button-background-on-dark | Set the background color on-dark of the |
--icon-button-background-on-dark-hover | Set the hover background color on-dark of the |
--icon-button-background-on-dark-pressed | Set the pressed background color on-dark of the |
--icon-button-background-ressed | Set the pressed background color of the |
--icon-button-border-radius | Set the border radius of the |
--icon-button-color | This is the color of the icon itself |
--icon-button-color-active | This is the hover color of the icon itself |
--icon-button-color-hover | This is the hover color of the icon itself |
--icon-button-color-on-dark | Set the color on-dark of the |
--icon-button-color-on-dark-hover | Set the hover color on-dark of the |
--icon-button-color-on-dark-pressed | Set the pressed color on-dark of the |
--icon-button-padding | Set the padding for |
--icon-button-size | Set the size of the |
--outline-override | Shorthand for changing the outline for the component |
Dependencies
Used by
Graph
graph TD;
anchor-help-box --> anchor-icon-button
anchor-navigation-card --> anchor-icon-button
anchor-notification-banner --> anchor-icon-button
anchor-quantity --> anchor-icon-button
style anchor-icon-button fill:#f9f,stroke:#333,stroke-width:4pxBuilt with StencilJS
