Skip to content

Commit 002ea2e

Browse files
authored
feat: Display Partially selected nodes ✨ (#73)
1 parent d578f3a commit 002ea2e

37 files changed

+2626
-706
lines changed

.eslintrc.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"parser": "babel-eslint",
3-
"extends": ["standard", "react-app"],
3+
"extends": ["standard", "react-app", "eslint:recommended"],
44
"rules": {
55
"react/jsx-filename-extension": [
66
1,
@@ -15,6 +15,15 @@
1515
}
1616
],
1717
"import/prefer-default-export": 0,
18+
"object-curly-newline": [
19+
"error",
20+
{
21+
"ObjectExpression": { "multiline": true, "minProperties": 3 },
22+
"ObjectPattern": { "multiline": true, "minProperties": 3 },
23+
"ImportDeclaration": { "multiline": true, "minProperties": 3 },
24+
"ExportDeclaration": { "multiline": true, "minProperties": 3 }
25+
}
26+
],
1827
"no-underscore-dangle": 0,
1928
"no-plusplus": 0,
2029
"no-shadow": 0,

.vscode/settings.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"spellright.language": "en",
3+
"spellright.documentTypes": [
4+
"markdown",
5+
"latex",
6+
"plaintext",
7+
"javascript"
8+
]
9+
}

README.md

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
## React Dropdown Tree Select
2626

27-
A lightweight and fast control to render a select component that can display hierarchical tree data. In addition, the control shows the selection in pills and allows user to search the options for quick filtering and selection.
27+
A lightweight and fast control to render a select component that can display hierarchical tree data. In addition, the control shows the selection in pills and allows user to search the options for quick filtering and selection. Also supports displaying partially selected nodes.
2828

2929
## Table of Contents
3030

