Skip to content

Commit 11d83f6

Browse files
aPreciado88benelan
authored andcommitted
feat(rating): enhance component's interactivity states (#11469)
**Related Issue:** [#10015](#10015) ## Summary - Update star icon to `fill` on `:hover`. - Update star icon color to `--calcite-color-brand-hover` on `:hover`. - Update star icon color to `--calcite-color-brand-press` on `:active`. - Add `--calcite-rating-color-press` css token.
1 parent 3084b09 commit 11d83f6

File tree

4 files changed

+26
-19
lines changed

4 files changed

+26
-19
lines changed

packages/calcite-components/src/components/rating/rating.e2e.ts

+15-16
Original file line numberDiff line numberDiff line change
@@ -454,9 +454,9 @@ describe("calcite-rating", () => {
454454
expect(changeEvent).toHaveReceivedEventTimes(0);
455455

456456
expect(await page.find("calcite-rating >>> .fraction")).toBeNull();
457-
expect(icons[0]).toEqualAttribute("icon", "star");
458-
expect(icons[1]).toEqualAttribute("icon", "star");
459-
expect(icons[2]).toEqualAttribute("icon", "star");
457+
expect(icons[0]).toEqualAttribute("icon", "star-f");
458+
expect(icons[1]).toEqualAttribute("icon", "star-f");
459+
expect(icons[2]).toEqualAttribute("icon", "star-f");
460460
expect(icons[3]).toEqualAttribute("icon", "star");
461461
expect(icons[4]).toEqualAttribute("icon", "star");
462462
expect(labels[0]).not.toHaveClass("selected");
@@ -499,7 +499,7 @@ describe("calcite-rating", () => {
499499
expect(icons[0]).toEqualAttribute("icon", "star-f");
500500
expect(icons[1]).toEqualAttribute("icon", "star-f");
501501
expect(icons[2]).toEqualAttribute("icon", "star-f");
502-
expect(icons[3]).toEqualAttribute("icon", "star");
502+
expect(icons[3]).toEqualAttribute("icon", "star-f");
503503
expect(icons[4]).toEqualAttribute("icon", "star");
504504
expect(labels[0]).toHaveClass("selected");
505505
expect(labels[1]).toHaveClass("selected");
@@ -675,7 +675,7 @@ describe("calcite-rating", () => {
675675
await page.keyboard.press("Tab");
676676
await page.waitForChanges();
677677

678-
expect(icons[0]).toEqualAttribute("icon", "star");
678+
expect(icons[0]).toEqualAttribute("icon", "star-f");
679679
expect(icons[1]).toEqualAttribute("icon", "star");
680680
expect(icons[2]).toEqualAttribute("icon", "star");
681681
expect(icons[3]).toEqualAttribute("icon", "star");
@@ -810,21 +810,20 @@ describe("calcite-rating", () => {
810810
shadowSelector: `.${CSS.star}`,
811811
targetProp: "color",
812812
},
813+
"--calcite-rating-color-press": {
814+
shadowSelector: `.${CSS.star}`,
815+
targetProp: "color",
816+
state: { press: `calcite-rating >>> .${CSS.star}` },
817+
},
813818
});
814819
});
815820
describe("selected", () => {
816821
themed(html`<calcite-rating value="2"></calcite-rating>`, {
817-
"--calcite-rating-color-hover": [
818-
{
819-
shadowSelector: `.${CSS.star}[data-value='3']`,
820-
targetProp: "color",
821-
state: "hover",
822-
},
823-
{
824-
shadowSelector: `.${CSS.selected}`,
825-
targetProp: "color",
826-
},
827-
],
822+
"--calcite-rating-color-hover": {
823+
shadowSelector: `.${CSS.star}[data-value='3']`,
824+
targetProp: "color",
825+
state: "hover",
826+
},
828827
});
829828
});
830829
describe("average", () => {

packages/calcite-components/src/components/rating/rating.scss

+9-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
*
66
* @prop --calcite-rating-spacing-unit: [Deprecated] Use `--calcite-rating-spacing`. Specifies the amount of left and right margin spacing between each item.
77
* @prop --calcite-rating-spacing: Specifies the amount of left and right margin spacing between each item.
8-
* @prop --calcite-rating-color-hover: Specifies the component's item color when hovered or selected.
8+
* @prop --calcite-rating-color-hover: Specifies the component's item color when hovered.
9+
* @prop --calcite-rating-color-press: Specifies the component's item color when active.
910
* @prop --calcite-rating-color: Specifies the component's item color.
1011
* @prop --calcite-rating-average-color: Specifies the component's item color when average is set.
1112
* @prop --calcite-rating-average-text-color: Specifies the component's average text color.
@@ -58,6 +59,12 @@
5859
flex-direction: column;
5960
cursor: pointer;
6061
color: var(--calcite-rating-color, theme("borderColor.color.input"));
62+
&:hover {
63+
color: var(--calcite-rating-color-hover, var(--calcite-color-brand-hover));
64+
}
65+
&:active {
66+
color: var(--calcite-rating-color-press, var(--calcite-color-brand-press));
67+
}
6168
&:focus {
6269
@apply focus-outset;
6370
}
@@ -70,7 +77,7 @@
7077

7178
.hovered,
7279
.selected {
73-
color: var(--calcite-rating-color-hover, theme("colors.brand"));
80+
color: var(--calcite-rating-color, theme("colors.brand"));
7481
}
7582

7683
.fraction {

packages/calcite-components/src/components/rating/rating.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ export class Rating
424424
type="radio"
425425
value={value}
426426
/>
427-
<StarIcon full={selected || average} scale={this.scale} />
427+
<StarIcon full={selected || average || hovered} scale={this.scale} />
428428
{partial && (
429429
<div class="fraction" style={{ width: `${fraction * 100}%` }}>
430430
<StarIcon full partial scale={this.scale} />

packages/calcite-components/src/custom-theme/rating.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { html } from "../../support/formatting";
33
export const ratingTokens = {
44
calciteRatingSpacing: "",
55
calciteRatingColorHover: "",
6+
calciteRatingColorPress: "",
67
calciteRatingColor: "",
78
calciteRatingAverageColor: "",
89
calciteRatingAverageTextColor: "",

0 commit comments

Comments
 (0)