@faststore/ui 1.7.20 → 1.7.23
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 +30 -0
- package/dist/molecules/AggregateRating/AggregateRating.d.ts +18 -0
- package/dist/molecules/AggregateRating/index.d.ts +2 -0
- package/dist/molecules/AggregateRating/stories/AggregateRating.stories.d.ts +16 -0
- package/package.json +3 -3
- package/src/molecules/AggregateRating/AggregateRating.test.tsx +87 -0
- package/src/molecules/AggregateRating/AggregateRating.tsx +84 -0
- package/src/molecules/AggregateRating/index.ts +2 -0
- package/src/molecules/AggregateRating/stories/AggregateRating.mdx +33 -0
- package/src/molecules/AggregateRating/stories/AggregateRating.stories.tsx +112 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,36 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## 1.7.23 (2022-04-18)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* Add url to events ([#1174](https://github.com/vtex/faststore/issues/1174)) ([0e2befe](https://github.com/vtex/faststore/commit/0e2befe3cb5dc99521a470c4096e31237b93a9c0))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## 1.7.22 (2022-04-13)
|
|
18
|
+
|
|
19
|
+
**Note:** Version bump only for package @faststore/ui
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
## 1.7.21 (2022-04-12)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Features
|
|
29
|
+
|
|
30
|
+
* AggregateRating (Stars) molecule ([#1037](https://github.com/vtex/faststore/issues/1037)) ([23f2fad](https://github.com/vtex/faststore/commit/23f2fad6fd4d58ea369a54a0b6600207016be17e))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
6
36
|
## 1.7.20 (2022-04-11)
|
|
7
37
|
|
|
8
38
|
**Note:** Version bump only for package @faststore/ui
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ListProps } from '../../atoms/List';
|
|
3
|
+
export interface AggregateRatingProps extends ListProps<HTMLUListElement> {
|
|
4
|
+
/**
|
|
5
|
+
* The current value of the rating, based on the quantity of child elements.
|
|
6
|
+
*/
|
|
7
|
+
value: number;
|
|
8
|
+
/**
|
|
9
|
+
* ID to find this component in testing tools (e.g.: cypress, testing library, and jest).
|
|
10
|
+
*/
|
|
11
|
+
testId?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface RatingItemProps {
|
|
14
|
+
'data-store-aggregate-rating-item'?: 'full' | 'partial' | 'empty';
|
|
15
|
+
'data-testid'?: string;
|
|
16
|
+
}
|
|
17
|
+
declare const AggregateRating: React.ForwardRefExoticComponent<AggregateRatingProps & React.RefAttributes<HTMLUListElement>>;
|
|
18
|
+
export default AggregateRating;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { ComponentArgTypes } from '../../../typings/utils';
|
|
3
|
+
import type { AggregateRatingProps } from '../AggregateRating';
|
|
4
|
+
export declare const AggregateRating: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react").ReactFramework, AggregateRatingProps>;
|
|
5
|
+
export declare const AggregateRatingWithoutIcon: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react").ReactFramework, AggregateRatingProps>;
|
|
6
|
+
export declare const AggregateRatingWithCSS: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react").ReactFramework, AggregateRatingProps>;
|
|
7
|
+
declare const _default: {
|
|
8
|
+
title: string;
|
|
9
|
+
argTypes: ComponentArgTypes<AggregateRatingProps>;
|
|
10
|
+
parameters: {
|
|
11
|
+
docs: {
|
|
12
|
+
page: (props: any) => JSX.Element;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export default _default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faststore/ui",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.23",
|
|
4
4
|
"description": "A lightweight, framework agnostic component library for React",
|
|
5
5
|
"author": "emersonlaurentino",
|
|
6
6
|
"license": "MIT",
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"@types/jest-axe": "^3.5.3",
|
|
77
77
|
"@types/tabbable": "^3.1.1",
|
|
78
78
|
"@types/testing-library__jest-dom": "^5.9.5",
|
|
79
|
-
"@vtex/theme-b2c-tailwind": "^1.7.
|
|
79
|
+
"@vtex/theme-b2c-tailwind": "^1.7.23",
|
|
80
80
|
"@vtex/tsconfig": "^0.5.0",
|
|
81
81
|
"chalk": "^5.0.0",
|
|
82
82
|
"jest-axe": "^5.0.1",
|
|
@@ -89,5 +89,5 @@
|
|
|
89
89
|
"tsdx": "^0.14.1",
|
|
90
90
|
"typescript": "^4.2.4"
|
|
91
91
|
},
|
|
92
|
-
"gitHead": "
|
|
92
|
+
"gitHead": "a7683787cb40c2a277884673daa4772f1492fe03"
|
|
93
93
|
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { render } from '@testing-library/react'
|
|
2
|
+
import { axe } from 'jest-axe'
|
|
3
|
+
import React from 'react'
|
|
4
|
+
|
|
5
|
+
import AggregateRating from './AggregateRating'
|
|
6
|
+
|
|
7
|
+
const fillCheck = (value: number) => {
|
|
8
|
+
if (value >= 1) {
|
|
9
|
+
return 'full'
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (0 < value && value < 1) {
|
|
13
|
+
return 'partial'
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return 'empty'
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
describe('AggregateRating', () => {
|
|
20
|
+
it('`data-store-aggregate-rating` is present', () => {
|
|
21
|
+
const { getByTestId } = render(
|
|
22
|
+
<AggregateRating value={2}>
|
|
23
|
+
<span />
|
|
24
|
+
<span />
|
|
25
|
+
<span />
|
|
26
|
+
<span />
|
|
27
|
+
<span />
|
|
28
|
+
</AggregateRating>
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
expect(getByTestId('store-aggregate-rating')).toHaveAttribute(
|
|
32
|
+
'data-store-aggregate-rating'
|
|
33
|
+
)
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
it('has the correct aggregate rating item data attribute', () => {
|
|
37
|
+
const { queryAllByTestId, rerender } = render(
|
|
38
|
+
<AggregateRating value={2}>
|
|
39
|
+
<span />
|
|
40
|
+
</AggregateRating>
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
// Test 5 random values and sizes in Aggregate Rating component.
|
|
44
|
+
for (let i = 1; i <= 5; i += 1) {
|
|
45
|
+
// Random value between 1 and 10
|
|
46
|
+
const numberOfElements = Math.ceil(Math.random() * 10)
|
|
47
|
+
const value = parseFloat((Math.random() * numberOfElements).toFixed(1))
|
|
48
|
+
|
|
49
|
+
rerender(
|
|
50
|
+
<AggregateRating value={value}>
|
|
51
|
+
{Array.from({ length: numberOfElements })}
|
|
52
|
+
</AggregateRating>
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
const ratingItems = queryAllByTestId('store-aggregate-rating-item')
|
|
56
|
+
|
|
57
|
+
// Validate if it's rendering with the correct number of ratings.
|
|
58
|
+
expect(ratingItems).toHaveLength(numberOfElements)
|
|
59
|
+
|
|
60
|
+
// Validate if each rating element has the correct attribute.
|
|
61
|
+
for (
|
|
62
|
+
let currentItemNumber = 0;
|
|
63
|
+
currentItemNumber < numberOfElements;
|
|
64
|
+
currentItemNumber += 1
|
|
65
|
+
) {
|
|
66
|
+
expect(ratingItems[currentItemNumber]).toHaveAttribute(
|
|
67
|
+
'data-store-aggregate-rating-item',
|
|
68
|
+
fillCheck(value - currentItemNumber)
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
it('AXE Test', async () => {
|
|
75
|
+
render(
|
|
76
|
+
<AggregateRating value={3}>
|
|
77
|
+
<span />
|
|
78
|
+
<span />
|
|
79
|
+
<span />
|
|
80
|
+
<span />
|
|
81
|
+
<span />
|
|
82
|
+
</AggregateRating>
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
expect(await axe(document.body)).toHaveNoViolations()
|
|
86
|
+
})
|
|
87
|
+
})
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react'
|
|
2
|
+
import type { FC, PropsWithChildren } from 'react'
|
|
3
|
+
|
|
4
|
+
import List from '../../atoms/List'
|
|
5
|
+
import type { ListProps } from '../../atoms/List'
|
|
6
|
+
|
|
7
|
+
export interface AggregateRatingProps extends ListProps<HTMLUListElement> {
|
|
8
|
+
/**
|
|
9
|
+
* The current value of the rating, based on the quantity of child elements.
|
|
10
|
+
*/
|
|
11
|
+
value: number
|
|
12
|
+
/**
|
|
13
|
+
* ID to find this component in testing tools (e.g.: cypress, testing library, and jest).
|
|
14
|
+
*/
|
|
15
|
+
testId?: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface RatingItemProps {
|
|
19
|
+
'data-store-aggregate-rating-item'?: 'full' | 'partial' | 'empty'
|
|
20
|
+
'data-testid'?: string
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const RatingItem: FC<PropsWithChildren<RatingItemProps>> = ({
|
|
24
|
+
children,
|
|
25
|
+
...otherProps
|
|
26
|
+
}) => {
|
|
27
|
+
if (!React.isValidElement(children)) {
|
|
28
|
+
return <li {...otherProps}>{children}</li>
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return <li>{React.cloneElement(children, otherProps)}</li>
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const AggregateRating = forwardRef<HTMLUListElement, AggregateRatingProps>(
|
|
35
|
+
function AggregateRating(
|
|
36
|
+
{
|
|
37
|
+
children,
|
|
38
|
+
testId = 'store-aggregate-rating',
|
|
39
|
+
value,
|
|
40
|
+
variant = 'unordered',
|
|
41
|
+
...otherProps
|
|
42
|
+
},
|
|
43
|
+
ref
|
|
44
|
+
) {
|
|
45
|
+
const fillCheck = (itemValue: number) => {
|
|
46
|
+
if (itemValue >= 1) {
|
|
47
|
+
return 'full'
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (0 < itemValue && itemValue < 1) {
|
|
51
|
+
return 'partial'
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return 'empty'
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<List
|
|
59
|
+
data-store-aggregate-rating
|
|
60
|
+
variant={variant}
|
|
61
|
+
ref={ref}
|
|
62
|
+
data-testid={testId}
|
|
63
|
+
{...otherProps}
|
|
64
|
+
>
|
|
65
|
+
{React.Children.map(children, (child, index: number) => {
|
|
66
|
+
const currentItemNumber = index
|
|
67
|
+
const fill = fillCheck(value - currentItemNumber)
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<RatingItem
|
|
71
|
+
key={`aggregate-rating-${index}`}
|
|
72
|
+
data-store-aggregate-rating-item={fill}
|
|
73
|
+
data-testid={`${testId}-item`}
|
|
74
|
+
>
|
|
75
|
+
{child}
|
|
76
|
+
</RatingItem>
|
|
77
|
+
)
|
|
78
|
+
})}
|
|
79
|
+
</List>
|
|
80
|
+
)
|
|
81
|
+
}
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
export default AggregateRating
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Canvas, Props, Story, ArgsTable } from '@storybook/addon-docs'
|
|
2
|
+
|
|
3
|
+
import AggregateRating from '../AggregateRating'
|
|
4
|
+
|
|
5
|
+
# Default Aggregate Rating
|
|
6
|
+
|
|
7
|
+
<Canvas>
|
|
8
|
+
<Story id="molecules-aggregaterating--aggregate-rating" />
|
|
9
|
+
</Canvas>
|
|
10
|
+
|
|
11
|
+
# Aggregate Rating Without Icon
|
|
12
|
+
|
|
13
|
+
<Canvas>
|
|
14
|
+
<Story id="molecules-aggregaterating--aggregate-rating-without-icon" />
|
|
15
|
+
</Canvas>
|
|
16
|
+
|
|
17
|
+
# Aggregate Rating With CSS
|
|
18
|
+
|
|
19
|
+
<Canvas>
|
|
20
|
+
<Story id="molecules-aggregaterating--aggregate-rating-with-css" />
|
|
21
|
+
</Canvas>
|
|
22
|
+
|
|
23
|
+
## Props
|
|
24
|
+
|
|
25
|
+
<ArgsTable of={AggregateRating} />
|
|
26
|
+
|
|
27
|
+
## CSS Selectors
|
|
28
|
+
|
|
29
|
+
```css
|
|
30
|
+
[data-store-aggregate-rating] {}
|
|
31
|
+
|
|
32
|
+
[data-aggregate-rating-item=(full|partial|empty)] {}
|
|
33
|
+
```
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { Story } from '@storybook/react'
|
|
2
|
+
import type { FC } from 'react'
|
|
3
|
+
import React from 'react'
|
|
4
|
+
|
|
5
|
+
import type { ComponentArgTypes } from '../../../typings/utils'
|
|
6
|
+
import type { AggregateRatingProps, RatingItemProps } from '../AggregateRating'
|
|
7
|
+
import Component from '../AggregateRating'
|
|
8
|
+
import mdx from './AggregateRating.mdx'
|
|
9
|
+
|
|
10
|
+
const RatingIcon: FC<RatingItemProps> = (props) => {
|
|
11
|
+
const fillColor = {
|
|
12
|
+
empty: 'transparent',
|
|
13
|
+
partial: 'url(#partial)',
|
|
14
|
+
full: '#ffb100',
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<svg
|
|
19
|
+
version="1.1"
|
|
20
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
21
|
+
viewBox="0 0 32 32"
|
|
22
|
+
{...props}
|
|
23
|
+
>
|
|
24
|
+
<defs>
|
|
25
|
+
<linearGradient id="partial">
|
|
26
|
+
<stop offset="50%" stopColor="#ffb100" />
|
|
27
|
+
<stop offset="50%" stopColor="transparent" stopOpacity="1" />
|
|
28
|
+
</linearGradient>
|
|
29
|
+
</defs>
|
|
30
|
+
<path
|
|
31
|
+
d="M20.388,10.918L32,12.118l-8.735,7.749L25.914,
|
|
32
|
+
31.4l-9.893-6.088L6.127,31.4l2.695-11.533L0,
|
|
33
|
+
12.118l11.547-1.2L16.026,0.6L20.388,10.918z"
|
|
34
|
+
fill={fillColor[props['data-store-aggregate-rating-item']!]}
|
|
35
|
+
strokeWidth="2"
|
|
36
|
+
stroke="#ffb100"
|
|
37
|
+
/>
|
|
38
|
+
</svg>
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const AggregateRatingTemplate: Story<AggregateRatingProps> = ({
|
|
43
|
+
value,
|
|
44
|
+
testId,
|
|
45
|
+
}) => {
|
|
46
|
+
return (
|
|
47
|
+
<Component value={value} testId={testId}>
|
|
48
|
+
<RatingIcon />
|
|
49
|
+
<RatingIcon />
|
|
50
|
+
<RatingIcon />
|
|
51
|
+
<RatingIcon />
|
|
52
|
+
<RatingIcon />
|
|
53
|
+
</Component>
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export const AggregateRating = AggregateRatingTemplate.bind({})
|
|
58
|
+
AggregateRating.args = { value: 3 }
|
|
59
|
+
|
|
60
|
+
const AggregateRatingWithoutIconTemplate: Story<AggregateRatingProps> = ({
|
|
61
|
+
value,
|
|
62
|
+
testId,
|
|
63
|
+
}) => {
|
|
64
|
+
return (
|
|
65
|
+
<Component value={value} testId={testId}>
|
|
66
|
+
{Array.from({ length: 5 }).map((_, index) => {
|
|
67
|
+
const isFullRating = value - index >= 1
|
|
68
|
+
|
|
69
|
+
return isFullRating ? '★' : '☆'
|
|
70
|
+
})}
|
|
71
|
+
</Component>
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export const AggregateRatingWithoutIcon = AggregateRatingWithoutIconTemplate.bind(
|
|
76
|
+
{}
|
|
77
|
+
)
|
|
78
|
+
AggregateRatingWithoutIcon.args = { value: 3 }
|
|
79
|
+
|
|
80
|
+
const AggregateRatingWithCSSTemplate: Story<AggregateRatingProps> = ({
|
|
81
|
+
value,
|
|
82
|
+
testId,
|
|
83
|
+
}) => {
|
|
84
|
+
return (
|
|
85
|
+
<Component data-with-css value={value} testId={testId}>
|
|
86
|
+
<span />
|
|
87
|
+
<span />
|
|
88
|
+
<span />
|
|
89
|
+
<span />
|
|
90
|
+
<span />
|
|
91
|
+
</Component>
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export const AggregateRatingWithCSS = AggregateRatingWithCSSTemplate.bind({})
|
|
96
|
+
AggregateRatingWithCSS.args = { value: 2 }
|
|
97
|
+
|
|
98
|
+
const argTypes: ComponentArgTypes<AggregateRatingProps> = {
|
|
99
|
+
value: {
|
|
100
|
+
control: { type: 'number' },
|
|
101
|
+
},
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export default {
|
|
105
|
+
title: 'Molecules/AggregateRating',
|
|
106
|
+
argTypes,
|
|
107
|
+
parameters: {
|
|
108
|
+
docs: {
|
|
109
|
+
page: mdx,
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
}
|