Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/techniq/svelte-ux
Browse files Browse the repository at this point in the history
  • Loading branch information
techniq committed May 7, 2024
2 parents b752d6e + 3ad0d41 commit b8284ad
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 4 deletions.
6 changes: 6 additions & 0 deletions packages/svelte-ux/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# svelte-ux

## 0.62.12

### Patch Changes

- [Field] Support passing `value` for simple display with handling of empty (null/undefined) with custom placeholder ([#339](https://github.com/techniq/svelte-ux/pull/339))

## 0.62.11

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/svelte-ux/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"author": "Sean Lynch <techniq35@gmail.com>",
"license": "MIT",
"repository": "techniq/svelte-ux",
"version": "0.62.11",
"version": "0.62.12",
"scripts": {
"dev": "vite dev",
"build": "vite build",
Expand Down
14 changes: 12 additions & 2 deletions packages/svelte-ux/src/lib/components/Field.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
export let label = '';
export let labelPlacement: LabelPlacement = defaults.labelPlacement ?? DEFAULT_LABEL_PLACEMENT;
export let value: any = null;
// export let placeholder = '';
export let placeholder = '';
export let error: string | string[] | boolean | undefined = '';
export let hint = '';
// export let autocomplete = 'off'; // https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete
Expand Down Expand Up @@ -156,7 +156,17 @@
>
<slot name="prefix" />

<slot {id} />
<slot {id}>
{#if value}
{value}
{:else if placeholder}
<span class="text-surface-content/50">
{placeholder}
</span>
{:else}
&nbsp
{/if}
</slot>

<slot name="suffix" />
</div>
Expand Down
29 changes: 28 additions & 1 deletion packages/svelte-ux/src/routes/docs/components/Field/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,16 @@

<h1>Examples</h1>

<h2>Text (display only)</h2>
<h2>Text (display only) as value</h2>

<Preview>
<div class="grid grid-flow-col gap-2">
<Field label="First Name" value="Sean" />
<Field label="Last Name" value="Lynch" />
</div>
</Preview>

<h2>Text (display only) as slot</h2>

<Preview>
<div class="grid grid-flow-col gap-2">
Expand All @@ -30,6 +39,24 @@
</div>
</Preview>

<h2>Empty (null / undefined)</h2>

<Preview>
<div class="grid grid-flow-col gap-2">
<Field label="First name" value={null} />
<Field label="Last name" value={undefined} />
</div>
</Preview>

<h2>Placeholder</h2>

<Preview>
<div class="grid grid-flow-col gap-2">
<Field label="First name" value={null} placeholder="empty" />
<Field label="Last name" value={undefined} placeholder="empty" />
</div>
</Preview>

<h2>Switch</h2>

<Preview>
Expand Down

0 comments on commit b8284ad

Please sign in to comment.