@htmlbricks/hb-input-radio 0.71.35 → 0.71.37

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 +177 -11
  2. package/manifest.json +35 -4
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,23 +1,189 @@
1
- # hb-input-radio
1
+ # `hb-input-radio`
2
2
 
3
- ## Description
3
+ **Category:** inputs · **Tags:** inputs
4
4
 
5
- Radio group built from **`schemaentry.params`** as **`InputRadioParams`**: optional **`options`** array of **`InputRadioOption`** (`value`, optional `label`). The shared native `name` is derived from the field `id`. Parses JSON `schemaentry` for initial `value` and supports required validation with Bulma `help is-danger` when `show_validation` is `yes` and invalid. Dispatches **`setVal`** with the selected string `value`, `valid`, and `id` whenever the choice changes.
5
+ `hb-input-radio` is a Bulma-styled **radio group** web component. It reads its configuration from a single **`schemaentry`** payload (JSON in HTML, or an object when set from JavaScript), builds one native `<input type="radio">` per option under a shared **`name`** equal to the field **`id`**, and reports the current choice with a **`setVal`** custom event.
6
6
 
7
- ## Styling (Bulma)
7
+ The group’s accessible name comes from **`label`**, then **`id`**, then the fallback `"Options"` (`aria-label` on the `radiogroup`).
8
8
 
9
- Shadow bundle: `form/shared`, `form/input-textarea`, `form/checkbox-radio`, `form/tools`. Markup uses Bulma `radios` / `radio` and host outline when invalid.
9
+ ---
10
10
 
11
- ## `schemaentry.params` (`InputRadioParams`)
11
+ ## When the component renders
12
+
13
+ - If **`schemaentry`** is missing, not parseable as JSON, or not an object, **nothing** is rendered.
14
+ - If **`params.options`** is missing or empty, the **field shell** still renders but **no radios** appear until you supply at least one option.
15
+
16
+ ---
17
+
18
+ ## Custom element
19
+
20
+ | Name | Tag |
21
+ | --- | --- |
22
+ | `hb-input-radio` | `<hb-input-radio …></hb-input-radio>` |
23
+
24
+ ---
25
+
26
+ ## Attributes (snake_case)
27
+
28
+ Web component attributes are **strings**. For booleans exposed as attributes, use **`yes`** or **`no`** (see `show_validation`).
29
+
30
+ | Attribute | Required | Description |
31
+ |-----------|----------|-------------|
32
+ | `schemaentry` | Yes* | Serialized field definition (JSON string from HTML). Must include a stable **`id`** and, for choices, **`params.options`**. Can be set to `undefined` / omitted in typed wrappers; the host then renders nothing. |
33
+ | `show_validation` | No | `"yes"` or `"no"` (default **`no`**). When **`yes`**, a required group with no selection shows **`validationTip`** in a Bulma danger help line (if `validationTip` is set). |
34
+ | `id` | No | Optional id on the host element. |
35
+ | `style` | No | Optional inline styles on the host element. |
36
+
37
+ \*Required for a usable field in markup; the TypeScript `Component` type allows `undefined` for programmatic cases.
38
+
39
+ ### Passing `schemaentry` from HTML
40
+
41
+ Use a **single-quoted** attribute value so the JSON can use double quotes:
42
+
43
+ ```html
44
+ <hb-input-radio
45
+ schemaentry='{"id":"plan","required":true,"label":"Plan","validationTip":"Select a plan.","params":{"options":[{"label":"Starter","value":"starter"},{"label":"Pro","value":"pro"}]}}'
46
+ show_validation="yes"
47
+ ></hb-input-radio>
48
+ ```
49
+
50
+ From JavaScript you may assign **`element.schemaentry`** as either a **JSON string** or a **plain object**; the internal parser accepts both without mutating the prop.
51
+
52
+ ---
53
+
54
+ ## `schemaentry` shape
55
+
56
+ The host expects a **`FormSchemaEntry`** compatible object (see `types/webcomponent.type.d.ts` and shared `FormSchemaEntryShared` from `hb-form`). Fields that matter for this component:
57
+
58
+ | Field | Description |
59
+ |-------|-------------|
60
+ | `id` | **Required.** Becomes the native `name` for all radios in the group and is echoed on events as `detail.id`. |
61
+ | `label` | Optional visible context; used for `aria-label` on the radiogroup. |
62
+ | `required` | If true, **`valid`** is false until an option is selected. |
63
+ | `value` | Optional initial selection; coerced with `String(...)` when the schema sync runs. |
64
+ | `validationTip` | Message shown when **`show_validation="yes"`**, the field is invalid, and this string is set. |
65
+ | `disabled` | If true, all radios are disabled. |
66
+ | `readonly` | If true, all radios are disabled (same effect as `disabled` in the template). |
67
+ | `placeholder` | Allowed by the shared schema type; **not** rendered as a separate control by this component. |
68
+ | `params` | **`InputRadioParams`** — see below. |
69
+
70
+ ### `params` (`InputRadioParams`)
12
71
 
