Anchor Design System

Button3.0

Buttons allow users to perform actions and choose with a single tap.

Installation

npm i @tryg/ui-library

Usage

Individual only imports the desired component, and only needs to be included once within the application. Which is beneficial to keep the application size small.

Webcomponent
<script type="module">
  import { defineCustomElement } from '@tryg/ui-library/dist/components/anchor-button';
  defineCustomElement();
</script>
<anchor-button text="anchor button" variant="primary" />

Global only needs to be defined once in the application, but it will import all components even the ones that are not in use..

Webcomponent
<script type="module">
  import { defineCustomElements } from '@tryg/ui-library/dist/loader';
  defineCustomElements();
</script>
<anchor-button text="anchor button" variant="primary" />

Variants

Pass the variant prop to display the desired button variant.

Webcomponent
<anchor-button variant="primary" text="anchor button"></anchor-button>
<anchor-button variant="secondary" text="anchor button"></anchor-button>
<anchor-button variant="tertiary" text="anchor button"></anchor-button>

Disabled

Pass the disabled prop to display disabled state of button.

Webcomponent
<anchor-button disabled text="anchor button" variant="primary" />

Loading

Pass the loading prop to display a Spinner component inside the button.

Webcomponent
<anchor-button loading text="anchor button" variant="primary" />

Icon

You can add icons to the AnchorButton by passing the icon prop and adjust its position with icon-placement prop.

Webcomponent
<anchor-button icon="chevron-right" icon-placement="right" text="anchor button" variant="primary" />

Accessibility

  • Button has role of button.
  • Keyboard event support for Space and Enter keys.
  • Mouse and touch event handling, and press state management.
  • Keyboard focus management and cross browser normalization.

We recommend to read this blog post about the complexities of building buttons that work well across devices and interaction methods.

CSS variables

With CSS variables you can easily customize parts of the Button component. See the table below for a list of available variables.

Button width and height

Previous versions of the Anchor Button has a fixed width of 200px. Now the Button is fully responsive and will grow with it's content by default. This can easily be overwritten by using the CSS variable, for instance like this:

A custom width:

anchor-button {
  --button-width: 300px;
}

Full width:

anchor-button {
  --button-width: 100%;
}

Note that this only works with a width of 100% at the moment.

A width declared in percentage of anything less than 100 will not achieve the desired result. Please use a container element or set a specific width in pixels if 100% is not what is needed.


The height of the button is set to be 48px if the base font-size is 16px. This is because we want the Button to match the height of the Input field by default.

If you wish to keep the Button at a height of 40px, like in previous iterations, you can do this with the --line-height variable.

Total height of 40px:

anchor-button {
  --button-line-height: 1rem;
}

Gap between icon and text

In previous versions of the Button, you could set the gap between icon and text with a prop.

To simplify the interface of the Button, this functionality is now only available as a CSS variable.

Example:

anchor-button {
  --button-gap-icon-text: [your value];
}

Handling click events

