Skip to content

Commit

Permalink
feat(Table): add row actions size control prop (#557)
Browse files Browse the repository at this point in the history
  • Loading branch information
calaquend1 authored Mar 3, 2023
1 parent 9e25c8b commit a045e12
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
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
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

0 comments on commit a045e12

Please sign in to comment.