Marigold
Getting StartedFoundationsComponentsPatternsRecipesReleases
Discover new Tutorials!

Components

Overview

Application

MarigoldProvider
updated
RouterProvider
updated

Layout

Aside
Aspect
Breakout
Center
Columns
Container
Grid
Inline
Inset
Scrollable
Split
Stack
updated
Tiles

Form

Autocomplete
Button
updated
Calendar
Checkbox
ComboBox
DateField
DatePicker
Form
Multiselect
new
NumberField
Radio
SearchField
Select
Slider
Switch
TextArea
TextField
TimeField
new

Collection

SelectList
updated
Table
updated
Tag

Navigation

Accordion
Breadcrumbs
beta
Pagination
Tabs

Overlay

ContextualHelp
new
Dialog
Menu
Toast
beta
Tooltip
updated

Content

Badge
Body
Card
Divider
updated
Footer
Header
Headline
updated
Icon
updated
Image
Link
updated
List
updated
SectionMessage
SVG
updated
Text
updated
VisuallyHidden
updated
XLoader

Formatters

DateFormat
NumericFormat

Hooks and Utils

cn
cva
extendTheme
useAsyncListData
useListData
useResponsiveValue
useTheme

cn

Helper that combines classnames together.

To combine Tailwind CSS classes with other classes, utilize the cn function within the className attribute to merge them seamlessly. The inputs of the className accept nearly every type. The function itself uses tailwind-merge which is a utility function to easily merge the given tailwind classes. We also use cx function from cva, which combines the class names together. You can pass in arrays, boolean conditions, strings or numbers.

Import

import { cn } from '@marigold/system';

Examples

Conditionally apply classnames

In this example you can see how to use the cn function on a <div> element. Here are written down some Tailwind CSS class names which will be merged with the ones before. So in the end the class names will be rendered (if myValue will be true) as className='flex flex-col cursor-pointer p-4'

const myOtherValue = 'p-4'
...
<div
  className={cn(
    'flex flex-col p-3',
    myValue ? 'cursor-pointer' : 'cursor-not-allowed',
    myOtherValue
  )}
/>

In this code you can see that p-3 will be overwritten by p-4, so keep in mind the order of your class names.

Last update: April 30, 2024
Build with 🥵, 🧡 and
v14.1.1