UI components: using PhoenixKit's components in your own pages
Describes PhoenixKit 3.6.1. On an older release? The version menu above has this guide as it was then.
PhoenixKit’s admin is built from a library of function components styled with daisyUI: buttons, inputs, tables, modals, badges, tabs and more. A host app can use the same components so its own pages match the admin. This guide is for developers; there is no admin page for it.
Where to find it
The components live in the phoenix_kit package under lib/phoenix_kit_web/components/core/, one module per component, each documented in its @moduledoc. Larger pieces sit one level up, such as PhoenixKitWeb.Components.MediaBrowser.
What’s included
Among the components the core set brings:
- Forms:
input,select,textarea,checkbox,simple_form,date_input,decimal_input, form sections and actions. Translatable fields for multilingual forms are inPhoenixKitWeb.Components.MultilangForm. - Tables and lists:
table_default(with an optional card view for phones), tree tables, sortable headers, bulk selection, a column chooser, row menus, pagination anddraggable_listfor drag-and-drop ordering. - Feedback and layout:
button,badge,modal,flash,empty_state(compact, card or featured), stat cards, charts, nav tabs, accordions, popovers and status dots. - Media: file upload, media thumbnails and the embeddable
MediaBrowserwith folders, upload, search and trash. - Forms that send mail:
turnstile_widget, the Cloudflare Turnstile check. Put<.turnstile_widget id="…" />inside your own public form and callPhoenixKitWeb.Users.BotCheck.run/3first in its submit handler. It renders nothing while Turnstile is off (Settings > Authorization > Abuse protection).
nav_tabs can keep a long strip of tabs on one row: overflow={:menu} moves the tabs that do not fit into a trailing “⋯” menu, and the active tab always stays in the strip. It needs an id. The default, overflow={:wrap}, wraps onto more rows as before.
Using them in a host app
Host LiveViews get nothing from PhoenixKit automatically; importing is a deliberate step. Either import single modules:
import PhoenixKitWeb.Components.Core.TableDefault
import PhoenixKitWeb.Components.Core.EmptyState
or bring in the whole core set the way PhoenixKit’s own views do:
use PhoenixKitWeb, :core_components
Since 3.6.0 PhoenixKit’s JavaScript comes in two parts. phoenix_kit.js holds what public pages use; the admin and user-dashboard hooks are in phoenix_kit_admin.js, which is fetched the first time a page mounts one of them. A host that uses the :phoenix_kit_js_sources compiler changes nothing; any other host runs mix phoenix_kit.update once, or the admin hooks do nothing. A component such as nav_tabs with overflow={:menu} on a public page of your own works once the admin part has loaded, not at page load. Chart.js is no longer on window.Chart at page load: window.PhoenixKitLibraries.chartjs() returns it.
A mix phx.new app already has its own button/1 and other helpers in CoreComponents. When both are in scope, the names clash. Exclude yours on import (import MyAppWeb.CoreComponents, except: [button: 1]) or delete the scaffold’s version.
The media browser has a helper that sets up uploads in one line:
use PhoenixKitWeb.Components.MediaBrowser.Embed
What it doesn’t do
- There is no gallery page of the components inside the admin. Read each module’s documentation, or the admin’s own templates, for examples.
- The components are styled with Tailwind and daisyUI classes, so the host app’s asset build must include them.