@htmlbricks/hb-input-radio 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.
- package/README.md +174 -10
- package/manifest.json +35 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,23 +1,187 @@
|
|
|
1
1
|
# hb-input-radio
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Category:** inputs · **Tags:** inputs
|
|
4
4
|
|
|
5
|
-
|
|
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
|
-
|
|
7
|
+
The group’s accessible name comes from **`label`**, then **`id`**, then the fallback `"Options"` (`aria-label` on the `radiogroup`).
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
---
|
|
10
10
|
|
|
11
|
-
##
|
|
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
|
+
`hb-input-radio`
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Attributes (snake_case)
|
|
25
|
+
|
|
26
|
+
Web component attributes are **strings**. For booleans exposed as attributes, use **`yes`** or **`no`** (see `show_validation`).
|
|
27
|
+
|
|
28
|
+
| Attribute | Required | Description |
|
|
29
|
+
|-----------|----------|-------------|
|
|
30
|
+
| `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. |
|
|
31
|
+
| `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). |
|
|
32
|
+
| `id` | No | Optional id on the host element. |
|
|
33
|
+
| `style` | No | Optional inline styles on the host element. |
|
|
34
|
+
|
|
35
|
+
\*Required for a usable field in markup; the TypeScript `Component` type allows `undefined` for programmatic cases.
|
|
36
|
+
|
|
37
|
+
### Passing `schemaentry` from HTML
|
|
38
|
+
|
|
39
|
+
Use a **single-quoted** attribute value so the JSON can use double quotes:
|
|
40
|
+
|
|
41
|
+
```html
|
|
42
|
+
<hb-input-radio
|
|
43
|
+
schemaentry='{"id":"plan","required":true,"label":"Plan","validationTip":"Select a plan.","params":{"options":[{"label":"Starter","value":"starter"},{"label":"Pro","value":"pro"}]}}'
|
|
44
|
+
show_validation="yes"
|
|
45
|
+
></hb-input-radio>
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
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.
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## `schemaentry` shape
|
|
53
|
+
|
|
54
|
+
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:
|
|
55
|
+
|
|
56
|
+
| Field | Description |
|
|
57
|
+
|-------|-------------|
|
|
58
|
+
| `id` | **Required.** Becomes the native `name` for all radios in the group and is echoed on events as `detail.id`. |
|
|
59
|
+
| `label` | Optional visible context; used for `aria-label` on the radiogroup. |
|
|
60
|
+
| `required` | If true, **`valid`** is false until an option is selected. |
|
|
61
|
+
| `value` | Optional initial selection; coerced with `String(...)` when the schema sync runs. |
|
|
62
|
+
| `validationTip` | Message shown when **`show_validation="yes"`**, the field is invalid, and this string is set. |
|
|
63
|
+
| `disabled` | If true, all radios are disabled. |
|
|
64
|
+
| `readonly` | If true, all radios are disabled (same effect as `disabled` in the template). |
|
|
65
|
+
| `placeholder` | Allowed by the shared schema type; **not** rendered as a separate control by this component. |
|
|
66
|
+
| `params` | **`InputRadioParams`** — see below. |
|
|
67
|
+
|
|
68
|
+
### `params` (`InputRadioParams`)
|
|
12
69
|
|
|
13
70
|
| Key | Type | Description |
|
|
14
|
-
|
|
15
|
-
| `options` | `InputRadioOption[]` | Each
|
|
71
|
+
|-----|------|-------------|
|
|
72
|
+
| `options` | `InputRadioOption[]` | List of choices. Each item needs a **`value`** (string). **`label`** is optional; the UI falls back to **`value`**. |
|
|
16
73
|
|
|
17
|
-
|
|
74
|
+
---
|
|
18
75
|
|
|
19
|
-
|
|
76
|
+
## Validation behavior
|
|
77
|
+
|
|
78
|
+
- **Required (`required: true`)**: `valid` is **false** until the user selects an option (`value` is a non-empty choice).
|
|
79
|
+
- **Optional (`required: false` or omitted)**: `valid` is **true** even when nothing is selected (`value` may be `undefined`).
|
|
80
|
+
- **Inline message**: Shown only when **`show_validation`** is **`yes`**, **`validationTip`** is set, and the current state is invalid.
|
|
81
|
+
|
|
82
|
+
---
|
|
20
83
|
|
|
21
84
|
## Events
|
|
22
85
|
|
|
23
|
-
|
|
86
|
+
| Event | `detail` | When |
|
|
87
|
+
|-------|----------|------|
|
|
88
|
+
| `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. |
|
|
89
|
+
|
|
90
|
+
Listen in plain JavaScript:
|
|
91
|
+
|
|
92
|
+
```js
|
|
93
|
+
const el = document.querySelector("hb-input-radio");
|
|
94
|
+
el.addEventListener("setVal", (e) => {
|
|
95
|
+
const { value, valid, id } = e.detail;
|
|
96
|
+
console.log(id, value, valid);
|
|
97
|
+
});
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
## Styling
|
|
103
|
+
|
|
104
|
+
- Bulma **form** patterns: `field`, `control`, `radios`, `radio`, and `help is-danger` for invalid feedback.
|
|
105
|
+
- 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`).
|
|
106
|
+
|
|
107
|
+
### CSS custom properties (high level)
|
|
108
|
+
|
|
109
|
+
| Variable | Role |
|
|
110
|
+
|----------|------|
|
|
111
|
+
| `--bulma-text` | Labels and legend-related text. |
|
|
112
|
+
| `--bulma-border` | Radio outline; group border when invalid. |
|
|
113
|
+
| `--bulma-link` | Checked accent where the browser supports tinting. |
|
|
114
|
+
| `--bulma-danger` | Invalid outline and danger help. |
|
|
115
|
+
| `--bulma-scheme-main` | Background inside the shadow root. |
|
|
116
|
+
|
|
117
|
+
### `::part` selectors
|
|
118
|
+
|
|
119
|
+
| Part | Targets |
|
|
120
|
+
|------|---------|
|
|
121
|
+
| `input` | Each native `<input type="radio">` (same part name repeated per option). |
|
|
122
|
+
| `invalid-feedback` | The `p.help.is-danger` node when validation messaging is visible. |
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## TypeScript
|
|
127
|
+
|
|
128
|
+
Authoring types for this package live in **`types/webcomponent.type.d.ts`**:
|
|
129
|
+
|
|
130
|
+
- **`InputRadioOption`**, **`InputRadioParams`**
|
|
131
|
+
- **`FormSchemaEntry`** (radio-specific entry)
|
|
132
|
+
- **`Component`** (host props)
|
|
133
|
+
- **`Events`** (`setVal` detail)
|
|
134
|
+
|
|
135
|
+
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`**.
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
## Examples
|
|
140
|
+
|
|
141
|
+
### Required group with validation
|
|
142
|
+
|
|
143
|
+
```html
|
|
144
|
+
<hb-input-radio
|
|
145
|
+
schemaentry='{"id":"tier","required":true,"label":"Tier","validationTip":"Choose a tier.","params":{"options":[{"label":"Free","value":"free"},{"label":"Paid","value":"paid"}]}}'
|
|
146
|
+
show_validation="yes"
|
|
147
|
+
></hb-input-radio>
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Preselected value
|
|
151
|
+
|
|
152
|
+
```html
|
|
153
|
+
<hb-input-radio
|
|
154
|
+
schemaentry='{"id":"region","required":true,"label":"Region","value":"eu","params":{"options":[{"label":"US","value":"us"},{"label":"EU","value":"eu"}]}}'
|
|
155
|
+
></hb-input-radio>
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Disabled group
|
|
159
|
+
|
|
160
|
+
```html
|
|
161
|
+
<hb-input-radio
|
|
162
|
+
schemaentry='{"id":"locked","label":"Plan","value":"pro","disabled":true,"params":{"options":[{"label":"Starter","value":"starter"},{"label":"Pro","value":"pro"}]}}'
|
|
163
|
+
></hb-input-radio>
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Updating options from JavaScript
|
|
167
|
+
|
|
168
|
+
```js
|
|
169
|
+
const radio = document.querySelector("hb-input-radio");
|
|
170
|
+
radio.schemaentry = JSON.stringify({
|
|
171
|
+
id: "gift",
|
|
172
|
+
required: false,
|
|
173
|
+
label: "Gift wrap",
|
|
174
|
+
params: {
|
|
175
|
+
options: [
|
|
176
|
+
{ label: "No", value: "no" },
|
|
177
|
+
{ label: "Yes", value: "yes" },
|
|
178
|
+
],
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
## Related metadata
|
|
186
|
+
|
|
187
|
+
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.
|
|
378
|
+
"version": "0.71.36"
|
|
348
379
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@htmlbricks/hb-input-radio",
|
|
3
|
-
"version": "0.71.
|
|
3
|
+
"version": "0.71.36",
|
|
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": [
|