diff --git a/packages/components/src/draggable/Draggable.tsx b/packages/components/src/draggable/Draggable.tsx index 9c16597..55dc09f 100644 --- a/packages/components/src/draggable/Draggable.tsx +++ b/packages/components/src/draggable/Draggable.tsx @@ -9,7 +9,7 @@ import { useDraggableChildren } from './hooks'; import type { ReactElement, FC } from 'react'; import { getClasses } from '@pkg/shared'; -export const cls = getClasses('draggable', ['ghost', 'item'], []); +export const cls = getClasses('draggable', ['ghost', 'item'], ['hidden']); const defaultProps = { tag: 'div', list: [], diff --git a/packages/components/src/draggable/DraggableGroup.tsx b/packages/components/src/draggable/DraggableGroup.tsx new file mode 100644 index 0000000..f53a3f9 --- /dev/null +++ b/packages/components/src/draggable/DraggableGroup.tsx @@ -0,0 +1,44 @@ +import { createContext, ReactElement, useRef, FC } from 'react'; +import type { DraggableGroupProps } from './draggable.types'; + +const defaultProps = {} satisfies Partial; + +/** + * 在 dragstart 里生产,在 dragenter 消费,在 drop | dragend 销毁 + */ +export interface DraggableGroupContextProvider { + readonly children: ReactElement; + cancel?: (id: symbol) => void; + enter?: (id: symbol) => void; + drop?: (id: symbol) => void; + readonly item: unknown; + id: symbol; +} +export const draggableContext = createContext<{ + fromRef: { current: DraggableGroupContextProvider | null }; + toRef: { current: DraggableGroupContextProvider | null }; + type: Exclude; +}>({ + fromRef: { current: null }, + toRef: { current: null }, + type: 'move', +}); + +export const DraggableGroup: FC = (props) => { + const fromRef = useRef(null); + const toRef = useRef(null); + return ( + + {props.children} + + ); +}; + +DraggableGroup.defaultProps = defaultProps; +DraggableGroup.displayName = 'DraggableGroup'; diff --git a/packages/components/src/draggable/demo/draggable-group.module.scss b/packages/components/src/draggable/demo/draggable-group.module.scss new file mode 100644 index 0000000..c2d3dff --- /dev/null +++ b/packages/components/src/draggable/demo/draggable-group.module.scss @@ -0,0 +1,23 @@ +.root { + :global { + .main { + display: flex; + margin-top: 1rem; + } + .t-draggable { + flex: 1; + + .t-draggable { + margin-left: 6px; + } + } + .draggable-item { + padding: 0 0.5rem; + border: 1px solid #e6e6e6; + background: #fff1d7; + line-height: 32px; + &.t-draggable__ghost { + background: #f6a306; + } + } + } +} diff --git a/packages/components/src/draggable/demo/draggable-group.tsx b/packages/components/src/draggable/demo/draggable-group.tsx new file mode 100644 index 0000000..647e68b --- /dev/null +++ b/packages/components/src/draggable/demo/draggable-group.tsx @@ -0,0 +1,50 @@ +/** + * title: 拖拽组 + * description: 拖拽组分为两种拖拽方式,'move' 为移动数据,'copy' 为复制数据,默认为 'move'。 + */ + +import { DraggableGroup, Draggable, Select } from '@tool-pack/react-ui'; +import styles from './draggable-group.module.scss'; +import React, { useState } from 'react'; + +const options = [ + { label: 'move', value: 'move' }, + { label: 'copy', value: 'copy' }, +]; + +const App: React.FC = () => { + const [type, setType] = useState<'copy' | 'move'>('move'); + const [state, setState] = React.useState(['A', 'B', 'C', 'D']); + const [state2, setState2] = React.useState(['a', 'b', 'c', 'd']); + return ( +
+