Skip to content

Commit c0e7ae6

Browse files
committed
body cell wrapper inner
1 parent e04b439 commit c0e7ae6

File tree

5 files changed

+54
-44
lines changed

5 files changed

+54
-44
lines changed

pages/table/cell-permutations.page.tsx

+28-5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
FormField,
1313
Header,
1414
Input,
15+
Link,
1516
Slider,
1617
SpaceBetween,
1718
StatusIndicator,
@@ -192,15 +193,37 @@ function TableCellsDemo() {
192193

193194
const columnDefinitions: TableProps.ColumnDefinition<number>[] = columns.map(index => {
194195
const columnId = index.toString();
195-
const cellContent = (item: number) =>
196-
editedValues[`${columnId}:${item}`] ??
197-
`Body cell content ${item}:${index}${index === 1 ? ` (L=${itemLevels[item]})` : ''}${index === 8 ? ' with longer text' : ''}`;
196+
const cellRenderer = (() => {
197+
const getText = (item: number) =>
198+
editedValues[`${columnId}:${item}`] ??
199+
`Body cell content ${item}:${index}${index === 1 ? ` (L=${itemLevels[item]})` : ''}${index === 8 ? ' with longer text' : ''}`;
200+
switch (index) {
201+
case 1:
202+
return { type: 'link', getText, render: (item: number) => <Link>{getText(item)}</Link> };
203+
case 3:
204+
return {
205+
type: 'status',
206+
getText,
207+
render: (item: number) => <StatusIndicator>{getText(item)}</StatusIndicator>,
208+
};
209+
case 4:
210+
return { type: 'right-align', getText, render: () => <Box textAlign="right">{index}</Box> };
211+
case 10:
212+
return {
213+
type: 'actions',
214+
getText,
215+
render: () => <Button variant="icon" iconName="ellipsis" ariaLabel="Actions" />,
216+
};
217+
default:
218+
return { type: 'text', getText, render: getText };
219+
}
220+
})();
198221
return {
199222
id: columnId,
200223
header: `Header cell content ${index}${index === 8 ? ' with longer text' : ''}`,
201224
sortingField: index === 2 ? 'field-1' : index === 3 ? 'field-2' : undefined,
202225
activeSorting: index === 3,
203-
cell: cellContent,
226+
cell: item => cellRenderer.render(item),
204227
verticalAlign: settings.verticalAlign,
205228
editConfig: settings.isEditable
206229
? {
@@ -216,7 +239,7 @@ function TableCellsDemo() {
216239
return (
217240
<Input
218241
autoFocus={true}
219-
value={currentValue ?? cellContent(item)}
242+
value={currentValue ?? cellRenderer.getText(item)}
220243
onChange={event => setValue(event.detail.value)}
221244
/>
222245
);

src/table/body-cell/inline-editor.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export function InlineEditor<ItemType>({
114114
aria-label={ariaLabels?.activateEditLabel?.(column, item)}
115115
onKeyDown={handleEscape}
116116
>
117-
<form onSubmit={onSubmitClick} className={styles['body-cell-editor-form']}>
117+
<form onSubmit={onSubmitClick}>
118118
<FormField
119119
stretch={true}
120120
label={ariaLabel}

src/table/body-cell/styles.scss

+14-35
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@ $edit-button-padding-right: calc(#{awsui.$space-xs} + #{awsui.$space-xxs});
2525
// Cell vertical padding + xxs space that would normally come from the button.
2626
$success-icon-padding-right: calc(#{$edit-button-padding-right} + #{$icon-width-with-spacing});
2727
$interactive-column-padding-inline-end: calc(#{$cell-horizontal-padding} + #{awsui.$space-l});
28+
$editing-cell-padding-inline: awsui.$space-xxs;
29+
$editing-cell-padding-block: awsui.$space-scaled-xxxs;
2830
$cell-offset: calc(#{awsui.$space-m} + #{awsui.$space-xs});
2931

30-
// Ensuring enough space for absolute-positioned focus outlines of focus-able cell content elements.
31-
$cell-negative-space-vertical: 2px;
32-
3332
@mixin cell-focus-outline {
3433
@include styles.focus-highlight(calc(-1 * #{awsui.$space-scaled-xxs}));
3534

@@ -99,20 +98,17 @@ $cell-negative-space-vertical: 2px;
9998
}
10099
@mixin cell-padding-block($padding) {
101100
> .body-cell-content {
102-
padding-block: calc(#{$padding} - 1 * #{awsui.$border-divider-list-width} + #{$cell-negative-space-vertical});
103-
margin-block: calc(-1 * #{$cell-negative-space-vertical});
101+
padding-block: calc(#{$padding} - 1 * #{awsui.$border-divider-list-width});
104102
}
105103
}
106104
@mixin cell-padding-block-start($padding) {
107105
> .body-cell-content {
108-
padding-block-start: calc(#{$padding} - 1 * #{awsui.$border-divider-list-width} + #{$cell-negative-space-vertical});
109-
margin-block-start: calc(-1 * #{$cell-negative-space-vertical});
106+
padding-block-start: calc(#{$padding} - 1 * #{awsui.$border-divider-list-width});
110107
}
111108
}
112109
@mixin cell-padding-block-end($padding) {
113110
> .body-cell-content {
114-
padding-block-end: calc(#{$padding} - 1 * #{awsui.$border-divider-list-width} + #{$cell-negative-space-vertical});
115-
margin-block-end: calc(-1 * #{$cell-negative-space-vertical});
111+
padding-block-end: calc(#{$padding} - 1 * #{awsui.$border-divider-list-width});
116112
}
117113
}
118114

@@ -131,6 +127,12 @@ $cell-negative-space-vertical: 2px;
131127

132128
&-content {
133129
box-sizing: border-box;
130+
block-size: 100%;
131+
align-content: center;
132+
133+
&.body-cell-align-top {
134+
align-content: baseline;
135+
}
134136

135137
&:not(.body-cell-wrap) {
136138
white-space: nowrap;
@@ -178,20 +180,10 @@ $cell-negative-space-vertical: 2px;
178180
&:not(.has-selection):not(.body-cell-editable) {
179181
border-inline-start: none;
180182
}
181-
182-
// Give extra space on the edge to allow slight content overflow.
183-
// That is to prevent focus outline on cell content from being cut out.
184-
> .body-cell-content {
185-
padding-inline-start: awsui.$border-divider-list-width;
186-
margin-inline-start: calc(-1 * #{awsui.$border-divider-list-width});
187-
}
188183
}
189184
&:first-child:not(.is-visual-refresh) {
190185
@include cell-padding-inline-start($cell-edge-horizontal-padding);
191186
}
192-
&-align-top {
193-
vertical-align: top;
194-
}
195187
&-first-row {
196188
border-block-start: $border-placeholder;
197189
}
@@ -381,19 +373,6 @@ $cell-negative-space-vertical: 2px;
381373
color: awsui.$color-text-button-normal-active;
382374
}
383375

384-
&-form {
385-
margin-block: calc(-1 * #{awsui.$space-xs});
386-
margin-inline: calc(-1.5 * #{awsui.$space-xs});
387-
388-
.is-visual-refresh.body-cell:first-child.has-striped-rows > & {
389-
margin-inline-start: calc(-1 * #{awsui.$space-xxs});
390-
}
391-
392-
.is-visual-refresh.body-cell:first-child:not(.has-striped-rows) > & {
393-
margin-inline-start: calc(-1 * #{awsui.$space-xxxs});
394-
}
395-
}
396-
397376
&-row {
398377
display: flex;
399378
flex-flow: row nowrap;
@@ -429,9 +408,9 @@ $cell-negative-space-vertical: 2px;
429408
}
430409

431410
&.body-cell-edit-active {
432-
> .body-cell-content {
433-
overflow: visible;
434-
}
411+
@include cell-padding-inline-start($editing-cell-padding-inline);
412+
@include cell-padding-inline-end($editing-cell-padding-inline);
413+
@include cell-padding-block($editing-cell-padding-block);
435414
}
436415

437416
&:not(.body-cell-edit-active) {

src/table/body-cell/td-element.tsx

+10-3
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export const TableTdElement = React.forwardRef<HTMLTableCellElement, TableTdElem
102102
const Element = isRowHeader ? 'th' : 'td';
103103
const isVisualRefresh = useVisualRefresh();
104104

105-
resizableStyle = resizableColumns ? resizableStyle : {};
105+
resizableStyle = resizableColumns ? {} : resizableStyle;
106106

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

@@ -139,7 +139,6 @@ export const TableTdElement = React.forwardRef<HTMLTableCellElement, TableTdElem
139139
hasSuccessIcon && styles['body-cell-has-success'],
140140
level !== undefined && styles['body-cell-expandable'],
141141
level !== undefined && styles[`expandable-level-${getLevelClassSuffix(level)}`],
142-
verticalAlign === 'top' && styles['body-cell-align-top'],
143142
stickyStyles.className
144143
)}
145144
onClick={onClick}
@@ -161,7 +160,15 @@ export const TableTdElement = React.forwardRef<HTMLTableCellElement, TableTdElem
161160
</div>
162161
)}
163162

164-
<div className={clsx(styles['body-cell-content'], wrapLines && styles['body-cell-wrap'])}>{children}</div>
163+
<div
164+
className={clsx(
165+
styles['body-cell-content'],
166+
verticalAlign === 'top' && styles['body-cell-align-top'],
167+
wrapLines && styles['body-cell-wrap']
168+
)}
169+
>
170+
{children}
171+
</div>
165172
</Element>
166173
);
167174
}

src/table/styles.scss

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353

5454
.table {
5555
inline-size: 100%;
56+
block-size: 100%;
5657
border-spacing: 0;
5758
position: relative;
5859
box-sizing: border-box;

0 commit comments

Comments
 (0)