Skip to content

Commit

Permalink
🔥 Remove convoluted mixin
Browse files Browse the repository at this point in the history
- in favor of passing condition/setting conditional styling logic directly in the cell actions component
  • Loading branch information
cee-chen committed Oct 4, 2023
1 parent 362d480 commit ad6894b
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 32 deletions.
21 changes: 11 additions & 10 deletions src/components/datagrid/_data_grid_data_row.scss
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,18 @@
}

// Cell actions
.euiDataGridRowCell__expandActions {
.euiDataGridRowCell__actions {
display: flex;
}
@include euiDataGridRowCellActions($definedHeight: false) {
.euiDataGridRowCell__actions--flex {
flex-grow: 0;
}
@include euiDataGridRowCellActions($definedHeight: true) {
background-color: $euiColorEmptyShade;
.euiDataGridRowCell__actions--overlay {
position: absolute;
right: 0;
top: 0;
padding: $euiDataGridCellPaddingM 0;
background-color: $euiColorEmptyShade;
}

.euiDataGridRowCell__actionButtonIcon {
Expand All @@ -171,20 +171,20 @@
// Row stripes
@include euiDataGridStyles(stripes) {
.euiDataGridRow--striped {
@include euiDataGridRowCellActions($definedHeight: true) {
&,
.euiDataGridRowCell__actions--overlay {
background-color: $euiColorLightestShade;
}
background-color: $euiColorLightestShade;
}
}

// Row highlights
@include euiDataGridStyles(rowHoverHighlight) {
.euiDataGridRow:hover {
@include euiDataGridRowCellActions($definedHeight: true) {
&,
.euiDataGridRowCell__actions--overlay {
background-color: $euiColorHighlight;
}
background-color: $euiColorHighlight;
}
}

Expand Down Expand Up @@ -230,10 +230,11 @@

// Compressed density grids - height tweaks
@include euiDataGridStyles(fontSizeSmall, paddingSmall) {
@include euiDataGridRowCellActions($definedHeight: true) {
.euiDataGridRowCell__actions--overlay {
padding: ($euiDataGridCellPaddingS / 2) 0;
}
@include euiDataGridRowCellActions($definedHeight: false) {

.euiDataGridRowCell__actions--flex {
transform: translateY(1px);
}
}
Expand Down
15 changes: 0 additions & 15 deletions src/components/datagrid/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,3 @@ $euiDataGridStyles: (
@content;
}
}

@mixin euiDataGridRowCellActions($definedHeight: false) {
@if $definedHeight {
// Defined heights are cells with row heights of auto, lineCount, or a static height
// that set the __contentByHeight class
.euiDataGridRowCell__contentByHeight + .euiDataGridRowCell__expandActions {
@content;
}
} @else {
// Otherwise, an undefined height (single flex row) will set __expandContent
.euiDataGridRowCell__expandContent + .euiDataGridRowCell__expandActions {
@content;
}
}
}
8 changes: 8 additions & 0 deletions src/components/datagrid/body/data_grid_cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,13 @@ export class EuiDataGridCell extends Component<
rowHeightsOptions
);

const rowHeightOption = rowHeightUtils?.getRowHeightOption(
rowIndex,
rowHeightsOptions
);
const cellHeightType =
rowHeightUtils?.getHeightType(rowHeightOption) || 'default';

const cellContentProps = {
...rest,
setCellProps: this.setCellProps,
Expand Down Expand Up @@ -729,6 +736,7 @@ export class EuiDataGridCell extends Component<
rowIndex={rowIndex}
colIndex={colIndex}
column={column}
cellHeightType={cellHeightType}
onExpandClick={() => {
if (popoverIsOpen) {
closeCellPopover();
Expand Down
17 changes: 15 additions & 2 deletions src/components/datagrid/body/data_grid_cell_actions.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import React from 'react';
import { shallow } from 'enzyme';
import { render } from '../../../test/rtl';

import { EuiDataGridColumnCellAction } from '../data_grid_types';
import {
Expand All @@ -24,14 +25,15 @@ describe('EuiDataGridCellActions', () => {
onExpandClick: jest.fn(),
rowIndex: 0,
colIndex: 0,
cellHeightType: 'default',
};

it('renders an expand button', () => {
const component = shallow(<EuiDataGridCellActions {...requiredProps} />);

expect(component).toMatchInlineSnapshot(`
<div
className="euiDataGridRowCell__expandActions"
className="euiDataGridRowCell__actions euiDataGridRowCell__actions--flex"
>
<EuiI18n
default="Click or hit enter to interact with cell content"
Expand Down Expand Up @@ -88,7 +90,7 @@ describe('EuiDataGridCellActions', () => {

expect(component).toMatchInlineSnapshot(`
<div
className="euiDataGridRowCell__expandActions"
className="euiDataGridRowCell__actions euiDataGridRowCell__actions--flex"
>
<MockAction
Component={[Function]}
Expand All @@ -109,6 +111,17 @@ describe('EuiDataGridCellActions', () => {
`);
});

it('renders with overlay positioning for non default height cells', () => {
const { container } = render(
<EuiDataGridCellActions {...requiredProps} cellHeightType="auto" />
);

// TODO: Switch to `.toHaveStyle({ position: 'absolute' })` once on Emotion
expect(container.firstChild).toHaveClass(
'euiDataGridRowCell__actions--overlay'
);
});

describe('visible cell actions limit', () => {
it('by default, does not render more than the first two primary cell actions', () => {
const component = shallow(
Expand Down
14 changes: 9 additions & 5 deletions src/components/datagrid/body/data_grid_cell_actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,20 @@ import { EuiButtonIcon, EuiButtonIconProps } from '../../button/button_icon';
import { EuiButtonEmpty, EuiButtonEmptyProps } from '../../button/button_empty';
import { EuiFlexGroup, EuiFlexItem } from '../../flex';
import { EuiPopoverFooter } from '../../popover';
import classNames from 'classnames';

export const EuiDataGridCellActions = ({
onExpandClick,
column,
rowIndex,
colIndex,
cellHeightType,
}: {
onExpandClick: () => void;
column?: EuiDataGridColumn;
rowIndex: number;
colIndex: number;
cellHeightType: string;
}) => {
// Note: The cell expand button/expansion popover is *always* rendered if
// column.cellActions is present (regardless of column.isExpandable).
Expand Down Expand Up @@ -91,11 +94,12 @@ export const EuiDataGridCellActions = ({
);
}, [column, colIndex, rowIndex]);

return (
<div className="euiDataGridRowCell__expandActions">
{[...additionalButtons, expandButton]}
</div>
);
const classes = classNames('euiDataGridRowCell__actions', {
'euiDataGridRowCell__actions--flex': cellHeightType === 'default',
'euiDataGridRowCell__actions--overlay': cellHeightType !== 'default',
});

return <div className={classes}>{[...additionalButtons, expandButton]}</div>;
};

export const EuiDataGridCellPopoverActions = ({
Expand Down

0 comments on commit ad6894b

Please sign in to comment.