Skip to content

Commit

Permalink
Update docs for what options are required
Browse files Browse the repository at this point in the history
  • Loading branch information
srcrip committed Dec 19, 2024
1 parent ed486ab commit 11f3904
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
25 changes: 22 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,19 @@ Finally, replace your `<.flash_group />` component with the new `<LiveToast.toas
<.flash_group flash={@flash} />
<!-- And replace it with this: -->
<LiveToast.toast_group flash={@flash} connected={assigns[:socket] != nil} />
<LiveToast.toast_group
flash={@flash}
connected={assigns[:socket] != nil}
toasts_sync={assigns[:toasts_sync]}
/>
<%= @inner_content %>
```

Those three options, `flash`, `connected`, and `toasts_sync` are all required. The library will not function properly if
you do not pass them in.


> **Note:**
> As far as I can tell in my testing, this usage of `assigns` in the layout has no negative impact on change tracking.
Expand Down Expand Up @@ -172,7 +180,12 @@ end
You can change which corner the toasts are anchored to by passing the `corner` setting to `toast_group`, one of either `:top_left`, `:top_right`, `:bottom_left`, `:bottom_right`. The default is `:bottom_right`.

```heex
<LiveToast.toast_group flash={@flash} connected={assigns[:socket] != nil} corner={:top_right} />
<LiveToast.toast_group
flash={@flash}
connected={assigns[:socket] != nil}
corner={:top_right}
toasts_sync={assigns[:toasts_sync]}
/>
```

### Internationalization
Expand Down Expand Up @@ -253,7 +266,12 @@ end
And then use it to override the default styles:

```heex
<LiveToast.toast_group flash={@flash} connected={assigns[:socket] != nil} toast_class_fn={&MyModule.toast_class_fn/1} />
<LiveToast.toast_group
flash={@flash}
connected={assigns[:socket] != nil}
toast_class_fn={&MyModule.toast_class_fn/1}
toasts_sync={assigns[:toasts_sync]}
/>
```

If you need to change the classes of the container, there is a similar function parameter called [`group_class_fn`](https://hexdocs.pm/live_toast/LiveToast.html#group_class_fn/1). Reference the documentation and apply the override just as you would `toast_class_fn/1` shown above.
Expand All @@ -270,6 +288,7 @@ additional severity level, like `:warning`, you can pass a list of these values
connected={assigns[:socket] != nil}
kinds={[:info, :error, :warning]}
toast_class_fn={&custom_toast_class_fn/1}
toasts_sync={assigns[:toasts_sync]}
/>
```

Expand Down
11 changes: 8 additions & 3 deletions lib/live_toast.ex
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,12 @@ defmodule LiveToast do
Then use it in your layout:
<LiveToast.toast_group flash={@flash} connected={assigns[:socket] != nil} group_class_fn={MyModule.group_class_fn/1} />
<LiveToast.toast_group
flash={@flash}
connected={assigns[:socket] != nil}
toasts_sync={assigns[:toasts_sync]}
group_class_fn={MyModule.group_class_fn/1}
/>
Since this is a public function, you can also write a new function that calls it and extends it's return values.
"""
Expand All @@ -206,7 +211,7 @@ defmodule LiveToast do

attr(:flash, :map, required: true, doc: "the map of flash messages")
attr(:id, :string, default: "toast-group", doc: "the optional id of flash container")
attr(:connected, :boolean, default: false, doc: "whether we're in a liveview or not")
attr(:connected, :boolean, required: true, doc: "whether we're in a liveview or not")
attr(:kinds, :list, default: [:info, :error], doc: "the valid severity level kinds")

attr(:corner, :atom,
Expand All @@ -225,7 +230,7 @@ defmodule LiveToast do
doc: "function to override the toast classes"
)

attr :toasts_sync, :list, default: nil
attr :toasts_sync, :list, required: true, doc: "toasts that get synchronized when calling `put_toast`"

@doc """
Renders a group of toasts and flashes.
Expand Down

0 comments on commit 11f3904

Please sign in to comment.