-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
91 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
Large diffs are not rendered by default.
Oops, something went wrong.
43 changes: 43 additions & 0 deletions
43
app/assets/javascripts/turbo_material/material_menu_button_controller.js
This file contains 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,43 @@ | ||
import { Controller } from "@hotwired/stimulus"; | ||
import { useClickOutside } from 'stimulus-use'; | ||
export default class extends Controller { | ||
menu = undefined; | ||
|
||
connect() { | ||
mdc.ripple.MDCRipple.attachTo(this.element); | ||
this.menu = mdc.menu.MDCMenu.attachTo(this.element.querySelector('.mdc-menu-surface')); | ||
const button = this.element.querySelector('.menu-button'); | ||
this.menu.setAnchorElement(button); | ||
this.menu.setAnchorCorner(mdc.menu.Corner.BOTTOM_START); | ||
this.menu.setFixedPosition(true); | ||
useClickOutside(this); | ||
} | ||
|
||
disconnect() { | ||
} | ||
|
||
click(event) { | ||
if (this.menu.open) { | ||
this.close(); | ||
} else { | ||
this.open(); | ||
} | ||
} | ||
|
||
open() { | ||
this.menu.open = true; | ||
} | ||
|
||
close() { | ||
this.menu.open = false; | ||
} | ||
|
||
clickOutside(event) { | ||
if (!this.menu.open) { | ||
return; | ||
} else { | ||
event.preventDefault(); | ||
this.close(); | ||
} | ||
} | ||
} |
This file contains 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 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,7 @@ | ||
module TurboMaterial | ||
module MenuButtonHelper | ||
def material_menu_button(kwargs = {}) | ||
render "components/menu_button", **kwargs | ||
end | ||
end | ||
end |
This file contains 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,15 @@ | ||
<%# locals: (button_text:, menu_contents_partial:) %> | ||
<div data-controller="material-menu-button" class="!z-100"> | ||
<button class="mdc-button mdc-button--touch menu-item menu-button" | ||
data-action="click->material-menu-button#click"> | ||
<span class="mdc-button__ripple"></span> | ||
<span class="mdc-button__focus-ring"></span> | ||
<span class="mdc-button__label flex items-center"> | ||
<span class="hidden lg:inline"><%= button_text %></span> | ||
<span class="material-icons">expand_more</span> | ||
</span> | ||
</button> | ||
<div class="mdc-menu mdc-menu-surface !w-auto"> | ||
<%= render partial: menu_contents_partial %> | ||
</div> | ||
</div> |
This file contains 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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,13 @@ | ||
<ul class="mdc-deprecated-list mdc-deprecated-list--icon-list" role="menu" aria-hidden="true" aria-orientation="vertical" tabindex="-1"> | ||
<li class="mdc-deprecated-list-item" role="menuitem"> | ||
<span class="mdc-deprecated-list-item__ripple"></span> | ||
<span class="mdc-deprecated-list-item__icon material-icons">person</span> | ||
<span class="mdc-deprecated-list-item__text pl-2">My Profile</span> | ||
</li> | ||
<li class="mdc-list-divider" role="separator"></li> | ||
<li class="mdc-deprecated-list-item" role="menuitem"> | ||
<span class="mdc-deprecated-list-item__ripple"></span> | ||
<span class="mdc-deprecated-list-item__icon material-icons">logout</span> | ||
<span class="mdc-deprecated-list-item__text pl-2">Logout</span> | ||
</li> | ||
</ul> |
This file contains 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,7 @@ | ||
class MenuButtonPreview < Lookbook::Preview | ||
|
||
# @param button_text text | ||
def default(button_text: 'Menu') | ||
render 'common/standalone', helper_name: 'material_menu_button', button_text:, menu_contents_partial: 'common/menu_contents' | ||
end | ||
end |