-
Hey, another question around converting from the react tailwind ui samples to svelte. Specifically these few lines:
I have tried the following (with and without slot props
Full React code:
Any help is greatly appreciated :) |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
You need the For your snippet, you've actually changed too much. That classNames(
checked ? 'bg-sky-600 border-transparent' : 'bg-white border-gray-300',
active ? 'ring-2 ring-offset-2 ring-sky-500' : '',
'h-4 w-4 mt-0.5 cursor-pointer rounded-full border flex items-center justify-center'
) evaluates to a string. |
Beta Was this translation helpful? Give feedback.
-
I'd do it like this: <RadioGroup value={selected} on:change={handleSelectChange}>
<RadioGroupLabel class="text-sm font-medium text-gray-900">Privacy</RadioGroupLabel>
<div class="mt-1 bg-white rounded-md shadow-sm -space-y-px">
{#each settings as setting, index (setting.name)}
<RadioGroupOption
let:checked
let:active
key={setting.name}
value={setting}
class={({ checked }) => {
return classNames(
index === 0 ? 'rounded-tl-md rounded-tr-md' : '',
index === settings.length - 1 ? 'rounded-bl-md rounded-br-md' : '',
checked ? 'bg-sky-50 border-sky-200' : 'border-gray-200',
'relative border p-4 flex cursor-pointer focus:outline-none'
);
}}
>
<span
class={classNames(
checked ? 'bg-sky-600 border-transparent' : 'bg-white border-gray-300',
active ? 'ring-2 ring-offset-2 ring-sky-500' : '',
'h-4 w-4 mt-0.5 cursor-pointer rounded-full border flex items-center justify-center'
)}
aria-hidden="true"
>
<span class="rounded-full bg-white w-1.5 h-1.5" />
</span>
<div class="ml-3 flex flex-col">
<RadioGroupLabel
as="span"
class={classNames(checked ? 'text-sky-900' : 'text-gray-900', 'block text-sm font-medium')}
>
{setting.name}
</RadioGroupLabel>
<RadioGroupDescription
as="span"
class={classNames(checked ? 'text-sky-700' : 'text-gray-500', 'block text-sm')}
>
{setting.description}
</RadioGroupDescription>
</div>
</RadioGroupOption>
{/each}
</div>
</RadioGroup> |
Beta Was this translation helpful? Give feedback.
-
Thanks both for the help. Everything now works except the radio buttons aren't actually appearing to toggle on/off. Think this might be a bug in the actual Tailwind classes, so will do some more debugging. |
Beta Was this translation helpful? Give feedback.
You need the
let: active
andlet: checked
on the surrounding<RadioGroupOption>
component. Then you can use those variables inside that tag.For your snippet, you've actually changed too much. That
<span>
just needs to haveclassName
renamed toclass
and that's it. You've additionally turnedclass
into a function, but it should just be a string like in the original code: this snippet