1.0.1 • Published 5 years ago

react-sortable-condition v1.0.1

Weekly downloads
14
License
MIT
Repository
github
Last release
5 years ago

react-sortable-condition

drag and drop sortable condition

npm NPM

Screenshots

sortablecondition

Install

npm install react-sortable-condition --save

Usage

<SortableCondition
  defaultDataSource={data}
  onChange={v => console.log('change', v)}
  onDragState={v => console.log('drag', v)}
  onVisible={v => console.log('visible', v)}
  onMoveNode={v => console.log('move', v)}
  maxDepth={3}
>
  <SortableCondition.Condition
    onAdd={() => console.log('add')}
    onDelete={() => console.log('delelte')}
    addIcon={<Icon type="plus-circle" />}
    deleteIcon={<Icon type="close-circle" />}
  />
  <SortableCondition.Pattern>
    <TestPattern />
  </SortableCondition.Pattern>
</SortableCondition>

Data Structure

condition data structure

{
  type: 'and' | 'or'
  expanded: boolean
  children: condition-data-structure[] | pattern-data-structure[] | undefined
}

pattern data structure

{
  type: 'normal',
  expanded: boolean
  patterns: any // data for pattern
  children: undefined
}

Rules

  1. pattern's data no chidlren data
  2. condition's children at least one
  3. convert only available with no-siblingitems-node
  4. cant't delete root node
  5. drag condition node to all-pattern-children'node will spreed condition's pattern children
  6. drag pattern node to all-condition-childrn'node will convert pattern node to condition node
  7. children is always same kinds

API

all typo in typings

Props of Sortablecondition

PropsUsageTypoDefault
onDragStatetrigger when drag start and end(value: DragStateData): void
onMoveNodetrigger when moved node(value: MoveStateData): void
onVisibletrigger when expaned node(value: VisibilityStateData): void
onChangetrigger by treeData change behaviours(value: ConditionTreeItem[]): void
children<Condition /> or <Pattern />
dataSourceset fullcontrol datasource, generate by useTreeData hooksConditionTreeItem[]
defaultDataSourceset un-fullcontrol initial datasourceDataItem[][]
maxDepthset max-depth of sortable-conditionnumber3
classNameset classname of SortableConditionstring
rowHeightset node rowheight, will overwrite condition and pattern row heightnumber62

Props of Sortablecondition.Condition

PropsUseageTypoDefault
onAddtrigger when add condition node(node: ConditionItem, path: NextPath) => void
onDeletetrigger when delete condition node(node: ConditionItem, path: NextPath) => void
onTypetrigger when change condition node type(node: ConditionItem, path: NextPath) => void
onConverttrigger when convert condition node to pattern node(node: ConditionItem, path: NextPath) => void
classNameset classname of Conditionstring
rowHeightset condition rowheightnumber62
indentset width between line and nodenumber44

Props of Sortablecondition.Pattern

PropsUseageTypoDefault
onAddtrigger when add pattern node(node: PatternItem, path: NextPath) => void
onDeletetrigger when delete pattern node(node: PatternItem, path: NextPath) => void
onTypetrigger when change pattern node type(node: PatternItem, path: NextPath) => void
onConverttrigger when convert pattern node to condition node(node: PatternItem, path: NextPath) => void
classNameset classname of Patternstring
childrenset render pattern in PatternReact.ReactNode'this is a pattern'
rowHeightset pattern rowheightnumber62

Note: Pattern.children see like below, TestPattern will get patterns from treeData

const TestPattern = ({ patterns, onChange }: { patterns?: any; onChange?: Function }) => {
  console.log('patterns', patterns)
  const handleClick = () => {
    console.log('clicked')
    if (onChange) {
      onChange({ patterns: 2 })
    }
  }
  return <span onClick={handleClick}>1</span>
}

Useage of useTreeData hooks

ParamsUseageTypoDefalut
initialTreeDatainitial treedataDataItem[]
ReturnUseageTypoDefalut
treeDatadatasouce of <SortableCondition />ConditionTreeData[]
dispatchthe way of how to change treeData, see dispatch paramsReact.Dispatch

Themes

  • antd - just import this files
1.0.1

5 years ago

1.0.0

5 years ago

0.3.2-0

5 years ago

0.3.1

5 years ago

0.2.3

5 years ago

0.3.0

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.0

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago