Comments (5)
Hey! Glad you're finding the library useful :) Sorry about the lack of docs, I'm actually working on them right now.
In your code, active
and checked
are erroring because in Svelte, the slot props (let:active
and let:checked
) are only defined in the child components. To get around this, the components in this library also accept a function for the class
prop. That function will take the slot props as input and should output a class string.
In your case, I think you want something like
class={({active, checked}) => classNames(
active && checked ? 'ring ring-offset-1' : '',
!active && checked ? 'ring-2' : '',
colour.selectedColour,
'-m-0.5 relative p-0.5 rounded-full flex items-center justify-center cursor-pointer focus:outline-none'
)}
where classNames is a helper function that looks like
function classNames(...classes) {
return classes.filter(Boolean).join(" ");
}
Or alternatively using template literals something like:
class={({active, checked}) =>
`${active && checked ? 'ring ring-offset-1' : ''} ${!active && checked ? 'ring-2' : ''} ${colour.selectedColour} -m-0.5 relative p-0.5 rounded-full flex items-center justify-center cursor-pointer focus:outline-none`
}
I also noticed that a bit further down in your snippet, I think you meant to use a template literal on this line:
class="{colour.bgColour} h-8 w-8 border border-black border-opacity-10 rounded-full"
Otherwise I think your HTML will end up with "{colour.bgColour}" in it instead of the value.
Hope that helps!
from svelte-headlessui.
Thanks @rgossiaux that was very helpful. Really looking forward to the docs. Happy to help review them if you want. If I could understand them, then anyone could! 😂
from svelte-headlessui.
Thanks to the implementation guidance from @rgossiaux I was able to implement the Tailwind UI e-commerce product quickview @sbadisa was trying to create. See it in action here or review the implementation here. (Note I could not figure out how to get the
disabled
slot prop working and left a FIXME in the code. I also left transitions/animation for a future iteration.)@rgossiaux Perhaps you could enable Discussions on this repo so we could move items like this to the Q&A section? @sbadisa if you can get
disabled
working for the size selector please let me know -- I tried to use a Svelte@const
in theeach
block but that didn't do it.
Sure, I enabled discussions for the repo.
As for your code, I took a quick peek. You want to just use the normal disabled
prop, the same as the Tailwind code: disabled={!size.inStock}
.
I also noticed that you commented out the Transitions in their code. Those should work just fine as well if you just delete the as={Fragment}
and rename the Transition.Root
to Transition
from svelte-headlessui.
Thanks to the implementation guidance from @rgossiaux I was able to implement the Tailwind UI e-commerce product quickview @sbadisa was trying to create. See it in action here or review the implementation here. (Note I could not figure out how to get the disabled
slot prop working and left a FIXME in the code. I also left transitions/animation for a future iteration.)
@rgossiaux Perhaps you could enable Discussions on this repo so we could move items like this to the Q&A section? @sbadisa if you can get disabled
working for the size selector please let me know -- I tried to use a Svelte @const
in the each
block but that didn't do it.
from svelte-headlessui.
Thanks so much for creating the Discussion section, @rgossiaux.
As for your code, I took a quick peek. You want to just use the normal
disabled
prop, the same as the Tailwind code:disabled={!size.inStock}
.
I did try that before attempting to use @const
as a workaround. Unfortunately Svelte throws a compiler error due to an invalid use of let
which I've detailed along with my issue in more detail in the Discussion section here: #48
Looking forward to getting past this issue as it's a blocker for creating a workable ecommerce storefront.
from svelte-headlessui.
Related Issues (20)
- component disappears after refresh when used in a svelte component HOT 1
- Support for @headlessui/tailwindcss HOT 1
- List box doesn't position absolute HOT 1
- Support Svelte 4 HOT 13
- Can't bind popover's "open" prop to a boolean HOT 1
- Switch not toggling
- RadioGroup and Listbox do not work properly when used together
- Can you readd on:change for listbox, etc
- Typo in Tabs Component Page
- Typescript Error 2322 when assigning object to ListboxOption value parameter
- Dialog breakes SvelteKit client-side routing HOT 2
- Conflicts in Svelte resolve
- Tree shaking HOT 1
- Time to update svelte? HOT 1
- Dialog nested in a Menu automatically opens when Menu opens
- warning when using sveltekit v2: The following packages have a svelte field in their package.json but no exports condition for svelte. HOT 1
- Missing close event on Menu
- Headless UI v2.0.0-alpha released
- Popover not detecting content click events (links / otherwise) in web component context (with fix) HOT 2
- Tabs: adding/removing tab work not properly
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from svelte-headlessui.