-
Notifications
You must be signed in to change notification settings - Fork 80
Tokens
Ali Stump edited this page Jul 5, 2024
·
7 revisions
Automated testing of component tokens may be done via the themed helper in commonTests.
desribe("theme", () => {
themed(`calcite-button`, {
"--calcite-button-background-color": {
shadowSelector: `.${CSS.button}`,
targetProp: "backgroundColor",
},
"--calcite-button-border-color": {
shadowSelector: `.${CSS.button}`,
targetProp: "borderColor",
}});
});
The themed helper accepts an object of tokens to test with the token name as the key
and accepts an object or array of objects as a value with the following properties...
/**
* The selector of the target element. When not provided, the component tag is used.
*/
selector?: string;
/**
* This selector will be used to find the target element within the shadow DOM of the component.
*/
shadowSelector?: string;
/**
* The CSSStyleDeclaration property to assert on.
*/
targetProp: CSSProp | MappedCalciteCSSCustomProp;
/**
* The state to apply to the target element.
*/
state?: State | RequireExactlyOne<Record<State, ContextSelectByAttr>, "focus" | "hover" | "press">;
Manual testing of component tokens should still be conducted when potential breaking changes are introduced.
- open the component's html demo page.
- add a new "theme-ing" section if one doesn't already exist.
- add a
<demo-theme>
component around the component(s) to test. - add all relevant component tokens to the
tokens
prop in a list. This will automatically generate some token values based on the name. - or add a
style
prop to eitherdemo-theme
or a specific component with the variable you want to test and a value.
<demo-theme tokens="
--calcite-button-background-color,
--calcite-button-border-color,
--calcite-button-corner-radius,
--calcite-button-corner-radius-start-start,
--calcite-button-corner-radius-start-end,
--calcite-button-corner-radius-end-start,
--calcite-button-corner-radius-end-end,
--calcite-button-loader-color,
--calcite-button-shadow,
--calcite-button-text-color,
--calcite-button-icon-color"
><calcite-button kind="inverse" scale="l"> Button </calcite-button></demo-theme>
<calcite-button kind="inverse" scale="l" style="--calcite-button-background-color: var(--calcite-color-info); --calcite-button-border-color: green; "> Button </calcite-button>