From 4c9b8a8a8b7c1e717ba2109d079fff7f1a2599d7 Mon Sep 17 00:00:00 2001 From: Andrei Zhaleznichenka Date: Tue, 26 Nov 2024 13:23:41 +0100 Subject: [PATCH 1/4] move cell wrap style to cell content --- src/table/body-cell/styles.scss | 11 ++++++----- src/table/body-cell/td-element.tsx | 3 +-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/table/body-cell/styles.scss b/src/table/body-cell/styles.scss index 6fe993a0a1..c1f5b19728 100644 --- a/src/table/body-cell/styles.scss +++ b/src/table/body-cell/styles.scss @@ -131,11 +131,12 @@ $cell-negative-space-vertical: 2px; &-content { box-sizing: border-box; - } - &:not(.body-cell-wrap) > .body-cell-content { - white-space: nowrap; - overflow: hidden; - text-overflow: ellipsis; + + &:not(.body-cell-wrap) { + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + } } &:first-child { border-inline-start: $border-placeholder; diff --git a/src/table/body-cell/td-element.tsx b/src/table/body-cell/td-element.tsx index 22a9def552..8e1b9238e6 100644 --- a/src/table/body-cell/td-element.tsx +++ b/src/table/body-cell/td-element.tsx @@ -118,7 +118,6 @@ export const TableTdElement = React.forwardRef )} -
{children}
+
{children}
); } From e04b43909f990f1a0156ea57b6848861cc24b47e Mon Sep 17 00:00:00 2001 From: Andrei Zhaleznichenka Date: Tue, 26 Nov 2024 13:36:55 +0100 Subject: [PATCH 2/4] replaces cell style with resizable-style --- src/table/body-cell/td-element.tsx | 9 ++++++--- src/table/column-widths-utils.ts | 8 +++++++- src/table/header-cell/index.tsx | 7 ++++--- src/table/header-cell/th-element.tsx | 7 ++++--- src/table/internal.tsx | 14 +++++--------- src/table/thead.tsx | 2 +- src/table/use-column-widths.tsx | 11 ++++------- 7 files changed, 31 insertions(+), 27 deletions(-) diff --git a/src/table/body-cell/td-element.tsx b/src/table/body-cell/td-element.tsx index 8e1b9238e6..18f3d7da52 100644 --- a/src/table/body-cell/td-element.tsx +++ b/src/table/body-cell/td-element.tsx @@ -8,6 +8,7 @@ import { copyAnalyticsMetadataAttribute } from '@cloudscape-design/component-too import { useSingleTabStopNavigation } from '../../internal/context/single-tab-stop-navigation-context'; import { useMergeRefs } from '../../internal/hooks/use-merge-refs'; import { useVisualRefresh } from '../../internal/hooks/use-visual-mode'; +import { ColumnWidthStyle } from '../column-widths-utils'; import { ExpandToggleButton } from '../expandable-rows/expand-toggle-button'; import { TableProps } from '../interfaces.js'; import { StickyColumnsModel, useStickyCellStyles } from '../sticky-columns'; @@ -18,7 +19,6 @@ import tableStyles from '../styles.css.js'; import styles from './styles.css.js'; export interface TableTdElementProps { - style?: React.CSSProperties; wrapLines: boolean | undefined; isRowHeader?: boolean; isFirstRow: boolean; @@ -51,6 +51,7 @@ export interface TableTdElementProps { collapseButtonLabel?: string; verticalAlign?: TableProps.VerticalAlign; resizableColumns?: boolean; + resizableStyle?: ColumnWidthStyle; isEditable: boolean; isEditing: boolean; isEditingDisabled?: boolean; @@ -60,7 +61,6 @@ export interface TableTdElementProps { export const TableTdElement = React.forwardRef( ( { - style, children, wrapLines, isRowHeader, @@ -90,6 +90,7 @@ export const TableTdElement = React.forwardRef>) { for (const column of columnDefinitions) { checkProperty(column, 'minWidth'); @@ -12,7 +18,7 @@ export function checkColumnWidths(columnDefinitions: ReadonlyArray { - style?: React.CSSProperties; tabIndex: number; column: TableProps.ColumnDefinition; activeSortingColumn?: TableProps.SortingColumn; @@ -40,6 +40,7 @@ export interface TableHeaderCellProps { colIndex: number; updateColumn: (columnId: PropertyKey, newWidth: number) => void; resizableColumns?: boolean; + resizableStyle?: ColumnWidthStyle; isEditable?: boolean; columnId: PropertyKey; stickyState: StickyColumnsModel; @@ -53,7 +54,6 @@ export interface TableHeaderCellProps { } export function TableHeaderCell({ - style, tabIndex, column, activeSortingColumn, @@ -69,6 +69,7 @@ export function TableHeaderCell({ colIndex, updateColumn, resizableColumns, + resizableStyle, onResizeFinish, isEditable, columnId, @@ -120,7 +121,7 @@ export function TableHeaderCell({ return ( onResizeFinish(columnWidths)} resizableColumns={resizableColumns} + resizableStyle={getColumnStyles(sticky, columnId)} onClick={detail => { setLastUserAction('sorting'); fireNonCancelableEvent(onSortingChange, detail); diff --git a/src/table/use-column-widths.tsx b/src/table/use-column-widths.tsx index 3e50e64974..db41a79c8c 100644 --- a/src/table/use-column-widths.tsx +++ b/src/table/use-column-widths.tsx @@ -5,15 +5,12 @@ import React, { createContext, useContext, useEffect, useRef, useState } from 'r import { useResizeObserver, useStableCallback } from '@cloudscape-design/component-toolkit/internal'; import { getLogicalBoundingClientRect } from '@cloudscape-design/component-toolkit/internal'; -import { setElementWidths } from './column-widths-utils'; +import { ColumnWidthStyle, setElementWidths } from './column-widths-utils'; export const DEFAULT_COLUMN_WIDTH = 120; -export interface ColumnWidthDefinition { +export interface ColumnWidthDefinition extends ColumnWidthStyle { id: PropertyKey; - minWidth?: string | number; - maxWidth?: string | number; - width?: string | number; } function readWidths( @@ -61,7 +58,7 @@ function updateWidths( } interface WidthsContext { - getColumnStyles(sticky: boolean, columnId: PropertyKey): React.CSSProperties; + getColumnStyles(sticky: boolean, columnId: PropertyKey): ColumnWidthStyle; columnWidths: Map; updateColumn: (columnId: PropertyKey, newWidth: number) => void; setCell: (sticky: boolean, columnId: PropertyKey, node: null | HTMLElement) => void; @@ -98,7 +95,7 @@ export function ColumnWidthsProvider({ visibleColumns, resizableColumns, contain } }; - const getColumnStyles = (sticky: boolean, columnId: PropertyKey): React.CSSProperties => { + const getColumnStyles = (sticky: boolean, columnId: PropertyKey): ColumnWidthStyle => { const column = visibleColumns.find(column => column.id === columnId); if (!column) { return {}; From c0e7ae64082fcc8828899becb5b52dd143bcec15 Mon Sep 17 00:00:00 2001 From: Andrei Zhaleznichenka Date: Tue, 26 Nov 2024 14:54:20 +0100 Subject: [PATCH 3/4] body cell wrapper inner --- pages/table/cell-permutations.page.tsx | 33 ++++++++++++++--- src/table/body-cell/inline-editor.tsx | 2 +- src/table/body-cell/styles.scss | 49 ++++++++------------------ src/table/body-cell/td-element.tsx | 13 +++++-- src/table/styles.scss | 1 + 5 files changed, 54 insertions(+), 44 deletions(-) diff --git a/pages/table/cell-permutations.page.tsx b/pages/table/cell-permutations.page.tsx index 560eed95ed..2caa481081 100644 --- a/pages/table/cell-permutations.page.tsx +++ b/pages/table/cell-permutations.page.tsx @@ -12,6 +12,7 @@ import { FormField, Header, Input, + Link, Slider, SpaceBetween, StatusIndicator, @@ -192,15 +193,37 @@ function TableCellsDemo() { const columnDefinitions: TableProps.ColumnDefinition[] = 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) => {getText(item)} }; + case 3: + return { + type: 'status', + getText, + render: (item: number) => {getText(item)}, + }; + case 4: + return { type: 'right-align', getText, render: () => {index} }; + case 10: + return { + type: 'actions', + getText, + render: () =>