generated from obsidianmd/obsidian-sample-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: separate input builder for select
fixes #75
- Loading branch information
1 parent
6346b7a
commit e75a1f4
Showing
4 changed files
with
137 additions
and
1 deletion.
There are no files selected for viewing
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,80 @@ | ||
<script lang="ts"> | ||
/** | ||
* This component is specific for the input builder, | ||
* specifically to build the select input type | ||
*/ | ||
import { setIcon } from "obsidian"; | ||
import FormRow from "./FormRow.svelte"; | ||
import InputFolder from "./InputFolder.svelte"; | ||
import type { EditableInput } from "src/core/formDefinition"; | ||
export let index: number; | ||
export let source: string = "fixed"; | ||
export let folder: string | undefined; | ||
export let options: EditableInput["options"] = []; | ||
export let notifyChange: () => void; | ||
$: id = `builder_select_${index}`; | ||
$: options_id = `builder_select_options_btn_${index}`; | ||
</script> | ||
|
||
<FormRow label="Source" {id}> | ||
<select bind:value={source} {id}> | ||
<option value="fixed">Static</option> | ||
<option value="notes">Notes</option> | ||
</select> | ||
</FormRow> | ||
{#if source === "fixed"} | ||
<FormRow label="Options" id={options_id}> | ||
<button | ||
type="button" | ||
on:click={() => { | ||
options?.push({ value: "", label: "" }); | ||
options = options; | ||
notifyChange(); | ||
}}>Add more options</button | ||
> | ||
{#each options || [] as option, idx} | ||
{@const value_id = `${options_id}_option_${idx}`} | ||
{@const label_id = `${options_id}_option_label_${idx}`} | ||
<div class="modal-form flex row gap1"> | ||
<FormRow label="Label" id={label_id}> | ||
<input | ||
type="text" | ||
placeholder="Label" | ||
bind:value={option.label} | ||
id={label_id} | ||
/></FormRow | ||
><FormRow label="Value" id={value_id}> | ||
<input | ||
type="text" | ||
placeholder="Value" | ||
bind:value={option.value} | ||
id={value_id} | ||
/></FormRow | ||
> | ||
|
||
<FormRow | ||
label="Delete" | ||
id={"button" + value_id} | ||
hideLabel={true} | ||
> | ||
<button | ||
id={"button" + value_id} | ||
use:setIcon={"trash"} | ||
type="button" | ||
on:click={() => { | ||
options = options?.filter((_, i) => i !== idx); | ||
notifyChange(); | ||
}} | ||
/></FormRow | ||
> | ||
</div> | ||
{/each} | ||
</FormRow> | ||
{:else if source === "notes"} | ||
<InputFolder {index} bind:folder {notifyChange} /> | ||
{/if} | ||
|
||
<style> | ||
</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,35 @@ | ||
<script lang="ts"> | ||
import { Setting } from "obsidian"; | ||
import { FolderSuggest } from "src/suggesters/suggestFolder"; | ||
/** | ||
* This component is just to select a folder, not notes inside the folder | ||
*/ | ||
export let index: number; | ||
export let folder: string = ""; | ||
// This is just used to notify the parent component that the value has changed | ||
// it is useful for example to persis the intermediary state of the form | ||
export let notifyChange: () => void; | ||
function searchFolder(element: HTMLElement) { | ||
new Setting(element).addSearch((search) => { | ||
search.setPlaceholder("Select a folder"); | ||
search.setValue(folder); | ||
new FolderSuggest(search.inputEl, app); | ||
search.onChange((value) => { | ||
folder = value; | ||
notifyChange(); | ||
}); | ||
}); | ||
} | ||
$: id = `dataview_${index}`; | ||
</script> | ||
|
||
<!-- The autocomplete input will be inside the first div, so we remove some styles with the utility classes --> | ||
<div | ||
class="modal-form flex column gap1 remove-padding remove-border fix-suggest" | ||
use:searchFolder | ||
> | ||
<label for={id}>Source Folder</label> | ||
</div> | ||
|
||
<style> | ||
</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