@lobehub/ui
Version:
Lobe UI is an open-source UI component library for building AIGC web apps
1 lines • 2.73 kB
Source Map (JSON)
{"version":3,"file":"SortableItem.mjs","names":["Flexbox"],"sources":["../../../src/SortableList/components/SortableItem.tsx"],"sourcesContent":["'use client';\n\nimport type { DraggableSyntheticListeners } from '@dnd-kit/core';\nimport { useSortable } from '@dnd-kit/sortable';\nimport { CSS } from '@dnd-kit/utilities';\nimport { cx } from 'antd-style';\nimport { createContext, memo, useMemo } from 'react';\n\nimport { type FlexboxProps } from '@/Flex';\nimport { Flexbox } from '@/Flex';\n\nimport { variants } from '../style';\n\ninterface Context {\n attributes: Record<string, any>;\n listeners: DraggableSyntheticListeners;\n ref: (node: HTMLElement | null) => void;\n}\n\nexport const SortableItemContext = createContext<Context>({\n attributes: {},\n listeners: undefined,\n ref() {},\n});\n\nexport interface SortableItemProps extends Omit<FlexboxProps, 'id'> {\n id: string | number;\n variant?: 'borderless' | 'filled' | 'outlined';\n}\n\nconst SortableItem = memo<SortableItemProps>(\n ({ variant = 'borderless', className, children, id, style, ...rest }) => {\n const {\n attributes,\n isDragging,\n listeners,\n setNodeRef,\n setActivatorNodeRef,\n transform,\n transition,\n } = useSortable({ id });\n const context = useMemo(\n () => ({\n attributes,\n listeners,\n ref: setActivatorNodeRef,\n }),\n [attributes, listeners, setActivatorNodeRef],\n );\n\n return (\n <SortableItemContext value={context}>\n <Flexbox\n horizontal\n align={'center'}\n as={'li'}\n className={cx(variants({ variant }), className)}\n gap={4}\n ref={setNodeRef}\n style={{\n opacity: isDragging ? 0.4 : undefined,\n transform: CSS.Translate.toString(transform),\n transition,\n ...style,\n }}\n {...rest}\n >\n {children}\n </Flexbox>\n </SortableItemContext>\n );\n },\n);\n\nSortableItem.displayName = 'SortableItem';\n\nexport default SortableItem;\n"],"mappings":";;;;;;;;;AAmBA,MAAa,sBAAsB,cAAuB;CACxD,YAAY,CAAC;CACb,WAAW,KAAA;CACX,MAAM,CAAC;AACT,CAAC;AAOD,MAAM,eAAe,MAClB,EAAE,UAAU,cAAc,WAAW,UAAU,IAAI,OAAO,GAAG,WAAW;CACvE,MAAM,EACJ,YACA,YACA,WACA,YACA,qBACA,WACA,eACE,YAAY,EAAE,GAAG,CAAC;CACtB,MAAM,UAAU,eACP;EACL;EACA;EACA,KAAK;CACP,IACA;EAAC;EAAY;EAAW;CAAmB,CAC7C;CAEA,OACE,oBAAC,qBAAD;EAAqB,OAAO;YAC1B,oBAACA,mBAAD;GACE,YAAA;GACA,OAAO;GACP,IAAI;GACJ,WAAW,GAAG,SAAS,EAAE,QAAQ,CAAC,GAAG,SAAS;GAC9C,KAAK;GACL,KAAK;GACL,OAAO;IACL,SAAS,aAAa,KAAM,KAAA;IAC5B,WAAW,IAAI,UAAU,SAAS,SAAS;IAC3C;IACA,GAAG;GACL;GACA,GAAI;GAEH;EACM,CAAA;CACU,CAAA;AAEzB,CACF;AAEA,aAAa,cAAc"}