Skip to content

Commit

Permalink
feat: LEAP-1356: Add custom button props (#6787)
Browse files Browse the repository at this point in the history
Co-authored-by: Gondragos <[email protected]>
Co-authored-by: MihajloHoma <[email protected]>
  • Loading branch information
3 people authored Jan 15, 2025
1 parent 054bfe1 commit 6d9d939
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const TableRow = observer(({ data, even, style, wrapperStyle, onClick, st

return (
<div className={rowWrapperCN.mod(mods).toString()} style={wrapperStyle} onClick={(e) => onClick?.(data, e)}>
<div className={tableRowCN.toString()} style={style}>
<div className={tableRowCN.toString()} style={style} data-leave={true}>
{columns.map((col) => {
return <CellRenderer key={col.id} col={col} data={data} cellViews={cellViews} decoration={decoration} />;
})}
Expand Down
3 changes: 2 additions & 1 deletion web/libs/datamanager/src/components/Common/Tabs/Tabs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const Tabs = ({
</Droppable>
</DragDropContext>
{allowedActions.add !== false && (
<Button className={tabsCN.elem("add").toString()} type="text" onClick={onAdd} icon={addIcon} />
<Button className={tabsCN.elem("add").toString()} type="text" onClick={onAdd} icon={addIcon} data-leave />
)}
</span>
<span className={tabsCN.elem("extra").toString()}>{tabBarExtraContent}</span>
Expand Down Expand Up @@ -140,6 +140,7 @@ export const TabsItem = ({
.toString()}
onClick={() => switchTab?.(tab)}
title={currentTitle}
data-leave
>
{renameMode ? (
<Input
Expand Down
8 changes: 6 additions & 2 deletions web/libs/datamanager/src/components/Common/Tabs/TabsMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ export const TabsMenu = ({ onClick, editable = true, closable = true, clonable =
title: "Duplicate",
enabled: !virtual && clonable,
action: () => onClick("duplicate"),
willLeave: true,
},
{
key: "save",
title: "Save",
enabled: virtual,
action: () => onClick("save"),
willLeave: true,
},
],
[editable, closable, clonable, virtual],
Expand All @@ -32,7 +34,7 @@ export const TabsMenu = ({ onClick, editable = true, closable = true, clonable =
<Menu size="medium" onClick={(e) => e.domEvent.stopPropagation()}>
{items.map((item) =>
item.enabled ? (
<Menu.Item key={item.key} onClick={item.action}>
<Menu.Item key={item.key} onClick={item.action} data-leave={item.willLeave}>
{item.title}
</Menu.Item>
) : null,
Expand All @@ -41,7 +43,9 @@ export const TabsMenu = ({ onClick, editable = true, closable = true, clonable =
{closable ? (
<>
{showDivider && <Menu.Divider />}
<Menu.Item onClick={() => onClick("close")}>Close</Menu.Item>
<Menu.Item onClick={() => onClick("close")} data-leave>
Close
</Menu.Item>
</>
) : null}
</Menu>
Expand Down
8 changes: 7 additions & 1 deletion web/libs/editor/src/components/BottomBar/Controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@ const ControlButton = observer(({ button, disabled, onClick }: ControlButtonProp

return (
<ButtonTooltip title={button.tooltip ?? ""}>
<Button aria-label={button.ariaLabel} disabled={button.disabled || disabled} look={look} onClick={onClick}>
<Button
{...button.props}
aria-label={button.ariaLabel}
disabled={button.disabled || disabled}
look={look}
onClick={onClick}
>
{button.title}
</Button>
</ButtonTooltip>
Expand Down
9 changes: 7 additions & 2 deletions web/libs/editor/src/stores/CustomButton.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { applySnapshot, getSnapshot, type Instance, type SnapshotIn, types } from "mobx-state-tree";
import { type Instance, type SnapshotIn, types } from "mobx-state-tree";
import { guidGenerator } from "../utils/unique";

export type CustomButtonType = Instance<typeof CustomButton>;
Expand All @@ -19,9 +19,14 @@ export const CustomButton = types
tooltip: types.maybe(types.string),
ariaLabel: types.maybe(types.string),
disabled: types.maybe(types.boolean),
props: types.maybe(types.frozen()),
})
.actions((self) => ({
updateState(newState: CustomButtonSnType) {
applySnapshot(self, Object.assign({}, getSnapshot(self), newState));
for (const key in newState) {
if (key in self) {
self[key] = newState[key];
}
}
},
}));

0 comments on commit 6d9d939

Please sign in to comment.