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>
img {
width: 22px;
margin-right: 6px;
}
div {
font-size: var(--font-size-l);

View File

@ -25,10 +25,10 @@
<span>
<Checkbox {disabled} {value} />
</span>
{#if text}
{text}
{/if}
<div>
<div class="text">
{#if text}
{text}
{/if}
<slot />
</div>
</FancyField>
@ -37,4 +37,16 @@
span {
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>

View File

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

View File

@ -1,6 +1,7 @@
<script>
import { createEventDispatcher } from "svelte"
import FancyField from "./FancyField.svelte"
import FancyFieldLabel from "./FancyFieldLabel.svelte"
export let label
export let value
@ -26,9 +27,7 @@
<FancyField {error} {value} {validate} {disabled} {focused}>
{#if label}
<div class="label" class:placeholder>
{label}
</div>
<FancyFieldLabel {placeholder}>{label}</FancyFieldLabel>
{/if}
<input
{disabled}
@ -42,19 +41,6 @@
</FancyField>
<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 {
width: 100%;
transition: transform 130ms ease-out;

View File

@ -3,6 +3,7 @@
import FancyField from "./FancyField.svelte"
import Icon from "../Icon/Icon.svelte"
import Popover from "../Popover/Popover.svelte"
import FancyFieldLabel from "./FancyFieldLabel.svelte"
export let label
export let value
@ -38,88 +39,59 @@
}
</script>
<div bind:this={wrapper}>
<FancyField
{error}
{value}
{validate}
{disabled}
clickable
on:click={() => (open = true)}
>
{#if label}
<div class="label" class:placeholder>
{label}
</div>
<FancyField
bind:ref={wrapper}
{error}
{value}
{validate}
{disabled}
clickable
on:click={() => (open = true)}
>
{#if label}
<FancyFieldLabel {placeholder}>{label}</FancyFieldLabel>
{/if}
<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}
<div class="value" class:placeholder>
{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>
</div>
</Popover>
<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 {
display: block;
flex: 1 1 auto;
@ -128,6 +100,10 @@
color: var(--spectrum-global-color-gray-900);
transition: margin-top 130ms ease-out, opacity 130ms ease-out;
opacity: 1;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
width: 0;
}
.value.placeholder {
opacity: 0;
@ -139,15 +115,16 @@
flex-direction: column;
justify-content: flex-start;
align-items: stretch;
padding: 10px 0;
padding: 7px 0;
}
.popover-option {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
padding: 7px 12px;
padding: 7px 16px;
transition: background 130ms ease-out;
font-size: 15px;
}
.popover-option:hover {
background: var(--spectrum-global-color-gray-200);