Do it as you would with any other element. Consult the documentation for your framework on how handle events. (https://reactjs.org/docs/handling-events.html, https://vuejs.org/v2/guide/events.html, etc...)

In basic vanilla html and javascript it goes like this.

<script>
  // DOM has to be loaded and ready. Not strictly necessary in this case but a good practice.
  // Depending on your framework and/or setup you might already have an implementation in place.
  document.addEventListener('DOMContentLoaded', () => {
    // select button element
    const myButtonEl = document.querySelector('#my-button');

    // add the custom listener
    myButtonEl.addEventListener('click', event => {
      console.log('clicked my button: ', event);
    });
  });
</script>
<anchor-button id="my-button" text="anchor button" variant="primary" theme="brand" />

<!-- inline listener -->
<anchor-button onclick="javascript: console.log('inline event')" text="anchor button" variant="primary" theme="brand" />

Notes

Please note that in order to support partner styling the buttons font-family is inherited. So if you are using a button inside an element with a custom font-style you need to specifically set the button font-family to it's proper value.

API

Button

Properties

PropertyAttributeDescriptionTypeDefault
disableddisabledSet whether or not the button should be disabled NB! This should be rarely be used as it's a potential accessibility issue. Disabled buttons are ignored by screen readers and keyboard navigation.booleanfalse
downloaddownloadThis attribute instructs browsers to download a URL instead of navigating to it, so the user will be prompted to save it as a local file. If the attribute has a value, it is used as the pre-filled file name in the Save prompt (the user can still change the file name if they want). Documentationstringundefined
hrefhrefContains a URL or a URL fragment that the hyperlink points to. If this property is set, an anchor tag will be rendered. Documentationstringundefined
iconiconSet an icon to be displayed on the button"activity" | "airplay" | "alarm" | "alert-circle" | "alert-octagon" | "alert-triangle" | "align-center" | "align-justify" | "align-left" | "align-right" | "anchor" | "aperture" | "archive" | "arrow-down" | "arrow-down-circle" | "arrow-down-left" | "arrow-down-right" | "arrow-left" | "arrow-left-circle" | "arrow-right" | "arrow-right-circle" | "arrow-up" | "arrow-up-circle" | "arrow-up-left" | "arrow-up-right" | "at-sign" | "award" | "band-aid" | "bar-chart" | "bar-chart-2" | "basket" | "battery" | "battery-charging" | "bell" | "bell-off" | "bluetooth" | "bold" | "bonus-tryghedsgruppen" | "book" | "book-open" | "bookmark" | "box" | "briefcase" | "calculator" | "calendar" | "camera" | "camera-off" | "cast" | "check" | "check-circle" | "check-square" | "chevron-down" | "chevron-left" | "chevron-right" | "chevron-up" | "chevrons-down" | "chevrons-left" | "chevrons-right" | "chevrons-up" | "chrome" | "circle" | "clipboard" | "clock" | "cloud" | "cloud-drizzle" | "cloud-lightning" | "cloud-off" | "cloud-rain" | "cloud-snow" | "code" | "codepen" | "codesandbox" | "coffee" | "columns" | "command" | "company" | "compass" | "copy" | "corner-down-left" | "corner-down-right" | "corner-left-down" | "corner-left-up" | "corner-right-down" | "corner-right-up" | "corner-up-left" | "corner-up-right" | "cpu" | "credit-card" | "crop" | "crosshair" | "database" | "delete" | "disc" | "divide" | "divide-circle" | "divide-square" | "dollar-sign" | "download" | "download-cloud" | "dribbble" | "droplet" | "edit" | "edit-2" | "edit-3" | "external-link" | "eye" | "eye-off" | "facebook" | "fast-forward" | "feather" | "figma" | "file" | "file-minus" | "file-pdf" | "file-plus" | "file-text" | "film" | "filter" | "flag" | "folder" | "folder-minus" | "folder-plus" | "framer" | "frown" | "gift" | "git-branch" | "git-commit" | "git-merge" | "git-pull-request" | "github" | "gitlab" | "globe" | "grid" | "hard-drive" | "hash" | "headphones" | "heart" | "help-circle" | "hexagon" | "home" | "image" | "inbox" | "info" | "instagram" | "italic" | "key" | "layers" | "layout" | "life-buoy" | "link" | "link-2" | "linkedin" | "list" | "loader" | "lock" | "log-in" | "log-out" | "mail" | "map" | "map-pin" | "maximize" | "maximize-2" | "megaphone" | "meh" | "menu" | "message-circle" | "message-square" | "mic" | "mic-off" | "minimize" | "minimize-2" | "minus" | "minus-circle" | "minus-square" | "monitor" | "moon" | "more-horizontal" | "more-vertical" | "mouse-pointer" | "move" | "music" | "navigation" | "navigation-2" | "octagon" | "offer" | "package" | "paperclip" | "pause" | "pause-circle" | "pen-tool" | "percent" | "phone" | "phone-call" | "phone-forwarded" | "phone-incoming" | "phone-missed" | "phone-off" | "phone-outgoing" | "pie-chart" | "play" | "play-circle" | "plus" | "plus-circle" | "plus-square" | "pocket" | "power" | "printer" | "radio" | "refresh-ccw" | "refresh-cw" | "repeat" | "rewind" | "rotate-ccw" | "rotate-cw" | "rss" | "save" | "scissors" | "search" | "send" | "server" | "settings" | "share" | "share-2" | "shield" | "shield-off" | "shopping-bag" | "shopping-cart" | "shuffle" | "sidebar" | "skip-back" | "skip-forward" | "slack" | "slash" | "sliders" | "smartphone" | "smile" | "speaker" | "sprout" | "square" | "star" | "star-filled" | "stop-circle" | "storm" | "sun" | "sunrise" | "sunset" | "table" | "tablet" | "tag" | "target" | "terminal" | "thermometer" | "thumbs-down" | "thumbs-up" | "toggle-left" | "toggle-right" | "tool" | "trash" | "trash-2" | "trello" | "trending-down" | "trending-up" | "triangle" | "truck" | "trygfonden" | "tv" | "twitch" | "twitter" | "type" | "umbrella" | "underline" | "unlock" | "upload" | "upload-cloud" | "user" | "user-check" | "user-minus" | "user-plus" | "user-x" | "users" | "video" | "video-off" | "voicemail" | "volume" | "volume-1" | "volume-2" | "volume-x" | "watch" | "wifi" | "wifi-off" | "wind" | "x" | "x-circle" | "x-octagon" | "x-square" | "youtube" | "zap" | "zap-off" | "zoom-in" | "zoom-out"undefined
iconPlacementicon-placementSet the position of the icon on a button with an icon"left" | "none" | "right"'none'
loadingloadingSet the Button state to loading to display a spinner iconbooleanfalse
onDarkon-darkSet to true if the Button is displayed on dark backgroundbooleanfalse
pingpingThe ping property is a space-separated list of URLs. When the link is followed, the browser will send POST requests with the body PING to the URLs. Documentationstringundefined
relrelSpecifies the relationship of the target object to the link object. The value is a space-separated list of link types."alternate" | "author" | "bookmark" | "external" | "help" | "license" | "me" | "next" | "nofollow" | "noopener" | "noreferrer" | "opener" | "prev" | "privacy-policy" | "search" | "tag" | "terms-of-service"undefined
targettargetSpecifies where to display the linked URL. Only applies when an href is provided. Special keywords: "_blank", "_self", "_parent", "_top". Documentation"_blank" | "_parent" | "_self" | "_top"undefined
texttextSet a text to be displayed in the content slot of the buttonstringundefined
typetypeSet the type of button"button" | "reset" | "submit"'button'
uuiduuidGive this instance of button a custom ID, or keep the default.stringuuidv4()
variantvariantSet the variant of the button"primary" | "secondary" | "tertiary"'primary'

Slots

SlotDescription
"end-content"Slot for the end content of the button
"start-content"Slot for the start content of the button

CSS Custom Properties

NameDescription
--background-colorDEPRECATED: kept for backwards compatibility, but will be removed by August 2024
--background-color-primaryDEPRECATED: kept for backwards compatibility, but will be removed by August 2024
--background-color-secondaryDEPRECATED: kept for backwards compatibility, but will be removed by August 2024
--background-color-tertiaryDEPRECATED: kept for backwards compatibility, but will be removed by August 2024
--border-widthDEPRECATED: kept for backwards compatibility, but will be removed by August 2024
--button-background-colorSet the background color.
--button-background-color-hoverSet the background color on hover
--button-background-color-pressedSet the background color on press
--button-background-color-primarySet the primary background color.
--button-background-color-secondarySet the secondary background color.
--button-background-color-tertiarySet the tertiary background color.
--button-border-colorSet the border color of the
--button-border-widthSet the border width of the
--button-bottom-left-radiusSet the bottom-left radius of the button.
--button-bottom-right-radiusSet the bottom-right radius of the button.
--button-gap-icon-textSet the gap between icon and text.
--button-icon-colorSet the icon color.
--button-line-heightSet the line height.
--button-text-colorSet the text color.
--button-top-left-radiusSet the top-left radius of the button.
--button-top-right-radiusSet the top-right radius of the button.
--button-widthSet the width.
--gap-icon-textDEPRECATED: kept for backwards compatibility, but will be removed by August 2024
--icon-colorDEPRECATED: kept for backwards compatibility, but will be removed by August 2024
--line-heightDEPRECATED: kept for backwards compatibility, but will be removed by August 2024
--text-colorDEPRECATED: kept for backwards compatibility, but will be removed by August 2024
--widthDEPRECATED: kept for backwards compatibility, but will be removed by August 2024

Dependencies

Depends on

Graph


Built with StencilJS

Anchor versionStatusNotes
3.0Ready for ImplementationThis component is in sync with Figma.

On this page