Skip to main content
Light Dark System

Tag

<ol-tag> | OlTag
Since 1.0 stable

Tags are used as labels to organize things or to indicate a selection.

Primary Success Neutral Warning Danger
<ol-tag variant="primary">Primary</ol-tag>
<ol-tag variant="success">Success</ol-tag>
<ol-tag variant="neutral">Neutral</ol-tag>
<ol-tag variant="warning">Warning</ol-tag>
<ol-tag variant="danger">Danger</ol-tag>
import OlTag from '@onlive.site/ui/dist/react/tag';

const App = () => (
  <>
    <OlTag variant="primary">Primary</OlTag>
    <OlTag variant="success">Success</OlTag>
    <OlTag variant="neutral">Neutral</OlTag>
    <OlTag variant="warning">Warning</OlTag>
    <OlTag variant="danger">Danger</OlTag>
  </>
);

Examples

Sizes

Use the size attribute to change a tag’s size.

Small Medium Large
<ol-tag size="small">Small</ol-tag>
<ol-tag size="medium">Medium</ol-tag>
<ol-tag size="large">Large</ol-tag>
import OlTag from '@onlive.site/ui/dist/react/tag';

const App = () => (
  <>
    <OlTag size="small">Small</OlTag>
    <OlTag size="medium">Medium</OlTag>
    <OlTag size="large">Large</OlTag>
  </>
);

Pill

Use the pill attribute to give tags rounded edges.

Small Medium Large
<ol-tag size="small" pill>Small</ol-tag>
<ol-tag size="medium" pill>Medium</ol-tag>
<ol-tag size="large" pill>Large</ol-tag>
import OlTag from '@onlive.site/ui/dist/react/tag';

const App = () => (
  <>
    <OlTag size="small" pill>
      Small
    </OlTag>
    <OlTag size="medium" pill>
      Medium
    </OlTag>
    <OlTag size="large" pill>
      Large
    </OlTag>
  </>
);

Removable

Use the removable attribute to add a remove button to the tag.

Small Medium Large
<div class="tags-removable">
  <ol-tag size="small" removable>Small</ol-tag>
  <ol-tag size="medium" removable>Medium</ol-tag>
  <ol-tag size="large" removable>Large</ol-tag>
</div>

<script>
  const div = document.querySelector('.tags-removable');

  div.addEventListener('ol-remove', event => {
    const tag = event.target;
    tag.style.opacity = '0';
    setTimeout(() => (tag.style.opacity = '1'), 2000);
  });
</script>

<style>
  .tags-removable ol-tag {
    transition: var(--ol-transition-medium) opacity;
  }
</style>
import OlTag from '@onlive.site/ui/dist/react/tag';

const css = `
  .tags-removable ol-tag {
    transition: var(--ol-transition-medium) opacity;
  }
`;

const App = () => {
  function handleRemove(event) {
    const tag = event.target;
    tag.style.opacity = '0';
    setTimeout(() => (tag.style.opacity = '1'), 2000);
  }

  return (
    <>
      <div className="tags-removable">
        <OlTag size="small" removable onOlRemove={handleRemove}>
          Small
        </OlTag>

        <OlTag size="medium" removable onOlRemove={handleRemove}>
          Medium
        </OlTag>

        <OlTag size="large" removable onOlRemove={handleRemove}>
          Large
        </OlTag>
      </div>

      <style>{css}</style>
    </>
  );
};

Importing

If you’re using the autoloader or the traditional loader, you can ignore this section. Otherwise, feel free to use any of the following snippets to cherry pick this component.

Script Import Bundler React

To import this component from the CDN using a script tag:

<script type="module" src="https://cdn.onlive.site/@onlive.site/ui@1.8.20/cdn/components/tag/tag.js"></script>

To import this component from the CDN using a JavaScript import:

import 'https://cdn.onlive.site/@onlive.site/ui@1.8.20/cdn/components/tag/tag.js';

To import this component using a bundler:

import '@onlive.site/ui/dist/components/tag/tag.js';

To import this component as a React component:

import OlTag from '@onlive.site/ui/dist/react/tag';

Slots

Name Description
(default) The tag’s content.

Learn more about using slots.

Properties

Name Description Reflects Type Default
variant The tag’s theme variant. 'primary' | 'success' | 'neutral' | 'warning' | 'danger' | 'text' 'neutral'
size The tag’s size. 'small' | 'medium' | 'large' 'medium'
pill Draws a pill-style tag with rounded edges. boolean false
removable Makes the tag removable and shows a remove button. boolean false
updateComplete A read-only promise that resolves when the component has finished updating.

Learn more about attributes and properties.

Events

Name React Event Description Event Detail
ol-remove onOlRemove Emitted when the remove button is activated. -

Learn more about events.

Parts

Name Description
base The component’s base wrapper.
content The tag’s content.
remove-button The tag’s remove button, an <ol-icon-button>.
remove-button__base The remove button’s exported base part.

Learn more about customizing CSS parts.

Dependencies

This component automatically imports the following dependencies.

  • <ol-icon>
  • <ol-icon-button>