TaxonomyTags
Displays taxonomy terms as styled tags. Uses Tag design system when tagClassName is passed; otherwise uses button variants.
Props
| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
taxonomies | Taxonomy[] | No | - | Taxonomies as Taxonomy objects (from Contentstack) |
terms | string[] | No | - | Taxonomies as string array (already extracted term_uids) |
cslp | CSLPFieldMapping | No | - | CSLP mapping for editable fields |
className | string | No | '' | Additional CSS classes for container |
tagClassName | string | No | - | CSS classes for each tag (e.g. tagVariants({ variant: 'taxonomyTag' }) from atoms/Tag) |
variant | ButtonVariant | No | 'PrimaryFillButton' | Button variant to use for tags |
size | ButtonSize | No | 'sm' | Size variant for tags |
interactive | boolean | No | false | Whether tags are clickable (removes cursor-pointer) |
getHref | (termUid: string) => string | No | - | Callback to generate href for each tag when interactive |
Usage
import TaxonomyTags from '@/components/molecules/TaxonomyTags';
import { tagVariants } from '@/components/atoms/Tag';
// Basic usage (non-interactive spans)
<TaxonomyTags
terms={['react', 'nextjs', 'typescript']}
/>
// With different variant
<TaxonomyTags
terms={terms}
variant="SecondaryFillButton"
size="default"
/>
// Taxonomy tag style (design system)
<TaxonomyTags
terms={terms}
tagClassName={tagVariants({ variant: 'taxonomyTag' })}
/>
// Interactive internal links (uses Next.js Link)
<TaxonomyTags
terms={terms}
interactive
getHref={(term) => `/tags/${term}`}
/>
// Interactive external links (uses anchor tag)
<TaxonomyTags
terms={terms}
interactive
getHref={(term) => `https://example.com/tags/${term}`}
/>Features
- Tag or button styling: Uses Tag design system when
tagClassNameprovided; otherwise button variants - Flexible input: Accepts either Taxonomy objects or string arrays
- Non-interactive by default: Renders as spans with
cursor-default - Smart link handling:
- Internal links (starting with
/) use Next.jsLinkfor client-side navigation - External links use anchor tags with
target="_blank"andrel="noopener noreferrer"
- Internal links (starting with
- Design system: Tag design system (via
tagClassName) or button variants and sizes
Link Behavior
- Internal links (
/tags/react): Renders as Next.jsLinkcomponent for optimized client-side navigation - External links (
https://example.com): Renders as<a>tag with proper security attributes - Non-interactive: Renders as
<span>elements
Notes
- Returns
nullif no terms are provided - Term UIDs are formatted for display via
formatTaxonomyTermLabel(underscores → spaces) - Uses
extractTaxonomyTermsutility to extract terms from Taxonomy objects - When
interactiveisfalse, addscursor-defaultto override button'scursor-pointer - Default size is
'sm'for tag-like appearance - Overrides padding with
py-1for compact tag styling - Internal links are detected by checking if href starts with
/ - External links automatically open in new tab with security attributes