diff --git a/packages/components/.storybook/preview.js b/packages/components/.storybook/preview.js index a21fd942c6..9a9064c96f 100644 --- a/packages/components/.storybook/preview.js +++ b/packages/components/.storybook/preview.js @@ -159,6 +159,14 @@ const mocks = { '', '/icons/system/colored/arrow-right.svg': '', + '/icons/system/colored/sort-down.svg': + '', + '/icons/system/colored/sort-down-filled.svg': + '', + '/icons/system/colored/sort-up.svg': + '', + '/icons/system/colored/sort-up-filled.svg': + '', /** * Content icons diff --git a/packages/components/src/docs/Migration/ui-table.mdx b/packages/components/src/docs/Migration/ui-table.mdx new file mode 100644 index 0000000000..bf3a5b3b1b --- /dev/null +++ b/packages/components/src/docs/Migration/ui-table.mdx @@ -0,0 +1,96 @@ +# Migration Guide: From `ui-table` to `sd-table` and `sd-table-cell` + +The new `sd-table` and `sd-table-cell` are designed to replace the `ui-table`. Rather than offering a complex component structure, they primarily focus on providing CSS styles for ``, `
`, and `` elements. + +As a result, tables no longer require the `ui-table` wrapper and instead can directly utilize the provided CSS classes. + +## ๐Ÿ’พ Slots + +### โŒ Removed Slots + +The following slots have been removed from the new components: + +1. [default] + +
+ +## ๐ŸŽจ CSS Classes + +### โœจ New CSS Classes + +#### [sd-table] + +The `sd-table` class is intended for use with the `` element and effectively resets the table styles like padding and border. + +#### [sd-table-cell] + +The `sd-table-cell` class should be applied to both `
` and `` elements. It introduces top and bottom borders to the cell and defines font size, text alignment and padding. + +#### [sd-table-cell--divider] + +This class adds a divider to the right side of the table cell. + +#### [sd-table-cell--bg-transparent] + +This class adds a transparent background color to the table cell. + +#### [sd-table-cell--bg-white] + +This class adds a white background color to the table cell. + +#### [sd-table-cell--bg-primary-100] + +This class adds a background color of primary-100 to the table cell. + +#### [sd-table-cell--bg-neutral-100] + +This class adds a background color of neutral-100 to the table cell. + +
+ +## โš™๏ธ Attributes + +### โŒ Removed Attributes + +Since the new [sd-table] and [sd-table-cell] are no longer components basically all attributes have been removed: + +1. [backgroundAlternating] +2. [coloredHead] +3. [columnLayout] +4. [firstColumnAsHeader] +5. [firstColumnFixed] +6. [firstRowAsHeader] +7. [light] + +
+ +## โœ๏ธ CSS Variables + +### โŒ Removed CSS variables + +The following CSS variables have been removed from the new components: + +1. [--component-table-head-color] +2. [--component-table-first-column-color] + +
+ +## ๐Ÿฆป Event Listeners + +### โŒ Removed Event Listeners: + +The following event listeners have been removed from the new components: + +1. [onGridReady] + +
+ +## ๐Ÿงช Methods + +### โŒ Removed Methods: + +The following methods have been removed from the new components: + +1. [componentDidLoad] + +
diff --git a/packages/components/src/solid-styles.css b/packages/components/src/solid-styles.css index 8589d72259..b770673dfe 100644 --- a/packages/components/src/solid-styles.css +++ b/packages/components/src/solid-styles.css @@ -4,3 +4,5 @@ @import './styles/paragraph/paragraph.css'; @import './styles/mark/mark.css'; @import './styles/interactive/interactive.css'; +@import './styles/table-cell/table-cell.css'; +@import './styles/table/table.css'; diff --git a/packages/components/src/styles/table-cell/table-cell.css b/packages/components/src/styles/table-cell/table-cell.css new file mode 100644 index 0000000000..75b6306b9a --- /dev/null +++ b/packages/components/src/styles/table-cell/table-cell.css @@ -0,0 +1,21 @@ +.sd-table-cell { + @apply bg-transparent border-solid border-neutral-400 border-y-[1px] border-x-0 text-black text-sm text-left p-4; + + &--divider { + @apply border-r-[1px]; + } + + &--bg { + &-white { + @apply bg-white; + } + + &-primary-100 { + @apply bg-primary-100; + } + + &-neutral-100 { + @apply bg-neutral-100; + } + } +} diff --git a/packages/components/src/styles/table-cell/table-cell.declaration.ts b/packages/components/src/styles/table-cell/table-cell.declaration.ts new file mode 100644 index 0000000000..1cc7f768b1 --- /dev/null +++ b/packages/components/src/styles/table-cell/table-cell.declaration.ts @@ -0,0 +1,20 @@ +import type { Style } from '../../declaration'; + +export default { + styleName: 'sd-table-cell', + summary: 'A table cell is a single cell inside a table, used to display discrete data elements.', + status: 'stable', + since: '1.13', + attributes: [ + { + name: 'sd-table-cell--divider', + description: 'Displays a divider to the right.' + }, + { + name: 'sd-table-cell--bg-...', + options: ['white', 'primary-100', 'neutral-100'], + description: + 'Applies the selected background-color to the table cell. If not selected, a transparent background-color is used per default.' + } + ] +} satisfies Style; diff --git a/packages/components/src/styles/table-cell/table-cell.stories.ts b/packages/components/src/styles/table-cell/table-cell.stories.ts new file mode 100644 index 0000000000..84631412dc --- /dev/null +++ b/packages/components/src/styles/table-cell/table-cell.stories.ts @@ -0,0 +1,208 @@ +import '../../solid-components'; +import { html } from 'lit-html'; +import { storybookDefaults, storybookHelpers, storybookTemplate } from '../../../scripts/storybook/helper'; + +const { argTypes, parameters } = storybookDefaults('sd-table-cell'); +const { overrideArgs } = storybookHelpers('sd-table-cell'); +const { generateTemplate } = storybookTemplate('sd-table-cell'); + +/** + * The `sd-table-cell` component offers basic styling for table cells. + * It is designed to be used in conjunction with the `sd-table` component. + */ + +export default { + title: 'Styles/sd-table-cell', + component: 'sd-table-cell', + parameters: { + ...parameters + }, + args: overrideArgs([ + { type: 'slot', name: 'default', value: 'Lorem ipsum dolor sit amet.' }, + { type: 'attribute', name: 'sd-table-cell--bg-...', value: 'transparent' } + ]), + argTypes +}; + +/** + * This shows sd-table-cell in its default state. + */ + +export const Default = { + render: (args: any) => { + return generateTemplate({ + options: { templateContent: '
%SLOT%
' }, + args + }); + } +}; + +/** + * These examples demonstrate the usage of sd-table-cell in various contexts. + * The examples are intended solely for illustrating how sd-table-cell can be used to style tables. + * The data generation and table sorting logic should not be used in production environments. + * + */ + +export const Samples = { + parameters: { + controls: { + exclude: ['sd-table-cell--divider', 'sd-table-cell--bg-...'] + } + }, + render: (args: Record) => { + // Initalize table data + const tableRowCount = 7; + const tableColumnCount = 5; + const headerData = Array.from({ length: tableColumnCount }, () => 'Header'); + const tableData = Array.from({ length: tableRowCount }, () => + Array.from({ length: tableColumnCount }, () => { + return args['default-slot'] ?? 'Lorem ipsum dolor sit amet.'; + }) + ); + + return html` + +
+
Simple Table
+ + + ${(() => { + return html` + ${headerData.map(cellData => { + return html``; + })} + `; + })()} + + + ${tableData.map(rowData => { + return html` + ${rowData.map(cellData => { + return html``; + })} + `; + })} + +
${cellData}
${cellData}
+
Simple Table With Vertical Lines
+ + + ${(() => { + return html` + ${headerData.map((cellData, columnIndex) => { + return html``; + })} + `; + })()} + + + ${tableData.map(rowData => { + return html` + ${rowData.map((cellData, columnIndex) => { + return html``; + })} + `; + })} + +
+ ${cellData} +
+ ${cellData} +
+
Simple Table With Alternating Colors
+ + + ${(() => { + return html` + ${headerData.map(cellData => { + return html``; + })} + `; + })()} + + + ${tableData.map((rowData, rowIndex) => { + return html` + ${rowData.map(cellData => { + return html``; + })} + `; + })} + +
${cellData}
+ ${cellData} +
+
Simple Table, First Column Fixed
+
This sample will be provided soon.
+ +
Multi Select Table
+
This sample will be provided soon.
+
+ `; + } +}; diff --git a/packages/components/src/styles/table/table.css b/packages/components/src/styles/table/table.css new file mode 100644 index 0000000000..c2771a7c6a --- /dev/null +++ b/packages/components/src/styles/table/table.css @@ -0,0 +1,7 @@ +/* +* Remove inherited styles from table before applying our styles. +*/ +.sd-table { + all: unset; + @apply table border-collapse border-spacing-0; +} diff --git a/packages/components/src/styles/table/table.declaration.ts b/packages/components/src/styles/table/table.declaration.ts new file mode 100644 index 0000000000..d0be4f953a --- /dev/null +++ b/packages/components/src/styles/table/table.declaration.ts @@ -0,0 +1,9 @@ +import type { Style } from '../../declaration'; + +export default { + styleName: 'sd-table', + summary: 'A table is organized structured content, used for scanning, comparing, and analyzing the data.', + status: 'stable', + since: '1.13', + attributes: [] +} satisfies Style; diff --git a/packages/components/src/styles/table/table.stories.ts b/packages/components/src/styles/table/table.stories.ts new file mode 100644 index 0000000000..51be33d66a --- /dev/null +++ b/packages/components/src/styles/table/table.stories.ts @@ -0,0 +1,29 @@ +import '../../solid-components'; +import { storybookDefaults, storybookHelpers, storybookTemplate } from '../../../scripts/storybook/helper'; + +const { argTypes, parameters } = storybookDefaults('sd-table'); +const { overrideArgs } = storybookHelpers('sd-table'); +const { generateTemplate } = storybookTemplate('sd-table'); + +/** + * The `sd-table` component resets the styles of a table to predefined values. To style table cells use the `sd-table-cell` component. + */ + +export default { + title: 'Styles/sd-table', + component: 'sd-table', + parameters: { + ...parameters + }, + args: overrideArgs({ type: 'slot', name: 'default', value: 'Lorem ipsum dolor sit amet.' }), + argTypes +}; + +export const Default = { + render: (args: any) => { + return generateTemplate({ + options: { templateContent: '
%SLOT%
' }, + args + }); + } +};