@adobe-commerce/elsie 3.0.0 → 3.1.0-alpha-20261106152546

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @adobe-commerce/elsie
2
2
 
3
+ ## 3.1.0-alpha-20261106152546
4
+
5
+ ### Minor Changes
6
+
7
+ - 0d54094: feat: add `StarRating` component that displays a 0-5 rating with
8
+ partial star fill, optional value, review count and accessible label
9
+
10
+ ### Patch Changes
11
+
12
+ - dc2c0f3: fix(elsie): render the latest context after an async slot callback
13
+ resolves
14
+
15
+ Context changes made while an async `slot` callback was pending were dropped:
16
+ once the callback resolved, `Slot` rendered with the children and context from
17
+ its first render and passed that stale context to `onRender`. It now renders
18
+ with the latest children and context.
19
+
3
20
  ## 3.0.0
4
21
 
5
22
  ### Major Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe-commerce/elsie",
3
- "version": "3.0.0",
3
+ "version": "3.1.0-alpha-20261106152546",
4
4
  "license": "SEE LICENSE IN LICENSE.md",
5
5
  "description": "Domain Package SDK",
6
6
  "engines": {
@@ -0,0 +1,87 @@
1
+ /********************************************************************
2
+ * ADOBE CONFIDENTIAL
3
+ * __________________
4
+ *
5
+ * Copyright 2026 Adobe
6
+ * All Rights Reserved.
7
+ *
8
+ * NOTICE: All information contained herein is, and remains
9
+ * the property of Adobe and its suppliers, if any. The intellectual
10
+ * and technical concepts contained herein are proprietary to Adobe
11
+ * and its suppliers and are protected by all applicable intellectual
12
+ * property laws, including trade secret and copyright laws.
13
+ * Dissemination of this information or reproduction of this material
14
+ * is strictly forbidden unless prior written permission is obtained
15
+ * from Adobe.
16
+ *******************************************************************/
17
+
18
+ .dropin-star-rating {
19
+ display: inline-flex;
20
+ flex-wrap: wrap;
21
+ align-items: center;
22
+ gap: var(--spacing-small);
23
+ max-width: 100%;
24
+ color: var(--color-neutral-800);
25
+ font: var(--type-body-2-default-font);
26
+ }
27
+
28
+ .dropin-star-rating__stars {
29
+ display: inline-flex;
30
+ flex: 0 0 auto;
31
+ }
32
+
33
+ .dropin-star-rating__star {
34
+ position: relative;
35
+ flex: 0 0 auto;
36
+ }
37
+
38
+ .dropin-star-rating__star svg {
39
+ display: block;
40
+ }
41
+
42
+ .dropin-star-rating__star path {
43
+ fill: var(--color-neutral-400);
44
+ }
45
+
46
+ .dropin-star-rating__fill {
47
+ position: absolute;
48
+ inset-block-start: 0;
49
+ inset-inline-start: 0;
50
+ height: 100%;
51
+ overflow: hidden;
52
+ }
53
+
54
+ .dropin-star-rating__fill svg {
55
+ position: absolute;
56
+ inset-inline-start: 0;
57
+ }
58
+
59
+ .dropin-star-rating__fill svg path {
60
+ fill: currentcolor;
61
+ }
62
+
63
+ .dropin-star-rating__count {
64
+ color: var(--color-neutral-700);
65
+ overflow-wrap: anywhere;
66
+ }
67
+
68
+ .dropin-star-rating__value {
69
+ font: var(--type-body-2-strong-font);
70
+ overflow-wrap: anywhere;
71
+ }
72
+
73
+ .dropin-star-rating--stacked {
74
+ flex-direction: column;
75
+ align-items: flex-start;
76
+ }
77
+
78
+ .dropin-star-rating--stacked .dropin-star-rating__value {
79
+ order: -1;
80
+ }
81
+
82
+ .dropin-star-rating--inline.dropin-star-rating--divider
83
+ .dropin-star-rating__count {
84
+ padding-inline-start: var(--spacing-small);
85
+ border-inline-start: var(--shape-border-width-1) solid
86
+ var(--color-neutral-400);
87
+ }
@@ -0,0 +1,140 @@
1
+ /********************************************************************
2
+ * ADOBE CONFIDENTIAL
3
+ * __________________
4
+ *
5
+ * Copyright 2026 Adobe
6
+ * All Rights Reserved.
7
+ *
8
+ * NOTICE: All information contained herein is, and remains
9
+ * the property of Adobe and its suppliers, if any. The intellectual
10
+ * and technical concepts contained herein are proprietary to Adobe
11
+ * and its suppliers and are protected by all applicable intellectual
12
+ * property laws, including trade secret and copyright laws.
13
+ * Dissemination of this information or reproduction of this material
14
+ * is strictly forbidden unless prior written permission is obtained
15
+ * from Adobe.
16
+ *******************************************************************/
17
+
18
+ import type { Meta, StoryObj } from '@storybook/preact-vite';
19
+ import { expect } from '@adobe-commerce/elsie/storybook/tests';
20
+ import {
21
+ StarRating as component,
22
+ StarRatingProps,
23
+ } from '@adobe-commerce/elsie/components/StarRating';
24
+
25
+ const meta: Meta<StarRatingProps> = {
26
+ title: 'Components/StarRating',
27
+ component,
28
+ tags: ['autodocs'],
29
+ args: { rating: 4.5 },
30
+ argTypes: {
31
+ rating: { control: { type: 'range', min: 0, max: 5, step: 0.1 } },
32
+ reviewCount: { control: { type: 'number', min: 0 } },
33
+ showCount: { control: 'boolean' },
34
+ size: { control: 'select', options: ['small', 'medium'] },
35
+ },
36
+ };
37
+
38
+ export default meta;
39
+
40
+ type Story = StoryObj<StarRatingProps>;
41
+
42
+ export const Fractional: Story = {};
43
+ export const Whole: Story = { args: { rating: 5 } };
44
+ export const WithCount: Story = { args: { reviewCount: 2, showCount: true } };
45
+ export const OneReview: Story = {
46
+ args: { rating: 4, reviewCount: 1, showCount: true },
47
+ };
48
+ export const ZeroReviews: Story = {
49
+ args: { rating: 0, reviewCount: 0, showCount: true },
50
+ };
51
+ export const CountInParentheses: Story = {
52
+ args: { reviewCount: 12, showCount: true, countDisplay: 'parentheses' },
53
+ };
54
+ export const CustomCountColor: Story = {
55
+ args: { reviewCount: 12, showCount: true, countDisplay: 'parentheses' },
56
+ decorators: [
57
+ (Story) => (
58
+ <div className="story-count-alert">
59
+ <style>{`.story-count-alert .dropin-star-rating__count { color: var(--color-alert-800); }`}</style>
60
+ <Story />
61
+ </div>
62
+ ),
63
+ ],
64
+ };
65
+ export const InlineWithValueAndCount: Story = {
66
+ args: {
67
+ rating: 4.3,
68
+ reviewCount: 12,
69
+ showCount: true,
70
+ valueDisplay: 'value',
71
+ countDisplay: 'parentheses',
72
+ layout: 'inline',
73
+ },
74
+ };
75
+ export const StackedOutOfFive: Story = {
76
+ args: {
77
+ rating: 4.3,
78
+ reviewCount: 12,
79
+ showCount: true,
80
+ valueDisplay: 'outOfFive',
81
+ countDisplay: 'text',
82
+ layout: 'stacked',
83
+ },
84
+ decorators: [
85
+ (Story) => (
86
+ <div className="story-count-positive">
87
+ <style>{`.story-count-positive .dropin-star-rating__count { color: var(--color-positive-800); }`}</style>
88
+ <Story />
89
+ </div>
90
+ ),
91
+ ],
92
+ };
93
+ export const Small: Story = {
94
+ args: {
95
+ rating: 4.3,
96
+ size: 'small',
97
+ reviewCount: 12,
98
+ showCount: true,
99
+ valueDisplay: 'value',
100
+ countDisplay: 'parentheses',
101
+ },
102
+ };
103
+ export const HeartIcon: Story = {
104
+ args: {
105
+ icon: 'HeartFilled',
106
+ reviewCount: 12,
107
+ showCount: true,
108
+ countDisplay: 'parentheses',
109
+ style: { color: 'var(--color-alert-500)' },
110
+ },
111
+ };
112
+ // Regression test: URL-loaded icons render inside a <span>, so the empty
113
+ // (gray) star layer must be styled without relying on a direct <svg> child.
114
+ export const UrlIconEmptyStarsStayGray: Story = {
115
+ args: {
116
+ rating: 0,
117
+ icon: (props) => (
118
+ <span>
119
+ <svg {...props} viewBox="0 0 24 24">
120
+ <path
121
+ d="M12 2l3 7h7l-5.5 4.5L18 21l-6-4-6 4 1.5-7.5L2 9h7z"
122
+ fill="red"
123
+ />
124
+ </svg>
125
+ </span>
126
+ ),
127
+ },
128
+ play: async ({ canvasElement }) => {
129
+ const basePath = canvasElement.querySelector(
130
+ '.dropin-star-rating__star > span path',
131
+ ) as SVGPathElement;
132
+ await expect(getComputedStyle(basePath).fill).not.toBe('rgb(255, 0, 0)');
133
+ },
134
+ };
135
+ export const CountHidden: Story = {
136
+ args: { reviewCount: 2, showCount: false },
137
+ };
138
+ export const RightToLeft: Story = {
139
+ args: { dir: 'rtl', reviewCount: 12, showCount: true },
140
+ };
@@ -0,0 +1,165 @@
1
+ /********************************************************************
2
+ * ADOBE CONFIDENTIAL
3
+ * __________________
4
+ *
5
+ * Copyright 2026 Adobe
6
+ * All Rights Reserved.
7
+ *
8
+ * NOTICE: All information contained herein is, and remains
9
+ * the property of Adobe and its suppliers, if any. The intellectual
10
+ * and technical concepts contained herein are proprietary to Adobe
11
+ * and its suppliers and are protected by all applicable intellectual
12
+ * property laws, including trade secret and copyright laws.
13
+ * Dissemination of this information or reproduction of this material
14
+ * is strictly forbidden unless prior written permission is obtained
15
+ * from Adobe.
16
+ *******************************************************************/
17
+
18
+ import { ComponentProps, FunctionComponent } from 'preact';
19
+ import { HTMLAttributes } from 'preact/compat';
20
+ import { classes } from '@adobe-commerce/elsie/lib';
21
+ import { Icon } from '@adobe-commerce/elsie/components/Icon';
22
+ import { Text, useText } from '@adobe-commerce/elsie/i18n';
23
+ import '@adobe-commerce/elsie/components/StarRating/StarRating.css';
24
+
25
+ export interface StarRatingProps extends Omit<
26
+ HTMLAttributes<HTMLDivElement>,
27
+ 'children' | 'icon'
28
+ > {
29
+ rating: number;
30
+ reviewCount?: number;
31
+ showCount?: boolean;
32
+ valueDisplay?: 'hidden' | 'value' | 'outOfFive';
33
+ countDisplay?: 'text' | 'parentheses';
34
+ layout?: 'inline' | 'stacked';
35
+ size?: 'small' | 'medium';
36
+ showDivider?: boolean;
37
+ icon?: ComponentProps<typeof Icon>['source'];
38
+ }
39
+
40
+ export const StarRating: FunctionComponent<StarRatingProps> = ({
41
+ className,
42
+ rating,
43
+ reviewCount,
44
+ showCount = false,
45
+ valueDisplay = 'hidden',
46
+ countDisplay = 'text',
47
+ layout = 'inline',
48
+ size = 'medium',
49
+ showDivider = false,
50
+ icon = 'Star',
51
+ ...props
52
+ }) => {
53
+ const countKey =
54
+ reviewCount === 0
55
+ ? 'zeroReviews'
56
+ : reviewCount === 1
57
+ ? 'oneReview'
58
+ : 'reviews';
59
+ // Round once so the fill, value text and accessible label always agree.
60
+ const roundedRating = Number.isFinite(rating)
61
+ ? Math.round(rating * 10) / 10
62
+ : rating;
63
+ const displayRating = Number.isFinite(rating) ? roundedRating.toFixed(1) : '';
64
+ const dictionary = useText({
65
+ ratingLabel: (
66
+ <Text
67
+ id={
68
+ icon === 'Star'
69
+ ? 'Dropin.StarRating.label'
70
+ : 'Dropin.StarRating.symbolLabel'
71
+ }
72
+ fields={{ rating: roundedRating }}
73
+ />
74
+ ),
75
+ valueLabel: (
76
+ <Text
77
+ id="Dropin.StarRating.valueLabel"
78
+ fields={{ rating: displayRating }}
79
+ />
80
+ ),
81
+ compactCount: (
82
+ <Text
83
+ id="Dropin.StarRating.compactCount"
84
+ fields={{ count: reviewCount }}
85
+ />
86
+ ),
87
+ countLabel: (
88
+ <Text
89
+ id={`Dropin.StarRating.${countKey}`}
90
+ fields={{ count: reviewCount }}
91
+ />
92
+ ),
93
+ noReviews: 'Dropin.StarRating.zeroReviews',
94
+ });
95
+ if (
96
+ !Number.isFinite(rating) ||
97
+ rating < 0 ||
98
+ rating > 5 ||
99
+ (reviewCount !== undefined &&
100
+ (!Number.isSafeInteger(reviewCount) || reviewCount < 0))
101
+ ) {
102
+ return null;
103
+ }
104
+ const iconSize = size === 'small' ? '16' : '24';
105
+ const iconStroke = size === 'small' ? '1' : '2';
106
+ const hasCount = showCount && reviewCount !== undefined;
107
+ const label =
108
+ reviewCount === 0 ? dictionary.noReviews : dictionary.ratingLabel;
109
+ const accessibleLabel =
110
+ hasCount && reviewCount !== 0
111
+ ? `${label}, ${dictionary.countLabel}`
112
+ : label;
113
+
114
+ return (
115
+ <div
116
+ {...props}
117
+ className={classes([
118
+ 'dropin-star-rating',
119
+ `dropin-star-rating--${layout}`,
120
+ ['dropin-star-rating--divider', showDivider && hasCount],
121
+ className,
122
+ ])}
123
+ role="img"
124
+ aria-label={accessibleLabel}
125
+ >
126
+ <span className="dropin-star-rating__stars" aria-hidden="true">
127
+ {[0, 1, 2, 3, 4].map((index) => (
128
+ <span key={index} className="dropin-star-rating__star">
129
+ <Icon
130
+ source={icon}
131
+ size={iconSize}
132
+ stroke={iconStroke}
133
+ aria-hidden="true"
134
+ />
135
+ <span
136
+ className="dropin-star-rating__fill"
137
+ style={{
138
+ width: `${Math.round(Math.min(Math.max(roundedRating - index, 0), 1) * 100)}%`,
139
+ }}
140
+ >
141
+ <Icon
142
+ source={icon}
143
+ size={iconSize}
144
+ stroke={iconStroke}
145
+ aria-hidden="true"
146
+ />
147
+ </span>
148
+ </span>
149
+ ))}
150
+ </span>
151
+ {valueDisplay !== 'hidden' && reviewCount !== 0 && (
152
+ <span className="dropin-star-rating__value" aria-hidden="true">
153
+ {valueDisplay === 'outOfFive' ? dictionary.valueLabel : displayRating}
154
+ </span>
155
+ )}
156
+ {hasCount && (
157
+ <span className="dropin-star-rating__count" aria-hidden="true">
158
+ {countDisplay === 'parentheses' && reviewCount !== 0
159
+ ? dictionary.compactCount
160
+ : dictionary.countLabel}
161
+ </span>
162
+ )}
163
+ </div>
164
+ );
165
+ };
@@ -0,0 +1,19 @@
1
+ /********************************************************************
2
+ * ADOBE CONFIDENTIAL
3
+ * __________________
4
+ *
5
+ * Copyright 2026 Adobe
6
+ * All Rights Reserved.
7
+ *
8
+ * NOTICE: All information contained herein is, and remains
9
+ * the property of Adobe and its suppliers, if any. The intellectual
10
+ * and technical concepts contained herein are proprietary to Adobe
11
+ * and its suppliers and are protected by all applicable intellectual
12
+ * property laws, including trade secret and copyright laws.
13
+ * Dissemination of this information or reproduction of this material
14
+ * is strictly forbidden unless prior written permission is obtained
15
+ * from Adobe.
16
+ *******************************************************************/
17
+
18
+ export * from '@adobe-commerce/elsie/components/StarRating/StarRating';
19
+ export { StarRating as default } from '@adobe-commerce/elsie/components/StarRating/StarRating';
@@ -52,3 +52,4 @@ export * from '@adobe-commerce/elsie/components/InputFile';
52
52
  export * from '@adobe-commerce/elsie/components/Table';
53
53
  export * from '@adobe-commerce/elsie/components/MultiSelect';
54
54
  export * from '@adobe-commerce/elsie/components/LiveRegion';
55
+ export * from '@adobe-commerce/elsie/components/StarRating';
@@ -187,6 +187,15 @@
187
187
  "itemsSelectedDescription": "{count} item{s} selected: {labels}",
188
188
  "noItemsSelected": "No items selected"
189
189
  }
