Add compact setting to table

This commit is contained in:
Andrew Kingston 2022-02-18 13:08:18 +00:00
parent 6237af2826
commit 9f92ee2d0b
4 changed files with 38 additions and 11 deletions

View File

@ -17,14 +17,16 @@
{#each attachments as attachment} {#each attachments as attachment}
{#if isImage(attachment.extension)} {#if isImage(attachment.extension)}
<Link quiet target="_blank" href={attachment.url}> <Link quiet target="_blank" href={attachment.url}>
<img src={attachment.url} alt={attachment.extension} /> <div class="center">
<img src={attachment.url} alt={attachment.extension} />
</div>
</Link> </Link>
{:else} {:else}
<Tooltip text={attachment.name} direction="right"> <Tooltip text={attachment.name} direction="right">
<div class="file"> <div class="file">
<Link quiet target="_blank" href={attachment.url} <Link quiet target="_blank" href={attachment.url}>
>{attachment.extension}</Link {attachment.extension}
> </Link>
</div> </div>
</Tooltip> </Tooltip>
{/if} {/if}
@ -38,12 +40,15 @@
height: 32px; height: 32px;
max-width: 64px; max-width: 64px;
} }
.center,
.file { .file {
height: 32px;
display: flex; display: flex;
flex-direction: row; flex-direction: row;
justify-content: flex-start; justify-content: flex-start;
align-items: center; align-items: center;
}
.file {
height: 32px;
padding: 0 8px; padding: 0 8px;
color: var(--spectrum-global-color-gray-800); color: var(--spectrum-global-color-gray-800);
border: 1px solid var(--spectrum-global-color-gray-300); border: 1px solid var(--spectrum-global-color-gray-300);

View File

@ -29,12 +29,12 @@
export let customRenderers = [] export let customRenderers = []
export let disableSorting = false export let disableSorting = false
export let autoSortColumns = true export let autoSortColumns = true
export let compact = false
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
rowCount = 8
// Config // Config
const rowHeight = 55 $: rowHeight = compact ? 46 : 55
const headerHeight = 36 const headerHeight = 36
const rowPreload = 5 const rowPreload = 5
@ -238,6 +238,7 @@
<div <div
class="wrapper" class="wrapper"
class:wrapper--quiet={quiet} class:wrapper--quiet={quiet}
class:wrapper--compact={compact}
bind:offsetHeight={height} bind:offsetHeight={height}
style={`--row-height: ${rowHeight}px; --header-height: ${headerHeight}px;`} style={`--row-height: ${rowHeight}px; --header-height: ${headerHeight}px;`}
> >
@ -251,7 +252,7 @@
> >
{#if fields.length} {#if fields.length}
{#if showEditColumn} {#if showEditColumn}
<div class="spectrum-Table-headCell"> <div class="spectrum-Table-headCell spectrum-Table-headCell--divider">
{editColumnTitle || ""} {editColumnTitle || ""}
</div> </div>
{/if} {/if}
@ -306,9 +307,7 @@
> >
{#if idx >= firstVisibleRow && idx <= lastVisibleRow} {#if idx >= firstVisibleRow && idx <= lastVisibleRow}
{#if showEditColumn} {#if showEditColumn}
<div <div class="spectrum-Table-cell spectrum-Table-cell--divider">
class="spectrum-Table-cell spectrum-Table-cell--divider spectrum-Table-cell--edit"
>
<SelectEditRenderer <SelectEditRenderer
data={row} data={row}
selected={selectedRows.includes(row)} selected={selectedRows.includes(row)}
@ -363,10 +362,16 @@
z-index: 0; z-index: 0;
--table-bg: var(--spectrum-global-color-gray-50); --table-bg: var(--spectrum-global-color-gray-50);
--table-border: 1px solid var(--spectrum-alias-border-color-mid); --table-border: 1px solid var(--spectrum-alias-border-color-mid);
--cell-padding: 20px;
} }
.wrapper--quiet { .wrapper--quiet {
--table-bg: var(--spectrum-alias-background-color-transparent); --table-bg: var(--spectrum-alias-background-color-transparent);
} }
.wrapper--compact {
/*--spectrum-table-header-padding-x: 5px;*/
/*--spectrum-table-cell-padding-x: 5px;*/
--cell-padding: 12px;
}
/* Table */ /* Table */
.spectrum-Table { .spectrum-Table {
@ -397,6 +402,11 @@
background-color: var(--spectrum-alias-background-color-secondary); background-color: var(--spectrum-alias-background-color-secondary);
z-index: 2; z-index: 2;
border-bottom: var(--table-border); border-bottom: var(--table-border);
padding-left: var(--cell-padding);
padding-right: 0;
}
.spectrum-Table-headCell--divider {
padding-right: var(--cell-padding);
} }
.spectrum-Table-headCell-content { .spectrum-Table-headCell-content {
overflow: hidden; overflow: hidden;
@ -469,6 +479,11 @@
transition: background-color transition: background-color
var(--spectrum-global-animation-duration-100, 0.13s) ease-in-out; var(--spectrum-global-animation-duration-100, 0.13s) ease-in-out;
border-bottom: 1px solid var(--spectrum-alias-border-color-mid); border-bottom: 1px solid var(--spectrum-alias-border-color-mid);
padding-left: var(--cell-padding);
padding-right: 0;
}
.spectrum-Table-cell--divider {
padding-right: var(--cell-padding);
} }
.spectrum-Table-cell--empty { .spectrum-Table-cell--empty {
grid-column: 1 / -1; grid-column: 1 / -1;

View File

@ -2702,6 +2702,11 @@
"label": "Quiet", "label": "Quiet",
"key": "quiet" "key": "quiet"
}, },
{
"type": "boolean",
"label": "Compact",
"key": "compact"
},
{ {
"type": "boolean", "type": "boolean",
"label": "Show auto columns", "label": "Show auto columns",

View File

@ -14,6 +14,7 @@
export let linkURL export let linkURL
export let linkColumn export let linkColumn
export let linkPeek export let linkPeek
export let compact
const component = getContext("component") const component = getContext("component")
const { styleable, getAction, ActionTypes, routeStore } = getContext("sdk") const { styleable, getAction, ActionTypes, routeStore } = getContext("sdk")
@ -122,6 +123,7 @@
{loading} {loading}
{rowCount} {rowCount}
{quiet} {quiet}
{compact}
{customRenderers} {customRenderers}
allowSelectRows={false} allowSelectRows={false}
allowEditRows={false} allowEditRows={false}