Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rating): add component tokens #11150

Merged
merged 11 commits into from
Jan 7, 2025
12 changes: 12 additions & 0 deletions packages/calcite-components/src/components/rating/rating.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ import {
reflects,
renders,
t9n,
themed,
} from "../../tests/commonTests";
import { html } from "../../../support/formatting";
import { isElementFocused } from "../../tests/utils";
import { CSS } from "./resources";

describe("calcite-rating", () => {
describe("common tests", () => {
Expand Down Expand Up @@ -795,4 +798,13 @@ describe("calcite-rating", () => {
expect(element).toEqualAttribute("value", "2");
});
});

describe("theme", () => {
themed(html`<calcite-rating></calcite-rating>`, {
"--calcite-rating-idle-unselected-color": {
shadowSelector: `.${CSS.star}`,
targetProp: "color",
},
});
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add tests for the other vars?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added tests for the other tokens. I'm having issues testing --calcite-rating-spacing, could you please take a look?
cc @driskull @alisonailea

});
26 changes: 16 additions & 10 deletions packages/calcite-components/src/components/rating/rating.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
*
* These properties can be overridden using the component's tag as selector.
*
* @prop --calcite-rating-spacing-unit: The amount of left and right margin spacing between each rating star.
* @prop --calcite-rating-spacing-unit: Specifies the amount of left and right margin spacing between each item.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deprecate in favor of --calcite-rating-spacing

* @prop --calcite-rating-selected-color-hover: Specifies the component's item color when hovered or selected.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--calcite-rating-color-hover

* @prop --calcite-rating-color: Specifies the component's item color.
* @prop --calcite-rating-average-color: Specifies the component's item color when average is set.
* @prop --calcite-rating-average-text-color: Specifies the component's average text color.
* @prop --calcite-rating-count-text-color: Specifies the component's count text color.
*/

:host {
Expand All @@ -15,17 +20,17 @@

:host([scale="s"]) {
@apply h-6;
--calcite-rating-spacing-unit: theme("spacing.1");
--spacing: theme("spacing.1");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tokens should not be assigned in the component unless they are tagged with -internal-

}

:host([scale="m"]) {
@apply h-8;
--calcite-rating-spacing-unit: theme("spacing.2");
--spacing: theme("spacing.2");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tokens should not be assigned in the component unless they are tagged with -internal-

}

:host([scale="l"]) {
@apply h-11;
--calcite-rating-spacing-unit: theme("spacing.3");
--spacing: theme("spacing.3");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tokens should not be assigned in the component unless they are tagged with -internal-

}

:host([read-only]) {
Expand All @@ -38,7 +43,7 @@
border-width: 0;
padding: 0;
align-items: center;
gap: var(--calcite-rating-spacing-unit);
gap: var(--calcite-rating-spacing-unit, var(--spacing));
}

.wrapper {
Expand All @@ -51,20 +56,20 @@
display: flex;
flex-direction: column;
cursor: pointer;
color: theme("borderColor.color.input");
color: var(--calcite-rating-color, theme("borderColor.color.input"));
&:focus {
@apply focus-outset;
}
}

.average,
.fraction {
color: theme("colors.warning");
color: var(--calcite-rating-average-color, theme("colors.warning"));
}

.hovered,
.selected {
color: theme("colors.brand");
color: var(--calcite-rating-selected-color-hover, theme("colors.brand"));
}

.fraction {
Expand All @@ -84,13 +89,14 @@ calcite-chip {

.number--average {
font-weight: bold;
color: var(--calcite-rating-average-text-color);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the purpose of this token?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It sets the average text color, I set it to purple in this example. Should I remove this token?

image

}

.number--count {
color: var(--calcite-color-text-2);
color: var(--calcite-rating-count-text-color, var(--calcite-color-text-2));
font-style: italic;
&:not(:first-child) {
margin-inline-start: var(--calcite-rating-spacing-unit);
margin-inline-start: var(--calcite-rating-spacing-unit, var(--spacing));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
export const CSS = {
star: "star",
};

export const IDS = {
validationMessage: "validationMessage",
};
4 changes: 3 additions & 1 deletion packages/calcite-components/src/custom-theme.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { pagination } from "./custom-theme/pagination";
import { popover, popoverTokens } from "./custom-theme/popover";
import { progress, progressTokens } from "./custom-theme/progress";
import { segmentedControl } from "./custom-theme/segmented-control";
import { rating, ratingTokens } from "./custom-theme/rating";
import { slider, sliderTokens } from "./custom-theme/slider";
import { switchTokens } from "./custom-theme/switch";
import { tabs, tabsBordered, tabsTokens } from "./custom-theme/tabs";
Expand Down Expand Up @@ -132,7 +133,7 @@ const kitchenSink = (args: Record<string, string>, useTestValues = false) =>
${avatarInitials} ${avatarThumbnail} ${progress} ${handle} ${textArea} ${popover} ${tile} ${tooltip}
${comboboxItem}
</div>
<div class="demo-column">${navigation} ${navigationLogos} ${navigationUsers} ${blockSection}</div>
<div class="demo-column">${navigation} ${navigationLogos} ${navigationUsers} ${blockSection} ${rating}</div>
<div class="demo-column">${alert}</div>
</div>
</div>`;
Expand Down Expand Up @@ -164,6 +165,7 @@ const componentTokens = {
...navigationUserTokens,
...popoverTokens,
...progressTokens,
...ratingTokens,
...sliderTokens,
...switchTokens,
...tabsTokens,
Expand Down
12 changes: 12 additions & 0 deletions packages/calcite-components/src/custom-theme/rating.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { html } from "../../support/formatting";

export const ratingTokens = {
calciteRatingSpacingUnit: "",
calciteRatingHoverSelectedColor: "",
calciteRatingIdleUnselectedColor: "",
calciteRatingAverageColor: "",
calciteRatingAverageTextColor: "",
calciteRatingCountColor: "",
};

export const rating = html`<calcite-rating></calcite-rating>`;
Loading