mirror of
https://github.com/hunvreus/basecoat.git
synced 2026-11-18 16:08:19 +00:00
Most docs are complete
This commit is contained in:
+48
-47
@@ -6,8 +6,10 @@ toc:
|
||||
- label: Usage
|
||||
id: usage
|
||||
children:
|
||||
- label: Default
|
||||
id: usage-default
|
||||
- label: HTML
|
||||
id: usage-html
|
||||
- label: HTML + Javascript
|
||||
id: usage-js
|
||||
- label: Jinja or Nunjucks
|
||||
id: usage-jinja
|
||||
- label: Examples
|
||||
@@ -35,7 +37,7 @@ toc:
|
||||
</select>{% endset %}
|
||||
{{ code_preview("select-native", code_native) }}
|
||||
|
||||
{% set code_alpine %}
|
||||
{% set code_html %}
|
||||
{% call select(
|
||||
name="select-js",
|
||||
trigger_attrs={"class": "w-[180px]"},
|
||||
@@ -51,11 +53,16 @@ toc:
|
||||
</div>
|
||||
{% endcall %}
|
||||
{% endset %}
|
||||
{{ code_preview("select", code_alpine | prettyHtml) }}
|
||||
|
||||
{% set code_script %}
|
||||
{% include "components/select-script.njk" %}
|
||||
{% endset %}
|
||||
|
||||
{{ code_preview("combobox", code_script | prettyHtml ~ code_html | prettyHtml) }}
|
||||
|
||||
<h2 id="usage"><a href="#usage">Usage</a></h2>
|
||||
|
||||
<h3 id="usage-html"><a href="#usage-html">Pure HTML</a></h3>
|
||||
<h3 id="usage-html"><a href="#usage-html">HTML</a></h3>
|
||||
|
||||
<section class="prose my-6">
|
||||
<p>If you use a <code><select></code> element, just add the <code>select</code> class to it or have a parent with the <code>form</code> class (<a href="/components/form">read more about form</a>).</p>
|
||||
@@ -63,55 +70,49 @@ toc:
|
||||
|
||||
{{ code_block(code_native) }}
|
||||
|
||||
<h3 id="usage-js"><a href="#usage-js">With Javascript</a></h3>
|
||||
<h3 id="usage-js"><a href="#usage-js">HTML + Javascript</a></h3>
|
||||
|
||||
<div class="alert my-6">
|
||||
{% lucide "circle-alert" %}
|
||||
<h2>This component requires Javascript.</h2>
|
||||
<section>
|
||||
<p>You will need to include the Javascript (Alpine.js) code provided below before the HTML code for this component. As with all interactive components, you will need to add some Alpine.js properties to certain elements (e.g. <code class="text-xs">x-bind</code>, <code class="text-xs">x-data</code>, <code class="text-xs">@click</code>).</p>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<section class="prose my-6">
|
||||
<p>If you need to do more than what <code><select></code> allows (e.g. HTML options), you can use the code below which uses the <a href="/components/combobox">Popover</a> component. Make sure to include the hidden input with the name you want to use for that field.</p>
|
||||
<p>If you need to do more than what <code><select></code> allows (e.g. HTML options), you can use this component. It is structured as such:</p>
|
||||
<ul>
|
||||
<li>A <code><div class="popover"></code> which wraps around the entire component and holds it state (e.g. open/close).</li>
|
||||
<li>A <code><button></code> that acts as the trigger to open or close the popover.</li>
|
||||
<li>A <code><div data-popover></code> that holds the content of the popover.</li>
|
||||
<li>Inside of the <code><div data-popover></code> is a <code><nav role="listbox"></code> that contains a combination of:
|
||||
<ul>
|
||||
<li><code><div role="option"></code> for the options with a <code>data-value</code> attribute.</li>
|
||||
<li><code><hr role="separator"></code> to display a horizontal separator.</li>
|
||||
<li><code><div role="group"></code> to group options.</li>
|
||||
<li><code><span role="heading"></code> for group headings.</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>An <code><input type="hidden"></code> to hold the value of the field (if needed).</li>
|
||||
</ul>
|
||||
<p>As with the <a href="/components/popover">Popover</a> component, you can set up a few additional options on the <code><div data-popover></code> element:</p>
|
||||
<ul>
|
||||
<li><code>data-side</code> can be set to <code>top</code>, <code>bottom</code>, <code>left</code>, or <code>right</code> to change the side of the popover.</li>
|
||||
<li><code>data-align</code> can be set to <code>start</code>, <code>center</code>, or <code>end</code> to change the alignment of the popover.</li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
<h4 class="badge-secondary">HTML</h4>
|
||||
|
||||
<section class="prose my-6">
|
||||
{% set code_html %}
|
||||
{% call select(
|
||||
name="select-js",
|
||||
trigger_attrs={"class": "w-[180px]"},
|
||||
register_on=["alpine:init", "htmx:afterSwap"],
|
||||
include_script=false
|
||||
) %}
|
||||
<div role="group" aria-labelledby="fruit-options-label">
|
||||
<span id="fruit-options-label" role="heading">Fruits</span>
|
||||
<div role="option" data-value="apple">Apple</div>
|
||||
<div role="option" data-value="banana">Banana</div>
|
||||
<div role="option" data-value="blueberry">Blueberry</div>
|
||||
<div role="option" data-value="pineapple">Grapes</div>
|
||||
<div role="option" data-value="pineapple">Pineapple</div>
|
||||
</div>
|
||||
{% endcall %}
|
||||
{% endset %}
|
||||
{{ code_block(code_html | prettyHtml) }}
|
||||
</section>
|
||||
|
||||
<h4 class="badge-secondary">Javascript</h4>
|
||||
|
||||
<section class="prose my-6">
|
||||
{% set code_script %}{% include "components/select-script.njk" %}{% endset %}
|
||||
{{ code_block(code_script | prettyHtml, "html") }}
|
||||
</section>
|
||||
{% from "components/tabs.njk" import tabs %}
|
||||
{% set tabsets = [
|
||||
{ tab: "HTML", panel: code_block(code_html | prettyHtml) },
|
||||
{ tab: "Javascipt (Alpine.js)", panel: code_block(code_script | prettyHtml) }
|
||||
] %}
|
||||
{{ tabs(id="select", tabsets=tabsets) }}
|
||||
|
||||
<h3 id="usage-jinja"><a href="#usage-jinja">Jinja or Nunjucks</a></h3>
|
||||
|
||||
<section class="prose my-6">
|
||||
<p>If you use Jinja (or Nunjucks), you can use the <code>select()</code> macro directly.</p>
|
||||
<ul>
|
||||
<li>
|
||||
<a href="/jinja-and-nunjucks">Read more about using Basecoat with Jinja or Nunjucks</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="/components/popover">Read more about the Popover component</a>
|
||||
</li>
|
||||
</ul>
|
||||
</section>
|
||||
<p class="my-6 prose">If you use Jinja (or Nunjucks), you can use the <code>dropdown_menu()</code> macro directly. <a href="/installation#jinja-and-nunjucks">Read more about using Basecoat with Jinja and Nunjucks</a>.</p>
|
||||
|
||||
{% set raw_code %}{% raw %}{% call select(name="select-js") %}
|
||||
<div role="group" aria-labelledby="fruit-options-label">
|
||||
|
||||
Reference in New Issue
Block a user