@ewc-lib/ewc-icon-button
v3.5.3-alpha
Published
A button with a certain look and feel, displaying one of a set of given icons.
Keywords
Readme
EWC icon-button Component
A button with a certain look and feel, displaying one of a set of given icons.
Overview
The ewc-icon-button component provides a standardized button for Eurostat web applications. It offers a consistent visual identity across Eurostat digital products.
Features
- Can be used on light or dark background
- Offers icons commonly used in visualisations
- Accessibility compliant
- It's state can be true (pressed), false (not pressed) or disabled (not focusable).
- Each state has it's own visual representation (incl. focus and hover effects).
Screenshot

API
Attributes
The following attributes are available and can be modified at runtime:
| Attributes | Properties | Default | Mandatory? | Description |----------------|------------|---------|------------|--------- | icon | | none | yes | Specifies the icon displayed in the button. one of: [close, linechart, barchart, dotplot, table, star, share, information, download, calendar, chevronleft, chevronright, squareshare] | background | | light | no | on which kind of background the button is used. one of: [light, dark, blue]. default is light. | state | state (set & get) | false | no | Specifies if the button is pressed or not pressed or disabled. tristate, one of [true,false,disabled] (see below for details about state) | size | | 32px | no | the width and height of the icon. | title | | none | no | Specifies a text that is displayed in a tooltip. If omitted, no tooltip is shown. | btn-aria-label | | "" | no | the aria-label of the button element inside the shadow DOM (not of the ewc-icon-button itself) | pressed-focusable | | false | no | if set to "true", a button that's pressed is also focusable. otherwise a pressed button is not focusable. | label | | "" | no | sets the text displayed in the button at the right side of the icon | use-config | | "" | no | specify the id of another config (see below for details) | tooltip-pos | | "bottom"| no | specify where the tooltip should appear - top, right, bottom or left of the button. one of: [top, right, bottom, left]. | | | | | Note: The convention is, to try to place it without covering other content. The preferred placement order is: bottom, top, right, left. | | | | | Example: If there is a button, surrounded by important content on it's bottom, top and right -> the tooltip should be placed on the left side of that button. | tooltip-suppressed| | false | no | If true, tooltip is not displayed at all | type | | action | no | one of [open-dialog, open-menu, toggle, action, radio]. This specifies the conext in which the button is used - and assigns aria attributes accordingly. For details, please see also usage contexts. | | | | | Note: type "action" is not toggle-able, all others are. | controlling-id | | | no | the ID of a menu or dialog or popover, any element which is controlled by this button. Takes care of setting aria-controls on this button appropriately.
Events
- action - keyboard-Enter/Space key and mouse-click are captured, prevented and instead one event "action" is dispatched.
Public functions
- toggle() - switches state between "true" and "false" as long as state is not "disabled".
Tooltip Z index
The tooltip has z-index: 70, so make sure content covered by the tooltip has a lower z-index.
Notes
aria ⚠️
- please put the aria-haspopup on the ewc-icon-button HTML element, depending on the context:
- for toggling the ewc-popover-sharing: aria-haspopup="menu"
- for info button: aria-haspopup="dialog"
- when used within an ewc-button-group: aria-haspopup="false"
- please put the aria-haspopup on the ewc-icon-button HTML element, depending on the context:
state
- if set to "true", the button visually displays as being "pressed".
- if set to "false" to display as "not pressed".
- "false" is the default.
- if set to "disabled", the button displays as disabled/no interaction possible.
- no events are emitted when disabled
- implicitly sets aria-pressed
- a button does not switch it's state by itself
- the user of the component has to set the state as reaction to an "action" event (eg. via toggle())
use-config - for developers only.
- Per default, the icon name identifies the (internal) config to be used. To keep the icon but style it alternatively, this attribute can specify the id of another config.
- Note: Intended primarily to support button groups.
- For a regular component user this is not relevant.
label can be changed at runtime
The temporary state when mouse is being clicked but not yet released, is not considered
Details
For further details please see comment in cfg.js.
Usage Contexts
|context|example of usage in vis.|button type| |--|--|--| |execute an action|close, save, print, prev, next|action |open a dialog|i to open info dialog|open-dialog| |open action list|share|open-menu| |toggle button|-|toggle| |button within a radiobutton-group|switch chart type|radio|
Note that type "radio" is implicitly utilised by ewc-icon-button-group.
Usage
Installation
npm install @ewc-lib/ewc-icon-buttonImport the component in your application:
// Using ES modules
import "@ewc-lib/ewc-css-common/custom-props.css";
import '@ewc-lib/ewc-icon-button';Note about ewc-css-common
- "ewc-css-common/custom-props.css" is necessary for the correct styling of this component.
- It needs to be imported by the host project because it's not imported by this component implicitly.
Setting the size
This sets the dimensions of the button (not the icon):
ewc-icon-button::part(button) {
width:48px;
height:72px;
}And this sets the dimensions of the icon and it's backdrop (circle):
<ewc-icon-button size="48">- The icon always stays in the center
- Setting width/height of ewc-icon-button itself is not supported, please use sizing methods mentioned above.
Notes
Accessibility
The component is designed with accessibility in mind:
- Keyboard navigable element
- Sufficient color contrast
Browser Support
- Chrome (latest)
- Firefox (latest)
- Safari (latest)
- Edge (latest)
License
European Union Public License (EUPL)
Changelog
3.5.3-alpha
- arias for button group
3.5.1-alpha, 3.5.2-alpha
- arias
- introduction of button type
- bugfix: error from shared icon click
3.5.0-alpha
- a11y fixes for button / main element
3.4.1-alpha - 3.4.3-alpha
- tooltip
3.4.0-alpha
- tooltip
3.3.0-alpha
- suppressTooltip feature
- Note: Playwright tests are not adapted yet
3.2.0-alpha
- tooltip pos configurable, default below
3.0.0-alpha
- config and tests
2.5.0-alpha
- tooltips
2.4.0-alpha
- new style
- new buttons
2.2.1-alpha
- simplify config, increasing human readability, while retaining fine-granular config possibility
- add mode for blue background
- slight corrections of icon svg and colors
2.2.0-alpha
- change config (colors) to match latest design
- rename some files
2.1.0-alpha
- correction of behaviour when toggling state "disabled"
- style config for (support of) disabled linechart, barchart, dotplot, table
- documentation
2.0.2-alpha
- fix label casing bug
2.0.1-alpha
- support integration, avoid unneccessary console output
2.0.0-alpha
- update icons: linechart, barchart, hilo-chart (dotplot), table
1.1.0-alpha
- add aria-disabled
- rework posibilities sizing button and icon
- docu
1.0.2-alpha
- add width/height attribs
- use peerDependencies
- docu
1.0.1-alpha
- add icons, implement state, add usage examples, config
