Skip to content

Commit

Permalink
0.7.1 (#181)
Browse files Browse the repository at this point in the history
* Update docs

* Update test

* Add a couple of slot attributes

* Downgrade primer/css

* asdf config

* 0.7.1
  • Loading branch information
ArthurClemens authored Aug 3, 2024
1 parent b48ecf2 commit aa7c424
Show file tree
Hide file tree
Showing 16 changed files with 9,819 additions and 21,440 deletions.
3 changes: 3 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
erlang 27.0.1
elixir 1.17.2
nodejs 18.18.0
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## 0.7.1

### Changes

- Added dialog attr `is_show_on_mount`.
- Downgraded dependency @primer/css to 21.0.7 due to regressions.

## 0.7.0

Updated dependencies:
Expand Down
437 changes: 199 additions & 238 deletions assets/package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions assets/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "primer-live",
"version": "0.7.0",
"version": "0.7.1",
"description": "JavaScript and CSS for PrimerLive",
"license": "MIT",
"repository": {},
Expand All @@ -11,7 +11,7 @@
"test": "jest"
},
"dependencies": {
"@primer/css": "21.3.6"
"@primer/css": "21.0.7"
},
"devDependencies": {
"@jest/globals": "^29.7.0",
Expand All @@ -27,4 +27,4 @@
"typescript": "^5.4.4"
},
"author": "Arthur Clemens <arthurclemens@gmail.com> (http://arthurclemens.com)"
}
}
8 changes: 7 additions & 1 deletion doc-extra/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Add PrimerLive as a dependency in your Phoenix application's `mix.exs`

```
{:primer_live, "~> 0.6"}
{:primer_live, "~> 0.7"}
```

Run `mix.deps get`
Expand All @@ -31,6 +31,12 @@ plug(Plug.Static,
)
```

Add the `primer_live` directory to the `Phoenix.VerifiedRoutes` configuration in `<app>_web.ex`:

```
def static_paths, do: ~w(assets fonts images favicon.png robots.txt primer_live)
```

<h4>CSS only</h4>

<p>Add the import link to <code>root.html.heex</code>.</p>
Expand Down
35 changes: 32 additions & 3 deletions doc-extra/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,21 @@

## Usage in LiveView pages

To use components, `use` module `PrimerLive`:
```
defmodule MyAppWeb.MyLiveView do
use MyAppWeb, :live_view
alias PrimerLive.Component, as: P
def render(assigns) do
~H"""
<P.button>Click me</P.button>
"""
end
end
```

Or import with `use`:

```
defmodule MyAppWeb.MyLiveView do
Expand All @@ -20,17 +34,32 @@ end

## Usage in regular views

In view files, for example in `page_view.ex`, `use` module `PrimerLive`:
In view files, for example in `page_view.ex`:

```
defmodule MyAppWeb.PageView do
use MyAppWeb, :view
use PrimerLive
alias PrimerLive.Component, as: P
end
```

Then call the component on a page, for example in `templates/page/index.html.heex`:

```
<P.button>Click me</P.button>
```

Or import with `use`:

```
defmodule MyAppWeb.PageView do
use MyAppWeb, :view
use PrimerLive
end
```

Call the component on a page:

```
<.button>Click me</.button>
```
37 changes: 30 additions & 7 deletions lib/component.ex
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,18 @@ defmodule PrimerLive.Component do
"""
)

attr(:onclick, :string,
doc: """
Onclick event.
"""
)

attr(:"phx-*", :string,
doc: """
phx attributes.
"""
)

DeclarationHelpers.slot_class()
DeclarationHelpers.slot_style()
DeclarationHelpers.slot_rest()
Expand Down Expand Up @@ -1293,10 +1305,13 @@ defmodule PrimerLive.Component do
"""
)

attr(:type, :string, doc: "For example: type=\"button\".")

DeclarationHelpers.slot_href()
DeclarationHelpers.patch()
DeclarationHelpers.navigate()
DeclarationHelpers.slot_class()
DeclarationHelpers.slot_phx()
DeclarationHelpers.slot_style()
DeclarationHelpers.slot_rest()
end
Expand Down Expand Up @@ -6811,6 +6826,9 @@ defmodule PrimerLive.Component do
"""
)

attr(:name, :string)
attr(:type, :string)

DeclarationHelpers.slot_class()
DeclarationHelpers.slot_style()
DeclarationHelpers.slot_rest()
Expand Down Expand Up @@ -7319,16 +7337,13 @@ defmodule PrimerLive.Component do
"""
)

