@htmlbricks/hb-searchbar 0.71.35 → 0.71.36

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.
Files changed (3) hide show
  1. package/README.md +171 -27
  2. package/manifest.json +78 -6
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -1,47 +1,191 @@
1
- ## `hb-searchbar` — searchbar
1
+ # hb-searchbar
2
2
 
3
- **Category:** utilities
4
- **Tags:** utilities, search
3
+ **Category:** utilities · **Tags:** utilities, search
5
4
 
6
- ### What it does
5
+ ## Overview
7
6
 
8
- Search field with optional dropdown `searchlist` (id, text, icons, badges, tags, URLs). Configure `value`, `searchlabel`, `textarea`, `minlength`, `disable_preview`, `disabled`, and CSS parts for the input and menu. Dispatches `search` and `clear`.
7
+ `hb-searchbar` is a Bulma-styled search control that lives in a shadow root. It renders either a single-line `<input type="search">` or a multiline `<textarea>`, an in-field submit (magnifier) button, and an optional suggestion dropdown driven by a `searchlist` you pass in.
9
8
 
10
- ### Custom element
9
+ Use it when you want a self-contained query field with debounced “search while typing”, optional fixed or fuzzy-matched suggestions, rich rows (icons, badges, tags, links), and explicit `search` / `clear` custom events for your host application.
11
10
 
12
- `hb-searchbar`
11
+ ## Custom element
13
12
 
