Style configuration
Choose your app's default look in one place: filled or outlined fields, dense or roomy lists, text or filled buttons, and whether touch targets take up layout space. Every component you don't set by hand follows it.
Style configuration in depth
What you can change
Any variant, size, or density you don't set on a component comes from the style configuration. Set that value once for the whole app:
- Outlined fields across a form-heavy app. Set
defaultFieldVarianttoOutlined. - A denser data-entry or admin screen. Set
defaultFieldDensity,defaultListDensity,defaultMenuDensity, anddefaultTableDensityto one ofDense1toDense4, whereDense4is the tightest. - Filled buttons as the house style. Set
defaultButtonVarianttoFilled. - A compact mode the user switches on. Change the density settings while the app runs. Components already on the page update to match.
- Touch targets that take up layout space. Set
defaultTouchTargettoWrapper.
The style configuration chooses a component's variant, size, and density. Colors, corners, and type within that choice come from theming.
Which value a component uses
- An attribute on the component wins. A component uses its own attribute first, then the style configuration, then Chameleon's default. To give one part of the page a different look, set the attribute on the components in that part.
- An attribute set to a value the setting doesn't list counts as unset, so a field with
variant="invalid-value"falls back to the style configuration. - Reduced motion overrides every animation setting. When the user's system asks for reduced motion, dialogs and popovers open and close without animating, whatever their own attribute or the style configuration says.
- Filled fields hide their label at
Dense2and tighter, because there's no room for it to float into. Pair dense fields withOutlinedto keep labels.
Before the library loads
Put style configuration classes on <body>, and the components listed below appear at your configured size before the library loads, so they don't move the page as they render. Link the stylesheet in the <head> as well, as Installation describes.
<body class="ct-button-size-large ct-field-density-2">
A class is ct-, then the setting's name without default in kebab case, then the value:
ct-button-size-largesetsdefaultButtonSizetoLarge.ct-chip-size-extra-smallsetsdefaultChipSizetoExtraSmall.ct-field-density-2setsdefaultFieldDensitytoDense2. Density values are digits:0isStandard, and1to4areDense1toDense4.
Eight settings have classes. Six of them size these components before the library loads:
defaultButtonSize: buttons and toggle buttonsdefaultIconButtonSize: icon buttons and toggle icon buttonsdefaultSliderSize: sliders, range sliders, and dialsdefaultChipSize: assist, filter, input, and suggestion chipsdefaultFieldDensity: text, email, number, password, search, and telephone fields, selects, and text areasdefaultListDensity: lists
The other two, defaultMenuDensity and defaultTableDensity, take effect when the library loads.
- The library reads the classes as your style configuration when it loads, and follows changes to them after that.
setStyleConfiguration()still works and updates the classes to match. - An attribute on the component still wins. A button with
size="small"stays small on a page whose<body>carriesct-button-size-large, before and after the library loads. <body>wins over<html>. The classes also work on<html>, but a class on<html>applies only while<body>carries none of that setting's classes, before and after the library loads.setStyleConfiguration()writes its classes on<html>, so put your own on<body>.
The Web components, React, and Blazor tabs show where to put the classes in each kind of app.
Settings
The table spells names as JavaScript does; in Blazor each starts with a capital letter, such as DefaultButtonVariant. Each value belongs to the enum named in the Values column.
Fields, lists, menus, and tables
These are the settings you're most likely to change.
| Setting | Values | Default | Applies to |
|---|---|---|---|
defaultFieldVariant |
FieldVariant: Filled, Outlined, Text |
Filled |
Text fields, text areas, number, email, password, search, and telephone fields, and selects |
defaultFieldDensity |
Density: Standard, Dense1, Dense2, Dense3, Dense4 |
Standard |
The same fields as defaultFieldVariant |
defaultListDensity |
Density: Standard, Dense1, Dense2, Dense3, Dense4 |
Standard |
Lists |
defaultMenuDensity |
Density: Standard, Dense1, Dense2, Dense3, Dense4 |
Standard |
Menus and sub-menus |
defaultTableDensity |
Density: Standard, Dense1, Dense2, Dense3, Dense4 |
Standard |
Data grids and data tables |
defaultTableVariant |
TableVariant: Standard, Surface |
Standard |
Data grids and data tables |
defaultTableCaptionPosition |
CaptionPosition: Leading, Trailing |
Leading |
Data grids and data tables |
Buttons, chips, cards, and sliders
| Setting | Values | Default | Applies to |
|---|---|---|---|
defaultButtonVariant |
ButtonVariant: Elevated, Filled, Tonal, Outlined, Text |
Text |
Buttons and toggle buttons |
defaultButtonSize |
Size: ExtraSmall, Small, Medium, Large, ExtraLarge |
Small |
Buttons and toggle buttons |
defaultIconButtonVariant |
IconButtonVariant: Filled, Outlined, Standard, Tonal |
Filled |
Icon buttons and toggle icon buttons |
defaultIconButtonSize |
Size: ExtraSmall, Small, Medium, Large, ExtraLarge |
Small |
Icon buttons and toggle icon buttons |
defaultIconButtonWidth |
IconButtonWidth: Narrow, Regular, Wide |
Regular |
Icon buttons and toggle icon buttons |
defaultFABMenuVariant |
FABMenuVariant: Primary, Secondary, Tertiary |
Primary |
Floating action button (FAB) menus |
defaultChipVariant |
ChipVariant: Elevated, Outlined |
Outlined |
Assist, filter, and suggestion chips |
defaultChipSize |
ChipSize: Small, ExtraSmall |
Small |
Every chip |
defaultCardVariant |
CardVariant: Elevated, Filled, Outlined |
Outlined |
Cards and action cards |
defaultSliderSize |
Size: ExtraSmall, Small, Medium, Large, ExtraLarge |
ExtraSmall |
Sliders, range sliders, and dials |
Touch targets
| Setting | Values | Default | Applies to |
|---|---|---|---|
defaultTouchTarget |
TouchTarget: None, Overflow, Wrapper |
Overflow |
Buttons, icon buttons, FABs, chips, checkboxes, radio buttons, switches, sliders, dials, list items, and action cards |
The setting decides what happens when a control is smaller than 48 by 48 pixels:
Overflowextends the area that responds to touch and the mouse beyond the control's visible edge, without changing the layout.Wrapperadds space around the control, so it takes up the full 48 by 48 pixels in the layout.Nonelimits the area to the visible control. Don't use it unless your layout already guarantees large enough targets.
Rarely changed
These set motion, loading indicators, scroll indicators, and tooltip placement.
| Setting | Values | Default | Applies to |
|---|---|---|---|
defaultDialogAnimation |
DialogAnimation: Fade, None, Slide |
Fade |
Dialogs |
defaultPopoverAnimation |
PopoverAnimation: None, Fade, FadedSlide, Expand |
FadedSlide |
Popovers, menus, sub-menus, selects, and FAB menus |
defaultScrollIndicator |
ScrollIndicator: Divider, None, Shadow |
Shadow |
Dialogs and scroll regions |
defaultTooltipPosition |
TooltipPosition: StartStart, StartCenter, StartEnd, CenterStart, CenterEnd, EndStart, EndCenter, EndEnd |
EndCenter |
Plain and rich tooltips |
defaultSkeletonVariant |
SkeletonVariant: Regular, Text |
Regular |
Skeletons |
defaultSkeletonAnimation |
SkeletonAnimation: None, Pulse, Wave |
Wave |
Skeletons |
defaultProgressTrackThickness |
ProgressTrackThickness: Standard, Thick |
Standard |
Linear and circular progress indicators |
defaultProgressWaveShape |
ProgressWaveShape: Flat, Wavy |
Flat |
Linear and circular progress indicators |
defaultProgressTrackShape |
ProgressTrackShape: Circle, SoftSquircle, Squircle |
Circle |
Circular progress indicators |
Set your defaults
Call setStyleConfiguration() once in your app's entry point, naming only the settings you change.
import { ButtonVariant, Density, FieldVariant, setStyleConfiguration } from "@materia-technologies-inc/chameleon-components-web";
setStyleConfiguration({
defaultButtonVariant: ButtonVariant.Filled,
defaultFieldVariant: FieldVariant.Outlined,
defaultFieldDensity: Density.Dense1,
});
Change them while the app runs
Call setStyleConfiguration() again with the settings to change. Settings you leave out keep their values, and components already on the page update to match.
import { Density, setStyleConfiguration } from "@materia-technologies-inc/chameleon-components-web";
function setCompactMode(compact) {
setStyleConfiguration({ defaultFieldDensity: compact ? Density.Dense3 : Density.Standard });
}
To return a setting to Chameleon's default, set it to "DEFAULT". getStyleConfiguration() returns the settings as you've set them, with "DEFAULT" for each one you haven't.
Set sizes in markup
Eight settings also take a class on your page's <body>: defaultButtonSize, defaultIconButtonSize, defaultChipSize, defaultSliderSize, defaultFieldDensity, defaultListDensity, defaultMenuDensity, and defaultTableDensity. Each class is ct-<setting>-<value>: the setting without default, in kebab case, then the value as the component's attribute spells it. Size.Large for defaultButtonSize is ct-button-size-large, and Density.Dense4 for defaultFieldDensity is ct-field-density-4.
The class is in the page before any script runs. With the stylesheet linked in the head, buttons, icon buttons, chips, sliders, dials, lists, and the fields defaultFieldDensity applies to appear at the class's size from the first paint. They keep that size when the library loads. Menu and table densities take effect when the library loads. A component's own size or density attribute wins over the class.
In a plain page
Put the classes on <body> in your index.html, with the stylesheet linked in the head. Here the first button and the first field follow the classes, and the others keep their own attributes.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="chameleon.css">
</head>
<body class="ct-button-size-large ct-field-density-4">
<cw-button>Large</cw-button>
<cw-button size="small">Small</cw-button>
<cw-text-field label="Dense"></cw-text-field>
<cw-text-field label="Standard" density="0"></cw-text-field>
</body>
</html>
The class also works on <html>, but <body> wins: a class on <html> applies only while <body> carries none of that setting's classes. So <body class="ct-field-density-0"> beats <html class="ct-field-density-3"> for a field with no density attribute, before and after the library loads.
Keep them in step
Call setStyleConfiguration() at run time as before, and it keeps the classes in step. It puts a setting's new class on <html>, unless <body> already carries that class, and removes the setting's other classes from <html> and <body>. A setting set to "DEFAULT" loses all its classes. The library also follows the classes on <html> and <body>. Add one, and the setting changes to match. Remove one, and the setting returns to "DEFAULT", unless setStyleConfiguration() gave the setting a value: then the library puts that value's class back on <html>.
Set your defaults
Call setStyleConfiguration() in your entry point, before the first render, naming only the settings you change.
import { createRoot } from "react-dom/client";
import { ButtonVariant, FieldVariant, setStyleConfiguration } from "@materia-technologies-inc/chameleon-components-react";
import { App } from "./App";
setStyleConfiguration({
defaultButtonVariant: ButtonVariant.Filled,
defaultFieldVariant: FieldVariant.Outlined,
});
createRoot(document.getElementById("root")!).render(<App />);
In a Next.js layout
Eight settings can also come from classes on <body>: the button, icon button, chip, and slider sizes, and the field, list, menu, and table densities. With the classes in the page's markup, the settings hold from the first render. For all but the menu and table densities, a component that sets no size or density of its own also takes the configured one from the first paint, before Chameleon's scripts load. A component's own size or density attribute still wins.
Write the classes on <body> in your root layout, app/layout.tsx. Each class is ct-<setting>-<value>: the setting without default, in kebab case, then the value as the component's attribute spells it, so Size.Medium for defaultButtonSize is ct-button-size-medium and Density.Dense2 for defaultFieldDensity is ct-field-density-2.
import type { ReactNode } from "react";
export default function RootLayout({ children }: { children: ReactNode }) {
return (
<html lang="en">
<body className="ct-button-size-medium ct-field-density-2">{children}</body>
</html>
);
}
Use the same values the app passes to setStyleConfiguration(). If the classes and the call disagree, the setting changes to the call's value when setStyleConfiguration() runs.
Change them while the app runs
Call setStyleConfiguration() again, from an event handler for instance, with the settings to change. Settings you leave out keep their values. Components already on the page update to match, with no state or re-render on your side.
To return a setting to Chameleon's default, set it to "DEFAULT". getStyleConfiguration() returns the settings as you've set them, with "DEFAULT" for each one you haven't.
Set your defaults
Set options.StyleConfiguration where you register Chameleon's services, in Program.cs. Settings you don't name keep Chameleon's defaults.
using Chameleon.Blazor;
builder.Services.AddChameleonServices(options =>
{
options.StyleConfiguration = new()
{
DefaultButtonVariant = ButtonVariant.Filled,
DefaultFieldVariant = FieldVariant.Outlined,
DefaultFieldDensity = Density.Dense1,
};
});
Set them in markup
Put the configuration's classes on <body> in App.razor, and most components appear at your configured size and density from the first paint, before Chameleon's scripts run. StyleConfigurationClasses.For(), in the Chameleon.Blazor namespace, returns the classes. Inject IChameleonConfigurationService and pass its StyleConfiguration, which is the configuration you gave AddChameleonServices.
@using Chameleon.Blazor
@inject IChameleonConfigurationService ChameleonConfiguration
<!DOCTYPE html>
<html lang="en">
<head>
@* Chameleon's stylesheet and scripts, as Installation describes *@
<HeadOutlet />
</head>
<body class="@StyleConfigurationClasses.For(ChameleonConfiguration.StyleConfiguration)">
<Routes />
<script src="_framework/blazor.web.js"></script>
</body>
</html>
With the configuration above, <body> gets ct-field-density-1. Eight settings have classes: the button, icon button, chip, and slider sizes, and the field, list, menu, and table densities. No other setting has one.
Before the scripts run, the classes size buttons, icon buttons, chips, sliders, dials, text fields, selects, text areas, and lists. Menus and tables take their density once the scripts run. A component's own size or density wins over the class. Before the library loads lists each setting's components.
Pass the configuration the services hold. A class that disagrees with the services changes to the services' value once they start.
Change them while the app runs
Inject IChameleonConfigurationService and assign its StyleConfiguration a copy of the current one, made with a with expression. Components already on the page update to match.
@inject IChameleonConfigurationService ChameleonConfiguration
@code {
private void UseCompactFields()
{
ChameleonConfiguration.StyleConfiguration = ChameleonConfiguration.StyleConfiguration with
{
DefaultFieldDensity = Density.Dense3,
};
}
}
The with expression keeps your other settings. Assigning a new() configuration resets every setting it doesn't name to Chameleon's default.
To return a setting to Chameleon's default, set it to Default.UseDefault.