Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT][TABLE] Add option to unstyle table component #224

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion packages/visualizations-react/.storybook/theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,23 @@ h3 {

a:link, a:visited, a:active {
color: #774936;
}
}

/* Style for the Custom style Table story */
.table-story--custom-style .table-wrapper {
border-color: #fcd4cf;
}
.table-story--custom-style thead {
border-bottom-color: #f94346;
border-bottom-width: 2px;
background-color: #fd635d;
color:#ffffff;
}

.table-story--custom-style tbody tr {
border-bottom-color: #fcd4cf;
}
.table-story--custom-style tbody tr:hover {
background-color: #f9aea4;
}

19 changes: 7 additions & 12 deletions packages/visualizations-react/stories/Table/Table.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,7 @@ Playground.args = {
};

const CustomStyleTemplate: ComponentStory<typeof Table> = (args) => (
<div
style={
{
'--ods-sdk-table-text-color': '#000000',
'--ods-sdk-table-border-color': '#fcd4cf',
'--ods-sdk-table-header-text-color': '#ffffff',
'--ods-sdk-table-header-background-color': '#fd635d',
'--ods-sdk-table-header-border-bottom-color': '#f94346',
'--ods-sdk-table-active-row-background-color': '#f9aea4',
} as React.CSSProperties
}
>
<div className="table-story--custom-style">
<Table {...args} />
</div>
);
Expand All @@ -92,3 +81,9 @@ CustomStyle.args = {
data,
options,
};

export const Unstyled = Template.bind({});
Unstyled.args = {
data,
options: { ...options, unstyled: true },
};
55 changes: 48 additions & 7 deletions packages/visualizations/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/visualizations/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-svelte3": "^3.2.1",
"eslint-plugin-svelte3": "^3.4.1",
"npm-run-all": "^4.1.5",
"postcss": "^8.3.11",
"prettier": "2.4.1",
Expand All @@ -82,6 +82,7 @@
"rollup-plugin-svelte": "^6.1.0",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-visualizer": "^4.2.0",
"sass": "^1.70.0",
"svelte": "^3.43.2",
"svelte-check": "^2.2.7",
"svelte-preprocess": "^4.9.8",
Expand Down
9 changes: 9 additions & 0 deletions packages/visualizations/src/components/Table/Body.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,12 @@
</tr>
{/each}
</tbody>

<style lang="scss">
:global(.ods-dataviz-sdk-table--default tbody tr) {
border-bottom: 1px solid var(--border-color);
}
:global(.ods-dataviz-sdk-table--default tbody tr:last-child) {
border-bottom: none;
}
</style>
10 changes: 10 additions & 0 deletions packages/visualizations/src/components/Table/Cell.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,13 @@
</script>

<td>{value}</td>

<style lang="scss">
:global(.ods-dataviz-sdk-table--default) {
:global(td) {
padding: var(--spacing-75);
font-weight: normal;
text-align: left;
}
}
</style>
13 changes: 13 additions & 0 deletions packages/visualizations/src/components/Table/Header.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,16 @@
{/each}
</tr>
</thead>

<style lang="scss">
:global(.ods-dataviz-sdk-table--default) {
:global(thead) {
border-bottom: 1px solid var(--border-color);
}
:global(th) {
padding: var(--spacing-75);
font-weight: normal;
text-align: left;
}
}
KevinFabre-ods marked this conversation as resolved.
Show resolved Hide resolved
</style>
101 changes: 42 additions & 59 deletions packages/visualizations/src/components/Table/Table.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,23 @@
const tableId = `table-${generateId()}`;

$: ({ value: records } = data);
$: ({ columns, title, subtitle, description, source } = options);
// FIXME: Eslint is in conflict with prettier
// eslint-disable-next-line object-curly-newline
$: ({ columns, title, subtitle, description, source, unstyled } = options);
$: defaultStyle = !unstyled;
</script>

<div class="container">
<div class="header">
{#if title}
<h3>{title}</h3>
{/if}
{#if subtitle}
<p>{subtitle}</p>
{/if}
</div>
<div class="ods-dataviz-sdk-table" class:ods-dataviz-sdk-table--default={defaultStyle}>
{#if title || subtitle}
<div class="dataviz-header">
KevinFabre-ods marked this conversation as resolved.
Show resolved Hide resolved
{#if title}
<h3>{title}</h3>
{/if}
{#if subtitle}
<p>{subtitle}</p>
{/if}
</div>
{/if}
<div class="table-wrapper">
<table aria-describedby={description ? tableId : undefined}>
<Header {columns} />
Expand All @@ -42,68 +47,46 @@
{/if}
</div>

<style>
.container {
<style lang="scss">
.ods-dataviz-sdk-table {
--spacing-50: 6px;
--spacing-75: 9px;
--spacing-100: 13px;

--text-color: var(--ods-sdk-table-text-color, #565656);
--border-color: var(--ods-sdk-table-border-color, #cbd2db);
--header-text-color: var(--ods-sdk-table-header-text-color, #3c3c3c);
--header-background-color: var(--ods-sdk-table-header-background-color, #f2f3f8);
--header-border-bottom-color: var(--ods-sdk-table-header-border-bottom-color, #dee5ef);
--active-row-background-color: var(--ods-sdk-table-active-row-background-color, #f6f8fb);
--border-color: #cbd2db;

/* FIXME: Only using flex style to center source link */
display: flex;
flex-wrap: wrap;
flex-direction: column;
width: 100%;
}
.header {
margin-bottom: var(--spacing-100);
}
.header h3,
.header p {
margin: 0;
}
.table-wrapper {
border: solid 1px var(--border-color);
border-radius: var(--spacing-50);
overflow-x: auto;
overscroll-behavior-x: none;
width: inherit;
max-width: 100%;
margin-bottom: var(--spacing-100);
}
table {
border-collapse: collapse;
color: var(--text-color);
white-space: nowrap;
width: inherit;
}
:global(.container th),
:global(.container td) {
padding: var(--spacing-75);
font-weight: normal;
text-align: left;
}
:global(.container th) {
color: var(--header-text-color);
background-color: var(--header-background-color);
}
:global(.container thead) {
border-bottom: 2px solid var(--header-border-bottom-color);
}
:global(.container tbody tr:not(:last-child)) {
border-bottom: 1px solid var(--border-color);
}
:global(.container tbody tr:hover) {
background-color: var(--active-row-background-color);
}
/* Suitable for elements that are used via aria-describedby or aria-labelledby */
.a11y-invisible-description {
display: none;
}

:global(.ods-dataviz-sdk-table--default) {
.dataviz-header {
margin-bottom: var(--spacing-100);
h3,
p {
margin: 0;
}
}
:global(.table-wrapper) {
border: solid 1px var(--border-color);
border-radius: var(--spacing-50);
overflow-x: auto;
overscroll-behavior-x: none;
max-width: 100%;
width: inherit;
margin-bottom: var(--spacing-100);
table {
border-collapse: collapse;
white-space: nowrap;
width: inherit;
}
}
}
</style>
5 changes: 5 additions & 0 deletions packages/visualizations/src/components/Table/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ export type TableOptions = {
subtitle?: string;
description?: string;
source?: Source;
/**
* Removes all the presentational styles.
* Default is `false`.
*/
unstyled?: boolean;
};
Loading