14
- ### Attributes (snake_case; use string values in HTML)
13
+ ```html
14
+ <hb-searchbar …></hb-searchbar>
15
+ ```
16
+
17
+ Tag name: **`hb-searchbar`**.
18
+
19
+ ## Attributes and properties
20
+
21
+ Web component attributes are **strings**. For structured data (`searchlist`, `input_info`), pass **JSON** as a string attribute (or set the corresponding property with a parsed object in JavaScript). Boolean-like flags use **`yes`** / **`no`** where noted.
22
+
23
+ | Name | Required | Description |
24
+ |------|----------|-------------|
25
+ | `value` | Yes | Current query text. |
26
+ | `id` | No | Host id string; included on `clear` event detail. |
27
+ | `style` | No | Inline style string for the host (optional). |
28
+ | `searchlabel` | No | Placeholder text. Default: `"Search"`. |
29
+ | `minlength` | No | Minimum query length (number) before input-driven search runs and before the preview can open; default `0`. Compares `value.length` to this number. |
30
+ | `searchlist` | No | Array of suggestions (`TSearchListItem[]`). From HTML, use a JSON string. Parsed at runtime if a string is received. |
31
+ | `input_info` | No | Single `TSearchListItem` shown when its `text` equals the current `value` (JSON string from HTML). |
32
+ | `textarea` | No | Multiline mode: `"yes"`, `"true"`, or `""` (empty string) enables `<textarea>`; otherwise a search `<input>` is used. |
33
+ | `disable_preview` | No | When `"yes"`, `"true"`, or `"on"`, the suggestion dropdown does not open. Any other value (including `"no"`, `"false"`, `"off"`) allows preview when other conditions are met. |
34
+ | `disabled` | No | `"yes"` disables the field and action buttons; `"no"` or omitted leaves them enabled. |
35
+
36
+ ### `TSearchListItem` shape
37
+
38
+ Each suggestion (and `input_info`) uses:
39
+
40
+ | Field | Type | Notes |
41
+ |-------|------|--------|
42
+ | `id` | string | Required stable id for the row. |
43
+ | `text` | string | Primary label. |
44
+ | `url` | string | Optional link target for the row. |
45
+ | `icon` | string | Optional Bootstrap Icons icon name (without `bi-` prefix in markup; the component uses `bi bi-{icon}` classes). |
46
+ | `number_of_results` | number | Optional count display. |
47
+ | `fixed` | boolean | When `true`, the row stays visible regardless of the current filter. |
48
+ | `tags` | `TSearchListItemTag[]` | Optional chips: `text`, `color`, `icon`. |
49
+ | `badge` | `TSearchListItemBadge` | Optional badge: `text`, `color`, `icon`. |
50
+
51
+ Tags and badges use Bulma-style color names (for example `primary`, `success`, `danger`) as consumed by the row renderer.
52
+
53
+ ### How the suggestion list behaves
54
+
55
+ - **Filtering:** Non-fixed items are shown when their `text` contains the current `value` (case-insensitive substring match). Items with `fixed: true` are always included.
56
+ - **Opening:** The dropdown is shown when preview is not disabled, the query length is **greater than** `minlength`, and the field is considered “open” after interaction (typing opens it; choosing an action may close it depending on the trigger).
57
+ - **Debounced input search:** After input changes, a **500 ms** debounce runs; if the value is non-empty and satisfies `minlength`, a `search` event fires with `by: "input"`. Enter in the field triggers submit-style search (`by: "button"`) without waiting for the timer.
58
+ - **Submit button:** Clicks dispatch `search` with `by: "button"`.
59
+ - **Picking a suggestion:** Dispatches `search` with `by: "searchlist"` and updates the field text to the chosen item’s `text`.
60
+ - **Clearing:** For the native search input, clearing via the browser’s search clear control dispatches `clear` with `{ id }`. In textarea mode, an explicit clear button empties the value, dispatches `clear`, and closes the dropdown. Clicks outside the host close the dropdown without clearing the value.
61
+
62
+ ## Events
63
+
64
+ Listen with `addEventListener` on the host element.
65
+
66
+ | Event | Detail (TypeScript `Events`) |
67
+ |-------|-------------------------------|
68
+ | `search` | `{ input: string; by: "button" \| "input" \| "searchlist" }` |
69
+ | `clear` | `{ id: string }` |
70
+
71
+ The `id` on `clear` is the component’s `id` attribute (empty string if unset).
72
+
73
+ ## Styling
74
+
75
+ ### Bulma CSS variables
76
+
77
+ The component uses Bulma layout and form patterns inside the shadow tree. Theme it with **`--bulma-*`** variables on a wrapping scope or `:root` / `body` so they apply to `:host`. Relevant groups include:
78
+
79
+ - **Accent and focus:** `--bulma-primary`, `--bulma-danger`
80
+ - **Surfaces and chrome:** `--bulma-background`, `--bulma-scheme-main`, `--bulma-border`, `--bulma-border-weak`
81
+ - **Typography:** `--bulma-text`, `--bulma-text-strong`, `--bulma-input-placeholder-color`
82
+ - **Shape and stacking:** `--bulma-radius`, `--bulma-radius-small`, `--bulma-dropdown-content-z`
83
+
84
+ See [Bulma CSS variables](https://bulma.io/documentation/features/css-variables/) for the full variable system.
85
+
86
+ ### Component-specific variables (`--hb-searchbar-*`)
87
+
88
+ These override frosted layers and panel backgrounds (defaults use `color-mix()` with Bulma tokens):
89
+
90
+ - `--hb-searchbar-host-background` — host background at rest
91
+ - `--hb-searchbar-host-background-focus` — host background while focused
92
+ - `--hb-searchbar-input-strip-background` — input row strip
93
+ - `--hb-searchbar-dropdown-panel-background` — open suggestion panel
94
+ - `--hb-searchbar-input-glass-blur` — backdrop blur behind the focused field
95
+ - `--hb-searchbar-input-glass-saturate` — backdrop saturation factor
96
+
97
+ Authoritative descriptions and defaults are listed in `extra/docs.ts` (`styleSetup.vars`).
98
+
99
+ ### CSS shadow parts
100
+
101
+ | Part | Targets |
102
+ |------|---------|
103
+ | `dropdown-menu` | Open suggestion list panel |
104
+ | `search-input` | Native `<input>` or `<textarea>` |
105
+ | `search-input-glass` | Frosted layer behind the field while focused |
106
+ | `search-submit` | In-field magnifier / submit control |
107
+
108
+ Example:
109
+
110
+ ```css
111
+ hb-searchbar::part(search-submit) {
112
+ color: var(--bulma-primary);
113
+ }
114
+ ```
15
115
 
16
- - `id`, `style` (optional): strings.
17
- - `value` (required): string — current query text.
18
- - `searchlabel` (optional): string — placeholder for the input (search is triggered by the in-field magnifier or Enter).
19
- - `minlength` (optional): number as string.
20
- - `searchlist` (optional): JSON string — `TSearchListItem[]` (`id`, `text`, optional `url`, `icon`, `tags`, `badge`, `number_of_results`, `fixed`).
21
- - `input_info` (optional): JSON string — single `TSearchListItem` for input adornment.
22
- - `textarea` (optional): `"yes"` | `"true"` | `""` — multiline input mode.
23
- - `disable_preview` (optional): `"yes"` | `"no"` | `"true"` | `"false"` | `"on"` | `"off"`.
24
- - `disabled` (optional): `"yes"` | `"no"` — when `"yes"`, the input/textarea and action buttons are disabled.
116
+ ## Icons and assets
25
117
 
26
- ### Events
118
+ The component loads **Bootstrap Icons** from jsDelivr in the shadow document head (`bootstrap-icons.css`). Icon names in `searchlist` / `input_info` refer to that font set.
27
119
 
28
- - `search`: `{ input: string; by: "button" | "input" | "searchlist" }`.
29
- - `clear`: `{ id: string }`.
120
+ ## Slots
30
121
 
31
- ### Usage notes
122
+ None (`htmlSlots` is empty).
32
123
 
33
- - **Browser autofill:** the search field uses `autocomplete="off"` so native address/password suggestions and similar do not target this control (browser support varies; password managers may still offer fills).
124
+ ## Usage notes
34
125
 
35
- - **CSS parts:** `dropdown-menu`, `search-input`, `search-input-glass` (frosted layer under the field when the input is focused), `search-submit` (magnifier button inside the field).
36
- - **Styling:** Bulma `field` with a single expanded control; the search icon sits on the right as a `search-submit` control. Dropdown and field styles live in the shadow root (`styles/bulma.scss` + `webcomponent.scss`). Prefer [Bulma CSS variables](https://bulma.io/documentation/features/css-variables/) on the host or ancestors: e.g. `--bulma-primary` (focus glow, search-button hover, suggestion row accents), `--bulma-background`, `--bulma-border`, and `--bulma-primary` (host strip: default resting/focus tints on `hb-searchbar` itself; input/textarea are transparent at rest so that shows through), `--bulma-scheme-main`, `--bulma-border-weak`, `--bulma-text`, `--bulma-text-strong`, `--bulma-input-placeholder-color`, `--bulma-danger` (clear button), `--bulma-radius`, `--bulma-radius-small`, `--bulma-dropdown-content-z`. Component-only: `--hb-searchbar-host-background`, `--hb-searchbar-host-background-focus` (:host), `--hb-searchbar-input-strip-background` (darker input row at rest), `--hb-searchbar-dropdown-panel-background` (lighter list panel), `--hb-searchbar-input-glass-blur`, `--hb-searchbar-input-glass-saturate` (frosted layer on input focus only). The primary-colored diffuse glow while the input/textarea is focused wraps the whole root (including the open dropdown) as one outline.
37
- - Storybook may list `initial_value`; runtime props follow `webcomponent.type.d.ts` (`value` is required).
126
+ - **Autocomplete:** The control sets `autocomplete="off"`. Browsers may still offer their own UI; behavior varies.
127
+ - **Storybook:** Controls may expose names like `initial_value` for demos; the runtime contract for authors is `types/webcomponent.type.d.ts` (`value` is the live bound field).
128
+ - **Structured props from HTML:** Always serialize `searchlist` and `input_info` as JSON strings on attributes; never rely on passing raw objects through HTML attributes.
38
129
 
39
- ### Minimal HTML example
130
+ ## Examples
131
+
132
+ ### Minimal search field
40
133
 
41
134
  ```html
42
135
  <hb-searchbar
43
136
  value=""
44
137
  searchlabel="Search"
45
- searchlist='[{"id":"1","text":"Suggestion"}]'
46
138
  ></hb-searchbar>
47
139
  ```
140
+
141
+ ### Suggestions with JSON `searchlist`
142
+
143
+ ```html
144
+ <hb-searchbar
145
+ value=""
146
+ searchlabel="Try a suggestion"
147
+ searchlist='[{"id":"1","text":"Documentation"},{"id":"2","text":"API reference"}]'
148
+ ></hb-searchbar>
149
+ ```
150
+
151
+ ### Multiline textarea mode
152
+
153
+ ```html
154
+ <hb-searchbar
155
+ value=""
156
+ searchlabel="Describe your query"
157
+ textarea="yes"
158
+ searchlist='[{"id":"1","text":"Example prompt"}]'
159
+ ></hb-searchbar>
160
+ ```
161
+
162
+ ### Disable preview, require two characters before input search
163
+
164
+ ```html
165
+ <hb-searchbar
166
+ value=""
167
+ disable_preview="yes"
168
+ minlength="2"
169
+ ></hb-searchbar>
170
+ ```
171
+
172
+ ### JavaScript: listen for `search` and `clear`
173
+
174
+ ```javascript
175
+ const el = document.querySelector("hb-searchbar");
176
+
177
+ el.addEventListener("search", (e) => {
178
+ const { input, by } = e.detail;
179
+ console.log("search", { input, by });
180
+ });
181
+
182
+ el.addEventListener("clear", (e) => {
183
+ console.log("cleared", e.detail.id);
184
+ });
185
+ ```
186
+
187
+ ## Related files
188
+
189
+ - `component.wc.svelte` — implementation
190
+ - `types/webcomponent.type.d.ts` — `Component` and `Events` typings
191
+ - `extra/docs.ts` — catalog metadata, CSS variables, parts, Storybook examples
package/manifest.json CHANGED
@@ -182,7 +182,7 @@
182
182
  }
183
183
  }
