Skip to content

Commit

Permalink
fix(Radio): class is reactive including child components
Browse files Browse the repository at this point in the history
  • Loading branch information
Craig Howell authored and Craig Howell committed Oct 12, 2022
1 parent f79255e commit 24ada7d
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/lib/components/radio/Description.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
const { id }: { id: string } = getContext(RADIO_GROUP_RADIO_CONTEXT_ID);
const defaultClass = 'text-light-secondary-content dark:text-dark-secondary-content';
const finalClass = twMerge(defaultClass, $$props.class);
$: finalClass = twMerge(defaultClass, $$props.class);
</script>

<span id={id ? `${id}-description` : undefined} class={finalClass} style={$$props.style}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/radio/GroupLabel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
const defaultClass =
'text-light-secondary-content dark:text-dark-secondary-content font-medium text-sm';
const finalClass = twMerge(defaultClass, $$props.class);
$: finalClass = twMerge(defaultClass, $$props.class);
</script>

<legend for={name} class={finalClass} style={$$props.style}><slot /></legend>
2 changes: 1 addition & 1 deletion src/lib/components/radio/Label.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
const { id }: { id: string } = getContext(RADIO_GROUP_RADIO_CONTEXT_ID);
const defaultClass = 'font-medium cursor-pointer text-light-content dark:text-dark-content';
const finalClass = twMerge(defaultClass, $$props.class);
$: finalClass = twMerge(defaultClass, $$props.class);
</script>

<label for={id ? id : undefined} class={finalClass} style={$$props.style}><slot /></label>
10 changes: 6 additions & 4 deletions src/lib/components/radio/Radio.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@
$selected = value;
}
let defaultClass =
'radio bg-light-surface dark:bg-dark-surface text-light-surface dark:text-dark-surface light-border dark:dark-border checked:bg-none border checked:border-primary group-hover:border-primary dark:checked:border-primary dark:group-hover:border-primary group-focus:border-primary dark:group-focus:border-primary active:border-primary dark:active:border-primary focus:active:border-primary dark:focus:active:border-primary rounded-full cursor-pointer h-6 w-6';
if (type === 'pill') {
let defaultClass = '';
if (type === 'default') {
defaultClass =
'radio bg-light-surface dark:bg-dark-surface text-light-surface dark:text-dark-surface light-border dark:dark-border checked:bg-none border checked:border-primary group-hover:border-primary dark:checked:border-primary dark:group-hover:border-primary group-focus:border-primary dark:group-focus:border-primary active:border-primary dark:active:border-primary focus:active:border-primary dark:focus:active:border-primary rounded-full cursor-pointer h-6 w-6';
} else if (type === 'pill') {
defaultClass =
'group relative border light-border dark:dark-border rounded-md py-3 px-3 flex items-center justify-center text-sm font-medium sm:flex-1 cursor-pointer focus:outline-none';
}
const finalClass = twMerge(defaultClass, $$props.class);
$: finalClass = twMerge(defaultClass, $$props.class);
</script>

{#if type === 'default'}
Expand Down
6 changes: 3 additions & 3 deletions src/lib/components/radio/RadioGroup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
let defaultClass = 'mt-1 grid-cols-4 gap-2';
if (type === 'default') {
defaultClass += ' space-y-4';
defaultClass = defaultClass + ' space-y-4';
} else if (type === 'pill') {
defaultClass += ' grid';
defaultClass = defaultClass + ' grid';
}
const finalClass = twMerge(defaultClass, $$props.class);
$: finalClass = twMerge(defaultClass, $$props.class);
</script>

<div>
Expand Down

0 comments on commit 24ada7d

Please sign in to comment.