fix ui components svelte 5 compatibility

This commit is contained in:
Justin Edmund 2025-09-16 20:10:04 -07:00
parent cc46a695d5
commit 1c5caccf5e
5 changed files with 325 additions and 326 deletions

View file

@ -1,3 +1,4 @@
@use 'sass:color';
@use 'themes/spacing'; @use 'themes/spacing';
@use 'themes/mixins'; @use 'themes/mixins';
@use 'themes/colors'; @use 'themes/colors';
@ -18,7 +19,9 @@
gap: 6px; gap: 6px;
transition: 0.18s opacity ease-in-out; transition: 0.18s opacity ease-in-out;
user-select: none; user-select: none;
transition: background-color 0.18s ease-out, color 0.18s ease-out; transition:
background-color 0.18s ease-out,
color 0.18s ease-out;
cursor: pointer; cursor: pointer;
outline: none; outline: none;
position: relative; position: relative;
@ -148,11 +151,11 @@
} }
&:hover { &:hover {
color: darken(colors.$save-red, 30); color: color.adjust(colors.$save-red, $lightness: -30%);
.accessory svg { .accessory svg {
fill: darken(colors.$save-red, 30); fill: color.adjust(colors.$save-red, $lightness: -30%);
stroke: darken(colors.$save-red, 30); stroke: color.adjust(colors.$save-red, $lightness: -30%);
} }
} }
} }
@ -178,7 +181,7 @@
color: white; color: white;
&:hover:not(:disabled) { &:hover:not(:disabled) {
background: darken(colors.$error, 15); background: color.adjust(colors.$error, $lightness: -15%);
} }
@include mixins.breakpoint(phone) { @include mixins.breakpoint(phone) {
@ -209,7 +212,7 @@
color: colors.$error; color: colors.$error;
&:hover:not(:disabled) { &:hover:not(:disabled) {
color: darken(colors.$error, 10); color: color.adjust(colors.$error, $lightness: -10%);
} }
} }
} }

View file

