return function () {
$fw = html5fw();
$e = fn ($s) => htmlspecialchars((string) $s, ENT_QUOTES);
$tw_url = _class('docs')->_bs_switch_url('tw');
$intro = '<p class="docs-demo-intro">The Tailwind CSS driver (plugin <code>tailwind</code>, <code>css_framework</code> <code>tw</code>, a preview):
daisyUI 5 component classes on Tailwind CSS 4, a stylesheet prebuilt from the driver\'s class map (no build on the site), and
Alpine.js (its CSP build) for dropdowns, modals, tabs and collapses. It is opt-in: Bootstrap 3 and 5 pages are unchanged.
See the docs page <a href="' . $e(url('/@object/misc/html5fw_drivers')) . '#html5fw-tailwind">CSS-framework drivers</a>.</p>';
if ( ! $fw->is('tw')) {
return $intro . '<p>This page shows the components under the driver: <a class="btn btn-primary" id="demo-tw-switch" href="' . $e($tw_url) . '">Open it with Tailwind CSS</a>
(<code>?bs=tw</code>; the framework switcher in the navbar goes back).</p>';
}
$c = fn ($component, $variant = '', $opts = []) => $e($fw->classes($component, $variant, $opts));
$buttons = '';
foreach (['default', 'primary', 'success', 'info', 'warning', 'danger', 'link'] as $type) {
$buttons .= '<button type="button" class="' . $c('btn', $type) . '">' . $e($type) . '</button> ';
}
$buttons .= '<button type="button" class="' . $c('btn', 'primary', ['size' => 'xs']) . '">xs</button> ';
$buttons .= '<button type="button" class="' . $c('btn', 'primary', ['size' => 'sm']) . '">sm</button> ';
$buttons .= '<button type="button" class="' . $c('btn', 'primary', ['size' => 'lg']) . '">lg</button>';
$badges = '';
foreach (['default', 'primary', 'success', 'info', 'warning', 'important'] as $type) {
$badges .= '<span class="' . $c('badge', $type) . '">' . $e($type) . '</span> ';
}
$alerts = '';
foreach (['info', 'success', 'warning', 'error'] as $type) {
$alerts .= '<div role="alert" class="' . $c('alert', $type) . ' mb-2">' . $e(ucfirst($type)) . ': <code>classes(\'alert\', \'' . $e($type) . '\')</code></div>';
}
$modal = '<div x-data="yfModal">'
. '<button type="button" class="' . $c('btn', 'primary') . '" x-bind="opener" id="demo-tw-modal-open">Open a modal</button>'
. '<dialog x-ref="dialog" class="' . $c('modal') . '" id="demo-tw-modal" aria-labelledby="demo-tw-modal-title"><div class="' . $c('modal_dialog') . '">'
. '<div class="' . $c('modal_header') . '"><h3 class="' . $c('modal_title') . '" id="demo-tw-modal-title">A native dialog</h3></div>'
. '<div class="' . $c('modal_body') . '"><p><code><dialog></code> with <code>showModal()</code>: the page behind is inert, Escape closes it.</p></div>'
. '<div class="' . $c('modal_footer') . '"><button type="button" class="' . $c('btn', 'default') . '" x-bind="closer" id="demo-tw-modal-close">Close</button></div>'
. '</div></dialog></div>';
$dropdown = '<div class="' . $c('dropdown') . '" x-data="yfDropdown" x-bind="root">'
. '<button type="button" class="' . $c('btn', 'default') . '" x-bind="trigger" aria-haspopup="true" id="demo-tw-dropdown">Dropdown <i class="fa fa-caret-down" aria-hidden="true"></i></button>'
. '<ul class="' . $c('dropdown_menu') . '" x-ref="menu" x-bind="menu" id="demo-tw-dropdown-menu">'
. '<li><a href="#one">First item</a></li><li><a href="#two">Second item</a></li><li><a href="#three">Third item</a></li></ul></div>';
$tabs = '<div x-data="yfTabs"><div role="tablist" class="' . $c('nav_tabs') . '">'
. '<a role="tab" href="#" class="' . $c('nav_link') . ' tab-active" data-yf-tab="one" x-bind="tab" id="demo-tw-tab-one">One</a>'
. '<a role="tab" href="#" class="' . $c('nav_link') . '" data-yf-tab="two" x-bind="tab" id="demo-tw-tab-two">Two</a>'
. '<a role="tab" href="#" class="' . $c('nav_link') . '" data-yf-tab="three" x-bind="tab">Three</a></div>'
. '<div class="p-3" role="tabpanel" data-yf-panel="one" x-bind="panel">The first panel (<code>yfTabs</code>, arrow keys move between the tabs).</div>'
. '<div class="p-3" role="tabpanel" data-yf-panel="two" x-bind="panel" style="display:none" id="demo-tw-panel-two">The second panel.</div>'
. '<div class="p-3" role="tabpanel" data-yf-panel="three" x-bind="panel" style="display:none">The third panel.</div></div>';
$collapse = '<div x-data="yfCollapse"><button type="button" class="' . $c('btn', 'default', ['size' => 'sm']) . '" x-bind="trigger" id="demo-tw-collapse">Show more</button>'
. '<div x-show="open" x-collapse style="display:none" id="demo-tw-collapse-body"><p class="pt-2">Hidden text, opened with <code>x-collapse</code>.</p></div></div>';
$tooltip = '<span class="tooltip" data-tip="A CSS-only daisyUI tooltip"><button type="button" class="' . $c('btn', 'default', ['size' => 'sm']) . '">Hover me</button></span>';
$form = form(['name' => 'Ann', 'status' => '1'], ['class' => 'form-horizontal'])
->text('name', 'Name', ['tip' => 'A form2 text field'])
->select_box('colour', ['red' => 'Red', 'green' => 'Green'], ['desc' => 'Colour'])
->info('status', 'Status', ['badge' => ['1' => 'success', '0' => 'default']])
->info('status', 'Default badge', ['badge' => ['1' => 'default']]);
$data = array_slice(json_decode(file_get_contents(dirname(__DIR__) . '/table/products.json'), true), 0, 4, true);
$table = table($data, ['no_pages' => 1, 'no_total' => 1])
->text('name')
->text('price')
->text('active', 'State', ['badge' => ['1' => 'success', '0' => 'default']]);
$card = fn ($title, $body) => '<div class="' . $c('card') . ' mb-4"><div class="' . $c('card_header') . '">' . $e($title) . '</div><div class="' . $c('card_body') . '">' . $body . '</div></div>';
return $intro
. '<div class="grid grid-cols-1 gap-4 md:grid-cols-2" id="demo-tw">'
. $card('Buttons: classes(\'btn\', $type, [\'size\' => ...])', '<div class="flex flex-wrap gap-2">' . $buttons . '</div>')
. $card('Badges: classes(\'badge\', $type)', '<div class="flex flex-wrap gap-2">' . $badges . '</div>')
. $card('Alerts', $alerts)
. $card('Alpine.js components (yf_alpine)', '<div class="flex flex-wrap items-start gap-3">' . $modal . $dropdown . $tooltip . '</div><div class="mt-4">' . $tabs . '</div><div class="mt-2">' . $collapse . '</div>')
. '</div>'
. $card('form2 under the driver (form rows, select, badge option with a named variant)', (string) $form)
. $card('table2 under the driver', (string) $table);
};