refactor: use classic for conditional classes
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@studio-freight/lenis": "^1.0.14",
|
"@studio-freight/lenis": "^1.0.14",
|
||||||
|
"classix": "^2.1.32",
|
||||||
"dayjs": "^1.11.8",
|
"dayjs": "^1.11.8",
|
||||||
"embla-carousel": "^7.1.0",
|
"embla-carousel": "^7.1.0",
|
||||||
"focus-visible": "^5.2.0",
|
"focus-visible": "^5.2.0",
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { cx } from 'classix'
|
||||||
import { splitText } from 'utils/text'
|
import { splitText } from 'utils/text'
|
||||||
|
|
||||||
export let text: string
|
export let text: string
|
||||||
@@ -7,7 +8,10 @@
|
|||||||
|
|
||||||
$: split = splitText(text, mode)
|
$: split = splitText(text, mode)
|
||||||
|
|
||||||
const classes = ['text-split', $$props.class].join(' ').trim()
|
$: classes = cx(
|
||||||
|
'text-split',
|
||||||
|
$$props.class,
|
||||||
|
)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if clone}
|
{#if clone}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { cx } from 'classix'
|
||||||
import Image from './Image.svelte'
|
import Image from './Image.svelte'
|
||||||
|
|
||||||
export let id: string
|
export let id: string
|
||||||
@@ -8,11 +9,11 @@
|
|||||||
let hovering = false
|
let hovering = false
|
||||||
let timer: ReturnType<typeof setTimeout> | number = null
|
let timer: ReturnType<typeof setTimeout> | number = null
|
||||||
|
|
||||||
$: classes = [
|
$: classes = cx(
|
||||||
hovering ? 'is-hovered' : undefined,
|
hovering ? 'is-hovered' : undefined,
|
||||||
disabled ? 'is-disabled' : undefined,
|
disabled ? 'is-disabled' : undefined,
|
||||||
$$props.class
|
$$props.class
|
||||||
].join(' ').trim()
|
)
|
||||||
|
|
||||||
// Hovering functions
|
// Hovering functions
|
||||||
const handleMouseEnter = () => {
|
const handleMouseEnter = () => {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
</style>
|
</style>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { cx } from 'classix'
|
||||||
import SplitText from '$components/SplitText.svelte'
|
import SplitText from '$components/SplitText.svelte'
|
||||||
|
|
||||||
export let tag = 'a'
|
export let tag = 'a'
|
||||||
@@ -15,13 +16,13 @@
|
|||||||
export let slotPosition = 'before'
|
export let slotPosition = 'before'
|
||||||
|
|
||||||
const className = 'button'
|
const className = 'button'
|
||||||
const classes = [
|
$: classes = cx(
|
||||||
className,
|
className,
|
||||||
effect ? effect : undefined,
|
effect ? effect : undefined,
|
||||||
...[color, size].map(variant => variant && `${className}--${variant}`),
|
...[color, size].map(variant => variant && `${className}--${variant}`),
|
||||||
Object.keys($$slots).length !== 0 ? `has-icon-${slotPosition}` : undefined,
|
Object.keys($$slots).length !== 0 ? `has-icon-${slotPosition}` : undefined,
|
||||||
$$props.class
|
$$props.class
|
||||||
].join(' ').trim()
|
)
|
||||||
|
|
||||||
// Define external links
|
// Define external links
|
||||||
$: isExternal = /^(http|https):\/\//i.test(url)
|
$: isExternal = /^(http|https):\/\//i.test(url)
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
</style>
|
</style>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { cx } from 'classix'
|
||||||
|
|
||||||
export let tag = 'button'
|
export let tag = 'button'
|
||||||
export let url: string = undefined
|
export let url: string = undefined
|
||||||
export let color: string = undefined
|
export let color: string = undefined
|
||||||
@@ -13,12 +15,12 @@
|
|||||||
export let label: string = undefined
|
export let label: string = undefined
|
||||||
|
|
||||||
const className = 'button-circle'
|
const className = 'button-circle'
|
||||||
const classes = [
|
$: classes = cx(
|
||||||
className,
|
className,
|
||||||
...[color, size].map(variant => variant && `${className}--${variant}`),
|
...[color, size].map(variant => variant && `${className}--${variant}`),
|
||||||
clone ? 'has-clone' : null,
|
clone ? 'has-clone' : null,
|
||||||
$$props.class
|
$$props.class
|
||||||
].join(' ').trim()
|
)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if tag === 'a'}
|
{#if tag === 'a'}
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { cx } from 'classix'
|
||||||
|
|
||||||
export let icon: string
|
export let icon: string
|
||||||
export let label: string = undefined
|
export let label: string = undefined
|
||||||
|
|
||||||
const classes = [$$props.class].join(' ').trim()
|
$: classes = cx($$props.class)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svg class={classes} aria-label={label} width="32" height="32">
|
<svg class={classes} aria-label={label} width="32" height="32">
|
||||||
|
|||||||
@@ -7,9 +7,14 @@
|
|||||||
</style>
|
</style>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { cx } from 'classix'
|
||||||
|
|
||||||
export let animate = false
|
export let animate = false
|
||||||
|
|
||||||
const classes = ['icon-earth', $$props.class].join(' ').trim()
|
$: classes = cx(
|
||||||
|
'icon-earth',
|
||||||
|
$$props.class,
|
||||||
|
)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"
|
<svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
</style>
|
</style>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import cx from 'classix'
|
||||||
import { map } from 'utils/math'
|
import { map } from 'utils/math'
|
||||||
import reveal from '$animations/reveal'
|
import reveal from '$animations/reveal'
|
||||||
|
|
||||||
@@ -39,11 +40,11 @@
|
|||||||
parallax = isLarger ? map(scrollY, offsetStart, offsetEnd, 0, -toTranslate, true) : 0
|
parallax = isLarger ? map(scrollY, offsetStart, offsetEnd, 0, -toTranslate, true) : 0
|
||||||
}
|
}
|
||||||
|
|
||||||
const classes = [
|
$: classes = cx(
|
||||||
'scrolling-title',
|
'scrolling-title',
|
||||||
'title-huge',
|
'title-huge',
|
||||||
$$props.class
|
$$props.class
|
||||||
].join(' ').trim()
|
)
|
||||||
|
|
||||||
const revealOptions = animate ? {
|
const revealOptions = animate ? {
|
||||||
children: '.char',
|
children: '.char',
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
import { getContext } from 'svelte'
|
import { getContext } from 'svelte'
|
||||||
import { spring } from 'svelte/motion'
|
import { spring } from 'svelte/motion'
|
||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
|
import { cx } from 'classix'
|
||||||
import { lerp } from 'utils/math'
|
import { lerp } from 'utils/math'
|
||||||
import { PUBLIC_PREVIEW_COUNT } from '$env/static/public'
|
import { PUBLIC_PREVIEW_COUNT } from '$env/static/public'
|
||||||
import { seenLocations } from '$utils/stores'
|
import { seenLocations } from '$utils/stores'
|
||||||
@@ -110,7 +111,7 @@
|
|||||||
<div class="location__photos">
|
<div class="location__photos">
|
||||||
{#each location.photos as { image }, index}
|
{#each location.photos as { image }, index}
|
||||||
{#if image}
|
{#if image}
|
||||||
{@const classes = ['location__photo', index === photoIndex ? 'is-visible' : null].join(' ').trim()}
|
{@const classes = cx('location__photo', index === photoIndex && 'is-visible')}
|
||||||
<Image
|
<Image
|
||||||
class={classes}
|
class={classes}
|
||||||
id={image.id}
|
id={image.id}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
</style>
|
</style>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { cx } from 'classix'
|
||||||
import Image from '$components/atoms/Image.svelte'
|
import Image from '$components/atoms/Image.svelte'
|
||||||
|
|
||||||
export let street: string
|
export let street: string
|
||||||
@@ -13,11 +14,11 @@
|
|||||||
export let size: string = undefined
|
export let size: string = undefined
|
||||||
|
|
||||||
const className = 'postcard'
|
const className = 'postcard'
|
||||||
$: classes = [
|
$: classes = cx(
|
||||||
className,
|
className,
|
||||||
...[size].map(variant => variant && `${className}--${variant}`),
|
...[size].map(variant => variant && `${className}--${variant}`),
|
||||||
$$props.class
|
$$props.class
|
||||||
].join(' ').trim()
|
)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class={classes}>
|
<div class={classes}>
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { goto } from '$app/navigation'
|
import { goto } from '$app/navigation'
|
||||||
import { getContext, tick } from 'svelte'
|
import { getContext, tick } from 'svelte'
|
||||||
|
import { cx } from 'classix'
|
||||||
import { shopCurrentProductSlug } from '$utils/stores/shop'
|
import { shopCurrentProductSlug } from '$utils/stores/shop'
|
||||||
import { smoothScroll } from '$utils/stores'
|
import { smoothScroll } from '$utils/stores'
|
||||||
|
|
||||||
@@ -12,11 +13,11 @@
|
|||||||
|
|
||||||
const { shopLocations }: any = getContext('shop')
|
const { shopLocations }: any = getContext('shop')
|
||||||
|
|
||||||
const classes = [
|
const classes = cx(
|
||||||
'shop-locationswitcher',
|
'shop-locationswitcher',
|
||||||
isOver && 'is-over',
|
isOver && 'is-over',
|
||||||
$$props.class
|
$$props.class
|
||||||
].join(' ').trim()
|
)
|
||||||
|
|
||||||
|
|
||||||
// Quick location change
|
// Quick location change
|
||||||
|
|||||||
7
pnpm-lock.yaml
generated
7
pnpm-lock.yaml
generated
@@ -29,6 +29,9 @@ importers:
|
|||||||
'@studio-freight/lenis':
|
'@studio-freight/lenis':
|
||||||
specifier: ^1.0.14
|
specifier: ^1.0.14
|
||||||
version: 1.0.14
|
version: 1.0.14
|
||||||
|
classix:
|
||||||
|
specifier: ^2.1.32
|
||||||
|
version: 2.1.32
|
||||||
dayjs:
|
dayjs:
|
||||||
specifier: ^1.11.8
|
specifier: ^1.11.8
|
||||||
version: 1.11.8
|
version: 1.11.8
|
||||||
@@ -3940,6 +3943,10 @@ packages:
|
|||||||
resolution: {integrity: sha512-bIomtDF5KGpdogkLd9VspvFzk9KfpyyGlS8YFVZl7TGPBHL5snIOnxeshwVgPteQ9b4Eydl+pVbIyE1DcvCWgQ==}
|
resolution: {integrity: sha512-bIomtDF5KGpdogkLd9VspvFzk9KfpyyGlS8YFVZl7TGPBHL5snIOnxeshwVgPteQ9b4Eydl+pVbIyE1DcvCWgQ==}
|
||||||
engines: {node: '>=10'}
|
engines: {node: '>=10'}
|
||||||
|
|
||||||
|
/classix@2.1.32:
|
||||||
|
resolution: {integrity: sha512-E08TD9XlszvcuOzEQJnjQEibqQp6qJH5idbjh8l5pWDV2poJwk0Gexcra0ZdMITUuqAveHju4A9B/HKk1pk7sA==}
|
||||||
|
dev: false
|
||||||
|
|
||||||
/clean-stack@2.2.0:
|
/clean-stack@2.2.0:
|
||||||
resolution: {integrity: sha512-4diC9HaTE+KRAMWhDhrGOECgWZxoevMc5TlkObMqNSsVU62PYzXZ/SMTjzyGAFF1YusgxGcSWTEXBhp0CPwQ1A==}
|
resolution: {integrity: sha512-4diC9HaTE+KRAMWhDhrGOECgWZxoevMc5TlkObMqNSsVU62PYzXZ/SMTjzyGAFF1YusgxGcSWTEXBhp0CPwQ1A==}
|
||||||
engines: {node: '>=6'}
|
engines: {node: '>=6'}
|
||||||
|
|||||||
Reference in New Issue
Block a user