Skip to content

Commit

Permalink
test(segmented-control, segmented-control-item): add component token …
Browse files Browse the repository at this point in the history
…E2E tests (#9592)

**Related Issue:** #7180

## Summary

✨🧪✨
  • Loading branch information
jcfranco authored Jun 18, 2024
1 parent 63c4c0f commit 5626ed8
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { newE2EPage } from "@stencil/core/testing";
import { renders, hidden } from "../../tests/commonTests";
import { renders, hidden, themed } from "../../tests/commonTests";
import { html } from "../../../support/formatting";
import { CSS } from "./resources";

describe("calcite-segmented-control-item", () => {
Expand Down Expand Up @@ -107,4 +108,43 @@ describe("calcite-segmented-control-item", () => {
expect(element).not.toHaveAttribute("icon-end");
});
});

describe("theme", () => {
describe("default", () => {
themed("calcite-segmented-control-item", {
"--calcite-segmented-control-item-background-color": {
targetProp: "backgroundColor",
},
"--calcite-segmented-control-item-border-color": {
shadowSelector: `.${CSS.label}`,
targetProp: "borderColor",
},
"--calcite-segmented-control-item-text-color": {
shadowSelector: `.${CSS.label}`,
targetProp: "color",
},
});
});

describe("checked", () => {
themed(
html`<calcite-segmented-control-item checked appearance="outline-fill"></calcite-segmented-control-item>`,
{
"--calcite-segmented-control-item-border-color": {
shadowSelector: `.${CSS.label}`,
targetProp: "borderColor",
},
},
);
});

describe("with icon", () => {
themed(html`<calcite-segmented-control-item icon-start="3d-glasses">3d!</calcite-segmented-control-item>`, {
"--calcite-segmented-control-item-icon-color": {
shadowSelector: `.${CSS.icon}`,
targetProp: "--calcite-icon-color",
},
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
*
* @prop --calcite-segmented-control-item-background-color: Specifies the background color of the component.
* @prop --calcite-segmented-control-item-border-color: Specifies the border color of the component.
* @prop --calcite-segmented-control-item-focus: Specifies the focus color of the component.
* @prop --calcite-segmented-control-item-icon-color: Specifies the icon color of the component.
* @prop --calcite-segmented-control-item-shadow: Specifies the shadow of the component.
* @prop --calcite-segmented-control-item-text-color: Specifies the text color of the component.
*/

:host {
display: flex;
@apply focus-base;
cursor: pointer;
align-self: stretch;
font-weight: var(--calcite-font-weight-normal);
Expand Down Expand Up @@ -42,11 +40,8 @@
}

:host(:focus) {
--calcite-internal-segmented-control-item-focus-offset: -1px;
@include focusInset(
"--calcite-segmented-control-item-focus",
"--calcite-internal-segmented-control-item-focus-offset"
);
@apply focus-inset;
outline-offset: -1px;
}

.label--scale-s {
Expand Down Expand Up @@ -79,19 +74,29 @@
background-color: var(--calcite-segmented-control-item-background-color, var(--calcite-color-foreground-3));
}

:host([checked]) label {
background-color: var(--calcite-segmented-control-item-background-color, var(--calcite-color-brand));
border-color: var(calcite-segmented-control-item-border-color, var(--calcite-color-brand));
cursor: default;
color: var(--calcite-segmented-control-item-text-color, var(--calcite-color-text-inverse));
:host([checked]) {
label {
background-color: var(--calcite-segmented-control-item-background-color, var(--calcite-color-brand));
border-color: var(calcite-segmented-control-item-border-color, var(--calcite-color-brand));
cursor: default;
color: var(--calcite-segmented-control-item-text-color, var(--calcite-color-text-inverse));
}

.icon {
--calcite-icon-color: var(--calcite-segmented-control-item-icon-color, var(--calcite-color-text-inverse));
}
}

:host([checked]) .label--outline,
:host([checked]) .label--outline-fill {
background-color: var(--calcite-segmented-control-item-background-color, var(--calcite-color-foreground-1));
border-color: var(calcite-segmented-control-item-border-color, var(--calcite-color-brand));
border-color: var(--calcite-segmented-control-item-border-color, var(--calcite-color-brand));
color: var(--calcite-segmented-control-item-text-color, var(--calcite-color-brand));
box-shadow: var(--calcite-segmented-control-item-shadow, inset 0 0 0 1px var(--calcite-color-brand));
box-shadow: inset 0 0 0 1px var(--calcite-segmented-control-item-border-color, var(--calcite-color-brand));

.icon {
--calcite-icon-color: var(--calcite-segmented-control-item-icon-color, var(--calcite-color-brand));
}
}

:host([checked]) .label--outline {
Expand Down Expand Up @@ -121,6 +126,8 @@
inline-flex;
line-height: inherit;

--calcite-icon-color: var(--calcite-segmented-control-item-icon-color, var(--calcite-color-text-3));

margin-inline-start: var(--calcite-internal-segmented-control-icon-margin-start);
margin-inline-end: var(--calcite-internal-segmented-control-icon-margin-end);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import {
labelable,
reflects,
renders,
themed,
} from "../../tests/commonTests";
import { CSS } from "./resources";

describe("calcite-segmented-control", () => {
describe("defaults", () => {
Expand Down Expand Up @@ -433,4 +435,19 @@ describe("calcite-segmented-control", () => {
describe("updates items when children are modified after initialization", () => {
// TODO:
});

describe("theme", () => {
describe("default", () => {
themed("calcite-segmented-control", {
"--calcite-segmented-control-background-color": {
shadowSelector: `.${CSS.itemWrapper}`,
targetProp: "backgroundColor",
},
"--calcite-segmented-control-border-color": {
shadowSelector: `.${CSS.itemWrapper}`,
targetProp: "outline",
},
});
});
});
});

0 comments on commit 5626ed8

Please sign in to comment.