feat: active

This commit is contained in:
cha0s 2021-04-02 17:01:02 -05:00
parent 66fac20fac
commit 90aa764a17
3 changed files with 27 additions and 27 deletions

View File

@ -4,31 +4,22 @@ import {PropTypes, React} from '@latus/react';
import Node from './node';
const Tree = ({
activate,
indent,
label,
nodes,
value,
}) => (
const Tree = (node) => (
<div className="tree">
<Node
activate={activate}
indent={indent}
label={label}
nodes={nodes}
value={value}
/>
{/* eslint-disable-next-line react/jsx-props-no-spreading */}
<Node {...node} />
</div>
);
Tree.defaultProps = {
active: () => false,
activate: () => {},
indent: 0,
nodes: null,
};
Tree.propTypes = {
active: PropTypes.func,
activate: PropTypes.func,
indent: PropTypes.number,
label: PropTypes.string.isRequired,

View File

@ -17,6 +17,13 @@
min-height: auto;
}
.node {
&.active {
background-color: rgba(0, 120, 255, 0.5);
}
&.parent > .item .label:before {
// content: "\25B8";
content: "\25BE";
}
> .item .label {
white-space: nowrap;
&:before {
@ -26,9 +33,5 @@
padding-right: 0.5em;
}
}
&.parent > .item .label:before {
// content: "\25B8";
content: "\25BE";
}
}
}

View File

@ -1,13 +1,15 @@
import {PropTypes, React} from '@latus/react';
import classnames from 'classnames';
const Node = ({
activate,
indent,
label,
nodes,
value,
}) => {
const Node = (node) => {
const {
active,
activate,
indent,
label,
nodes,
value,
} = node;
const childrenNodes = nodes
? nodes.map(
({
@ -16,6 +18,7 @@ const Node = ({
value,
}) => (
<Node
active={active}
activate={activate}
key={value}
// eslint-disable-next-line react/no-children-prop
@ -30,8 +33,8 @@ const Node = ({
let item = (
<div
className="label"
onClick={() => {
activate(value, nodes);
onMouseDown={() => {
activate(node);
}}
onKeyPress={() => {}}
role="button"
@ -47,6 +50,7 @@ const Node = ({
<div
className={classnames(
'node',
{active: active(node)},
{parent: !!nodes},
)}
key={value}
@ -58,12 +62,14 @@ const Node = ({
};
Node.defaultProps = {
active: () => false,
activate: () => {},
indent: 0,
nodes: null,
};
Node.propTypes = {
active: PropTypes.func,
activate: PropTypes.func,
indent: PropTypes.number,
label: PropTypes.string.isRequired,