From 4b2b3467d2bbb204acd5330c4c100d63acb4e40a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81d=C3=A1m=20Kov=C3=A1cs?= <43071496+adam-kov@users.noreply.github.com> Date: Wed, 23 Nov 2022 19:45:19 +0100 Subject: [PATCH] feat: Update apps button component with colors (#936) * feat: Update app component types * fix: Typos * feat: Add select input type to components * fix: Remove width property from component types * fix: Make button full width in editor * fix: Types Co-authored-by: Faton Ramadani --- .../components/common/ButtonComponent.svelte | 7 +- .../apps/components/helpers/InputValue.svelte | 9 +- .../componentsPanel/componentDefaultProps.ts | 8 +- .../componentsPanel/componentStaticValues.ts | 7 + .../apps/editor/componentsPanel/data.ts | 13 +- .../settingsPanel/ComponentPanel.svelte | 12 +- .../settingsPanel/StaticInputEditor.svelte | 9 ++ frontend/src/lib/components/apps/rx.ts | 2 +- frontend/src/lib/components/apps/types.ts | 136 +++++++++++------- .../src/lib/components/common/button/model.ts | 5 +- 10 files changed, 135 insertions(+), 73 deletions(-) create mode 100644 frontend/src/lib/components/apps/editor/componentsPanel/componentStaticValues.ts diff --git a/frontend/src/lib/components/apps/components/common/ButtonComponent.svelte b/frontend/src/lib/components/apps/components/common/ButtonComponent.svelte index 5a2c9843f7..f69ea6ab2e 100644 --- a/frontend/src/lib/components/apps/components/common/ButtonComponent.svelte +++ b/frontend/src/lib/components/apps/components/common/ButtonComponent.svelte @@ -1,5 +1,5 @@ + { runnableComponent?.runComponent() }} - btnClasses="h-full w-full" + btnClasses="w-full h-full" + {color} > {labelValue} diff --git a/frontend/src/lib/components/apps/components/helpers/InputValue.svelte b/frontend/src/lib/components/apps/components/helpers/InputValue.svelte index e5de65c772..76cb46ca3b 100644 --- a/frontend/src/lib/components/apps/components/helpers/InputValue.svelte +++ b/frontend/src/lib/components/apps/components/helpers/InputValue.svelte @@ -3,9 +3,10 @@ import type { StaticInput, DynamicInput, AppEditorContext, UserInput } from '../../types' import { accessPropertyByPath } from '../../utils' - type T = $$Generic + type T = string | number | boolean | Record | undefined + export let input: DynamicInput | StaticInput | UserInput - export let value: T | undefined = undefined + export let value: T const { worldStore } = getContext('AppEditorContext') @@ -25,12 +26,12 @@ } } - function onValueChange(newValue: T): void { + function onValueChange(newValue: any): void { if (input.type === 'output') { if (input.name?.includes('.')) { const path = input.name.split('.').slice(1).join('.') - value = accessPropertyByPath(newValue, path) + value = accessPropertyByPath(newValue, path) } else { value = newValue } diff --git a/frontend/src/lib/components/apps/editor/componentsPanel/componentDefaultProps.ts b/frontend/src/lib/components/apps/editor/componentsPanel/componentDefaultProps.ts index 63e5b3a6db..f9c88807ff 100644 --- a/frontend/src/lib/components/apps/editor/componentsPanel/componentDefaultProps.ts +++ b/frontend/src/lib/components/apps/editor/componentsPanel/componentDefaultProps.ts @@ -1,11 +1,13 @@ +import type { Aligned } from "../../types" + const defaultProps = { inputs: {}, componentInputs: {} } -const defaultAlignement = { - horizontalAlignement: 'center', - verticalAlignement: 'center' +const defaultAlignement: Aligned = { + horizontalAlignment: 'center', + verticalAlignment: 'center' } export { defaultProps, defaultAlignement } diff --git a/frontend/src/lib/components/apps/editor/componentsPanel/componentStaticValues.ts b/frontend/src/lib/components/apps/editor/componentsPanel/componentStaticValues.ts new file mode 100644 index 0000000000..bad464e2a5 --- /dev/null +++ b/frontend/src/lib/components/apps/editor/componentsPanel/componentStaticValues.ts @@ -0,0 +1,7 @@ +import { BUTTON_COLORS } from "../../../common"; + +const buttonColorOptions = [...BUTTON_COLORS] + +export const staticValues = { + buttonColorOptions, +} as const \ No newline at end of file diff --git a/frontend/src/lib/components/apps/editor/componentsPanel/data.ts b/frontend/src/lib/components/apps/editor/componentsPanel/data.ts index efba3a2004..b687973a12 100644 --- a/frontend/src/lib/components/apps/editor/componentsPanel/data.ts +++ b/frontend/src/lib/components/apps/editor/componentsPanel/data.ts @@ -1,4 +1,4 @@ -import type { AppComponent } from '../../types' +import type { AppComponent, ComponentSet } from '../../types' import { defaultAlignement, defaultProps } from './componentDefaultProps' const windmillComponents = { @@ -20,7 +20,7 @@ const windmillComponents = { ] as AppComponent[] } -const plainComponents = { +const plainComponents: ComponentSet = { title: 'Plain Components', components: [ { @@ -47,11 +47,18 @@ const plainComponents = { visible: true, value: 'Lorem ipsum', fieldType: 'textarea' + }, + color: { + fieldType: 'select', + type: 'static', + visible: true, + value: 'blue', + optionValuesKey: 'buttonColorOptions', } }, runnable: true } - ] as AppComponent[] + ] } const chartComponents = { diff --git a/frontend/src/lib/components/apps/editor/settingsPanel/ComponentPanel.svelte b/frontend/src/lib/components/apps/editor/settingsPanel/ComponentPanel.svelte index 82357c2fd1..8aba6660b7 100644 --- a/frontend/src/lib/components/apps/editor/settingsPanel/ComponentPanel.svelte +++ b/frontend/src/lib/components/apps/editor/settingsPanel/ComponentPanel.svelte @@ -118,11 +118,11 @@ {/if} - {#if component.verticalAlignement !== undefined} - -
Horizontal alignement
+ {#if component.verticalAlignment !== undefined} + +
Horizontal alignment
- + @@ -133,9 +133,9 @@ -
Vertical alignement
+
Vertical alignment
- + diff --git a/frontend/src/lib/components/apps/editor/settingsPanel/StaticInputEditor.svelte b/frontend/src/lib/components/apps/editor/settingsPanel/StaticInputEditor.svelte index 29b9199130..7e111eee08 100644 --- a/frontend/src/lib/components/apps/editor/settingsPanel/StaticInputEditor.svelte +++ b/frontend/src/lib/components/apps/editor/settingsPanel/StaticInputEditor.svelte @@ -1,6 +1,7 @@