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

chore: migrate heroicons to new tailwind bundle #532

Merged
merged 6 commits into from
Sep 13, 2024
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
10 changes: 5 additions & 5 deletions assets/css/components/avatar.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@
/* Avatar - sizes */

.atomic-avatar--xs {
@apply h-8 w-8 text-xs;
@apply size-8 text-xs;
}

.atomic-avatar--sm {
@apply h-12 w-12 text-lg;
@apply size-12 text-lg;
}

.atomic-avatar--md {
@apply h-16 w-16 text-lg;
@apply size-16 text-lg;
}

.atomic-avatar--lg {
@apply h-20 w-20 text-4xl;
@apply size-20 text-4xl;
}

.atomic-avatar--xl {
@apply h-24 w-24 text-4xl;
@apply size-24 text-4xl;
}

/* Avatar - colors */
Expand Down
75 changes: 62 additions & 13 deletions assets/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const colors = require("tailwindcss/colors");
const plugin = require('tailwindcss/plugin');

const fs = require("fs");
const path = require("path");

module.exports = {
darkMode: 'selector',
content: [
Expand All @@ -25,23 +28,23 @@ module.exports = {
},
keyframes: {
wave: {
'0%': { transform: 'rotate(0.0deg)' },
'15%': { transform: 'rotate(14.0deg)' },
'30%': { transform: 'rotate(-8.0deg)' },
'40%': { transform: 'rotate(14.0deg)' },
'50%': { transform: 'rotate(-4.0deg)' },
'60%': { transform: 'rotate(10.0deg)' },
'70%': { transform: 'rotate(0.0deg)' },
'100%': { transform: 'rotate(0.0deg)' },
'0%': { transform: 'rotate(0.0deg)' },
'15%': { transform: 'rotate(14.0deg)' },
'30%': { transform: 'rotate(-8.0deg)' },
'40%': { transform: 'rotate(14.0deg)' },
'50%': { transform: 'rotate(-4.0deg)' },
'60%': { transform: 'rotate(10.0deg)' },
'70%': { transform: 'rotate(0.0deg)' },
'100%': { transform: 'rotate(0.0deg)' },
},
progress: {
'0%': { width: '0%' },
'100%': { width: '100%' },
'0%': { width: '0%' },
'100%': { width: '100%' },
}
},
animation: {
wave: 'wave 1.5s infinite',
progress: 'progress 5s linear 1'
wave: 'wave 1.5s infinite',
progress: 'progress 5s linear 1'
},
backgroundSize: {
'75': '75%'
Expand All @@ -50,9 +53,55 @@ module.exports = {
},
plugins: [
require('@tailwindcss/forms'),

// Allows prefixing tailwind classes with LiveView classes to add rules
// only when LiveView classes are applied, for example:
//
// <div class="phx-click-loading:animate-ping">
//
plugin(({addVariant}) => addVariant('phx-no-feedback', ['&.phx-no-feedback', '.phx-no-feedback &'])),
plugin(({addVariant}) => addVariant('phx-click-loading', ['&.phx-click-loading', '.phx-click-loading &'])),
plugin(({addVariant}) => addVariant('phx-submit-loading', ['&.phx-submit-loading', '.phx-submit-loading &'])),
plugin(({addVariant}) => addVariant('phx-change-loading', ['&.phx-change-loading', '.phx-change-loading &']))
plugin(({addVariant}) => addVariant('phx-change-loading', ['&.phx-change-loading', '.phx-change-loading &'])),

// Embeds Heroicons (https://heroicons.com) into app.css bundle
plugin(function({matchComponents, theme}) {
let iconsDir = path.join(__dirname, "../deps/heroicons/optimized")
let values = {}
let icons = [
["", "/24/outline"],
["-solid", "/24/solid"],
["-mini", "/20/solid"],
["-micro", "/16/solid"]
]
icons.forEach(([suffix, dir]) => {
fs.readdirSync(path.join(iconsDir, dir)).forEach(file => {
let name = path.basename(file, ".svg") + suffix
values[name] = {name, fullPath: path.join(iconsDir, dir, file)}
})
})
matchComponents({
"hero": ({name, fullPath}) => {
let content = fs.readFileSync(fullPath).toString().replace(/\r?\n|\r/g, "")
let size = theme("spacing.6")
if (name.endsWith("-mini")) {
size = theme("spacing.5")
} else if (name.endsWith("-micro")) {
size = theme("spacing.4")
}
return {
[`--hero-${name}`]: `url('data:image/svg+xml;utf8,${content}')`,
"-webkit-mask": `var(--hero-${name})`,
"mask": `var(--hero-${name})`,
"mask-repeat": "no-repeat",
"background-color": "currentColor",
"vertical-align": "middle",
"display": "inline-block",
"width": size,
"height": size
}
}
}, {values})
})
]
}
6 changes: 3 additions & 3 deletions lib/atomic/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ defmodule Atomic.Schema do
@moduledoc """
The application Schema for all the modules, providing Ecto.UUIDs as default id.
"""
alias Atomic.Time
use Gettext, backend: AtomicWeb.Gettext

import AtomicWeb.Gettext
alias Atomic.Time

defmacro __using__(_) do
quote do
use Ecto.Schema
use Waffle.Ecto.Schema
use Gettext, backend: AtomicWeb.Gettext

import AtomicWeb.Gettext
import Ecto.Changeset
import Ecto.Query

Expand Down
9 changes: 6 additions & 3 deletions lib/atomic_web.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ defmodule AtomicWeb do
def controller do
quote do
use Phoenix.Controller, namespace: AtomicWeb
use Gettext, backend: AtomicWeb.Gettext

import Plug.Conn
import AtomicWeb.Gettext

alias AtomicWeb.Router.Helpers, as: Routes
end
end
Expand Down Expand Up @@ -80,7 +81,7 @@ defmodule AtomicWeb do
def channel do
quote do
use Phoenix.Channel
import AtomicWeb.Gettext
use Gettext, backend: AtomicWeb.Gettext
end
end

Expand All @@ -99,8 +100,10 @@ defmodule AtomicWeb do
# Import basic rendering functionality (render, render_layout, etc)
import Phoenix.View

# Custom imports
use Gettext, backend: AtomicWeb.Gettext

import AtomicWeb.ErrorHelpers
import AtomicWeb.Gettext
import AtomicWeb.Helpers

alias Atomic.Uploaders
Expand Down
6 changes: 3 additions & 3 deletions lib/atomic_web/components/activity.ex
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,21 @@ defmodule AtomicWeb.Components.Activity do
<div class="flex space-x-4">
<span class="inline-flex items-center text-sm">
<span class="inline-flex space-x-2 text-zinc-400">
<.icon name={:clock} solid class="h-5 w-5" />
<.icon name="hero-clock-solid" class="size-5" />
<span class="font-medium text-gray-900"><%= relative_datetime(@activity.start) %></span>
<span class="sr-only">starting in</span>
</span>
</span>
<span class="inline-flex items-center text-sm">
<span class="inline-flex space-x-2 text-zinc-400">
<.icon name={:user_group} solid class="h-5 w-5" />
<.icon name="hero-user-group-solid" class="size-5" />
<span class="font-medium text-gray-900"><%= @activity.enrolled %>/<%= @activity.maximum_entries %></span>
<span class="sr-only">enrollments</span>
</span>
</span>
<span class="inline-flex items-center text-sm">
<span class="inline-flex space-x-2 text-zinc-400">
<.icon name={:map_pin} solid class="h-5 w-5" />
<.icon name="hero-map-pin-solid" class="size-5" />
<span class="font-medium text-gray-900"><%= @activity.location.name %></span>
<span class="sr-only">location</span>
</span>
Expand Down
21 changes: 10 additions & 11 deletions lib/atomic_web/components/badge.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,18 @@ defmodule AtomicWeb.Components.Badge do
default: :left,
doc: "The position of the icon if applicable."

attr :icon, :atom, default: nil, doc: "The icon to display."

attr :icon_variant, :atom,
default: :outline,
values: [:solid, :outline, :mini],
doc: "The icon variation to display."

attr :icon, :string, default: nil, doc: "The icon to display."
attr :icon_class, :string, default: "", doc: "Additional classes to apply to the icon."

attr :class, :string, default: "", doc: "Additional classes to apply to the badge."
attr :label, :string, default: nil, doc: "Badge label."
attr :rest, :global
slot :inner_block, required: false

attr :rest, :global,
include:
~w(csrf_token disabled download form href hreflang method name navigate patch referrerpolicy rel replace target type value autofocus tabindex),
doc: "Arbitrary HTML or phx attributes."

slot :inner_block, required: false, doc: "Slot for the content of the badge."

def badge(assigns) do
~H"""
Expand All @@ -50,11 +49,11 @@ defmodule AtomicWeb.Components.Badge do
]}
>
<%= if @icon && @icon_position == :left do %>
<.icon name={@icon} class={"#{generate_icon_classes(assigns)}"} solid={@icon_variant == :solid} mini={@icon_variant == :mini} />
<.icon name={@icon} class={"#{generate_icon_classes(assigns)}"} />
<% end %>
<%= render_slot(@inner_block) || @label %>
<%= if @icon && @icon_position == :right do %>
<.icon name={@icon} class={"#{generate_icon_classes(assigns)}"} solid={@icon_variant == :solid} mini={@icon_variant == :mini} />
<.icon name={@icon} class={"#{generate_icon_classes(assigns)}"} />
<% end %>
</div>
"""
Expand Down
10 changes: 2 additions & 8 deletions lib/atomic_web/components/button.ex
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,7 @@ defmodule AtomicWeb.Components.Button do
default: :left,
doc: "The position of the icon if applicable."

attr :icon, :atom, default: nil, doc: "The icon to display."

attr :icon_variant, :atom,
default: :outline,
values: [:solid, :outline, :mini],
doc: "The icon variation to display."

attr :icon, :string, default: nil, doc: "The icon to display."
attr :icon_class, :string, default: "", doc: "Additional classes to apply to the icon."

attr :class, :string, default: "", doc: "Additional classes to apply to the component."
Expand Down Expand Up @@ -127,7 +121,7 @@ defmodule AtomicWeb.Components.Button do

defp icon_content(assigns) do
~H"""
<.icon name={@icon} class={"#{generate_icon_classes(assigns)}"} solid={@icon_variant == :solid} mini={@icon_variant == :mini} />
<.icon name={@icon} class={"#{generate_icon_classes(assigns)}"} />
"""
end

Expand Down
8 changes: 4 additions & 4 deletions lib/atomic_web/components/calendar/calendar.ex
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ defmodule AtomicWeb.Components.Calendar do
<.link patch={"#{if @mode == "month" do @previous_month_path else @previous_week_path end}"}>
<button type="button" class="flex items-center justify-center py-2 pr-4 pl-3 text-zinc-400 hover:bg-zinc-50 hover:text-zinc-500 focus:relative md:w-9 md:px-2">
<span class="sr-only">Previous month</span>
<.icon name={:chevron_left} solid class="h-3 w-3 sm:h-5 sm:w-5" />
<.icon name="hero-chevron-left-solid" class="size-3 sm:h-5 sm:w-5" />
</button>
</.link>
<.link patch={"#{if @mode == "month" do @present_month_path else @present_week_path end}"}>
Expand All @@ -80,7 +80,7 @@ defmodule AtomicWeb.Components.Calendar do
<.link patch={"#{if @mode == "month" do @next_month_path else @next_week_path end}"}>
<button type="button" class="flex items-center justify-center py-2 pr-3 pl-4 text-zinc-400 hover:bg-zinc-50 hover:text-zinc-500 focus:relative md:w-9 md:px-2">
<span class="sr-only">Next month</span>
<.icon name={:chevron_right} solid class="h-3 w-3 sm:h-5 sm:w-5" />
<.icon name="hero-chevron-right-solid" class="size-3 sm:h-5 sm:w-5" />
</button>
</.link>
</div>
Expand All @@ -95,7 +95,7 @@ defmodule AtomicWeb.Components.Calendar do
]}
>
<:wrapper>
<.button color={:white} icon={:chevron_down} icon_position={:right} icon_variant={:solid}>
<.button color={:white} icon="hero-chevron-down-solid" icon_position={:right}>
<%= if @mode == "month" do %>
<%= gettext("Month view") %>
<% else %>
Expand Down Expand Up @@ -150,7 +150,7 @@ defmodule AtomicWeb.Components.Calendar do
<div class="relative ml-6 md:hidden">
<button type="button" @click="mode_view = !mode_view" class="-mx-2 flex items-center rounded-full border border-transparent p-2 text-zinc-400 hover:text-zinc-500" id="menu-0-button" aria-expanded="false" aria-haspopup="true">
<span class="sr-only">Open menu</span>
<.icon name={:ellipsis_horizontal} solid class="h-3 w-3 sm:h-5 sm:w-5" />
<.icon name="hero-ellipsis-horizontal-solid" class="size-3 sm:h-5 sm:w-5" />
</button>
<div x-bind:class="mode_view ?'block' : 'hidden'" class="absolute right-0 mt-3 w-36 origin-top-right divide-y divide-zinc-100 overflow-hidden rounded-md bg-white shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none">
<div class="py-1" role="none">
Expand Down
6 changes: 3 additions & 3 deletions lib/atomic_web/components/calendar/month.ex
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ defmodule AtomicWeb.Components.CalendarMonth do
<.badge variant={:outline} color={:primary} label="Activity" />
</.link>
<time datetime={activity.start} class="flex items-center text-zinc-700">
<.icon name={:clock} solid class="mr-2 h-5 w-5 text-zinc-400" />
<.icon name="hero-clock-solid" class="size-5 mr-2 text-zinc-400" />
<%= Calendar.strftime(activity.start, "%Hh%M") %>
</time>
</div>
Expand Down Expand Up @@ -99,7 +99,7 @@ defmodule AtomicWeb.Components.CalendarMonth do
<div class={@class}>
<time date-time={@date} class={
"ml-auto lg:ml-0 pr-2 lg:pr-0 #{if @today? == 0 do
"flex h-6 w-6 items-center justify-center rounded-full bg-orange-400 font-semibold text-white shrink-0"
"flex size-6 items-center justify-center rounded-full bg-orange-400 font-semibold text-white shrink-0"
end}"
}>
<%= @text %>
Expand All @@ -122,7 +122,7 @@ defmodule AtomicWeb.Components.CalendarMonth do
date-time={@date}
class={
"ml-auto lg:ml-0 #{if current_from_params(@timezone, @params) == @date do
"ml-auto flex h-6 w-6 items-center justify-center rounded-full #{if @today? == 0 do
"ml-auto flex size-6 items-center justify-center rounded-full #{if @today? == 0 do
"bg-orange-700"
else
"bg-zinc-900"
Expand Down
9 changes: 2 additions & 7 deletions lib/atomic_web/components/dropdown.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ defmodule AtomicWeb.Components.Dropdown do

attr :items, :list, default: [], doc: "The items to display in the dropdown."

attr :icon_variant, :atom,
default: :outline,
values: [:solid, :outline, :mini],
doc: "The icon variation to display."

attr :orientation, :atom,
default: :down,
doc: "The orientation of the dropdown.",
Expand Down Expand Up @@ -51,14 +46,14 @@ defmodule AtomicWeb.Components.Dropdown do
method={Map.get(item, :method, "get")}
>
<%= if item[:icon] do %>
<.icon solid={@icon_variant == :solid} mini={@icon_variant == :mini} name={item.icon} class="ml-2 inline-block h-5 w-5" />
<.icon name={item.icon} class="size-5 ml-2 inline-block" />
<% end %>
<%= item.name %>
</.link>
<% else %>
<div class={"#{item[:class]} flex items-center gap-x-2 px-4 py-2 text-sm text-gray-700"}>
<%= if item[:icon] do %>
<.icon solid={@icon_variant == :solid} mini={@icon_variant == :mini} name={item.icon} class="ml-2 inline-block h-5 w-5" />
<.icon name={item.icon} class="size-5 ml-2 inline-block" />
<% end %>
<%= item.name %>
</div>
Expand Down
4 changes: 2 additions & 2 deletions lib/atomic_web/components/empty.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ defmodule AtomicWeb.Components.Empty do
def empty_state(assigns) do
~H"""
<div id={@id} class="text-center">
<.icon name={:plus_circle} class="mx-auto h-12 w-12 text-zinc-400" />
<.icon name="hero-plus-circle" class="size-12 mx-auto text-zinc-400" />
<h3 class="mt-2 text-sm font-semibold text-zinc-900">No <%= plural(@placeholder) %></h3>
<p class="mt-1 text-sm text-zinc-500">Get started by creating a new <%= @placeholder %>.</p>
<div class="mt-4">
<.link navigate={@url} class="inline-flex items-center rounded-md bg-orange-500 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-orange-600 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-orange-500">
<svg class="mr-1.5 -ml-0.5 h-5 w-5" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
<svg class="size-5 mr-1.5 -ml-0.5" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
<path d="M10.75 4.75a.75.75 0 00-1.5 0v4.5h-4.5a.75.75 0 000 1.5h4.5v4.5a.75.75 0 001.5 0v-4.5h4.5a.75.75 0 000-1.5h-4.5v-4.5z" />
</svg>
New <%= @placeholder %>
Expand Down
Loading
Loading