ng-hub-ui-forms 22.29.0 → 22.31.0
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 +91 -0
- package/fesm2022/ng-hub-ui-forms.mjs +221 -131
- package/fesm2022/ng-hub-ui-forms.mjs.map +1 -1
- package/package.json +1 -1
- package/styles/_field.scss +158 -3
- package/styles/_tokens.scss +40 -0
- package/styles/index.scss +7 -0
- package/types/ng-hub-ui-forms.d.ts +84 -76
package/README.md
CHANGED
|
@@ -149,6 +149,40 @@ npm install ng-hub-ui-forms @angular/cdk
|
|
|
149
149
|
|
|
150
150
|
## ⚙️ Usage
|
|
151
151
|
|
|
152
|
+
### Helper text
|
|
153
|
+
|
|
154
|
+
Every field takes `formText`, and `formTextType` says where it goes.
|
|
155
|
+
|
|
156
|
+
```html
|
|
157
|
+
<!-- one sentence: below, where it is read without being asked for -->
|
|
158
|
+
<hub-input label="Name" formText="As it appears on the card." />
|
|
159
|
+
|
|
160
|
+
<!-- more than one: behind a question mark at the end of the label row -->
|
|
161
|
+
<hub-input
|
|
162
|
+
label="IBAN"
|
|
163
|
+
formTextType="tooltip"
|
|
164
|
+
formText="The account the refund is paid into. It must belong to the cardholder — a transfer to a third party is rejected by the bank."
|
|
165
|
+
/>
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
The rule the product settled on is **one sentence below, more than one in the tooltip**. A paragraph
|
|
169
|
+
under every field turns a form into a document, pushes the next field off the screen, and is read by
|
|
170
|
+
nobody who already knew what the field was for.
|
|
171
|
+
|
|
172
|
+
The mark is pushed to the end of the label row, so a column of fields lines its question marks up
|
|
173
|
+
instead of scattering them wherever each label happens to stop. It is a `<button>` beside the label
|
|
174
|
+
and never inside it: activating a label focuses the control it names, so a mark nested in one would
|
|
175
|
+
open the tooltip _and_ jump the caret into the field. Its accessible name is the helper text itself.
|
|
176
|
+
|
|
177
|
+
`formTextType="tooltip"` needs the tooltip stylesheet, which this package does not pull in for you:
|
|
178
|
+
|
|
179
|
+
```scss
|
|
180
|
+
@use 'ng-hub-ui-utils/styles/tooltip';
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
A projected `hubFormText` template keeps its block below even in tooltip mode. The tooltip takes a
|
|
184
|
+
string, so asking it to carry markup would drop the markup silently.
|
|
185
|
+
|
|
152
186
|
### Input
|
|
153
187
|
|
|
154
188
|
```html
|
|
@@ -210,6 +244,63 @@ provideHubForms({
|
|
|
210
244
|
});
|
|
211
245
|
```
|
|
212
246
|
|
|
247
|
+
#### Plain-text fields
|
|
248
|
+
|
|
249
|
+
`readonly` and `plaintext` are the two halves of a shut field, and the difference is who the
|
|
250
|
+
field is for. `readonly` is a _state_ of a field somebody is still filling in, and a theme can
|
|
251
|
+
give it a box — `--hub-input-readonly-bg`, `--hub-input-readonly-border-color`, `-color` and
|
|
252
|
+
`-cursor` exist to be set. `plaintext` is for a value that is merely being _shown_: a record
|
|
253
|
+
open for consultation, a figure the server settled, a field a plan has locked. There the box is
|
|
254
|
+
noise, and having none is what `plaintext` is rather than a colour it happens to wear.
|
|
255
|
+
|
|
256
|
+
> **At the shipped defaults `readonly` already draws no box** — both those token defaults are
|
|
257
|
+
> `transparent`, deliberately: a read-only value is there to be read and loses only the chrome
|
|
258
|
+
> that promises you can type in it. Untouched, the two differ in the horizontal padding (12px
|
|
259
|
+
> against 0), the inline border width, the cursor, and the affordances. Set the two tokens and
|
|
260
|
+
> read-only takes the boxed look Bootstrap's own `readonly` ships with, while `plaintext` stays
|
|
261
|
+
> flat:
|
|
262
|
+
>
|
|
263
|
+
> ```css
|
|
264
|
+
> .hub-field--readonly {
|
|
265
|
+
> --hub-input-readonly-bg: var(--hub-sys-surface-sunken);
|
|
266
|
+
> --hub-input-readonly-border-color: var(--hub-sys-border-subtle);
|
|
267
|
+
> }
|
|
268
|
+
> ```
|
|
269
|
+
|
|
270
|
+
The value steps back a shade. Inside a box the box does the separating; with it gone, label and
|
|
271
|
+
value were the same colour and two pixels apart in size, so a column of them read as
|
|
272
|
+
undifferentiated lines. The label is left exactly as every other field's — same tokens, same
|
|
273
|
+
weight, because a form's labels keep one rhythm whatever state each field is in — and
|
|
274
|
+
`--hub-input-plaintext-color` moves the value instead, to `gray-700` against the editable
|
|
275
|
+
`gray-900`, with `--hub-input-plaintext-font-weight` one step lighter so it does not compete
|
|
276
|
+
with its own label.
|
|
277
|
+
|
|
278
|
+
The vertical padding moves rather than shrinks, through `--hub-input-plaintext-padding-block`:
|
|
279
|
+
none above, the field's whole vertical padding below. Nothing above puts the value directly under
|
|
280
|
+
its label — a label and its value are one thing and should read as a pair — while twice the
|
|
281
|
+
padding below holds the control at exactly an editable field's height, so a grid mixing the two
|
|
282
|
+
still lines up. Replace it with a single value and you give up one of the two.
|
|
283
|
+
|
|
284
|
+
```html
|
|
285
|
+
<!-- being filled in, so it keeps the box -->
|
|
286
|
+
<hub-input formControlName="reference" label="Reference" [readonly]="true" />
|
|
287
|
+
|
|
288
|
+
<!-- merely being read, so the box goes -->
|
|
289
|
+
<hub-input formControlName="customer" label="Customer" [plaintext]="true" />
|
|
290
|
+
<hub-textarea formControlName="notes" label="Notes" [rows]="3" [plaintext]="true" />
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
Modelled on Bootstrap's `.form-control-plaintext`, deliberately: the control stays a real
|
|
294
|
+
`<input>` / `<textarea>`, so the `<label for>` still points at something labelable and the text
|
|
295
|
+
stays selectable. A `<span>` would have broken both while going on looking right.
|
|
296
|
+
|
|
297
|
+
The horizontal padding goes and the border turns transparent **without losing its width**, so a
|
|
298
|
+
plain-text value lands on the same baseline as an editable neighbour and a form mixing the two
|
|
299
|
+
does not stagger. `plaintext` implies `readonly` and the two presentations are exclusive, so
|
|
300
|
+
they can never be passed in disagreement. Every affordance goes with the box — the clear button,
|
|
301
|
+
a projected caret, a datepicker icon, and a textarea's character counter, which tells you how
|
|
302
|
+
much room is left to type and so promises typing.
|
|
303
|
+
|
|
213
304
|
### Select
|
|
214
305
|
|
|
215
306
|
```html
|