-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: introduce
CoreColorInput
+ last colors selected. WF-9
- Loading branch information
Showing
10 changed files
with
203 additions
and
26 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<template> | ||
<input | ||
ref="pickerEl" | ||
type="color" | ||
class="BaseInputColor" | ||
:value="value" | ||
:list="id" | ||
@input="handleInput" | ||
@change="handleChange" | ||
/> | ||
<datalist :id="id"> | ||
<option v-for="color of customColors" :key="color">{{ color }}</option> | ||
</datalist> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { ref } from "vue"; | ||
import useCustomColors from "./hooks/useCustomColors"; | ||
import useId from "./hooks/useId"; | ||
const pickerEl = ref<HTMLInputElement | undefined>(); | ||
defineProps({ | ||
id: { type: String, default: () => useId() }, | ||
value: { type: String, required: false, default: undefined }, | ||
}); | ||
const customColors = useCustomColors(); | ||
const emit = defineEmits({ | ||
"update:value": (value: string) => typeof value === "string", | ||
change: (value: string) => typeof value === "string", | ||
}); | ||
function focus(options?: Parameters<HTMLInputElement["focus"]>[0]) { | ||
pickerEl?.value.focus(options); | ||
} | ||
function getValue() { | ||
return pickerEl?.value.value; | ||
} | ||
defineExpose({ focus, getValue }); | ||
function handleInput(event: Event) { | ||
emit("update:value", (event.target as HTMLInputElement).value); | ||
} | ||
function handleChange(event: Event) { | ||
emit("change", (event.target as HTMLInputElement).value); | ||
} | ||
</script> | ||
|
||
<style scoped> | ||
.BaseInputColor { | ||
width: 100%; | ||
border: 0; | ||
outline: none; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { computed, inject } from "vue"; | ||
import injectionKeys from "../../../injectionKeys"; | ||
|
||
/** | ||
* Get the list of colors used in any component settings | ||
*/ | ||
export default function useCustomColors() { | ||
const wf = inject(injectionKeys.core); | ||
|
||
return computed(() => { | ||
const colors = new Set( | ||
wf?.components?.value | ||
.flatMap((component) => Object.entries(component.content)) | ||
.filter(([key, _]) => String(key).endsWith("Color")) | ||
.map(([_, value]) => value), | ||
); | ||
|
||
return Array.from(colors); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* Simply generate a uniq ID to use as HTML `id` attribute | ||
*/ | ||
export default function useId() { | ||
// `crypto.randomUUID` is only available in HTTPS context | ||
return typeof crypto.randomUUID === "function" | ||
? crypto.randomUUID() | ||
: Date.now().toString(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<template> | ||
<BaseInputWrapper | ||
ref="rootInstance" | ||
:label="fields.label.value" | ||
class="CoreColorInput" | ||
> | ||
<BaseInputColor | ||
:value="formValue" | ||
@update:value="handleInput($event, 'wf-change')" | ||
@change="handleInput($event, 'wf-change-finish')" | ||
/> | ||
</BaseInputWrapper> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { ComponentPublicInstance } from "vue"; | ||
import { cssClasses } from "../../renderer/sharedStyleFields"; | ||
import { FieldType } from "../../writerTypes"; | ||
import BaseInputColor from "../base/BaseInputColor.vue"; | ||
import BaseInputWrapper from "../base/BaseInputWrapper.vue"; | ||
const description = | ||
"A user input component that allows users to select a color using a color picker interface."; | ||
const onChangeHandlerStub = ` | ||
def onchange_handler(state, payload): | ||
# Set the state variable "new_color" to the new value, provided as string. | ||
state["new_color"] = payload`; | ||
export default { | ||
writer: { | ||
name: "Color Input", | ||
description, | ||
category: "Input", | ||
fields: { | ||
label: { | ||
name: "Label", | ||
init: "Input Label", | ||
type: FieldType.Text, | ||
}, | ||
cssClasses, | ||
}, | ||
events: { | ||
"wf-change": { | ||
desc: "Capture changes as they happen.", | ||
stub: onChangeHandlerStub, | ||
bindable: true, | ||
}, | ||
"wf-change-finish": { | ||
desc: "Capture changes once this control has lost focus.", | ||
stub: onChangeHandlerStub, | ||
}, | ||
}, | ||
}, | ||
}; | ||
</script> | ||
<script setup lang="ts"> | ||
import { inject, ref } from "vue"; | ||
import injectionKeys from "../../injectionKeys"; | ||
import { useFormValueBroker } from "../../renderer/useFormValueBroker"; | ||
const fields = inject(injectionKeys.evaluatedFields); | ||
const rootInstance = ref<ComponentPublicInstance | null>(null); | ||
const wf = inject(injectionKeys.core); | ||
const instancePath = inject(injectionKeys.instancePath); | ||
const { formValue, handleInput } = useFormValueBroker<string>( | ||
wf, | ||
instancePath, | ||
rootInstance, | ||
); | ||
</script> | ||
|
||
<style scoped> | ||
@import "../../renderer/sharedStyles.css"; | ||
@import "../../renderer/colorTransformations.css"; | ||
.CoreColorInput { | ||
width: fit-content; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters