finish custom class and improved options overhaul

This commit is contained in:
Elijah Duffy
2025-07-03 14:45:23 -07:00
parent c54002f5fa
commit 02311a0e7b
16 changed files with 170 additions and 131 deletions

View File

@@ -1,39 +1,13 @@
<script lang="ts" module>
export type RadioGroupOption =
| {
value: string;
label?: string;
}
| string;
/** getLabel returns the option label if it exists*/
const getLabel = (option: RadioGroupOption): string => {
if (typeof option === 'string') {
return option;
} else {
return option.label ?? option.value;
}
};
/** getValue returns the option value */
const getValue = (option: RadioGroupOption): string => {
if (typeof option === 'string') {
return option;
} else {
return option.value;
}
};
</script>
<script lang="ts">
import { RadioGroup, type RadioGroupProps } from 'melt/builders';
import type { ClassValue } from 'svelte/elements';
import { scale } from 'svelte/transition';
import Label from './Label.svelte';
import { validate } from '@svelte-toolkit/validate';
import { getLabel, getValue, type Option } from './util.js';
interface Props extends RadioGroupProps {
options: RadioGroupOption[];
options: Option[];
label?: string;
required?: boolean;
invalidMessage?: string;