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

Tree TreeTable Structure Enhancement #6241

Merged
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
1 change: 1 addition & 0 deletions components/lib/tree/Tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ export const Tree = React.memo(
selectionKeys={props.selectionKeys}
selectionMode={props.selectionMode}
togglerTemplate={props.togglerTemplate}
isUnstyled={isUnstyled}
/>
);
};
Expand Down
57 changes: 28 additions & 29 deletions components/lib/tree/TreeBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,45 @@ import { ComponentBase } from '../componentbase/ComponentBase';
import { classNames } from '../utils/Utils';

const classes = {
container: 'p-tree-container',
loadingIcon: 'p-tree-loading-icon',
root: ({ props }) =>
classNames('p-tree p-component', {
'p-tree-selectable': props.selectionMode,
'p-tree-loading': props.loading,
'p-disabled': props.disabled
}),
loadingOverlay: 'p-tree-loading-overlay p-component-overlay',
searchIcon: 'p-tree-filter-icon',
emptyMessage: 'p-treenode p-tree-empty-message',
loadingIcon: 'p-tree-loading-icon',
filterContainer: 'p-tree-filter-container',
input: 'p-tree-filter p-inputtext p-component',
header: 'p-tree-header',
footer: 'p-tree-footer',
root: ({ props }) =>
classNames('p-tree p-component', {
'p-tree-selectable': props.selectionMode,
'p-tree-loading': props.loading,
'p-disabled': props.disabled
}),
label: 'p-treenode-label',
checkboxIcon: 'p-checkbox-icon p-c',
checkboxContainer: 'p-checkbox p-component',
checkbox: ({ nodeProps: props, checked, partialChecked }) => classNames('p-checkbox-box', { 'p-highlight': checked, 'p-indeterminate': partialChecked, 'p-disabled': props.disabled }),
nodeIcon: 'p-treenode-icon',
togglerIcon: 'p-tree-toggler-icon',
toggler: 'p-tree-toggler p-link',
droppoint: 'p-treenode-droppoint',
searchIcon: 'p-tree-filter-icon',
container: 'p-tree-container',
node: ({ isLeaf }) =>
classNames('p-treenode', {
'p-treenode-leaf': isLeaf
}),
content: ({ nodeProps: props, checked, selected, isCheckboxSelectionMode }) =>
classNames('p-treenode-content', {
'p-treenode-selectable': props.selectionMode && props.node.selectable !== false,
'p-highlight': isCheckboxSelectionMode() ? checked : selected,
'p-highlight-contextmenu': props.contextMenuSelectionKey && props.contextMenuSelectionKey === props.node.key,
'p-disabled': props.disabled
}),
}),
toggler: 'p-tree-toggler p-link',
togglerIcon: 'p-tree-toggler-icon',
nodeCheckbox: ({ partialChecked }) => classNames({ 'p-indeterminate': partialChecked }),
nodeIcon: 'p-treenode-icon',
label: 'p-treenode-label',
subgroup: 'p-treenode-children',
node: ({ isLeaf }) =>
classNames('p-treenode', {
'p-treenode-leaf': isLeaf
})

emptyMessage: 'p-treenode p-tree-empty-message',
droppoint: 'p-treenode-droppoint',
header: 'p-tree-header',
footer: 'p-tree-footer',

};


const styles = `
@layer primereact {
.p-tree-container {
margin: 0;
padding: 0;
Expand Down Expand Up @@ -107,7 +107,7 @@ const styles = `
align-items: center;
justify-content: center;
}
}

