PineUiPhoenix (Pine UI v0.2.1)

Copy Markdown View Source

Pine UI 🌲 — the Pines component library for Phoenix LiveView.

Pines is an Alpine.js + Tailwind CSS component library. This package ports it to Phoenix function components, with declarative attr/slot APIs, dark mode, and the LiveView plumbing that Alpine needs in order to survive DOM patching.

Installation

def deps do
  [{:pine_ui_phoenix, "~> 0.2.0"}]
end

Three further steps are required — the components will not work without them. They are covered in full in the Installation guide:

  1. Tell Tailwind to scan this package, or every class it uses will be purged from your production build and the components will render unstyled.

    // Tailwind v3  tailwind.config.js
    content: [..., "../deps/pine_ui_phoenix/lib/**/*.ex"]
    
    /* Tailwind v4  app.css */
    @source "../../deps/pine_ui_phoenix/lib";
  2. Import the stylesheet, which carries the [x-cloak] rule that stops overlays flashing their contents on page load.

    @import "../../deps/pine_ui_phoenix/priv/static/pine_ui.css";
  3. Install Alpine and wire up pineDom(), so Alpine state survives LiveView patches.

    import { pineDom, PineHooks } from "../../deps/pine_ui_phoenix/priv/static/pine_ui.js"
    
    const liveSocket = new LiveSocket("/live", Socket, {
      params: { _csrf_token: csrfToken },
      hooks: { ...PineHooks },
      dom: pineDom()
    })

Usage

Import everything in your html_helpers/0:

defp html_helpers do
  quote do
    use PineUiPhoenix
    # ...
  end
end

Then use any component:

<.card title="Getting started">
  <p>Pine UI brings Pines to Phoenix.</p>
  <:footer>
    <.button>Read the docs</.button>
  </:footer>
</.card>

Avoiding name collisions

A stock Phoenix 1.7/1.8 app generates a CoreComponents module with its own <.button>, <.table> and <.modal>. Since both are imported into the same scope, you must resolve the clash one of three ways:

use PineUiPhoenix, except: [:button, :table, :modal]
use PineUiPhoenix, only: [:command, :marquee, :rating]
use PineUiPhoenix, prefix: :pine   # <.pine_button>, <.pine_table>

prefix: generates delegating wrappers, which means the prefixed calls lose compile-time attribute validation. only:/except: keep it, so prefer them where you can.

Upgrading from v0.1.x

Every v0.1.x function name still works and is re-exported here as a deprecated delegate, so upgrading does not break your templates. See the Upgrading to v0.2 guide for the old-to-new mapping.

Summary

Deprecated (v0.1.x)

Functions

The component registry: {key, module, [{function, arity}]} for every component.

Imports Pine UI components into the calling module.

Third-party JavaScript each component needs, keyed by registry key.

Deprecated (v0.1.x)

accordion_group(assigns)

This function is deprecated. Use the components under PineUiPhoenix.Components. See the Upgrading to v0.2 guide..

See PineUiPhoenix.Legacy.accordion_group/1.

accordion_item(assigns)

This function is deprecated. Use the components under PineUiPhoenix.Components. See the Upgrading to v0.2 guide..

See PineUiPhoenix.Legacy.accordion_item/1.

badge(assigns)

This function is deprecated. Use the components under PineUiPhoenix.Components. See the Upgrading to v0.2 guide..

See PineUiPhoenix.Legacy.badge/1.

badge_dismissible(assigns)

This function is deprecated. Use the components under PineUiPhoenix.Components. See the Upgrading to v0.2 guide..

See PineUiPhoenix.Legacy.badge_dismissible/1.

badge_dot(assigns)

This function is deprecated. Use the components under PineUiPhoenix.Components. See the Upgrading to v0.2 guide..

See PineUiPhoenix.Legacy.badge_dot/1.

button_danger(assigns)

This function is deprecated. Use the components under PineUiPhoenix.Components. See the Upgrading to v0.2 guide..

See PineUiPhoenix.Legacy.button_danger/1.

button_primary(assigns)

This function is deprecated. Use the components under PineUiPhoenix.Components. See the Upgrading to v0.2 guide..

See PineUiPhoenix.Legacy.button_primary/1.

button_secondary(assigns)

This function is deprecated. Use the components under PineUiPhoenix.Components. See the Upgrading to v0.2 guide..

See PineUiPhoenix.Legacy.button_secondary/1.

card(assigns)

This function is deprecated. Use the components under PineUiPhoenix.Components. See the Upgrading to v0.2 guide..

See PineUiPhoenix.Legacy.card/1.

card_collapsible(assigns)

