Guide
JavaScript
The package script exposes one object, tallkit, with the helpers the components use: toasts, modals, announcements, the appearance, the consent signal, tooltips and asset loading. Your own scripts and Alpine expressions can call the same helpers.
The tallkit object
The script defines it as window.tallkit, also reachable as window.TALLKit, and dispatches tallkit:init on the document right after. In Alpine expressions it is the $tallkit magic, or the shorter $tk, and the tallkit store ($store.tallkit); the three are the same object.
Nothing to show
Nothing to show
With the ESM plugin, the object is also the named export tallkit of tallkit.esm.js, and window.tallkit is set when the plugin is registered. If the injected script tag loaded too (inject_assets left on), the plugin hands over to it and the imported object is a second, unused copy: changes made on it, like tallkit.tooltip.configure() or tallkit.appearance, don't reach the page. Set inject_assets to false, or use window.tallkit.
| Member | What it does |
|---|---|
toast(...) |
Shows a toast and returns its id. See Toasts. |
modal(name) |
.show() and .close() open and close every modal with that name. |
modals() |
.close() closes every open modal. |
announce(text, priority = 'polite') |
Reads text through a shared, visually hidden live region; 'assertive' for something urgent. Texts sent together are read as one message. |
copy(text) |
Copies text to the clipboard and resolves to true when it was copied. Works on plain HTTP too, where navigator.clipboard does not exist. tk:copyable uses it. |
appearance |
Light and dark mode. See Appearance. |
consent(state = 'granted') |
Records the user's consent for Google's tags: anything but 'granted' counts as 'denied'. consent.state() returns the stored choice, or null. See Google. |
tooltip |
configure(), show(), hide() and refresh(). See Tooltips. |
loadScript(src, { integrity, crossorigin }) |
Adds a <script> once and returns a promise that resolves when it loads. An array loads the scripts in order. |
loadStyle(href, { integrity, crossorigin }) |
The same for a stylesheet. |
plugin(Alpine) |
Registers the package on an Alpine instance, as the default export of tallkit.esm.js does. |
loadScript() and loadStyle() give the tags the page's CSP nonce, and a URL already on the page, or already requested, is not added again.
Toasts
tallkit.toast() takes the same arguments as the PHP toast(): an object of options, or the message, title, type, duration, position, progress, size, invert, actions and id in that order. Called with no arguments, it returns one method per type:
Nothing to show
success(), error(), info(), warning() and loading() take the same arguments as toast(). toast() and these shortcuts return the toast's id: the one given in the options object (loading({ message: 'Exporting...', id: 'export' })), or a generated one. promise() returns the promise. A loading toast stays until it is closed by its id. Toasts sent before the toast area is on the page wait for it. See Toast.
Modals
Nothing to show
tallkit.modal(name).show() and .close() reach every modal with that name on the page; tallkit.modals().close() closes all of them. From PHP, $this->modal($name) in a Livewire component reaches only the modals that component renders, and TALLKit::modal($name) outside Livewire opens the modal on the next page. See Modal.
Tooltips
Elements get a tooltip from the tooltip prop of the components (see Element), or from the x-tooltip directive on any element:
Nothing to show
The expression is the text and is reactive: null, false or '' removes the tooltip. The modifiers set the position (.top, .bottom, .left, .right), the alignment (.start, .center, .end), .arrow or .no-arrow, .manual, which opens the tooltip only through tallkit.tooltip.show(), and .click, which opens and closes it on a click or tap instead of on hover (it closes on a click elsewhere or Escape), for a hint the user asks for. On a component, tooltip:open="click" does the same. While a tooltip is open, the pointer can move onto it and it stays open, so its content can be selected.
| Method | What it does |
|---|---|
configure(options) |
Changes the defaults: delay (milliseconds, or a string such as '1s'), position, align, arrow, variant (null, 'accent', 'inverse') and size (null, 'xs', 'sm', 'lg', 'xl'). The script tag passes the ones from config('tallkit.tooltip'). |
show(el, text = null) |
Opens the tooltip of el, as with .manual. With text, that text replaces the tooltip's while it is open. |
hide(el = null) |
Closes the open tooltip, or only the one of el. |
refresh() |
Links every tooltip to its element again (aria-describedby), for markup added without Alpine or Livewire. |
Two CSS variables, read from the trigger when its tooltip opens, change the panel: --tallkit-tooltip-max-width (default 20rem) and --tallkit-tooltip-duration, the fade (default 100ms). Set them on the trigger, on a parent or on :root:
Nothing to show
Document events
The package names its events with the tallkit: prefix (TALLKit::eventName() in PHP). These are dispatched on, and listened for on, the document:
| Event | Detail | When |
|---|---|---|
tallkit:init |
The tallkit object is defined, before Alpine starts. |
|
tallkit:modal-show |
{ name } |
Opens the modals with that name. tallkit.modal(name).show() and $this->modal($name)->show() dispatch it. |
tallkit:modal-close |
{ name }, or {} |
Closes the modals with that name, or every open modal without one. |
tallkit:toast |
the toast options | Shows a toast. Prefer tallkit.toast(), which also waits for the toast area. |
tallkit:toast-close |
{ id } |
Closes the toast with that id. |
From a Livewire component, $this->dispatch('tallkit:modal-show', name: 'edit-user') reaches every modal with that name on the page, while $this->modal('edit-user')->show() reaches only the ones that component renders.
Components that take commands or report what happened through events document them on their own page:
tallkit:openandtallkit:closeon the trigger of a Dropdown or a Context menu.tallkit:dismisson an Alert, a Badge or a Notification item;tallkit:pauseandtallkit:resumeon an Alert.tallkit:sidebar-toggle,tallkit:sidebar-close,tallkit:sidebar-state,tallkit:sidebar-collapseandtallkit:sidebar-collapsedfor the Sidebar.tallkit:table-resetfor the Table.tallkit:consentafterconsent().- The events without a prefix (
picked,changed,loaded...) in the Events section of each component.