184
184
  },
185
- "description": "Search field with optional dropdown `searchlist` (id, text, icons, badges, tags, URLs). Configure `value`, `initial_value`, `searchlabel`, `textarea`, `minlength`, `disable_preview`, `disabled`, and CSS parts for the input and menu. Dispatches `search` and `clear`.",
185
+ "description": "Search field with optional dropdown `searchlist` (id, text, icons, badges, tags, URLs). Configure `value`, `searchlabel`, `textarea`, `minlength`, `disable_preview`, `disabled`, and CSS parts for the input and menu. Dispatches `search` and `clear`.",
186
186
  "storybookArgs": {
187
187
  "initial_value": {
188
188
  "control": {
@@ -245,6 +245,78 @@
245
245
  },
246
246
  "styleSetup": {
247
247
  "vars": [
248
+ {
249
+ "name": "--bulma-primary",
250
+ "valueType": "color",
251
+ "defaultValue": "#00d1b2",
252
+ "description": "Focus ring, submit control hover, and highlighted suggestion rows."
253
+ },
254
+ {
255
+ "name": "--bulma-background",
256
+ "valueType": "color",
257
+ "defaultValue": "#ffffff",
258
+ "description": "Mixed into host strip and frosted defaults via `color-mix()`."
259
+ },
260
+ {
261
+ "name": "--bulma-scheme-main",
262
+ "valueType": "color",
263
+ "defaultValue": "#ffffff",
264
+ "description": "Dropdown panel mix target for open suggestions."
265
+ },
266
+ {
267
+ "name": "--bulma-border",
268
+ "valueType": "color",
269
+ "defaultValue": "#dbdbdb",
270
+ "description": "Field outline, dividers, and mix inputs for glass layers."
271
+ },
272
+ {
273
+ "name": "--bulma-border-weak",
274
+ "valueType": "color",
275
+ "defaultValue": "#ededed",
276
+ "description": "Softer separators inside the suggestion list."
277
+ },
278
+ {
279
+ "name": "--bulma-text",
280
+ "valueType": "color",
281
+ "defaultValue": "#363636",
282
+ "description": "Primary query text and list item copy."
283
+ },
284
+ {
285
+ "name": "--bulma-text-strong",
286
+ "valueType": "color",
287
+ "defaultValue": "#363636",
288
+ "description": "Emphasized suggestion titles."
289
+ },
290
+ {
291
+ "name": "--bulma-input-placeholder-color",
292
+ "valueType": "color",
293
+ "defaultValue": "rgba(54, 54, 54, 0.3)",
294
+ "description": "Placeholder tone for `searchlabel`."
295
+ },
296
+ {
297
+ "name": "--bulma-danger",
298
+ "valueType": "color",
299
+ "defaultValue": "#f14668",
300
+ "description": "Clear control accent."
301
+ },
302
+ {
303
+ "name": "--bulma-radius",
304
+ "valueType": "number",
305
+ "defaultValue": "0.375rem",
306
+ "description": "Field and dropdown corner radius."
307
+ },
308
+ {
309
+ "name": "--bulma-radius-small",
310
+ "valueType": "number",
311
+ "defaultValue": "0.25rem",
312
+ "description": "Inner chips / compact controls inside rows."
313
+ },
314
+ {
315
+ "name": "--bulma-dropdown-content-z",
316
+ "valueType": "number",
317
+ "defaultValue": "50",
318
+ "description": "Stacking order for the open suggestion panel."
319
+ },
248
320
  {
249
321
  "name": "--hb-searchbar-host-background",
250
322
  "valueType": "string",
@@ -285,19 +357,19 @@
285
357
  "parts": [
286
358
  {
287
359
  "name": "dropdown-menu",
288
- "description": "The dropdown menu"
360
+ "description": "Open suggestion list panel."
289
361
  },
290
362
  {
291
363
  "name": "search-input",
292
- "description": "The search input"
364
+ "description": "Native input or textarea surface."
293
365
  },
294
366
  {
295
367
  "name": "search-input-glass",
296
- "description": "Frosted glass layer behind the field (visible when the input/textarea is focused)"
368
+ "description": "Frosted backdrop behind the field while the input/textarea is focused."
297
369
  },
298
370
  {
299
371
  "name": "search-submit",
300
- "description": "The clickable search (magnifier) control"
372
+ "description": "In-field magnifier / submit control."
301
373
  }
302
374
  ]
303
375
  },
@@ -841,5 +913,5 @@
841
913
  "size": {},
842
914
  "iifePath": "main.iife.js",
843
915
  "repoName": "@htmlbricks/hb-searchbar",
844
- "version": "0.71.35"
916
+ "version": "0.71.36"
845
917
  }
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@htmlbricks/hb-searchbar",
3
- "version": "0.71.35",
3
+ "version": "0.71.36",
4
4
  "contributors": [],
5
- "description": "Search field with optional dropdown `searchlist` (id, text, icons, badges, tags, URLs). Configure `value`, `initial_value`, `searchlabel`, `textarea`, `minlength`, `disable_preview`, `disabled`, and CSS parts for the input and menu. Dispatches `search` and `clear`.",
5
+ "description": "Search field with optional dropdown `searchlist` (id, text, icons, badges, tags, URLs). Configure `value`, `searchlabel`, `textarea`, `minlength`, `disable_preview`, `disabled`, and CSS parts for the input and menu. Dispatches `search` and `clear`.",
6
6
  "licenses": [
7
7
  {
8
8
  "type": "Apache-2.0",