Add initial work on refactoring color picker to account for client app theme
This commit is contained in:
parent
f2be9501d3
commit
2b7f3942d0
|
@ -9,6 +9,9 @@
|
||||||
|
|
||||||
export let value
|
export let value
|
||||||
export let size = "M"
|
export let size = "M"
|
||||||
|
export let spectrumTheme
|
||||||
|
|
||||||
|
$: console.log(spectrumTheme)
|
||||||
|
|
||||||
let open = false
|
let open = false
|
||||||
|
|
||||||
|
@ -21,7 +24,8 @@
|
||||||
{
|
{
|
||||||
label: "Grays",
|
label: "Grays",
|
||||||
colors: [
|
colors: [
|
||||||
"white",
|
"gray-50",
|
||||||
|
"gray-75",
|
||||||
"gray-100",
|
"gray-100",
|
||||||
"gray-200",
|
"gray-200",
|
||||||
"gray-300",
|
"gray-300",
|
||||||
|
@ -31,7 +35,6 @@
|
||||||
"gray-700",
|
"gray-700",
|
||||||
"gray-800",
|
"gray-800",
|
||||||
"gray-900",
|
"gray-900",
|
||||||
"black",
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -86,7 +89,7 @@
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
let found = false
|
let found = false
|
||||||
const comparisonValue = value.substring(35, value.length - 1)
|
const comparisonValue = value.substring(28, value.length - 1)
|
||||||
for (let category of categories) {
|
for (let category of categories) {
|
||||||
found = category.colors.includes(comparisonValue)
|
found = category.colors.includes(comparisonValue)
|
||||||
if (found) {
|
if (found) {
|
||||||
|
@ -102,17 +105,19 @@
|
||||||
|
|
||||||
const getCheckColor = value => {
|
const getCheckColor = value => {
|
||||||
return /^.*(white|(gray-(50|75|100|200|300|400|500)))\)$/.test(value)
|
return /^.*(white|(gray-(50|75|100|200|300|400|500)))\)$/.test(value)
|
||||||
? "black"
|
? "var(--spectrum-global-color-gray-900)"
|
||||||
: "white"
|
: "var(--spectrum-global-color-gray-50)"
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div
|
<div class="spectrum-wrapper {spectrumTheme || ''}">
|
||||||
class="preview size--{size || 'M'}"
|
<div
|
||||||
style="background: {color};"
|
class="preview size--{size || 'M'}"
|
||||||
on:click={() => (open = true)}
|
style="background: {color};"
|
||||||
/>
|
on:click={() => (open = true)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
{#if open}
|
{#if open}
|
||||||
<div
|
<div
|
||||||
use:clickOutside={() => (open = false)}
|
use:clickOutside={() => (open = false)}
|
||||||
|
@ -124,17 +129,19 @@
|
||||||
<div class="heading">{category.label}</div>
|
<div class="heading">{category.label}</div>
|
||||||
<div class="colors">
|
<div class="colors">
|
||||||
{#each category.colors as color}
|
{#each category.colors as color}
|
||||||
<div
|
<div class="spectrum-wrapper {spectrumTheme || ''}">
|
||||||
on:click={() => {
|
<div
|
||||||
onChange(`var(--spectrum-global-color-static-${color})`)
|
on:click={() => {
|
||||||
}}
|
onChange(`var(--spectrum-global-color-${color})`)
|
||||||
class="color"
|
}}
|
||||||
style="background: var(--spectrum-global-color-static-{color}); color: {checkColor};"
|
class="color"
|
||||||
title={prettyPrint(color)}
|
style="background: var(--spectrum-global-color-{color}); color: {checkColor};"
|
||||||
>
|
title={prettyPrint(color)}
|
||||||
{#if value === `var(--spectrum-global-color-static-${color})`}
|
>
|
||||||
<Icon name="Checkmark" size="S" />
|
{#if value === `var(--spectrum-global-color-${color})`}
|
||||||
{/if}
|
<Icon name="Checkmark" size="S" />
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
|
@ -236,4 +243,8 @@
|
||||||
.category--custom .heading {
|
.category--custom .heading {
|
||||||
margin-bottom: var(--spacing-xs);
|
margin-bottom: var(--spacing-xs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.spectrum-wrapper {
|
||||||
|
background-color: transparent;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -1,12 +1,6 @@
|
||||||
<script>
|
<script>
|
||||||
import { isEmpty } from "lodash/fp"
|
import { isEmpty } from "lodash/fp"
|
||||||
import {
|
import { Checkbox, Input, Select, DetailSummary } from "@budibase/bbui"
|
||||||
Checkbox,
|
|
||||||
Input,
|
|
||||||
Select,
|
|
||||||
DetailSummary,
|
|
||||||
ColorPicker,
|
|
||||||
} from "@budibase/bbui"
|
|
||||||
import { store } from "builderStore"
|
import { store } from "builderStore"
|
||||||
import PropertyControl from "./PropertyControls/PropertyControl.svelte"
|
import PropertyControl from "./PropertyControls/PropertyControl.svelte"
|
||||||
import LayoutSelect from "./PropertyControls/LayoutSelect.svelte"
|
import LayoutSelect from "./PropertyControls/LayoutSelect.svelte"
|
||||||
|
@ -31,6 +25,7 @@
|
||||||
import AttachmentFieldSelect from "./PropertyControls/AttachmentFieldSelect.svelte"
|
import AttachmentFieldSelect from "./PropertyControls/AttachmentFieldSelect.svelte"
|
||||||
import RelationshipFieldSelect from "./PropertyControls/RelationshipFieldSelect.svelte"
|
import RelationshipFieldSelect from "./PropertyControls/RelationshipFieldSelect.svelte"
|
||||||
import ResetFieldsButton from "./PropertyControls/ResetFieldsButton.svelte"
|
import ResetFieldsButton from "./PropertyControls/ResetFieldsButton.svelte"
|
||||||
|
import ColorPicker from "./PropertyControls/ColorPicker.svelte"
|
||||||
|
|
||||||
export let componentDefinition
|
export let componentDefinition
|
||||||
export let componentInstance
|
export let componentInstance
|
||||||
|
|
|
@ -1,42 +1,8 @@
|
||||||
<script>
|
<script>
|
||||||
import { createEventDispatcher } from "svelte"
|
import { ColorPicker } from "@budibase/bbui"
|
||||||
import Colorpicker from "@budibase/colorpicker"
|
import { store } from "builderStore"
|
||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
|
||||||
|
|
||||||
export let value
|
export let value
|
||||||
|
|
||||||
const WAIT = 150
|
|
||||||
|
|
||||||
function throttle(callback, wait, immediate = false) {
|
|
||||||
let timeout = null
|
|
||||||
let initialCall = true
|
|
||||||
|
|
||||||
return function () {
|
|
||||||
const callNow = immediate && initialCall
|
|
||||||
const next = () => {
|
|
||||||
callback.apply(this, arguments)
|
|
||||||
timeout = null
|
|
||||||
}
|
|
||||||
|
|
||||||
if (callNow) {
|
|
||||||
initialCall = false
|
|
||||||
next()
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!timeout) {
|
|
||||||
timeout = setTimeout(next, wait)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const onChange = throttle(
|
|
||||||
e => {
|
|
||||||
dispatch("change", e.detail)
|
|
||||||
},
|
|
||||||
WAIT,
|
|
||||||
true
|
|
||||||
)
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Colorpicker value={value || "#C4C4C4"} on:change={onChange} />
|
<ColorPicker {value} on:change spectrumTheme={$store.theme} />
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { Input, Select, ColorPicker } from "@budibase/bbui"
|
import { Input, Select } from "@budibase/bbui"
|
||||||
|
import ColorPicker from "./PropertyControls/ColorPicker.svelte"
|
||||||
|
|
||||||
export const margin = {
|
export const margin = {
|
||||||
label: "Margin",
|
label: "Margin",
|
||||||
|
|
|
@ -125,6 +125,7 @@
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
overflow-x: hidden;
|
overflow-x: hidden;
|
||||||
position: relative;
|
position: relative;
|
||||||
|
background: var(--spectrum-alias-background-color-secondary);
|
||||||
}
|
}
|
||||||
|
|
||||||
.nav-wrapper {
|
.nav-wrapper {
|
||||||
|
@ -132,7 +133,7 @@
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: stretch;
|
align-items: stretch;
|
||||||
background: white;
|
background: var(--spectrum-alias-background-color-primary);
|
||||||
z-index: 2;
|
z-index: 2;
|
||||||
box-shadow: 0 0 8px -1px rgba(0, 0, 0, 0.075);
|
box-shadow: 0 0 8px -1px rgba(0, 0, 0, 0.075);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue