@faststore/ui 2.0.53-alpha.0 → 2.0.54-alpha.0
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/dist/index.d.ts +0 -4
- package/dist/index.js +0 -2
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/components/atoms/Slider/styles.scss +137 -0
- package/src/components/organisms/PriceRange/styles.scss +36 -0
- package/src/index.ts +0 -6
- package/src/styles/components.scss +2 -0
- package/dist/components/atoms/Slider/Slider.d.ts +0 -67
- package/dist/components/atoms/Slider/Slider.js +0 -48
- package/dist/components/atoms/Slider/Slider.js.map +0 -1
- package/dist/components/atoms/Slider/index.d.ts +0 -2
- package/dist/components/atoms/Slider/index.js +0 -2
- package/dist/components/atoms/Slider/index.js.map +0 -1
- package/dist/components/molecules/PriceRange/PriceRange.d.ts +0 -47
- package/dist/components/molecules/PriceRange/PriceRange.js +0 -28
- package/dist/components/molecules/PriceRange/PriceRange.js.map +0 -1
- package/dist/components/molecules/PriceRange/index.d.ts +0 -2
- package/dist/components/molecules/PriceRange/index.js +0 -2
- package/dist/components/molecules/PriceRange/index.js.map +0 -1
- package/src/components/atoms/Slider/Slider.tsx +0 -182
- package/src/components/atoms/Slider/index.ts +0 -2
- package/src/components/molecules/PriceRange/PriceRange.tsx +0 -108
- package/src/components/molecules/PriceRange/index.ts +0 -2
package/dist/index.d.ts
CHANGED
|
@@ -3,8 +3,6 @@ export { default as Popover } from './components/atoms/Popover';
|
|
|
3
3
|
export type { PopoverProps } from './components/atoms/Popover';
|
|
4
4
|
export { default as TextArea } from './components/atoms/TextArea';
|
|
5
5
|
export type { TextAreaProps } from './components/atoms/TextArea';
|
|
6
|
-
export { default as Slider } from './components/atoms/Slider';
|
|
7
|
-
export type { SliderProps } from './components/atoms/Slider';
|
|
8
6
|
export { default as Skeleton } from './components/atoms/Skeleton';
|
|
9
7
|
export type { SkeletonProps } from './components/atoms/Skeleton';
|
|
10
8
|
export { default as Incentive } from './components/atoms/Incentive';
|
|
@@ -35,8 +33,6 @@ export { default as PaymentMethods } from './components/molecules/PaymentMethods
|
|
|
35
33
|
export type { PaymentMethodsProps } from './components/molecules/PaymentMethods';
|
|
36
34
|
export { default as Breadcrumb } from './components/molecules/Breadcrumb';
|
|
37
35
|
export type { BreadcrumbProps } from './components/molecules/Breadcrumb';
|
|
38
|
-
export { default as PriceRange } from './components/molecules/PriceRange';
|
|
39
|
-
export type { PriceRangeProps } from './components/molecules/PriceRange';
|
|
40
36
|
export { default as Form } from './components/molecules/Form';
|
|
41
37
|
export type { FormProps } from './components/molecules/Form';
|
|
42
38
|
export { default as OutOfStock, OutOfStockTitle, OutOfStockMessage, } from './components/organisms/OutOfStock';
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,6 @@ export * from '@faststore/components';
|
|
|
2
2
|
// Atoms
|
|
3
3
|
export { default as Popover } from './components/atoms/Popover';
|
|
4
4
|
export { default as TextArea } from './components/atoms/TextArea';
|
|
5
|
-
export { default as Slider } from './components/atoms/Slider';
|
|
6
5
|
export { default as Skeleton } from './components/atoms/Skeleton';
|
|
7
6
|
export { default as Incentive } from './components/atoms/Incentive';
|
|
8
7
|
// Molecules
|
|
@@ -19,7 +18,6 @@ export { default as Modal } from './components/molecules/Modal';
|
|
|
19
18
|
export { default as Banner, BannerContent, BannerImage, BannerLink, } from './components/molecules/Banner';
|
|
20
19
|
export { default as PaymentMethods } from './components/molecules/PaymentMethods';
|
|
21
20
|
export { default as Breadcrumb } from './components/molecules/Breadcrumb';
|
|
22
|
-
export { default as PriceRange } from './components/molecules/PriceRange';
|
|
23
21
|
export { default as Form } from './components/molecules/Form';
|
|
24
22
|
// Organisms
|
|
25
23
|
export { default as OutOfStock, OutOfStockTitle, OutOfStockMessage, } from './components/organisms/OutOfStock';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAA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,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,iCAAiC,CAAA;AAGrE,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,8BAA8B,CAAA;AAG/D,OAAO,EACL,OAAO,IAAI,MAAM,EACjB,aAAa,EACb,WAAW,EACX,UAAU,GACX,MAAM,+BAA+B,CAAA;AAQtC,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,uCAAuC,CAAA;AAGjF,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,mCAAmC,CAAA;AAGzE,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,6BAA6B,CAAA;AAG7D,YAAY;AACZ,OAAO,EACL,OAAO,IAAI,UAAU,EACrB,eAAe,EACf,iBAAiB,GAClB,MAAM,mCAAmC,CAAA;AAO1C,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,8BAA8B,CAAA;AAG1D,QAAQ;AACR,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,mBAAmB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faststore/ui",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.54-alpha.0",
|
|
4
4
|
"description": "A lightweight, framework agnostic component library for React",
|
|
5
5
|
"author": "emersonlaurentino",
|
|
6
6
|
"license": "MIT",
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"node": "16.18.0",
|
|
60
60
|
"yarn": "1.19.1"
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "7173ea0bec153905a6b800d002401b5c27fd3213"
|
|
63
63
|
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
[data-fs-slider] {
|
|
2
|
+
// --------------------------------------------------------
|
|
3
|
+
// Design Tokens for Slider
|
|
4
|
+
// --------------------------------------------------------
|
|
5
|
+
|
|
6
|
+
// Default properties
|
|
7
|
+
--fs-slider-height : var(--fs-spacing-2);
|
|
8
|
+
--fs-slider-border-radius : var(--fs-border-radius-pill);
|
|
9
|
+
--fs-slider-margin-bottom : var(--fs-spacing-3);
|
|
10
|
+
|
|
11
|
+
--fs-slider-bkg-color : var(--fs-color-neutral-bkg);
|
|
12
|
+
--fs-slider-selection-bkg-color : var(--fs-color-primary-bkg-light-active);
|
|
13
|
+
|
|
14
|
+
--fs-slider-transition-function : var(--fs-transition-function);
|
|
15
|
+
--fs-slider-transition-property : var(--fs-transition-property);
|
|
16
|
+
--fs-slider-transition-timing : var(--fs-transition-timing);
|
|
17
|
+
|
|
18
|
+
// Thumb
|
|
19
|
+
--fs-slider-thumb-size : var(--fs-spacing-4);
|
|
20
|
+
--fs-slider-thumb-bkg-color : var(--fs-color-primary-bkg);
|
|
21
|
+
--fs-slider-thumb-bkg-color-hover : var(--fs-color-primary-bkg-hover);
|
|
22
|
+
--fs-slider-thumb-border-width : var(--fs-border-width);
|
|
23
|
+
--fs-slider-thumb-border-radius : var(--fs-border-radius-circle);
|
|
24
|
+
--fs-slider-thumb-border-color : var(--fs-slider-thumb-bkg-color);
|
|
25
|
+
--fs-slider-thumb-border-color-hover : var(--fs-slider-thumb-bkg-color-hover);
|
|
26
|
+
|
|
27
|
+
// Absolute Values
|
|
28
|
+
--fs-slider-absolute-values-text-color : var(--fs-color-disabled-text);
|
|
29
|
+
|
|
30
|
+
// Value Label
|
|
31
|
+
--fs-slider-value-label-bottom : var(--fs-spacing-3);
|
|
32
|
+
--fs-slider-value-label-bkg-color : var(--fs-color-body-bkg);
|
|
33
|
+
|
|
34
|
+
// --------------------------------------------------------
|
|
35
|
+
// Structural Styles
|
|
36
|
+
// --------------------------------------------------------
|
|
37
|
+
|
|
38
|
+
width: 100%;
|
|
39
|
+
|
|
40
|
+
[data-fs-slider-wrapper] {
|
|
41
|
+
position: relative;
|
|
42
|
+
width: 100%;
|
|
43
|
+
height: var(--fs-slider-height);
|
|
44
|
+
margin-bottom: var(--fs-slider-margin-bottom);
|
|
45
|
+
background-color: var(--fs-slider-bkg-color);
|
|
46
|
+
border-radius: var(--fs-slider-border-radius);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
[data-fs-slider-range] {
|
|
50
|
+
position: absolute;
|
|
51
|
+
height: var(--fs-slider-height);
|
|
52
|
+
background-color: var(--fs-slider-selection-bkg-color);
|
|
53
|
+
border-radius: var(--fs-slider-border-radius);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Thumb styles for Webkit based browsers (Chrome, Edge)
|
|
57
|
+
[data-fs-slider-thumb],
|
|
58
|
+
[data-fs-slider-thumb]::-webkit-slider-thumb {
|
|
59
|
+
width: var(--fs-slider-thumb-size);
|
|
60
|
+
height: var(--fs-slider-thumb-size);
|
|
61
|
+
pointer-events: auto;
|
|
62
|
+
cursor: col-resize;
|
|
63
|
+
background-color: var(--fs-slider-thumb-bkg-color);
|
|
64
|
+
border: var(--fs-slider-thumb-border-width) solid var(--fs-slider-thumb-border-color);
|
|
65
|
+
border-radius: var(--fs-slider-thumb-border-radius);
|
|
66
|
+
-webkit-tap-highlight-color: transparent;
|
|
67
|
+
appearance: none;
|
|
68
|
+
transition: var(--fs-slider-transition-property) var(--fs-slider-transition-timing) var(--fs-slider-transition-function);
|
|
69
|
+
|
|
70
|
+
&:hover {
|
|
71
|
+
background-color: var(--fs-slider-thumb-bkg-color-hover);
|
|
72
|
+
border-color: var(--fs-slider-thumb-border-color-hover);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Thumb styles for Mozilla
|
|
77
|
+
[data-fs-slider-thumb]::-moz-range-thumb {
|
|
78
|
+
width: var(--fs-slider-thumb-size);
|
|
79
|
+
height: var(--fs-slider-thumb-size);
|
|
80
|
+
pointer-events: auto;
|
|
81
|
+
cursor: col-resize;
|
|
82
|
+
background-color: var(--fs-slider-thumb-bkg-color);
|
|
83
|
+
border: var(--fs-slider-thumb-border-width) solid var(--fs-slider-thumb-border-color);
|
|
84
|
+
border-radius: var(--fs-slider-thumb-radius);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
[data-fs-slider-thumb] {
|
|
88
|
+
position: absolute;
|
|
89
|
+
width: inherit;
|
|
90
|
+
height: 0;
|
|
91
|
+
margin: calc(var(--fs-slider-height) / 2) 0;
|
|
92
|
+
pointer-events: none;
|
|
93
|
+
border: none;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
[data-fs-slider-thumb="left"] {
|
|
97
|
+
z-index: 1;
|
|
98
|
+
|
|
99
|
+
&:hover + [data-fs-slider-value-label="min"] {
|
|
100
|
+
opacity: 1;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
[data-fs-slider-thumb="right"] {
|
|
105
|
+
z-index: 2;
|
|
106
|
+
|
|
107
|
+
&:hover + [data-fs-slider-value-label="max"] {
|
|
108
|
+
opacity: 1;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
[data-fs-slider-value-label] {
|
|
113
|
+
position: absolute;
|
|
114
|
+
bottom: var(--fs-slider-value-label-bottom);
|
|
115
|
+
padding: var(--fs-spacing-1);
|
|
116
|
+
background-color: var(--fs-slider-value-label-bkg-color);
|
|
117
|
+
opacity: 0;
|
|
118
|
+
transition: opacity var(--fs-slider-transition-timing) var(--fs-slider-transition-function);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
[data-fs-slider-value-label="min"] {
|
|
122
|
+
text-align: left;
|
|
123
|
+
transform: translateX(-1rem);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
[data-fs-slider-value-label="max"] {
|
|
127
|
+
text-align: right;
|
|
128
|
+
transform: translateX(calc(-100% + 1.25rem));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
[data-fs-slider-absolute-values] {
|
|
132
|
+
display: flex;
|
|
133
|
+
justify-content: space-between;
|
|
134
|
+
margin-bottom: var(--fs-spacing-2);
|
|
135
|
+
color: var(--fs-slider-absolute-values-text-color);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
[data-fs-price-range] {
|
|
2
|
+
// --------------------------------------------------------
|
|
3
|
+
// Structural Styles
|
|
4
|
+
// --------------------------------------------------------
|
|
5
|
+
|
|
6
|
+
width: 100%;
|
|
7
|
+
|
|
8
|
+
[data-fs-price-range-inputs] {
|
|
9
|
+
display: flex;
|
|
10
|
+
|
|
11
|
+
[data-fs-input-field] {
|
|
12
|
+
width: 50%;
|
|
13
|
+
|
|
14
|
+
input:hover,
|
|
15
|
+
input:focus-visible,
|
|
16
|
+
input:focus {
|
|
17
|
+
z-index: 1;
|
|
18
|
+
+ label { z-index: 1; }
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
&:first-of-type {
|
|
22
|
+
margin-right: -1px;
|
|
23
|
+
|
|
24
|
+
input {
|
|
25
|
+
border-top-right-radius: 0;
|
|
26
|
+
border-bottom-right-radius: 0;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
&:last-of-type input {
|
|
31
|
+
border-top-left-radius: 0;
|
|
32
|
+
border-bottom-left-radius: 0;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -7,9 +7,6 @@ export type { PopoverProps } from './components/atoms/Popover'
|
|
|
7
7
|
export { default as TextArea } from './components/atoms/TextArea'
|
|
8
8
|
export type { TextAreaProps } from './components/atoms/TextArea'
|
|
9
9
|
|
|
10
|
-
export { default as Slider } from './components/atoms/Slider'
|
|
11
|
-
export type { SliderProps } from './components/atoms/Slider'
|
|
12
|
-
|
|
13
10
|
export { default as Skeleton } from './components/atoms/Skeleton'
|
|
14
11
|
export type { SkeletonProps } from './components/atoms/Skeleton'
|
|
15
12
|
|
|
@@ -105,9 +102,6 @@ export type { PaymentMethodsProps } from './components/molecules/PaymentMethods'
|
|
|
105
102
|
export { default as Breadcrumb } from './components/molecules/Breadcrumb'
|
|
106
103
|
export type { BreadcrumbProps } from './components/molecules/Breadcrumb'
|
|
107
104
|
|
|
108
|
-
export { default as PriceRange } from './components/molecules/PriceRange'
|
|
109
|
-
export type { PriceRangeProps } from './components/molecules/PriceRange'
|
|
110
|
-
|
|
111
105
|
export { default as Form } from './components/molecules/Form'
|
|
112
106
|
export type { FormProps } from './components/molecules/Form'
|
|
113
107
|
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
@import "../components/atoms/Price/styles";
|
|
12
12
|
@import "../components/atoms/Radio/styles";
|
|
13
13
|
@import "../components/atoms/Select/styles";
|
|
14
|
+
@import "../components/atoms/Slider/styles";
|
|
14
15
|
@import "../components/atoms/SROnly/styles";
|
|
15
16
|
|
|
16
17
|
// Molecules
|
|
@@ -34,3 +35,4 @@
|
|
|
34
35
|
|
|
35
36
|
// Organisms
|
|
36
37
|
@import "../components/organisms/Hero/styles";
|
|
38
|
+
@import "../components/organisms/PriceRange/styles";
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This code is inspired by the work of [sandra-lewis](https://codesandbox.io/u/sandra-lewis)
|
|
3
|
-
*/
|
|
4
|
-
import React from 'react';
|
|
5
|
-
import type { ReactNode } from 'react';
|
|
6
|
-
interface Range {
|
|
7
|
-
absolute: number;
|
|
8
|
-
selected: number;
|
|
9
|
-
}
|
|
10
|
-
export type SliderProps = {
|
|
11
|
-
/**
|
|
12
|
-
* The minimum value of the slider.
|
|
13
|
-
*/
|
|
14
|
-
min: Range;
|
|
15
|
-
/**
|
|
16
|
-
* The maximum value of the slider.
|
|
17
|
-
*/
|
|
18
|
-
max: Range;
|
|
19
|
-
/**
|
|
20
|
-
* Specifies the number interval to be used in the inputs.
|
|
21
|
-
*/
|
|
22
|
-
step?: number;
|
|
23
|
-
/**
|
|
24
|
-
* ID to find this component in testing tools (e.g.: cypress, testing library, and jest).
|
|
25
|
-
*
|
|
26
|
-
* @default 'store-slider'
|
|
27
|
-
*/
|
|
28
|
-
testId?: string;
|
|
29
|
-
/**
|
|
30
|
-
* Callback that fires when the slider value changes.
|
|
31
|
-
*/
|
|
32
|
-
onChange?: (value: {
|
|
33
|
-
min: number;
|
|
34
|
-
max: number;
|
|
35
|
-
}) => void;
|
|
36
|
-
/**
|
|
37
|
-
* Callback that fires when the slider value ends changing.
|
|
38
|
-
*/
|
|
39
|
-
onEnd?: (value: {
|
|
40
|
-
min: number;
|
|
41
|
-
max: number;
|
|
42
|
-
}) => void;
|
|
43
|
-
/**
|
|
44
|
-
* A function used to set a human-readable value text based on the slider's current value.
|
|
45
|
-
*/
|
|
46
|
-
getAriaValueText?(value: number, thumb?: 'min' | 'max'): string;
|
|
47
|
-
/**
|
|
48
|
-
* Returns the value of element's class content attribute.
|
|
49
|
-
*/
|
|
50
|
-
className?: string;
|
|
51
|
-
/**
|
|
52
|
-
* Component that renders min value label above the left thumb.
|
|
53
|
-
*/
|
|
54
|
-
minValueLabelComponent?: (minValue: number) => ReactNode;
|
|
55
|
-
/**
|
|
56
|
-
* Component that renders max value label above the right thumb.
|
|
57
|
-
*/
|
|
58
|
-
maxValueLabelComponent?: (maxValue: number) => ReactNode;
|
|
59
|
-
};
|
|
60
|
-
type SliderRefType = {
|
|
61
|
-
setSliderValues: (values: {
|
|
62
|
-
min: number;
|
|
63
|
-
max: number;
|
|
64
|
-
}) => void;
|
|
65
|
-
};
|
|
66
|
-
declare const Slider: React.ForwardRefExoticComponent<SliderProps & React.RefAttributes<SliderRefType | undefined>>;
|
|
67
|
-
export default Slider;
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This code is inspired by the work of [sandra-lewis](https://codesandbox.io/u/sandra-lewis)
|
|
3
|
-
*/
|
|
4
|
-
import React, { useState, useMemo, useImperativeHandle, forwardRef, } from 'react';
|
|
5
|
-
const percent = (value, min, max) => Math.round(((value - min) / (max - min)) * 100);
|
|
6
|
-
const Slider = forwardRef(function Slider({ min, max, onChange, onEnd, testId = 'store-slider', getAriaValueText, className, step, minValueLabelComponent, maxValueLabelComponent, }, ref) {
|
|
7
|
-
const widthPercent = useMemo(() => (max.absolute - min.absolute) / 100, [max.absolute, min.absolute]);
|
|
8
|
-
const [minPercent, setMinPercent] = useState(() => percent(min.selected, min.absolute, max.absolute));
|
|
9
|
-
const [maxPercent, setMaxPercent] = useState(() => percent(max.selected, min.absolute, max.absolute));
|
|
10
|
-
const [minVal, setMinVal] = useState(() => Math.round(min.absolute + minPercent * widthPercent));
|
|
11
|
-
const [maxVal, setMaxVal] = useState(() => Math.round(min.absolute + maxPercent * widthPercent));
|
|
12
|
-
useImperativeHandle(ref, () => ({
|
|
13
|
-
setSliderValues: (values) => {
|
|
14
|
-
const sliderMinValue = Math.min(Number(values.min), maxVal);
|
|
15
|
-
setMinVal(sliderMinValue);
|
|
16
|
-
setMinPercent(percent(sliderMinValue, min.absolute, max.absolute));
|
|
17
|
-
if (values.max > max.absolute) {
|
|
18
|
-
setMaxVal(max.absolute);
|
|
19
|
-
setMaxPercent(percent(max.absolute, min.absolute, max.absolute));
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
const sliderMaxValue = Math.max(Number(values.max), minVal);
|
|
23
|
-
setMaxVal(sliderMaxValue);
|
|
24
|
-
setMaxPercent(percent(sliderMaxValue, min.absolute, max.absolute));
|
|
25
|
-
},
|
|
26
|
-
}));
|
|
27
|
-
return (React.createElement("div", { "data-fs-slider": true, "data-testid": testId, className: className },
|
|
28
|
-
React.createElement("div", { "data-slider-range": true, style: {
|
|
29
|
-
left: `${minPercent}%`,
|
|
30
|
-
width: `${maxPercent - minPercent}%`,
|
|
31
|
-
} }),
|
|
32
|
-
React.createElement("input", { type: "range", min: Math.round(min.absolute), max: Math.round(max.absolute), value: minVal, step: step, onMouseUp: () => onEnd?.({ min: minVal, max: maxVal }), onTouchEnd: () => onEnd?.({ min: minVal, max: maxVal }), onChange: (event) => {
|
|
33
|
-
const minValue = Math.min(Number(event.target.value), maxVal);
|
|
34
|
-
setMinVal(minValue);
|
|
35
|
-
setMinPercent(percent(minValue, min.absolute, max.absolute));
|
|
36
|
-
onChange?.({ min: minValue, max: maxVal });
|
|
37
|
-
}, "data-slider-thumb": "left", "aria-valuemin": min.absolute, "aria-valuemax": max.absolute, "aria-valuenow": minVal, "aria-label": String(minVal), "aria-labelledby": getAriaValueText?.(minVal, 'min') }),
|
|
38
|
-
minValueLabelComponent && minValueLabelComponent(minVal),
|
|
39
|
-
React.createElement("input", { type: "range", min: Math.round(min.absolute), max: Math.round(max.absolute), value: maxVal, step: step, onMouseUp: () => onEnd?.({ min: minVal, max: maxVal }), onTouchEnd: () => onEnd?.({ min: minVal, max: maxVal }), onChange: (event) => {
|
|
40
|
-
const maxValue = Math.max(Number(event.target.value), minVal);
|
|
41
|
-
setMaxVal(maxValue);
|
|
42
|
-
setMaxPercent(percent(maxValue, min.absolute, max.absolute));
|
|
43
|
-
onChange?.({ min: minVal, max: maxValue });
|
|
44
|
-
}, "data-slider-thumb": "right", "aria-valuemin": min.absolute, "aria-valuemax": max.absolute, "aria-valuenow": maxVal, "aria-label": String(maxVal), "aria-labelledby": getAriaValueText?.(maxVal, 'max') }),
|
|
45
|
-
maxValueLabelComponent && maxValueLabelComponent(maxVal)));
|
|
46
|
-
});
|
|
47
|
-
export default Slider;
|
|
48
|
-
//# sourceMappingURL=Slider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Slider.js","sourceRoot":"","sources":["../../../../src/components/atoms/Slider/Slider.tsx"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,EACZ,QAAQ,EACR,OAAO,EACP,mBAAmB,EACnB,UAAU,GACX,MAAM,OAAO,CAAA;AAyDd,MAAM,OAAO,GAAG,CAAC,KAAa,EAAE,GAAW,EAAE,GAAW,EAAE,EAAE,CAC1D,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,G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E,MAAM,EAAE,CAAC,EACvD,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE;gBAClB,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,CAAA;gBAE7D,SAAS,CAAC,QAAQ,CAAC,CAAA;gBACnB,aAAa,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAA;gBAC5D,QAAQ,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,CAAA;YAC5C,CAAC,uBACiB,OAAO,mBACV,GAAG,CAAC,QAAQ,mBACZ,GAAG,CAAC,QAAQ,mBACZ,MAAM,gBACT,MAAM,CAAC,MAAM,CAAC,qBACT,gBAAgB,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC,GAClD;QACD,sBAAsB,IAAI,sBAAsB,CAAC,MAAM,CAAC,CACrD,CACP,CAAA;AACH,CAAC,CACF,CAAA;AAED,eAAe,MAAM,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/atoms/Slider/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA"}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import type { AriaAttributes } from 'react';
|
|
3
|
-
import type { PriceProps } from '@faststore/components';
|
|
4
|
-
import type { SliderProps } from '../../atoms/Slider';
|
|
5
|
-
export type PriceRangeProps = SliderProps & {
|
|
6
|
-
/**
|
|
7
|
-
* The current use case variant for prices.
|
|
8
|
-
*/
|
|
9
|
-
variant?: PriceProps['variant'];
|
|
10
|
-
/**
|
|
11
|
-
* Formatter function that transforms the raw price value and render the result.
|
|
12
|
-
*/
|
|
13
|
-
formatter: PriceProps['formatter'];
|
|
14
|
-
/**
|
|
15
|
-
* Returns the value of element's class content attribute.
|
|
16
|
-
*/
|
|
17
|
-
className?: string;
|
|
18
|
-
/**
|
|
19
|
-
* Defines a string value that labels the current element.
|
|
20
|
-
*/
|
|
21
|
-
'aria-label'?: AriaAttributes['aria-label'];
|
|
22
|
-
};
|
|
23
|
-
type PriceRangeRefType = {
|
|
24
|
-
setPriceRangeValues: (values: {
|
|
25
|
-
min: number;
|
|
26
|
-
max: number;
|
|
27
|
-
}) => void;
|
|
28
|
-
};
|
|
29
|
-
declare const PriceRange: React.ForwardRefExoticComponent<SliderProps & {
|
|
30
|
-
/**
|
|
31
|
-
* The current use case variant for prices.
|
|
32
|
-
*/
|
|
33
|
-
variant?: PriceProps['variant'];
|
|
34
|
-
/**
|
|
35
|
-
* Formatter function that transforms the raw price value and render the result.
|
|
36
|
-
*/
|
|
37
|
-
formatter: PriceProps['formatter'];
|
|
38
|
-
/**
|
|
39
|
-
* Returns the value of element's class content attribute.
|
|
40
|
-
*/
|
|
41
|
-
className?: string | undefined;
|
|
42
|
-
/**
|
|
43
|
-
* Defines a string value that labels the current element.
|
|
44
|
-
*/
|
|
45
|
-
'aria-label'?: AriaAttributes['aria-label'];
|
|
46
|
-
} & React.RefAttributes<PriceRangeRefType | undefined>>;
|
|
47
|
-
export default PriceRange;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import React, { useRef, useImperativeHandle, forwardRef } from 'react';
|
|
2
|
-
import { Price } from '@faststore/components';
|
|
3
|
-
import Slider from '../../atoms/Slider';
|
|
4
|
-
const PriceRange = forwardRef(function PriceRange({ className, formatter, max, min, step, onChange, onEnd, testId = 'store-price-range', variant, 'aria-label': ariaLabel, }, ref) {
|
|
5
|
-
const sliderRef = useRef();
|
|
6
|
-
useImperativeHandle(ref, () => ({
|
|
7
|
-
setPriceRangeValues: (values) => {
|
|
8
|
-
onChange?.(values);
|
|
9
|
-
sliderRef.current?.setSliderValues(values);
|
|
10
|
-
},
|
|
11
|
-
}));
|
|
12
|
-
return (React.createElement("div", { "data-fs-price-range": true, "data-testid": testId, className: className },
|
|
13
|
-
React.createElement(Slider, { ref: sliderRef, min: min, max: max, step: step, onEnd: onEnd, "aria-label": ariaLabel, onChange: (value) => onChange?.(value), minValueLabelComponent: (minValue) => {
|
|
14
|
-
const minPercent = (minValue / max.absolute) * 100;
|
|
15
|
-
return (React.createElement(Price, { value: minValue, variant: variant, formatter: formatter, "data-price-range-value-label": "min", style: {
|
|
16
|
-
position: 'absolute',
|
|
17
|
-
left: `calc(${minPercent}% + (${8 - minPercent * 0.2}px))`,
|
|
18
|
-
} }));
|
|
19
|
-
}, maxValueLabelComponent: (maxValue) => {
|
|
20
|
-
const maxPercent = (maxValue / max.absolute) * 100;
|
|
21
|
-
return (React.createElement(Price, { formatter: formatter, variant: variant, value: maxValue, "data-price-range-value-label": "max", style: {
|
|
22
|
-
position: 'absolute',
|
|
23
|
-
left: `calc(${maxPercent}% + (${8 - maxPercent * 0.2}px))`,
|
|
24
|
-
} }));
|
|
25
|
-
} })));
|
|
26
|
-
});
|
|
27
|
-
export default PriceRange;
|
|
28
|
-
//# sourceMappingURL=PriceRange.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PriceRange.js","sourceRoot":"","sources":["../../../../src/components/molecules/PriceRange/PriceRange.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,MAAM,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAGtE,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAA;AAG7C,OAAO,MAAM,MAAM,oBAAoB,CAAA;AA0BvC,MAAM,UAAU,GAAG,UAAU,CAC3B,SAAS,UAAU,CACjB,EACE,SAAS,EACT,SAAS,EACT,GAAG,EACH,GAAG,EACH,IAAI,EACJ,QAAQ,EACR,KAAK,EACL,MAAM,GAAG,mBAAmB,EAC5B,OAAO,EACP,YAAY,EAA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Q,kCACc,KAAK,EAClC,KAAK,EAAE;wBACL,QAAQ,EAAE,UAAU;wBACpB,IAAI,EAAE,QAAQ,UAAU,QAAQ,CAAC,GAAG,UAAU,GAAG,GAAG,MAAM;qBAC3D,GACD,CACH,CAAA;YACH,CAAC,GACD,CACE,CACP,CAAA;AACH,CAAC,CACF,CAAA;AAED,eAAe,UAAU,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/molecules/PriceRange/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA"}
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This code is inspired by the work of [sandra-lewis](https://codesandbox.io/u/sandra-lewis)
|
|
3
|
-
*/
|
|
4
|
-
import React, {
|
|
5
|
-
useState,
|
|
6
|
-
useMemo,
|
|
7
|
-
useImperativeHandle,
|
|
8
|
-
forwardRef,
|
|
9
|
-
} from 'react'
|
|
10
|
-
import type { ReactNode } from 'react'
|
|
11
|
-
|
|
12
|
-
interface Range {
|
|
13
|
-
absolute: number
|
|
14
|
-
selected: number
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export type SliderProps = {
|
|
18
|
-
/**
|
|
19
|
-
* The minimum value of the slider.
|
|
20
|
-
*/
|
|
21
|
-
min: Range
|
|
22
|
-
/**
|
|
23
|
-
* The maximum value of the slider.
|
|
24
|
-
*/
|
|
25
|
-
max: Range
|
|
26
|
-
/**
|
|
27
|
-
* Specifies the number interval to be used in the inputs.
|
|
28
|
-
*/
|
|
29
|
-
step?: number
|
|
30
|
-
/**
|
|
31
|
-
* ID to find this component in testing tools (e.g.: cypress, testing library, and jest).
|
|
32
|
-
*
|
|
33
|
-
* @default 'store-slider'
|
|
34
|
-
*/
|
|
35
|
-
testId?: string
|
|
36
|
-
/**
|
|
37
|
-
* Callback that fires when the slider value changes.
|
|
38
|
-
*/
|
|
39
|
-
onChange?: (value: { min: number; max: number }) => void
|
|
40
|
-
/**
|
|
41
|
-
* Callback that fires when the slider value ends changing.
|
|
42
|
-
*/
|
|
43
|
-
onEnd?: (value: { min: number; max: number }) => void
|
|
44
|
-
/**
|
|
45
|
-
* A function used to set a human-readable value text based on the slider's current value.
|
|
46
|
-
*/
|
|
47
|
-
getAriaValueText?(value: number, thumb?: 'min' | 'max'): string
|
|
48
|
-
/**
|
|
49
|
-
* Returns the value of element's class content attribute.
|
|
50
|
-
*/
|
|
51
|
-
className?: string
|
|
52
|
-
/**
|
|
53
|
-
* Component that renders min value label above the left thumb.
|
|
54
|
-
*/
|
|
55
|
-
minValueLabelComponent?: (minValue: number) => ReactNode
|
|
56
|
-
/**
|
|
57
|
-
* Component that renders max value label above the right thumb.
|
|
58
|
-
*/
|
|
59
|
-
maxValueLabelComponent?: (maxValue: number) => ReactNode
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
type SliderRefType = {
|
|
63
|
-
setSliderValues: (values: { min: number; max: number }) => void
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const percent = (value: number, min: number, max: number) =>
|
|
67
|
-
Math.round(((value - min) / (max - min)) * 100)
|
|
68
|
-
|
|
69
|
-
const Slider = forwardRef<SliderRefType | undefined, SliderProps>(
|
|
70
|
-
function Slider(
|
|
71
|
-
{
|
|
72
|
-
min,
|
|
73
|
-
max,
|
|
74
|
-
onChange,
|
|
75
|
-
onEnd,
|
|
76
|
-
testId = 'store-slider',
|
|
77
|
-
getAriaValueText,
|
|
78
|
-
className,
|
|
79
|
-
step,
|
|
80
|
-
minValueLabelComponent,
|
|
81
|
-
maxValueLabelComponent,
|
|
82
|
-
},
|
|
83
|
-
ref
|
|
84
|
-
) {
|
|
85
|
-
const widthPercent = useMemo(
|
|
86
|
-
() => (max.absolute - min.absolute) / 100,
|
|
87
|
-
[max.absolute, min.absolute]
|
|
88
|
-
)
|
|
89
|
-
const [minPercent, setMinPercent] = useState(() =>
|
|
90
|
-
percent(min.selected, min.absolute, max.absolute)
|
|
91
|
-
)
|
|
92
|
-
|
|
93
|
-
const [maxPercent, setMaxPercent] = useState(() =>
|
|
94
|
-
percent(max.selected, min.absolute, max.absolute)
|
|
95
|
-
)
|
|
96
|
-
|
|
97
|
-
const [minVal, setMinVal] = useState(() =>
|
|
98
|
-
Math.round(min.absolute + minPercent * widthPercent)
|
|
99
|
-
)
|
|
100
|
-
const [maxVal, setMaxVal] = useState(() =>
|
|
101
|
-
Math.round(min.absolute + maxPercent * widthPercent)
|
|
102
|
-
)
|
|
103
|
-
|
|
104
|
-
useImperativeHandle(ref, () => ({
|
|
105
|
-
setSliderValues: (values: { min: number; max: number }) => {
|
|
106
|
-
const sliderMinValue = Math.min(Number(values.min), maxVal)
|
|
107
|
-
setMinVal(sliderMinValue)
|
|
108
|
-
setMinPercent(percent(sliderMinValue, min.absolute, max.absolute))
|
|
109
|
-
|
|
110
|
-
if (values.max > max.absolute) {
|
|
111
|
-
setMaxVal(max.absolute)
|
|
112
|
-
setMaxPercent(percent(max.absolute, min.absolute, max.absolute))
|
|
113
|
-
return
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const sliderMaxValue = Math.max(Number(values.max), minVal)
|
|
117
|
-
setMaxVal(sliderMaxValue)
|
|
118
|
-
setMaxPercent(percent(sliderMaxValue, min.absolute, max.absolute))
|
|
119
|
-
},
|
|
120
|
-
}))
|
|
121
|
-
|
|
122
|
-
return (
|
|
123
|
-
<div data-fs-slider data-testid={testId} className={className}>
|
|
124
|
-
<div
|
|
125
|
-
data-slider-range
|
|
126
|
-
style={{
|
|
127
|
-
left: `${minPercent}%`,
|
|
128
|
-
width: `${maxPercent - minPercent}%`,
|
|
129
|
-
}}
|
|
130
|
-
/>
|
|
131
|
-
<input
|
|
132
|
-
type="range"
|
|
133
|
-
min={Math.round(min.absolute)}
|
|
134
|
-
max={Math.round(max.absolute)}
|
|
135
|
-
value={minVal}
|
|
136
|
-
step={step}
|
|
137
|
-
onMouseUp={() => onEnd?.({ min: minVal, max: maxVal })}
|
|
138
|
-
onTouchEnd={() => onEnd?.({ min: minVal, max: maxVal })}
|
|
139
|
-
onChange={(event) => {
|
|
140
|
-
const minValue = Math.min(Number(event.target.value), maxVal)
|
|
141
|
-
|
|
142
|
-
setMinVal(minValue)
|
|
143
|
-
setMinPercent(percent(minValue, min.absolute, max.absolute))
|
|
144
|
-
onChange?.({ min: minValue, max: maxVal })
|
|
145
|
-
}}
|
|
146
|
-
data-slider-thumb="left"
|
|
147
|
-
aria-valuemin={min.absolute}
|
|
148
|
-
aria-valuemax={max.absolute}
|
|
149
|
-
aria-valuenow={minVal}
|
|
150
|
-
aria-label={String(minVal)}
|
|
151
|
-
aria-labelledby={getAriaValueText?.(minVal, 'min')}
|
|
152
|
-
/>
|
|
153
|
-
{minValueLabelComponent && minValueLabelComponent(minVal)}
|
|
154
|
-
<input
|
|
155
|
-
type="range"
|
|
156
|
-
min={Math.round(min.absolute)}
|
|
157
|
-
max={Math.round(max.absolute)}
|
|
158
|
-
value={maxVal}
|
|
159
|
-
step={step}
|
|
160
|
-
onMouseUp={() => onEnd?.({ min: minVal, max: maxVal })}
|
|
161
|
-
onTouchEnd={() => onEnd?.({ min: minVal, max: maxVal })}
|
|
162
|
-
onChange={(event) => {
|
|
163
|
-
const maxValue = Math.max(Number(event.target.value), minVal)
|
|
164
|
-
|
|
165
|
-
setMaxVal(maxValue)
|
|
166
|
-
setMaxPercent(percent(maxValue, min.absolute, max.absolute))
|
|
167
|
-
onChange?.({ min: minVal, max: maxValue })
|
|
168
|
-
}}
|
|
169
|
-
data-slider-thumb="right"
|
|
170
|
-
aria-valuemin={min.absolute}
|
|
171
|
-
aria-valuemax={max.absolute}
|
|
172
|
-
aria-valuenow={maxVal}
|
|
173
|
-
aria-label={String(maxVal)}
|
|
174
|
-
aria-labelledby={getAriaValueText?.(maxVal, 'max')}
|
|
175
|
-
/>
|
|
176
|
-
{maxValueLabelComponent && maxValueLabelComponent(maxVal)}
|
|
177
|
-
</div>
|
|
178
|
-
)
|
|
179
|
-
}
|
|
180
|
-
)
|
|
181
|
-
|
|
182
|
-
export default Slider
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import React, { useRef, useImperativeHandle, forwardRef } from 'react'
|
|
2
|
-
import type { AriaAttributes } from 'react'
|
|
3
|
-
|
|
4
|
-
import { Price } from '@faststore/components'
|
|
5
|
-
import type { PriceProps } from '@faststore/components'
|
|
6
|
-
|
|
7
|
-
import Slider from '../../atoms/Slider'
|
|
8
|
-
import type { SliderProps } from '../../atoms/Slider'
|
|
9
|
-
|
|
10
|
-
export type PriceRangeProps = SliderProps & {
|
|
11
|
-
/**
|
|
12
|
-
* The current use case variant for prices.
|
|
13
|
-
*/
|
|
14
|
-
variant?: PriceProps['variant']
|
|
15
|
-
/**
|
|
16
|
-
* Formatter function that transforms the raw price value and render the result.
|
|
17
|
-
*/
|
|
18
|
-
formatter: PriceProps['formatter']
|
|
19
|
-
/**
|
|
20
|
-
* Returns the value of element's class content attribute.
|
|
21
|
-
*/
|
|
22
|
-
className?: string
|
|
23
|
-
/**
|
|
24
|
-
* Defines a string value that labels the current element.
|
|
25
|
-
*/
|
|
26
|
-
'aria-label'?: AriaAttributes['aria-label']
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
type PriceRangeRefType = {
|
|
30
|
-
setPriceRangeValues: (values: { min: number; max: number }) => void
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const PriceRange = forwardRef<PriceRangeRefType | undefined, PriceRangeProps>(
|
|
34
|
-
function PriceRange(
|
|
35
|
-
{
|
|
36
|
-
className,
|
|
37
|
-
formatter,
|
|
38
|
-
max,
|
|
39
|
-
min,
|
|
40
|
-
step,
|
|
41
|
-
onChange,
|
|
42
|
-
onEnd,
|
|
43
|
-
testId = 'store-price-range',
|
|
44
|
-
variant,
|
|
45
|
-
'aria-label': ariaLabel,
|
|
46
|
-
},
|
|
47
|
-
ref
|
|
48
|
-
) {
|
|
49
|
-
const sliderRef = useRef<{
|
|
50
|
-
setSliderValues: (values: { min: number; max: number }) => void
|
|
51
|
-
}>()
|
|
52
|
-
|
|
53
|
-
useImperativeHandle(ref, () => ({
|
|
54
|
-
setPriceRangeValues: (values: { min: number; max: number }) => {
|
|
55
|
-
onChange?.(values)
|
|
56
|
-
sliderRef.current?.setSliderValues(values)
|
|
57
|
-
},
|
|
58
|
-
}))
|
|
59
|
-
|
|
60
|
-
return (
|
|
61
|
-
<div data-fs-price-range data-testid={testId} className={className}>
|
|
62
|
-
<Slider
|
|
63
|
-
ref={sliderRef}
|
|
64
|
-
min={min}
|
|
65
|
-
max={max}
|
|
66
|
-
step={step}
|
|
67
|
-
onEnd={onEnd}
|
|
68
|
-
aria-label={ariaLabel}
|
|
69
|
-
onChange={(value) => onChange?.(value)}
|
|
70
|
-
minValueLabelComponent={(minValue) => {
|
|
71
|
-
const minPercent = (minValue / max.absolute) * 100
|
|
72
|
-
|
|
73
|
-
return (
|
|
74
|
-
<Price
|
|
75
|
-
value={minValue}
|
|
76
|
-
variant={variant}
|
|
77
|
-
formatter={formatter}
|
|
78
|
-
data-price-range-value-label="min"
|
|
79
|
-
style={{
|
|
80
|
-
position: 'absolute',
|
|
81
|
-
left: `calc(${minPercent}% + (${8 - minPercent * 0.2}px))`,
|
|
82
|
-
}}
|
|
83
|
-
/>
|
|
84
|
-
)
|
|
85
|
-
}}
|
|
86
|
-
maxValueLabelComponent={(maxValue) => {
|
|
87
|
-
const maxPercent = (maxValue / max.absolute) * 100
|
|
88
|
-
|
|
89
|
-
return (
|
|
90
|
-
<Price
|
|
91
|
-
formatter={formatter}
|
|
92
|
-
variant={variant}
|
|
93
|
-
value={maxValue}
|
|
94
|
-
data-price-range-value-label="max"
|
|
95
|
-
style={{
|
|
96
|
-
position: 'absolute',
|
|
97
|
-
left: `calc(${maxPercent}% + (${8 - maxPercent * 0.2}px))`,
|
|
98
|
-
}}
|
|
99
|
-
/>
|
|
100
|
-
)
|
|
101
|
-
}}
|
|
102
|
-
/>
|
|
103
|
-
</div>
|
|
104
|
-
)
|
|
105
|
-
}
|
|
106
|
-
)
|
|
107
|
-
|
|
108
|
-
export default PriceRange
|