This function is deprecated. Use the components under PineUiPhoenix.Components. See the Upgrading to v0.2 guide..

See PineUiPhoenix.Legacy.card_collapsible/1.

card_interactive(assigns)

This function is deprecated. Use the components under PineUiPhoenix.Components. See the Upgrading to v0.2 guide..

See PineUiPhoenix.Legacy.card_interactive/1.

context_menu(assigns)

This function is deprecated. Use the components under PineUiPhoenix.Components. See the Upgrading to v0.2 guide..

See PineUiPhoenix.Legacy.context_menu/1.

data_table(assigns)

This function is deprecated. Use the components under PineUiPhoenix.Components. See the Upgrading to v0.2 guide..

See PineUiPhoenix.Legacy.data_table/1.

data_table_expandable(assigns)

This function is deprecated. Use the components under PineUiPhoenix.Components. See the Upgrading to v0.2 guide..

See PineUiPhoenix.Legacy.data_table_expandable/1.

date_picker(assigns)

This function is deprecated. Use the components under PineUiPhoenix.Components. See the Upgrading to v0.2 guide..

See PineUiPhoenix.Legacy.date_picker/1.

date_range_picker(assigns)

This function is deprecated. Use the components under PineUiPhoenix.Components. See the Upgrading to v0.2 guide..

See PineUiPhoenix.Legacy.date_range_picker/1.

file_uploader(assigns)

This function is deprecated. Use the components under PineUiPhoenix.Components. See the Upgrading to v0.2 guide..

See PineUiPhoenix.Legacy.file_uploader/1.

image_carousel(assigns)

This function is deprecated. Use the components under PineUiPhoenix.Components. See the Upgrading to v0.2 guide..

See PineUiPhoenix.Legacy.image_carousel/1.

image_gallery(assigns)

This function is deprecated. Use the components under PineUiPhoenix.Components. See the Upgrading to v0.2 guide..

See PineUiPhoenix.Legacy.image_gallery/1.

image_uploader(assigns)

This function is deprecated. Use the components under PineUiPhoenix.Components. See the Upgrading to v0.2 guide..

See PineUiPhoenix.Legacy.image_uploader/1.

modal(assigns)

This function is deprecated. Use the components under PineUiPhoenix.Components. See the Upgrading to v0.2 guide..

See PineUiPhoenix.Legacy.modal/1.

multi_file_uploader(assigns)

This function is deprecated. Use the components under PineUiPhoenix.Components. See the Upgrading to v0.2 guide..

See PineUiPhoenix.Legacy.multi_file_uploader/1.

pagination(assigns)

This function is deprecated. Use the components under PineUiPhoenix.Components. See the Upgrading to v0.2 guide..

See PineUiPhoenix.Legacy.pagination/1.

pagination_load_more(assigns)

This function is deprecated. Use the components under PineUiPhoenix.Components. See the Upgrading to v0.2 guide..

See PineUiPhoenix.Legacy.pagination_load_more/1.

pagination_simple(assigns)

This function is deprecated. Use the components under PineUiPhoenix.Components. See the Upgrading to v0.2 guide..

See PineUiPhoenix.Legacy.pagination_simple/1.

progress_bar(assigns)

This function is deprecated. Use the components under PineUiPhoenix.Components. See the Upgrading to v0.2 guide..

See PineUiPhoenix.Legacy.progress_bar/1.

progress_circle(assigns)

This function is deprecated. Use the components under PineUiPhoenix.Components. See the Upgrading to v0.2 guide..

See PineUiPhoenix.Legacy.progress_circle/1.

progress_steps(assigns)

This function is deprecated. Use the components under PineUiPhoenix.Components. See the Upgrading to v0.2 guide..

See PineUiPhoenix.Legacy.progress_steps/1.

select(assigns)

This function is deprecated. Use the components under PineUiPhoenix.Components. See the Upgrading to v0.2 guide..

See PineUiPhoenix.Legacy.select/1.

select_grouped(assigns)

This function is deprecated. Use the components under PineUiPhoenix.Components. See the Upgrading to v0.2 guide..

See PineUiPhoenix.Legacy.select_grouped/1.

select_searchable(assigns)

This function is deprecated. Use the components under PineUiPhoenix.Components. See the Upgrading to v0.2 guide..

See PineUiPhoenix.Legacy.select_searchable/1.

switch(assigns)

This function is deprecated. Use the components under PineUiPhoenix.Components. See the Upgrading to v0.2 guide..

See PineUiPhoenix.Legacy.switch/1.

switch_card(assigns)

This function is deprecated. Use the components under PineUiPhoenix.Components. See the Upgrading to v0.2 guide..

