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

Update elixir to 1.17 #7

Open
wants to merge 82 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
2c27bc1
Updated dependency versions
suranyami Jan 23, 2024
db79c1e
Merge pull request #1 from suranyami/deps_version_bump
suranyami Jan 23, 2024
f8dc597
Initial attempts at upgrading to phoenix_storybook
suranyami Jan 23, 2024
9cb3d70
Starting from scratch with the storybook
suranyami Jan 24, 2024
689cd89
Merge branch 'main' into deps_version_bump
suranyami Feb 19, 2024
54a3690
Merge pull request #2 from suranyami/deps_version_bump
suranyami Feb 19, 2024
32e8399
Add components for buttons, icons, table and module for colors
suranyami Feb 19, 2024
390a124
Add missing scss file for storybook
suranyami Feb 19, 2024
8cb7f72
Add my fontawesome free kit details
suranyami Feb 19, 2024
57fa7cc
made formatting consistent
suranyami Feb 19, 2024
2c9cc1a
Added more variations for buttons
suranyami Feb 19, 2024
3c9f5ba
Add icon story
suranyami Feb 19, 2024
d40eb47
Somewhat improved table story
suranyami Feb 19, 2024
fcae98c
Haven't started modal yet
suranyami Feb 19, 2024
e0b3201
Add color to action button
suranyami Feb 19, 2024
1cdf3f9
add gettext dependency outside of phoenix
suranyami Feb 19, 2024
aff1d82
Add credo
suranyami Feb 19, 2024
c65f4c7
Added missing `disabled` attr
suranyami Feb 19, 2024
6bd33a4
Add components for buttons, icons, table and module for colors
suranyami Feb 19, 2024
2474c87
Add missing scss file for storybook
suranyami Feb 19, 2024
1a51019
Add my fontawesome free kit details
suranyami Feb 19, 2024
2caf13b
made formatting consistent
suranyami Feb 19, 2024
6c14e51
Added more variations for buttons
suranyami Feb 19, 2024
8f8d397
Add icon story
suranyami Feb 19, 2024
e8e9054
Somewhat improved table story
suranyami Feb 19, 2024
f7643c3
Haven't started modal yet
suranyami Feb 19, 2024
5cb042f
Add color to action button
suranyami Feb 19, 2024
7f70d30
add gettext dependency outside of phoenix
suranyami Feb 19, 2024
c53e4a4
Add credo
suranyami Feb 19, 2024
2e84832
Added missing `disabled` attr
suranyami Feb 19, 2024
1894a6f
refactor Colors.rgb to Colors.theme
suranyami Feb 21, 2024
0182c81
Add `align` attr to icons for `is-right`, `is-left`
suranyami Feb 21, 2024
26680ce
remove tailwind markup from `simple_form`
suranyami Feb 21, 2024
14d5e4b
First attempt at checkbox, select, text inputs
suranyami Feb 21, 2024
8c13cd8
credo config, coz it's a good idea
suranyami Feb 21, 2024
478f8b9
removed vendor/assets/heroicons
suranyami Feb 21, 2024
c194af4
Fixed module names `Components` -> `CoreComponents`
suranyami Feb 21, 2024
2f78b14
remove unneeded `x` icon in close button
suranyami Feb 21, 2024
b8f89c1
fix checkbox nesting of label/input to match bulma (and best practice…
suranyami Feb 21, 2024
410e444
replace tailwind classes in inputs, icons and errors with bulma class…
suranyami Feb 21, 2024
1310e7c
use BulmaComponents instead of built-in Tailwind CoreComponents for I…
suranyami Feb 21, 2024
b01335d
Add email input type
suranyami Feb 21, 2024
9d4c21b
first attempt at getting modal to work: it doesn't
suranyami Feb 21, 2024
3e3cfce
Use `BulmaComponents` instead of Tailwind-based `CoreComponents`
suranyami Feb 21, 2024
7af5f2b
Merge branch 'more-stories' of github.com:suranyami/bulma_components …
suranyami Feb 21, 2024
210561d
Merge pull request #4 from suranyami/more-stories
suranyami Feb 22, 2024
5b94d5b
fix class for checkbox
suranyami Feb 22, 2024
2f6e630
Merge pull request #5 from suranyami/checkbox
suranyami Feb 22, 2024
bca30bc
Add missing <div class="select"> element
suranyami Feb 22, 2024
24f821d
only add icon classes if we have an icon or an error
suranyami Feb 22, 2024
76d5835
Add error icons only if needed
suranyami Feb 22, 2024
881eb53
Add color attr to inputs
suranyami Feb 22, 2024
a31348c
Remove unneeded import
suranyami Feb 22, 2024
30d9b93
add custom class field to icons
suranyami Feb 22, 2024
5d53324
move label to correct nesting in generic input
suranyami Feb 22, 2024
9b60e54
add icon_color and icon_size attributes to input
suranyami Feb 22, 2024
4601dc2
make error_icon and icon usage consistent
suranyami Feb 22, 2024
6197c79
checkbox should use standard input_classes
suranyami Feb 22, 2024
c6ffd7c
add conditional rendering of error_icon
suranyami Feb 22, 2024
1b95819
input class is a bit fiddly: checkbox and textarea are different to t…
suranyami Feb 22, 2024
1159c9e
add icon_align_class and icon_size_class functions
suranyami Feb 22, 2024
6d26bd1
add more detailed input examples
suranyami Feb 22, 2024
a826367
add uuid for making unique identifiers in input story
suranyami Feb 22, 2024
dad9180
add aliases for the storybook webapp
suranyami Feb 22, 2024
1b7427a
Merge pull request #6 from suranyami/input-details
suranyami Feb 22, 2024
082fe85
remove unused attribute
suranyami Feb 22, 2024
4de7ff4
Merge branch 'main' of github.com:suranyami/bulma_components
suranyami Feb 22, 2024
010f146
update
suranyami Jul 24, 2024
1ec331f
update
suranyami Jul 24, 2024
1eeafd5
removed irrelevant text in navbar, footer
suranyami Sep 16, 2024
7b051db
adds components for flash and flash_group notifications
suranyami Oct 11, 2024
c519666
Commented out definition_list for now
suranyami Oct 11, 2024
c7d16be
adds __using__ function for easy inclusion of library
suranyami Oct 11, 2024
d458bd2
fixed @import of bulma from @use
suranyami Oct 11, 2024
3bb9147
removed no longer needed `font: $family-primary !important`
suranyami Oct 11, 2024
c98c19c
add `gettext` config
suranyami Oct 11, 2024
c63e587
deletes `core_components`
suranyami Oct 11, 2024
c6ba913
adds `use` include
suranyami Oct 11, 2024
a088a9b
Revert "deletes `core_components`"
suranyami Oct 11, 2024
d77dff4
mostly working, but list and modal broken with duplicate import
suranyami Oct 13, 2024
e3f5191
experiencing very strange behaviour
suranyami Oct 13, 2024
3f00466
adds header size variants
suranyami Oct 13, 2024
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
Prev Previous commit
Next Next commit
Add components for buttons, icons, table and module for colors
  • Loading branch information
suranyami committed Feb 19, 2024
commit 32e839921c99cb4a4f869c5e152265303b650df7
53 changes: 0 additions & 53 deletions lib/bulma_components.ex
Original file line number Diff line number Diff line change
@@ -1,55 +1,2 @@
defmodule BulmaComponents do
@moduledoc """
Documentation for `BulmaComponents`.
"""

@rgb [
:primary,
:link,
:info,
:success,
:warning,
:danger
]

@monochrome [
:white,
:light,
:dark,
:black,
:text,
:ghost
]

@colors @rgb ++ @monochrome

@doc """
Returns a list of Bulma `$colors` as atoms.

## Examples

iex> BulmaComponents.colors()
#{inspect(@colors)}
"""
def colors, do: @colors

@doc """
Returns a list of monochrome colors as atoms.

## Examples

iex> BulmaComponents.monochrome()
#{inspect(@monochrome)}
"""
def monochrome, do: @monochrome

@doc """
Returns a list of rgb colors as atoms.

## Examples

iex> BulmaComponents.rgb()
#{inspect(@rgb)}
"""
def rgb, do: @rgb
end
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
defmodule BulmaComponents.Elements do
defmodule BulmaComponents.Button do
@moduledoc """
Element components.
Button component.
"""
use Phoenix.Component
alias BulmaComponents.Colors

def imports, do: [{BulmaComponents.Icon, [icon: 1]}]

@doc """
Renders a button element.
Expand Down Expand Up @@ -35,7 +38,7 @@ defmodule BulmaComponents.Elements do
attr :size, :atom, default: nil, values: [nil, :small, :normal, :medium, :large]
attr :responsive, :boolean, default: false, doc: "Different sizes for each breakpoint"
# Colors
attr :color, :atom, default: nil, values: [nil | BulmaComponents.colors()]
attr :color, :atom, default: nil, values: [nil | Colors.colors()]
attr :light, :boolean, default: false, doc: "Light color variant"
# States
attr :hovered, :boolean, default: false
Expand Down
51 changes: 51 additions & 0 deletions lib/bulma_components/colors.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
defmodule BulmaComponents.Colors do
@rgb [
:primary,
:link,
:info,
:success,
:warning,
:danger
]

@monochrome [
:white,
:light,
:dark,
:black,
:text,
:ghost
]

@colors @rgb ++ @monochrome

@doc """
Returns a list of Bulma `$colors` as atoms.

## Examples

iex> CoreComponents.colors()
#{inspect(@colors)}
"""
def colors, do: @colors

@doc """
Returns a list of monochrome colors as atoms.

## Examples

iex> CoreComponents.monochrome()
#{inspect(@monochrome)}
"""
def monochrome, do: @monochrome

@doc """
Returns a list of rgb colors as atoms.

## Examples

iex> CoreComponents.rgb()
#{inspect(@rgb)}
"""
def rgb, do: @rgb
end
64 changes: 64 additions & 0 deletions lib/bulma_components/icon.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
defmodule BulmaComponents.Icon do
use Phoenix.Component

@doc """
Renders a [FontAwesome Icon](https://fontawesome.com).

## Examples

<.icon name="home" />
<.icon name="spinner" class="fas fa-spinner fa-pulse" />
"""
attr :name, :string, required: true
attr :class, :string, default: nil
attr :color, :string, default: nil
attr :size, :atom, default: nil, values: [nil, :small, :normal, :medium, :large]
attr :title, :string, default: nil
attr :fixed_width, :boolean, default: false
attr :bordered, :boolean, default: false
attr :spin, :boolean, default: false

def icon(%{title: nil} = assigns) do
~H"""
<span class={icon_classes(assigns)}>
<i class={["fas", "fa-#{@name}"]}></i>
</span>
"""
end

def icon(%{title: title} = assigns) when title != nil do
~H"""
<span class={["icon-text"] ++ container_size_class(@size)}>
<span class={icon_classes(assigns)}>
<i class={["fas", "fa-#{@name}"]}></i>
</span>
<span><%= @title %></span>
</span>
"""
end

def icon_classes(assigns) do
["icon"] ++
color_class(assigns.color) ++
icon_size_class(assigns.size) ++
fixed_width_class(assigns.fixed_width) ++
bordered_class(assigns.bordered) ++
spin_class(assigns.spin)
end

def spin_class(false), do: []
def spin_class(true), do: ["fa-pulse"]
def bordered_class(false), do: []
def bordered_class(true), do: ["fa-border"]
def fixed_width_class(false), do: []
def fixed_width_class(true), do: ["fa-fw"]
def color_class(nil), do: []
def color_class(color), do: ["has-text-#{color}"]
def icon_size_class(nil), do: ["fa-lg"]
def icon_size_class(:small), do: []
def icon_size_class(:normal), do: ["fa-lg"]
def icon_size_class(:medium), do: ["fa-2x"]
def icon_size_class(:large), do: ["fa-3x"]
def container_size_class(nil), do: []
def container_size_class(size), do: ["is-#{size}"]
end
118 changes: 118 additions & 0 deletions lib/bulma_components/modal.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
defmodule BulmaComponents.Modal do
@moduledoc """
Modal component.
"""
use Phoenix.Component
alias Phoenix.LiveView.JS
import BulmaComponents.Icon

@doc """
Renders a modal.

## Examples

<.modal id="confirm-modal">
This is a modal.
</.modal>

JS commands may be passed to the `:on_cancel` to configure
the closing/cancel event, for example:

<.modal id="confirm" on_cancel={JS.navigate(~p"/posts")}>
This is another modal.
</.modal>

"""
attr :id, :string, required: true
attr :show, :boolean, default: false
attr :on_cancel, JS, default: %JS{}
slot :inner_block, required: true

def modal(assigns) do
~H"""
<div
class="modal"
id={@id}
phx-mounted={@show && show_modal(@id)}
phx-remove={hide_modal(@id)}
data-cancel={JS.exec(@on_cancel, "phx-remove")}
>
<div id={"#{@id}-bg"} aria-hidden="true" class="modal-background"></div>
<.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}")}
>
<div
class="modal-content"
id={"#{@id}-content"}
aria-labelledby={"#{@id}-title"}
aria-describedby={"#{@id}-description"}
role="dialog"
aria-modal="true"
tabindex="0"
>
<%= render_slot(@inner_block) %>
</div>
</.focus_wrap>
<button
class="modal-close is-large"
phx-click={JS.exec("data-cancel", to: "##{@id}")}
aria-label="close"
type="button"
aria-label="close"
>
<.icon name="hero-x-mark-solid" class="h-5 w-5" />
</button>
</div>
"""
end

## JS Commands

def show(js \\ %JS{}, selector) do
JS.show(js,
to: selector,
transition:
{"transition-all transform ease-out duration-300",
"opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95",
"opacity-100 translate-y-0 sm:scale-100"}
)
end

def hide(js \\ %JS{}, selector) do
JS.hide(js,
to: selector,
time: 200,
transition:
{"transition-all transform ease-in duration-200",
"opacity-100 translate-y-0 sm:scale-100",
"opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"}
)
end

def show_modal(js \\ %JS{}, id) when is_binary(id) do
js
|> JS.show(to: "##{id}")
|> JS.show(
to: "##{id}-bg",
transition: {"transition-all transform ease-out duration-300", "opacity-0", "opacity-100"}
)
|> show("##{id}-container")
|> JS.add_class("overflow-hidden", to: "body")
|> JS.focus_first(to: "##{id}-content")
end

def hide_modal(js \\ %JS{}, id) do
js
|> JS.hide(
to: "##{id}-bg",
transition: {"transition-all transform ease-in duration-200", "opacity-100", "opacity-0"}
)
|> hide("##{id}-container")
|> JS.hide(to: "##{id}", transition: {"block", "block", "hidden"})
|> JS.remove_class("overflow-hidden", to: "body")
|> JS.pop_focus()
end
end
46 changes: 46 additions & 0 deletions lib/bulma_components/table.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
defmodule BulmaComponents.Table do
use Phoenix.Component

attr :rows, :list, doc: "Data you want to list", required: true
attr :bordered, :boolean, default: false
attr :striped, :boolean, default: false
attr :narrow, :boolean, default: false
attr :hoverable, :boolean, default: false
attr :fullwidth, :boolean, default: false

slot :col, doc: "Describe one of your table columns" do
attr :label, :string, doc: "Column label", required: true
end

@doc """
Simple table component.

"""
def table(assigns) do
~H"""
<table class={modifier_classes(assigns) ++ ["table"]}>
<thead>
<tr>
<th :for={col <- @col}><%= col.label %></th>
</tr>
</thead>
<tbody>
<tr :for={row <- @rows} class={selected_class(row)}>
<td :for={col <- @col}>
<%= render_slot(col, row) %>
</td>
</tr>
</tbody>
</table>
"""
end

def modifier_classes(assigns) do
Enum.filter([:bordered, :striped, :narrow, :hoverable, :fullwidth], fn key -> assigns[key] end)
|> Enum.map(fn key -> "is-#{key}" end)
end

def selected_class(row) do
if row[:selected], do: "is-selected", else: ""
end
end