Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code examples #73

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

MichalBryxi
Copy link
Sponsor Contributor

  • Remove the calls to {{yield}} - those seem to assume some more complex code structure(?) that is not obvious from the README examples

  • Give complete, working example using headless-ui

  • I think this makes a good, yet simple to follow starting point?

  • Giving it out there as a newcomer who had trouble figuring out bits

@NullVoxPopuli
Copy link
Owner

NullVoxPopuli commented Nov 20, 2021

I think having the first example being a simpler one is probably good. I do think, generally, people always want the the architecture with the yields though -- because folks always want a "Menu" component that's generic and can be used for any kind of menu.

Any chance you'd be willing to write up an example of this pattern?
the gist that I'd want conveyed is:

  • <PopperJS> - for coordinating the positing of the {{popover}} element to the {{reference}} element
  • (HeadlessUI's) <Menu> - for accessibility
  • (Your) <MyMenu> - for wiring up the previous two and adding your own styling / design system stuff (this can be named Menu if the Tailwind Menu is imported rather than used via globals resolver -- which is fun, because it then prevents usage of the headless Menu and forces folks to use your design system
  • final usage of <MyMenu>:
<MyMenu>
  <:trigger>
    text / icon / etc, maybe button if this were to yield yet another modifier, 
    but _that_ may be out of scope here
  </:trigger>
  <:menu as |Item|>
     <Item> a </Item>
     <Item> b </Item>
  </:menu>
</MyMenu>

@MichalBryxi
Copy link
Sponsor Contributor Author

Good point. Having a complex example that shows the real world scenario is a good idea. Will re-do.

- Remove the calls to `{{yield}}`
  those seem to assume some more complex code structure
  that is not obvious from the README examples
- Give complete, working example using headless-ui
- I _think_ this makes a good,
  yet simple to follow starting point?
- Introduce complete example of <MyMenu> component
- Most of the code taken from:
- https://github.com/GavinJoyce/ember-headlessui/tree/master/tests/dummy/app/components
- Introduce <MyMenu::Item> for styling abilities
- To overcome: emberjs/rfcs#497
@MichalBryxi
Copy link
Sponsor Contributor Author

Ok, I got a little bit tangled over how to yield a pre-defined component. To my best understanding this is not really possible (yet) so I just went ahead and created <MyMenu> and <MyMenu::Item> to give folks full example that should not(?) have any major flaws:

my-menu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants