mirror of
https://github.com/koloml/furbooru-tagging-assistant.git
synced 2025-12-23 23:02:58 +00:00
Added select and checkboxes fields
This commit is contained in:
12
src/components/ui/forms/CheckboxField.svelte
Normal file
12
src/components/ui/forms/CheckboxField.svelte
Normal file
@@ -0,0 +1,12 @@
|
||||
<script>
|
||||
/** @type {string|undefined} */
|
||||
export let name = undefined;
|
||||
|
||||
/** @type {boolean} */
|
||||
export let checked;
|
||||
</script>
|
||||
|
||||
<input type="checkbox" {name} bind:checked={checked}>
|
||||
<span>
|
||||
<slot></slot>
|
||||
</span>
|
||||
34
src/components/ui/forms/SelectField.svelte
Normal file
34
src/components/ui/forms/SelectField.svelte
Normal file
@@ -0,0 +1,34 @@
|
||||
<script>
|
||||
/**
|
||||
* @type {string[]|Record<string, string>}
|
||||
*/
|
||||
export let options = [];
|
||||
|
||||
/** @type {string|undefined} */
|
||||
export let name = undefined;
|
||||
|
||||
/** @type {string|undefined} */
|
||||
export let id = undefined;
|
||||
|
||||
/** @type {string|undefined} */
|
||||
export let value = undefined;
|
||||
|
||||
/** @type {Record<string, string>} */
|
||||
const optionPairs = {};
|
||||
|
||||
if (Array.isArray(options)) {
|
||||
for (let option of options) {
|
||||
optionPairs[option] = option;
|
||||
}
|
||||
} else if (options && typeof options === 'object') {
|
||||
Object.keys(options).forEach((key) => {
|
||||
optionPairs[key] = options[key];
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<select {name} {id} bind:value={value}>
|
||||
{#each Object.entries(optionPairs) as [value, label]}
|
||||
<option {value}>{label}</option>
|
||||
{/each}
|
||||
</select>
|
||||
Reference in New Issue
Block a user