@sreedev/my3dui 0.2.1 → 0.2.2

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.cjs CHANGED
@@ -1657,56 +1657,73 @@ function Tabs3D({
1657
1657
  var import_react18 = require("react");
1658
1658
  var import_framer_motion8 = require("framer-motion");
1659
1659
  var import_jsx_runtime20 = require("react/jsx-runtime");
1660
- function Toggle3D({
1661
- checked: controlledChecked,
1662
- defaultChecked = false,
1663
- onChange,
1664
- disabled = false,
1665
- variant = "pill",
1666
- label
1667
- }) {
1668
- const [internalChecked, setInternalChecked] = (0, import_react18.useState)(defaultChecked);
1669
- const isControlled = controlledChecked !== void 0;
1670
- const isChecked = isControlled ? controlledChecked : internalChecked;
1671
- const handleToggle = () => {
1672
- if (disabled) return;
1673
- const newChecked = !isChecked;
1674
- if (!isControlled) setInternalChecked(newChecked);
1675
- onChange?.(newChecked);
1676
- };
1677
- const getVariantStyles = () => {
1678
- switch (variant) {
1679
- case "neon":
1680
- return isChecked ? "bg-slate-900 border border-cyan-500/50 shadow-[0_0_15px_rgba(6,182,212,0.4)]" : "bg-slate-900 border border-slate-700";
1681
- case "glass":
1682
- return "bg-white/20 backdrop-blur-md border border-white/30 shadow-inner";
1683
- case "pill":
1684
- default:
1685
- return isChecked ? "bg-primary shadow-inner" : "bg-slate-200 dark:bg-slate-700 shadow-inner";
1686
- }
1687
- };
1688
- return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: "flex items-center gap-3", children: [
1689
- /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(
1690
- "button",
1691
- {
1692
- onClick: handleToggle,
1693
- className: cn(
1694
- "relative h-8 w-14 rounded-full transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
1695
- disabled && "opacity-50 cursor-not-allowed",
1696
- getVariantStyles()
1697
- ),
1698
- role: "switch",
1699
- "aria-checked": isChecked,
1700
- children: [
1701
- /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
1660
+ var Toggle3D = (0, import_react18.forwardRef)(
1661
+ ({
1662
+ checked: controlledChecked,
1663
+ defaultChecked = false,
1664
+ onChange,
1665
+ disabled = false,
1666
+ variant = "pill",
1667
+ label
1668
+ }, ref) => {
1669
+ const [internalChecked, setInternalChecked] = (0, import_react18.useState)(defaultChecked);
1670
+ const isControlled = controlledChecked !== void 0;
1671
+ const isChecked = isControlled ? controlledChecked : internalChecked;
1672
+ const handleToggle = () => {
1673
+ if (disabled) return;
1674
+ const newChecked = !isChecked;
1675
+ if (!isControlled) {
1676
+ setInternalChecked(newChecked);
1677
+ }
1678
+ onChange?.(newChecked);
1679
+ };
1680
+ const getVariantStyles = () => {
1681
+ switch (variant) {
1682
+ case "neon":
1683
+ return isChecked ? "bg-black border border-cyan-400 shadow-[0_0_15px_rgba(34,211,238,0.4)]" : "bg-black border border-slate-700";
1684
+ case "glass":
1685
+ return "bg-white/20 backdrop-blur-md border border-white/30";
1686
+ case "pill":
1687
+ default:
1688
+ return isChecked ? "bg-primary" : "bg-muted";
1689
+ }
1690
+ };
1691
+ const toggleWidth = 56;
1692
+ const knobSize = 24;
1693
+ const padding = 4;
1694
+ const travel = toggleWidth - knobSize - padding * 2;
1695
+ return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: "flex items-center gap-3", children: [
1696
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
1697
+ "button",
1698
+ {
1699
+ ref,
1700
+ type: "button",
1701
+ role: "switch",
1702
+ "aria-checked": isChecked,
1703
+ "aria-disabled": disabled,
1704
+ disabled,
1705
+ onClick: handleToggle,
1706
+ onKeyDown: (e) => {
1707
+ if (e.key === "Enter" || e.key === " ") {
1708
+ e.preventDefault();
1709
+ handleToggle();
1710
+ }
1711
+ },
1712
+ className: cn(
1713
+ "relative h-8 w-14 rounded-full transition-colors",
1714
+ "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
1715
+ disabled && "opacity-50 cursor-not-allowed",
1716
+ getVariantStyles()
1717
+ ),
1718
+ children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
1702
1719
  import_framer_motion8.motion.div,
1703
1720
  {
1704
1721
  className: cn(
1705
- "absolute top-1 left-1 h-6 w-6 rounded-full shadow-md z-10",
1722
+ "absolute top-1 left-1 h-6 w-6 rounded-full shadow-md",
1706
1723
  variant === "neon" && isChecked ? "bg-cyan-400 shadow-[0_0_10px_#22d3ee]" : "bg-white"
1707
1724
  ),
1708
1725
  animate: {
1709
- x: isChecked ? 24 : 0,
1726
+ x: isChecked ? travel : 0,
1710
1727
  scale: disabled ? 0.9 : 1
1711
1728
  },
1712
1729
  transition: {
@@ -1715,22 +1732,14 @@ function Toggle3D({
1715
1732
  damping: 30
1716
1733
  }
1717
1734
  }
1718
- ),
1719
- variant !== "neon" && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
1720
- "div",
1721
- {
1722
- className: cn(
1723
- "absolute inset-0 rounded-full border-b-[3px] border-black/5 pointer-events-none",
1724
- isChecked ? "border-black/10" : "border-black/5"
1725
- )
1726
- }
1727
1735
  )
1728
- ]
1729
- }
1730
- ),
1731
- label && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("span", { className: "text-sm font-medium", children: label })
1732
- ] });
1733
- }
1736
+ }
1737
+ ),
1738
+ label && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("span", { className: "text-sm font-medium", children: label })
1739
+ ] });
1740
+ }
1741
+ );
1742
+ Toggle3D.displayName = "Toggle3D";
1734
1743
 
1735
1744
  // src/components/ui/modal3d.tsx
1736
1745
  var DialogPrimitive = __toESM(require("@radix-ui/react-dialog"), 1);