Skip to content
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

Add Render Button Right #190

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions examples/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ <h2>Filter Example</h2>
<p>Filtering of nodes is also easily possible.</p>
<div id="filter-example"></div>

<h2>Expander Right Example</h2>
<p>Place the expander on the right side of the node.</p>
<div id="expander-right-example"></div>

<footer class="site-footer">
<span class="site-footer-owner">
<a href="https://github.com/jakezatecky/react-checkbox-tree">React Checkbox Tree</a> is maintained by <a href="https://github.com/jakezatecky">jakezatecky</a>.
Expand Down
2 changes: 2 additions & 0 deletions examples/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import NoCascadeExample from './js/NoCascadeExample';
import LargeDataExample from './js/LargeDataExample';
import PessimisticToggleExample from './js/PessimisticToggleExample';
import FilterExample from './js/FilterExample';
import ExpanderRightExample from './js/ExpanderRightExample';

ReactDOM.render(<BasicExample />, document.getElementById('basic-example'));
ReactDOM.render(<CustomIconsExample />, document.getElementById('custom-icons-example'));
Expand All @@ -22,3 +23,4 @@ ReactDOM.render(<HiddenCheckboxesExample />, document.getElementById('hidden-che
ReactDOM.render(<ExpandAllExample />, document.getElementById('expand-all-example'));
ReactDOM.render(<LargeDataExample />, document.getElementById('large-data-example'));
ReactDOM.render(<FilterExample />, document.getElementById('filter-example'));
ReactDOM.render(<ExpanderRightExample />, document.getElementById('expander-right-example'));
129 changes: 129 additions & 0 deletions examples/src/js/ExpanderRightExample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import React from 'react';
import CheckboxTree from 'react-checkbox-tree';

const nodes = [
{
value: '/app',
label: 'app',
children: [
{
value: '/app/Http',
label: 'Http',
children: [
{
value: '/app/Http/Controllers',
label: 'Controllers',
children: [{
value: '/app/Http/Controllers/WelcomeController.js',
label: 'WelcomeController.js',
}],
},
{
value: '/app/Http/routes.js',
label: 'routes.js',
},
],
},
{
value: '/app/Providers',
label: 'Providers',
children: [{
value: '/app/Providers/EventServiceProvider.js',
label: 'EventServiceProvider.js',
}],
},
],
},
{
value: '/config',
label: 'config',
children: [
{
value: '/config/app.js',
label: 'app.js',
},
{
value: '/config/database.js',
label: 'database.js',
},
],
},
{
value: '/public',
label: 'public',
children: [
{
value: '/public/assets/',
label: 'assets',
children: [{
value: '/public/assets/style.css',
label: 'style.css',
}],
},
{
value: '/public/index.html',
label: 'index.html',
},
],
},
{
value: '/.env',
label: '.env',
},
{
value: '/.gitignore',
label: '.gitignore',
},
{
value: '/README.md',
label: 'README.md',
},
];

class ExpanderRightExample extends React.Component {
state = {
checked: [
'/app/Http/Controllers/WelcomeController.js',
'/app/Http/routes.js',
'/public/assets/style.css',
'/public/index.html',
'/.gitignore',
],
expanded: [
'/app',
],
};

constructor(props) {
super(props);

this.onCheck = this.onCheck.bind(this);
this.onExpand = this.onExpand.bind(this);
}

onCheck(checked) {
this.setState({ checked });
}

onExpand(expanded) {
this.setState({ expanded });
}

render() {
const { checked, expanded } = this.state;

return (
<CheckboxTree
checked={checked}
expanded={expanded}
iconsClass="fa5"
nodes={nodes}
onCheck={this.onCheck}
onExpand={this.onExpand}
expanderRight
/>
);
}
}

export default ExpanderRightExample;
4 changes: 4 additions & 0 deletions src/js/CheckboxTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class CheckboxTree extends React.Component {
expandDisabled: PropTypes.bool,
expandOnClick: PropTypes.bool,
expanded: listShape,
expanderRight: PropTypes.bool,
icons: iconsShape,
iconsClass: PropTypes.string,
id: PropTypes.string,
Expand All @@ -48,6 +49,7 @@ class CheckboxTree extends React.Component {
expandDisabled: false,
expandOnClick: false,
expanded: [],
expanderRight: false,
icons: {
check: <span className="rct-icon rct-icon-check" />,
uncheck: <span className="rct-icon rct-icon-uncheck" />,
Expand Down Expand Up @@ -208,6 +210,7 @@ class CheckboxTree extends React.Component {
const {
expandDisabled,
expandOnClick,
expanderRight,
icons,
lang,
noCascade,
Expand Down Expand Up @@ -247,6 +250,7 @@ class CheckboxTree extends React.Component {
className={node.className}
disabled={flatNode.disabled}
expandDisabled={expandDisabled}
expanderRight={expanderRight}
expandOnClick={expandOnClick}
expanded={flatNode.expanded}
icon={node.icon}
Expand Down
11 changes: 8 additions & 3 deletions src/js/TreeNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class TreeNode extends React.Component {
disabled: PropTypes.bool.isRequired,
expandDisabled: PropTypes.bool.isRequired,
expanded: PropTypes.bool.isRequired,
expanderRight: PropTypes.bool.isRequired,
icons: iconsShape.isRequired,
isLeaf: PropTypes.bool.isRequired,
isParent: PropTypes.bool.isRequired,
Expand Down Expand Up @@ -105,7 +106,9 @@ class TreeNode extends React.Component {
}

renderCollapseButton() {
const { expandDisabled, isLeaf, lang } = this.props;
const {
expandDisabled, isLeaf, lang, expanderRight,
} = this.props;

if (isLeaf) {
return (
Expand All @@ -117,7 +120,7 @@ class TreeNode extends React.Component {

return (
<Button
className="rct-collapse rct-collapse-btn"
className={`rct-collapse rct-collapse-btn ${expanderRight ? 'rct-collapse-right' : ''}`}
disabled={expandDisabled}
title={lang.toggle}
onClick={this.onExpand}
Expand Down Expand Up @@ -275,6 +278,7 @@ class TreeNode extends React.Component {
className,
disabled,
expanded,
expanderRight,
isLeaf,
} = this.props;
const nodeClass = classNames({
Expand All @@ -289,8 +293,9 @@ class TreeNode extends React.Component {
return (
<li className={nodeClass}>
<span className="rct-text">
{this.renderCollapseButton()}
{expanderRight ? null : this.renderCollapseButton() }
{this.renderLabel()}
{expanderRight ? this.renderCollapseButton() : null }
</span>
{this.renderChildren()}
</li>
Expand Down
4 changes: 4 additions & 0 deletions src/scss/react-checkbox-tree.scss
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ $rct-clickable-focus: rgba($rct-icon-color, .2) !default;
}
}

.rct-collapse-right {
margin-left: auto;
}

.rct-checkbox {
.rct-native-display & {
display: none;
Expand Down