OverviewInstallationMigrating to 1.0Themes and layersKanok designCustomizingIconsForms and validationFrameworksUsing with AIButtonText inputText areaNumber inputSearchSelectDropdownComboboxMulti-selectCheckboxRadio buttonToggleDate pickerTime pickerSliderFile uploaderModalSide panelTearsheetNotificationToastTooltipDefinition tooltipPopoverToggletipMenuData tableStructured listPaginationContained listTree viewTabsBreadcrumbLinkPagination navContent switcherAccordionProgress indicatorUI shellTagTileCardProduct cardCode snippetCopy buttonUser avatarTruncated textListLoadingInline loadingProgress barSkeletonBadge indicatorStatus indicatorGridHeadingLayerAction setPage headerBig numberEdit in placeIntroductionText inputText areaNumber inputSearchSelectDropdownComboboxMulti-selectCheckboxRadio buttonToggleDate pickerTime pickerSliderFile uploaderTabsPagination navContent switcherTooltipDefinition tooltipPopoverMenuAccordionProgress indicatorUI shellModalSide panelTearsheetNotificationToastData tableStructured listPaginationTree viewCode snippetCopy buttonTruncated textLoadingTagCardProduct cardEdit in place
Layer
<ui-layer> is Carbon's Layer: everything inside it uses the theme's next layer set, so a field on a gray tile isn't the same gray as the tile. Fields, menus, borders, dividers and hover fills all follow it. The Themes and layers guide explains the layering model; this page shows the element.
HTMLReactReact + Tailwind<ui-text-inputlabel="On the page (field-01)"></ui-text-input>
<ui-layerlevel="1"with-backgroundstyle="padding: 16px">
<ui-text-inputlabel="Inside a layer (field-02)"></ui-text-input>
<ui-layerwith-backgroundstyle="padding: 16px; margin-top: 16px">
<ui-dropdownlabel="One level deeper (field-03)"placeholder="Choose a department">
<optionvalue="sales">Sales</option>
<optionvalue="legal">Legal</option>
</ui-dropdown>
</ui-layer>
</ui-layer><UiTextInputlabel="On the page (field-01)" />
<UiLayerlevel={1} withBackgroundstyle={{ padding:16 }}>
<UiTextInputlabel="Inside a layer (field-02)" />
<UiLayerwithBackgroundstyle={{ padding:16, marginTop:16 }}>
<UiDropdownlabel="One level deeper (field-03)"placeholder="Choose a department">
<optionvalue="sales">Sales</option>
<optionvalue="legal">Legal</option>
</UiDropdown>
</UiLayer>
</UiLayer><TextInputlabel="On the page (field-01)" />
<LayerwithBackgroundclassName="p-4">
<TextInputlabel="Inside a layer (field-02)" />
<LayerwithBackgroundclassName="mt-4 p-4">
<Dropdownlabel="One level deeper (field-03)"placeholder="Choose a department"items={[{ value:'sales', label:'Sales' }, { value:'legal', label:'Legal' }]} />
</Layer>
</Layer>
Installation
npmshadcn · Web componentshadcn · React + TailwindManualnpminstall@purpurabog/uinpxshadcn@4add@kanok-ui/layernpxshadcn@4add@kanok-ui/tw-layer# Web component# 1. Install the dependenciesnpminstalllit@^3.3.0# 2. Copy each file's "content" from# https://cdn.jsdelivr.net/npm/@purpurabog/ui@2.3.0/registry/layer.json# to its target:# components/ui/primitives/layer/layer-shift.styles.ts# components/ui/primitives/layer/layer.ts# 3. Do the same for the items it needs (registry/<name>.json):# shared-element, tokens# React + Tailwind# 1. Install the dependencies# (none)# 2. Copy each file's "content" from# https://cdn.jsdelivr.net/npm/@purpurabog/ui@2.3.0/registry/tw-layer.json# to its target:# components/ui/react-tw/layer.tsx# 3. Do the same for the items it needs (registry/<name>.json):# tw-theme, tw-utils
npm gives you every component from the package. shadcn copies the source into your app instead: a copy pinned to this version that you can change. The shadcn commands need the @kanok-ui registry in your components.json once, see Installation.
Use it
HTMLReactReact + Tailwind<scripttype="module">import'@purpurabog/ui/layer';</script>
<ui-layerlevel="1"with-background>
<ui-text-inputlabel="Field on a tile"></ui-text-input>
</ui-layer>import { UiLayer, UiTextInput } from'@purpurabog/ui/react';
<UiLayerlevel={1} withBackground>
<UiTextInputlabel="Field on a tile" />
</UiLayer>import { Layer } from'@/components/ui/react-tw/layer';
<LayerwithBackground>
<TextInputlabel="Field on a tile" />
</Layer>
Levels
level is 0, 1 or 2. Level 0 is the page's own set, the same as outside any layer; 1 and 2 go deeper. Without level, the web component and the React wrapper start at 0 and a nested layer goes one deeper, as Carbon's cds-layer. The React + Tailwind Layer follows Carbon React instead: it starts at 1.
A tile paints the current layer's color, but it doesn't change the layer of what is inside it. Put the fields in a layer one level up, so they stand out from the tile.
A layer on its own only changes the tokens for what is inside it; it paints nothing. with-background (withBackground) paints it with Carbon's layer background, the surface its content sits on. Leave it off when your own box (a tile, a panel) already paints the surface.
Everything that reads the layer tokens follows the layer: the list of a dropdown, the rows of a table, the dividers of a structured list, the hover fill of a ghost button.
Add another approver
HTMLReactReact + Tailwind<ui-layerlevel="1"with-backgroundstyle="padding: 16px">
<ui-dropdownlabel="Approver"placeholder="Choose an approver">
<optionvalue="somchai">Somchai K.</option>
<optionvalue="malee">Malee S.</option>
</ui-dropdown>
<divstyle="margin-top: 16px"><ui-buttonkind="ghost">Add another approver</ui-button></div>
</ui-layer><UiLayerlevel={1} withBackgroundstyle={{ padding:16 }}>
<UiDropdownlabel="Approver"placeholder="Choose an approver">
<optionvalue="somchai">Somchai K.</option>
<optionvalue="malee">Malee S.</option>
</UiDropdown>
<UiButtonkind="ghost">Add another approver</UiButton>
</UiLayer><LayerwithBackgroundclassName="p-4">
<Dropdownlabel="Approver"placeholder="Choose an approver"items={[{ value:'somchai', label:'Somchai K.' }, { value:'malee', label:'Malee S.' }]} />
<Buttonkind="ghost"className="mt-4">Add another approver</Button>
</Layer>
In a dark zone
A layer works inside any theme zone: it moves along that theme's layer sets. See Make a zone dark for the zone itself.
The element's level property holds its level, worked out or set. In React + Tailwind, useLayerLevel() returns the level of the closest Layer (-1 outside any), for your own components that paint by layer.
The web component works its level out when it is added to the page, through shadow roots too. Set level yourself if you move a layer somewhere else later.
Accessibility
A layer is only color. It has no role and adds nothing for screen readers.
Layers keep fields visible against the surface under them, which helps everyone see where to type. Don't rely on the layer color alone to tell areas apart; use headings and labels too.
API
Generated from the package. In React, pass a property as a prop of the same name; events are props too (the React column).
<ui-layer> · React UiLayer
Attributes
Attribute
Property
Type
Default
Description
level
level
0, 1 or 2. Computed from the nearest ancestor layer when not set.
with-background
withBackground
boolean
false
Paint the layer with Carbon's layer-background (withBackground): the colour its content sits on (white theme, level 1: #f4f4f4 under #ffffff fields).
Methods
Method
Description
syncLevel()
An automatic level follows the layer around it (also called by a layer whose level changed); a set one stays.
Slots
Slot
Description
(default)
Content
CSS parts
Part
Description
base
The wrapper
CSS custom properties
Custom property
Default
Description
--ui-layer-border
/ --ui-layer-radius - With with-background: its border and corner radius (default none, 0: Carbon's square, unbordered zone, Kanok too)