`;

export const TreeBase = ComponentBase.extend({
Expand Down Expand Up @@ -166,7 +166,6 @@ export const TreeBase = ComponentBase.extend({
children: undefined
},
css: {
classes,
styles
classes
}
});
36 changes: 14 additions & 22 deletions components/lib/tree/UITreeNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ChevronRightIcon } from '../icons/chevronright';
import { MinusIcon } from '../icons/minus';
import { Ripple } from '../ripple/Ripple';
import { classNames, DomHandler, IconUtils, ObjectUtils } from '../utils/Utils';
import { Checkbox } from '../checkbox/Checkbox';

export const UITreeNode = React.memo((props) => {
const contentRef = React.useRef(null);
Expand Down Expand Up @@ -670,33 +671,24 @@ export const UITreeNode = React.memo((props) => {
if (isCheckboxSelectionMode() && props.node.selectable !== false) {
const checked = isChecked();
const partialChecked = isPartialChecked();
const checkboxIconProps = mergeProps(
{
className: cx('checkboxIcon')
},
getPTOptions('checkboxIcon')
);
const icon = checked ? props.checkboxIcon || <CheckIcon {...checkboxIconProps} /> : partialChecked ? props.checkboxIcon || <MinusIcon {...checkboxIconProps} /> : null;
const checkboxIcon = IconUtils.getJSXIcon(icon, { ...checkboxIconProps }, props);
const checkboxContainerProps = mergeProps(
{
'aria-hidden': true,
className: cx('checkboxContainer')
},
getPTOptions('checkboxContainer')
);
const icon = checked ? props.checkboxIcon || <CheckIcon /> : partialChecked ? props.checkboxIcon || <MinusIcon /> : null;
const checkboxIcon = IconUtils.getJSXIcon(icon, {}, props);
const checkboxProps = mergeProps(
{
className: cx('checkbox', { checked, partialChecked, nodeProps: props }),
role: 'checkbox'
className: cx('nodeCheckbox', { partialChecked }),
checked: checked || partialChecked,
icon: checkboxIcon,
tabIndex: -1,
unstyled: props?.isUnstyled?.(),
'data-p-checked': checked,
'data-p-partialchecked': partialChecked,
onChange: onClick
},
getPTOptions('checkbox')
getPTOptions('nodeCheckbox')
);

return (
<div {...checkboxContainerProps}>
<div {...checkboxProps}>{checkboxIcon}</div>
</div>
<Checkbox {...checkboxProps} />
);
}

Expand Down Expand Up @@ -830,7 +822,7 @@ export const UITreeNode = React.memo((props) => {
},
getPTOptions('subgroup')
);

if (ObjectUtils.isNotEmpty(props.node.children) && expanded) {
return (
<ul {...subgroupProps}>
Expand Down
160 changes: 2 additions & 158 deletions components/lib/treetable/TreeTableBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,159 +2,6 @@ import { FilterMatchMode } from '../api/Api';
import { ComponentBase } from '../componentbase/ComponentBase';
import { classNames } from '../utils/Utils';

const styles = `
@layer primereact {
.p-treetable {
position: relative;
}

.p-treetable > .p-treetable-wrapper {
overflow: auto;
}

.p-treetable table {
border-collapse: collapse;
width: 100%;
table-layout: fixed;
}

.p-treetable .p-sortable-column {
cursor: pointer;
user-select: none;
}

.p-treetable-selectable .p-treetable-tbody > tr {
cursor: pointer;
}

.p-treetable-toggler {
cursor: pointer;
user-select: none;
display: inline-flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
vertical-align: middle;
overflow: hidden;
position: relative;
}

.p-treetable-toggler + .p-checkbox {
vertical-align: middle;
}

.p-treetable-toggler + .p-checkbox + span {
vertical-align: middle;
}

/* Resizable */
.p-treetable-resizable > .p-treetable-wrapper {
overflow-x: auto;
}

.p-treetable-resizable .p-treetable-thead > tr > th,
.p-treetable-resizable .p-treetable-tfoot > tr > td,
.p-treetable-resizable .p-treetable-tbody > tr > td {
overflow: hidden;
}

.p-treetable-resizable .p-resizable-column {
background-clip: padding-box;
position: relative;
}

.p-treetable-resizable-fit .p-resizable-column:last-child .p-column-resizer {
display: none;
}

.p-treetable .p-column-resizer {
display: block;
position: absolute;
top: 0;
right: 0;
margin: 0;
width: 0.5rem;
height: 100%;
padding: 0px;
cursor: col-resize;
border: 1px solid transparent;
}

.p-treetable .p-column-resizer-helper {
width: 1px;
position: absolute;
z-index: 10;
display: none;
}

/* Scrollable */
.p-treetable-scrollable-wrapper {
position: relative;
}
.p-treetable-scrollable-header,
.p-treetable-scrollable-footer {
overflow: hidden;
border: 0 none;
}

.p-treetable-scrollable-body {
overflow: auto;
position: relative;
}

.p-treetable-virtual-table {
position: absolute;
}

/* Frozen Columns */
.p-treetable-frozen-view .p-treetable-scrollable-body {
overflow: hidden;
}

.p-treetable-unfrozen-view {
position: absolute;
top: 0px;
left: 0px;
}

/* Reorder */
.p-treetable-reorder-indicator-up,
.p-treetable-reorder-indicator-down {
position: absolute;
display: none;
}

/* Loader */
.p-treetable .p-treetable-loading-overlay {
position: absolute;
display: flex;
align-items: center;
justify-content: center;
z-index: 2;
}

/* Alignment */
.p-treetable .p-treetable-thead > tr > th.p-align-left > .p-column-header-content,
.p-treetable .p-treetable-tbody > tr > td.p-align-left,
.p-treetable .p-treetable-tfoot > tr > td.p-align-left {
text-align: left;
justify-content: flex-start;
}
.p-treetable .p-treetable-thead > tr > th.p-align-right > .p-column-header-content,
.p-treetable .p-treetable-tbody > tr > td.p-align-right,
.p-treetable .p-treetable-tfoot > tr > td.p-align-right {
text-align: right;
justify-content: flex-end;
}
.p-treetable .p-treetable-thead > tr > th.p-align-center > .p-column-header-content,
.p-treetable .p-treetable-tbody > tr > td.p-align-center,
.p-treetable .p-treetable-tfoot > tr > td.p-align-center {
text-align: center;
justify-content: center;
}
}
`;

const classes = {
root: ({ props, isRowSelectionMode }) =>
classNames('p-treetable p-component', {
Expand Down Expand Up @@ -212,9 +59,7 @@ const classes = {
'p-highlight-contextmenu': props.contextMenuSelectionKey && props.contextMenuSelectionKey === props.node.key,
'p-row-odd': props.rowIndex % 2 !== 0
}),
checkboxWrapper: 'p-checkbox p-treetable-checkbox p-component',
checkbox: ({ checked, partialChecked }) => classNames('p-checkbox-box', { 'p-highlight': checked, 'p-indeterminate': partialChecked }),
checkboxIcon: 'p-checkbox-icon p-c',
rowCheckbox: ({ partialChecked }) => classNames('p-treetable-checkbox', { 'p-indeterminate': partialChecked }),
rowToggler: 'p-treetable-toggler p-link p-unselectable-text',
rowTogglerIcon: 'p-treetable-toggler-icon',
scrollableBody: 'p-treetable-scrollable-body',
Expand Down Expand Up @@ -317,7 +162,6 @@ export const TreeTableBase = ComponentBase.extend({
children: undefined
},
css: {
classes,
styles
classes
}
});
Loading
Loading