Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurClemens committed Aug 3, 2024
1 parent 7cafe4f commit c484dcf
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 5 deletions.
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>
```
2 changes: 2 additions & 0 deletions lib/component.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11272,6 +11272,8 @@ defmodule PrimerLive.Component do
PromptDeclarationHelpers.is_escapable()
PromptDeclarationHelpers.focus_first("the dialog")

attr(:is_show_on_mount, :boolean, default: false)

DeclarationHelpers.class()

attr(:classes, :map,
Expand Down
1 change: 1 addition & 0 deletions lib/helpers/attribute_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,7 @@ defmodule PrimerLive.Helpers.AttributeHelpers do
append_attributes([
[
id: toggle_id,
checked: assigns[:is_show_on_mount],
"aria-hidden": "true",
# Only use the default extra hidden input when using the menu inside a form
hidden_input: !is_nil(field),
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

0 comments on commit c484dcf

Please sign in to comment.