@ -1,8 +1,8 @@
<!-- Checkbox Component --> <!-- Checkbox Component -->
<svelte:options runes={true} />
<script lang="ts"> <script lang="ts">
import { Checkbox as CheckboxPrimitive } from 'bits-ui'; import { Checkbox as CheckboxPrimitive } from 'bits-ui';
import { Check, Minus } from 'lucide-svelte'; import { Check, Minus } from 'lucide-svelte';
import { cn } from '$lib/utils.js';
import styles from './checkbox.module.scss'; import styles from './checkbox.module.scss';
import type { HTMLButtonAttributes } from 'svelte/elements'; import type { HTMLButtonAttributes } from 'svelte/elements';
@ -31,9 +31,11 @@
...restProps ...restProps
}: Props = $props(); }: Props = $props();
$: if (onCheckedChange && checked !== undefined) { $effect(() => {
if (onCheckedChange && checked !== undefined) {
onCheckedChange(checked); onCheckedChange(checked);
} }
});
const sizeClasses = { const sizeClasses = {
small: styles.small, small: styles.small,
@ -53,12 +55,7 @@
{required} {required}
{name} {name}
{value} {value}
class={cn( class={`${styles.checkbox} ${sizeClasses[size]} ${variantClasses[variant]} ${className || ''}`}
styles.checkbox,
sizeClasses[size],
variantClasses[variant],
className
)}
{...restProps} {...restProps}
> >
<CheckboxPrimitive.Indicator class={styles.indicator}> <CheckboxPrimitive.Indicator class={styles.indicator}>

View file

@ -1,7 +1,7 @@
<!-- Segment Component --> <!-- Segment Component -->
<svelte:options runes={true} />
<script lang="ts"> <script lang="ts">
import { RadioGroup as RadioGroupPrimitive } from 'bits-ui'; import { RadioGroup as RadioGroupPrimitive } from 'bits-ui';
import { cn } from '$lib/utils.js';
import styles from './segment.module.scss'; import styles from './segment.module.scss';
import type { HTMLButtonAttributes } from 'svelte/elements'; import type { HTMLButtonAttributes } from 'svelte/elements';
@ -13,16 +13,20 @@
let { let {
value, value,
class: className, class: className,
children, children: content,
...restProps ...restProps
}: Props = $props(); }: Props = $props();
</script> </script>
<RadioGroupPrimitive.Item <RadioGroupPrimitive.Item
{value} {value}
class={cn(styles.segment, className)} class={`${styles.segment} ${className || ''}`}
{...restProps} {...restProps}
> >
<RadioGroupPrimitive.ItemIndicator class={styles.indicator} /> {#snippet children({ checked })}
<span class={styles.label}>{children}</span> {#if checked}
<div class={styles.indicator}></div>
{/if}
<span class={styles.label}>{@render content?.()}</span>
{/snippet}
</RadioGroupPrimitive.Item> </RadioGroupPrimitive.Item>

View file

@ -1,7 +1,7 @@
<!-- SegmentedControl Component --> <!-- SegmentedControl Component -->
<svelte:options runes={true} />
<script lang="ts"> <script lang="ts">
import { RadioGroup as RadioGroupPrimitive } from 'bits-ui'; import { RadioGroup as RadioGroupPrimitive } from 'bits-ui';
import { cn } from '$lib/utils.js';
import styles from './segmented-control.module.scss'; import styles from './segmented-control.module.scss';
import type { HTMLDivAttributes } from 'svelte/elements'; import type { HTMLDivAttributes } from 'svelte/elements';
@ -29,9 +29,11 @@
...restProps ...restProps
}: Props = $props(); }: Props = $props();
$: if (onValueChange && value !== undefined) { $effect(() => {
if (onValueChange && value !== undefined) {
onValueChange(value); onValueChange(value);
} }
});
const variantClasses = { const variantClasses = {
default: '', default: '',
@ -49,21 +51,12 @@
}; };
</script> </script>
<div class={cn(styles.wrapper, wrapperClass)}> <div class={`${styles.wrapper} ${wrapperClass || ''}`}>
<RadioGroupPrimitive.Root <RadioGroupPrimitive.Root
bind:value bind:value
class={cn( class={`${styles.segmentedControl} ${variantClasses[variant]} ${element ? elementClasses[element] : ''} ${grow ? styles.grow : ''} ${gap ? styles.gap : ''} ${className || ''}`}
styles.segmentedControl,
variantClasses[variant],
element && elementClasses[element],
{
[styles.grow]: grow,
[styles.gap]: gap
},
className
)}
{...restProps} {...restProps}
> >
{children} {@render children?.()}
</RadioGroupPrimitive.Root> </RadioGroupPrimitive.Root>
</div> </div>

View file

@ -1,7 +1,7 @@
<!-- Switch Component --> <!-- Switch Component -->
<svelte:options runes={true} />
<script lang="ts"> <script lang="ts">
import { Switch as SwitchPrimitive } from 'bits-ui'; import { Switch as SwitchPrimitive } from 'bits-ui';
import { cn } from '$lib/utils.js';
import styles from './switch.module.scss'; import styles from './switch.module.scss';
import type { HTMLButtonAttributes } from 'svelte/elements'; import type { HTMLButtonAttributes } from 'svelte/elements';
@ -28,9 +28,11 @@
...restProps ...restProps
}: Props = $props(); }: Props = $props();
$: if (onCheckedChange && checked !== undefined) { $effect(() => {
if (onCheckedChange && checked !== undefined) {
onCheckedChange(checked); onCheckedChange(checked);
} }
});
</script> </script>
<SwitchPrimitive.Root <SwitchPrimitive.Root
@ -39,8 +41,8 @@
{required} {required}
{name} {name}
{value} {value}
class={cn(styles.switch, className)} class={`${styles.switch} ${className || ''}`}
{...restProps} {...restProps}
> >
<SwitchPrimitive.Thumb class={cn(styles.thumb, thumbClass)} /> <SwitchPrimitive.Thumb class={`${styles.thumb} ${thumbClass || ''}`} />
</SwitchPrimitive.Root> </SwitchPrimitive.Root>