@pokle/basecoat 0.3.10-beta2.pokle
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eleventy.js +47 -0
- package/.gitattributes +1 -0
- package/.gitignore +12 -0
- package/AGENTS.md +112 -0
- package/CONTRIBUTING.md +15 -0
- package/LICENSE.md +21 -0
- package/README.md +29 -0
- package/ROADMAP.md +20 -0
- package/docs/css/custom.css +92 -0
- package/docs/css/highlight.css +151 -0
- package/docs/css/styles.css +8 -0
- package/docs/css/themes/claude.css +95 -0
- package/docs/css/themes/doom-64.css +95 -0
- package/docs/css/themes/supabase.css +100 -0
- package/docs/src/_data/site.js +10 -0
- package/docs/src/_includes/layouts/base.njk +112 -0
- package/docs/src/_includes/layouts/layout.njk +15 -0
- package/docs/src/_includes/layouts/page.njk +21 -0
- package/docs/src/_includes/macros/code_block.njk +23 -0
- package/docs/src/_includes/macros/code_preview.njk +26 -0
- package/docs/src/_includes/macros/toc.njk +20 -0
- package/docs/src/_includes/partials/header.njk +64 -0
- package/docs/src/_includes/partials/kitchen-sink/accordion.njk +89 -0
- package/docs/src/_includes/partials/kitchen-sink/alert-dialog.njk +26 -0
- package/docs/src/_includes/partials/kitchen-sink/alert.njk +72 -0
- package/docs/src/_includes/partials/kitchen-sink/avatar.njk +37 -0
- package/docs/src/_includes/partials/kitchen-sink/badge.njk +47 -0
- package/docs/src/_includes/partials/kitchen-sink/breadcrumb.njk +42 -0
- package/docs/src/_includes/partials/kitchen-sink/button.njk +101 -0
- package/docs/src/_includes/partials/kitchen-sink/card.njk +147 -0
- package/docs/src/_includes/partials/kitchen-sink/checkbox.njk +34 -0
- package/docs/src/_includes/partials/kitchen-sink/combobox.njk +83 -0
- package/docs/src/_includes/partials/kitchen-sink/dialog.njk +65 -0
- package/docs/src/_includes/partials/kitchen-sink/dropdown-menu.njk +294 -0
- package/docs/src/_includes/partials/kitchen-sink/form.njk +106 -0
- package/docs/src/_includes/partials/kitchen-sink/input.njk +27 -0
- package/docs/src/_includes/partials/kitchen-sink/label.njk +30 -0
- package/docs/src/_includes/partials/kitchen-sink/pagination.njk +34 -0
- package/docs/src/_includes/partials/kitchen-sink/popover.njk +43 -0
- package/docs/src/_includes/partials/kitchen-sink/radio-group.njk +33 -0
- package/docs/src/_includes/partials/kitchen-sink/select.njk +99 -0
- package/docs/src/_includes/partials/kitchen-sink/skeleton.njk +40 -0
- package/docs/src/_includes/partials/kitchen-sink/slider.njk +38 -0
- package/docs/src/_includes/partials/kitchen-sink/switch.njk +27 -0
- package/docs/src/_includes/partials/kitchen-sink/table.njk +74 -0
- package/docs/src/_includes/partials/kitchen-sink/tabs.njk +105 -0
- package/docs/src/_includes/partials/kitchen-sink/textarea.njk +27 -0
- package/docs/src/_includes/partials/kitchen-sink/toast.njk +25 -0
- package/docs/src/_includes/partials/kitchen-sink/tooltip.njk +24 -0
- package/docs/src/_includes/partials/sidebar.njk +139 -0
- package/docs/src/assets/apple-touch-icon.png +0 -0
- package/docs/src/assets/favicon.svg +12 -0
- package/docs/src/assets/images/avatar-1.png +0 -0
- package/docs/src/assets/images/avatar-2.png +0 -0
- package/docs/src/assets/images/avatar-3.png +0 -0
- package/docs/src/assets/images/screenshot.png +0 -0
- package/docs/src/assets/social-screenshot.png +0 -0
- package/docs/src/assets/social.png +0 -0
- package/docs/src/assets/styles.css +6309 -0
- package/docs/src/components/accordion.njk +75 -0
- package/docs/src/components/alert-dialog.njk +119 -0
- package/docs/src/components/alert.njk +108 -0
- package/docs/src/components/avatar.njk +40 -0
- package/docs/src/components/badge.njk +93 -0
- package/docs/src/components/breadcrumb.njk +71 -0
- package/docs/src/components/button-group.njk +290 -0
- package/docs/src/components/button.njk +141 -0
- package/docs/src/components/card.njk +156 -0
- package/docs/src/components/carousel.njk +102 -0
- package/docs/src/components/chart.njk +814 -0
- package/docs/src/components/checkbox.njk +101 -0
- package/docs/src/components/combobox.njk +293 -0
- package/docs/src/components/command.njk +288 -0
- package/docs/src/components/dialog.njk +177 -0
- package/docs/src/components/dropdown-menu.njk +403 -0
- package/docs/src/components/empty.njk +157 -0
- package/docs/src/components/field.njk +459 -0
- package/docs/src/components/form.njk +79 -0
- package/docs/src/components/input-group.njk +372 -0
- package/docs/src/components/input.njk +90 -0
- package/docs/src/components/item.njk +320 -0
- package/docs/src/components/kbd.njk +76 -0
- package/docs/src/components/label.njk +41 -0
- package/docs/src/components/pagination.njk +48 -0
- package/docs/src/components/popover.njk +174 -0
- package/docs/src/components/progress.njk +44 -0
- package/docs/src/components/radio-group.njk +48 -0
- package/docs/src/components/select.njk +457 -0
- package/docs/src/components/sidebar.njk +219 -0
- package/docs/src/components/skeleton.njk +51 -0
- package/docs/src/components/slider.njk +47 -0
- package/docs/src/components/spinner.njk +214 -0
- package/docs/src/components/switch.njk +54 -0
- package/docs/src/components/table.njk +87 -0
- package/docs/src/components/tabs.njk +232 -0
- package/docs/src/components/textarea.njk +90 -0
- package/docs/src/components/theme-switcher.njk +111 -0
- package/docs/src/components/toast.njk +279 -0
- package/docs/src/components/tooltip.njk +53 -0
- package/docs/src/fragments/toast/error.njk +6 -0
- package/docs/src/fragments/toast/info.njk +5 -0
- package/docs/src/fragments/toast/success.njk +7 -0
- package/docs/src/fragments/toast/warning.njk +5 -0
- package/docs/src/index.njk +336 -0
- package/docs/src/installation.njk +275 -0
- package/docs/src/introduction.njk +63 -0
- package/docs/src/kitchen-sink.njk +52 -0
- package/docs/src/llms.txt +506 -0
- package/docs/src/robots.njk +7 -0
- package/docs/src/sitemap.njk +15 -0
- package/docs/src/test.njk +39 -0
- package/package.json +51 -0
- package/packages/cli/README.md +55 -0
- package/packages/cli/index.js +193 -0
- package/packages/cli/package.json +44 -0
- package/packages/css/README.md +63 -0
- package/packages/css/package.json +63 -0
- package/scripts/build.js +170 -0
- package/src/css/basecoat.cdn.css +2 -0
- package/src/css/basecoat.css +1310 -0
- package/src/jinja/command.html.jinja +206 -0
- package/src/jinja/dialog.html.jinja +94 -0
- package/src/jinja/dropdown-menu.html.jinja +124 -0
- package/src/jinja/popover.html.jinja +48 -0
- package/src/jinja/select.html.jinja +196 -0
- package/src/jinja/sidebar.html.jinja +144 -0
- package/src/jinja/tabs.html.jinja +78 -0
- package/src/jinja/toast.html.jinja +117 -0
- package/src/js/basecoat.js +99 -0
- package/src/js/command.js +175 -0
- package/src/js/dropdown-menu.js +171 -0
- package/src/js/popover.js +73 -0
- package/src/js/select.js +432 -0
- package/src/js/sidebar.js +104 -0
- package/src/js/tabs.js +63 -0
- package/src/js/toast.js +181 -0
- package/src/nunjucks/command.njk +206 -0
- package/src/nunjucks/dialog.njk +92 -0
- package/src/nunjucks/dropdown-menu.njk +124 -0
- package/src/nunjucks/popover.njk +48 -0
- package/src/nunjucks/select.njk +196 -0
- package/src/nunjucks/sidebar.njk +144 -0
- package/src/nunjucks/tabs.njk +78 -0
- package/src/nunjucks/toast.njk +117 -0
- package/wrangler.jsonc +7 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
---
|
|
2
|
+
layout: layouts/page.njk
|
|
3
|
+
title: Checkbox
|
|
4
|
+
description: A control that allows the user to toggle between checked and not checked.
|
|
5
|
+
toc:
|
|
6
|
+
- label: Usage
|
|
7
|
+
id: usage
|
|
8
|
+
- label: Examples
|
|
9
|
+
id: examples
|
|
10
|
+
children:
|
|
11
|
+
- label: Disabled
|
|
12
|
+
id: example-disabled
|
|
13
|
+
- label: With text
|
|
14
|
+
id: example-with-text
|
|
15
|
+
- label: Form
|
|
16
|
+
id: example-form
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
{% from "macros/code_preview.njk" import code_preview %}
|
|
20
|
+
{% from "macros/code_block.njk" import code_block %}
|
|
21
|
+
|
|
22
|
+
{% set code %}<label class="label gap-3">
|
|
23
|
+
<input type="checkbox" class="input">
|
|
24
|
+
Accept terms and conditions
|
|
25
|
+
</label>{% endset %}
|
|
26
|
+
{{ code_preview("checkbox", code) }}
|
|
27
|
+
|
|
28
|
+
<h2 id="usage">Usage</h2>
|
|
29
|
+
|
|
30
|
+
<section class="prose">
|
|
31
|
+
<p>Add the <code>input</code> class to your <code><input type="radio"></code> elements or have a parent with the <code>form</code> class (<a href="/components/form">read more about form</a>). You can also set the <code>aria-invalid</code> attribute to <code>true</code> to make the input invalid.</p>
|
|
32
|
+
</section>
|
|
33
|
+
|
|
34
|
+
{% set code %}<input type="checkbox" class="input">{% endset %}
|
|
35
|
+
{{ code_block(code) }}
|
|
36
|
+
|
|
37
|
+
<h2 id="examples"><a href="#examples">Examples</a></h2>
|
|
38
|
+
|
|
39
|
+
<h3 id="example-disabled"><a href="#example-disabled">Disabled</a></h3>
|
|
40
|
+
|
|
41
|
+
{% set code %}<label class="label gap-3">
|
|
42
|
+
<input type="checkbox" class="input" disabled>
|
|
43
|
+
Accept terms and conditions
|
|
44
|
+
</label>{% endset %}
|
|
45
|
+
{{ code_preview("checkbox-disabled", code) }}
|
|
46
|
+
|
|
47
|
+
<h3 id="example-with-text"><a href="#example-with-text">With text</a></h3>
|
|
48
|
+
|
|
49
|
+
{% set code %}<div class="flex items-start gap-3">
|
|
50
|
+
<input type="checkbox" id="checkbox-with-text" class="input">
|
|
51
|
+
<div class="grid gap-2">
|
|
52
|
+
<label for="checkbox-with-text" class="label">Accept terms and conditions</label>
|
|
53
|
+
<p class="text-muted-foreground text-sm">By clicking this checkbox, you agree to the terms and conditions.</p>
|
|
54
|
+
</div>
|
|
55
|
+
</div>{% endset %}
|
|
56
|
+
{{ code_preview("checkbox-with-text", code) }}
|
|
57
|
+
|
|
58
|
+
<h3 id="example-form"><a href="#example-form">Form</a></h3>
|
|
59
|
+
|
|
60
|
+
{% set code %}<form class="form flex flex-row items-start gap-3 rounded-md border p-4 shadow-xs">
|
|
61
|
+
<input type="checkbox" id="checkbox-form-1">
|
|
62
|
+
<div class="flex flex-col gap-1">
|
|
63
|
+
<label for="checkbox-form-1" class="leading-snug">Use different settings for my mobile devices</label>
|
|
64
|
+
<p class="text-muted-foreground text-sm leading-snug">You can manage your mobile notifications in the mobile settings page.</p>
|
|
65
|
+
</div>
|
|
66
|
+
</form>{% endset %}
|
|
67
|
+
{{ code_preview("input-form", code) }}
|
|
68
|
+
|
|
69
|
+
{% set code %}<form class="form flex flex-col gap-4">
|
|
70
|
+
<header>
|
|
71
|
+
<label for="demo-form-checkboxes" class="text-base leading-normal">Sidebar</label>
|
|
72
|
+
<p class="text-muted-foreground text-sm">Select the items you want to display in the sidebar.</p>
|
|
73
|
+
</header>
|
|
74
|
+
<fieldset id="demo-form-checkboxes" class="flex flex-col gap-2">
|
|
75
|
+
<label class="font-normal leading-tight">
|
|
76
|
+
<input type="checkbox" name="demo-form-checkboxes" value="1" checked>
|
|
77
|
+
Recents
|
|
78
|
+
</label>
|
|
79
|
+
<label class="font-normal leading-tight">
|
|
80
|
+
<input type="checkbox" name="demo-form-checkboxes" value="2" checked>
|
|
81
|
+
Home
|
|
82
|
+
</label>
|
|
83
|
+
<label class="font-normal leading-tight">
|
|
84
|
+
<input type="checkbox" name="demo-form-checkboxes" value="3">
|
|
85
|
+
Applications
|
|
86
|
+
</label>
|
|
87
|
+
<label class="font-normal leading-tight">
|
|
88
|
+
<input type="checkbox" name="demo-form-checkboxes" value="4">
|
|
89
|
+
Desktop
|
|
90
|
+
</label>
|
|
91
|
+
<label class="font-normal leading-tight">
|
|
92
|
+
<input type="checkbox" name="demo-form-checkboxes" value="5">
|
|
93
|
+
Download
|
|
94
|
+
</label>
|
|
95
|
+
<label class="font-normal leading-tight">
|
|
96
|
+
<input type="checkbox" name="demo-form-checkboxes" value="6">
|
|
97
|
+
Documents
|
|
98
|
+
</label>
|
|
99
|
+
</fieldset>
|
|
100
|
+
</form>{% endset %}
|
|
101
|
+
{{ code_preview("input-form", code) }}
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
---
|
|
2
|
+
layout: layouts/page.njk
|
|
3
|
+
title: Combobox
|
|
4
|
+
description: Autocomplete input and command palette with a list of suggestions.
|
|
5
|
+
toc:
|
|
6
|
+
- label: Usage
|
|
7
|
+
id: usage
|
|
8
|
+
children:
|
|
9
|
+
- label: HTML + JavaScript
|
|
10
|
+
id: usage-html-js
|
|
11
|
+
children:
|
|
12
|
+
- label: "Step 1: Include the JavaScript files"
|
|
13
|
+
id: usage-html-js-1
|
|
14
|
+
- label: "Step 2: Add your combobox HTML"
|
|
15
|
+
id: usage-html-js-2
|
|
16
|
+
- label: HTML structure
|
|
17
|
+
id: usage-html-js-3
|
|
18
|
+
- label: JavaScript events
|
|
19
|
+
id: usage-html-js-4
|
|
20
|
+
- label: JavaScript methods
|
|
21
|
+
id: usage-html-js-5
|
|
22
|
+
- label: Jinja and Nunjucks
|
|
23
|
+
id: usage-macro
|
|
24
|
+
- label: Examples
|
|
25
|
+
id: examples
|
|
26
|
+
children:
|
|
27
|
+
- label: Scrollable
|
|
28
|
+
id: example-scrollable
|
|
29
|
+
- label: Top side
|
|
30
|
+
id: example-top
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
{% from "macros/code_preview.njk" import code_preview %}
|
|
34
|
+
{% from "macros/code_block.njk" import code_block %}
|
|
35
|
+
{% from "select.njk" import select %}
|
|
36
|
+
|
|
37
|
+
{% set options_frameworks = ["Next.js", "SvelteKit", "Nuxt.js", "Remix", "Astro"] %}
|
|
38
|
+
{% set code_html %}
|
|
39
|
+
{% call select(
|
|
40
|
+
trigger_attrs={"class": "w-[200px]"},
|
|
41
|
+
listbox_attrs={"data-empty": "No framework found."},
|
|
42
|
+
is_combobox=true,
|
|
43
|
+
search_placeholder="Search framework..."
|
|
44
|
+
) %}
|
|
45
|
+
{% for framework in options_frameworks %}
|
|
46
|
+
<div role="option" data-value="{{ framework }}">{{ framework }}</div>
|
|
47
|
+
{% endfor %}
|
|
48
|
+
{% endcall %}
|
|
49
|
+
{% endset %}
|
|
50
|
+
|
|
51
|
+
{{ code_preview("combobox", code_html | prettyHtml) }}
|
|
52
|
+
|
|
53
|
+
<h2 id="usage"><a href="#usage">Usage</a></h2>
|
|
54
|
+
|
|
55
|
+
<h3 id="usage-html-js"><a href="#usage-html-js">HTML + JavaScript</a></h3>
|
|
56
|
+
|
|
57
|
+
<h4 id="usage-html-js-1"><a href="#usage-html-js-1">Step 1: Include the JavaScript files</a></h4>
|
|
58
|
+
|
|
59
|
+
<section class="prose">
|
|
60
|
+
<p>You can either <a href="/installation/#install-cdn-all">include the JavaScript file for all the components</a>, or just the one for this component by adding this to the <code><head></code> of your page:</p>
|
|
61
|
+
</section>
|
|
62
|
+
|
|
63
|
+
{% set code_script %}<script src="https://cdn.jsdelivr.net/npm/basecoat-css@{{ pkg.version }}/dist/js/basecoat.min.js" defer></script>
|
|
64
|
+
<script src="https://cdn.jsdelivr.net/npm/basecoat-css@{{ pkg.version }}/dist/js/select.min.js" defer></script>{% endset %}
|
|
65
|
+
{{ code_block(code_script | prettyHtml, "html") }}
|
|
66
|
+
|
|
67
|
+
<div class="flex flex-wrap gap-2 my-6">
|
|
68
|
+
<a class="badge-outline" href="/installation/#install-js">
|
|
69
|
+
Components with JavaScript
|
|
70
|
+
{% lucide "arrow-right" %}
|
|
71
|
+
</a>
|
|
72
|
+
<a class="badge-outline" href="/installation/#install-cli">
|
|
73
|
+
Use the CLI
|
|
74
|
+
{% lucide "arrow-right" %}
|
|
75
|
+
</a>
|
|
76
|
+
<a class="badge-outline" href="https://github.com/hunvreus/basecoat/blob/main/src/js/select.js" target="_blank">
|
|
77
|
+
select.js
|
|
78
|
+
{% lucide "arrow-right" %}
|
|
79
|
+
</a>
|
|
80
|
+
</div>
|
|
81
|
+
|
|
82
|
+
<h4 id="usage-html-js-2"><a href="#usage-html-js-2">Step 2: Add your combobox HTML</a></h4>
|
|
83
|
+
|
|
84
|
+
<section class="prose">
|
|
85
|
+
<p>Combobox uses the same markup and JavaScript as the <a href="/components/select#usage-html-js">Select component</a>, the only difference being the search box at the top of the listbox:</p>
|
|
86
|
+
</section>
|
|
87
|
+
|
|
88
|
+
{{ code_block(code_html | prettyHtml, "html") }}
|
|
89
|
+
|
|
90
|
+
<h4 id="usage-html-js-3"><a href="#usage-html-js-3">HTML structure</a></h4>
|
|
91
|
+
|
|
92
|
+
<section class="prose">
|
|
93
|
+
<dl>
|
|
94
|
+
<dt><code class="highlight language-html"><div class="select"></code></dt>
|
|
95
|
+
<dd>Wraps around the entire component.
|
|
96
|
+
<dl>
|
|
97
|
+
<dt><code class="highlight language-html"><button type="button" popovertarget="{ POPOVER_ID }"></code></dt>
|
|
98
|
+
<dd>
|
|
99
|
+
<p>The trigger to open the popover, can also have the following attributes:</p>
|
|
100
|
+
<ul>
|
|
101
|
+
<li><code>id="{BUTTON_ID}"</code>: linked to by the <code>aria-labelledby</code> attribute of the listbox.</li>
|
|
102
|
+
<li><code>aria-haspopup="listbox"</code>: indicates that the button opens a listbox.</li>
|
|
103
|
+
<li><code>aria-controls="{ LISTBOX_ID }"</code>: points to the listbox's id.</li>
|
|
104
|
+
<li><code>aria-expanded="false"</code>: tracks the popover's state.</li>
|
|
105
|
+
<li><code>aria-activedescendant="{ OPTION_ID }"</code>: points to the active option's id.</li>
|
|
106
|
+
</ul>
|
|
107
|
+
</dd>
|
|
108
|
+
<dt><code class="highlight language-html"><div popover class="popover" id="{ POPOVER_ID }"></code></dt>
|
|
109
|
+
<dd>As with the <a href="/components/popover">Popover</a> component, you can set up the side and alignment of the popover using the <code>data-side</code> and <code>data-align</code> attributes.
|
|
110
|
+
<dl>
|
|
111
|
+
<dt><code class="highlight language-html"><header></code></dt>
|
|
112
|
+
<dd>Contains the search input to filter the options in the listbox.</dd>
|
|
113
|
+
<dt><code class="highlight language-html"><div role="listbox"></code></dt>
|
|
114
|
+
<dd>The listbox containing the options. Should have the following attributes:
|
|
115
|
+
<ul>
|
|
116
|
+
<li><code>id="{ LISTBOX_ID }"</code>: refered to by the <code>aria-controls</code> attribute of the trigger.</li>
|
|
117
|
+
<li><code>aria-labelledby="{ BUTTON_ID }"</code>: linked to by the button's <code>id</code> attribute.</li>
|
|
118
|
+
</ul>
|
|
119
|
+
<dl>
|
|
120
|
+
<dt><code class="highlight language-html"><div role="option" data-value="{ VALUE }"></code></dt>
|
|
121
|
+
<dd>Option that can be selected. Should have a unique id if you use the <code>aria-activedescendant</code> attribute on the trigger. Optional attributes:
|
|
122
|
+
<ul>
|
|
123
|
+
<li><code>data-filter</code>: custom text used for filtering (if different from displayed content, e.g., <code>data-filter="united states"</code>)</li>
|
|
124
|
+
<li><code>data-keywords</code>: additional keywords for enhanced filtering (e.g., <code>data-keywords="bread fruit"</code>)</li>
|
|
125
|
+
<li><code>data-force</code>: forces the option to always display, regardless of filter (e.g., <code>data-force</code>)</li>
|
|
126
|
+
<li><code>aria-disabled="true"</code>: marks option as disabled (excluded from selection and keyboard navigation)</li>
|
|
127
|
+
</ul>
|
|
128
|
+
</dd>
|
|
129
|
+
<dt><code class="highlight language-html"><hr role="separator"></code> <span class="badge-secondary">Optional</span></dt>
|
|
130
|
+
<dd>Separator between groups/options.</dd>
|
|
131
|
+
<dt><code class="highlight language-html"><div role="group"></code> <span class="badge-secondary">Optional</span></dt>
|
|
132
|
+
<dd>Group of options, can have a <code>aria-labelledby</code> attribute to link to a heading.</dd>
|
|
133
|
+
<dt><code class="highlight language-html"><span role="heading"></code></dt>
|
|
134
|
+
<dd>Group heading, must have an <code>id</code> attribute if you use the <code>aria-labelledby</code> attribute on the group.</dd>
|
|
135
|
+
</dl>
|
|
136
|
+
</dd>
|
|
137
|
+
</dl>
|
|
138
|
+
</dl>
|
|
139
|
+
</dd>
|
|
140
|
+
<dt><code class="highlight language-html"><input type="hidden" name="{ NAME }" value="{ VALUE }"></code> <span class="badge-secondary">Optional</span></dt>
|
|
141
|
+
<dd>The hidden input that holds the value of the field (if needed).</dd>
|
|
142
|
+
</dl>
|
|
143
|
+
</section>
|
|
144
|
+
|
|
145
|
+
<h4 id="usage-html-js-4"><a href="#usage-html-js-4">JavaScript events</a></h4>
|
|
146
|
+
|
|
147
|
+
<section class="prose">
|
|
148
|
+
<dl>
|
|
149
|
+
<dt><code>basecoat:initialized</code></dt>
|
|
150
|
+
<dd>Once the component is fully initialized, it dispatches a custom (non-bubbling) <code>basecoat:initialized</code> event on itself.</dd>
|
|
151
|
+
<dt><code>basecoat:popover</code></dt>
|
|
152
|
+
<dd>When the popover opens, the component dispatches a custom (non-bubbling) <code>basecoat:popover</code> event on <code>document</code>. Other popover components (Combobox, Dropdown Menu, Popover and Select) listen for this to close any open popovers.</dd>
|
|
153
|
+
<dt><code>change</code></dt>
|
|
154
|
+
<dd>When the selected value changes, the component dispatches a custom (bubbling) <code>change</code> event on itself, with the selected value in <code>event.detail</code> (e.g. <code>{detail: {value: "something"}}</code>).</dd>
|
|
155
|
+
</dl>
|
|
156
|
+
</section>
|
|
157
|
+
|
|
158
|
+
<h4 id="usage-html-js-5"><a href="#usage-html-js-4">JavaScript methods</a></h4>
|
|
159
|
+
|
|
160
|
+
<section class="prose">
|
|
161
|
+
<dl>
|
|
162
|
+
<dt><code>selectByValue</code></dt>
|
|
163
|
+
<dd>
|
|
164
|
+
<p>You can call this method on the component after it is initialized to select an option by value (i.e. the option with the matching <code>data-value</code> attribute):</p>
|
|
165
|
+
|
|
166
|
+
{% set code_script %}<script>
|
|
167
|
+
const comboboxComponent = document.querySelector('#my-combobox');
|
|
168
|
+
comboboxComponent.addEventListener('basecoat:initialized', () => {
|
|
169
|
+
comboboxComponent.selectByValue('apple');
|
|
170
|
+
});
|
|
171
|
+
</script>{% endset %}
|
|
172
|
+
{{ code_block(code_script | prettyHtml, "html") }}
|
|
173
|
+
</dd>
|
|
174
|
+
</dl>
|
|
175
|
+
</section>
|
|
176
|
+
|
|
177
|
+
<h3 id="usage-macro"><a href="#usage-macro">Jinja and Nunjucks</a></h3>
|
|
178
|
+
|
|
179
|
+
<div class="prose">
|
|
180
|
+
<p>You can use the <code class="relative rounded bg-muted px-[0.3rem] py-[0.2rem] font-mono text-xs">select()</code> Nunjucks or Jinja macro for this component. If you use one of the macros, make sure to set <code>is_combobox</code> to <code>True</code> (or <code>true</code> for Nunjucks).</p>
|
|
181
|
+
</div>
|
|
182
|
+
|
|
183
|
+
<div class="flex flex-wrap gap-2 my-6">
|
|
184
|
+
<a class="badge-outline" href="/installation/#install-macros" target="_blank">
|
|
185
|
+
Use Nunjucks or Jinja macros
|
|
186
|
+
{% lucide "arrow-right" %}
|
|
187
|
+
</a>
|
|
188
|
+
<a class="badge-outline" href="https://github.com/hunvreus/basecoat/blob/main/src/jinja/select.html.jinja" target="_blank">
|
|
189
|
+
Jinja macro
|
|
190
|
+
{% lucide "arrow-right" %}
|
|
191
|
+
</a>
|
|
192
|
+
<a class="badge-outline" href="https://github.com/hunvreus/basecoat/blob/main/src/nunjucks/select.njk" target="_blank">
|
|
193
|
+
Nunjucks macro
|
|
194
|
+
{% lucide "arrow-right" %}
|
|
195
|
+
</a>
|
|
196
|
+
</div>
|
|
197
|
+
|
|
198
|
+
{% set raw_code %}{% raw %}{% call select(
|
|
199
|
+
listbox_attrs={"data-empty": "No framework found."},
|
|
200
|
+
is_combobox=true
|
|
201
|
+
) %}
|
|
202
|
+
<div role="option" data-value="nextjs">Next.js</div>
|
|
203
|
+
<div role="option" data-value="sveltekit">SvelteKit</div>
|
|
204
|
+
<div role="option" data-value="nuxtjs">Nuxt.js</div>
|
|
205
|
+
<div role="option" data-value="remix">Remix</div>
|
|
206
|
+
<div role="option" data-value="astro">Astro</div>
|
|
207
|
+
{% endcall %}{% endraw %}{% endset %}
|
|
208
|
+
{{ code_block(raw_code, "jinja") }}
|
|
209
|
+
|
|
210
|
+
<h2 id="examples"><a href="#examples">Examples</a></h2>
|
|
211
|
+
|
|
212
|
+
<h3 id="example-scrollable"><a href="#example-scrollable">Scrollable</a></h3>
|
|
213
|
+
|
|
214
|
+
{% set options_timezones = [
|
|
215
|
+
{
|
|
216
|
+
label: "Americas",
|
|
217
|
+
timezones: [
|
|
218
|
+
{ value: "America/New_York", label: "(GMT-5) New York" },
|
|
219
|
+
{ value: "America/Los_Angeles", label: "(GMT-8) Los Angeles" },
|
|
220
|
+
{ value: "America/Chicago", label: "(GMT-6) Chicago" },
|
|
221
|
+
{ value: "America/Toronto", label: "(GMT-5) Toronto" },
|
|
222
|
+
{ value: "America/Vancouver", label: "(GMT-8) Vancouver" },
|
|
223
|
+
{ value: "America/Sao_Paulo", label: "(GMT-3) São Paulo" }
|
|
224
|
+
]
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
label: "Europe",
|
|
228
|
+
timezones: [
|
|
229
|
+
{ value: "Europe/London", label: "(GMT+0) London" },
|
|
230
|
+
{ value: "Europe/Paris", label: "(GMT+1) Paris" },
|
|
231
|
+
{ value: "Europe/Berlin", label: "(GMT+1) Berlin" },
|
|
232
|
+
{ value: "Europe/Rome", label: "(GMT+1) Rome" },
|
|
233
|
+
{ value: "Europe/Madrid", label: "(GMT+1) Madrid" },
|
|
234
|
+
{ value: "Europe/Amsterdam", label: "(GMT+1) Amsterdam" }
|
|
235
|
+
]
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
label: "Asia/Pacific",
|
|
239
|
+
timezones: [
|
|
240
|
+
{ value: "Asia/Tokyo", label: "(GMT+9) Tokyo" },
|
|
241
|
+
{ value: "Asia/Shanghai", label: "(GMT+8) Shanghai" },
|
|
242
|
+
{ value: "Asia/Singapore", label: "(GMT+8) Singapore" },
|
|
243
|
+
{ value: "Asia/Dubai", label: "(GMT+4) Dubai" },
|
|
244
|
+
{ value: "Australia/Sydney", label: "(GMT+11) Sydney" },
|
|
245
|
+
{ value: "Asia/Seoul", label: "(GMT+9) Seoul" }
|
|
246
|
+
]
|
|
247
|
+
}
|
|
248
|
+
] %}
|
|
249
|
+
{% set code %}
|
|
250
|
+
{% call select(
|
|
251
|
+
trigger_attrs={"class": "w-[200px]"},
|
|
252
|
+
popover_attrs={"class": "w-72"},
|
|
253
|
+
listbox_attrs={"data-empty": "No timezone found."},
|
|
254
|
+
is_combobox=true,
|
|
255
|
+
search_placeholder="Search timezone..."
|
|
256
|
+
) %}
|
|
257
|
+
<div class="max-h-64 overflow-y-auto scrollbar">
|
|
258
|
+
{% for group in options_timezones %}
|
|
259
|
+
<div role="group" aria-labelledby="demo-combobox-timezones-group-{{ loop.index0 }}">
|
|
260
|
+
<div role="heading" id="demo-combobox-timezones-group-{{ loop.index0 }}">{{ group.label }}</div>
|
|
261
|
+
{% for timezone in group.timezones %}
|
|
262
|
+
<div role="option" data-value="{{ timezone.value}}">
|
|
263
|
+
{{ timezone.label }}
|
|
264
|
+
</div>
|
|
265
|
+
{% endfor %}
|
|
266
|
+
</div>
|
|
267
|
+
{% endfor %}
|
|
268
|
+
</div>
|
|
269
|
+
<hr role="separator">
|
|
270
|
+
<div role="option">
|
|
271
|
+
{% lucide "circle-plus" %}
|
|
272
|
+
Create timezone
|
|
273
|
+
</div>
|
|
274
|
+
{% endcall %}
|
|
275
|
+
{% endset %}
|
|
276
|
+
{{ code_preview("combobox-with-groups", code | prettyHtml) }}
|
|
277
|
+
|
|
278
|
+
<h3 id="example-top"><a href="#example-top">Top side</a></h3>
|
|
279
|
+
|
|
280
|
+
{% set options_frameworks = ["Next.js", "SvelteKit", "Nuxt.js", "Remix", "Astro"] %}
|
|
281
|
+
{% set code %}
|
|
282
|
+
{% call select(
|
|
283
|
+
trigger_attrs={"class": "w-[200px]"},
|
|
284
|
+
listbox_attrs={"data-empty": "No framework found."},
|
|
285
|
+
is_combobox=true,
|
|
286
|
+
search_placeholder="Search framework...",
|
|
287
|
+
popover_attrs={"data-side": "top"}
|
|
288
|
+
) %}
|
|
289
|
+
{% for framework in options_frameworks %}
|
|
290
|
+
<div role="option" data-value="{{ framework }}">{{ framework }}</div>
|
|
291
|
+
{% endfor %}
|
|
292
|
+
{% endcall %}{% endset %}
|
|
293
|
+
{{ code_preview("combobox", code | prettyHtml) }}
|