13
72
  | Key | Type | Description |
14
- | --- | --- | --- |
15
- | `options` | `InputRadioOption[]` | Each entry: **`value`**, optional **`label`** (falls back to `value` in the UI). |
73
+ |-----|------|-------------|
74
+ | `options` | `InputRadioOption[]` | List of choices. Each item needs a **`value`** (string). **`label`** is optional; the UI falls back to **`value`**. |
16
75
 
17
- ## Typings
76
+ ---
18
77
 
19
- **`types/webcomponent.type.d.ts`** `InputRadioParams`, `InputRadioOption`, `FormSchemaEntry`, `Component`, `Events`.
78
+ ## Validation behavior
79
+
80
+ - **Required (`required: true`)**: `valid` is **false** until the user selects an option (`value` is a non-empty choice).
81
+ - **Optional (`required: false` or omitted)**: `valid` is **true** even when nothing is selected (`value` may be `undefined`).
82
+ - **Inline message**: Shown only when **`show_validation`** is **`yes`**, **`validationTip`** is set, and the current state is invalid.
83
+
84
+ ---
20
85
 
21
86
  ## Events
22
87
 
23
- - **`setVal`** `{ value: string | undefined; valid: boolean; id: string }`
88
+ | Event | `detail` | When |
89
+ |-------|----------|------|
90
+ | `setVal` | `{ value: string \| undefined; valid: boolean; id: string }` | Whenever **`value`**, **`valid`**, or **`id`** changes in a way that affects the payload. Duplicate payloads are suppressed. |
91
+
92
+ Listen in plain JavaScript:
93
+
94
+ ```js
95
+ const el = document.querySelector("hb-input-radio");
96
+ el.addEventListener("setVal", (e) => {
97
+ const { value, valid, id } = e.detail;
98
+ console.log(id, value, valid);
99
+ });
100
+ ```
101
+
102
+ ---
103
+
104
+ ## Styling
105
+
106
+ - Bulma **form** patterns: `field`, `control`, `radios`, `radio`, and `help is-danger` for invalid feedback.
107
+ - Theme the host with Bulma **CSS variables** on `:host` — see [Bulma CSS variables](https://bulma.io/documentation/features/css-variables/). Public tokens used by this bundle are listed in **`extra/docs.ts`** (`styleSetup.vars`).
108
+
109
+ ### CSS custom properties (high level)
110
+
111
+ | Variable | Role |
112
+ |----------|------|
113
+ | `--bulma-text` | Labels and legend-related text. |
114
+ | `--bulma-border` | Radio outline; group border when invalid. |
115
+ | `--bulma-link` | Checked accent where the browser supports tinting. |
116
+ | `--bulma-danger` | Invalid outline and danger help. |
117
+ | `--bulma-scheme-main` | Background inside the shadow root. |
118
+
119
+ ### `::part` selectors
120
+
121
+ | Part | Targets |
122
+ |------|---------|
123
+ | `input` | Each native `<input type="radio">` (same part name repeated per option). |
124
+ | `invalid-feedback` | The `p.help.is-danger` node when validation messaging is visible. |
125
+
126
+ ---
127
+
128
+ ## TypeScript
129
+
130
+ Authoring types for this package live in **`types/webcomponent.type.d.ts`**:
131
+
132
+ - **`InputRadioOption`**, **`InputRadioParams`**
133
+ - **`FormSchemaEntry`** (radio-specific entry)
134
+ - **`Component`** (host props)
135
+ - **`Events`** (`setVal` detail)
136
+
137
+ After a full web component build, generated element maps may also include this tag under **`types/html-elements.d.ts`** / **`types/svelte-elements.d.ts`**.
138
+
139
+ ---
140
+
141
+ ## Examples
142
+
143
+ ### Required group with validation
144
+
145
+ ```html
146
+ <hb-input-radio
147
+ schemaentry='{"id":"tier","required":true,"label":"Tier","validationTip":"Choose a tier.","params":{"options":[{"label":"Free","value":"free"},{"label":"Paid","value":"paid"}]}}'
148
+ show_validation="yes"
149
+ ></hb-input-radio>
150
+ ```
151
+
152
+ ### Preselected value
153
+
154
+ ```html
155
+ <hb-input-radio
156
+ schemaentry='{"id":"region","required":true,"label":"Region","value":"eu","params":{"options":[{"label":"US","value":"us"},{"label":"EU","value":"eu"}]}}'
157
+ ></hb-input-radio>
158
+ ```
159
+
160
+ ### Disabled group
161
+
162
+ ```html
163
+ <hb-input-radio
164
+ schemaentry='{"id":"locked","label":"Plan","value":"pro","disabled":true,"params":{"options":[{"label":"Starter","value":"starter"},{"label":"Pro","value":"pro"}]}}'
165
+ ></hb-input-radio>
166
+ ```
167
+
168
+ ### Updating options from JavaScript
169
+
170
+ ```js
171
+ const radio = document.querySelector("hb-input-radio");
172
+ radio.schemaentry = JSON.stringify({
173
+ id: "gift",
174
+ required: false,
175
+ label: "Gift wrap",
176
+ params: {
177
+ options: [
178
+ { label: "No", value: "no" },
179
+ { label: "Yes", value: "yes" },
180
+ ],
181
+ },
182
+ });
183
+ ```
184
+
185
+ ---
186
+
187
+ ## Related metadata
188
+
189
+ Storybook knobs, CSS variables, `::part` names, and packaged examples are defined in **`extra/docs.ts`** (`componentSetup`, `styleSetup`, `examples`).
package/manifest.json CHANGED
@@ -176,15 +176,46 @@
176
176
  }
