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

[EuiTableRow] Convert to Emotion #7628

Merged
merged 9 commits into from
Mar 28, 2024
36 changes: 33 additions & 3 deletions src/components/table/table.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,43 @@
import { css } from '@emotion/react';

import { UseEuiTheme } from '../../services';
import { euiFontSize, euiNumberFormat, logicalCSS } from '../../global_styling';
import {
euiFontSize,
euiNumberFormat,
logicalCSS,
mathWithUnits,
} from '../../global_styling';

export const euiTableVariables = ({ euiTheme }: UseEuiTheme) => {
mgadewoll marked this conversation as resolved.
Show resolved Hide resolved
const cellContentPadding = euiTheme.size.s;
const compressedCellContentPadding = euiTheme.size.xs;

const mobileSizes = {
actions: {
width: euiTheme.size.xxl,
offset: mathWithUnits(cellContentPadding, (x) => x * 2),
},
checkbox: {
width: mathWithUnits(
[euiTheme.size.xl, euiTheme.size.xs],
(x, y) => x + y
),
offset: mathWithUnits(cellContentPadding, (x) => x / 2),
},
};

return {
cellContentPadding,
compressedCellContentPadding,
mobileSizes,
};
};

export const euiTableStyles = (euiThemeContext: UseEuiTheme) => {
const { euiTheme } = euiThemeContext;

const cellContentPadding = euiTheme.size.s;
const compressedCellContentPadding = euiTheme.size.xs;
const { cellContentPadding, compressedCellContentPadding } =
euiTableVariables(euiThemeContext);

return {
euiTable: css`
Expand Down
40 changes: 13 additions & 27 deletions src/components/table/table_row.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,19 @@
import { css, keyframes } from '@emotion/react';

import { UseEuiTheme, tint, shade, transparentize } from '../../services';
import {
euiBackgroundColor,
logicalCSS,
mathWithUnits,
} from '../../global_styling';
import { euiBackgroundColor, logicalCSS } from '../../global_styling';
import { euiShadow } from '../../themes/amsterdam/global_styling/mixins';

import { euiTableVariables } from './table.styles';

export const euiTableRowStyles = (euiThemeContext: UseEuiTheme) => {
const { euiTheme } = euiThemeContext;

const rowColors = _rowColorVariables(euiThemeContext);
const expandedAnimationCss = _expandedRowAnimation(euiThemeContext);

const cellContentPadding = euiTheme.size.s;
const mobileColumns = {
actions: {
width: euiTheme.size.xxl,
offset: mathWithUnits(cellContentPadding, (x) => x * 2),
},
checkbox: {
width: mathWithUnits(
[euiTheme.size.xl, euiTheme.size.xs],
(x, y) => x + y
),
offset: mathWithUnits(cellContentPadding, (x) => x / 2),
},
};
const { cellContentPadding, mobileSizes } =
euiTableVariables(euiThemeContext);

return {
euiTableRow: css``,
Expand Down Expand Up @@ -97,26 +83,26 @@ export const euiTableRowStyles = (euiThemeContext: UseEuiTheme) => {
* Used for selection checkbox
*/
selectable: css`
${logicalCSS('padding-left', mobileColumns.checkbox.width)}
${logicalCSS('padding-left', mobileSizes.checkbox.width)}

.euiTableRowCellCheckbox {
position: absolute;
${logicalCSS('top', cellContentPadding)}
${logicalCSS('left', mobileColumns.checkbox.offset)}
${logicalCSS('left', mobileSizes.checkbox.offset)}
}
`,
/**
* Right column styles + border
* Used for cell actions and row expander arrow
*/
hasRightColumn: css`
${logicalCSS('padding-right', mobileColumns.actions.width)}
${logicalCSS('padding-right', mobileSizes.actions.width)}

&::after {
content: '';
position: absolute;
${logicalCSS('vertical', 0)}
${logicalCSS('right', mobileColumns.actions.width)}
${logicalCSS('right', mobileSizes.actions.width)}
${logicalCSS('width', euiTheme.border.width.thin)}
background-color: ${euiTheme.border.color};
}
Expand All @@ -126,7 +112,7 @@ export const euiTableRowStyles = (euiThemeContext: UseEuiTheme) => {
${logicalCSS('right', 0)}
/* TODO: remove !important once euiTableRowCell is converted to Emotion */
${logicalCSS('min-width', '0 !important')}
${logicalCSS('width', mobileColumns.actions.width)}
${logicalCSS('width', mobileSizes.actions.width)}

.euiTableCellContent {
display: flex;
Expand All @@ -140,23 +126,23 @@ export const euiTableRowStyles = (euiThemeContext: UseEuiTheme) => {
return css`
.euiTableRowCell--hasActions {
${this.rightColumnContent}
${logicalCSS('top', mobileColumns.actions.offset)}
${logicalCSS('top', mobileSizes.actions.offset)}
}
`;
},
get expandable() {
return css`
.euiTableRowCell--isExpander {
${this.rightColumnContent}
${logicalCSS('bottom', mobileColumns.actions.offset)}
${logicalCSS('bottom', mobileSizes.actions.offset)}
}
`;
},
/**
* Bottom of card - expanded rows
*/
expanded: css`
${logicalCSS('margin-top', `-${mobileColumns.actions.offset}`)}
${logicalCSS('margin-top', `-${mobileSizes.actions.offset}`)}
/* Padding accounting for the checkbox is already applied via the content */
${logicalCSS('padding-left', cellContentPadding)}

Expand Down