@bytebrand/fe-ui-core-autobahn 1.0.211 → 1.0.213

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/ui/Stars.tsx CHANGED
@@ -3,27 +3,45 @@ import React from 'react';
3
3
  import Icon from './Icon';
4
4
 
5
5
  export interface StarsProps {
6
- /** rating value 0–5; each star fills when value − index >= 0.5. */
6
+ /** rating value 0–5; each star fills by its exact share (4,52 → four full stars + 52 % of the fifth). */
7
7
  value: number;
8
8
  size?: number;
9
9
  }
10
10
 
11
- /** 5-star row (rounded to nearest .5). */
12
- const Stars: React.FunctionComponent<StarsProps> = ({ value, size = 16 }) => (
13
- <span style={{ display: 'inline-flex', gap: 1 }}>
14
- {[0, 1, 2, 3, 4].map((i) => {
15
- const fill = value - i;
16
- return (
17
- <Icon
18
- key={i}
19
- name={fill >= 0.5 ? 'star' : 'star'}
20
- size={size}
21
- color={fill >= 0.5 ? '#F2A900' : '#D8D6DC'}
22
- style={{ fill: fill >= 0.5 ? '#F2A900' : '#D8D6DC' }}
23
- />
24
- );
25
- })}
26
- </span>
27
- );
11
+ const FILLED = '#F2A900';
12
+ const EMPTY = '#D8D6DC';
13
+
14
+ /**
15
+ * 5-star row filled to the exact value: a grey star with the gold one clipped to the star's
16
+ * share on top, so a site rating of 4,5 shows four and a half stars (whole-number review
17
+ * ratings render exactly as before).
18
+ */
19
+ const Stars: React.FunctionComponent<StarsProps> = ({ value, size = 16 }) => {
20
+ const v = Math.max(0, Math.min(5, Number(value) || 0));
21
+ return (
22
+ <span
23
+ role="img"
24
+ aria-label={`${v.toLocaleString('de-DE', { maximumFractionDigits: 1 })} von 5 Sternen`}
25
+ style={{ display: 'inline-flex', gap: 1 }}
26
+ >
27
+ {[0, 1, 2, 3, 4].map((i) => {
28
+ const share = Math.max(0, Math.min(1, v - i));
29
+ return (
30
+ <span key={i} style={{ position: 'relative', display: 'inline-flex', flex: 'none' }}>
31
+ <Icon name="star" size={size} color={EMPTY} style={{ fill: EMPTY }} />
32
+ {share > 0 && (
33
+ <span
34
+ aria-hidden="true"
35
+ style={{ position: 'absolute', top: 0, left: 0, bottom: 0, width: `${share * 100}%`, overflow: 'hidden', display: 'flex' }}
36
+ >
37
+ <Icon name="star" size={size} color={FILLED} style={{ fill: FILLED, flex: 'none' }} />
38
+ </span>
39
+ )}
40
+ </span>
41
+ );
42
+ })}
43
+ </span>
44
+ );
45
+ };
28
46
 
29
47
  export default Stars;