-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Made consent optional in assignment settings
- Loading branch information
1 parent
91230b8
commit 794b848
Showing
16 changed files
with
270 additions
and
315 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
defmodule Frameworks.Pixel.Switch do | ||
use CoreWeb, :live_component_fabric | ||
use Fabric.LiveComponent | ||
|
||
alias Frameworks.Pixel | ||
|
||
# Handle Selector Update | ||
@impl true | ||
def update(%{active_item_id: status, selector_id: :selector}, socket) do | ||
{:ok, socket |> update_status(status)} | ||
end | ||
|
||
@impl true | ||
def update( | ||
%{id: id, on_text: on_text, off_text: off_text, opt_in?: opt_in?, status: status}, | ||
socket | ||
) do | ||
{ | ||
:ok, | ||
socket | ||
|> assign( | ||
id: id, | ||
on_text: on_text, | ||
off_text: off_text, | ||
opt_in?: opt_in?, | ||
status: status | ||
) | ||
|> compose_child(:selector) | ||
} | ||
end | ||
|
||
defp update_status(%{assigns: %{status: status}} = socket, new_status) | ||
when status != new_status do | ||
socket | ||
|> assign(status: new_status) | ||
|> send_event(:parent, "switch", %{status: new_status}) | ||
end | ||
|
||
defp update_status(socket, _status) do | ||
socket | ||
end | ||
|
||
@impl true | ||
def compose(:selector, %{ | ||
id: id, | ||
on_text: on_text, | ||
off_text: off_text, | ||
opt_in?: opt_in?, | ||
status: status | ||
}) do | ||
off = %{id: :off, value: off_text, active: status == :off} | ||
on = %{id: :on, value: on_text, active: status == :on} | ||
|
||
items = | ||
if opt_in? do | ||
[off, on] | ||
else | ||
[on, off] | ||
end | ||
|
||
%{ | ||
module: Pixel.Selector, | ||
params: %{ | ||
grid_options: "flex flex-row gap-8", | ||
items: items, | ||
type: :radio, | ||
optional?: false, | ||
parent: %{id: id, type: __MODULE__} | ||
} | ||
} | ||
end | ||
|
||
@impl true | ||
def render(assigns) do | ||
~H""" | ||
<div> | ||
<.stack fabric={@fabric} /> | ||
</div> | ||
""" | ||
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
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
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
Oops, something went wrong.