190
+ },
191
+ "StarRating": {
192
+ "label": "{{rating}} out of 5 stars",
193
+ "symbolLabel": "{{rating}} out of 5",
194
+ "valueLabel": "{{rating}} out of 5",
195
+ "compactCount": "({{count}})",
196
+ "zeroReviews": "No reviews",
197
+ "oneReview": "1 review",
198
+ "reviews": "{{count}} reviews"
190
199
  }
191
200
  }
192
201
  }
package/src/lib/slot.tsx CHANGED
@@ -337,6 +337,9 @@ export function useSlot<K, V extends HTMLElement>(
337
337
  status.current = 'ready';
338
338
  }, [children, context, name, props, render, state]);
339
339
 
340
+ const handleLifeCycleRenderRef = useRef(handleLifeCycleRender);
341
+ handleLifeCycleRenderRef.current = handleLifeCycleRender;
342
+
340
343
  // Initialization
341
344
  const handleLifeCycleInit = useCallback(async () => {
342
345
  if (!callback) return;
@@ -355,9 +358,9 @@ export function useSlot<K, V extends HTMLElement>(
355
358
  status.current = 'ready';
356
359
 
357
360
  // first render
358
- await handleLifeCycleRender();
361
+ await handleLifeCycleRenderRef.current();
359
362
  }
360
- }, [callback, context, handleLifeCycleRender, name]);
363
+ }, [callback, context, name]);
361
364
 
362
365
  // Initialization
363
366
  useEffect(() => {