diff --git a/src/components/calcite-rating/calcite-rating.e2e.ts b/src/components/calcite-rating/calcite-rating.e2e.ts index 44cc41f637e..704e57144f4 100644 --- a/src/components/calcite-rating/calcite-rating.e2e.ts +++ b/src/components/calcite-rating/calcite-rating.e2e.ts @@ -381,14 +381,21 @@ describe("calcite-rating", () => { it("does not render the calcite chip when count and average are not present", async () => { const page = await newE2EPage(); - await page.setContent(""); + await page.setContent(""); + const calciteChip = await page.find("calcite-rating >>> calcite-chip"); + expect(calciteChip).toBeNull(); + }); + + it("does not render the calcite chip when show-chip is false", async () => { + const page = await newE2EPage(); + await page.setContent(""); const calciteChip = await page.find("calcite-rating >>> calcite-chip"); expect(calciteChip).toBeNull(); }); it("renders the calcite chip and the count span when count is present and average is not", async () => { const page = await newE2EPage(); - await page.setContent(``); + await page.setContent(``); const calciteChip = await page.find("calcite-rating >>> calcite-chip"); const countSpan = await page.find("calcite-rating >>> .number--count"); const averageSpan = await page.find("calcite-rating >>> .number--average"); @@ -399,7 +406,7 @@ describe("calcite-rating", () => { it("renders the calcite chip and the average span when average is present and count is not", async () => { const page = await newE2EPage(); - await page.setContent(""); + await page.setContent(""); const calciteChip = await page.find("calcite-rating >>> calcite-chip"); const countSpan = await page.find("calcite-rating >>> .number---count"); const averageSpan = await page.find("calcite-rating >>> .number--average"); @@ -410,7 +417,7 @@ describe("calcite-rating", () => { it("renders the calcite chip and both the average and count spans when average and count are present", async () => { const page = await newE2EPage(); - await page.setContent(""); + await page.setContent(""); const calciteChip = await page.find("calcite-rating >>> calcite-chip"); const countSpan = await page.find("calcite-rating >>> .number--count"); const averageSpan = await page.find("calcite-rating >>> .number--average"); diff --git a/src/components/calcite-rating/calcite-rating.stories.ts b/src/components/calcite-rating/calcite-rating.stories.ts index 5aa223ab275..2085f377262 100644 --- a/src/components/calcite-rating/calcite-rating.stories.ts +++ b/src/components/calcite-rating/calcite-rating.stories.ts @@ -16,6 +16,7 @@ export const Simple = (): string => html` html` theme="dark" scale="${select("scale", ["s", "m", "l"], "m")}" value="${number("value", 0)}" + ${boolean("show-chip", false)} average="${number("average", 0)}" count="${number("count", 0)}" ${boolean("read-only", false)} @@ -50,6 +52,7 @@ export const WrappedInCalciteLabel = (): string => html` html` ; //-------------------------------------------------------------------------- // @@ -153,6 +153,7 @@ export class CalciteRating { } render() { + const { intlRating, showChip, scale, theme, count, average } = this; const dir = getElementDir(this.el); return ( @@ -162,18 +163,13 @@ export class CalciteRating { onMouseLeave={() => (this.hoverValue = null)} onTouchEnd={() => (this.hoverValue = null)} > - {this.intlRating} + {intlRating} {this.renderStars()} - {this.count || this.average ? ( - - {this.average && {this.average.toString()}} - {this.count && ({this.count?.toString()})} + {(count || average) && showChip ? ( + + {!!average && {average.toString()}} + {!!count && ({count?.toString()})} ) : null} diff --git a/src/components/calcite-rating/readme.md b/src/components/calcite-rating/readme.md index c34ec3638e1..a31d9f9a3ff 100644 --- a/src/components/calcite-rating/readme.md +++ b/src/components/calcite-rating/readme.md @@ -10,24 +10,24 @@ ## Properties -| Property | Attribute | Description | Type | Default | -| -------------- | --------------- | ----------------------------------------------------------------------------------------------- | ------------------- | ------------- | -| `average` | `average` | optionally pass a cumulative average rating to display | `number` | `undefined` | -| `count` | `count` | optionally pass a number of previous ratings to display | `number` | `undefined` | -| `disabled` | `disabled` | is the rating component in a selectable mode | `boolean` | `false` | -| `displayValue` | `display-value` | display rating value | `boolean` | `false` | -| `intlRating` | `intl-rating` | Localized string for "Rating" (used for aria label) | `string` | `TEXT.rating` | -| `intlStars` | `intl-stars` | Localized string for labelling each star, `${num}` in the string will be replaced by the number | `string` | `TEXT.stars` | -| `readOnly` | `read-only` | is the rating component in a selectable mode | `boolean` | `false` | -| `scale` | `scale` | specify the scale of the component, defaults to m | `"l" \| "m" \| "s"` | `"m"` | -| `theme` | `theme` | specify the theme of scrim, defaults to light | `"dark" \| "light"` | `undefined` | -| `value` | `value` | the value of the rating component | `number` | `0` | +| Property | Attribute | Description | Type | Default | +| ------------ | ------------- | ----------------------------------------------------------------------------------------------- | ------------------- | ------------- | +| `average` | `average` | optionally pass a cumulative average rating to display | `number` | `undefined` | +| `count` | `count` | optionally pass a number of previous ratings to display | `number` | `undefined` | +| `disabled` | `disabled` | is the rating component in a selectable mode | `boolean` | `false` | +| `intlRating` | `intl-rating` | Localized string for "Rating" (used for aria label) | `string` | `TEXT.rating` | +| `intlStars` | `intl-stars` | Localized string for labelling each star, `${num}` in the string will be replaced by the number | `string` | `TEXT.stars` | +| `readOnly` | `read-only` | is the rating component in a selectable mode | `boolean` | `false` | +| `scale` | `scale` | specify the scale of the component, defaults to m | `"l" \| "m" \| "s"` | `"m"` | +| `showChip` | `show-chip` | Show average and count data summary chip (if available) | `boolean` | `false` | +| `theme` | `theme` | specify the theme of scrim, defaults to light | `"dark" \| "light"` | `undefined` | +| `value` | `value` | the value of the rating component | `number` | `0` | ## Events -| Event | Description | Type | -| --------------------- | ----------- | ------------------ | -| `calciteRatingChange` | | `CustomEvent` | +| Event | Description | Type | +| --------------------- | ----------- | --------------------------------- | +| `calciteRatingChange` | | `CustomEvent<{ value: number; }>` | ## Methods diff --git a/src/demos/calcite-rating.html b/src/demos/calcite-rating.html index 5456a96fb9e..03203a92742 100644 --- a/src/demos/calcite-rating.html +++ b/src/demos/calcite-rating.html @@ -34,6 +34,10 @@
Default with average and value
Default without average or value
+
Default with average, show chip
+ +
Default with average, value, and count; show chip
+

Wrapped in calcite-label

@@ -99,15 +103,16 @@

RTL

Default

Default with average
- - -
Default with value
Default with average and value
Default without average or value
+
Default with average, show chip
+ +
Default with average, value, and count; show chip
+

Wrapped in calcite-label

Rate this item