Icon Button for M3E
npm install @m3e/icon-buttonm3e-icon-button component is a semantic, expressive UI primitive for triggering actions with a single icon. Designed according to Material Design 3 guidelines, it supports four visual variants, specified using the variant attributeβfilled, tonal, outlined, and standardβeach with dynamic elevation, shape morphing, and adaptive color theming. The component responds to interaction states (hover, focus, press, disabled) with smooth motion transitions, ensuring emotional clarity and visual hierarchy.
m3e-icon for icons, filled is automatically set based on the selected state of a toggle button. It can also function as a link or be used to submit form data.
elements cannot receive focus. This can be problematic in some cases because it can prevent you from telling the user why the button is disabled. You can use the disabled-interactive attribute to style a m3e-icon-button as disabled but allow for it to receive focus. The button will have aria-disabled="true" for assistive technology.
bash
npm install @m3e/icon-button
`
π» Editor Integration
This package includes a Custom Elements Manifest to support enhanced editor tooling and developer experience.
$3
To enable autocomplete and hover documentation for @m3e/icon-button, install the Custom Elements Manifest Language Server extension. It will automatically detect the manifest bundled with this package and surface tag names, attributes, slots, and events in supported files.
Alternately, you can explicitly reference the html-custom-data.json and css-custom-data.json in your workspace settings:
`json
{
"html.customData": ["./node_modules/@m3e/icon-button/dist/html-custom-data.json"],
"css.customData": ["./node_modules/@m3e/icon-button/dist/css-custom-data.json"]
}
`
π Native Module Support
This package uses JavaScript Modules. To use it directly in a browser without a bundler, use a module script similar to the following.
`html
`
In addition, you must use an import map to include dependencies.
`html
`
> For production, use index.min.js for faster load times.
ποΈ Elements
- m3e-icon-button β An icon button users interact with to perform a supplementary action.
π§ͺ Examples
The following example illustrates changing the appearance from standard (default) to filled using the variant attribute,
changing the size using the size attribute, and enabling toggle behavior using the toggle attribute.
`html
`
π API Reference
This section details the attributes, slots and CSS custom properties available for the m3e-icon-button component.
$3
| Attribute | Type | Default | Description |
| ---------------------- | ------------------------------------------------- | ------------ | -------------------------------------------------------------------------------------------------------------------------------------- |
| variant | "standard" \| "outlined" \| "filled" \| "tonal" | "standard" | The appearance variant of the button. |
| shape | "rounded" \| "square" | "rounded" | The shape of the button. |
| size | "extra-small" \| "small" \| "medium" \| "large" | "small" | The size of the button. |
| width | "narrow" \| "default" \| "wide" | "default" | The width of the button. |
| toggle | boolean | false | Whether the button will toggle between selected and unselected states. |
| selected | boolean | false | Whether the toggle button is selected. |
| disabled | boolean | false | Whether the element is disabled. |
| disabled-interactive | boolean | false | Whether the element is disabled and interactive. |
| type | "button" \| "submit" \| "reset" | "button" | The type of the element. |
| name | string | | The name of the element, submitted as a pair with the element's value as part of form data, when the element is used to submit a form. |
| value | string | | The value associated with the element's name when it's submitted with form data. |
| href | string | | The URL to which the link button points. |
| target | string | | The target of the link button. |
| rel | string | | The relationship between the target of the link button and the document. |
| download | string | | A value indicating whether the target of the link button will be downloaded, optionally specifying the new name of the file. |
$3
| Slot | Description |
| ----------- | --------------------------------------- |
| _(default)_ | Renders the icon of the button. |
| selected | Renders an icon when selected (toggle). |
$3
#### π§± Size Properties
All size variants (extra-small, small, medium, large, extra-large) support:
| Property | Description |
| ------------------------------------------------- | ------------------------------------ |
| --m3e-icon-button-[size]-container-height | Height of the button container |
| --m3e-icon-button-[size]-outline-thickness | Outline thickness |
| --m3e-icon-button-[size]-icon-size | Icon size |
| --m3e-icon-button-[size]-shape-round | Corner radius for round shape |
| --m3e-icon-button-[size]-shape-square | Corner radius for square shape |
| --m3e-icon-button-[size]-selected-shape-round | Corner radius when selected (round) |
| --m3e-icon-button-[size]-selected-shape-square | Corner radius when selected (square) |
| --m3e-icon-button-[size]-shape-pressed-morph | Corner radius when pressed |
| --m3e-icon-button-[size]-narrow-leading-space | Space before icon (narrow width) |
| --m3e-icon-button-[size]-narrow-trailing-space | Space after icon (narrow width) |
| --m3e-icon-button-[size]-default-leading-space | Space before icon (default width) |
| --m3e-icon-button-[size]-default-trailing-space | Space after icon (default width) |
| --m3e-icon-button-[size]-wide-leading-space | Space before icon (wide width) |
| --m3e-icon-button-[size]-wide-trailing-space | Space after icon (wide width) |
#### π¨ Appearance Variant Properties
All appearance variants (standard, outlined, filled, tonal) support the following properties (replace [variant] with the variant name):
| Property | Description |
| --------------------------------------------- | ----------------------------- |
| --m3e-[variant]-icon-button-icon-color | Icon color |
| --m3e-[variant]-icon-button-container-color | Container background color |
| --m3e-[variant]-icon-button-outline-color | Outline color (outlined only) |
#### π« State Properties
Each variant supports state properties for disabled, hover, focus, pressed, selected, and unselected. For each variant, the following properties are available (replace [variant] with the variant name):
| Property | Description |
| ------------------------------------------------------------------ | -------------------------------------- |
| --m3e-[variant]-icon-button-disabled-container-color | Container color when disabled |
| --m3e-[variant]-icon-button-disabled-container-opacity | Container opacity when disabled |
| --m3e-[variant]-icon-button-disabled-icon-color | Icon color when disabled |
| --m3e-[variant]-icon-button-disabled-icon-opacity | Icon opacity when disabled |
| --m3e-[variant]-icon-button-disabled-outline-color | Outline color when disabled (outlined) |
| --m3e-[variant]-icon-button-hover-icon-color | Icon color on hover |
| --m3e-[variant]-icon-button-hover-outline-color | Outline color on hover (outlined) |
| --m3e-[variant]-icon-button-hover-state-layer-color | State layer color on hover |
| --m3e-[variant]-icon-button-hover-state-layer-opacity | State layer opacity on hover |
| --m3e-[variant]-icon-button-hover-unselected-icon-color | Unselected icon color on hover |
| --m3e-[variant]-icon-button-hover-unselected-state-layer-color | Unselected state layer color on hover |
| --m3e-[variant]-icon-button-hover-selected-icon-color | Selected icon color on hover |
| --m3e-[variant]-icon-button-hover-selected-state-layer-color | Selected state layer color on hover |
| --m3e-[variant]-icon-button-focus-icon-color | Icon color on focus |
| --m3e-[variant]-icon-button-focus-outline-color | Outline color on focus (outlined) |
| --m3e-[variant]-icon-button-focus-state-layer-color | State layer color on focus |
| --m3e-[variant]-icon-button-focus-state-layer-opacity | State layer opacity on focus |
| --m3e-[variant]-icon-button-focus-unselected-icon-color | Unselected icon color on focus |
| --m3e-[variant]-icon-button-focus-unselected-state-layer-color | Unselected state layer color on focus |
| --m3e-[variant]-icon-button-focus-selected-icon-color | Selected icon color on focus |
| --m3e-[variant]-icon-button-focus-selected-state-layer-color | Selected state layer color on focus |
| --m3e-[variant]-icon-button-pressed-icon-color | Icon color on press |
| --m3e-[variant]-icon-button-pressed-outline-color | Outline color on press (outlined) |
| --m3e-[variant]-icon-button-pressed-state-layer-color | State layer color on press |
| --m3e-[variant]-icon-button-pressed-state-layer-opacity | State layer opacity on press |
| --m3e-[variant]-icon-button-pressed-unselected-icon-color | Unselected icon color on press |
| --m3e-[variant]-icon-button-pressed-unselected-state-layer-color | Unselected state layer color on press |
| --m3e-[variant]-icon-button-pressed-selected-icon-color | Selected icon color on press |
| --m3e-[variant]-icon-button-pressed-selected-state-layer-color | Selected state layer color on press |
#### π¦ Selected/Unselected State Properties
For toggle buttons, each variant supports selected/unselected state properties:
| Property | Description |
| ---------------------------------------------------------- | --------------------------------- |
| --m3e-[variant]-icon-button-selected-icon-color | Icon color when selected |
| --m3e-[variant]-icon-button-selected-container-color | Container color when selected |
| --m3e-[variant]-icon-button-selected-state-layer-color | State layer color when selected |
| --m3e-[variant]-icon-button-unselected-icon-color | Icon color when unselected |
| --m3e-[variant]-icon-button-unselected-container-color | Container color when unselected |
| --m3e-[variant]-icon-button-unselected-state-layer-color | State layer color when unselected |
π€ Contributing
See the root monorepo CONTRIBUTING.md` for guidelines on contributing to this package.