Update fancy components and fix select rounded corners

This commit is contained in:
Andrew Kingston 2023-01-18 14:48:04 +00:00
parent f60db08765
commit 107af4205a
7 changed files with 107 additions and 106 deletions

View File

@ -22,7 +22,6 @@
<style> <style>
img { img {
width: 22px; width: 22px;
margin-right: 6px;
} }
div { div {
font-size: var(--font-size-l); font-size: var(--font-size-l);

View File

@ -25,10 +25,10 @@
<span> <span>
<Checkbox {disabled} {value} /> <Checkbox {disabled} {value} />
</span> </span>
{#if text} <div class="text">
{text} {#if text}
{/if} {text}
<div> {/if}
<slot /> <slot />
</div> </div>
</FancyField> </FancyField>
@ -37,4 +37,16 @@
span { span {
pointer-events: none; pointer-events: none;
} }
.text {
font-size: 15px;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 2;
line-clamp: 2;
-webkit-box-orient: vertical;
}
.text > :global(*) {
font-size: inherit !important;
}
</style> </style>

View File

@ -1,6 +1,7 @@
<script> <script>
import Icon from "../Icon/Icon.svelte" import Icon from "../Icon/Icon.svelte"
import { getContext, onMount } from "svelte" import { getContext, onMount } from "svelte"
import { slide } from "svelte/transition"
export let disabled = false export let disabled = false
export let error = null export let error = null
@ -8,6 +9,7 @@
export let clickable = false export let clickable = false
export let validate export let validate
export let value export let value
export let ref
const formContext = getContext("fancy-form") const formContext = getContext("fancy-form")
const id = Math.random() const id = Math.random()
@ -33,6 +35,7 @@
</script> </script>
<div <div
bind:this={ref}
class="fancy-field" class="fancy-field"
class:error class:error
class:disabled class:disabled
@ -50,7 +53,7 @@
{/if} {/if}
</div> </div>
{#if error} {#if error}
<div class="error-message"> <div transition:slide|local={{ duration: 130 }} class="error-message">
{error} {error}
</div> </div>
{/if} {/if}
@ -97,7 +100,7 @@
flex-direction: row; flex-direction: row;
justify-content: flex-start; justify-content: flex-start;
align-items: center; align-items: center;
gap: 10px; gap: 16px;
} }
.field { .field {
flex: 1 1 auto; flex: 1 1 auto;

View File

@ -0,0 +1,24 @@
<script>
export let placeholder = true
</script>
<div class:placeholder>
<slot />
</div>
<style>
div {
font-size: 14px;
font-weight: 500;
transform: translateY(-50%);
position: absolute;
top: 18px;
color: var(--spectrum-global-color-gray-600);
transition: font-size 130ms ease-out, top 130ms ease-out;
}
div.placeholder {
top: 50%;
font-size: 15px;
transform: translateY(-50%);
}
</style>

View File

@ -29,11 +29,11 @@
</div> </div>
<style> <style>
.fancy-form :global(.fancy-field:not(:first-child)) { .fancy-form :global(.fancy-field:not(:first-of-type)) {
border-top-left-radius: 0; border-top-left-radius: 0;
border-top-right-radius: 0; border-top-right-radius: 0;
} }
.fancy-form :global(.fancy-field:not(:last-child)) { .fancy-form :global(.fancy-field:not(:last-of-type)) {
border-bottom-left-radius: 0; border-bottom-left-radius: 0;
border-bottom-right-radius: 0; border-bottom-right-radius: 0;
} }

View File

@ -1,6 +1,7 @@
<script> <script>
import { createEventDispatcher } from "svelte" import { createEventDispatcher } from "svelte"
import FancyField from "./FancyField.svelte" import FancyField from "./FancyField.svelte"
import FancyFieldLabel from "./FancyFieldLabel.svelte"
export let label export let label
export let value export let value
@ -26,9 +27,7 @@
<FancyField {error} {value} {validate} {disabled} {focused}> <FancyField {error} {value} {validate} {disabled} {focused}>
{#if label} {#if label}
<div class="label" class:placeholder> <FancyFieldLabel {placeholder}>{label}</FancyFieldLabel>
{label}
</div>
{/if} {/if}
<input <input
{disabled} {disabled}
@ -42,19 +41,6 @@
</FancyField> </FancyField>
<style> <style>
.label {
font-size: 14px;
font-weight: 500;
transform: translateY(calc(-50% - 12px));
position: absolute;
top: 50%;
color: var(--spectrum-global-color-gray-600);
transition: font-size 130ms ease-out, transform 130ms ease-out;
}
.label.placeholder {
font-size: 15px;
transform: translateY(-50%);
}
input { input {
width: 100%; width: 100%;
transition: transform 130ms ease-out; transition: transform 130ms ease-out;

View File

@ -3,6 +3,7 @@
import FancyField from "./FancyField.svelte" import FancyField from "./FancyField.svelte"
import Icon from "../Icon/Icon.svelte" import Icon from "../Icon/Icon.svelte"
import Popover from "../Popover/Popover.svelte" import Popover from "../Popover/Popover.svelte"
import FancyFieldLabel from "./FancyFieldLabel.svelte"
export let label export let label
export let value export let value
@ -38,88 +39,59 @@
} }
</script> </script>
<div bind:this={wrapper}> <FancyField
<FancyField bind:ref={wrapper}
{error} {error}
{value} {value}
{validate} {validate}
{disabled} {disabled}
clickable clickable
on:click={() => (open = true)} on:click={() => (open = true)}
> >
{#if label} {#if label}
<div class="label" class:placeholder> <FancyFieldLabel {placeholder}>{label}</FancyFieldLabel>
{label} {/if}
</div>
<div class="value" class:placeholder>
{value || ""}
</div>
<div class="arrow">
<Icon name="ChevronDown" />
</div>
</FancyField>
<Popover
anchor={wrapper}
align="left"
portalTarget={document.documentElement}
bind:this={popover}
{open}
on:close={() => (open = false)}
useAnchorWidth={true}
maxWidth={null}
>
<div class="popover-content">
{#if options.length}
{#each options as option, idx}
<div
class="popover-option"
tabindex="0"
on:click={() => onChange(getOptionValue(option, idx))}
>
<span class="option-text">
{getOptionLabel(option, idx)}
</span>
{#if value === getOptionValue(option, idx)}
<Icon name="Checkmark" />
{/if}
</div>
{/each}
{/if} {/if}
</div>
<div class="value" class:placeholder> </Popover>
{value || ""}
</div>
<div class="arrow">
<Icon name="ChevronDown" />
</div>
</FancyField>
</div>
<svelte:head>
<script>
console.log("FOO")
</script>
</svelte:head>
<span>
<Popover
anchor={wrapper}
align="left"
portalTarget={document.documentElement}
bind:this={popover}
{open}
on:close={() => (open = false)}
useAnchorWidth={true}
maxWidth={null}
>
<div class="popover-content">
{#if options.length}
{#each options as option, idx}
<div
class="popover-option"
tabindex="0"
on:click={() => onChange(getOptionValue(option, idx))}
>
<span class="option-text">
{getOptionLabel(option, idx)}
</span>
{#if value === getOptionValue(option, idx)}
<Icon name="Checkmark" />
{/if}
</div>
{/each}
{/if}
</div>
</Popover>
</span>
<style> <style>
span :global(.spectrum-Popover) {
background: red !important;
}
.label {
font-size: 14px;
font-weight: 500;
transform: translateY(-50%);
position: absolute;
top: 18px;
color: var(--spectrum-global-color-gray-600);
transition: font-size 130ms ease-out, top 130ms ease-out;
}
.label.placeholder {
top: 50%;
font-size: 15px;
transform: translateY(-50%);
}
.value { .value {
display: block; display: block;
flex: 1 1 auto; flex: 1 1 auto;
@ -128,6 +100,10 @@
color: var(--spectrum-global-color-gray-900); color: var(--spectrum-global-color-gray-900);
transition: margin-top 130ms ease-out, opacity 130ms ease-out; transition: margin-top 130ms ease-out, opacity 130ms ease-out;
opacity: 1; opacity: 1;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
width: 0;
} }
.value.placeholder { .value.placeholder {
opacity: 0; opacity: 0;
@ -139,15 +115,16 @@
flex-direction: column; flex-direction: column;
justify-content: flex-start; justify-content: flex-start;
align-items: stretch; align-items: stretch;
padding: 10px 0; padding: 7px 0;
} }
.popover-option { .popover-option {
display: flex; display: flex;
flex-direction: row; flex-direction: row;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
padding: 7px 12px; padding: 7px 16px;
transition: background 130ms ease-out; transition: background 130ms ease-out;
font-size: 15px;
} }
.popover-option:hover { .popover-option:hover {
background: var(--spectrum-global-color-gray-200); background: var(--spectrum-global-color-gray-200);