Skip to content

Commit fa55991

Browse files
committed
[setup] DRY out new euiTableVariables util
- table cells will use these shortly, so we might as well make it now
1 parent 6b9ef79 commit fa55991

2 files changed

Lines changed: 46 additions & 30 deletions

File tree

src/components/table/table.styles.ts

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,43 @@
99
import { css } from '@emotion/react';
1010

1111
import { UseEuiTheme } from '../../services';
12-
import { euiFontSize, euiNumberFormat, logicalCSS } from '../../global_styling';
12+
import {
13+
euiFontSize,
14+
euiNumberFormat,
15+
logicalCSS,
16+
mathWithUnits,
17+
} from '../../global_styling';
18+
19+
export const euiTableVariables = ({ euiTheme }: UseEuiTheme) => {
20+
const cellContentPadding = euiTheme.size.s;
21+
const compressedCellContentPadding = euiTheme.size.xs;
22+
23+
const mobileSizes = {
24+
actions: {
25+
width: euiTheme.size.xxl,
26+
offset: mathWithUnits(cellContentPadding, (x) => x * 2),
27+
},
28+
checkbox: {
29+
width: mathWithUnits(
30+
[euiTheme.size.xl, euiTheme.size.xs],
31+
(x, y) => x + y
32+
),
33+
offset: mathWithUnits(cellContentPadding, (x) => x / 2),
34+
},
35+
};
36+
37+
return {
38+
cellContentPadding,
39+
compressedCellContentPadding,
40+
mobileSizes,
41+
};
42+
};
1343

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

17-
const cellContentPadding = euiTheme.size.s;
18-
const compressedCellContentPadding = euiTheme.size.xs;
47+
const { cellContentPadding, compressedCellContentPadding } =
48+
euiTableVariables(euiThemeContext);
1949

2050
return {
2151
euiTable: css`

src/components/table/table_row.styles.ts

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,19 @@
99
import { css, keyframes } from '@emotion/react';
1010

1111
import { UseEuiTheme, tint, shade, transparentize } from '../../services';
12-
import {
13-
euiBackgroundColor,
14-
logicalCSS,
15-
mathWithUnits,
16-
} from '../../global_styling';
12+
import { euiBackgroundColor, logicalCSS } from '../../global_styling';
1713
import { euiShadow } from '../../themes/amsterdam/global_styling/mixins';
1814

15+
import { euiTableVariables } from './table.styles';
16+
1917
export const euiTableRowStyles = (euiThemeContext: UseEuiTheme) => {
2018
const { euiTheme } = euiThemeContext;
2119

2220
const rowColors = _rowColorVariables(euiThemeContext);
2321
const expandedAnimationCss = _expandedRowAnimation(euiThemeContext);
2422

25-
const cellContentPadding = euiTheme.size.s;
26-
const mobileColumns = {
27-
actions: {
28-
width: euiTheme.size.xxl,
29-
offset: mathWithUnits(cellContentPadding, (x) => x * 2),
30-
},
31-
checkbox: {
32-
width: mathWithUnits(
33-
[euiTheme.size.xl, euiTheme.size.xs],
34-
(x, y) => x + y
35-
),
36-
offset: mathWithUnits(cellContentPadding, (x) => x / 2),
37-
},
38-
};
23+
const { cellContentPadding, mobileSizes } =
24+
euiTableVariables(euiThemeContext);
3925

4026
return {
4127
euiTableRow: css``,
@@ -97,26 +83,26 @@ export const euiTableRowStyles = (euiThemeContext: UseEuiTheme) => {
9783
* Used for selection checkbox
9884
*/
9985
selectable: css`
100-
${logicalCSS('padding-left', mobileColumns.checkbox.width)}
86+
${logicalCSS('padding-left', mobileSizes.checkbox.width)}
10187
10288
.euiTableRowCellCheckbox {
10389
position: absolute;
10490
${logicalCSS('top', cellContentPadding)}
105-
${logicalCSS('left', mobileColumns.checkbox.offset)}
91+
${logicalCSS('left', mobileSizes.checkbox.offset)}
10692
}
10793
`,
10894
/**
10995
* Right column styles + border
11096
* Used for cell actions and row expander arrow
11197
*/
11298
hasRightColumn: css`
113-
${logicalCSS('padding-right', mobileColumns.actions.width)}
99+
${logicalCSS('padding-right', mobileSizes.actions.width)}
114100
115101
&::after {
116102
content: '';
117103
position: absolute;
118104
${logicalCSS('vertical', 0)}
119-
${logicalCSS('right', mobileColumns.actions.width)}
105+
${logicalCSS('right', mobileSizes.actions.width)}
120106
${logicalCSS('width', euiTheme.border.width.thin)}
121107
background-color: ${euiTheme.border.color};
122108
}
@@ -126,7 +112,7 @@ export const euiTableRowStyles = (euiThemeContext: UseEuiTheme) => {
126112
${logicalCSS('right', 0)}
127113
/* TODO: remove !important once euiTableRowCell is converted to Emotion */
128114
${logicalCSS('min-width', '0 !important')}
129-
${logicalCSS('width', mobileColumns.actions.width)}
115+
${logicalCSS('width', mobileSizes.actions.width)}
130116
131117
.euiTableCellContent {
132118
display: flex;
@@ -140,23 +126,23 @@ export const euiTableRowStyles = (euiThemeContext: UseEuiTheme) => {
140126
return css`
141127
.euiTableRowCell--hasActions {
142128
${this.rightColumnContent}
143-
${logicalCSS('top', mobileColumns.actions.offset)}
129+
${logicalCSS('top', mobileSizes.actions.offset)}
144130
}
145131
`;
146132
},
147133
get expandable() {
148134
return css`
149135
.euiTableRowCell--isExpander {
150136
${this.rightColumnContent}
151-
${logicalCSS('bottom', mobileColumns.actions.offset)}
137+
${logicalCSS('bottom', mobileSizes.actions.offset)}
152138
}
153139
`;
154140
},
155141
/**
156142
* Bottom of card - expanded rows
157143
*/
158144
expanded: css`
159-
${logicalCSS('margin-top', `-${mobileColumns.actions.offset}`)}
145+
${logicalCSS('margin-top', `-${mobileSizes.actions.offset}`)}
160146
/* Padding accounting for the checkbox is already applied via the content */
161147
${logicalCSS('padding-left', cellContentPadding)}
162148

0 commit comments

Comments
 (0)