Skip to content

Commit

Permalink
ui: support hide on disable based on a function for the toolbar
Browse files Browse the repository at this point in the history
componenet

Signed-off-by: ryjiang <[email protected]>
  • Loading branch information
shanghaikid committed Jul 22, 2024
1 parent d55846a commit ba617dc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 8 additions & 2 deletions client/src/components/grid/ToolBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,15 @@ const CustomToolBar: FC<ToolBarType> = props => {
const Icon = c.icon ? Icons[c.icon!]() : '';
const disabled = c.disabled ? c.disabled(selected) : false;

if (disabled && hideOnDisable && !c.alwaysShow) {
return null;
if (
disabled && // Check if the component is disabled
hideOnDisable && // Check if the component should be hidden when disabled
!c.alwaysShow && // Check if the button is not marked to always be shown
(typeof c.hideOnDisable === 'undefined' || c.hideOnDisable()) // Check if hideOnDisable on button is undefined or returns true
) {
return null; // Return null to hide the component
}

// when disabled "disabledTooltip" will replace "tooltip"
const tooltip =
disabled && c.disabledTooltip ? c.disabledTooltip : c.tooltip;
Expand Down
1 change: 1 addition & 0 deletions client/src/components/grid/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export type ToolBarConfig = Partial<TableSwitchType> &
btnVariant?: 'contained' | 'outlined' | 'text';
btnColor?: 'primary' | 'secondary';
alwaysShow?: boolean;
hideOnDisable?: () => boolean;
};

export type TableHeadType = {
Expand Down

0 comments on commit ba617dc

Please sign in to comment.