refactor: update Button to always use a size, determine tag from url

This commit is contained in:
2023-06-11 21:28:47 +02:00
parent 1360b095be
commit 9c329b5ff7
10 changed files with 37 additions and 25 deletions

View File

@@ -6,22 +6,23 @@
import { cx } from 'classix' import { cx } from 'classix'
import SplitText from '$components/SplitText.svelte' import SplitText from '$components/SplitText.svelte'
export let tag = 'a'
export let text: string export let text: string
export let url: string = undefined export let url: string = undefined
export let color: string = undefined export let color: string = undefined
export let size: string = undefined export let size: 'xsmall' | 'small' | 'medium' | 'large'
export let effect = 'link-3d' export let effect = 'link-3d'
export let disabled: boolean = undefined export let disabled: boolean = undefined
export let slotPosition = 'before' export let slotPosition = 'before'
const className = 'button' let tag: 'a' | 'button'
$: tag = url ? 'a' : 'button'
$: classes = cx( $: classes = cx(
className, 'button',
effect ? effect : undefined, effect ? effect : undefined,
...[color, size].map(variant => variant && `${className}--${variant}`), ...[color, size].map(variant => variant && `button--${variant}`),
Object.keys($$slots).length !== 0 ? `has-icon-${slotPosition}` : undefined, Object.keys($$slots).length !== 0 ? `has-icon-${slotPosition}` : undefined,
$$props.class $$props.class,
) )
// Define external links // Define external links

View File

@@ -78,7 +78,7 @@
<dd class="text-info">{shopProduct.name} {shopProduct.price}</dd> <dd class="text-info">{shopProduct.name} {shopProduct.price}</dd>
</dl> </dl>
<Button <Button
tag="button" size="medium"
text={hasStock ? 'Add to cart' : 'Sold out'} text={hasStock ? 'Add to cart' : 'Sold out'}
color="pinklight" color="pinklight"
disabled={!hasStock} disabled={!hasStock}

View File

@@ -40,7 +40,6 @@
on:click={() => $smoothScroll.scrollTo('#poster', { duration: 2 })} on:click={() => $smoothScroll.scrollTo('#poster', { duration: 2 })}
/> />
<Button <Button
tag="button"
size="xsmall" size="xsmall"
text="Add to cart" text="Add to cart"
color="pink" color="pink"

View File

@@ -136,10 +136,10 @@
{#if $cartData && $cartAmount > 0 && $cartData.checkout_url} {#if $cartData && $cartAmount > 0 && $cartData.checkout_url}
<div transition:fly={{ y: 8, duration: 600, easing: quartOut }}> <div transition:fly={{ y: 8, duration: 600, easing: quartOut }}>
<Button <Button
size="small"
url={$cartData && $cartData.checkout_url} url={$cartData && $cartData.checkout_url}
text="Checkout" text="Checkout"
color="pink" color="pink"
size="small"
on:click={() => sendEvent('cartCheckout', { props: { amount: $cartAmount } })} on:click={() => sendEvent('cartCheckout', { props: { amount: $cartAmount } })}
/> />
</div> </div>

View File

@@ -49,7 +49,8 @@
{#each continents as { name, slug }} {#each continents as { name, slug }}
<li class:is-active={currentContinent === slug}> <li class:is-active={currentContinent === slug}>
<Button <Button
tag="button" text={name} size="small" size="small"
text={name}
slotPosition="after" slotPosition="after"
class={'is-disabled'} class={'is-disabled'}
on:click={() => { on:click={() => {

View File

@@ -83,7 +83,7 @@
<h2 class="title-medium">{title}</h2> <h2 class="title-medium">{title}</h2>
<p class="text-small">{text}</p> <p class="text-small">{text}</p>
{#if enabled} {#if enabled}
<Button {url} text={buttonText} color="pinklight" /> <Button size="medium" {url} text={buttonText} color="pinklight" />
{/if} {/if}
{#if textBottom} {#if textBottom}
<p class="detail">{textBottom}</p> <p class="detail">{textBottom}</p>

View File

@@ -258,12 +258,12 @@
</div> </div>
<div class="ctas"> <div class="ctas">
<Button url="/locations" text="Change location" class="shadow-small"> <Button size="medium" url="/locations" text="Change location" class="shadow-small">
<IconEarth /> <IconEarth />
</Button> </Button>
{#if location.has_poster} {#if location.has_poster}
<Button url="/shop/poster-{location.slug}" text="Buy the poster" color="pinklight" class="shadow-small"> <Button size="medium" url="/shop/poster-{location.slug}" text="Buy the poster" color="pinklight" class="shadow-small">
<!-- <IconEarth /> --> <!-- <IconEarth /> -->
</Button> </Button>
{/if} {/if}

View File

@@ -464,9 +464,9 @@
</p> </p>
<Button <Button
tag="button" size="large"
color="beige"
text={!ended ? 'See more photos' : "You've seen it all!"} text={!ended ? 'See more photos' : "You've seen it all!"}
size="large" color="beige"
on:click={loadMorePhotos} on:click={loadMorePhotos}
disabled={ended} disabled={ended}
/> />

View File

@@ -104,7 +104,12 @@
{settings.description} {settings.description}
</p> </p>
<Button url="#locations" text="Explore locations" on:click={() => $smoothScroll.scrollTo('#locations', { duration: 2 })}> <Button
size="medium"
url="#locations"
text="Explore locations"
on:click={() => $smoothScroll.scrollTo('#locations', { duration: 2 })}
>
<IconEarth animate={true} /> <IconEarth animate={true} />
</Button> </Button>
</div> </div>

View File

@@ -1,10 +1,10 @@
.button { .button {
display: inline-flex; display: inline-flex;
align-items: center; align-items: center;
height: 40px;
padding: 0 16px;
background: #fff; background: #fff;
font: 900 #{rem(16px)}/1 $font-sans; font-weight: 900;
line-height: 1;
font-family: $font-sans;
color: $color-text; color: $color-text;
cursor: pointer; cursor: pointer;
border-radius: 100vh; border-radius: 100vh;
@@ -12,12 +12,6 @@
text-decoration: none; text-decoration: none;
transition: background-color 0.55s var(--ease-quart), color 0.55s var(--ease-quart); transition: background-color 0.55s var(--ease-quart), color 0.55s var(--ease-quart);
@include bp (md) {
height: 48px;
padding: 1px 24px 0;
font-size: rem(18px);
}
// Icon // Icon
:global(img), :global(svg) { :global(img), :global(svg) {
display: block; display: block;
@@ -68,6 +62,18 @@
} }
} }
// Medium
&--medium {
height: 40px;
padding: 0 16px;
font-size: rem(16px);
@include bp (md) {
height: 48px;
font-size: rem(18px);
}
}
// Large // Large
&--large { &--large {
height: 56px; height: 56px;