-
Notifications
You must be signed in to change notification settings - Fork 0
/
phoenix_webcomponent.ex
99 lines (77 loc) · 2.32 KB
/
phoenix_webcomponent.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
defmodule Phoenix.WebComponent do
@moduledoc """
Provides a suit of html custom component for phoenix.
This library provides three main functionalities:
* Enhance form helper with manterial web componet
* Enhance link helper with manterial web componet
* Markdown render helper with `@gsmlg/lit/remark-element`
* TopAppBar render top app bar with custom element.
## Form helper
See `Phoenix.WebComponent.FormHelper`.
## JavaScript library
This project provides javascript that define custom elements.
To use the web component, you must load `priv/static/phoenix_webcomponent.js`
into your build tool. Or through npm by install `phoenix_webcomponent`.
The difference is npm version is not bundled.
"""
def live_component do
quote do
use Phoenix.LiveComponent
unquote(html_helpers())
end
end
def html do
quote do
use Phoenix.Component
# Import convenience functions from controllers
import Phoenix.Controller,
only: [get_csrf_token: 0, view_module: 1, view_template: 1]
# Include general helpers for rendering HTML
unquote(html_helpers())
end
end
def alias do
quote do
alias Phoenix.WebComponent.Actionbar
alias Phoenix.WebComponent.Appbar
alias Phoenix.WebComponent.Card
alias Phoenix.WebComponent.LeftMenu
alias Phoenix.WebComponent.Markdown
alias Phoenix.WebComponent.Pagination
alias Phoenix.WebComponent.Table
end
end
defp html_helpers do
quote do
# HTML escaping functionality
import Phoenix.HTML
# Shortcut for generating JS commands
alias Phoenix.LiveView.JS
end
end
defp components do
quote do
import Phoenix.WebComponent.Actionbar
import Phoenix.WebComponent.Appbar
import Phoenix.WebComponent.Card
import Phoenix.WebComponent.LeftMenu
import Phoenix.WebComponent.Markdown
import Phoenix.WebComponent.Pagination
import Phoenix.WebComponent.Table
end
end
@doc """
Import helpers for internal usage.
Support:
- `use Phoenix.WebComponent, :component`
- `use Phoenix.WebComponent, :live_component`
"""
defmacro __using__(which) when is_atom(which) do
apply(__MODULE__, which, [])
end
defmacro __using__(_) do
quote do
unquote(components())
end
end
end