Skip to content

Commit

Permalink
Add unround and external content options to ChipInput
Browse files Browse the repository at this point in the history
  • Loading branch information
laurakwhit committed Nov 6, 2024
1 parent ac78690 commit 0de2c30
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/lib/components/search-attribute-filter/list-filter.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
removeChipButtonLabel={(chip) =>
translate('workflows.remove-keyword-label', { keyword: chip })}
placeholder="{translate('common.type-or-paste-in')} {$filter.attribute}"
unroundLeft
unroundRight
external
/>
<div class="flex h-fit items-center">
<Button
Expand Down
4 changes: 4 additions & 0 deletions src/lib/holocene/input/chip-input.stories.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
placeholder: 'Placeholder...',
disabled: false,
required: false,
external: false,
hintText: 'This is the hint text...',
removeChipButtonLabel: 'Remove',
labelHidden: false,
Expand All @@ -25,6 +26,7 @@
hintText: { name: 'Hint Text', control: 'text' },
disabled: { name: 'Disabled', control: 'boolean' },
required: { name: 'Required', control: 'boolean' },
external: { name: 'External Content', control: 'boolean' },
labelHidden: { name: 'Label Hidden', control: 'boolean' },
chips: { name: 'Chips', table: { disable: true } },
validator: { table: { disable: true } },
Expand All @@ -47,6 +49,8 @@

<Story name="Default" />

<Story name="External Content" args={{ external: true }} />

<Story name="Disabled" args={{ disabled: true }} />

<Story name="Required" args={{ required: true }} />
Expand Down
31 changes: 30 additions & 1 deletion src/lib/holocene/input/chip-input.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
export let hintText = '';
export let validator: (value: string) => boolean = () => true;
export let removeChipButtonLabel: string | ((chipValue: string) => string);
export let unroundRight = false;
export let unroundLeft = false;
export let external = false;
const values = writable<string[]>(chips);
let displayValue = '';
let shouldScrollToInput = false;
Expand Down Expand Up @@ -111,8 +115,10 @@
disabled && 'cursor-not-allowed opacity-65',
invalid && 'invalid',
)}
class:unroundLeft
class:unroundRight
>
{#if $values.length > 0}
{#if $values.length > 0 && !external}
{#each $values as chip, i (`${chip}-${i}`)}
{@const valid = validator(chip)}
<Chip
Expand Down Expand Up @@ -149,6 +155,21 @@
{hintText}
</span>
{/if}
{#if $values.length > 0 && external}
<div class="mt-1 flex flex-row flex-wrap gap-1">
{#each $values as chip, i (`${chip}-${i}`)}
{@const valid = validator(chip)}
<Chip
removeButtonLabel={typeof removeChipButtonLabel === 'string'
? removeChipButtonLabel
: removeChipButtonLabel(chip)}
on:remove={() => removeChip(i)}
intent={valid ? 'default' : 'warning'}
{disabled}>{chip}</Chip
>
{/each}
</div>
{/if}
</div>

<style lang="postcss">
Expand All @@ -164,6 +185,14 @@
@apply surface-primary inline-block w-full focus:outline-none;
}
.unroundRight {
@apply rounded-br-none rounded-tr-none border-r-0;
}
.unroundLeft {
@apply rounded-bl-none rounded-tl-none border-l-0;
}
.hint {
@apply text-xs text-danger;
}
Expand Down

0 comments on commit 0de2c30

Please sign in to comment.