Skip to content

1) Add a feature to disable a node. 2) Reduce around 400kB in the transpiled code. 3) Adding support to React node type (string or jsx tags) to the node label. #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@ Individual nodes within the `nodes` property can have the following structure:

| Property | Type | Description |
| ----------- | ------ | ------------------------------- |
| `label` | string | **Required**. The node's label. |
| `label` | mixed | **Required**. The node's label. |
| `value` | mixed | **Required**. The node's value. |
| `children` | array | An array of child nodes. |
| `className` | string | A className to add to the node. |
| `disabled` | bool | Disable node. |
| `icon` | mixed | A custom icon for the node. |
5 changes: 3 additions & 2 deletions src/js/CheckboxTree.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import classNames from 'classnames';
import { isEqual } from 'lodash';
import isEqual from 'lodash/isEqual';
import PropTypes from 'prop-types';
import React from 'react';
import shortid from 'shortid';
Expand Down Expand Up @@ -190,13 +190,14 @@ class CheckboxTree extends React.Component {
const key = `${node.value}`;
const checked = this.getCheckState(node, noCascade);
const children = this.renderChildNodes(node);
const nodeDisabled = !!(disabled || node.disabled);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason the double negation is being used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. The disabled property on TreeNode isRequired. The double negation will transform undefined to false.


return (
<TreeNode
key={key}
checked={checked}
className={node.className}
disabled={disabled}
disabled={nodeDisabled}
expandDisabled={expandDisabled}
expanded={node.expanded}
icon={node.icon}
Expand Down
3 changes: 2 additions & 1 deletion src/js/TreeNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class TreeNode extends React.Component {
disabled: PropTypes.bool.isRequired,
expandDisabled: PropTypes.bool.isRequired,
expanded: PropTypes.bool.isRequired,
label: PropTypes.string.isRequired,
label: PropTypes.node.isRequired,
optimisticToggle: PropTypes.bool.isRequired,
showNodeIcon: PropTypes.bool.isRequired,
treeId: PropTypes.string.isRequired,
Expand Down Expand Up @@ -145,6 +145,7 @@ class TreeNode extends React.Component {
'rct-node': true,
'rct-node-parent': this.hasChildren(),
'rct-node-leaf': !this.hasChildren(),
'rct-disabled': disabled,
}, className);

return (
Expand Down
2 changes: 1 addition & 1 deletion src/js/nodeShape.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import PropTypes from 'prop-types';

const nodeShape = {
label: PropTypes.string.isRequired,
label: PropTypes.node.isRequired,
value: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number,
Expand Down