@toptal/picasso-slider 4.0.6-alpha-1757603192867.0 → 4.0.6-alpha-FF-49-enhance-publishing-6b5d306f0.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-package/src/Slider/Slider.d.ts +47 -0
- package/dist-package/src/Slider/Slider.d.ts.map +1 -0
- package/dist-package/src/Slider/Slider.js +64 -0
- package/dist-package/src/Slider/Slider.js.map +1 -0
- package/dist-package/src/Slider/hooks/index.d.ts +2 -0
- package/dist-package/src/Slider/hooks/index.d.ts.map +1 -0
- package/dist-package/src/Slider/hooks/index.js +2 -0
- package/dist-package/src/Slider/hooks/index.js.map +1 -0
- package/dist-package/src/Slider/hooks/use-label-overlap.d.ts +9 -0
- package/dist-package/src/Slider/hooks/use-label-overlap.d.ts.map +1 -0
- package/dist-package/src/Slider/hooks/use-label-overlap.js +41 -0
- package/dist-package/src/Slider/hooks/use-label-overlap.js.map +1 -0
- package/dist-package/src/Slider/index.d.ts +5 -0
- package/dist-package/src/Slider/index.d.ts.map +1 -0
- package/dist-package/src/Slider/index.js +2 -0
- package/dist-package/src/Slider/index.js.map +1 -0
- package/dist-package/src/SliderMark/SliderMark.d.ts +13 -0
- package/dist-package/src/SliderMark/SliderMark.d.ts.map +1 -0
- package/dist-package/src/SliderMark/SliderMark.js +10 -0
- package/dist-package/src/SliderMark/SliderMark.js.map +1 -0
- package/dist-package/src/SliderMark/index.d.ts +2 -0
- package/dist-package/src/SliderMark/index.d.ts.map +1 -0
- package/dist-package/src/SliderMark/index.js +2 -0
- package/dist-package/src/SliderMark/index.js.map +1 -0
- package/dist-package/src/SliderValueLabel/SliderValueLabel.d.ts +12 -0
- package/dist-package/src/SliderValueLabel/SliderValueLabel.d.ts.map +1 -0
- package/dist-package/src/SliderValueLabel/SliderValueLabel.js +44 -0
- package/dist-package/src/SliderValueLabel/SliderValueLabel.js.map +1 -0
- package/dist-package/src/SliderValueLabel/index.d.ts +2 -0
- package/dist-package/src/SliderValueLabel/index.d.ts.map +1 -0
- package/dist-package/src/SliderValueLabel/index.js +2 -0
- package/dist-package/src/SliderValueLabel/index.js.map +1 -0
- package/dist-package/src/index.d.ts +2 -0
- package/dist-package/src/index.d.ts.map +1 -0
- package/dist-package/src/index.js +2 -0
- package/dist-package/src/index.js.map +1 -0
- package/dist-package/src/utils/check-bg-color.d.ts +7 -0
- package/dist-package/src/utils/check-bg-color.d.ts.map +1 -0
- package/dist-package/src/utils/check-bg-color.js +15 -0
- package/dist-package/src/utils/check-bg-color.js.map +1 -0
- package/dist-package/src/utils/check-overlap.d.ts +26 -0
- package/dist-package/src/utils/check-overlap.d.ts.map +1 -0
- package/dist-package/src/utils/check-overlap.js +32 -0
- package/dist-package/src/utils/check-overlap.js.map +1 -0
- package/dist-package/src/utils/get-x-placement.d.ts +8 -0
- package/dist-package/src/utils/get-x-placement.d.ts.map +1 -0
- package/dist-package/src/utils/get-x-placement.js +17 -0
- package/dist-package/src/utils/get-x-placement.js.map +1 -0
- package/dist-package/src/utils/index.d.ts +4 -0
- package/dist-package/src/utils/index.d.ts.map +1 -0
- package/dist-package/src/utils/index.js +4 -0
- package/dist-package/src/utils/index.js.map +1 -0
- package/package.json +9 -9
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { BaseProps } from '@toptal/picasso-shared';
|
|
3
|
+
export interface Props extends BaseProps {
|
|
4
|
+
/** Minimum slider value */
|
|
5
|
+
min?: number;
|
|
6
|
+
/** Maximum slider value */
|
|
7
|
+
max?: number;
|
|
8
|
+
/** Controlled value of the component */
|
|
9
|
+
value?: number | number[];
|
|
10
|
+
/** The default value. Use when the component is not controlled */
|
|
11
|
+
defaultValue?: number | number[];
|
|
12
|
+
/** Step for the thumb movement */
|
|
13
|
+
step?: number;
|
|
14
|
+
/** Whether marks are shown or not */
|
|
15
|
+
marks?: boolean;
|
|
16
|
+
/** Whether component is disabled or not */
|
|
17
|
+
disabled?: boolean;
|
|
18
|
+
/** Controls when tooltip is displayed:
|
|
19
|
+
- **auto** the value tooltip will display when the thumb is hovered or focused.
|
|
20
|
+
- **on** will display persistently.
|
|
21
|
+
- **off** will never display
|
|
22
|
+
*/
|
|
23
|
+
tooltip?: 'on' | 'auto' | 'off';
|
|
24
|
+
/** The format function the value tooltip's value. */
|
|
25
|
+
tooltipFormat?: string | ((value: number, index: number) => React.ReactNode);
|
|
26
|
+
/** Callback invoked when slider changes its state. */
|
|
27
|
+
onChange?: (event: Event, value: number | number[], activeThumb: number) => void;
|
|
28
|
+
/** Callback invoked on focus */
|
|
29
|
+
onFocus?: (event: React.FocusEvent<HTMLElement>) => void;
|
|
30
|
+
/** Callback invoked on blur */
|
|
31
|
+
onBlur?: (event: React.FocusEvent<HTMLElement>) => void;
|
|
32
|
+
/** Hide thumb when value is undefined or null. Works only when the component is controlled. */
|
|
33
|
+
hideThumbOnEmpty?: boolean;
|
|
34
|
+
/** Disable track highlight. */
|
|
35
|
+
disableTrackHighlight?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Name attribute of the `input` element.
|
|
38
|
+
*/
|
|
39
|
+
name?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Id attribute of the `input` element.
|
|
42
|
+
*/
|
|
43
|
+
id?: string;
|
|
44
|
+
}
|
|
45
|
+
export declare const Slider: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLElement>>;
|
|
46
|
+
export default Slider;
|
|
47
|
+
//# sourceMappingURL=Slider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Slider.d.ts","sourceRoot":"","sources":["../../../src/Slider/Slider.tsx"],"names":[],"mappings":"AACA,OAAO,KAA6B,MAAM,OAAO,CAAA;AAIjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAMvD,MAAM,WAAW,KAAM,SAAQ,SAAS;IACtC,2BAA2B;IAC3B,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,2BA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// import type { ComponentProps } from 'react'
|
|
2
|
+
import React, { forwardRef, useRef } from 'react';
|
|
3
|
+
import { Slider as MUIBaseSlider } from '@mui/base/Slider';
|
|
4
|
+
import { useCombinedRefs, useOnScreen } from '@toptal/picasso-utils';
|
|
5
|
+
import { twJoin, twMerge } from '@toptal/picasso-tailwind-merge';
|
|
6
|
+
import SliderMark from '../SliderMark';
|
|
7
|
+
import SliderValueLabel from '../SliderValueLabel';
|
|
8
|
+
import { useLabelOverlap } from './hooks';
|
|
9
|
+
export const Slider = forwardRef(function Slider(props, ref) {
|
|
10
|
+
const { min, max, marks, value, defaultValue = 0, tooltip = 'off', tooltipFormat, step, disabled, onChange, onBlur, onFocus, hideThumbOnEmpty, disableTrackHighlight, className, style, name, id, 'data-private': dataPrivate, 'data-testid': dataTestid, } = props;
|
|
11
|
+
const containerRef = useRef(null);
|
|
12
|
+
const sliderRef = useCombinedRefs(ref, useRef(null));
|
|
13
|
+
// The rootMargin is not working correctly in the storybooks iframe
|
|
14
|
+
// To test properly we can open the iframe in new window
|
|
15
|
+
const { isOnScreen, isObserved } = useOnScreen({
|
|
16
|
+
ref: containerRef,
|
|
17
|
+
rootMargin: '-24px 0px 0px 0px',
|
|
18
|
+
threshold: 1,
|
|
19
|
+
});
|
|
20
|
+
const { isPartiallyOverlapped, handleValueLabelOnRender } = useLabelOverlap({
|
|
21
|
+
value,
|
|
22
|
+
// until IntersectionObserver starts observing the element, we don't render the tooltip
|
|
23
|
+
isTooltipRendered: isObserved,
|
|
24
|
+
});
|
|
25
|
+
const isThumbHidden = hideThumbOnEmpty && (typeof value === 'undefined' || value === null);
|
|
26
|
+
return (React.createElement("div", { ref: containerRef, className: twMerge('my-[6px] mx-0', className), style: style },
|
|
27
|
+
React.createElement(MUIBaseSlider, { ref: sliderRef, defaultValue: defaultValue, value: value, min: min, max: max, step: step, marks: marks, disabled: disabled, "data-testid": dataTestid, "data-private": dataPrivate, onFocus: onFocus, onBlur: onBlur, name: name, id: id, slots: {
|
|
28
|
+
mark: SliderMark,
|
|
29
|
+
valueLabel: SliderValueLabel,
|
|
30
|
+
}, slotProps: {
|
|
31
|
+
mark: {
|
|
32
|
+
// @ts-expect-error we have custom Mark component, where we extend props and MUI does not understand it
|
|
33
|
+
forceInactive: disableTrackHighlight,
|
|
34
|
+
},
|
|
35
|
+
root: {
|
|
36
|
+
className: 'block cursor-pointer width-full relative py-[6px] -my-[6px]',
|
|
37
|
+
},
|
|
38
|
+
rail: {
|
|
39
|
+
className: 'block absolute w-full h-[1px] opacity-[0.24] rounded-none bg-gray-500',
|
|
40
|
+
},
|
|
41
|
+
thumb: {
|
|
42
|
+
className: twJoin('group/thumb flex justify-center items-center w-[15px] h-[15px]', 'rounded-[50%] bg-blue-500 border-[2px] border-solid border-white', '-mt-[7px] -ml-[6px] outline-0 absolute transition-shadow cursor-pointer', isThumbHidden && 'hidden'),
|
|
43
|
+
role: 'slider',
|
|
44
|
+
},
|
|
45
|
+
track: {
|
|
46
|
+
className: twJoin('block absolute h-[1px]', disableTrackHighlight ? 'bg-gray-200' : 'bg-blue-500'),
|
|
47
|
+
},
|
|
48
|
+
valueLabel: {
|
|
49
|
+
tooltip: isObserved ? tooltip : 'off',
|
|
50
|
+
onRender: handleValueLabelOnRender,
|
|
51
|
+
yPlacement: isOnScreen ? 'top' : 'bottom',
|
|
52
|
+
isOverlaped: isPartiallyOverlapped,
|
|
53
|
+
},
|
|
54
|
+
}, valueLabelFormat: tooltipFormat, onChange: onChange })));
|
|
55
|
+
});
|
|
56
|
+
Slider.displayName = 'Slider';
|
|
57
|
+
Slider.defaultProps = {
|
|
58
|
+
defaultValue: 0,
|
|
59
|
+
min: 0,
|
|
60
|
+
max: 100,
|
|
61
|
+
tooltip: 'off',
|
|
62
|
+
};
|
|
63
|
+
export default Slider;
|
|
64
|
+
//# sourceMappingURL=Slider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Slider.js","sourceRoot":"","sources":["../../../src/Slider/Slider.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C,CAAC,KAAK;oBACrC,QAAQ,EAAE,wBAAwB;oBAClC,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ;oBACzC,WAAW,EAAE,qBAAqB;iBACnC;aACF,EACD,gBAAgB,EAAE,aAAa,EAC/B,QAAQ,EAAE,QAAQ,GAClB,CACE,CACP,CAAA;AACH,CAAC,CAAC,CAAA;AAEF,MAAM,CAAC,WAAW,GAAG,QAAQ,CAAA;AAE7B,MAAM,CAAC,YAAY,GAAG;IACpB,YAAY,EAAE,CAAC;IACf,GAAG,EAAE,CAAC;IACN,GAAG,EAAE,GAAG;IACR,OAAO,EAAE,KAAK;CACf,CAAA;AAED,eAAe,MAAM,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/Slider/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/Slider/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { RefObject } from 'react';
|
|
2
|
+
export declare const useLabelOverlap: ({ value, isTooltipRendered, }: {
|
|
3
|
+
value?: number | number[] | undefined;
|
|
4
|
+
isTooltipRendered: boolean;
|
|
5
|
+
}) => {
|
|
6
|
+
isPartiallyOverlapped: boolean;
|
|
7
|
+
handleValueLabelOnRender: (index: number, labelRef: RefObject<HTMLSpanElement>) => void;
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=use-label-overlap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-label-overlap.d.ts","sourceRoot":"","sources":["../../../../src/Slider/hooks/use-label-overlap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAKtC,eAAO,MAAM,eAAe;;uBAKP,OAAO;;;sCAsChB,MAAM,YAAY,UAAU,eAAe,CAAC;CAWvD,CAAA"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
2
|
+
import { checkOverlap } from '../../utils';
|
|
3
|
+
export const useLabelOverlap = ({ value, isTooltipRendered, }) => {
|
|
4
|
+
const [isPartiallyOverlapped, setIsPartiallyOverlapped] = useState(false);
|
|
5
|
+
const [valueLabels, setValueLabels] = useState([]);
|
|
6
|
+
const isRangeSlider = Array.isArray(value);
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
var _a, _b;
|
|
9
|
+
if (!isRangeSlider || !isTooltipRendered) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const isFullyOverlaped = value[0] === value[1];
|
|
13
|
+
if (isFullyOverlaped) {
|
|
14
|
+
setIsPartiallyOverlapped(false);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
if (!(((_a = valueLabels[0]) === null || _a === void 0 ? void 0 : _a.current) && ((_b = valueLabels[1]) === null || _b === void 0 ? void 0 : _b.current))) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
setIsPartiallyOverlapped(checkOverlap({
|
|
21
|
+
firstLabelRect: valueLabels[0].current.getBoundingClientRect(),
|
|
22
|
+
secondLabelRect: valueLabels[1].current.getBoundingClientRect(),
|
|
23
|
+
previousResult: isPartiallyOverlapped,
|
|
24
|
+
}));
|
|
25
|
+
}
|
|
26
|
+
}, [
|
|
27
|
+
value,
|
|
28
|
+
isRangeSlider,
|
|
29
|
+
isPartiallyOverlapped,
|
|
30
|
+
valueLabels,
|
|
31
|
+
isTooltipRendered,
|
|
32
|
+
]);
|
|
33
|
+
const handleValueLabelOnRender = useCallback((index, labelRef) => {
|
|
34
|
+
setValueLabels(valLabels => {
|
|
35
|
+
valLabels[index] = labelRef;
|
|
36
|
+
return valLabels;
|
|
37
|
+
});
|
|
38
|
+
}, [setValueLabels]);
|
|
39
|
+
return { isPartiallyOverlapped, handleValueLabelOnRender };
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=use-label-overlap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-label-overlap.js","sourceRoot":"","sources":["../../../../src/Slider/hooks/use-label-overlap.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAExD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1C,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,EAC9B,KAAK,EACL,iBAAiB,GAIlB,EAAE,EAAE;IACH,MAAM,CAAC,qBAAqB,EAAE,wBAAwB,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;IACzE,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,QAAQ,CAC5C,EAAE,CACH,CAAA;IACD,MAAM,aAAa,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IAE1C,SAAS,CAAC,GAAG,EAAE;;QACb,IAAI,CAAC,aAAa,IAAI,CAAC,iBAAiB,EAAE;YACxC,OAAM;SACP;QACD,MAAM,gBAAgB,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,CAAA;QAE9C,IAAI,gBAAgB,EAAE;YACpB,wBAAwB,CAAC,KAAK,CAAC,CAAA;SAChC;aAAM;YACL,IAAI,CAAC,CAAC,CAAA,MAAA,WAAW,CAAC,CAAC,CAAC,0CAAE,OAAO,MAAI,MAAA,WAAW,CAAC,CAAC,CAAC,0CAAE,OAAO,CAAA,CAAC,EAAE;gBACzD,OAAM;aACP;YAED,wBAAwB,CACtB,YAAY,CAAC;gBACX,cAAc,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,qBAAqB,EAAE;gBAC9D,eAAe,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,qBAAqB,EAAE;gBAC/D,cAAc,EAAE,qBAAqB;aACtC,CAAC,CACH,CAAA;SACF;IACH,CAAC,EAAE;QACD,KAAK;QACL,aAAa;QACb,qBAAqB;QACrB,WAAW;QACX,iBAAiB;KAClB,CAAC,CAAA;IAEF,MAAM,wBAAwB,GAAG,WAAW,CAC1C,CAAC,KAAa,EAAE,QAAoC,EAAE,EAAE;QACtD,cAAc,CAAC,SAAS,CAAC,EAAE;YACzB,SAAS,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAA;YAE3B,OAAO,SAAS,CAAA;QAClB,CAAC,CAAC,CAAA;IACJ,CAAC,EACD,CAAC,cAAc,CAAC,CACjB,CAAA;IAED,OAAO,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,CAAA;AAC5D,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/Slider/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAE/D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAErC,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,UAAU,CAAA;AAC5C,oBAAY,WAAW,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Slider/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,UAAU,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export declare type SliderMarkProps = {
|
|
3
|
+
markActive: boolean;
|
|
4
|
+
ownerState: {
|
|
5
|
+
value: number;
|
|
6
|
+
};
|
|
7
|
+
style: React.CSSProperties;
|
|
8
|
+
'data-index': number;
|
|
9
|
+
forceInactive: boolean;
|
|
10
|
+
};
|
|
11
|
+
declare const SliderMark: ({ markActive, ownerState, "data-index": dataIndex, style, forceInactive, }: SliderMarkProps) => JSX.Element;
|
|
12
|
+
export default SliderMark;
|
|
13
|
+
//# sourceMappingURL=SliderMark.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SliderMark.d.ts","sourceRoot":"","sources":["../../../src/SliderMark/SliderMark.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAKzB,oBAAY,eAAe,GAAG;IAC5B,UAAU,EAAE,OAAO,CAAA;IACnB,UAAU,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAA;IAC7B,KAAK,EAAE,KAAK,CAAC,aAAa,CAAA;IAC1B,YAAY,EAAE,MAAM,CAAA;IACpB,aAAa,EAAE,OAAO,CAAA;CACvB,CAAA;AAID,QAAA,MAAM,UAAU,+EAMb,eAAe,gBAWjB,CAAA;AAED,eAAe,UAAU,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { twJoin } from '@toptal/picasso-tailwind-merge';
|
|
3
|
+
import { getBgColor } from '../utils';
|
|
4
|
+
// We need custom Mark component because we have
|
|
5
|
+
// different bg color based on value of the Slider
|
|
6
|
+
const SliderMark = ({ markActive, ownerState, 'data-index': dataIndex, style, forceInactive, }) => {
|
|
7
|
+
return (React.createElement("span", { "data-index": dataIndex, style: style, className: twJoin('absolute w-[6px] h-[6px] rounded-[50%] border-[2px] top-[1.5px] border-solid border-white opacity-100 -translate-x-2/4 box-content', getBgColor({ markActive, forceInactive, value: ownerState.value })) }));
|
|
8
|
+
};
|
|
9
|
+
export default SliderMark;
|
|
10
|
+
//# sourceMappingURL=SliderMark.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SliderMark.js","sourceRoot":"","sources":["../../../src/SliderMark/SliderMark.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,MAAM,EAAE,MAAM,gCAAgC,CAAA;AAEvD,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAUrC,gDAAgD;AAChD,kDAAkD;AAClD,MAAM,UAAU,GAAG,CAAC,EAClB,UAAU,EACV,UAAU,EACV,YAAY,EAAE,SAAS,EACvB,KAAK,EACL,aAAa,GACG,EAAE,EAAE;IACpB,OAAO,CACL,4CACc,SAAS,EACrB,KAAK,EAAE,KAAK,EACZ,SAAS,EAAE,MAAM,CACf,oIAAoI,EACpI,UAAU,CAAC,EAAE,UAAU,EAAE,aAAa,EAAE,KAAK,EAAE,UAAU,CAAC,KAAK,EAAE,CAAC,CACnE,GACD,CACH,CAAA;AACH,CAAC,CAAA;AAED,eAAe,UAAU,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/SliderMark/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/SliderMark/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { SliderValueLabelSlotProps } from '@mui/base/Slider';
|
|
2
|
+
import type { RefObject } from 'react';
|
|
3
|
+
declare type ValueLabelDisplay = 'on' | 'auto' | 'off';
|
|
4
|
+
declare const SliderValueLabel: ({ children, index, tooltip, onRender, yPlacement, isOverlaped, ownerState: { value }, }: SliderValueLabelSlotProps & {
|
|
5
|
+
tooltip: ValueLabelDisplay;
|
|
6
|
+
yPlacement: 'top' | 'bottom';
|
|
7
|
+
/** indicates if there are two SliderValueLabels that overlap each other */
|
|
8
|
+
isOverlaped: boolean;
|
|
9
|
+
onRender: (index: number, ref: RefObject<HTMLSpanElement>) => void;
|
|
10
|
+
}) => JSX.Element;
|
|
11
|
+
export default SliderValueLabel;
|
|
12
|
+
//# sourceMappingURL=SliderValueLabel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SliderValueLabel.d.ts","sourceRoot":"","sources":["../../../src/SliderValueLabel/SliderValueLabel.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAA;AACjE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAMtC,aAAK,iBAAiB,GAAG,IAAI,GAAG,MAAM,GAAG,KAAK,CAAA;AAqB9C,QAAA,MAAM,gBAAgB;aASX,iBAAiB;gBACd,KAAK,GAAG,QAAQ;IAC5B,2EAA2E;iBAC9D,OAAO;sBACF,MAAM,OAAO,UAAU,eAAe,CAAC,KAAK,IAAI;iBAkDnE,CAAA;AAED,eAAe,gBAAgB,CAAA"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { twJoin } from '@toptal/picasso-tailwind-merge';
|
|
3
|
+
import { getXPlacement } from '../utils';
|
|
4
|
+
const classesByTooltip = {
|
|
5
|
+
off: 'hidden',
|
|
6
|
+
// We need to use visibility: hidden instead of display: none to keep the
|
|
7
|
+
// label visible for javascript calculations.
|
|
8
|
+
auto: 'invisible group-hover/thumb:visible flex justify-center items-center',
|
|
9
|
+
on: 'flex justify-center items-center',
|
|
10
|
+
};
|
|
11
|
+
const xPlacementClasses = {
|
|
12
|
+
left: 'right-[calc(100%-13px)]',
|
|
13
|
+
right: 'left-[calc(100%-13px)]',
|
|
14
|
+
center: '',
|
|
15
|
+
};
|
|
16
|
+
const yPlacementClasses = {
|
|
17
|
+
bottom: 'top-[calc(100%+2px)]',
|
|
18
|
+
top: 'bottom-[calc(100%+2px)]',
|
|
19
|
+
};
|
|
20
|
+
const SliderValueLabel = ({ children, index = -1, tooltip = 'off', onRender, yPlacement, isOverlaped, ownerState: { value }, }) => {
|
|
21
|
+
const ref = useRef(null);
|
|
22
|
+
// we need to change the placement of the label if it is overlaped
|
|
23
|
+
// or if it is out of the viewport
|
|
24
|
+
const [xPlacement, setXPlacement] = useState('center');
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
onRender(index, ref);
|
|
27
|
+
}, [index, onRender]);
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (!ref.current) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
setXPlacement(getXPlacement({
|
|
33
|
+
rect: ref.current.getBoundingClientRect(),
|
|
34
|
+
isOverlaped: isOverlaped,
|
|
35
|
+
isFirstLabel: index === 0,
|
|
36
|
+
currentPlacement: xPlacement,
|
|
37
|
+
}));
|
|
38
|
+
// we need to recalculate on value change to get new rect
|
|
39
|
+
}, [isOverlaped, index, xPlacement, value, tooltip]);
|
|
40
|
+
return (React.createElement("span", { ref: ref, className: twJoin('absolute will-change-transform transition-transform', classesByTooltip[tooltip], yPlacementClasses[yPlacement], xPlacementClasses[xPlacement]) },
|
|
41
|
+
React.createElement("span", { className: twJoin('shadow-4 text-sm text-white bg-graphite-800', 'm-1 rounded-sm py-[2px] px-2 max-w-[300px] break-words') }, children)));
|
|
42
|
+
};
|
|
43
|
+
export default SliderValueLabel;
|
|
44
|
+
//# sourceMappingURL=SliderValueLabel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SliderValueLabel.js","sourceRoot":"","sources":["../../../src/SliderValueLabel/SliderValueLabel.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,gCAAgC,CAAA;AAEvD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA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AC,CAAA;IAEpD,OAAO,CACL,8BACE,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,MAAM,CACf,qDAAqD,EACrD,gBAAgB,CAAC,OAAO,CAAC,EACzB,iBAAiB,CAAC,UAAU,CAAC,EAC7B,iBAAiB,CAAC,UAAU,CAAC,CAC9B;QAED,8BACE,SAAS,EAAE,MAAM,CACf,6CAA6C,EAC7C,wDAAwD,CACzD,IAEA,QAAQ,CACJ,CACF,CACR,CAAA;AACH,CAAC,CAAA;AAED,eAAe,gBAAgB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/SliderValueLabel/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/SliderValueLabel/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare type GetBgColorProps = {
|
|
2
|
+
markActive?: boolean;
|
|
3
|
+
forceInactive?: boolean;
|
|
4
|
+
value?: number | readonly number[];
|
|
5
|
+
};
|
|
6
|
+
export declare const getBgColor: ({ markActive, forceInactive, value, }: GetBgColorProps) => "bg-gray-500" | "bg-blue-500";
|
|
7
|
+
//# sourceMappingURL=check-bg-color.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check-bg-color.d.ts","sourceRoot":"","sources":["../../../src/utils/check-bg-color.ts"],"names":[],"mappings":"AAAA,oBAAY,eAAe,GAAG;IAC5B,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAAA;CACnC,CAAA;AAED,eAAO,MAAM,UAAU,0CAIpB,eAAe,kCAiBjB,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const getBgColor = ({ markActive, forceInactive, value, }) => {
|
|
2
|
+
const inactive = 'bg-gray-500';
|
|
3
|
+
const active = 'bg-blue-500';
|
|
4
|
+
if (forceInactive) {
|
|
5
|
+
return inactive;
|
|
6
|
+
}
|
|
7
|
+
if (markActive) {
|
|
8
|
+
if (value === undefined) {
|
|
9
|
+
return inactive;
|
|
10
|
+
}
|
|
11
|
+
return active;
|
|
12
|
+
}
|
|
13
|
+
return inactive;
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=check-bg-color.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check-bg-color.js","sourceRoot":"","sources":["../../../src/utils/check-bg-color.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,EACzB,UAAU,EACV,aAAa,EACb,KAAK,GACW,EAAE,EAAE;IACpB,MAAM,QAAQ,GAAG,aAAa,CAAA;IAC9B,MAAM,MAAM,GAAG,aAAa,CAAA;IAE5B,IAAI,aAAa,EAAE;QACjB,OAAO,QAAQ,CAAA;KAChB;IAED,IAAI,UAAU,EAAE;QACd,IAAI,KAAK,KAAK,SAAS,EAAE;YACvB,OAAO,QAAQ,CAAA;SAChB;QAED,OAAO,MAAM,CAAA;KACd;IAED,OAAO,QAAQ,CAAA;AACjB,CAAC,CAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare type CheckOverlapProps = {
|
|
2
|
+
firstLabelRect: DOMRect;
|
|
3
|
+
secondLabelRect: DOMRect;
|
|
4
|
+
previousResult: boolean;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* if we have range slider, there is a chance
|
|
8
|
+
* when we select values next to each other
|
|
9
|
+
* that the lables might overlap each other. Like this example:
|
|
10
|
+
* [ [ ] ]
|
|
11
|
+
* A B
|
|
12
|
+
*
|
|
13
|
+
* In that case we need to reposition the labels to the edges of the thumb.
|
|
14
|
+
* [ ] [ ]
|
|
15
|
+
* A B
|
|
16
|
+
*
|
|
17
|
+
* In next rerender when we recalculate the position of the labels the
|
|
18
|
+
* above example would end with result as not overlapping as the position was already changed.
|
|
19
|
+
* So we need to work with the previous result of this function `previousResult`. When
|
|
20
|
+
* true we need to add half of the width of the label to simulate the center position.
|
|
21
|
+
*
|
|
22
|
+
* This function checks and returns if the labels overlap.
|
|
23
|
+
* It is called on each render of the component and everytime the Slider changes value.
|
|
24
|
+
**/
|
|
25
|
+
export declare const checkOverlap: ({ firstLabelRect, secondLabelRect, previousResult, }: CheckOverlapProps) => boolean;
|
|
26
|
+
//# sourceMappingURL=check-overlap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check-overlap.d.ts","sourceRoot":"","sources":["../../../src/utils/check-overlap.ts"],"names":[],"mappings":"AAAA,oBAAY,iBAAiB,GAAG;IAC9B,cAAc,EAAE,OAAO,CAAA;IACvB,eAAe,EAAE,OAAO,CAAA;IACxB,cAAc,EAAE,OAAO,CAAA;CACxB,CAAA;AAED;;;;;;;;;;;;;;;;;;IAkBI;AACJ,eAAO,MAAM,YAAY,yDAItB,iBAAiB,KAAG,OAatB,CAAA"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* if we have range slider, there is a chance
|
|
3
|
+
* when we select values next to each other
|
|
4
|
+
* that the lables might overlap each other. Like this example:
|
|
5
|
+
* [ [ ] ]
|
|
6
|
+
* A B
|
|
7
|
+
*
|
|
8
|
+
* In that case we need to reposition the labels to the edges of the thumb.
|
|
9
|
+
* [ ] [ ]
|
|
10
|
+
* A B
|
|
11
|
+
*
|
|
12
|
+
* In next rerender when we recalculate the position of the labels the
|
|
13
|
+
* above example would end with result as not overlapping as the position was already changed.
|
|
14
|
+
* So we need to work with the previous result of this function `previousResult`. When
|
|
15
|
+
* true we need to add half of the width of the label to simulate the center position.
|
|
16
|
+
*
|
|
17
|
+
* This function checks and returns if the labels overlap.
|
|
18
|
+
* It is called on each render of the component and everytime the Slider changes value.
|
|
19
|
+
**/
|
|
20
|
+
export const checkOverlap = ({ firstLabelRect, secondLabelRect, previousResult, }) => {
|
|
21
|
+
const gap = 16;
|
|
22
|
+
const halfWidth1 = firstLabelRect.width / 2;
|
|
23
|
+
const halfWidth2 = secondLabelRect.width / 2;
|
|
24
|
+
const rightBoundaryOfFirstLabel = previousResult
|
|
25
|
+
? firstLabelRect.right + halfWidth1
|
|
26
|
+
: firstLabelRect.right;
|
|
27
|
+
const leftBoundaryOfSecondLabel = previousResult
|
|
28
|
+
? secondLabelRect.left - halfWidth2
|
|
29
|
+
: secondLabelRect.left;
|
|
30
|
+
return rightBoundaryOfFirstLabel + gap > leftBoundaryOfSecondLabel;
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=check-overlap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check-overlap.js","sourceRoot":"","sources":["../../../src/utils/check-overlap.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;;;IAkBI;AACJ,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,EAC3B,cAAc,EACd,eAAe,EACf,cAAc,GACI,EAAW,EAAE;IAC/B,MAAM,GAAG,GAAG,EAAE,CAAA;IACd,MAAM,UAAU,GAAG,cAAc,CAAC,KAAK,GAAG,CAAC,CAAA;IAC3C,MAAM,UAAU,GAAG,eAAe,CAAC,KAAK,GAAG,CAAC,CAAA;IAE5C,MAAM,yBAAyB,GAAG,cAAc;QAC9C,CAAC,CAAC,cAAc,CAAC,KAAK,GAAG,UAAU;QACnC,CAAC,CAAC,cAAc,CAAC,KAAK,CAAA;IACxB,MAAM,yBAAyB,GAAG,cAAc;QAC9C,CAAC,CAAC,eAAe,CAAC,IAAI,GAAG,UAAU;QACnC,CAAC,CAAC,eAAe,CAAC,IAAI,CAAA;IAExB,OAAO,yBAAyB,GAAG,GAAG,GAAG,yBAAyB,CAAA;AACpE,CAAC,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare type GetPositionProps = {
|
|
2
|
+
rect: DOMRect;
|
|
3
|
+
isOverlaped: boolean;
|
|
4
|
+
isFirstLabel: boolean;
|
|
5
|
+
currentPlacement: 'left' | 'right' | 'center';
|
|
6
|
+
};
|
|
7
|
+
export declare const getXPlacement: ({ rect: { width, left, right }, isOverlaped, isFirstLabel, currentPlacement, }: GetPositionProps) => 'left' | 'right' | 'center';
|
|
8
|
+
//# sourceMappingURL=get-x-placement.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-x-placement.d.ts","sourceRoot":"","sources":["../../../src/utils/get-x-placement.ts"],"names":[],"mappings":"AAAA,oBAAY,gBAAgB,GAAG;IAC7B,IAAI,EAAE,OAAO,CAAA;IACb,WAAW,EAAE,OAAO,CAAA;IACpB,YAAY,EAAE,OAAO,CAAA;IACrB,gBAAgB,EAAE,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAA;CAC9C,CAAA;AAED,eAAO,MAAM,aAAa,mFAKvB,gBAAgB,KAAG,MAAM,GAAG,OAAO,GAAG,QAexC,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export const getXPlacement = ({ rect: { width, left, right }, isOverlaped, isFirstLabel, currentPlacement, }) => {
|
|
2
|
+
const gap = 16;
|
|
3
|
+
const halfWidth = width / 2;
|
|
4
|
+
const leftBoundary = currentPlacement === 'right' ? left - halfWidth : left;
|
|
5
|
+
const rightBoundary = currentPlacement === 'left' ? right + halfWidth : right;
|
|
6
|
+
if (leftBoundary < gap) {
|
|
7
|
+
return 'right';
|
|
8
|
+
}
|
|
9
|
+
else if (rightBoundary > window.innerWidth - gap) {
|
|
10
|
+
return 'left';
|
|
11
|
+
}
|
|
12
|
+
else if (isOverlaped) {
|
|
13
|
+
return isFirstLabel ? 'left' : 'right';
|
|
14
|
+
}
|
|
15
|
+
return 'center';
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=get-x-placement.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-x-placement.js","sourceRoot":"","sources":["../../../src/utils/get-x-placement.ts"],"names":[],"mappings":"AAOA,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,EAC5B,IAAI,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,EAC5B,WAAW,EACX,YAAY,EACZ,gBAAgB,GACC,EAA+B,EAAE;IAClD,MAAM,GAAG,GAAG,EAAE,CAAA;IACd,MAAM,SAAS,GAAG,KAAK,GAAG,CAAC,CAAA;IAC3B,MAAM,YAAY,GAAG,gBAAgB,KAAK,OAAO,CAAC,CAAC,CAAC,IAAI,GAAG,SAAS,CAAC,CAAC,CAAC,IAAI,CAAA;IAC3E,MAAM,aAAa,GAAG,gBAAgB,KAAK,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC,KAAK,CAAA;IAE7E,IAAI,YAAY,GAAG,GAAG,EAAE;QACtB,OAAO,OAAO,CAAA;KACf;SAAM,IAAI,aAAa,GAAG,MAAM,CAAC,UAAU,GAAG,GAAG,EAAE;QAClD,OAAO,MAAM,CAAA;KACd;SAAM,IAAI,WAAW,EAAE;QACtB,OAAO,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAA;KACvC;IAED,OAAO,QAAQ,CAAA;AACjB,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,mBAAmB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,mBAAmB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toptal/picasso-slider",
|
|
3
|
-
"version": "4.0.6-alpha-
|
|
3
|
+
"version": "4.0.6-alpha-FF-49-enhance-publishing-6b5d306f0.0",
|
|
4
4
|
"description": "Toptal UI components library - Slider",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -24,23 +24,23 @@
|
|
|
24
24
|
"homepage": "https://github.com/toptal/picasso/tree/master/packages/picasso#readme",
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@mui/base": "5.0.0-beta.58",
|
|
27
|
-
"@toptal/picasso-shared": "15.0.1-alpha-
|
|
28
|
-
"@toptal/picasso-tooltip": "2.0.4-alpha-
|
|
29
|
-
"@toptal/picasso-utils": "3.1.1-alpha-
|
|
27
|
+
"@toptal/picasso-shared": "15.0.1-alpha-FF-49-enhance-publishing-6b5d306f0.0",
|
|
28
|
+
"@toptal/picasso-tooltip": "2.0.4-alpha-FF-49-enhance-publishing-6b5d306f0.0",
|
|
29
|
+
"@toptal/picasso-utils": "3.1.1-alpha-FF-49-enhance-publishing-6b5d306f0.0"
|
|
30
30
|
},
|
|
31
31
|
"sideEffects": false,
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"@toptal/picasso-tailwind-merge": "2.0.4-alpha-
|
|
34
|
-
"@toptal/picasso-provider": "5.0.2-alpha-
|
|
35
|
-
"@toptal/picasso-tailwind": "3.0.1-alpha-
|
|
33
|
+
"@toptal/picasso-tailwind-merge": "2.0.4-alpha-FF-49-enhance-publishing-6b5d306f0.0",
|
|
34
|
+
"@toptal/picasso-provider": "5.0.2-alpha-FF-49-enhance-publishing-6b5d306f0.0",
|
|
35
|
+
"@toptal/picasso-tailwind": "3.0.1-alpha-FF-49-enhance-publishing-6b5d306f0.0",
|
|
36
36
|
"react": ">=16.12.0 < 19.0.0"
|
|
37
37
|
},
|
|
38
38
|
"exports": {
|
|
39
39
|
".": "./dist-package/src/index.js"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@toptal/picasso-tailwind-merge": "2.0.4-alpha-
|
|
43
|
-
"@toptal/picasso-provider": "5.0.2-alpha-
|
|
42
|
+
"@toptal/picasso-tailwind-merge": "2.0.4-alpha-FF-49-enhance-publishing-6b5d306f0.0",
|
|
43
|
+
"@toptal/picasso-provider": "5.0.2-alpha-FF-49-enhance-publishing-6b5d306f0.0"
|
|
44
44
|
},
|
|
45
45
|
"files": [
|
|
46
46
|
"dist-package/**",
|