Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Top Nav Bar #1

Merged
merged 10 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .formatter.exs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
"priv/*/seeds.exs"
],
&Path.wildcard(&1, match_dot: true)
) -- [".scratch.ex", ".notes.ex"]
) -- [".scratch.ex", ".notes.ex", "lib/bike_shop_web/components/core_components.ex"]
]
21 changes: 1 addition & 20 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,26 +117,7 @@ jobs:
mix deps.get
mix ecto.create
- name: Check Test Coverage
# run: mix coveralls.html
run: mix coveralls.github
run_tests:
- uses: actions/checkout@v3
- name: Set up Elixir
uses: erlef/setup-beam@61e01a43a562a89bfc54c7f9a378ff67b03e4a21 # v1.16.0
strategy:
matrix:
elixir: [1.14]
otp: [26.0] # [Required] Define the Erlang/OTP version
- name: Restore dependencies cache
uses: actions/cache@v3
with:
path: deps
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
restore-keys: ${{ runner.os }}-mix-
- name: Install dependencies
run: mix deps.get
- name: Run tests
run: mix test
run: mix coveralls.html
services:
pg:
image: postgres:12
Expand Down
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
# BikesOfBurningMan BikeShop
__Demo BikeShop Built with Phoenix LiveView__

![dialyxir check](https://github.com/marka2g/bike_shop/actions/workflows/dialyxir.yml/badge.svg)
![tests passing](https://github.com/marka2g/bike_shop/actions/workflows/tests.yml/badge.svg)
![security check](https://github.com/marka2g/bike_shop/actions/workflows/security.yml/badge.svg)

![build status](https://github.com/marka2g/bike_shop/actions/workflows/main.yml/badge.svg)

## Notable Dependencies
>1. [credo](https://github.com/rrrene/credo) - static code analysis tool for Elixir
Expand Down
3 changes: 2 additions & 1 deletion coveralls.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"lib/bike_shop_web/components/core_components.ex",
"lib/bike_shop_web/components/layouts.ex",
"lib/bike_shop/repo.ex",
"lib/bike_shop_web/controllers/error_html"
"lib/bike_shop_web/controllers/error_html",
"lib/bike_shop_web/components/layouts/top_nav_component.ex"
],
"coverage_options": {
"treat_no_relevant_lines_as_covered": true,
Expand Down
62 changes: 32 additions & 30 deletions lib/bike_shop_web/components/core_components.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ defmodule BikeShopWeb.CoreComponents do
"""
use Phoenix.Component

alias Phoenix.LiveView.JS
import BikeShopWeb.Gettext

alias Phoenix.HTML.Form
alias Phoenix.LiveView.JS

@doc """
Renders a modal.

Expand Down Expand Up @@ -50,7 +52,7 @@ defmodule BikeShopWeb.CoreComponents do
data-cancel={JS.exec(@on_cancel, "phx-remove")}
class="relative z-50 hidden"
>
<div id={"#{@id}-bg"} class="bg-zinc-50/90 fixed inset-0 transition-opacity" aria-hidden="true" />
<div id={"#{@id}-bg"} class="fixed inset-0 transition-opacity bg-zinc-50/90" aria-hidden="true" />
<div
class="fixed inset-0 overflow-y-auto"
aria-labelledby={"#{@id}-title"}
Expand All @@ -59,23 +61,23 @@ defmodule BikeShopWeb.CoreComponents do
aria-modal="true"
tabindex="0"
>
<div class="flex min-h-full items-center justify-center">
<div class="flex items-center justify-center min-h-full">
<div class="w-full max-w-3xl p-4 sm:p-6 lg:py-8">
<.focus_wrap
id={"#{@id}-container"}
phx-window-keydown={JS.exec("data-cancel", to: "##{@id}")}
phx-key="escape"
phx-click-away={JS.exec("data-cancel", to: "##{@id}")}
class="shadow-zinc-700/10 ring-zinc-700/10 relative hidden rounded-2xl bg-white p-14 shadow-lg ring-1 transition"
class="relative hidden transition bg-white shadow-lg shadow-zinc-700/10 ring-zinc-700/10 rounded-2xl p-14 ring-1"
>
<div class="absolute top-6 right-5">
<button
phx-click={JS.exec("data-cancel", to: "##{@id}")}
type="button"
class="-m-3 flex-none p-3 opacity-20 hover:opacity-40"
class="flex-none p-3 -m-3 opacity-20 hover:opacity-40"
aria-label={gettext("close")}
>
<.icon name="hero-x-mark-solid" class="h-5 w-5" />
<.icon name="hero-x-mark-solid" class="w-5 h-5" />
</button>
</div>
<div id={"#{@id}-content"}>
Expand Down Expand Up @@ -120,13 +122,13 @@ defmodule BikeShopWeb.CoreComponents do
{@rest}
>
<p :if={@title} class="flex items-center gap-1.5 text-sm font-semibold leading-6">
<.icon :if={@kind == :info} name="hero-information-circle-mini" class="h-4 w-4" />
<.icon :if={@kind == :error} name="hero-exclamation-circle-mini" class="h-4 w-4" />
<.icon :if={@kind == :info} name="hero-information-circle-mini" class="w-4 h-4" />
<.icon :if={@kind == :error} name="hero-exclamation-circle-mini" class="w-4 h-4" />
<%= @title %>
</p>
<p class="mt-2 text-sm leading-5"><%= msg %></p>
<button type="button" class="group absolute top-1 right-1 p-2" aria-label={gettext("close")}>
<.icon name="hero-x-mark-solid" class="h-5 w-5 opacity-40 group-hover:opacity-70" />
<button type="button" class="absolute p-2 group top-1 right-1" aria-label={gettext("close")}>
<.icon name="hero-x-mark-solid" class="w-5 h-5 opacity-40 group-hover:opacity-70" />
</button>
</div>
"""
Expand All @@ -153,7 +155,7 @@ defmodule BikeShopWeb.CoreComponents do
phx-connected={hide("#client-error")}
hidden
>
Attempting to reconnect <.icon name="hero-arrow-path" class="ml-1 h-3 w-3 animate-spin" />
Attempting to reconnect <.icon name="hero-arrow-path" class="w-3 h-3 ml-1 animate-spin" />
</.flash>

<.flash
Expand All @@ -165,7 +167,7 @@ defmodule BikeShopWeb.CoreComponents do
hidden
>
Hang in there while we get back on track
<.icon name="hero-arrow-path" class="ml-1 h-3 w-3 animate-spin" />
<.icon name="hero-arrow-path" class="w-3 h-3 ml-1 animate-spin" />
</.flash>
"""
end
Expand Down Expand Up @@ -198,7 +200,7 @@ defmodule BikeShopWeb.CoreComponents do
<.form :let={f} for={@for} as={@as} {@rest}>
<div class="mt-10 space-y-8 bg-white">
<%= render_slot(@inner_block, f) %>
<div :for={action <- @actions} class="mt-2 flex items-center justify-between gap-6">
<div :for={action <- @actions} class="flex items-center justify-between gap-6 mt-2">
<%= render_slot(action, f) %>
</div>
</div>
Expand Down Expand Up @@ -297,7 +299,7 @@ defmodule BikeShopWeb.CoreComponents do

def input(%{type: "checkbox", value: value} = assigns) do
assigns =
assign_new(assigns, :checked, fn -> Phoenix.HTML.Form.normalize_value("checkbox", value) end)
assign_new(assigns, :checked, fn -> Form.normalize_value("checkbox", value) end)

~H"""
<div phx-feedback-for={@name}>
Expand Down Expand Up @@ -326,12 +328,12 @@ defmodule BikeShopWeb.CoreComponents do
<select
id={@id}
name={@name}
class="mt-2 block w-full rounded-md border border-gray-300 bg-white shadow-sm focus:border-zinc-400 focus:ring-0 sm:text-sm"
class="block w-full mt-2 bg-white border border-gray-300 rounded-md shadow-sm focus:border-zinc-400 focus:ring-0 sm:text-sm"
multiple={@multiple}
{@rest}
>
<option :if={@prompt} value=""><%= @prompt %></option>
<%= Phoenix.HTML.Form.options_for_select(@options, @value) %>
<%= Form.options_for_select(@options, @value) %>
</select>
<.error :for={msg <- @errors}><%= msg %></.error>
</div>
Expand All @@ -352,7 +354,7 @@ defmodule BikeShopWeb.CoreComponents do
@errors != [] && "border-rose-400 focus:border-rose-400"
]}
{@rest}
><%= Phoenix.HTML.Form.normalize_value("textarea", @value) %></textarea>
><%= Form.normalize_value("textarea", @value) %></textarea>
<.error :for={msg <- @errors}><%= msg %></.error>
</div>
"""
Expand All @@ -367,7 +369,7 @@ defmodule BikeShopWeb.CoreComponents do
type={@type}
name={@name}
id={@id}
value={Phoenix.HTML.Form.normalize_value(@type, @value)}
value={Form.normalize_value(@type, @value)}
class={[
"mt-2 block w-full rounded-lg text-zinc-900 focus:ring-0 sm:text-sm sm:leading-6",
"phx-no-feedback:border-zinc-300 phx-no-feedback:focus:border-zinc-400",
Expand Down Expand Up @@ -402,7 +404,7 @@ defmodule BikeShopWeb.CoreComponents do

def error(assigns) do
~H"""
<p class="mt-3 flex gap-3 text-sm leading-6 text-rose-600 phx-no-feedback:hidden">
<p class="flex gap-3 mt-3 text-sm leading-6 text-rose-600 phx-no-feedback:hidden">
<.icon name="hero-exclamation-circle-mini" class="mt-0.5 h-5 w-5 flex-none" />
<%= render_slot(@inner_block) %>
</p>
Expand Down Expand Up @@ -466,18 +468,18 @@ defmodule BikeShopWeb.CoreComponents do
end

~H"""
<div class="overflow-y-auto px-4 sm:overflow-visible sm:px-0">
<div class="px-4 overflow-y-auto sm:overflow-visible sm:px-0">
<table class="w-[40rem] mt-11 sm:w-full">
<thead class="text-sm text-left leading-6 text-zinc-500">
<thead class="text-sm leading-6 text-left text-zinc-500">
<tr>
<th :for={col <- @col} class="p-0 pr-6 pb-4 font-normal"><%= col[:label] %></th>
<th :for={col <- @col} class="p-0 pb-4 pr-6 font-normal"><%= col[:label] %></th>
<th class="relative p-0 pb-4"><span class="sr-only"><%= gettext("Actions") %></span></th>
</tr>
</thead>
<tbody
id={@id}
phx-update={match?(%Phoenix.LiveView.LiveStream{}, @rows) && "stream"}
class="relative divide-y divide-zinc-100 border-t border-zinc-200 text-sm leading-6 text-zinc-700"
class="relative text-sm leading-6 border-t divide-y divide-zinc-100 border-zinc-200 text-zinc-700"
>
<tr :for={row <- @rows} id={@row_id && @row_id.(row)} class="group hover:bg-zinc-50">
<td
Expand All @@ -486,15 +488,15 @@ defmodule BikeShopWeb.CoreComponents do
class={["relative p-0", @row_click && "hover:cursor-pointer"]}
>
<div class="block py-4 pr-6">
<span class="absolute -inset-y-px right-0 -left-4 group-hover:bg-zinc-50 sm:rounded-l-xl" />
<span class="absolute right-0 -inset-y-px -left-4 group-hover:bg-zinc-50 sm:rounded-l-xl" />
<span class={["relative", i == 0 && "font-semibold text-zinc-900"]}>
<%= render_slot(col, @row_item.(row)) %>
</span>
</div>
</td>
<td :if={@action != []} class="relative w-14 p-0">
<div class="relative whitespace-nowrap py-4 text-right text-sm font-medium">
<span class="absolute -inset-y-px -right-4 left-0 group-hover:bg-zinc-50 sm:rounded-r-xl" />
<td :if={@action != []} class="relative p-0 w-14">
<div class="relative py-4 text-sm font-medium text-right whitespace-nowrap">
<span class="absolute left-0 -inset-y-px -right-4 group-hover:bg-zinc-50 sm:rounded-r-xl" />
<span
:for={action <- @action}
class="relative ml-4 font-semibold leading-6 text-zinc-900 hover:text-zinc-700"
Expand Down Expand Up @@ -529,7 +531,7 @@ defmodule BikeShopWeb.CoreComponents do
<div class="mt-14">
<dl class="-my-4 divide-y divide-zinc-100">
<div :for={item <- @item} class="flex gap-4 py-4 text-sm leading-6 sm:gap-8">
<dt class="w-1/4 flex-none text-zinc-500"><%= item.title %></dt>
<dt class="flex-none w-1/4 text-zinc-500"><%= item.title %></dt>
<dd class="text-zinc-700"><%= render_slot(item) %></dd>
</div>
</dl>
Expand All @@ -554,7 +556,7 @@ defmodule BikeShopWeb.CoreComponents do
navigate={@navigate}
class="text-sm font-semibold leading-6 text-zinc-900 hover:text-zinc-700"
>
<.icon name="hero-arrow-left-solid" class="h-3 w-3" />
<.icon name="hero-arrow-left-solid" class="w-3 h-3" />
<%= render_slot(@inner_block) %>
</.link>
</div>
Expand All @@ -577,7 +579,7 @@ defmodule BikeShopWeb.CoreComponents do
## Examples

<.icon name="hero-x-mark-solid" />
<.icon name="hero-arrow-path" class="ml-1 w-3 h-3 animate-spin" />
<.icon name="hero-arrow-path" class="w-3 h-3 ml-1 animate-spin" />
"""
attr :name, :string, required: true
attr :class, :string, default: nil
Expand Down
1 change: 1 addition & 0 deletions lib/bike_shop_web/components/layouts/root.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
</head>
<body>
<div class="mx-auto max-w-7xl">
<BikeShopWeb.TopNavComponent.menu request_path={@conn.request_path} />
<%= @inner_content %>
</div>
</body>
Expand Down
40 changes: 40 additions & 0 deletions lib/bike_shop_web/components/layouts/top_nav_component.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
defmodule BikeShopWeb.TopNavComponent do
use BikeShopWeb, :html

def menu(assigns) do
~H"""
<nav class="flex items-center justify-between py-2 border-b border-neutral-200">
<a href={~p"/"} id="logo">
<img src="/images/logo.png" alt="" class="h-20 w-26" />
</a>
<div class="flex text-2xl text-neutral-600">
Bikes Of Burning Man
</div>
<ul class="flex items-center">
<a
class="bg-neutral-100 hover:bg-neutral-200 rounded-lg font-bold transition flex items-center text-neutral-700 leading-6 py-2 px-2 -my-1 -mx-1.5"
href="https://github.com/marka2g/bike_shop"
target="_blank"
>
<svg viewBox="0 0 24 24" aria-hidden="true" class="w-12 h-12">
<path
fill-rule="evenodd"
clip-rule="evenodd"
d="M12 2C6.477 2 2 6.463 2 11.97c0 4.404 2.865 8.14 6.839 9.458.5.092.682-.216.682-.48 0-.236-.008-.864-.013-1.695-2.782.602-3.369-1.337-3.369-1.337-.454-1.151-1.11-1.458-1.11-1.458-.908-.618.069-.606.069-.606 1.003.07 1.531 1.027 1.531 1.027.892 1.524 2.341 1.084 2.91.828.092-.643.35-1.083.636-1.332-2.22-.251-4.555-1.107-4.555-4.927 0-1.088.39-1.979 1.029-2.675-.103-.252-.446-1.266.098-2.638 0 0 .84-.268 2.75 1.022A9.607 9.607 0 0 1 12 6.82c.85.004 1.705.114 2.504.336 1.909-1.29 2.747-1.022 2.747-1.022.546 1.372.202 2.386.1 2.638.64.696 1.028 1.587 1.028 2.675 0 3.83-2.339 4.673-4.566 4.92.359.307.678.915.678 1.846 0 1.332-.012 2.407-.012 2.734 0 .267.18.577.688.48 3.97-1.32 6.833-5.054 6.833-9.458C22 6.463 17.522 2 12 2Z"
>
</path>
</svg>
Source Code
</a>
<a
href={~p"/"}
class="flex p-4 ml-6 mr-2 transition bg-purple-600 rounded-full text-neutral-100 group hover:text-purple-600 hover:bg-purple-100"
>
<span class="text-xs"></span>
<.icon name="hero-shopping-cart" class="w-5 h-5 stroke-current" />
</a>
</ul>
</nav>
"""
end
end
9 changes: 0 additions & 9 deletions lib/bike_shop_web/controllers/page_controller.ex

This file was deleted.

5 changes: 0 additions & 5 deletions lib/bike_shop_web/controllers/page_html.ex

This file was deleted.

Loading