command+click 'Create' button to load in new tab
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
defmodule LabelmakerWeb.Constants do
|
defmodule LabelmakerWeb.Constants do
|
||||||
@defaults %{
|
@defaults %{
|
||||||
label: "",
|
label: "",
|
||||||
|
link: "",
|
||||||
font: "Helvetica",
|
font: "Helvetica",
|
||||||
color: "black",
|
color: "black",
|
||||||
outline: "white",
|
outline: "white",
|
||||||
|
|||||||
@@ -39,13 +39,6 @@ defmodule LabelmakerWeb.Home do
|
|||||||
end
|
end
|
||||||
|
|
||||||
def render(assigns) do
|
def render(assigns) do
|
||||||
assigns =
|
|
||||||
assign(
|
|
||||||
assigns,
|
|
||||||
:label_too_long,
|
|
||||||
String.length(assigns.label) > Constants.max_label_length()
|
|
||||||
)
|
|
||||||
|
|
||||||
preview_background =
|
preview_background =
|
||||||
case assigns.preview_bg do
|
case assigns.preview_bg do
|
||||||
"r" -> "bg-[linear-gradient(to_right,_black_33%,_white_67%)]"
|
"r" -> "bg-[linear-gradient(to_right,_black_33%,_white_67%)]"
|
||||||
@@ -54,13 +47,20 @@ defmodule LabelmakerWeb.Home do
|
|||||||
_ -> "bg-[linear-gradient(to_right,_black_33%,_white_67%)]"
|
_ -> "bg-[linear-gradient(to_right,_black_33%,_white_67%)]"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
assigns =
|
||||||
|
assign(
|
||||||
|
assigns,
|
||||||
|
label_too_long: String.length(assigns.label) > Constants.max_label_length(),
|
||||||
|
preview_background: preview_background
|
||||||
|
)
|
||||||
|
|
||||||
~H"""
|
~H"""
|
||||||
<div class="max-w-xl mx-auto p-4 space-y-6">
|
<div class="max-w-xl mx-auto p-4 space-y-6">
|
||||||
<h1 class="text-2xl font-bold text-center">Labelmaker</h1>
|
<h1 class="text-2xl font-bold text-center">Labelmaker</h1>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
class={
|
class={
|
||||||
"flex justify-center items-center p-4 overflow-hidden whitespace-nowrap border rounded transition duration-300 #{preview_background} #{if @label_too_long, do: "border-danger", else: "border-primary"} #{if @label_too_long, do: "outline-danger", else: @outline != "none" && "outline-#{@outline}"}"}
|
"flex justify-center items-center p-4 overflow-hidden whitespace-nowrap border rounded transition duration-300 #{@preview_background} #{if @label_too_long, do: "border-danger", else: "border-primary"} #{if @label_too_long, do: "outline-danger", else: @outline != "none" && "outline-#{@outline}"}"}
|
||||||
style={"height: calc(2rem + #{@preview_height}px); color: #{if @label_too_long, do: "white", else: @color}; font-family: #{@font}; font-size: #{@size}px; line-height: #{@size}px; background-color: #{if @preview_bg == "c", do: @color, else: ""}"}
|
style={"height: calc(2rem + #{@preview_height}px); color: #{if @label_too_long, do: "white", else: @color}; font-family: #{@font}; font-size: #{@size}px; line-height: #{@size}px; background-color: #{if @preview_bg == "c", do: @color, else: ""}"}
|
||||||
>
|
>
|
||||||
<%= if @label_too_long do %>
|
<%= if @label_too_long do %>
|
||||||
@@ -169,16 +169,15 @@ defmodule LabelmakerWeb.Home do
|
|||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<button
|
<a href={@link}>
|
||||||
type="submit"
|
<button class="inline-block bg-primary text-fg-light dark:text-fg-dark px-4 py-2 rounded hover:bg-highlight focus:ring-fg-light focus:dark:ring-fg-dark">
|
||||||
class="inline-block bg-primary text-fg-light dark:text-fg-dark px-4 py-2 rounded hover:bg-highlight focus:ring-fg-light focus:dark:ring-fg-dark"
|
|
||||||
>
|
|
||||||
Create
|
Create
|
||||||
</button>
|
</button>
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
|
||||||
</div>
|
</div>
|
||||||
"""
|
"""
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,8 +1,16 @@
|
|||||||
defmodule LabelmakerWeb.Tools do
|
defmodule LabelmakerWeb.Tools do
|
||||||
|
# for the ~p sigil
|
||||||
|
use Phoenix.VerifiedRoutes,
|
||||||
|
endpoint: LabelmakerWeb.Endpoint,
|
||||||
|
router: LabelmakerWeb.Router,
|
||||||
|
statics: LabelmakerWeb.static_paths()
|
||||||
|
|
||||||
alias LabelmakerWeb.Constants
|
alias LabelmakerWeb.Constants
|
||||||
|
|
||||||
def process_parameters(parameters) do
|
def process_parameters(parameters) do
|
||||||
%{"label" => label, "size" => size} = parameters
|
%{"label" => label, "size" => size} = parameters
|
||||||
|
|
||||||
|
link = ~p"/#{label}?#{Map.take(parameters, ["color", "font", "outline", "size"])}"
|
||||||
line_breaks = Regex.scan(~r/#{Regex.escape("\\n")}/, label) |> length()
|
line_breaks = Regex.scan(~r/#{Regex.escape("\\n")}/, label) |> length()
|
||||||
size = String.to_integer(size)
|
size = String.to_integer(size)
|
||||||
|
|
||||||
@@ -16,6 +24,9 @@ defmodule LabelmakerWeb.Tools do
|
|||||||
do: {:label, String.slice(label, 0, Constants.max_label_length() + 1)},
|
do: {:label, String.slice(label, 0, Constants.max_label_length() + 1)},
|
||||||
else: {:label, label}
|
else: {:label, label}
|
||||||
|
|
||||||
|
{:link, _} ->
|
||||||
|
{:link, link}
|
||||||
|
|
||||||
{:preview_height, _} ->
|
{:preview_height, _} ->
|
||||||
{:preview_height, size + size * line_breaks}
|
{:preview_height, size + size * line_breaks}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user