react-icons/fa#FaChevronUp JavaScript Examples
The following examples show how to use
react-icons/fa#FaChevronUp.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: sort.js From react-table-library with MIT License | 5 votes |
Component = () => {
const data = { nodes };
const chakraTheme = getTheme(DEFAULT_OPTIONS);
const theme = useTheme(chakraTheme);
const sort = useSort(
data,
{
onChange: onSortChange,
},
{
sortIcon: {
iconDefault: null,
iconUp: <FaChevronUp />,
iconDown: <FaChevronDown />,
},
sortFns: {
TASK: (array) => array.sort((a, b) => a.name.localeCompare(b.name)),
DEADLINE: (array) => array.sort((a, b) => a.deadline - b.deadline),
TYPE: (array) => array.sort((a, b) => a.type.localeCompare(b.type)),
COMPLETE: (array) => array.sort((a, b) => a.isComplete - b.isComplete),
TASKS: (array) => array.sort((a, b) => (a.nodes || []).length - (b.nodes || []).length),
},
},
);
function onSortChange(action, state) {
console.log(action, state);
}
const COLUMNS = [
{ label: 'Task', renderCell: (item) => item.name, sort: { sortKey: 'TASK' } },
{
label: 'Deadline',
renderCell: (item) =>
item.deadline.toLocaleDateString('en-US', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
}),
sort: { sortKey: 'DEADLINE' },
},
{ label: 'Type', renderCell: (item) => item.type, sort: { sortKey: 'TYPE' } },
{
label: 'Complete',
renderCell: (item) => item.isComplete.toString(),
sort: { sortKey: 'COMPLETE' },
},
{ label: 'Tasks', renderCell: (item) => item.nodes?.length, sort: { sortKey: 'TASKS' } },
];
return (
<>
<Box p={3} borderWidth="1px" borderRadius="lg">
<CompactTable columns={COLUMNS} data={data} sort={sort} theme={theme} />
</Box>
<br />
<DocumentationSee anchor={'Features/' + key} />
</>
);
}
Example #2
Source File: sort.js From react-table-library with MIT License | 5 votes |
Component = () => {
const data = { nodes };
const mantineTheme = getTheme(DEFAULT_OPTIONS);
const theme = useTheme(mantineTheme);
const sort = useSort(
data,
{
onChange: onSortChange,
},
{
sortIcon: {
iconDefault: null,
iconUp: <FaChevronUp />,
iconDown: <FaChevronDown />,
},
sortFns: {
TASK: (array) => array.sort((a, b) => a.name.localeCompare(b.name)),
DEADLINE: (array) => array.sort((a, b) => a.deadline - b.deadline),
TYPE: (array) => array.sort((a, b) => a.type.localeCompare(b.type)),
COMPLETE: (array) => array.sort((a, b) => a.isComplete - b.isComplete),
TASKS: (array) => array.sort((a, b) => (a.nodes || []).length - (b.nodes || []).length),
},
},
);
function onSortChange(action, state) {
console.log(action, state);
}
const COLUMNS = [
{ label: 'Task', renderCell: (item) => item.name, sort: { sortKey: 'TASK' } },
{
label: 'Deadline',
renderCell: (item) =>
item.deadline.toLocaleDateString('en-US', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
}),
sort: { sortKey: 'DEADLINE' },
},
{ label: 'Type', renderCell: (item) => item.type, sort: { sortKey: 'TYPE' } },
{
label: 'Complete',
renderCell: (item) => item.isComplete.toString(),
sort: { sortKey: 'COMPLETE' },
},
{ label: 'Tasks', renderCell: (item) => item.nodes?.length, sort: { sortKey: 'TASKS' } },
];
return (
<>
<CompactTable columns={COLUMNS} data={data} sort={sort} theme={theme} />
<br />
<DocumentationSee anchor={'Features/' + key} />
</>
);
}
Example #3
Source File: sort.js From react-table-library with MIT License | 5 votes |
Component = () => {
const data = { nodes };
const materialTheme = getTheme(DEFAULT_OPTIONS);
const theme = useTheme(materialTheme);
const sort = useSort(
data,
{
onChange: onSortChange,
},
{
sortIcon: {
iconDefault: null,
iconUp: <FaChevronUp />,
iconDown: <FaChevronDown />,
},
sortFns: {
TASK: (array) => array.sort((a, b) => a.name.localeCompare(b.name)),
DEADLINE: (array) => array.sort((a, b) => a.deadline - b.deadline),
TYPE: (array) => array.sort((a, b) => a.type.localeCompare(b.type)),
COMPLETE: (array) => array.sort((a, b) => a.isComplete - b.isComplete),
TASKS: (array) => array.sort((a, b) => (a.nodes || []).length - (b.nodes || []).length),
},
},
);
function onSortChange(action, state) {
console.log(action, state);
}
const COLUMNS = [
{ label: 'Task', renderCell: (item) => item.name, sort: { sortKey: 'TASK' } },
{
label: 'Deadline',
renderCell: (item) =>
item.deadline.toLocaleDateString('en-US', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
}),
sort: { sortKey: 'DEADLINE' },
},
{ label: 'Type', renderCell: (item) => item.type, sort: { sortKey: 'TYPE' } },
{
label: 'Complete',
renderCell: (item) => item.isComplete.toString(),
sort: { sortKey: 'COMPLETE' },
},
{ label: 'Tasks', renderCell: (item) => item.nodes?.length, sort: { sortKey: 'TASKS' } },
];
return (
<>
<CompactTable columns={COLUMNS} data={data} sort={sort} theme={theme} />
<br />
<DocumentationSee anchor={'Features/' + key} />
</>
);
}
Example #4
Source File: Article.js From testnets-cardano-org with MIT License | 4 votes |
Article = ({ pageContext }) => {
const [position, setPosition] = useState('top')
const [navigationHeights, setNavigationHeights] = useState({
min: null,
max: null,
})
const [maxWidth, setMaxWidth] = useState(null)
const [mobileTopNavigationOpen, setMobileTopNavigationOpen] = useState(false)
const [mobileBottomNavigationOpen, setMobileBottomNavigationOpen] =
useState(false)
function getReportIssueHref({ pathname, query, hash }) {
const baseHref = `https://github.com/${config.gitHubRepository}/issues/new?assignees=&labels=content&template=content-issue.md&title=`
return `${baseHref}${encodeURIComponent(
`Invalid content ${pathname}${query || ''}${hash || ''}`
)}`
}
const renderDownloaders = (loc) => {
if (!loc) return
if (!loc.href) return
if (loc.href.includes('/cardano/get-started/wallet/')) {
return <CardanoDownloader />
}
}
/**
* Replaces references to custom components with rendered component
* e.g. <!-- include components/OtherComponent --> -> renders components/MarkdownComponents/OtherComponent if it exists
* e.g. <!-- embed youtube/123 --> -> Renders embedded youtube video with id 123
*/
function renderArticleContent() {
let remainingContent = pageContext.content
const contentParts = []
// Matches <!-- include components/<MyComponent> --> - where <MyComponent> is Alpha string reference to component
// Or <!-- embed youtube/id --> - where id is the YouTube video id to embed
// Or <!-- embed grafana/url --> - where url is the Grafana URL
// in src/components/MarkdownComponent/index.js
const pattern =
/<!--\s(include|embed)\s(components|youtube|grafana)\/([^\s]+)\s-->/
let match = remainingContent.match(pattern)
let matchIndex = match ? match.index : -1
while (remainingContent.length > 0 && matchIndex >= 0) {
if (matchIndex > 0) {
contentParts.push(
<Markdown source={remainingContent.substring(0, matchIndex)} />
)
}
const [_, type, category, value] = match
if (type === 'include' && category === 'components') {
const Component = MarkdownComponents[value]
if (Component) contentParts.push(<Component />)
} else if (type === 'embed' && category === 'youtube' && value) {
contentParts.push(
<YouTube
videoId={value}
opts={{
width: '100%',
height: '350px',
}}
/>
)
} else if (type === 'embed' && category === 'grafana' && value) {
contentParts.push(<Grafana embedLink={value} />)
}
remainingContent = remainingContent.substring(
matchIndex + match[0].length
)
match = remainingContent.match(pattern)
matchIndex = match ? match.index : -1
}
if (remainingContent)
contentParts.push(<Markdown source={remainingContent} />)
return (
<Fragment>
{contentParts.map((content, index) => (
<Fragment key={index}>{content}</Fragment>
))}
</Fragment>
)
}
return (
<GlobalContentQuery
render={(content) => (
<Layout
template={Blank}
headData={{
title: pageContext.pageTitle,
meta: [{ name: 'description', content: '' }],
}}
>
<Container>
<Location>
{({ location }) => (
<PageContent>
{pageContext.navigationContext.children.length > 0 && (
<SideNavigationContainer
navigationheights={navigationHeights}
maxWidth={maxWidth}
className={`position-${position}`}
>
<div>
<NavigationTree
ariaLabel={`${pageContext.navigationContext.title} subnavigation`}
lang={pageContext.lang}
items={pageContext.navigationContext.children}
path={`/${pageContext.navigationContext.key}`}
currentPathname={location.pathname}
position={position}
setPosition={setPosition}
navigationHeights={navigationHeights}
setNavigationHeights={setNavigationHeights}
maxWidth={maxWidth}
setMaxWidth={setMaxWidth}
/>
</div>
</SideNavigationContainer>
)}
<MainContent
className={
pageContext.navigationContext.children.length === 0
? 'no-nav'
: ''
}
>
{pageContext.navigationContext.children.length > 0 && (
<MobileInlineNavigation
className={mobileTopNavigationOpen ? 'open' : ''}
>
<div>
<NavigationTree
lang={pageContext.lang}
ariaLabel={`${pageContext.navigationContext.title} subnavigation`}
items={pageContext.navigationContext.children}
path={`/${pageContext.navigationContext.key}`}
currentPathname={location.pathname}
autoScroll={false}
/>
</div>
<a
href="#"
aria-hidden="true"
tracking={{
label: 'toggle_mobile_article_navigation_top',
}}
onClick={(e) => {
e.preventDefault()
setMobileTopNavigationOpen(!mobileTopNavigationOpen)
}}
>
{mobileTopNavigationOpen && <FaChevronUp />}
{!mobileTopNavigationOpen && <FaEllipsisH />}
</a>
</MobileInlineNavigation>
)}
<MarkdownContent>{renderArticleContent()}</MarkdownContent>
<MarkdownContent>
{renderDownloaders(location)}
</MarkdownContent>
<MarkdownContent>
{!pageContext.hasNoChildContent &&
(pageContext.previous || pageContext.next) && (
<Box
display="flex"
flexDirection="row"
justifyContent="space-between"
width="100%"
>
{pageContext.previous &&
pageContext.previous.path !==
'/testnets/cardano/' && (
<Link
href={pageContext.previous.path}
title={pageContext.previous.title}
>
← {content.previous}
</Link>
)}
{pageContext.next && (
<Link
href={pageContext.next.path}
title={pageContext.next.title}
>
{content.next} →
</Link>
)}
</Box>
)}
</MarkdownContent>
<Box marginTop={2} marginBottom={2}>
{config.gitHubRepository && (
<Box display="flex">
<ReportAnIssueLink
href={getReportIssueHref(location)}
tracking={{
category: 'article',
label: 'report_an_issue',
}}
>
<Box
display="flex"
marginRight={1}
flexDirection="column"
justifyContent="center"
>
<FaGithub />
</Box>
<Box
display="flex"
flexDirection="column"
justifyContent="center"
>
<p>{content.report_an_issue}</p>
</Box>
</ReportAnIssueLink>
</Box>
)}
</Box>
{pageContext.navigationContext.children.length > 0 && (
<MobileInlineNavigation
className={mobileBottomNavigationOpen ? 'open' : ''}
>
<div>
<NavigationTree
lang={pageContext.lang}
ariaLabel={`${pageContext.navigationContext.title} subnavigation`}
items={pageContext.navigationContext.children}
path={`/${pageContext.navigationContext.key}`}
currentPathname={location.pathname}
autoScroll={false}
/>
</div>
<a
href="#"
aria-hidden="true"
tracking={{
label: 'toggle_mobile_article_navigation_bottom',
}}
onClick={(e) => {
e.preventDefault()
setMobileBottomNavigationOpen(
!mobileBottomNavigationOpen
)
}}
>
{mobileBottomNavigationOpen && <FaChevronUp />}
{!mobileBottomNavigationOpen && <FaEllipsisH />}
</a>
</MobileInlineNavigation>
)}
</MainContent>
</PageContent>
)}
</Location>
<Theme.Consumer>
{({ theme, key }) => (
<Footer theme={theme.palette.type} variant={key} />
)}
</Theme.Consumer>
</Container>
</Layout>
)}
/>
)
}
Example #5
Source File: showreel.js From react-table-library with MIT License | 4 votes |
Component = () => {
const [data, setData] = React.useState({ nodes });
//* Theme *//
const chakraTheme = getTheme({
...DEFAULT_OPTIONS,
striped: true,
});
const customTheme = {
Table: `
--data-table-library_grid-template-columns: 64px repeat(5, minmax(0, 1fr));
margin: 16px 0px;
`,
};
const theme = useTheme([chakraTheme, customTheme]);
//* Resize *//
const resize = { resizerHighlight: '#dee2e6' };
//* Pagination *//
const pagination = usePagination(data, {
state: {
page: 0,
size: 4,
},
onChange: onPaginationChange,
});
function onPaginationChange(action, state) {
console.log(action, state);
}
//* Search *//
const [search, setSearch] = React.useState('');
useCustom('search', data, {
state: { search },
onChange: onSearchChange,
});
function onSearchChange(action, state) {
console.log(action, state);
pagination.fns.onSetPage(0);
}
//* Filter *//
const [isHide, setHide] = React.useState(false);
useCustom('filter', data, {
state: { isHide },
onChange: onFilterChange,
});
function onFilterChange(action, state) {
console.log(action, state);
pagination.fns.onSetPage(0);
}
//* Select *//
const select = useRowSelect(data, {
onChange: onSelectChange,
});
function onSelectChange(action, state) {
console.log(action, state);
}
//* Tree *//
const tree = useTree(
data,
{
onChange: onTreeChange,
},
{
clickType: TreeExpandClickTypes.ButtonClick,
treeYLevel: 1,
treeIcon: {
margin: '4px',
iconDefault: null,
iconRight: <FaChevronRight />,
iconDown: <FaChevronDown />,
},
},
);
function onTreeChange(action, state) {
console.log(action, state);
}
//* Sort *//
const sort = useSort(
data,
{
onChange: onSortChange,
},
{
sortIcon: {
iconDefault: null,
iconUp: <FaChevronUp />,
iconDown: <FaChevronDown />,
},
sortFns: {
TASK: (array) => array.sort((a, b) => a.name.localeCompare(b.name)),
DEADLINE: (array) => array.sort((a, b) => a.deadline - b.deadline),
TYPE: (array) => array.sort((a, b) => a.type.localeCompare(b.type)),
COMPLETE: (array) => array.sort((a, b) => a.isComplete - b.isComplete),
TASKS: (array) => array.sort((a, b) => (a.nodes || []).length - (b.nodes || []).length),
},
},
);
function onSortChange(action, state) {
console.log(action, state);
}
//* Drawer *//
const [drawerId, setDrawerId] = React.useState(null);
const [edited, setEdited] = React.useState('');
const handleEdit = (event) => {
setEdited(event.target.value);
};
const handleCancel = () => {
setEdited('');
setDrawerId(null);
};
const handleSave = () => {
const node = findNodeById(data.nodes, drawerId);
const editedNode = { ...node, name: edited };
const nodes = insertNode(data.nodes, editedNode);
setData({
nodes,
});
setEdited('');
setDrawerId(null);
};
//* Modal *//
const [modalOpened, setModalOpened] = React.useState(false);
//* Custom Modifiers *//
let modifiedNodes = data.nodes;
// search
modifiedNodes = modifiedNodes.filter((node) =>
node.name.toLowerCase().includes(search.toLowerCase()),
);
// filter
modifiedNodes = isHide ? modifiedNodes.filter((node) => !node.isComplete) : modifiedNodes;
//* Columns *//
const COLUMNS = [
{
label: 'Task',
renderCell: (item) => item.name,
resize,
sort: { sortKey: 'TASK' },
select: {
renderHeaderCellSelect: () => (
<Checkbox
colorScheme="teal"
isChecked={select.state.all}
isIndeterminate={!select.state.all && !select.state.none}
onChange={select.fns.onToggleAll}
/>
),
renderCellSelect: (item) => (
<Checkbox
colorScheme="teal"
style={{ backgroundColor: '#ffffff' }}
isChecked={select.state.ids.includes(item.id)}
onChange={() => select.fns.onToggleById(item.id)}
/>
),
},
tree: true,
},
{
label: 'Deadline',
renderCell: (item) =>
item.deadline.toLocaleDateString('en-US', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
}),
resize,
sort: { sortKey: 'DEADLINE' },
},
{ label: 'Type', renderCell: (item) => item.type, resize, sort: { sortKey: 'TYPE' } },
{
label: 'Complete',
renderCell: (item) => item.isComplete.toString(),
resize,
sort: { sortKey: 'COMPLETE' },
},
{
label: 'Tasks',
renderCell: (item) => (
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
<span>{item.nodes?.length}</span>
<IconButton
aria-label="edit"
icon={<FaPen />}
size="xs"
variant="ghost"
colorScheme="teal"
onClick={() => setDrawerId(item.id)}
/>
</div>
),
resize,
sort: { sortKey: 'TASKS' },
},
];
return (
<>
<Modal isOpen={modalOpened} onClose={() => setModalOpened(false)}>
<ModalOverlay />
<ModalContent>
<ModalHeader>Not all features included here, but we got ...</ModalHeader>
<ModalCloseButton />
<ModalBody>
<div>
<Checkbox colorScheme="teal" isChecked>
Resize
</Checkbox>
</div>
<div>
<Checkbox colorScheme="teal" isChecked>
Sort
</Checkbox>
</div>
<div>
<Checkbox colorScheme="teal" isChecked>
Search
</Checkbox>
</div>
<div>
<Checkbox colorScheme="teal" isChecked>
Filter
</Checkbox>
</div>
<div>
<Checkbox colorScheme="teal" isChecked>
Select
</Checkbox>
</div>
<div>
<Checkbox colorScheme="teal" isChecked>
Tree
</Checkbox>
</div>
<div>
<Checkbox colorScheme="teal" isChecked>
Drawer on Edit
</Checkbox>
</div>
<div>
<Checkbox colorScheme="teal" isChecked>
Pagination
</Checkbox>
</div>
</ModalBody>
</ModalContent>
</Modal>
{/* Form */}
<HStack m={3}>
<Button colorScheme="teal" onClick={() => setModalOpened(true)}>
Features?
</Button>
<InputGroup>
<InputLeftElement
pointerEvents="none"
children={<FaSearch style={{ color: '#4a5568' }} />}
/>
<Input
placeholder="Search Task"
value={search}
onChange={(event) => setSearch(event.target.value)}
/>
</InputGroup>
<Checkbox
style={{ whiteSpace: 'nowrap' }}
colorScheme="teal"
isChecked={isHide}
onChange={(event) => setHide(event.target.checked)}
>
Hide Complete
</Checkbox>
</HStack>
{/* Table */}
<Box p={3} borderWidth="1px" borderRadius="lg">
<CompactTable
columns={COLUMNS}
data={{ ...data, nodes: modifiedNodes }}
theme={theme}
layout={{ custom: true }}
select={select}
tree={tree}
sort={sort}
pagination={pagination}
/>
</Box>
<br />
<HStack justify="flex-end">
<IconButton
aria-label="previous page"
icon={<FaChevronLeft />}
colorScheme="teal"
variant="ghost"
disabled={pagination.state.page === 0}
onClick={() => pagination.fns.onSetPage(pagination.state.page - 1)}
/>
{pagination.state.getPages(modifiedNodes).map((_, index) => (
<Button
key={index}
colorScheme="teal"
variant={pagination.state.page === index ? 'solid' : 'ghost'}
onClick={() => pagination.fns.onSetPage(index)}
>
{index + 1}
</Button>
))}
<IconButton
aria-label="next page"
icon={<FaChevronRight />}
colorScheme="teal"
variant="ghost"
disabled={pagination.state.page + 1 === pagination.state.getTotalPages(data.nodes)}
onClick={() => pagination.fns.onSetPage(pagination.state.page + 1)}
/>
</HStack>
<Drawer isOpen={drawerId} onClose={handleCancel} placement="right">
<DrawerOverlay />
<DrawerContent>
<DrawerCloseButton />
<DrawerHeader>Create your account</DrawerHeader>
<DrawerBody>
<Text>Name: </Text>
<Input
autoFocus
value={
edited || fromTreeToList(data.nodes).find((node) => node.id === drawerId)?.name
}
onChange={handleEdit}
data-autofocus
/>
</DrawerBody>
<DrawerFooter>
<Button variant="outline" mr={3} onClick={handleCancel}>
Cancel
</Button>
<Button onClick={handleSave} colorScheme="teal">
Save
</Button>
</DrawerFooter>
</DrawerContent>
</Drawer>
</>
);
}
Example #6
Source File: showreel.js From react-table-library with MIT License | 4 votes |
Component = () => {
const [data, setData] = React.useState({ nodes });
//* Theme *//
const mantineTheme = getTheme({
...DEFAULT_OPTIONS,
striped: true,
highlightOnHover: true,
});
const customTheme = {
Table: `
--data-table-library_grid-template-columns: 44px repeat(5, minmax(0, 1fr));
margin: 16px 0px;
`,
};
const theme = useTheme([mantineTheme, customTheme]);
//* Resize *//
const resize = { resizerHighlight: '#dee2e6' };
//* Pagination *//
const pagination = usePagination(data, {
state: {
page: 0,
size: 4,
},
onChange: onPaginationChange,
});
function onPaginationChange(action, state) {
console.log(action, state);
}
//* Search *//
const [search, setSearch] = React.useState('');
useCustom('search', data, {
state: { search },
onChange: onSearchChange,
});
function onSearchChange(action, state) {
console.log(action, state);
pagination.fns.onSetPage(0);
}
//* Filter *//
const [isHide, setHide] = React.useState(false);
useCustom('filter', data, {
state: { isHide },
onChange: onFilterChange,
});
function onFilterChange(action, state) {
console.log(action, state);
pagination.fns.onSetPage(0);
}
//* Select *//
const select = useRowSelect(data, {
onChange: onSelectChange,
});
function onSelectChange(action, state) {
console.log(action, state);
}
//* Tree *//
const tree = useTree(
data,
{
onChange: onTreeChange,
},
{
clickType: TreeExpandClickTypes.ButtonClick,
treeYLevel: 1,
treeIcon: {
margin: '4px',
iconDefault: null,
iconRight: <FaChevronRight />,
iconDown: <FaChevronDown />,
},
},
);
function onTreeChange(action, state) {
console.log(action, state);
}
//* Sort *//
const sort = useSort(
data,
{
onChange: onSortChange,
},
{
sortIcon: {
iconDefault: null,
iconUp: <FaChevronUp />,
iconDown: <FaChevronDown />,
},
sortFns: {
TASK: (array) => array.sort((a, b) => a.name.localeCompare(b.name)),
DEADLINE: (array) => array.sort((a, b) => a.deadline - b.deadline),
TYPE: (array) => array.sort((a, b) => a.type.localeCompare(b.type)),
COMPLETE: (array) => array.sort((a, b) => a.isComplete - b.isComplete),
TASKS: (array) => array.sort((a, b) => (a.nodes || []).length - (b.nodes || []).length),
},
},
);
function onSortChange(action, state) {
console.log(action, state);
}
//* Drawer *//
const [drawerId, setDrawerId] = React.useState(null);
const [edited, setEdited] = React.useState('');
const handleEdit = (event) => {
setEdited(event.target.value);
};
const handleCancel = () => {
setEdited('');
setDrawerId(null);
};
const handleSave = () => {
const node = findNodeById(data.nodes, drawerId);
const editedNode = { ...node, name: edited };
const nodes = insertNode(data.nodes, editedNode);
setData({
nodes,
});
setEdited('');
setDrawerId(null);
};
//* Modal *//
const [modalOpened, setModalOpened] = React.useState(false);
//* Custom Modifiers *//
let modifiedNodes = data.nodes;
// search
modifiedNodes = modifiedNodes.filter((node) =>
node.name.toLowerCase().includes(search.toLowerCase()),
);
// filter
modifiedNodes = isHide ? modifiedNodes.filter((node) => !node.isComplete) : modifiedNodes;
//* Columns *//
const COLUMNS = [
{
label: 'Task',
renderCell: (item) => item.name,
resize,
sort: { sortKey: 'TASK' },
select: {
renderHeaderCellSelect: () => (
<Checkbox
checked={select.state.all}
indeterminate={!select.state.all && !select.state.none}
onChange={select.fns.onToggleAll}
/>
),
renderCellSelect: (item) => (
<Checkbox
checked={select.state.ids.includes(item.id)}
onChange={() => select.fns.onToggleById(item.id)}
/>
),
},
tree: true,
},
{
label: 'Deadline',
renderCell: (item) =>
item.deadline.toLocaleDateString('en-US', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
}),
resize,
sort: { sortKey: 'DEADLINE' },
},
{ label: 'Type', renderCell: (item) => item.type, resize, sort: { sortKey: 'TYPE' } },
{
label: 'Complete',
renderCell: (item) => item.isComplete.toString(),
resize,
sort: { sortKey: 'COMPLETE' },
},
{
label: 'Tasks',
renderCell: (item) => (
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
<span>{item.nodes?.length}</span>
<ActionIcon
variant="hover"
color="blue"
component="button"
onClick={() => setDrawerId(item.id)}
>
<FaPen />
</ActionIcon>
</div>
),
resize,
sort: { sortKey: 'TASKS' },
},
];
return (
<>
<Modal
opened={modalOpened}
onClose={() => setModalOpened(false)}
title="Not all features included here, but we got ..."
>
<div>
<Checkbox label="Resize" checked />
</div>
<div>
<Checkbox label="Sort" checked />
</div>
<div>
<Checkbox label="Search" checked />
</div>
<div>
<Checkbox label="Filter" checked />
</div>
<div>
<Checkbox label="Select" checked />
</div>
<div>
<Checkbox label="Tree" checked />
</div>
<div>
<Checkbox label="Drawer on Edit" checked />
</div>
<div>
<Checkbox label="Pagination" checked />
</div>
</Modal>
{/* Form */}
<Group mx={10}>
<Button onClick={() => setModalOpened(true)}>Features?</Button>
<TextInput
placeholder="Search Task"
value={search}
icon={<FaSearch />}
onChange={(event) => setSearch(event.target.value)}
/>
<Checkbox
label="Hide Complete"
checked={isHide}
onChange={(event) => setHide(event.target.checked)}
/>
</Group>
{/* Table */}
<CompactTable
columns={COLUMNS}
data={{ ...data, nodes: modifiedNodes }}
theme={theme}
layout={{ custom: true }}
select={select}
tree={tree}
sort={sort}
pagination={pagination}
/>
<Group position="right" mx={10}>
<Pagination
total={pagination.state.getTotalPages(modifiedNodes)}
page={pagination.state.page + 1}
onChange={(page) => pagination.fns.onSetPage(page - 1)}
/>
</Group>
<Drawer
opened={drawerId}
onClose={handleCancel}
title="Edit"
padding="xl"
size="xl"
position="right"
>
<Group grow>
<TextInput
label="Name"
value={edited || fromTreeToList(data.nodes).find((node) => node.id === drawerId)?.name}
onChange={handleEdit}
data-autofocus
/>
</Group>
<Space h="md" />
<Group grow>
<Button variant="outline" onClick={handleCancel}>
Cancel
</Button>
<Button onClick={handleSave}>Save</Button>
</Group>
</Drawer>
</>
);
}
Example #7
Source File: showreel.js From react-table-library with MIT License | 4 votes |
Component = () => {
const [data, setData] = React.useState({ nodes });
//* Theme *//
const materialTheme = getTheme({
...DEFAULT_OPTIONS,
striped: true,
highlightOnHover: true,
});
const customTheme = {
Table: `
--data-table-library_grid-template-columns: 70px repeat(5, minmax(0, 1fr));
margin: 16px 0px;
`,
};
const theme = useTheme([materialTheme, customTheme]);
//* Resize *//
const resize = { resizerHighlight: '#dee2e6' };
//* Pagination *//
const pagination = usePagination(data, {
state: {
page: 0,
size: 2,
},
onChange: onPaginationChange,
});
function onPaginationChange(action, state) {
console.log(action, state);
}
//* Search *//
const [search, setSearch] = React.useState('');
useCustom('search', data, {
state: { search },
onChange: onSearchChange,
});
function onSearchChange(action, state) {
console.log(action, state);
pagination.fns.onSetPage(0);
}
//* Filter *//
const [isHide, setHide] = React.useState(false);
useCustom('filter', data, {
state: { isHide },
onChange: onFilterChange,
});
function onFilterChange(action, state) {
console.log(action, state);
pagination.fns.onSetPage(0);
}
//* Select *//
const select = useRowSelect(data, {
onChange: onSelectChange,
});
function onSelectChange(action, state) {
console.log(action, state);
}
//* Tree *//
const tree = useTree(
data,
{
onChange: onTreeChange,
},
{
clickType: TreeExpandClickTypes.ButtonClick,
treeYLevel: 1,
treeIcon: {
margin: '4px',
iconDefault: null,
iconRight: <FaChevronRight />,
iconDown: <FaChevronDown />,
},
},
);
function onTreeChange(action, state) {
console.log(action, state);
}
//* Sort *//
const sort = useSort(
data,
{
onChange: onSortChange,
},
{
sortIcon: {
iconDefault: null,
iconUp: <FaChevronUp />,
iconDown: <FaChevronDown />,
},
sortFns: {
TASK: (array) => array.sort((a, b) => a.name.localeCompare(b.name)),
DEADLINE: (array) => array.sort((a, b) => a.deadline - b.deadline),
TYPE: (array) => array.sort((a, b) => a.type.localeCompare(b.type)),
COMPLETE: (array) => array.sort((a, b) => a.isComplete - b.isComplete),
TASKS: (array) => array.sort((a, b) => (a.nodes || []).length - (b.nodes || []).length),
},
},
);
function onSortChange(action, state) {
console.log(action, state);
}
//* Drawer *//
const [drawerId, setDrawerId] = React.useState(null);
const [edited, setEdited] = React.useState('');
const handleEdit = (event) => {
setEdited(event.target.value);
};
const handleCancel = () => {
setEdited('');
setDrawerId(null);
};
const handleSave = () => {
const node = findNodeById(data.nodes, drawerId);
const editedNode = { ...node, name: edited };
const nodes = insertNode(data.nodes, editedNode);
setData({
nodes,
});
setEdited('');
setDrawerId(null);
};
//* Modal *//
const [modalOpened, setModalOpened] = React.useState(false);
//* Custom Modifiers *//
let modifiedNodes = data.nodes;
// search
modifiedNodes = modifiedNodes.filter((node) =>
node.name.toLowerCase().includes(search.toLowerCase()),
);
// filter
modifiedNodes = isHide ? modifiedNodes.filter((node) => !node.isComplete) : modifiedNodes;
//* Columns *//
const COLUMNS = [
{
label: 'Task',
renderCell: (item) => item.name,
resize,
sort: { sortKey: 'TASK' },
select: {
renderHeaderCellSelect: () => (
<Checkbox
size="small"
checked={select.state.all}
indeterminate={!select.state.all && !select.state.none}
onChange={select.fns.onToggleAll}
/>
),
renderCellSelect: (item) => (
<Checkbox
size="small"
checked={select.state.ids.includes(item.id)}
onChange={() => select.fns.onToggleById(item.id)}
/>
),
},
tree: true,
},
{
label: 'Deadline',
renderCell: (item) =>
item.deadline.toLocaleDateString('en-US', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
}),
resize,
sort: { sortKey: 'DEADLINE' },
},
{ label: 'Type', renderCell: (item) => item.type, resize, sort: { sortKey: 'TYPE' } },
{
label: 'Complete',
renderCell: (item) => item.isComplete.toString(),
resize,
sort: { sortKey: 'COMPLETE' },
},
{
label: 'Tasks',
renderCell: (item) => (
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
<span>{item.nodes?.length}</span>
<IconButton onClick={() => setDrawerId(item.id)}>
<FaPen size={14} />
</IconButton>
</div>
),
resize,
sort: { sortKey: 'TASKS' },
},
];
return (
<>
<Modal open={modalOpened} onClose={() => setModalOpened(false)}>
<Box
style={{
position: 'absolute',
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)',
width: 500,
backgroundColor: '#ffffff',
border: '1px solid #e0e0e0',
borderRadius: '4px',
padding: '10px',
}}
>
<Typography variant="h6" component="h2">
"Not all features included here, but we got ..."
</Typography>
<FormGroup>
<FormControlLabel control={<Checkbox checked />} label="Resize" />
<FormControlLabel control={<Checkbox checked />} label="Sort" />
<FormControlLabel control={<Checkbox checked />} label="Search" />
<FormControlLabel control={<Checkbox checked />} label="Filter" />
<FormControlLabel control={<Checkbox checked />} label="Select" />
<FormControlLabel control={<Checkbox checked />} label="Tree" />
<FormControlLabel control={<Checkbox checked />} label="Drawer on Edit" />
<FormControlLabel control={<Checkbox checked />} label="Pagination" />
</FormGroup>
</Box>
</Modal>
{/* Form */}
<Stack spacing={1} direction="row">
<Button variant="contained" onClick={() => setModalOpened(true)}>
Features?
</Button>
<TextField
label="Search Task"
value={search}
onChange={(event) => setSearch(event.target.value)}
/>
<FormControlLabel
control={
<Checkbox checked={isHide} onChange={(event) => setHide(event.target.checked)} />
}
label="Hide Complete"
/>
</Stack>
{/* Table */}
<CompactTable
columns={COLUMNS}
data={{ ...data, nodes: modifiedNodes }}
theme={theme}
layout={{ custom: true }}
select={select}
tree={tree}
sort={sort}
pagination={pagination}
/>
<br />
<Stack spacing={10}>
<TablePagination
count={modifiedNodes.length}
page={pagination.state.page}
rowsPerPage={pagination.state.size}
rowsPerPageOptions={[1, 2, 5]}
onRowsPerPageChange={(event) =>
pagination.fns.onSetSize(parseInt(event.target.value, 10))
}
onPageChange={(event, page) => pagination.fns.onSetPage(page)}
/>
</Stack>
<Drawer
open={drawerId}
onClose={handleCancel}
title="Edit"
anchor="right"
PaperProps={{
sx: { width: '50%', padding: '20px' },
}}
>
<Stack spacing={1}>
<TextField
label="Name"
value={edited || fromTreeToList(data.nodes).find((node) => node.id === drawerId)?.name}
onChange={handleEdit}
autoFocus
/>
<Button variant="outlined" onClick={handleCancel}>
Cancel
</Button>
<Button variant="contained" onClick={handleSave}>
Save
</Button>
</Stack>
</Drawer>
</>
);
}