177
177
  },
178
178
  "styleSetup": {
179
- "vars": [],
179
+ "vars": [
180
+ {
181
+ "name": "--bulma-text",
182
+ "valueType": "color",
183
+ "defaultValue": "",
184
+ "description": "Radio labels and legend text color."
185
+ },
186
+ {
187
+ "name": "--bulma-border",
188
+ "valueType": "color",
189
+ "defaultValue": "",
190
+ "description": "Radio outline and group border when invalid."
191
+ },
192
+ {
193
+ "name": "--bulma-link",
194
+ "valueType": "color",
195
+ "defaultValue": "",
196
+ "description": "Checked radio accent (native control tint where supported)."
197
+ },
198
+ {
199
+ "name": "--bulma-danger",
200
+ "valueType": "color",
201
+ "defaultValue": "",
202
+ "description": "Invalid group outline and `help is-danger`."
203
+ },
204
+ {
205
+ "name": "--bulma-scheme-main",
206
+ "valueType": "color",
207
+ "defaultValue": "",
208
+ "description": "Background for the radios block inside the shadow root."
209
+ }
210
+ ],
180
211
  "parts": [
181
212
  {
182
213
  "name": "input",
183
- "description": ""
214
+ "description": "Each native `<input type=\"radio\">` in the group (same part name repeated per option)."
184
215
  },
185
216
  {
186
217
  "name": "invalid-feedback",
187
- "description": ""
218
+ "description": "The `p.help.is-danger` message when `show_validation` is `yes` and a required choice is missing."
188
219
  }
189
220
  ]
190
221
  },
@@ -344,5 +375,5 @@
344
375
  "size": {},
345
376
  "iifePath": "main.iife.js",
346
377
  "repoName": "@htmlbricks/hb-input-radio",
347
- "version": "0.71.35"
378
+ "version": "0.71.37"
348
379
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@htmlbricks/hb-input-radio",
3
- "version": "0.71.35",
3
+ "version": "0.71.37",
4
4
  "contributors": [],
5
5
  "description": "Radio group from `schemaentry.params` as `InputRadioParams`: optional `options` array of `InputRadioOption` (`value`, optional `label`); the native `name` matches the field `id`. Initial `value` is stringified from `schemaentry`. Required + `show_validation` use Bulma `radios` / `radio` and `help is-danger`. Dispatches `setVal` `{ value, valid, id }` when the selection changes. Theme `--bulma-*` on `:host`. Typings: `InputRadioParams`, `InputRadioOption`, `FormSchemaEntry`, `Component`, `Events`.",
6
6
  "licenses": [