@@ -35,6 +35,8 @@ A lightweight and fast control to render a select component that can display hie
3535
* [With Material Design](#with-material-design)
3636
* [As Single Select](#as-single-select)
3737
* [Install](#install)
38+
* [As NPM package](#as-npm-package)
39+
* [Using a CDN](#using-a-cdn)
3840
* [Peer Dependencies](#peer-dependencies)
3941
* [Usage](#usage)
4042
* [Props](#props)
@@ -46,6 +48,7 @@ A lightweight and fast control to render a select component that can display hie
4648
* [noMatchesText](#noMatchesText)
4749
* [keepTreeOnSearch](#keeptreeonsearch)
4850
* [simpleSelect](#simpleselect)
51+
* [showPartiallySelected](#showPartiallySelected)
4952
* [Styling and Customization](#styling-and-customization)
5053
* [Using default styles](#default-styles)
5154
* [Customizing with Bootstrap, Material Design styles](#customizing-styles)
@@ -83,24 +86,46 @@ Online demo: https://dowjones.github.io/react-dropdown-tree-select/#/story/simpl
8386

8487
## Install
8588

86-
```
87-
> npm i react-dropdown-tree-select
89+
### As NPM package
90+
91+
```js
92+
npm i react-dropdown-tree-select
8893

8994
// or if using yarn
95+
yarn add react-dropdown-tree-select
96+
```
97+
98+
### Using a CDN
9099

91-
> yarn add react-dropdown-tree-select
100+
You can import the standalone UMD build from a CDN such as:
101+
102+
```html
103+
<script src="https://unpkg.com/react-dropdown-tree-select/dist/react-dropdown-tree-select.js"></script>
104+
<link href="https://unpkg.com/react-dropdown-tree-select/dist/styles.css" rel="stylesheet">
92105
```
93106

107+
**Note:** Above example will always fetch the latest version. To fetch a specific version, use `https://unpkg.com/react-dropdown-tree-select@<version>/dist/...`
108+
Visit [unpkg.com](https://unpkg.com/#/) to see other options.
109+
94110
### Peer Dependencies
95111

96112
In order to avoid version conflicts in your project, you must specify and install [react](https://www.npmjs.com/package/react), [react-dom](https://www.npmjs.com/package/react-dom) as [peer dependencies](https://nodejs.org/en/blog/npm/peer-dependencies/). Note that NPM doesn't install peer dependencies automatically. Instead it will show you a warning message with instructions on how to install them.
97113

114+
If you're using the UMD builds, you'd also need to install the peer dependencies in your application:
115+
116+
```html
117+
<script src="https://unpkg.com/react/dist/react.js"></script>
118+
<script src="https://unpkg.com/react-dom/dist/react-dom.js"></script>
119+
```
120+
98121
## Usage
99122

100123
```jsx
101124
import React from 'react'
102125
import ReactDOM from 'react-dom'
126+
103127
import DropdownTreeSelect from 'react-dropdown-tree-select'
128+
import 'react-dropdown-tree-select/dist/styles.css'
104129

105130
const data = {
106131
label: 'search me',
@@ -129,15 +154,7 @@ const onNodeToggle = currentNode => {
129154
console.log('onNodeToggle::', currentNode)
130155
}
131156

132-
ReactDOM.render(
133-
<DropdownTreeSelect
134-
data={data}
135-
onChange={onChange}
136-
onAction={onAction}
137-
onNodeToggle={onNodeToggle}
138-
/>,
139-
document.body
140-
) // in real world, you'd want to render to an element, instead of body.
157+
ReactDOM.render(<DropdownTreeSelect data={data} onChange={onChange} onAction={onAction} onNodeToggle={onNodeToggle} />, document.body) // in real world, you'd want to render to an element, instead of body.
141158
```
142159

143160
## Props
@@ -244,6 +261,12 @@ Type: `bool` (default: `false`)
244261

245262
Turns the dropdown into a simple, single select dropdown. If you pass tree data, only immediate children are picked, grandchildren nodes are ignored. Defaults to `false`.
246263

264+
### showPartiallySelected
265+
266+
Type: `bool` (default: `false`)
267+
268+
If set to true, shows checkboxes in a partial state when one, but not all of their children are selected. Allows styling of partially selected nodes as well, by using [:indeterminate](https://developer.mozilla.org/en-US/docs/Web/CSS/:indeterminate) pseudo class. Simply add desired styles to `.node.partial .checkbox-item:indeterminate { ... }` in your CSS.
269+
247270
## Styling and Customization
248271

249272
### Default styles
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Snapshot report for `src\checkbox\index.test.js`
2+
3+
The actual snapshot is saved in `index.test.js.snap`.
4+
5+
Generated by [AVA](https://ava.li).
6+
7+
## Checkbox component
8+
9+
> Snapshot 1
10+
11+
<input
12+
className="sample"
13+
type="checkbox"
14+
/>
15+
16+
## renders disabled state
17+
18+
> Snapshot 1
19+
20+
<input
21+
disabled={true}
22+
type="checkbox"
23+
/>
252 Bytes
Binary file not shown.

docs/.eslintrc.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"rules": {
3+
"no-console": 0
4+
}
5+
}

docs/src/App.js

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
import React from 'react'
22
import ReactStory, { defaultProps } from 'react-story'
33

4-
import CodeSandbox from './CodeSandbox.js'
5-
import HOCReadme from './stories/HOCReadme.js'
6-
import Readme from './stories/Readme.js'
4+
import CodeSandbox from './CodeSandbox'
5+
import HOCReadme from './stories/HOCReadme'
6+
import Readme from './stories/Readme'
7+
import Simple from './stories/Simple'
8+
import Options from './stories/Options'
79

810
import './stories/utils/prism.css'
911

1012
const stories = [
1113
{ name: 'Readme', component: Readme },
1214
{ name: 'HOC Readme', component: HOCReadme },
1315

14-
{ name: 'With Vanilla Styles', component: CodeSandbox('v0nmw5ykk5') },
16+
{ name: 'Basic (no extra styles)', component: Simple },
17+
{ name: 'Options', component: Options },
1518
{ name: 'With Bootstrap Styles', component: CodeSandbox('382pjronm') },
1619
{ name: 'With Material Design Styles', component: CodeSandbox('2o1pv6925p') },
1720
{ name: 'With Country flags', component: CodeSandbox('6w41wlvj8z') },
@@ -31,35 +34,33 @@ const stories = [
3134
{ name: 'Tree Node Paths (HOC)', component: CodeSandbox('l765q6lmrq') }
3235
]
3336

34-
export default class App extends React.Component {
35-
render() {
36-
return (
37-
<ReactStory
38-
style={{
39-
display: 'block',
40-
width: '100%',
41-
height: '100%'
37+
const App = () => (
38+
<ReactStory
39+
style={{
40+
display: 'block',
41+
width: '100%',
42+
height: '100%'
43+
}}
44+
pathPrefix="story/"
45+
Story={props => (
46+
<defaultProps.StoryWrapper
47+
css={{
48+
padding: 0,
49+
display: 'flex',
50+
flexDirection: 'column'
4251
}}
43-
pathPrefix="story/"
44-
Story={props => (
45-
<defaultProps.StoryWrapper
46-
css={{
47-
padding: 0,
48-
display: 'flex',
49-
flexDirection: 'column'
50-
}}
51-
>
52-
<div
53-
{...props}
54-
style={{
55-
flex: '1 0 auto',
56-
position: 'relative'
57-
}}
58-
/>
59-
</defaultProps.StoryWrapper>
60-
)}
61-
stories={stories}
62-
/>
63-
)
64-
}
65-
}
52+
>
53+
<div
54+
{...props}
55+
style={{
56+
flex: '1 0 auto',
57+
position: 'relative'
58+
}}
59+
/>
60+
</defaultProps.StoryWrapper>
61+
)}
62+
stories={stories}
63+
/>
64+
)
65+
66+
export default App

docs/src/index.css

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,11 @@
1-
html, body, #app {
1+
html,
2+
body,
3+
#app {
24
height: 100%;
35
}
46

57
body {
68
margin: 0;
79
padding: 0;
8-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', Helvetica, Arial, sans-serif;;
9-
}
10-
11-
.suspended .node-label {
12-
font-style: italic;
13-
text-decoration: line-through;
14-
}
15-
16-
.dropdown-content {
17-
max-height: 400px;
18-
overflow-y: auto;
19-
}
20-
21-
.node .fa {
22-
font-size: 12px;
23-
margin-left: 4px;
24-
cursor: pointer;
25-
}
26-
27-
.node .fa-ban {
28-
color: darkorange;
10+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', Helvetica, Arial, sans-serif;
2911
}

docs/src/stories/Options/Checkbox.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import React, { PureComponent } from 'react'
2+
import PropTypes from 'prop-types'
3+
4+
class Checkbox extends PureComponent {
5+
state = {isChecked: this.props.checked || false}
6+
7+
toggleCheckboxChange = () => {
8+
const { onChange, value } = this.props
9+
10+
this.setState(({ isChecked }) => ({isChecked: !isChecked}))
11+
12+
onChange(value)
13+
}
14+
15+
render() {
16+
const { label, value } = this.props
17+
const { isChecked } = this.state
18+
19+
return (
20+
<div className="checkbox">
21+
<label>
22+
<input type="checkbox" value={value} defaultChecked={isChecked} onChange={this.toggleCheckboxChange} />
23+
{label}
24+
</label>
25+
</div>
26+
)
27+
}
28+
}
29+
30+
Checkbox.propTypes = {
31+
label: PropTypes.string.isRequired,
32+
value: PropTypes.string.isRequired,
33+
onChange: PropTypes.func.isRequired,
34+
checked: PropTypes.bool
35+
}
36+
37+
export default Checkbox

0 commit comments

Comments
 (0)