-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Chore: Extract off-canvas drawer pattern into Overlays::DrawerComponent #5312
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| <div | ||
| class="relative z-50 hidden <%= breakpoint_class %> <%= hook_class %>" | ||
| role="dialog" | ||
| aria-modal="true" | ||
| aria-label="<%= aria_label %>" | ||
| data-controller="visibility" | ||
| data-visibility-target="content" | ||
| data-visibility-visible-value="false"> | ||
|
|
||
| <div | ||
| class="fixed inset-0 bg-gray-900/80 dark:bg-black/70 hidden" | ||
| data-visibility-target="content" | ||
| data-action="click->visibility#off" | ||
| aria-hidden="true" | ||
| data-transition-enter="transition-opacity ease-linear duration-200" | ||
| data-transition-enter-start="opacity-0" | ||
| data-transition-enter-end="opacity-100" | ||
| data-transition-leave="transition-opacity ease-linear duration-200" | ||
| data-transition-leave-start="opacity-100" | ||
| data-transition-leave-end="opacity-0"> | ||
| </div> | ||
|
|
||
| <div class="fixed inset-0 flex"> | ||
| <div | ||
| class="relative mr-16 flex w-full max-w-xs flex-1 hidden" | ||
| data-visibility-target="content" | ||
| data-transition-enter="transition ease-in-out duration-200 transform" | ||
| data-transition-enter-start="-translate-x-full" | ||
| data-transition-enter-end="translate-x-0" | ||
| data-transition-leave="transition ease-in-out duration-200 transform" | ||
| data-transition-leave-start="translate-x-0" | ||
| data-transition-leave-end="-translate-x-full"> | ||
|
|
||
| <div | ||
| class="absolute left-full top-0 flex w-16 justify-center pt-5 hidden" | ||
| data-visibility-target="content" | ||
| data-transition-enter="ease-in-out duration-200" | ||
| data-transition-enter-start="opacity-0" | ||
| data-transition-enter-end="opacity-100" | ||
| data-transition-leave="ease-in-out duration-200" | ||
| data-transition-leave-start="opacity-100" | ||
| data-transition-leave-end="opacity-0"> | ||
| <button type="button" class="-m-2.5 p-2.5" data-action="click->visibility#off"> | ||
| <span class="sr-only"><%= close_label %></span> | ||
| <%= inline_svg_tag 'icons/x-mark.svg', class: 'h-6 w-6 text-white', aria: true, title: close_label %> | ||
| </button> | ||
| </div> | ||
|
|
||
| <%= content %> | ||
| </div> | ||
| </div> | ||
| </div> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| class Overlays::DrawerComponent < ApplicationComponent | ||
| BREAKPOINT_CLASSES = { lg: 'lg:hidden', xl: 'xl:hidden' }.freeze | ||
|
|
||
| def initialize(hook_class:, aria_label:, breakpoint: :lg, close_label: 'Close sidebar') | ||
| unless BREAKPOINT_CLASSES.key?(breakpoint) | ||
| raise ArgumentError, "Unsupported breakpoint: #{breakpoint.inspect}. Must be one of #{BREAKPOINT_CLASSES.keys}" | ||
| end | ||
|
|
||
| @hook_class = hook_class | ||
| @breakpoint = breakpoint | ||
| @close_label = close_label | ||
| @aria_label = aria_label | ||
| end | ||
|
|
||
| private | ||
|
|
||
| attr_reader :hook_class, :breakpoint, :close_label, :aria_label | ||
|
|
||
| def breakpoint_class | ||
| BREAKPOINT_CLASSES.fetch(breakpoint) | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,90 +1,40 @@ | ||
| <div | ||
| data-controller="visibility" | ||
| data-visibility-target="content" | ||
| data-visibility-visible-value="false" | ||
| class="fixed inset-0 flex z-40 hidden lg:hidden off-canvas-menu" | ||
| role="dialog" | ||
| aria-modal="true"> | ||
|
|
||
| <div | ||
| data-visibility-target="content" | ||
| data-action="click->visibility#off" | ||
| class="fixed inset-0 bg-gray-600 bg-opacity-75 dark:bg-black dark:bg-opacity-60 hidden" | ||
| aria-hidden="true" | ||
| data-transition-enter="transition-opacity ease-linear duration-200" | ||
| data-transition-enter-start="transform opacity-0" | ||
| data-transition-enter-end="transform opacity-100" | ||
| data-transition-leave="transition-opacity ease-linear duration-200" | ||
| data-transition-leave-start="transform opacity-100" | ||
| data-transition-leave-end="transform opacity-0"> | ||
| </div> | ||
|
|
||
| <div | ||
| data-visibility-target="content" | ||
| class="relative flex-1 flex flex-col max-w-xs w-full bg-white focus:outline-hidden hidden dark:bg-gray-800" | ||
| data-transition-enter="transition ease-in-out duration-200 transform" | ||
| data-transition-enter-start="-translate-x-full" | ||
| data-transition-enter-end="translate-x-0" | ||
| data-transition-leave="transition ease-in-out duration-200 transform" | ||
| data-transition-leave-start="translate-x-0" | ||
| data-transition-leave-end="-translate-x-full"> | ||
|
|
||
| <div | ||
| data-visibility-target="content" | ||
| class="absolute top-2 right-2 -mr-12 pt-3 hidden" | ||
| data-transition-enter="transition ease-in-out duration-200" | ||
| data-transition-enter-start="transform opacity-0" | ||
| data-transition-enter-end="transform opacity-100" | ||
| data-transition-leave="transition ease-in duration-200" | ||
| data-transition-leave-start="transform opacity-100" | ||
| data-transition-leave-end="transform opacity-0"> | ||
| <button type="button" data-action="click->visibility#off" class="ml-1 flex items-center justify-center h-10 w-10 rounded-full focus:outline-hidden focus:ring-2 focus:ring-inset focus:ring-white"> | ||
| <span class="sr-only">Close sidebar</span> | ||
| <%= inline_svg_tag 'icons/x-mark.svg', class: 'h-6 w-6 text-white', aria: true, title: 'Close menu' %> | ||
| </button> | ||
| <%= render Overlays::DrawerComponent.new(hook_class: 'off-canvas-menu', close_label: 'Close sidebar', aria_label: 'Main navigation') do %> | ||
| <div class="flex grow flex-col pt-3 pb-4 overflow-y-auto bg-white dark:bg-gray-800"> | ||
| <div class="shrink-0 flex items-center px-4"> | ||
| <%= render LogoComponent.new(classes: 'h-12 w-auto') %> | ||
| </div> | ||
|
|
||
| <div class="flex-1 h-0 pt-3 pb-4 overflow-y-auto"> | ||
| <div class="shrink-0 flex items-center px-4"> | ||
| <%= render LogoComponent.new(classes: 'h-12 w-auto') %> | ||
| <nav aria-label="Sidebar" class="mt-3"> | ||
| <div class="px-2 space-y-1"> | ||
| <% if user_signed_in? %> | ||
| <%= render Nav::ItemComponent.new(path: dashboard_path, text: 'Dashboard', test_id: 'nav-dashboard', icon_path: 'icons/home.svg', options: { mobile: true }) %> | ||
| <%= render Nav::ItemComponent.new(path: paths_url, text: 'All Paths', test_id: 'nav-all-paths', icon_path: 'icons/map.svg', options: { mobile: true }) %> | ||
| <%= render Nav::ItemComponent.new(path: notifications_path, text: 'Notifications', test_id: 'nav-notifications', icon_path: 'icons/bell.svg', options: { mobile: true }) %> | ||
| <%= render Nav::ItemComponent.new(path: support_us_path, text: 'Support Us', test_id: 'nav-support-us', icon_path: 'icons/heart-outline.svg', options: { mobile: true }) %> | ||
| <%= render Nav::ItemComponent.new(path: ODIN_CHAT_URL, text: 'Community', test_id: 'nav-community', icon_path: 'icons/speech-bubbles.svg', options: { mobile: true }) %> | ||
| <% else %> | ||
| <%= render Nav::ItemComponent.new(path: root_path, text: 'Home', test_id: 'nav-home', icon_path: 'icons/home.svg', options: { mobile: true }) %> | ||
| <%= render Nav::ItemComponent.new(path: paths_url, text: 'All Paths', test_id: 'nav-all-paths', icon_path: 'icons/map.svg', options: { mobile: true }) %> | ||
| <%= render Nav::ItemComponent.new(path: about_path, text: 'About', test_id: 'nav-about', icon_path: 'icons/information.svg', options: { mobile: true }) %> | ||
| <%= render Nav::ItemComponent.new(path: support_us_path, text: 'Support Us', test_id: 'nav-support-us', icon_path: 'icons/heart-outline.svg', options: { mobile: true }) %> | ||
| <%= render Nav::ItemComponent.new(path: ODIN_CHAT_URL, text: 'Community', test_id: 'nav-community', icon_path: 'icons/speech-bubbles.svg', options: { mobile: true }) %> | ||
| <% end %> | ||
| </div> | ||
| <nav aria-label="Sidebar" class="mt-3"> | ||
| <div class="px-2 space-y-1"> | ||
| <% if user_signed_in? %> | ||
| <%= render Nav::ItemComponent.new(path: dashboard_path, text: 'Dashboard', test_id: 'nav-dashboard', icon_path: 'icons/home.svg', options: { mobile: true }) %> | ||
| <%= render Nav::ItemComponent.new(path: paths_url, text: 'All Paths', test_id: 'nav-all-paths', icon_path: 'icons/map.svg', options: { mobile: true }) %> | ||
| <%= render Nav::ItemComponent.new(path: notifications_path, text: 'Notifications', test_id: 'nav-notifications', icon_path: 'icons/bell.svg', options: { mobile: true }) %> | ||
| <%= render Nav::ItemComponent.new(path: support_us_path, text: 'Support Us', test_id: 'nav-support-us', icon_path: 'icons/heart-outline.svg', options: { mobile: true }) %> | ||
| <%= render Nav::ItemComponent.new(path: ODIN_CHAT_URL, text: 'Community', test_id: 'nav-community', icon_path: 'icons/speech-bubbles.svg', options: { mobile: true }) %> | ||
| <% else %> | ||
| <%= render Nav::ItemComponent.new(path: root_path, text: 'Home', test_id: 'nav-home', icon_path: 'icons/home.svg', options: { mobile: true }) %> | ||
| <%= render Nav::ItemComponent.new(path: paths_url, text: 'All Paths', test_id: 'nav-all-paths', icon_path: 'icons/map.svg', options: { mobile: true }) %> | ||
| <%= render Nav::ItemComponent.new(path: about_path, text: 'About', test_id: 'nav-about', icon_path: 'icons/information.svg', options: { mobile: true }) %> | ||
| <%= render Nav::ItemComponent.new(path: support_us_path, text: 'Support Us', test_id: 'nav-support-us', icon_path: 'icons/heart-outline.svg', options: { mobile: true }) %> | ||
| <%= render Nav::ItemComponent.new(path: ODIN_CHAT_URL, text: 'Community', test_id: 'nav-community', icon_path: 'icons/speech-bubbles.svg', options: { mobile: true }) %> | ||
| <hr class="border-t border-gray-200 my-4" aria-hidden="true"> | ||
| <div class="px-2 space-y-1"> | ||
| <% if user_signed_in? %> | ||
| <%= render Nav::ItemComponent.new(path: edit_users_profile_path, text: 'Settings', test_id: 'nav-settings', icon_path: 'icons/gear.svg', options: { mobile: true }) %> | ||
| <%= turbo_frame_tag 'theme_switcher_mobile' do %> | ||
| <%= render Theme::SwitcherComponent.new(current_theme:, type: :mobile) %> | ||
| <% end %> | ||
| </div> | ||
| <hr class="border-t border-gray-200 my-4" aria-hidden="true"> | ||
| <div class="px-2 space-y-1"> | ||
| <% if user_signed_in? %> | ||
| <%= render Nav::ItemComponent.new(path: edit_users_profile_path, text: 'Settings', test_id: 'nav-settings', icon_path: 'icons/gear.svg', options: { mobile: true }) %> | ||
| <%= turbo_frame_tag 'theme_switcher_mobile' do %> | ||
| <%= render Theme::SwitcherComponent.new(current_theme:, type: :mobile) %> | ||
| <% end %> | ||
| <%= render Nav::ItemComponent.new(path: sign_out_path, text: 'Sign out', test_id: 'nav-sign-out', icon_path: 'icons/sign-out.svg', options: { method: :delete, mobile: true }) %> | ||
| <% else %> | ||
| <%= render Nav::ItemComponent.new(path: sign_up_path, text: 'Get started', test_id: 'nav-sign-up', icon_path: 'icons/rocket.svg', options: { mobile: true }) %> | ||
| <%= turbo_frame_tag 'theme_switcher_mobile' do %> | ||
| <%= render Theme::SwitcherComponent.new(current_theme:, type: :mobile) %> | ||
| <% end %> | ||
| <%= render Nav::ItemComponent.new(path: sign_in_path, text: 'Sign in', test_id: 'nav-sign-in', icon_path: 'icons/sign-in.svg', options: { mobile: true }) %> | ||
| <%= render Nav::ItemComponent.new(path: sign_out_path, text: 'Sign out', test_id: 'nav-sign-out', icon_path: 'icons/sign-out.svg', options: { method: :delete, mobile: true }) %> | ||
| <% else %> | ||
| <%= render Nav::ItemComponent.new(path: sign_up_path, text: 'Get started', test_id: 'nav-sign-up', icon_path: 'icons/rocket.svg', options: { mobile: true }) %> | ||
| <%= turbo_frame_tag 'theme_switcher_mobile' do %> | ||
| <%= render Theme::SwitcherComponent.new(current_theme:, type: :mobile) %> | ||
| <% end %> | ||
| </div> | ||
| </nav> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div class="shrink-0 w-14" aria-hidden="true"> | ||
| <!-- Force sidebar to shrink to fit close icon --> | ||
| <%= render Nav::ItemComponent.new(path: sign_in_path, text: 'Sign in', test_id: 'nav-sign-in', icon_path: 'icons/sign-in.svg', options: { mobile: true }) %> | ||
| <% end %> | ||
| </div> | ||
| </nav> | ||
| </div> | ||
| </div> | ||
| <% end %> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.