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

feat(Table): add row actions size control prop #557

Merged
merged 6 commits into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
4 changes: 4 additions & 0 deletions src/components/Table/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ interface Props {
* Array of action configs for each row.
*/
getRowActions: (item: any, index: number) => TableActionConfig[];
/**
* Size of actions button and popup menu items.
*/
rowActionsSize?: 's' | 'm' | 'l' | 'xl';
}
```

Expand Down
2 changes: 1 addition & 1 deletion src/components/Table/__stories__/Table.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const WithTableActionsTemplate: Story<TableProps<DataItem>> = (args) => {
},
},
];
return <TableWithAction {...args} getRowActions={getRowActions} />;
return <TableWithAction {...args} rowActionsSize="l" getRowActions={getRowActions} />;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's keep the default size here

};
export const HOCWithTableActions = WithTableActionsTemplate.bind({});

Expand Down
12 changes: 8 additions & 4 deletions src/components/Table/hoc/withTableActions/withTableActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import _memoize from 'lodash/memoize';
import {block} from '../../../utils/cn';
import {getComponentName} from '../../../utils/getComponentName';
import {Icon} from '../../../Icon';
import {Button} from '../../../Button';
import {Button, ButtonSize} from '../../../Button';
import {Popup} from '../../../Popup';
import {Menu, MenuItemProps} from '../../../Menu';
import {DotsIcon} from '../../../icons/DotsIcon';
Expand Down Expand Up @@ -54,6 +54,7 @@ export type TableActionConfig<I> = TableAction<I> | TableActionGroup<I>;

export interface WithTableActionsProps<I> {
getRowActions: (item: I, index: number) => TableActionConfig<I>[];
rowActionsSize?: ButtonSize;
}

interface WithTableActionsState<I> {
Expand Down Expand Up @@ -105,7 +106,7 @@ export function withTableActions<I extends TableDataItem, E extends {} = {}>(
}

private renderBodyCell = (item: I, index: number) => {
const {isRowDisabled, getRowActions} = this.props;
const {isRowDisabled, getRowActions, rowActionsSize} = this.props;
const actions = getRowActions(item, index);

if (actions.length === 0) {
Expand All @@ -121,6 +122,7 @@ export function withTableActions<I extends TableDataItem, E extends {} = {}>(
disabled={disabled}
className={BUTTON_CLASSNAME}
onClick={this.handleActionsButtonClick.bind(this, {item, index})}
size={rowActionsSize}
>
<Icon data={DotsIcon} />
</Button>
Expand All @@ -129,7 +131,7 @@ export function withTableActions<I extends TableDataItem, E extends {} = {}>(
};

private renderPopup() {
const {getRowActions} = this.props;
const {getRowActions, rowActionsSize} = this.props;
const {popupOpen, popupData} = this.state;

if (!popupData) {
Expand All @@ -145,7 +147,9 @@ export function withTableActions<I extends TableDataItem, E extends {} = {}>(
placement={['bottom-end', 'top-end']}
onClose={this.handlePopupClose}
>
<Menu className={bPopup('menu')}>{actions.map(this.renderPopupMenuItem)}</Menu>
<Menu className={bPopup('menu')} size={rowActionsSize}>
{actions.map(this.renderPopupMenuItem)}
</Menu>
</Popup>
);
}
Expand Down