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

Final tables PR: cleanup, tests, stories #7642

Merged
merged 14 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion src/components/table/_table_cell_content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const EuiTableCellContent: FunctionComponent<
const styles = useEuiMemoizedStyles(euiTableCellContentStyles);
const cssStyles = [
styles.euiTableCellContent,
!isResponsive && styles[align], // On mobile, always align cells to the left
styles[align],
truncateText === true && styles.truncateText,
truncateText === false && styles.wrapText,
...(hasActions
Expand Down
13 changes: 2 additions & 11 deletions src/components/table/table.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,10 @@ export const euiTableStyles = (euiThemeContext: UseEuiTheme) => {
`,
/**
* Responsive/mobile vs desktop styles
* Individual row/cells handle their own desktop vs mobile styles
*/
desktop: css`
.euiTableHeaderCell--hideForDesktop,
.euiTableRowCell--hideForDesktop,
.euiTableRowCell__mobileHeader {
display: none;
}
`,
desktop: css``,
mobile: css`
.euiTableRowCell--hideForMobile {
display: none;
}

thead {
display: none; /* Use mobile versions of selecting and filtering instead */
}
Expand Down
10 changes: 6 additions & 4 deletions src/components/table/table_header_cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { EuiIcon } from '../icon';
import { EuiInnerText } from '../inner_text';

import { resolveWidthAsStyle } from './utils';
import { useEuiTableIsResponsive } from './mobile/responsive_context';
import { EuiTableCellContent } from './_table_cell_content';
import { euiTableHeaderFooterCellStyles } from './table_cells_shared.styles';

Expand Down Expand Up @@ -137,11 +138,12 @@ export const EuiTableHeaderCell: FunctionComponent<EuiTableHeaderCellProps> = ({
}) => {
const styles = useEuiMemoizedStyles(euiTableHeaderFooterCellStyles);

const classes = classNames('euiTableHeaderCell', className, {
'euiTableHeaderCell--hideForDesktop': mobileOptions.only,
'euiTableHeaderCell--hideForMobile': !mobileOptions.show,
});
const isResponsive = useEuiTableIsResponsive();
const hideForDesktop = !isResponsive && mobileOptions?.only;
const hideForMobile = isResponsive && !mobileOptions?.show;
if (hideForDesktop || hideForMobile) return null;

const classes = classNames('euiTableHeaderCell', className);
const inlineStyles = resolveWidthAsStyle(style, width);

const CellComponent = children ? 'th' : 'td';
Expand Down
82 changes: 33 additions & 49 deletions src/components/table/table_row_cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ export const EuiTableRowCell: FunctionComponent<Props> = ({
const cellClasses = classNames('euiTableRowCell', className, {
'euiTableRowCell--hasActions': hasActions,
'euiTableRowCell--isExpander': isExpander,
'euiTableRowCell--hideForDesktop': mobileOptions.only,
});

const widthValue = isResponsive
Expand All @@ -157,9 +156,6 @@ export const EuiTableRowCell: FunctionComponent<Props> = ({

const styleObj = resolveWidthAsStyle(style, widthValue);

const hideForMobileClasses = 'euiTableRowCell--hideForMobile';
const showForMobileClasses = 'euiTableRowCell--hideForDesktop';

const Element = setScopeRow ? 'th' : 'td';
const sharedProps = {
scope: setScopeRow ? 'row' : undefined,
Expand All @@ -174,54 +170,42 @@ export const EuiTableRowCell: FunctionComponent<Props> = ({
hasActions: hasActions || isExpander,
};

if (mobileOptions.show === false) {
return (
<Element
className={`${cellClasses} ${hideForMobileClasses}`}
{...sharedProps}
>
<EuiTableCellContent {...sharedContentProps}>
{children}
</EuiTableCellContent>
</Element>
);
} else {
return (
<Element className={cellClasses} {...sharedProps}>
{/* Mobile-only header */}
{mobileOptions.header && (
<div
css={styles.euiTableRowCell__mobileHeader}
className={`euiTableRowCell__mobileHeader ${showForMobileClasses}`}
>
{mobileOptions.header}
</div>
)}

{/* Content depending on mobile render existing */}
{mobileOptions.render ? (
<>
<EuiTableCellContent
className={showForMobileClasses}
align={mobileOptions.align ?? align}
truncateText={mobileOptions.truncateText ?? truncateText}
textOnly={mobileOptions.textOnly ?? textOnly}
if (isResponsive) {
mgadewoll marked this conversation as resolved.
Show resolved Hide resolved
if (mobileOptions.show === false) {
return null;
} else {
return (
<Element className={cellClasses} {...sharedProps}>
{mobileOptions.header && (
<div
className="euiTableRowCell__mobileHeader"
css={styles.euiTableRowCell__mobileHeader}
>
{mobileOptions.render}
</EuiTableCellContent>
<EuiTableCellContent
{...sharedContentProps}
className={hideForMobileClasses}
>
{children}
</EuiTableCellContent>
</>
) : (
{mobileOptions.header}
</div>
)}
<EuiTableCellContent
{...sharedContentProps}
align={mobileOptions.align ?? 'left'} // Default to left aligned mobile cells, unless consumers specifically set an alignment for mobile
truncateText={mobileOptions.truncateText ?? truncateText}
textOnly={mobileOptions.textOnly ?? textOnly}
>
{mobileOptions.render || children}
</EuiTableCellContent>
</Element>
);
}
} else {
if (mobileOptions.only) {
return null;
} else {
return (
<Element className={cellClasses} {...sharedProps}>
<EuiTableCellContent {...sharedContentProps}>
{children}
</EuiTableCellContent>
)}
</Element>
);
</Element>
);
}
}
};