Skip to content

Commit 6a78971

Browse files
committed
body cell wrapper inner
1 parent e04b439 commit 6a78971

File tree

5 files changed

+53
-44
lines changed

5 files changed

+53
-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

+13-35
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,9 @@ $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: awsui.$space-xs;
2829
$cell-offset: calc(#{awsui.$space-m} + #{awsui.$space-xs});
2930

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

@@ -99,20 +97,17 @@ $cell-negative-space-vertical: 2px;
9997
}
10098
@mixin cell-padding-block($padding) {
10199
> .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});
100+
padding-block: calc(#{$padding} - 1 * #{awsui.$border-divider-list-width});
104101
}
105102
}
106103
@mixin cell-padding-block-start($padding) {
107104
> .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});
105+
padding-block-start: calc(#{$padding} - 1 * #{awsui.$border-divider-list-width});
110106
}
111107
}
112108
@mixin cell-padding-block-end($padding) {
113109
> .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});
110+
padding-block-end: calc(#{$padding} - 1 * #{awsui.$border-divider-list-width});
116111
}
117112
}
118113

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

132127
&-content {
133128
box-sizing: border-box;
129+
block-size: 100%;
130+
align-content: center;
131+
132+
&.body-cell-align-top {
133+
align-content: baseline;
134+
}
134135

135136
&:not(.body-cell-wrap) {
136137
white-space: nowrap;
@@ -178,20 +179,10 @@ $cell-negative-space-vertical: 2px;
178179
&:not(.has-selection):not(.body-cell-editable) {
179180
border-inline-start: none;
180181
}
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-
}
188182
}
189183
&:first-child:not(.is-visual-refresh) {
190184
@include cell-padding-inline-start($cell-edge-horizontal-padding);
191185
}
192-
&-align-top {
193-
vertical-align: top;
194-
}
195186
&-first-row {
196187
border-block-start: $border-placeholder;
197188
}
@@ -381,19 +372,6 @@ $cell-negative-space-vertical: 2px;
381372
color: awsui.$color-text-button-normal-active;
382373
}
383374

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-
397375
&-row {
398376
display: flex;
399377
flex-flow: row nowrap;
@@ -429,9 +407,9 @@ $cell-negative-space-vertical: 2px;
429407
}
430408

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

437415
&: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)