Skip to content

Commit

Permalink
body cell wrapper inner
Browse files Browse the repository at this point in the history
  • Loading branch information
pan-kot committed Nov 28, 2024
1 parent e04b439 commit 82b8f7c
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 51 deletions.
74 changes: 49 additions & 25 deletions pages/table/cell-permutations.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
FormField,
Header,
Input,
Link,
Slider,
SpaceBetween,
StatusIndicator,
Expand Down Expand Up @@ -192,37 +193,60 @@ function TableCellsDemo() {

const columnDefinitions: TableProps.ColumnDefinition<number>[] = columns.map(index => {
const columnId = index.toString();
const cellContent = (item: number) =>
editedValues[`${columnId}:${item}`] ??
`Body cell content ${item}:${index}${index === 1 ? ` (L=${itemLevels[item]})` : ''}${index === 8 ? ' with longer text' : ''}`;
const cellRenderer = (() => {
const getText = (item: number) =>
editedValues[`${columnId}:${item}`] ??
`Body cell content ${item}:${index}${index === 1 ? ` (L=${itemLevels[item]})` : ''}${index === 8 ? ' with longer text' : ''}`;
switch (index) {
case 1:
return { type: 'link', getText, render: (item: number) => <Link>{getText(item)}</Link> };
case 3:
return {
type: 'status',
getText,
render: (item: number) => <StatusIndicator>{getText(item)}</StatusIndicator>,
};
case 4:
return { type: 'right-align', getText, render: () => <Box textAlign="right">{index}</Box> };
case 10:
return {
type: 'actions',
getText,
render: () => <Button variant="icon" iconName="ellipsis" ariaLabel="Actions" />,
};
default:
return { type: 'text', getText, render: getText };
}
})();
return {
id: columnId,
header: `Header cell content ${index}${index === 8 ? ' with longer text' : ''}`,
sortingField: index === 2 ? 'field-1' : index === 3 ? 'field-2' : undefined,
activeSorting: index === 3,
cell: cellContent,
cell: item => cellRenderer.render(item),
verticalAlign: settings.verticalAlign,
editConfig: settings.isEditable
? {
ariaLabel: 'Edit dialog aria label',
editIconAriaLabel: 'Edit icon label',
errorIconAriaLabel: 'Edit error icon label',
validation(_item, value = '') {
if (value.trim() && value.toLowerCase().includes('content')) {
return 'Must not include "content"';
}
},
editingCell(item, { currentValue, setValue }: TableProps.CellContext<string>) {
return (
<Input
autoFocus={true}
value={currentValue ?? cellContent(item)}
onChange={event => setValue(event.detail.value)}
/>
);
},
}
: undefined,
editConfig:
settings.isEditable && cellRenderer.type !== 'link' && cellRenderer.type !== 'actions'
? {
ariaLabel: 'Edit dialog aria label',
editIconAriaLabel: 'Edit icon label',
errorIconAriaLabel: 'Edit error icon label',
validation(_item, value = '') {
if (value.trim() && value.toLowerCase().includes('content')) {
return 'Must not include "content"';
}
},
editingCell(item, { currentValue, setValue }: TableProps.CellContext<string>) {
return (
<Input
autoFocus={true}
value={currentValue ?? cellRenderer.getText(item)}
onChange={event => setValue(event.detail.value)}
/>
);
},
}
: undefined,
};
});

Expand Down
33 changes: 10 additions & 23 deletions src/table/body-cell/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ $interactive-column-padding-inline-end: calc(#{$cell-horizontal-padding} + #{aws
$cell-offset: calc(#{awsui.$space-m} + #{awsui.$space-xs});

// Ensuring enough space for absolute-positioned focus outlines of focus-able cell content elements.
$cell-negative-space-vertical: 2px;
$cell-negative-space: 4px;

@mixin cell-focus-outline {
@include styles.focus-highlight(calc(-1 * #{awsui.$space-scaled-xxs}));
Expand Down Expand Up @@ -99,20 +99,17 @@ $cell-negative-space-vertical: 2px;
}
@mixin cell-padding-block($padding) {
> .body-cell-content {
padding-block: calc(#{$padding} - 1 * #{awsui.$border-divider-list-width} + #{$cell-negative-space-vertical});
margin-block: calc(-1 * #{$cell-negative-space-vertical});
padding-block: calc(#{$padding} - 1 * #{awsui.$border-divider-list-width});
}
}
@mixin cell-padding-block-start($padding) {
> .body-cell-content {
padding-block-start: calc(#{$padding} - 1 * #{awsui.$border-divider-list-width} + #{$cell-negative-space-vertical});
margin-block-start: calc(-1 * #{$cell-negative-space-vertical});
padding-block-start: calc(#{$padding} - 1 * #{awsui.$border-divider-list-width});
}
}
@mixin cell-padding-block-end($padding) {
> .body-cell-content {
padding-block-end: calc(#{$padding} - 1 * #{awsui.$border-divider-list-width} + #{$cell-negative-space-vertical});
margin-block-end: calc(-1 * #{$cell-negative-space-vertical});
padding-block-end: calc(#{$padding} - 1 * #{awsui.$border-divider-list-width});
}
}

Expand All @@ -131,6 +128,12 @@ $cell-negative-space-vertical: 2px;

&-content {
box-sizing: border-box;
block-size: 100%;
align-content: center;

&.body-cell-align-top {
align-content: baseline;
}

&:not(.body-cell-wrap) {
white-space: nowrap;
Expand Down Expand Up @@ -178,20 +181,10 @@ $cell-negative-space-vertical: 2px;
&:not(.has-selection):not(.body-cell-editable) {
border-inline-start: none;
}

// Give extra space on the edge to allow slight content overflow.
// That is to prevent focus outline on cell content from being cut out.
> .body-cell-content {
padding-inline-start: awsui.$border-divider-list-width;
margin-inline-start: calc(-1 * #{awsui.$border-divider-list-width});
}
}
&:first-child:not(.is-visual-refresh) {
@include cell-padding-inline-start($cell-edge-horizontal-padding);
}
&-align-top {
vertical-align: top;
}
&-first-row {
border-block-start: $border-placeholder;
}
Expand Down Expand Up @@ -428,12 +421,6 @@ $cell-negative-space-vertical: 2px;
position: sticky;
}

&.body-cell-edit-active {
> .body-cell-content {
overflow: visible;
}
}

&:not(.body-cell-edit-active) {
cursor: pointer;

Expand Down
13 changes: 10 additions & 3 deletions src/table/body-cell/td-element.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export const TableTdElement = React.forwardRef<HTMLTableCellElement, TableTdElem
const Element = isRowHeader ? 'th' : 'td';
const isVisualRefresh = useVisualRefresh();

resizableStyle = resizableColumns ? resizableStyle : {};
resizableStyle = resizableColumns ? {} : resizableStyle;

nativeAttributes = { ...nativeAttributes, ...getTableCellRoleProps({ tableRole, isRowHeader, colIndex }) };

Expand Down Expand Up @@ -139,7 +139,6 @@ export const TableTdElement = React.forwardRef<HTMLTableCellElement, TableTdElem
hasSuccessIcon && styles['body-cell-has-success'],
level !== undefined && styles['body-cell-expandable'],
level !== undefined && styles[`expandable-level-${getLevelClassSuffix(level)}`],
verticalAlign === 'top' && styles['body-cell-align-top'],
stickyStyles.className
)}
onClick={onClick}
Expand All @@ -161,7 +160,15 @@ export const TableTdElement = React.forwardRef<HTMLTableCellElement, TableTdElem
</div>
)}

<div className={clsx(styles['body-cell-content'], wrapLines && styles['body-cell-wrap'])}>{children}</div>
<div
className={clsx(
styles['body-cell-content'],
verticalAlign === 'top' && styles['body-cell-align-top'],
wrapLines && styles['body-cell-wrap']
)}
>
{children}
</div>
</Element>
);
}
Expand Down
1 change: 1 addition & 0 deletions src/table/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@

.table {
inline-size: 100%;
block-size: 100%;
border-spacing: 0;
position: relative;
box-sizing: border-box;
Expand Down

0 comments on commit 82b8f7c

Please sign in to comment.