ca1989

ca1989

Is CoreComponents a prelude of an official Phoenix components library?

Hi all,
just out of curiosity:

  • Is the CoreComponents module a prelude of an official Phoenix components library? Or are they just a great example of defining function components to be reused throughout our application.
  • Is there any point in the Phoenix roadmap to add an official set of components?

PS:

  • do you think that open sourcing components is a nice idea (if they don’t really have a specific feature that makes them stand out)?

I am asking because my fear is that a user could be baffled by having to choose between a pletora of similar component libraries (looking at you linux distros!)

I would love to hear your thoughts.

Thank you

Most Liked

Eiji

Eiji

I don’t think that components would be officially changed a lot. Phoenix core team prefers Tailwind and they are most probably not going to add support for let’s say Bootstrap or other CSS framework/library. Also the Tailwind styles are prepared for a default look of Phoenix applications.

It would be amazing if somebody would write a library that defines a set of components (i.e. HEEX + live part) and gives a user not only choice which framework/library to use, but also which theme should be applied.

import Config

config :my_app, MyApp.ComponentManager, default_theme: :theme_name, style: :bootstrap
defmodule MyApp.ComponentManager do
  use MyLib.ComponentManager, otp_app: :my_app

  component :custom_component, MyApp.Components.CustomComponent

  style :bootstrap, MyLib.Styles.Bootstrap
  # …

  theme :theme_name, MyApp.Themes.ThemeName
  # …

  manage config, %{profile: profile} do
    %{
      theme: profile.preferred_theme || config[:default_theme],
      # …
    }
  end

  prepare  _config, _component_module, data do
    data
  end
end
defimpl MyApp.Themes.ThemeName, for: MyLib.ComponentTheme.Button do
  def dark_variant(opts) do
    # …
  end

  def light_variant(opts) do
    # …
  end
end
defimpl MyLib.Styles.Bootstrap for: MyLib.Component.Button do
  def basic_style(opts) do
    type = opts[:type] || :primary
    # …
  end

  def render(assigns) do
    ~H"""
    <!-- … -->
    """
  end

  def sizing_style(opts) do
    # …
  end

  # …
end
alias MyApp.ComponentManager
<ComponentManager.button phx-click="…" profile={@current_user.profile} type: :primary>
  Button text …
</ComponentManager.button>
kokolegorille

kokolegorille

For example… the modal

  def modal(assigns) do
    assigns = assign_new(assigns, :patch, fn -> nil end)

    ~H"""
    <div id="modal" class="phx-modal fade-in" phx-remove={hide_modal()}>
      <div
        id="modal-content"
        class="phx-modal-content fade-in-scale"
        phx-click-away={JS.dispatch("click", to: "#close")}
        phx-window-keydown={JS.dispatch("click", to: "#close")}
        phx-key="escape"
      >
        <%= if @patch do %>
          <%= live_patch "✖", to: @patch, id: "close", class: "phx-modal-close", phx_click: hide_modal() %>
        <% else %>
         <a id="close" href="#" class="phx-modal-close" phx-click={hide_modal()}>✖</a>
        <% end %>

        <%= render_slot(@inner_block) %>
      </div>
    </div>
    """
  end

and the corresponding js code, where I changed transition classes

  defp hide_modal(js \\ %JS{}) do
    js
    |> JS.hide(to: "#modal", transition: "fade-out")
    |> JS.hide(to: "#modal-content", transition: "fade-out-scale")
  end
LostKobrakai

LostKobrakai

They try to be that while containing all the components needed to support the variuous generators phoenix ships with. They’re meant to be flexible enough to be used outside of that, but they primarily serve that usecase.

Where Next?

Popular in Discussions Top

matthias_toepp
I’d love to hear what people think about Wisp, the new Gleam web framework started by Gleam’s primary creator Louis Pilfold. Gleam, alon...
New
blackode
Elixir Upgrading is so Simple in Ubuntu and It worked for me Ubuntu 16.04 git clone https://github.com/elixir-lang/elixir.git cd elixir...
New
jeramyRR
This is an interesting article to read. Elixir’s performance, like usual, is excellent. However, it seems like the high CPU usage is co...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39467 209
New
mmport80
I have put far too much effort into Dialyzer over the last year or so - and basically - I doubt it’s worth the effort. It’s not as easy ...
New
AstonJ
If a newbie asked you about Phoenix Contexts, how would you explain the basics to them? Feel free to be as concise or in-depth as you li...
New
fireproofsocks
I’ve been working on an Elixir project that has required a lot of scripting. I usually reach for Elixir because I like it more (and in th...
New
AstonJ
If so I (and hopefully others!) might have some tips for you :slight_smile: But first, please say which area you’re finding most challen...
New
sashaafm
Piggy backing a bit on @dvcrn topic BEAM optimization for functions with static return type?, I’ve been trying to understand in a deeper ...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

Other popular topics Top

hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a &gt; b) do {:ok, "a"} end if (a &lt; b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement