Skip to content

Commit

Permalink
Merge pull request #237 from appwrite/feat-add-leading-html-to-select
Browse files Browse the repository at this point in the history
Feat add leading html to select
  • Loading branch information
ArmanNik authored Nov 14, 2024
2 parents e26f8e6 + cfb0880 commit 341f598
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
22 changes: 20 additions & 2 deletions v2/pink-sb/src/lib/input/Select.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
badge?: string;
leadingIcon?: ComponentType;
trailingIcon?: ComponentType;
leadingHtml?: string;
}>;
} & Partial<{
value: string | boolean | number | null;
Expand All @@ -35,6 +36,7 @@
export let readonly: $$Props['readonly'] = false;
const dispatch = createEventDispatcher();
let selectedLeadingHtml: undefined | string = undefined;
const {
elements: { trigger, menu, option },
Expand All @@ -55,6 +57,7 @@
portal: null,
onSelectedChange(event) {
value = event.next?.value;
selectedLeadingHtml = options.find((option) => option.value === value)?.leadingHtml;
dispatch('change', value);
return event.next;
}
Expand All @@ -76,14 +79,24 @@
disabled={disabled || readonly}
>
<span>
{$selectedLabel || placeholder}
{#if $selectedLabel}
{#if selectedLeadingHtml}
{@html selectedLeadingHtml}
{/if}
{$selectedLabel}
{:else}
{placeholder}
{/if}
</span>
<Icon size="m" icon={$open ? IconChevronUp : IconChevronDown} />
</button>
{#if $open}
<ul {...$menu} use:menu>
{#each options as { value, label, badge, disabled, readonly, leadingIcon, trailingIcon }}
{#each options as { value, label, badge, disabled, readonly, leadingIcon, trailingIcon, leadingHtml }}
<li {...$option({ value, label, disabled })} use:option>
{#if leadingHtml}
{@html leadingHtml}
{/if}
{#if leadingIcon}
<Icon size="s" icon={leadingIcon} />
{/if}
Expand All @@ -104,6 +117,11 @@
@use './input';
@use '../../scss/mixins/transitions';
button span {
display: flex;
gap: var(--space-3);
}
.input {
@include transitions.common;
@include input.wrapper;
Expand Down
4 changes: 3 additions & 1 deletion v2/pink-sb/src/stories/input/Select.stories.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
},
{
label: 'Option 3',
value: 'option3'
value: 'option3',
leadingHtml:
"<img src='https://cloud.appwrite.io/v1/avatars/flags/de?width=22&height=15' alt='Flag of Germany'/>"
},
{
label: 'Option 4',
Expand Down

0 comments on commit 341f598

Please sign in to comment.