Use more CSS variables and add utils to spreadsheets

This commit is contained in:
Andrew Kingston 2023-02-21 12:05:16 +00:00
parent 3abc2ddbd1
commit 8da1e507b1
6 changed files with 50 additions and 43 deletions

View File

@ -48,13 +48,13 @@
<style> <style>
.container { .container {
padding: 0 8px; padding: 0 var(--cell-padding);
display: flex; display: flex;
flex-direction: row; flex-direction: row;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
flex: 1 1 auto; flex: 1 1 auto;
gap: 4px; gap: var(--cell-spacing);
} }
.value { .value {
flex: 1 1 auto; flex: 1 1 auto;

View File

@ -1,5 +1,6 @@
<script> <script>
import { Icon } from "@budibase/bbui" import { Icon } from "@budibase/bbui"
import { getColor } from "./utils"
export let value export let value
export let schema export let schema
@ -22,12 +23,9 @@
} }
} }
const getColor = value => { const getOptionColor = value => {
const index = options.indexOf(value) const index = value ? options.indexOf(value) : null
if (!value || index === -1) { return getColor(index)
return null
}
return `hsla(${((index + 1) * 222) % 360}, 90%, 75%, 0.3)`
} }
const toggleOption = option => { const toggleOption = option => {
@ -60,7 +58,7 @@
> >
<div class="values"> <div class="values">
{#each values as val (val)} {#each values as val (val)}
{@const color = getColor(val)} {@const color = getOptionColor(val)}
{#if color} {#if color}
<div class="badge text" style="--color: {color}"> <div class="badge text" style="--color: {color}">
{val} {val}
@ -80,7 +78,7 @@
{#if open} {#if open}
<div class="options"> <div class="options">
{#each values as val (val)} {#each values as val (val)}
{@const color = getColor(val)} {@const color = getOptionColor(val)}
<div class="option" on:click={() => toggleOption(val)}> <div class="option" on:click={() => toggleOption(val)}>
<div class="badge text" style="--color: {color}"> <div class="badge text" style="--color: {color}">
{val} {val}
@ -93,7 +91,7 @@
{/each} {/each}
{#each unselectedOptions as option (option)} {#each unselectedOptions as option (option)}
<div class="option" on:click={() => toggleOption(option)}> <div class="option" on:click={() => toggleOption(option)}>
<div class="badge text" style="--color: {getColor(option)}"> <div class="badge text" style="--color: {getOptionColor(option)}">
{option} {option}
</div> </div>
</div> </div>
@ -121,9 +119,9 @@
align-items: center; align-items: center;
flex: 1 1 auto; flex: 1 1 auto;
width: 0; width: 0;
gap: 4px; gap: var(--cell-spacing);
overflow: hidden; overflow: hidden;
padding: 0 8px; padding: 0 var(--cell-padding);
} }
.text { .text {
overflow: hidden; overflow: hidden;
@ -134,9 +132,9 @@
flex: 0 0 auto; flex: 0 0 auto;
} }
.badge { .badge {
padding: 2px 8px; padding: 2px var(--cell-padding);
background: var(--color); background: var(--color);
border-radius: 8px; border-radius: var(--cell-padding);
user-select: none; user-select: none;
} }
.arrow { .arrow {
@ -153,6 +151,13 @@
var(--cell-background) 40% var(--cell-background) 40%
); );
} }
:global(.cell.hovered) .arrow {
background: linear-gradient(
to right,
transparent 0%,
var(--cell-background-hover) 40%
);
}
.options { .options {
min-width: 100%; min-width: 100%;
position: absolute; position: absolute;
@ -168,19 +173,19 @@
z-index: 1; z-index: 1;
} }
.option { .option {
flex: 0 0 32px; flex: 0 0 var(--cell-height);
padding: 0 8px; padding: 0 var(--cell-padding);
display: flex; display: flex;
flex-direction: row; flex-direction: row;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
gap: 4px; gap: var(--cell-spacing);
background-color: var(--spectrum-global-color-gray-50); background-color: var(--cell-background);
} }
.option:first-child { .option:first-child {
flex: 0 0 31px; flex: 0 0 calc(var(--cell-height) - 1px);
} }
.option:hover { .option:hover {
background-color: var(--spectrum-global-color-gray-100); background-color: var(--cell-background-hover);
} }
</style> </style>

View File

@ -1,14 +1,7 @@
<script> <script>
import { getColor } from "./utils"
export let value export let value
$: console.log(value)
const getColor = idx => {
if (!value || idx === -1) {
return null
}
return `hsla(${((idx + 1) * 222) % 360}, 90%, 75%, 0.3)`
}
</script> </script>
<div class="container"> <div class="container">
@ -24,17 +17,17 @@
display: flex; display: flex;
flex-direction: row; flex-direction: row;
align-items: center; align-items: center;
padding: 0 8px; padding: 0 var(--cell-padding);
flex: 1 1 auto; flex: 1 1 auto;
width: 0; width: 0;
gap: 4px; gap: var(--cell-spacing);
overflow: hidden; overflow: hidden;
} }
.badge { .badge {
flex: 0 0 auto; flex: 0 0 auto;
padding: 2px 8px; padding: 2px var(--cell-padding);
background: var(--color); background: var(--color);
border-radius: 8px; border-radius: var(--cell-padding);
user-select: none; user-select: none;
} }
</style> </style>

View File

@ -369,6 +369,10 @@
/* 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: 8px;
--cell-spacing: 4px;
--cell-height: 32px;
--cell-font-size: 14px;
} }
.spreadsheet { .spreadsheet {
display: grid; display: grid;
@ -407,7 +411,7 @@
flex-direction: row; flex-direction: row;
justify-content: flex-start; justify-content: flex-start;
align-items: center; align-items: center;
gap: 4px; gap: var(--cell-spacing);
} }
.delete { .delete {
display: flex; display: flex;
@ -424,7 +428,7 @@
} }
.cell { .cell {
height: 32px; height: var(--cell-height);
border-bottom: 1px solid var(--spectrum-global-color-gray-300); border-bottom: 1px solid var(--spectrum-global-color-gray-300);
border-right: 1px solid var(--spectrum-global-color-gray-300); border-right: 1px solid var(--spectrum-global-color-gray-300);
display: flex; display: flex;
@ -432,14 +436,13 @@
justify-content: flex-start; justify-content: flex-start;
align-items: center; align-items: center;
color: var(--spectrum-global-color-gray-900); color: var(--spectrum-global-color-gray-900);
font-size: 14px; font-size: var(--cell-font-size);
gap: 4px; gap: var(--cell-spacing);
background: var(--cell-background); background: var(--cell-background);
position: relative; position: relative;
} }
.cell.hovered { .cell.hovered {
background: var(--cell-background-hover); background: var(--cell-background-hover);
--cell-background: var(--cell-background-hover);
} }
.cell.selected { .cell.selected {
box-shadow: inset 0 0 0 2px var(--spectrum-global-color-blue-400); box-shadow: inset 0 0 0 2px var(--spectrum-global-color-blue-400);
@ -470,7 +473,7 @@
background: var(--spectrum-global-color-gray-200); background: var(--spectrum-global-color-gray-200);
position: sticky; position: sticky;
top: 0; top: 0;
padding: 0 8px; padding: 0 var(--cell-padding);
z-index: 3; z-index: 3;
border-color: var(--spectrum-global-color-gray-400); border-color: var(--spectrum-global-color-gray-400);
} }

View File

@ -22,7 +22,7 @@
<style> <style>
.text-cell { .text-cell {
padding: 0 8px; padding: 0 var(--cell-padding);
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: nowrap; white-space: nowrap;
@ -30,12 +30,12 @@
input { input {
border: none; border: none;
padding: 0; padding: 0;
margin: 0 8px; margin: 0 var(--cell-padding);
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: nowrap; white-space: nowrap;
background: none; background: none;
font-size: 14px; font-size: var(--cell-font-size);
font-family: var(--font-sans); font-family: var(--font-sans);
color: inherit; color: inherit;
} }

View File

@ -0,0 +1,6 @@
export const getColor = idx => {
if (idx == null || idx === -1) {
return null
}
return `hsla(${((idx + 1) * 222) % 360}, 90%, 75%, 0.3)`
}