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

Recreate Menu as a Svelte Action #196

Closed
endigo9740 opened this issue Sep 7, 2022 · 7 comments · Fixed by #298
Closed

Recreate Menu as a Svelte Action #196

endigo9740 opened this issue Sep 7, 2022 · 7 comments · Fixed by #298
Assignees
Labels
enhancement New feature or request ready to test Ready to be tested for quality assurance.

Comments

@endigo9740
Copy link
Contributor

Similar to Tooltips (#195) I believe Menus could benefit from making breaking out of the confines of a target/content sibling relationship.

I'll investigate the use of Svelte Actions (read: directives) to make this possible.

@endigo9740 endigo9740 added the enhancement New feature or request label Sep 7, 2022
@endigo9740 endigo9740 self-assigned this Sep 7, 2022
@endigo9740 endigo9740 pinned this issue Sep 26, 2022
@endigo9740
Copy link
Contributor Author

NOTE: here's how to ensure param data stays up to date:
https://discord.com/channels/457912077277855764/1023340103071965194/threads/1024077183158845561

@endigo9740
Copy link
Contributor Author

@endigo9740 endigo9740 linked a pull request Sep 27, 2022 that will close this issue
@endigo9740
Copy link
Contributor Author

I've submitted a draft PR showcasing my first version of this change.

menu-examples

These make use of both Tailwind Elements (for canned class styles) as well as a dedicated Svelte Action.

Screen Shot 2022-09-27 at 6 35 27 PM

Usage is pretty straight forward, you create a wrapping element, add a trigger, add a menu. Then link the two together via the action, via the target and data attribute.

Screen Shot 2022-09-27 at 6 35 43 PM

Given it's a Tailwind Element there's plenty of style options available:

Screen Shot 2022-09-27 at 6 35 59 PM

Likewise I've made the auto-origin the default, but you can still set a fixed value if you wish:

Screen Shot 2022-09-27 at 6 36 04 PM

I'll most likely pick up and improve this tomorrow, so expect more updates then. However feel free to try the PR and submit feedback!

@endigo9740
Copy link
Contributor Author

endigo9740 commented Sep 27, 2022

In case you're wondering, the goal with the data attribute is to make the linking arbitrary. This opens the door to crazy stuff like this:

<div class="hidden absolute top-4 right-4 card card-body w-64 shadow-xl" data-menu-1>(menu)</div>
<button class="btn btn-ghost" use:menu={{ target: '1', fixed: true }}>Menu 1</button>

Where the menu is not required to be relative to the trigger, but rather it can appear anywhere you want on the page.

Kapture 2022-09-27 at 18 53 37

@endigo9740
Copy link
Contributor Author

endigo9740 commented Sep 28, 2022

I've worked up a REPL of some potential updates:
https://svelte.dev/repl/b9055bf14e2d4bb5a38f2102ffbfa260?version=3.50.1

General idea:

  • Playing with the idea of making this a generic "popup" action, shared w/ tooltips
  • We completely abstract visual styling and layout to Tailwind Elements
  • We opt for a more generic data attribute (ex: data-menu), with a unique value (ex: 'foo')
  • We target default menu styles via [data-menu] { ... } CSS selector and make it hidden by default
  • Rename action param target -> menu
  • Use JS to modify the display style directly rather than toggling the TW hidden class
  • Add the autoclose: boolean option:
    • true (default): the menu closes when clicking within the menu
    • false: the menu does NOT close when clicking within the menu

@endigo9740
Copy link
Contributor Author

I've applied all updates above, update the docs, and actually implemented the new menus as part of the documentation site app bar. These are working great!

menus-updated

Screen Shot 2022-09-28 at 2 39 15 PM

Screen Shot 2022-09-28 at 2 39 20 PM

I'll keep the PR open for a bit to give folks a chance to test these, otherwise I'll aim to merge soon.

@endigo9740 endigo9740 added the ready to test Ready to be tested for quality assurance. label Sep 28, 2022
@endigo9740 endigo9740 changed the title Investigate using Svelte Actions for Menus Recreate Menu as a Svelte Action Sep 29, 2022
@endigo9740
Copy link
Contributor Author

endigo9740 commented Sep 29, 2022

FYI I've attempted to setup test cases for this action. However, this is not operating as expected. I'd welcome feedback from anyone that can shed light on this:

https://github.com/Brain-Bones/skeleton/blob/e2b8ba3e2cf35ce0d0787e8e79c8482e6dcc0c85/src/lib/utilities/Menu/menu.test.ts

For now the test is present but skipped.

@endigo9740 endigo9740 unpinned this issue Oct 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request ready to test Ready to be tested for quality assurance.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant