Update text cells, number cells, long form field cells and relationship cells to respect row height

This commit is contained in:
Andrew Kingston 2023-04-17 13:37:03 +01:00
parent bed6fe607c
commit c4125b5a93
10 changed files with 94 additions and 28 deletions

View File

@ -111,6 +111,7 @@
width={column.width} width={column.width}
left={column.left} left={column.left}
defaultHeight defaultHeight
center
> >
<Icon <Icon
size="S" size="S"

View File

@ -56,6 +56,7 @@
value={value || ""} value={value || ""}
on:change={handleChange} on:change={handleChange}
on:wheel|stopPropagation on:wheel|stopPropagation
spellcheck="false"
/> />
{:else} {:else}
<div class="long-form-cell" on:click={editable ? open : null} class:editable> <div class="long-form-cell" on:click={editable ? open : null} class:editable>
@ -68,19 +69,21 @@
<style> <style>
.long-form-cell { .long-form-cell {
flex: 1 1 auto; flex: 1 1 auto;
padding: 0 var(--cell-padding); padding: var(--cell-padding);
align-self: stretch; align-self: stretch;
display: flex; display: flex;
align-items: center; align-items: flex-start;
overflow: hidden; overflow: hidden;
} }
.long-form-cell.editable:hover { .long-form-cell.editable:hover {
cursor: text; cursor: text;
} }
.value { .value {
display: -webkit-box;
-webkit-line-clamp: var(--content-lines);
-webkit-box-orient: vertical;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; line-height: 19px;
white-space: nowrap;
} }
textarea { textarea {
padding: var(--cell-padding); padding: var(--cell-padding);
@ -98,6 +101,7 @@
z-index: 1; z-index: 1;
border-radius: 2px; border-radius: 2px;
resize: none; resize: none;
line-height: 19px;
} }
textarea.invertX { textarea.invertX {
left: auto; left: auto;

View File

@ -289,7 +289,7 @@
min-height: var(--row-height); min-height: var(--row-height);
max-height: var(--row-height); max-height: var(--row-height);
overflow: hidden; overflow: hidden;
--max-relationship-height: 94px; --max-relationship-height: 92px;
} }
.wrapper.focused { .wrapper.focused {
position: absolute; position: absolute;
@ -330,15 +330,15 @@
justify-content: flex-start; justify-content: flex-start;
align-items: flex-start; align-items: flex-start;
flex: 1 1 auto; flex: 1 1 auto;
gap: var(--cell-spacing); grid-column-gap: var(--cell-spacing);
grid-row-gap: 7px; grid-row-gap: var(--cell-padding);
overflow: hidden; overflow: hidden;
padding: 7px var(--cell-padding); padding: var(--cell-padding);
flex-wrap: wrap; flex-wrap: wrap;
} }
.badge { .badge {
flex: 0 0 auto; flex: 0 0 auto;
padding: 2px var(--cell-padding); padding: 0 var(--cell-padding);
background: var(--color); background: var(--color);
border-radius: var(--cell-padding); border-radius: var(--cell-padding);
user-select: none; user-select: none;
@ -348,6 +348,7 @@
display: flex; display: flex;
align-items: center; align-items: center;
gap: var(--cell-spacing); gap: var(--cell-spacing);
height: 20px;
} }
.focused .badge span:hover { .focused .badge span:hover {
cursor: pointer; cursor: pointer;
@ -368,8 +369,7 @@
position: absolute; position: absolute;
top: 100%; top: 100%;
left: 0; left: 0;
min-width: 100%; width: 100%;
max-width: calc(100% + var(--max-cell-render-width-overflow));
height: calc( height: calc(
var(--max-cell-render-height) + var(--row-height) - var(--max-cell-render-height) + var(--row-height) -
var(--max-relationship-height) var(--max-relationship-height)

View File

@ -7,6 +7,7 @@
export let error = null export let error = null
export let rowIdx export let rowIdx
export let defaultHeight = false export let defaultHeight = false
export let center = false
$: style = getStyle(width, selectedUser) $: style = getStyle(width, selectedUser)
@ -25,6 +26,7 @@
class:highlighted class:highlighted
class:focused class:focused
class:error class:error
class:center
class:default-height={defaultHeight} class:default-height={defaultHeight}
class:selected-other={selectedUser != null} class:selected-other={selectedUser != null}
on:focus on:focus
@ -57,7 +59,7 @@
display: flex; display: flex;
flex-direction: row; flex-direction: row;
justify-content: flex-start; justify-content: flex-start;
align-items: center; align-items: flex-start;
color: var(--spectrum-global-color-gray-800); color: var(--spectrum-global-color-gray-800);
font-size: var(--cell-font-size); font-size: var(--cell-font-size);
gap: var(--cell-spacing); gap: var(--cell-spacing);
@ -69,6 +71,9 @@
.cell.default-height { .cell.default-height {
height: var(--default-row-height); height: var(--default-row-height);
} }
.cell.center {
align-items: center;
}
/* Cell border */ /* Cell border */
.cell.focused:after, .cell.focused:after,

View File

@ -48,23 +48,42 @@
on:change={handleChange} on:change={handleChange}
/> />
{:else} {:else}
<div class="text-cell"> <div class="text-cell" class:number={type === "number"}>
{value || ""} <div class="value">
{value || ""}
</div>
</div> </div>
{/if} {/if}
<style> <style>
.text-cell { .text-cell {
padding: 0 var(--cell-padding); flex: 1 1 auto;
padding: var(--cell-padding);
align-self: stretch;
display: flex;
align-items: flex-start;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; }
white-space: nowrap; .text-cell.editable:hover {
cursor: text;
}
.text-cell.number {
justify-content: flex-end;
}
.value {
display: -webkit-box;
-webkit-line-clamp: var(--content-lines);
-webkit-box-orient: vertical;
overflow: hidden;
line-height: 19px;
}
.number .value {
-webkit-line-clamp: 1;
} }
input { input {
flex: 1 1 auto; flex: 1 1 auto;
border: none; border: none;
padding: 0; padding: var(--cell-padding);
margin: 0 var(--cell-padding);
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: nowrap; white-space: nowrap;
@ -76,4 +95,17 @@
input:focus { input:focus {
outline: none; outline: none;
} }
input[type="number"] {
text-align: right;
}
/* Hide arrows for number fields */
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
-webkit-appearance: none;
margin: 0;
}
input[type="number"] {
-moz-appearance: textfield;
}
</style> </style>

View File

@ -1,21 +1,25 @@
<script> <script>
import { getContext } from "svelte" import { getContext } from "svelte"
import { ActionButton, Popover } from "@budibase/bbui" import { ActionButton, Popover } from "@budibase/bbui"
import { DefaultRowHeight } from "../lib/constants" import {
LargeRowHeight,
MediumRowHeight,
SmallRowHeight,
} from "../lib/constants"
const { rowHeight, loaded } = getContext("sheet") const { rowHeight, loaded } = getContext("sheet")
const sizeOptions = [ const sizeOptions = [
{ {
label: "Small", label: "Small",
size: DefaultRowHeight, size: SmallRowHeight,
}, },
{ {
label: "Medium", label: "Medium",
size: 65, size: MediumRowHeight,
}, },
{ {
label: "Large", label: "Large",
size: 94, size: LargeRowHeight,
}, },
] ]

View File

@ -62,7 +62,8 @@
context = attachStores(context) context = attachStores(context)
// Reference some stores for local use // Reference some stores for local use
const { isResizing, isReordering, ui, loaded, rowHeight } = context const { isResizing, isReordering, ui, loaded, rowHeight, contentLines } =
context
// Keep stores up to date // Keep stores up to date
$: tableIdStore.set(tableId) $: tableIdStore.set(tableId)
@ -90,7 +91,7 @@
id="sheet-{rand}" id="sheet-{rand}"
class:is-resizing={$isResizing} class:is-resizing={$isResizing}
class:is-reordering={$isReordering} class:is-reordering={$isReordering}
style="--row-height:{$rowHeight}px; --default-row-height:{DefaultRowHeight}px; --gutter-width:{GutterWidth}px; --max-cell-render-height:{MaxCellRenderHeight}px; --max-cell-render-width-overflow:{MaxCellRenderWidthOverflow}px;" style="--row-height:{$rowHeight}px; --default-row-height:{DefaultRowHeight}px; --gutter-width:{GutterWidth}px; --max-cell-render-height:{MaxCellRenderHeight}px; --max-cell-render-width-overflow:{MaxCellRenderWidthOverflow}px; --content-lines:{$contentLines};"
> >
<div class="controls"> <div class="controls">
<div class="controls-left"> <div class="controls-left">
@ -145,7 +146,7 @@
/* Variables */ /* Variables */
--cell-background: var(--spectrum-global-color-gray-50); --cell-background: var(--spectrum-global-color-gray-50);
--cell-background-hover: var(--spectrum-global-color-gray-100); --cell-background-hover: var(--spectrum-global-color-gray-100);
--cell-padding: 10px; --cell-padding: 8px;
--cell-spacing: 4px; --cell-spacing: 4px;
--cell-border: 1px solid var(--spectrum-global-color-gray-200); --cell-border: 1px solid var(--spectrum-global-color-gray-200);
--cell-font-size: 14px; --cell-font-size: 14px;

View File

@ -58,7 +58,7 @@
class:scrolled={$scrollLeft > 0} class:scrolled={$scrollLeft > 0}
> >
<div class="header row"> <div class="header row">
<SheetCell width={GutterWidth} defaultHeight> <SheetCell width={GutterWidth} defaultHeight center>
<div class="gutter"> <div class="gutter">
<div class="checkbox visible"> <div class="checkbox visible">
{#if $config.allowDeleteRows} {#if $config.allowDeleteRows}

View File

@ -6,4 +6,7 @@ export const GutterWidth = 72
export const DefaultColumnWidth = 200 export const DefaultColumnWidth = 200
export const DefaultRelationshipColumnWidth = 360 export const DefaultRelationshipColumnWidth = 360
export const MinColumnWidth = 100 export const MinColumnWidth = 100
export const DefaultRowHeight = 36 export const SmallRowHeight = 36
export const MediumRowHeight = 64
export const LargeRowHeight = 92
export const DefaultRowHeight = SmallRowHeight

View File

@ -1,4 +1,9 @@
import { writable, get, derived } from "svelte/store" import { writable, get, derived } from "svelte/store"
import {
LargeRowHeight,
MediumRowHeight,
SmallRowHeight,
} from "../lib/constants"
export const createStores = () => { export const createStores = () => {
const focusedCellId = writable(null) const focusedCellId = writable(null)
@ -35,6 +40,7 @@ export const deriveStores = context => {
hoveredRowId, hoveredRowId,
enrichedRows, enrichedRows,
rowLookupMap, rowLookupMap,
rowHeight,
} = context } = context
// Derive the row that contains the selected cell // Derive the row that contains the selected cell
@ -62,8 +68,18 @@ export const deriveStores = context => {
hoveredRowId.set(null) hoveredRowId.set(null)
} }
const contentLines = derived(rowHeight, $rowHeight => {
if ($rowHeight === LargeRowHeight) {
return 4
} else if ($rowHeight === MediumRowHeight) {
return 2
}
return 1
})
return { return {
focusedRow, focusedRow,
contentLines,
ui: { ui: {
actions: { actions: {
blur, blur,