Update colorpicker to work with nullish values by always providing a fallback default value
This commit is contained in:
parent
0cfc05f6a8
commit
750d00a95a
|
@ -23,7 +23,6 @@ import {
|
||||||
getComponentDefinition,
|
getComponentDefinition,
|
||||||
findParent,
|
findParent,
|
||||||
} from "../storeUtils"
|
} from "../storeUtils"
|
||||||
import { defaults } from "../../components/userInterface/propertyCategories"
|
|
||||||
|
|
||||||
const INITIAL_FRONTEND_STATE = {
|
const INITIAL_FRONTEND_STATE = {
|
||||||
apps: [],
|
apps: [],
|
||||||
|
@ -382,11 +381,7 @@ export const getFrontendStore = () => {
|
||||||
},
|
},
|
||||||
resetStyles: async () => {
|
resetStyles: async () => {
|
||||||
const selected = get(selectedComponent)
|
const selected = get(selectedComponent)
|
||||||
selected._styles = {
|
selected._styles = { normal: {}, hover: {}, active: {} }
|
||||||
normal: defaults,
|
|
||||||
hover: defaults,
|
|
||||||
active: defaults,
|
|
||||||
}
|
|
||||||
await store.actions.preview.saveSelected()
|
await store.actions.preview.saveSelected()
|
||||||
},
|
},
|
||||||
updateProp: (name, value) => {
|
updateProp: (name, value) => {
|
||||||
|
|
|
@ -11,9 +11,14 @@
|
||||||
export let open = false
|
export let open = false
|
||||||
|
|
||||||
const hasPropChanged = prop => {
|
const hasPropChanged = prop => {
|
||||||
|
// TODO: replace color picker with one that works better.
|
||||||
|
// Currently it cannot support null values, so this is a hack which
|
||||||
|
// prevents the color fields from always being marked as changed
|
||||||
|
if (!["color", "background", "border-color"].includes(prop.key)) {
|
||||||
if (prop.initialValue !== undefined) {
|
if (prop.initialValue !== undefined) {
|
||||||
return style[prop.key] !== prop.initialValue
|
return style[prop.key] !== prop.initialValue
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return style[prop.key] != null && style[prop.key] !== ""
|
return style[prop.key] != null && style[prop.key] !== ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@ import { isString, isUndefined, cloneDeep } from "lodash/fp"
|
||||||
import { TYPE_MAP } from "./types"
|
import { TYPE_MAP } from "./types"
|
||||||
import { assign } from "lodash"
|
import { assign } from "lodash"
|
||||||
import { uuid } from "builderStore/uuid"
|
import { uuid } from "builderStore/uuid"
|
||||||
import { defaults } from "../propertyCategories"
|
|
||||||
|
|
||||||
export const getBuiltin = _component => {
|
export const getBuiltin = _component => {
|
||||||
const { props } = createProps({ _component })
|
const { props } = createProps({ _component })
|
||||||
|
@ -25,11 +24,7 @@ export const createProps = (componentDefinition, derivedFromProps) => {
|
||||||
const props = {
|
const props = {
|
||||||
_id: uuid(),
|
_id: uuid(),
|
||||||
_component: componentDefinition._component,
|
_component: componentDefinition._component,
|
||||||
_styles: {
|
_styles: { normal: {}, hover: {}, active: {} },
|
||||||
normal: defaults,
|
|
||||||
hover: defaults,
|
|
||||||
active: defaults,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const errors = []
|
const errors = []
|
||||||
|
@ -80,11 +75,7 @@ export const makePropsSafe = (componentDefinition, props) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!props._styles) {
|
if (!props._styles) {
|
||||||
props._styles = {
|
props._styles = { normal: {}, hover: {}, active: {} }
|
||||||
normal: defaults,
|
|
||||||
hover: defaults,
|
|
||||||
active: defaults,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return props
|
return props
|
||||||
|
|
|
@ -2,9 +2,6 @@ import Input from "./PropertyPanelControls/Input.svelte"
|
||||||
import OptionSelect from "./OptionSelect.svelte"
|
import OptionSelect from "./OptionSelect.svelte"
|
||||||
import FlatButtonGroup from "./FlatButtonGroup.svelte"
|
import FlatButtonGroup from "./FlatButtonGroup.svelte"
|
||||||
import Colorpicker from "@budibase/colorpicker"
|
import Colorpicker from "@budibase/colorpicker"
|
||||||
/*
|
|
||||||
TODO: Allow for default values for all properties
|
|
||||||
*/
|
|
||||||
|
|
||||||
export const layout = [
|
export const layout = [
|
||||||
{
|
{
|
||||||
|
@ -481,6 +478,7 @@ export const typography = [
|
||||||
label: "Color",
|
label: "Color",
|
||||||
key: "color",
|
key: "color",
|
||||||
control: Colorpicker,
|
control: Colorpicker,
|
||||||
|
initialValue: "#000",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "align",
|
label: "align",
|
||||||
|
@ -524,6 +522,7 @@ export const background = [
|
||||||
label: "Color",
|
label: "Color",
|
||||||
key: "background",
|
key: "background",
|
||||||
control: Colorpicker,
|
control: Colorpicker,
|
||||||
|
initialValue: "#000",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "Gradient",
|
label: "Gradient",
|
||||||
|
@ -646,6 +645,7 @@ export const border = [
|
||||||
label: "Color",
|
label: "Color",
|
||||||
key: "border-color",
|
key: "border-color",
|
||||||
control: Colorpicker,
|
control: Colorpicker,
|
||||||
|
initialValue: "#000",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "Style",
|
label: "Style",
|
||||||
|
@ -807,13 +807,3 @@ export function excludeProps(props, propsToExclude) {
|
||||||
}
|
}
|
||||||
return modifiedProps
|
return modifiedProps
|
||||||
}
|
}
|
||||||
|
|
||||||
let defaultStyles = {}
|
|
||||||
Object.values(all).forEach(category => {
|
|
||||||
category.forEach(prop => {
|
|
||||||
if (prop.initialValue) {
|
|
||||||
defaultStyles[prop.key] = prop.initialValue
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
export const defaults = defaultStyles
|
|
||||||
|
|
Loading…
Reference in New Issue