See PineUiPhoenix.Legacy.switch_card/1.

switch_labeled(assigns)

This function is deprecated. Use the components under PineUiPhoenix.Components. See the Upgrading to v0.2 guide..

See PineUiPhoenix.Legacy.switch_labeled/1.

tabs(assigns)

This function is deprecated. Use the components under PineUiPhoenix.Components. See the Upgrading to v0.2 guide..

See PineUiPhoenix.Legacy.tabs/1.

tabs_boxed(assigns)

This function is deprecated. Use the components under PineUiPhoenix.Components. See the Upgrading to v0.2 guide..

See PineUiPhoenix.Legacy.tabs_boxed/1.

tabs_pills(assigns)

This function is deprecated. Use the components under PineUiPhoenix.Components. See the Upgrading to v0.2 guide..

See PineUiPhoenix.Legacy.tabs_pills/1.

text_animation_blow(assigns)

This function is deprecated. Use the components under PineUiPhoenix.Components. See the Upgrading to v0.2 guide..

See PineUiPhoenix.Legacy.text_animation_blow/1.

text_animation_fade(assigns)

This function is deprecated. Use the components under PineUiPhoenix.Components. See the Upgrading to v0.2 guide..

See PineUiPhoenix.Legacy.text_animation_fade/1.

text_input(assigns)

This function is deprecated. Use the components under PineUiPhoenix.Components. See the Upgrading to v0.2 guide..

See PineUiPhoenix.Legacy.text_input/1.

text_input_with_icon(assigns)

This function is deprecated. Use the components under PineUiPhoenix.Components. See the Upgrading to v0.2 guide..

See PineUiPhoenix.Legacy.text_input_with_icon/1.

textarea(assigns)

This function is deprecated. Use the components under PineUiPhoenix.Components. See the Upgrading to v0.2 guide..

See PineUiPhoenix.Legacy.textarea/1.

toast(assigns)

This function is deprecated. Use the components under PineUiPhoenix.Components. See the Upgrading to v0.2 guide..

See PineUiPhoenix.Legacy.toast/1.

toast_container(assigns)

This function is deprecated. Use the components under PineUiPhoenix.Components. See the Upgrading to v0.2 guide..

See PineUiPhoenix.Legacy.toast_container/1.

toast_trigger(assigns)

This function is deprecated. Use the components under PineUiPhoenix.Components. See the Upgrading to v0.2 guide..

See PineUiPhoenix.Legacy.toast_trigger/1.

tooltip(assigns)

This function is deprecated. Use the components under PineUiPhoenix.Components. See the Upgrading to v0.2 guide..

See PineUiPhoenix.Legacy.tooltip/1.

typing_effect(assigns)

This function is deprecated. Use the components under PineUiPhoenix.Components. See the Upgrading to v0.2 guide..

See PineUiPhoenix.Legacy.typing_effect/1.

Functions

__components__()

@spec __components__() :: [{atom(), module(), keyword(non_neg_integer())}]

The component registry: {key, module, [{function, arity}]} for every component.

Used by the demo app and by the cross-component contract tests, so neither can drift out of sync with what the library actually ships.

__using__(opts)

(macro)

Imports Pine UI components into the calling module.

Options

  • :only — import just these components, by registry key.
  • :except — import everything but these.
  • :prefix — an atom prepended to every function name, e.g. prefix: :pine gives <.pine_button>. Note that prefixed components are delegates, so they do not get compile-time attr validation.

:only and :except are mutually exclusive.

Alpine attributes

This macro also defines __global__?/1 on the calling module, registering x- as a global attribute prefix. Without it, every Alpine directive written at a call site —

<.dropdown x-on:keydown.escape="open = false">

— produces warning: undefined attribute "x-on:keydown.escape". The attribute is still forwarded to the component's @rest, so the page works; the cost is a noisy build, which --warnings-as-errors turns into a broken one.

Phoenix resolves global prefixes against the module containing the call site, which is why the library cannot register this centrally on its own modules.

If you already pass your own prefixes —

use Phoenix.Component, global_prefixes: ~w(x- data-my-)

— that definition wins and this macro leaves it alone. In that case include x- yourself. For the same reason, use PineUiPhoenix must come after use Phoenix.Component.

requirements()

@spec requirements() :: %{required(atom()) => [atom()]}

Third-party JavaScript each component needs, keyed by registry key.

Components absent from this map need nothing beyond Alpine core. Used to generate the requirements table in the installation guide, so the docs cannot drift from the code.

iex> PineUiPhoenix.requirements()[:modal]
[:alpine_focus]