Skip to content

Commit

Permalink
feat: added tooltip and scale-icon in data-grid button
Browse files Browse the repository at this point in the history
  • Loading branch information
Fatima committed Mar 1, 2024
1 parent dcbbfdb commit 3c4a2d6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,23 @@ export const ActionsCell: Cell = {
return (
<div class={`tbody__actions`}>
{content.map((action) => {
const { label, ...props } = action;
const { label, iconName, tooltip, ...props } = action;
const tooltipProps = tooltip ? { 'title': tooltip } : {};
const IconComponent = resolveIconComponent(iconName);
if (typeof label === 'object' && '__html' in label) {
return (
<scale-button
size="small"
innerHTML={label.__html}

{...props}
{...tooltipProps}
></scale-button>
);
}
return (
<scale-button size="small" {...props}>
<scale-button size="small" {...props} {...tooltipProps}>
{IconComponent}
{label}
</scale-button>
);
Expand All @@ -38,3 +43,15 @@ export const ActionsCell: Cell = {
);
},
};

function resolveIconComponent(iconName) {
switch (iconName) {
case 'edit':
return <scale-icon-action-edit></scale-icon-action-edit>;
case 'delete':
return <scale-icon-action-remove></scale-icon-action-remove>;

default:
return null;
}
}
7 changes: 6 additions & 1 deletion packages/components/src/html/data-grid.html
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,20 @@
label: 'Edit',
variant: 'secondary',
onClick: () => alert('Edit'),
disabled: true,
iconName: 'edit',
tooltip: 'This action is disabled because...',

},
{
label: 'Delete',
iconName: 'delete',
variant: 'secondary',
onClick: () => alert('Delete'),
},
],
],

],
// Row 2
[
'dolor sit amet',
Expand Down

0 comments on commit 3c4a2d6

Please sign in to comment.