@fab1o978/react-ui 0.1.5 → 0.1.7
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/components/ColorPicker/index.cjs +205 -63
- package/dist/components/ColorPicker/index.cjs.map +1 -1
- package/dist/components/ColorPicker/index.css +200 -42
- package/dist/components/ColorPicker/index.css.map +1 -1
- package/dist/components/ColorPicker/index.js +205 -63
- package/dist/components/ColorPicker/index.js.map +1 -1
- package/dist/components/SliderControl/index.cjs +268 -0
- package/dist/components/SliderControl/index.cjs.map +1 -0
- package/dist/components/SliderControl/index.css +202 -0
- package/dist/components/SliderControl/index.css.map +1 -0
- package/dist/components/SliderControl/index.d.cts +21 -0
- package/dist/components/SliderControl/index.d.ts +21 -0
- package/dist/components/SliderControl/index.js +266 -0
- package/dist/components/SliderControl/index.js.map +1 -0
- package/dist/index.cjs +206 -63
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +200 -42
- package/dist/index.css.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +206 -64
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -599,10 +599,6 @@ var ColorPicker_module_default = {
|
|
|
599
599
|
discWrapper: "ColorPicker_module_discWrapper",
|
|
600
600
|
disc: "ColorPicker_module_disc",
|
|
601
601
|
dot: "ColorPicker_module_dot",
|
|
602
|
-
lSlider: "ColorPicker_module_lSlider",
|
|
603
|
-
lThumb: "ColorPicker_module_lThumb",
|
|
604
|
-
alphaSlider: "ColorPicker_module_alphaSlider",
|
|
605
|
-
alphaThumb: "ColorPicker_module_alphaThumb",
|
|
606
602
|
previewSwatch: "ColorPicker_module_previewSwatch",
|
|
607
603
|
eyedropperBtn: "ColorPicker_module_eyedropperBtn",
|
|
608
604
|
inputSection: "ColorPicker_module_inputSection",
|
|
@@ -618,6 +614,190 @@ var ColorPicker_module_default = {
|
|
|
618
614
|
swatches: "ColorPicker_module_swatches",
|
|
619
615
|
recentSwatch: "ColorPicker_module_recentSwatch"
|
|
620
616
|
};
|
|
617
|
+
|
|
618
|
+
// src/components/SliderControl/SliderControl.module.scss
|
|
619
|
+
var SliderControl_module_default = {
|
|
620
|
+
wrapper: "SliderControl_module_wrapper",
|
|
621
|
+
disabled: "SliderControl_module_disabled",
|
|
622
|
+
icon: "SliderControl_module_icon",
|
|
623
|
+
trackArea: "SliderControl_module_trackArea",
|
|
624
|
+
groove: "SliderControl_module_groove",
|
|
625
|
+
rail: "SliderControl_module_rail",
|
|
626
|
+
fill: "SliderControl_module_fill",
|
|
627
|
+
thumb: "SliderControl_module_thumb",
|
|
628
|
+
thumbDragging: "SliderControl_module_thumbDragging",
|
|
629
|
+
tooltip: "SliderControl_module_tooltip",
|
|
630
|
+
tooltipVisible: "SliderControl_module_tooltipVisible"
|
|
631
|
+
};
|
|
632
|
+
function clamp(v, min, max) {
|
|
633
|
+
return Math.min(Math.max(v, min), max);
|
|
634
|
+
}
|
|
635
|
+
function snapToStep(v, min, step) {
|
|
636
|
+
return Math.round((v - min) / step) * step + min;
|
|
637
|
+
}
|
|
638
|
+
var SliderControl = ({
|
|
639
|
+
value: controlledValue,
|
|
640
|
+
defaultValue = 50,
|
|
641
|
+
min = 0,
|
|
642
|
+
max = 100,
|
|
643
|
+
step = 1,
|
|
644
|
+
onChange,
|
|
645
|
+
showTooltip = "drag",
|
|
646
|
+
leftIcon,
|
|
647
|
+
rightIcon,
|
|
648
|
+
railBackground,
|
|
649
|
+
accent,
|
|
650
|
+
className,
|
|
651
|
+
disabled = false
|
|
652
|
+
}) => {
|
|
653
|
+
const isControlled = controlledValue !== void 0;
|
|
654
|
+
const [internalValue, setInternalValue] = useState(defaultValue);
|
|
655
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
656
|
+
const [isFocused, setIsFocused] = useState(false);
|
|
657
|
+
const trackRef = useRef(null);
|
|
658
|
+
const thumbRef = useRef(null);
|
|
659
|
+
const value = isControlled ? controlledValue : internalValue;
|
|
660
|
+
const pct = (clamp(value, min, max) - min) / (max - min);
|
|
661
|
+
const accentVars = accent ? accentToCssVars(deriveAccent(accent), "slider") : {};
|
|
662
|
+
const setValue = useCallback(
|
|
663
|
+
(next) => {
|
|
664
|
+
const snapped = clamp(snapToStep(next, min, step), min, max);
|
|
665
|
+
if (!isControlled) setInternalValue(snapped);
|
|
666
|
+
onChange?.(snapped);
|
|
667
|
+
},
|
|
668
|
+
[isControlled, min, max, step, onChange]
|
|
669
|
+
);
|
|
670
|
+
const valueFromPointer = useCallback(
|
|
671
|
+
(e) => {
|
|
672
|
+
const rect = trackRef.current.getBoundingClientRect();
|
|
673
|
+
const ratio = clamp((e.clientX - rect.left) / rect.width, 0, 1);
|
|
674
|
+
return min + ratio * (max - min);
|
|
675
|
+
},
|
|
676
|
+
[min, max]
|
|
677
|
+
);
|
|
678
|
+
const handlePointerDown = useCallback(
|
|
679
|
+
(e) => {
|
|
680
|
+
if (disabled) return;
|
|
681
|
+
e.currentTarget.setPointerCapture(e.pointerId);
|
|
682
|
+
setIsDragging(true);
|
|
683
|
+
thumbRef.current?.focus();
|
|
684
|
+
setValue(valueFromPointer(e.nativeEvent));
|
|
685
|
+
},
|
|
686
|
+
[disabled, setValue, valueFromPointer]
|
|
687
|
+
);
|
|
688
|
+
const handlePointerMove = useCallback(
|
|
689
|
+
(e) => {
|
|
690
|
+
if (!isDragging || disabled) return;
|
|
691
|
+
setValue(valueFromPointer(e.nativeEvent));
|
|
692
|
+
},
|
|
693
|
+
[isDragging, disabled, setValue, valueFromPointer]
|
|
694
|
+
);
|
|
695
|
+
const handlePointerUp = useCallback(() => {
|
|
696
|
+
setIsDragging(false);
|
|
697
|
+
thumbRef.current?.blur();
|
|
698
|
+
}, []);
|
|
699
|
+
useEffect(() => {
|
|
700
|
+
const el = trackRef.current;
|
|
701
|
+
if (!el) return;
|
|
702
|
+
const onWheel = (e) => {
|
|
703
|
+
if (disabled) return;
|
|
704
|
+
e.preventDefault();
|
|
705
|
+
setValue(value + (e.deltaY < 0 ? step : -step));
|
|
706
|
+
};
|
|
707
|
+
el.addEventListener("wheel", onWheel, { passive: false });
|
|
708
|
+
return () => el.removeEventListener("wheel", onWheel);
|
|
709
|
+
}, [disabled, value, step, setValue]);
|
|
710
|
+
const handleKeyDown = useCallback(
|
|
711
|
+
(e) => {
|
|
712
|
+
if (disabled) return;
|
|
713
|
+
const map = {
|
|
714
|
+
ArrowRight: step,
|
|
715
|
+
ArrowUp: step,
|
|
716
|
+
ArrowLeft: -step,
|
|
717
|
+
ArrowDown: -step,
|
|
718
|
+
PageUp: step * 10,
|
|
719
|
+
PageDown: -step * 10
|
|
720
|
+
};
|
|
721
|
+
if (e.key === "Home") {
|
|
722
|
+
setValue(min);
|
|
723
|
+
e.preventDefault();
|
|
724
|
+
return;
|
|
725
|
+
}
|
|
726
|
+
if (e.key === "End") {
|
|
727
|
+
setValue(max);
|
|
728
|
+
e.preventDefault();
|
|
729
|
+
return;
|
|
730
|
+
}
|
|
731
|
+
if (map[e.key] !== void 0) {
|
|
732
|
+
setValue(value + map[e.key]);
|
|
733
|
+
e.preventDefault();
|
|
734
|
+
}
|
|
735
|
+
},
|
|
736
|
+
[disabled, step, min, max, value, setValue]
|
|
737
|
+
);
|
|
738
|
+
const tooltipVisible = showTooltip === "always" || showTooltip === "drag" && (isDragging || isFocused);
|
|
739
|
+
const displayValue = `${Math.round(value)}%`;
|
|
740
|
+
const tooltipOffset = `calc(${pct * 100}% + ${(0.5 - pct) * 20}px)`;
|
|
741
|
+
return /* @__PURE__ */ jsxs(
|
|
742
|
+
"div",
|
|
743
|
+
{
|
|
744
|
+
className: [SliderControl_module_default.wrapper, disabled ? SliderControl_module_default.disabled : "", className ?? ""].filter(Boolean).join(" "),
|
|
745
|
+
style: accentVars,
|
|
746
|
+
children: [
|
|
747
|
+
leftIcon !== null && leftIcon !== void 0 && /* @__PURE__ */ jsx("span", { className: SliderControl_module_default.icon, children: leftIcon }),
|
|
748
|
+
/* @__PURE__ */ jsxs(
|
|
749
|
+
"div",
|
|
750
|
+
{
|
|
751
|
+
ref: trackRef,
|
|
752
|
+
className: SliderControl_module_default.trackArea,
|
|
753
|
+
onPointerDown: handlePointerDown,
|
|
754
|
+
onPointerMove: handlePointerMove,
|
|
755
|
+
onPointerUp: handlePointerUp,
|
|
756
|
+
onPointerCancel: handlePointerUp,
|
|
757
|
+
children: [
|
|
758
|
+
/* @__PURE__ */ jsx("div", { className: SliderControl_module_default.groove, children: /* @__PURE__ */ jsx(
|
|
759
|
+
"div",
|
|
760
|
+
{
|
|
761
|
+
className: SliderControl_module_default.rail,
|
|
762
|
+
style: railBackground ? { background: railBackground } : void 0,
|
|
763
|
+
children: !railBackground && /* @__PURE__ */ jsx("div", { className: SliderControl_module_default.fill, style: { width: `${pct * 100}%` } })
|
|
764
|
+
}
|
|
765
|
+
) }),
|
|
766
|
+
/* @__PURE__ */ jsx(
|
|
767
|
+
"div",
|
|
768
|
+
{
|
|
769
|
+
ref: thumbRef,
|
|
770
|
+
role: "slider",
|
|
771
|
+
tabIndex: disabled ? -1 : 0,
|
|
772
|
+
"aria-valuenow": Math.round(value),
|
|
773
|
+
"aria-valuemin": min,
|
|
774
|
+
"aria-valuemax": max,
|
|
775
|
+
"aria-disabled": disabled,
|
|
776
|
+
className: [SliderControl_module_default.thumb, isDragging ? SliderControl_module_default.thumbDragging : ""].filter(Boolean).join(" "),
|
|
777
|
+
style: { left: `calc(${pct * 100}% + ${(0.5 - pct) * 24}px)` },
|
|
778
|
+
onKeyDown: handleKeyDown,
|
|
779
|
+
onFocus: () => setIsFocused(true),
|
|
780
|
+
onBlur: () => setIsFocused(false)
|
|
781
|
+
}
|
|
782
|
+
),
|
|
783
|
+
/* @__PURE__ */ jsx(
|
|
784
|
+
"div",
|
|
785
|
+
{
|
|
786
|
+
className: [SliderControl_module_default.tooltip, tooltipVisible ? SliderControl_module_default.tooltipVisible : ""].filter(Boolean).join(" "),
|
|
787
|
+
style: { left: tooltipOffset },
|
|
788
|
+
"aria-hidden": "true",
|
|
789
|
+
children: displayValue
|
|
790
|
+
}
|
|
791
|
+
)
|
|
792
|
+
]
|
|
793
|
+
}
|
|
794
|
+
),
|
|
795
|
+
rightIcon !== null && rightIcon !== void 0 && /* @__PURE__ */ jsx("span", { className: SliderControl_module_default.icon, children: rightIcon })
|
|
796
|
+
]
|
|
797
|
+
}
|
|
798
|
+
);
|
|
799
|
+
};
|
|
800
|
+
SliderControl.displayName = "SliderControl";
|
|
621
801
|
var DISC = 200;
|
|
622
802
|
var CopyIcon = () => /* @__PURE__ */ jsxs("svg", { width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", children: [
|
|
623
803
|
/* @__PURE__ */ jsx("rect", { x: "5", y: "5", width: "7", height: "7", rx: "1.5", stroke: "currentColor", strokeWidth: "1.4" }),
|
|
@@ -787,50 +967,21 @@ var ColorPicker = ({
|
|
|
787
967
|
},
|
|
788
968
|
[updateDisc]
|
|
789
969
|
);
|
|
790
|
-
const
|
|
791
|
-
(
|
|
792
|
-
const nl = Math.max(0, Math.min(100, (clientX - rect.left) / rect.width * 100));
|
|
970
|
+
const handleLChange = useCallback(
|
|
971
|
+
(nl) => {
|
|
793
972
|
setL(nl);
|
|
794
973
|
notify(h, s, nl, a);
|
|
795
974
|
},
|
|
796
975
|
[h, s, a, notify]
|
|
797
976
|
);
|
|
798
|
-
const
|
|
799
|
-
(
|
|
800
|
-
|
|
801
|
-
updateL(e.clientX, e.currentTarget.getBoundingClientRect());
|
|
802
|
-
},
|
|
803
|
-
[updateL]
|
|
804
|
-
);
|
|
805
|
-
const handleLPointerMove = useCallback(
|
|
806
|
-
(e) => {
|
|
807
|
-
if (e.buttons === 0) return;
|
|
808
|
-
updateL(e.clientX, e.currentTarget.getBoundingClientRect());
|
|
809
|
-
},
|
|
810
|
-
[updateL]
|
|
811
|
-
);
|
|
812
|
-
const updateA = useCallback(
|
|
813
|
-
(clientX, rect) => {
|
|
814
|
-
const na = Math.max(0, Math.min(1, (clientX - rect.left) / rect.width));
|
|
977
|
+
const handleAChange = useCallback(
|
|
978
|
+
(val) => {
|
|
979
|
+
const na = val / 100;
|
|
815
980
|
setA(na);
|
|
816
981
|
notify(h, s, l, na);
|
|
817
982
|
},
|
|
818
983
|
[h, s, l, notify]
|
|
819
984
|
);
|
|
820
|
-
const handleAPointerDown = useCallback(
|
|
821
|
-
(e) => {
|
|
822
|
-
e.currentTarget.setPointerCapture(e.pointerId);
|
|
823
|
-
updateA(e.clientX, e.currentTarget.getBoundingClientRect());
|
|
824
|
-
},
|
|
825
|
-
[updateA]
|
|
826
|
-
);
|
|
827
|
-
const handleAPointerMove = useCallback(
|
|
828
|
-
(e) => {
|
|
829
|
-
if (e.buttons === 0) return;
|
|
830
|
-
updateA(e.clientX, e.currentTarget.getBoundingClientRect());
|
|
831
|
-
},
|
|
832
|
-
[updateA]
|
|
833
|
-
);
|
|
834
985
|
const { r: rr, g: gg, b: bb } = hslToRgb(h, s, l);
|
|
835
986
|
const luminance = (0.299 * rr + 0.587 * gg + 0.114 * bb) / 255;
|
|
836
987
|
const swatchFg = luminance > 0.6 ? "rgba(0,0,0,0.5)" : "rgba(255,255,255,0.9)";
|
|
@@ -843,7 +994,6 @@ var ColorPicker = ({
|
|
|
843
994
|
hsl(${h}, ${s}%, 5%),
|
|
844
995
|
hsl(${h}, ${s}%, 50%),
|
|
845
996
|
hsl(${h}, ${s}%, 95%))`;
|
|
846
|
-
const alphaGradient = `linear-gradient(to right, transparent, ${rgbStr})`;
|
|
847
997
|
const handleEyeDropper = async () => {
|
|
848
998
|
if (!window.EyeDropper) return;
|
|
849
999
|
try {
|
|
@@ -904,35 +1054,27 @@ var ColorPicker = ({
|
|
|
904
1054
|
)
|
|
905
1055
|
] }) }),
|
|
906
1056
|
/* @__PURE__ */ jsx(
|
|
907
|
-
|
|
1057
|
+
SliderControl,
|
|
908
1058
|
{
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
className: ColorPicker_module_default.lThumb,
|
|
917
|
-
style: { left: `${l}%` }
|
|
918
|
-
}
|
|
919
|
-
)
|
|
1059
|
+
value: l,
|
|
1060
|
+
onChange: handleLChange,
|
|
1061
|
+
min: 0,
|
|
1062
|
+
max: 100,
|
|
1063
|
+
step: 1,
|
|
1064
|
+
showTooltip: "never",
|
|
1065
|
+
railBackground: lGradient
|
|
920
1066
|
}
|
|
921
1067
|
),
|
|
922
1068
|
showAlpha && /* @__PURE__ */ jsx(
|
|
923
|
-
|
|
1069
|
+
SliderControl,
|
|
924
1070
|
{
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
className: ColorPicker_module_default.alphaThumb,
|
|
933
|
-
style: { left: `${a * 100}%` }
|
|
934
|
-
}
|
|
935
|
-
)
|
|
1071
|
+
value: Math.round(a * 100),
|
|
1072
|
+
onChange: handleAChange,
|
|
1073
|
+
min: 0,
|
|
1074
|
+
max: 100,
|
|
1075
|
+
step: 1,
|
|
1076
|
+
showTooltip: "never",
|
|
1077
|
+
railBackground: `linear-gradient(to right, transparent, ${rgbStr}), repeating-conic-gradient(#ccc 0% 25%, #fff 0% 50%) 0 / 10px 10px`
|
|
936
1078
|
}
|
|
937
1079
|
),
|
|
938
1080
|
/* @__PURE__ */ jsx(
|
|
@@ -4543,6 +4685,6 @@ var PageBreakButton = () => {
|
|
|
4543
4685
|
);
|
|
4544
4686
|
};
|
|
4545
4687
|
|
|
4546
|
-
export { Badge, Button, ColorPicker, Highlight, HighlightButton, Input, PageBreak, PageBreakButton, RainCanvas, RichTextEditor, SlidingCounter, Timeline };
|
|
4688
|
+
export { Badge, Button, ColorPicker, Highlight, HighlightButton, Input, PageBreak, PageBreakButton, RainCanvas, RichTextEditor, SliderControl, SlidingCounter, Timeline };
|
|
4547
4689
|
//# sourceMappingURL=index.js.map
|
|
4548
4690
|
//# sourceMappingURL=index.js.map
|