Add setting for table row count and improve height calculation

This commit is contained in:
Andrew Kingston 2021-03-24 19:06:02 +00:00
parent c619b8f39e
commit 19c659fa16
2 changed files with 61 additions and 42 deletions

View File

@ -1533,6 +1533,12 @@
"key": "showAutoColumns", "key": "showAutoColumns",
"defaultValue": false "defaultValue": false
}, },
{
"type": "number",
"label": "Row Count",
"key": "rowCount",
"defaultValue": 8
},
{ {
"type": "select", "type": "select",
"label": "Theme", "label": "Theme",

View File

@ -8,7 +8,7 @@
export let dataProvider export let dataProvider
export let columns export let columns
export let showAutoColumns export let showAutoColumns
export let rowCount = 8 export let rowCount
const component = getContext("component") const component = getContext("component")
const { styleable } = getContext("sdk") const { styleable } = getContext("sdk")
@ -16,12 +16,26 @@
let sortColumn let sortColumn
let sortOrder let sortOrder
$: styles = makeStyles($component.styles, rowCount)
$: rows = dataProvider?.rows ?? [] $: rows = dataProvider?.rows ?? []
$: sortedRows = sortRows(rows, sortColumn, sortOrder) $: sortedRows = sortRows(rows, sortColumn, sortOrder)
$: loaded = dataProvider?.loaded ?? false $: loaded = dataProvider?.loaded ?? false
$: schema = dataProvider?.schema ?? {} $: schema = dataProvider?.schema ?? {}
$: fields = getFields(schema, columns, showAutoColumns) $: fields = getFields(schema, columns, showAutoColumns)
const makeStyles = (styles, rowCount) => {
if (!rowCount) {
return styles
}
return {
...styles,
normal: {
...styles.normal,
height: `${37 + rowCount * 56}px`,
},
}
}
const sortRows = (rows, sortColumn, sortOrder) => { const sortRows = (rows, sortColumn, sortOrder) => {
if (!sortColumn || !sortOrder) { if (!sortColumn || !sortOrder) {
return rows return rows
@ -52,7 +66,6 @@
} }
let columns = [] let columns = []
Object.entries(schema).forEach(([field, fieldSchema]) => { Object.entries(schema).forEach(([field, fieldSchema]) => {
console.log(fieldSchema)
if (showAutoColumns || !fieldSchema?.autocolumn) { if (showAutoColumns || !fieldSchema?.autocolumn) {
columns.push(field) columns.push(field)
} }
@ -61,12 +74,11 @@
} }
</script> </script>
<div use:styleable={$component.styles}>
<div <div
lang="en" lang="en"
dir="ltr" dir="ltr"
class={`spectrum ${size || 'spectrum--medium'} ${theme || 'spectrum--light'}`} class={`spectrum ${size || 'spectrum--medium'} ${theme || 'spectrum--light'}`}
style={`height: ${rowCount * 55}px;`}> use:styleable={styles}>
<table class="spectrum-Table"> <table class="spectrum-Table">
<thead class="spectrum-Table-head"> <thead class="spectrum-Table-head">
<tr> <tr>
@ -105,7 +117,6 @@
</tbody> </tbody>
</table> </table>
</div> </div>
</div>
<style> <style>
.spectrum { .spectrum {
@ -119,6 +130,8 @@
z-index: 1; z-index: 1;
} }
th { th {
vertical-align: bottom;
height: 36px;
position: sticky; position: sticky;
top: 0; top: 0;
background-color: var(--spectrum-global-color-gray-100); background-color: var(--spectrum-global-color-gray-100);