0.7.6 • Published 4 years ago

intelligent-dag-select v0.7.6

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

Intelligent-DAG-Select

React DAG select component based on intelligent-tree-select which is based on react-select and react-virtualized-select

Intelligent-DAG-Select is a modified version of intelligent-tree-select that uses DAG as input data and renders it as a tree. Thus, some subtrees may occur multiple times in the tree.

Before start

Before you can use this component you will need Node.js in version 6.5+, but i recommend to use the latest available version.

Getting started

Easiest way is to install via NPM

npm install intelligent-dag-select --save

Then import it

import { DagSelect } from 'intelligent-dag-select'
import { TreeSelect } from 'intelligent-dag-select'
import 'bootstrap/dist/css/bootstrap.css';
import "intelligent-dag-select/lib/styles.css"

example of the usage in the src/demo.js

Components

  • VirtualizedTreeSelect provides a list select.
  • ExpandableTreeSelect adds an expand button to each item in the list.
  • TreeSelect adds an option to load data using the fetchOptions function, that returns either a list of new items or a Promise of the new items.
  • DagSelect adds a "DAG to Tree" conversion adding items to the list so that it can handle duplicate items and cycles.

Virtualized tree select Props

Props types are same as the one introduced by react-select@1.x The additional parameters introduced by virtualized-tree-select are optional. They are:

PropertyTypeDefault ValueDescription
childrenKeystring'children'path of the child value in option objects
expandedboolfalsewhether the options are expanded by default
isMenuOpenboolfalseWhether the menu is open. Setting this to true force menu to me always opened
maxHeightnumber300Maximum height of the dropdown menu
minHeightnumber0Minimum height of the dropdown menu
menuRendererfunc-overriding built-in drop-down menu render function
optionRendererfunc-overriding built-in option render function.
optionHeightnumber or func25pxOption height. Dynamic height can be supported via a function with the signature ({ option: Object }): number
optionLeftOffsetnumber16pxOption base left offset. Left offset is calculated as depth level of the option * optionLeftOffset
renderAsTreebooltruewhether options should be rendered as a tree.

Custom Option Renderer

You can override the built-in option renderer by specifying your own optionRenderer property. Your renderer should return a React element that represents the specified option. It will be passed the following named parameters:

PropertyTypeDescription
childrenKeystringAttribute of option that contains the children key.
focusedOptionObjectThe option currently-focused in the dropdown. Use this property to determine if your rendered option should be highlighted or styled differently.
focusedOptionIndexnumberIndex of the currently-focused option.
focusOptionFunctionCallback to update the focused option; for example, you may want to call this function on mouse-over.
keystringA unique identifier for each element created by the renderer.
labelKeystringAttribute of option that contains the display text.
optionObjectThe option to be rendered.
optionIndexnumberIndex of the option to be rendered.
renderAsTreeboolWhether the options should be render as a tree.
searchStringstringCurrent content of the search input.
selectValueFunctionCallback to update the selected values; for example, you may want to call this function on click.
optionStyleObjectStyles that must be passed to the rendered option. These styles are specifying the position of each option (required for correct option displaying in the dropdown).
toggleOptionFunctionExpand/Collapse option if it has children.
valueArrayArray<Object>Array of the currently-selected options. Use this property to determine if your rendered option should be highlighted or styled differently.
valueKeystringAttribute of option that contains the value.

Intelligent tree select props

PropertyTypeDefault ValueDescription
displayInfoOnHoverboolfalseWhether to render option information on hover. By default, this info is extracted by transforming the option to JSON and stringifying it.
tooltipKeystring--Attribute of option which will be used as content of hover tooltip (instead of stringified option itself).
labelValuefunc--Return the label for option. Function with signature ({ option: Object }): string
onOptionCreatefunction--callback when the new option is created. Signature ({ option: Object}): none
optionLifetimestring'5m'String representing how long the options should be cached. Syntax: XdXhXmXs where X is some number, d stands for days, h hours ,m minutes, s seconds
showSettingsbool'true'whether the section with settings and button for creating new option should be visible
simpleTreeDatabooltruewhether the options are in the simple format. (One node == one option)
fetchOptionsfunc--Signature: ({searchString, optionID, limit, offset, option}): Promise. If the optionID is not an empty string then the function should return children options of that option (option is provided as well should it be needed). If the searchString is not an empty string then the function should return all options whose label value match the searchStromg + their parent options
fetchLimitnumber100amount of data to be fetched
multibooltruewhether the select in multi select or not
namestring--Unique name for the component. Whenever this prop is set then the options will be cached
formComponentfunc--Function returning React element representing form. Syntax ({onOptionCreate, toggleModal, options, labelKey, valueKey, childrenKey}): React.component

IntelligentTreeSelect public API

MethodDescription
resetOptionsForce reloading of options when fetchOptions property is used to specify how to load options. If options are specified in props, this reloads them from the current props.