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
6 changed files
with
76 additions
and
1 deletion.
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
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,45 @@ | ||
defmodule Phoenix.WebComponent.TopAppBar do | ||
@moduledoc """ | ||
Conveniences for create top app bar. | ||
""" | ||
|
||
import Phoenix.HTML.Tag | ||
|
||
@doc """ | ||
Generates a top app bar. | ||
## Examples | ||
wc_link("hello", to: "/world") | ||
#=> <a href="/world"><mwc-button>hello</mwc-button></a> | ||
## Options | ||
### Slots | ||
| Name | Description | ||
| ---- | ----------- | ||
| `actionItems` | A number of `<mwc-icon-button>` elements to use for action icons on the right side. _NOTE:_ If using with `mwc-drawer`, please read note under [`Standard` drawer example](https://github.com/material-components/material-web/tree/master/packages/top-app-bar). | ||
| `navigationIcon` | One `<mwc-icon-button>` element to use for the left icon. | ||
| `title` | A `<div>` or `<span>` that will be used as the title text. | ||
| _default_ | Scrollable content to display under the bar. This may be the entire application. | ||
### Properties/Attributes | ||
| Name | Type | Default | Description | ||
| ---- | ---- | ------- | ----------- | ||
| `centerTitle` | `boolean` | `false` | Centers the title horizontally. Only meant to be used with 0 or 1 `actionItems`. | ||
| `dense` | `boolean` | `false` | Makes the bar a little smaller for higher density applications. | ||
| `prominent` | `boolean` | `false` | Makes the bar much taller, can be combined with `dense`. | ||
| `scrollTarget` | `HTMLElement` \| `Window` | `window` | Element used to listen for `scroll` events. | ||
""" | ||
def wc_top_app_bar(opts, do: contents) when is_list(opts) do | ||
{fixed, opts} = Keyword.pop(opts, :fixed, false) | ||
app_bar_tag = if fixed, do: :"mwc-top-app-bar-fixed", else: :"mwc-top-app-bar" | ||
|
||
content_tag(app_bar_tag, opts) do | ||
contents | ||
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
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,21 @@ | ||
defmodule Phoenix.WebComponent.TopAppBarTest do | ||
use ExUnit.Case, async: true | ||
|
||
import Phoenix.HTML | ||
import Phoenix.HTML.Tag | ||
import Phoenix.WebComponent.TopAppBar | ||
|
||
test "wc_top_app_bar empty" do | ||
assert safe_to_string(wc_top_app_bar([], do: "")) == | ||
~s[<mwc-top-app-bar></mwc-top-app-bar>] | ||
end | ||
|
||
test "wc_top_app_bar fixed with slots" do | ||
assert safe_to_string( | ||
wc_top_app_bar(fixed: true) do | ||
content_tag(:"mwc-icon-button", "", icon: "menu", slot: "navigationIcon") | ||
end | ||
) == | ||
~s[<mwc-top-app-bar-fixed><mwc-icon-button icon="menu" slot="navigationIcon"></mwc-icon-button></mwc-top-app-bar-fixed>] | ||
end | ||
end |