Anchor Design System

Card2.0

Card description

Installation

npm i @tryg/vue-ui-library

Usage

<template>
  <anchor-card>
    <h2 slot="header">Card Title</h2>
    <span slot="text">This is the card content.</span>
  </anchor-card>
</template>

Install the component library as a Vue plugin. This globally registers all Anchor components.

main.js
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');
YourComponent.vue
<template>
  <anchor-card>
    <h2 slot="header">Card Title</h2>
    <span slot="text">This is the card content.</span>
  </anchor-card>
</template>

Import only the components you need for optimal bundle size.

YourComponent.vue
<script setup>
import { AnchorCard } from '@tryg/vue-ui-library';
</script>
<template>
  <anchor-card>
    <h2 slot="header">Card Title</h2>
    <span slot="text">This is the card content.</span>
  </anchor-card>
</template>

Clickable Card

To make the card clickable, specify the url prop with the target URL:

<template>
  <anchor-card url="https://example.com">
    <h2 slot="header">Clickable Card</h2>
    <span slot="text">Click me to go to example.com</span>
  </anchor-card>
</template>

Customization

The Card component provides several props to customize its appearance and behavior:

  • align (optional, default: 'center'): Sets the text alignment of the card. Can be 'center' or 'left'.
  • showBorder (optional, default: true): Determines whether to show a border around the card.
  • showIcon (optional, default: false): Determines whether to show an icon in the card.
<template>
  <anchor-card :show-border="false">
    <span slot="text">card content.</span>
  </anchor-card>
  <anchor-card :show-icon="true">
    <span slot="header">This is the card content.</span>
  </anchor-card>
</template>

Slot Usage

The Card component supports several slots to insert different types of content:

  • header: The header content of the card.
  • text: The main text content of the card.
  • illustration: An optional illustration to display in the card (should not be used with the image slot).
  • image: An optional image to display in the card (should not be used with the illustration slot).
<template>
  <anchor-card>
    <h2 slot="header">Card Title</h2>
    <img slot="image" src="path/to/image.jpg" alt="Card Image" />
    <span slot="text">This is the card content.</span>
  </anchor-card>
</template>

Events

The Card component emits the following event:

  • clickEvent: Fired when the card is clicked. Use it to perform any necessary actions or navigation.
<script setup>
const handleCardClick = () => console.log('You clicked me!');
</script>
<template>
  <anchor-card vertical-align="center" @click-event="handleCardClick">
    <span slot="text">This is the card content.</span>
  </anchor-card>
</template>

Styling

The following CSS variables are exposed at the

level so you can overwrite them with your own values:

--width: unset;
--min-width: 128px;
--image-margin: calc(var(--padding) * -1);
--background-color: var(--color-background-default);

// Text
--text-color: var(--color-text-default);

// Border
--border-color: var(--color-border-default);
--border-width: 1px;
--border-radius: 4px;

// Focus
--focus-color: var(--color-border-outline);
--focus-offset: 2px;

// Padding
--padding: 24px;

// Icon
--icon-color: var(--color-icon-variant);

// Shadow
--shadow: none;

Accessibility

  • When a url prop is provided, the card renders as a native <a> element, inheriting standard anchor accessibility semantics. Without a url, it renders as a <div>.
  • Set the type prop to 'button' to render the card as a <button> element when the card triggers an action rather than navigation.
  • Keyboard support: Enter activates the card when it has focus. The card has a tabindex="0" to be reachable via keyboard navigation.
  • Uses aria-disabled when the card is in a disabled state to communicate inaccessibility to screen readers.

API

anchor-card-clickable

Properties

PropertyAttributeDescriptionTypeDefault
alignalignText alignment of the card. Can be either 'center' or 'left'."center" | "left"'center'
iconSizeicon-sizeTo determine the icon size, defaults to medium."large" | "medium" | "small" | "xlarge" | "xsmall""medium"
showBordershow-borderWhether to show a border around the card.booleantrue
showIconshow-iconWhether to show an icon in the card.booleanfalse
targettargetThe target for the link."_blank" | "_parent" | "_self" | "_top"'_self'
typetypeOverrides the default element type of the card. By default, the card is rendered as an tag if a url prop is provided, or a
tag otherwise. Set this prop to 'button' to render the card as a
"button"undefined
urlurlWhere should the user go, when clicking on the card.anyundefined
variantvariantThe variant of the card. The variants "navigation" and "navigation-bold" are in WIP."default" | "navigation" | "navigation-bold""default"
verticalAlignvertical-alignContent alignment of the card. Can be either 'top', 'center' or 'bottom'."bottom" | "center" | "top"'top'

Events

EventDescriptionType
clickEventEvent emitted when the card is clicked.CustomEvent<any>

Shadow Parts

PartDescription
"icon"

CSS Custom Properties

NameDescription
--background-colorThe background color of the card. Defaults to the value of '--s-color-background-default-default'.
--border-colorThe color of the card's border. Defaults to the value of '--s-color-border-default'.
--border-radiusThe border radius of the card. Defaults to var(--s-size-radius-medium).
--border-widthThe width of the card's border. Defaults to var(--p-size-static-0125).
--focus-colorThe color of the card's border when it is in focus. Defaults to the value of '--color-border-outline'.
--focus-offsetThe offset applied to the card's focus border. Defaults to var(--p-size-static-025).
--icon-colorThe color of the icon within the card. Defaults to the value of '--color-icon-variant'.
--image-marginThe negative margin applied to the image slot. It is calculated as the negative value of the '--padding' variable.
--min-widthThe minimum width of the card. Defaults to 128px.
--paddingThe padding applied to the card's content area. Defaults to var(--p-size-static-300).
--shadowThe shadow effect applied to the card. Defaults to 'none'.
--text-colorThe color of the text content within the card. Defaults to the value of '--s-color-text-default'.
--widthThe width of the card. Defaults to 'unset'.

Dependencies

Depends on

Graph

graph TD;
  anchor-card --> anchor-icon
  style anchor-card fill:#f9f,stroke:#333,stroke-width:4px

Built with StencilJS

On this page