Comments (1)
i tried this kind of workaround
the idea is to have a placeholder loading node as children and update the nodes array as needed, declaring it as a function state var
seems like it's not calling the static getDerivedFromProps (and thus flattenNode), but can't check it because the lib is already bundled
import React from 'react';
import CheckboxTree from 'react-checkbox-tree';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import {
faCheckSquare,
faSquareMinus,
faChevronRight,
faChevronDown,
faPlusSquare,
faMinusSquare,
faFolder,
faFolderOpen,
faFile,
faSpinner,
} from '@fortawesome/free-solid-svg-icons';
import { faSquare } from '@fortawesome/free-regular-svg-icons';
import 'react-checkbox-tree/lib/react-checkbox-tree.css';
interface Node {
value: string;
label: string;
children?: Node[];
showCheckbox?: boolean;
icon?: JSX.Element;
}
export const FileSystem: React.FunctionComponent = () => {
const [nodes, setNodes] = React.useState<Node[]>([
{
value: '/mnt',
label: '/mnt',
children: [
{
value: 'loading',
label: 'loading',
// children: [],
showCheckbox: false,
icon: (
<FontAwesomeIcon
className="fill-red-400 text-yellow-600"
icon={faSpinner}
/>
),
},
],
},
]);
const [checked, setChecked] = React.useState<string[]>([]);
const [expanded, setExpanded] = React.useState<string[]>([]);
const onCheck = (value: string[]) => {
console.log('onCheck ', value);
setChecked(value);
};
const onExpand = (value: string[]) => {
console.log('onExpand ', value);
// setIsLoading(true);
// const loaded =
const newNodes = [...nodes];
newNodes[0].children = [
{
value: 'films',
label: 'films',
children: [
{
value: 'loading',
label: 'loading',
children: [],
showCheckbox: false,
icon: (
<FontAwesomeIcon
className="fill-red-400 text-yellow-600"
icon={faSpinner}
/>
),
},
],
},
];
console.log('newNodes ', newNodes);
setNodes(newNodes);
setExpanded(value);
};
return (
<div className="flex flex-1 bg-neutral-200 dark:bg-gray-950">
<div className={`overflow-y-auto`} style={{ height: 500 }}>
<FontAwesomeIcon
className="rct-icon rct-icon-check"
icon="check-square"
/>
<CheckboxTree
checked={checked}
expanded={expanded}
nodes={nodes}
onCheck={onCheck}
onExpand={onExpand}
noCascade
optimisticToggle={false}
icons={{
check: (
<FontAwesomeIcon
className="fill-red-400 text-yellow-600"
icon={faCheckSquare}
/>
),
uncheck: (
<FontAwesomeIcon className="text-slate-700" icon={faSquare} />
),
halfCheck: (
<FontAwesomeIcon
className="rct-icon rct-icon-half-check"
icon={faSquareMinus}
/>
),
expandClose: (
<FontAwesomeIcon
className="rct-icon rct-icon-expand-close"
icon={faChevronRight}
/>
),
expandOpen: (
<FontAwesomeIcon
className="rct-icon rct-icon-expand-close"
icon={faChevronDown}
/>
),
expandAll: (
<FontAwesomeIcon className="fill-red-600" icon={faPlusSquare} />
),
collapseAll: (
<FontAwesomeIcon
className="rct-icon rct-icon-collapse-all"
icon={faMinusSquare}
/>
),
parentClose: (
<FontAwesomeIcon
className="rct-icon rct-icon-parent-close"
icon={faFolder}
/>
),
parentOpen: (
<FontAwesomeIcon
className="rct-icon rct-icon-parent-open"
icon={faFolderOpen}
/>
),
leaf: (
<FontAwesomeIcon
className="rct-icon rct-icon-leaf-close"
icon={faFile}
/>
),
}}
/>
</div>
</div>
);
};
from react-checkbox-tree.
Related Issues (20)
- Unable to get just the checked parent value if all the childrens are selected rather than getting all checked values HOT 1
- stop checked value clear when refresh HOT 1
- select parent value only
- checked parent programatically
- Does this library have built in function for filtering?
- Inconsistent Id between render HOT 2
- After filtering, is it possible for all parent nodes of filtered nodes to be expanded? HOT 1
- When a parent is checked is it possible to expand all its children nodes HOT 1
- When I input the filter , icon
- Enable the check only at last level parent node and child nodes HOT 2
- Any plan to update npm? HOT 1
- css is not loading properly HOT 2
- Icon option for disabled HOT 1
- Handling for having a single node in multiple separate branches of the same tree.
- Add the ability to create files and folders
- Add half checked icon to parent element with some checked children HOT 2
- How to override the checkbox predefined classes HOT 1
- Get ID HOT 2
- Disable Parent checkbox if have children checkbox HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-checkbox-tree.