UNPKG

lightswind

Version:

A collection of beautifully crafted React Components, Blocks & Templates for Modern Developers. Create stunning web applications effortlessly by using our 160+ professional and animated react components.

85 lines 4.57 kB
"use strict"; "use client"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.DragOrderList = DragOrderList; const jsx_runtime_1 = require("react/jsx-runtime"); const react_1 = __importStar(require("react")); const framer_motion_1 = require("framer-motion"); const lucide_react_1 = require("lucide-react"); function DragOrderList({ items, onReorder }) { const [list, setList] = react_1.default.useState(items); (0, react_1.useEffect)(() => { if (onReorder) onReorder(list); }, [list]); return ((0, jsx_runtime_1.jsx)(framer_motion_1.Reorder.Group, { axis: "y", values: list, onReorder: setList, className: "space-y-4 w-full max-w-2xl mx-auto", children: list.map((item) => ((0, jsx_runtime_1.jsx)(DragOrderItem, { item: item }, item.id))) })); } function DragOrderItem({ item }) { const y = (0, framer_motion_1.useMotionValue)(0); const boxShadow = useRaisedShadow(y); const dragControls = (0, framer_motion_1.useDragControls)(); return ((0, jsx_runtime_1.jsxs)(framer_motion_1.Reorder.Item, { value: item, style: { boxShadow, y }, dragListener: false, dragControls: dragControls, className: "flex justify-between items-start p-4 bg-background \r\n text-foreground rounded-xl border shadow-sm", children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex flex-col space-y-1 flex-1", children: [(0, jsx_runtime_1.jsx)("h2", { className: "text-lg font-semibold", children: item.title }), (0, jsx_runtime_1.jsx)("p", { className: "text-sm text-muted-foreground", children: item.subtitle }), (0, jsx_runtime_1.jsx)("span", { className: "text-xs text-muted-foreground", children: item.date }), item.link && ((0, jsx_runtime_1.jsxs)("a", { href: item.link, target: "_blank", rel: "noopener noreferrer", className: "mt-2 inline-block text-xs text-primarylw hover:underline", children: ["View details about ", item.title] }))] }), (0, jsx_runtime_1.jsx)(ReorderHandle, { dragControls: dragControls })] })); } function ReorderHandle({ dragControls }) { return ((0, jsx_runtime_1.jsx)(framer_motion_1.motion.div, { whileTap: { scale: 0.95 }, onPointerDown: (e) => { e.preventDefault(); dragControls.start(e); }, className: "cursor-grab active:cursor-grabbing p-2 text-muted-foreground", children: (0, jsx_runtime_1.jsx)(lucide_react_1.GripVertical, {}) })); } const inactiveShadow = "0px 0px 0px rgba(0,0,0,0.8)"; function useRaisedShadow(value) { const boxShadow = (0, framer_motion_1.useMotionValue)(inactiveShadow); (0, react_1.useEffect)(() => { let isActive = false; value.onChange((latest) => { const wasActive = isActive; if (latest !== 0) { isActive = true; if (isActive !== wasActive) { (0, framer_motion_1.animate)(boxShadow, "5px 5px 15px rgba(0,0,0,0.15)"); } } else { isActive = false; if (isActive !== wasActive) { (0, framer_motion_1.animate)(boxShadow, inactiveShadow); } } }); }, [value]); return boxShadow; } //# sourceMappingURL=drag-order-list.js.map