attr(:name, :string)
attr(:type, :string)

DeclarationHelpers.slot_href()
DeclarationHelpers.patch()
DeclarationHelpers.navigate()

attr(:phx_click, :string,
doc: """
See https://hexdocs.pm/phoenix_live_view/bindings.html
"""
)

DeclarationHelpers.slot_phx()
DeclarationHelpers.slot_class()
DeclarationHelpers.slot_style()
DeclarationHelpers.slot_rest()
Expand Down Expand Up @@ -11272,6 +11287,12 @@ defmodule PrimerLive.Component do
PromptDeclarationHelpers.is_escapable()
PromptDeclarationHelpers.focus_first("the dialog")

attr(:is_show_on_mount, :boolean,
default: false,
doc:
"Displays the dialog on mount. Control conditional display by using the regular `:if={}` attribute."
)

DeclarationHelpers.class()

attr(:classes, :map,
Expand Down Expand Up @@ -11694,6 +11715,8 @@ defmodule PrimerLive.Component do
"""
)

attr(:style, :string)

DeclarationHelpers.slot_rest()
end

Expand Down
33 changes: 32 additions & 1 deletion lib/helpers/attribute_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,36 @@ defmodule PrimerLive.Helpers.AttributeHelpers do
touch_layer_attrs: ["data-touch": ""]
}
With is_show_on_mount:
iex> PrimerLive.Helpers.AttributeHelpers.prompt_attrs(
...> %{
...> rest: %{
...> id: "some-id"
...> },
...> prompt_options: nil,
...> is_fast: false,
...> is_dark_backdrop: false,
...> is_medium_backdrop: false,
...> is_light_backdrop: false,
...> is_show_on_mount: true
...> },
...> %{
...> form: nil,
...> field: nil,
...> toggle_slot: nil,
...> toggle_class: "btn",
...> menu_class: "",
...> is_menu: false
...> })
%{
backdrop_attrs: [],
checkbox_attrs: [{:"aria-hidden", "true"}, {:checked, true}, {:hidden_input, false}, {:id, "some-id-toggle"}, {:onchange, "window.Prompt && Prompt.change(this)"}],
focus_wrap_id: "focus-wrap-some-id",
menu_attrs: [class: "", "data-prompt": "", id: "some-id", "phx-hook": "Prompt"],
toggle_attrs: [{:"aria-haspopup", "true"}, {:class, "btn"}, {:for, "some-id-toggle"}],
touch_layer_attrs: ["data-touch": ""]
}
phx_click_touch:
iex> PrimerLive.Helpers.AttributeHelpers.prompt_attrs(
...> %{
Expand Down Expand Up @@ -1002,7 +1032,8 @@ defmodule PrimerLive.Helpers.AttributeHelpers do
")"
]
|> Enum.join("")
]
],
if(assigns[:is_show_on_mount], do: [checked: true], else: nil)
])

menu_id = id || "menu-" <> toggle_id
Expand Down
6 changes: 6 additions & 0 deletions lib/helpers/declaration_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ defmodule PrimerLive.Helpers.DeclarationHelpers do
end
end

defmacro slot_phx do
quote do
attr(:"phx-click", :string)
end
end

defmacro input_id do
quote do
attr(:input_id, :string,
Expand Down
2 changes: 1 addition & 1 deletion lib/helpers/prompt_declaration_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ defmodule PrimerLive.Helpers.PromptDeclarationHelpers do
attr :form, :any,
doc:
"""
To maintain the open state when using the menu inside a form, pass the form surrounding {the_menu_element}.
To maintain the open state when using {the_menu_element} inside a form, pass the form surrounding {the_menu_element}.
Either a [Phoenix.HTML.Form](https://hexdocs.pm/phoenix_html/Phoenix.HTML.Form.html) or an atom.
"""
|> String.replace("{the_menu_element}", unquote(the_menu_element))
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule PrimerLive.MixProject do
def project do
[
app: :primer_live,
version: "0.7.0",
version: "0.7.1",
homepage_url: "https://github.com/ArthurClemens/primer_live",
description: description(),
package: package(),
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "primer-live",
"version": "0.7.0",
"version": "0.7.1",
"description": "JavaScript and CSS for PrimerLive",
"license": "MIT",
"module": "./priv/static/primer-live.esm.js",
Expand Down Expand Up @@ -50,4 +50,4 @@
"package.json",
"priv/static/*"
]
}
}
Loading

0 comments on commit aa7c424

Please sign in to comment.