Skip to content
This repository was archived by the owner on Nov 18, 2026. It is now read-only.

Commit f02246d

Browse files
committed
Merge branch 'feature/inputs'
# Conflicts: # README.md
2 parents 1069a7f + f9f3cfb commit f02246d

16 files changed

Lines changed: 1398 additions & 15 deletions

‎README.md‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ wherever the screen happens to be.
2626
* Sit two short fields on one line with `'width' => 'half'`
2727
* Take an amount with its currency symbol inside the control
2828
* Fill a select from a named preset — roles, timezones, countries — with one string
29+
* Put a unit inside any input — a `$` before a price, `days` after a number
30+
* Reveal a password as it is typed, and count characters against a limit
2931
* Fold a repeater's rows away, each titled by one of its own fields
3032
* Reorder a repeater by dragging its handle, or from the keyboard
3133
* Refuse a value that fails a rule — required, email, url, your own callable — and say why
@@ -157,6 +159,27 @@ options pass through the `field_kit_preset_options` filter. Register your own
157159
with `Presets::register( 'products', fn() => $options )` and any field can say
158160
`'options' => 'products'`.
159161

162+
## A unit in the box, a reveal, a count
163+
164+
Any single-line input takes a `prefix` or a `suffix`, drawn inside the box
165+
and announced with the value. A `percentage` is a number from 0 to 100 with
166+
the sign already in it. A password shows what is typed on request, and
167+
anything with a `maxlength` counts as you go.
168+
169+
```php
170+
$set = new FieldSet(
171+
[
172+
'price' => [ 'type' => 'number', 'label' => __( 'Price', 'my-plugin' ), 'prefix' => '$', 'step' => 0.01 ],
173+
'discount' => [ 'type' => 'percentage', 'label' => __( 'Discount', 'my-plugin' ) ],
174+
'expires' => [ 'type' => 'number', 'label' => __( 'Expires after', 'my-plugin' ), 'suffix' => 'days' ],
175+
'api_key' => [ 'type' => 'password', 'label' => __( 'API key', 'my-plugin' ), 'reveal' => true ],
176+
'tagline' => [ 'type' => 'text', 'label' => __( 'Tagline', 'my-plugin' ), 'maxlength' => 80 ],
177+
],
178+
new OptionContext( 'my_plugin' ),
179+
'my_plugin'
180+
);
181+
```
182+
160183
## Requirements
161184

162185
* PHP 8.3 or later

‎assets/css/field-kit.css‎

Lines changed: 166 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3249,22 +3249,30 @@ span.field-kit__provider-logo {
32493249
could press to change the currency -- which is the one thing it does not
32503250
do, since the currency is a setting. Muted text in the input's own
32513251
leading padding instead. */
3252-
.field-kit__money-symbol {
3252+
.field-kit__money-symbol,
3253+
.field-kit__adornment {
32533254
position: absolute;
32543255
top: 0;
32553256
bottom: 0;
3256-
inset-inline-start: 0;
32573257
display: flex;
32583258
align-items: center;
3259-
justify-content: flex-end;
32603259
width: 2rem;
3261-
padding-inline-end: .1rem;
32623260
color: #646970;
32633261
font-size: 13px;
32643262
line-height: 1;
32653263
pointer-events: none;
32663264
}
32673265

3266+
/* Leading: set against the start of the value, with a hair of space before
3267+
the first digit. The money symbol is always this; a prefix on any other
3268+
input is the same thing. */
3269+
.field-kit__money-symbol,
3270+
.field-kit__adornment--prefix {
3271+
inset-inline-start: 0;
3272+
justify-content: flex-end;
3273+
padding-inline-end: .1rem;
3274+
}
3275+
32683276
.wp-core-ui .field-kit__money input.field-kit__money-value,
32693277
.field-kit__money input.field-kit__money-value {
32703278
width: 100%;
@@ -3277,7 +3285,9 @@ span.field-kit__provider-logo {
32773285

32783286
/* A longer symbol -- "CHF", or a code standing in for one we have no symbol
32793287
for -- needs the room, and the input needs to know how much. */
3280-
.field-kit__money--wide .field-kit__money-symbol {
3288+
.field-kit__money--wide .field-kit__money-symbol,
3289+
.field-kit__adorned--wide-prefix > .field-kit__adornment--prefix,
3290+
.field-kit__adorned--wide-suffix > .field-kit__adornment--suffix {
32813291
width: 3.1rem;
32823292
}
32833293

@@ -3286,6 +3296,157 @@ span.field-kit__provider-logo {
32863296
padding-inline-start: 3.3rem;
32873297
}
32883298

3299+
/* -----------------------------------------------------------------------
3300+
* Adornments
3301+
*
3302+
* A unit inside the box: "$" before a price, "%" after a discount, "days"
3303+
* after a number. Built the way the money symbol above is -- muted text in
3304+
* the input's own padding, sharing its rules -- and for the same reason: a
3305+
* unit set beside a full-width input wraps onto a line of its own inside a
3306+
* narrow panel, and boxed with a border of its own it reads as a button.
3307+
* -------------------------------------------------------------------- */
3308+
3309+
/* Shrink-wrapped round the input, so a trailing affix sits at the input's
3310+
end rather than the row's. The input keeps whatever width class it has. */
3311+
.field-kit__adorned {
3312+
position: relative;
3313+
display: inline-block;
3314+
max-width: 100%;
3315+
vertical-align: middle;
3316+
}
3317+
3318+
/* Except round a full-width one. A percentage width inside a shrink-wrapped
3319+
box has nothing to resolve against and the input collapses to its
3320+
intrinsic size, so the wrapper goes full width instead, takes a flex
3321+
line's spare room where it sits in one, and the input fills it -- core's
3322+
large-text is 99%, which would leave the suffix a sliver past the box. */
3323+
.field-kit__adorned:has( > .large-text ) {
3324+
display: block;
3325+
flex: 1 1 auto;
3326+
}
3327+
3328+
.wp-core-ui .field-kit__adorned:has( > .large-text ) > input.field-kit__input,
3329+
.field-kit__adorned:has( > .large-text ) > input.field-kit__input {
3330+
width: 100%;
3331+
}
3332+
3333+
/* Trailing: set against the end of the value. Narrower than the leading
3334+
one, because core gives a small number 65px and "100" beside a "%" has to
3335+
fit in it. */
3336+
.field-kit__adornment--suffix {
3337+
inset-inline-end: 0;
3338+
justify-content: flex-start;
3339+
width: 1.6rem;
3340+
padding-inline-start: .1rem;
3341+
}
3342+
3343+
.wp-core-ui .field-kit__adorned > input.field-kit__input,
3344+
.field-kit__adorned > input.field-kit__input {
3345+
max-width: 100%;
3346+
margin: 0;
3347+
}
3348+
3349+
.wp-core-ui .field-kit__adorned--prefix > input.field-kit__input,
3350+
.field-kit__adorned--prefix > input.field-kit__input {
3351+
padding-inline-start: 2.2rem;
3352+
}
3353+
3354+
.wp-core-ui .field-kit__adorned--suffix > input.field-kit__input,
3355+
.field-kit__adorned--suffix > input.field-kit__input {
3356+
padding-inline-end: 1.7rem;
3357+
}
3358+
3359+
/* A longer affix takes the room the money field gives a currency code, and
3360+
the input reserves the same. */
3361+
.wp-core-ui .field-kit__adorned--wide-prefix > input.field-kit__input,
3362+
.field-kit__adorned--wide-prefix > input.field-kit__input {
3363+
padding-inline-start: 3.3rem;
3364+
}
3365+
3366+
.wp-core-ui .field-kit__adorned--wide-suffix > input.field-kit__input,
3367+
.field-kit__adorned--wide-suffix > input.field-kit__input {
3368+
padding-inline-end: 3.3rem;
3369+
}
3370+
3371+
/* A number's spinner lives exactly where a suffix does, and Firefox draws
3372+
it whether or not the pointer is near. The two cannot share the space,
3373+
so the spinner goes: the arrow keys still step the value, and the unit
3374+
is the thing worth seeing. */
3375+
.field-kit__adorned--suffix > input[type="number"] {
3376+
-moz-appearance: textfield;
3377+
appearance: textfield;
3378+
}
3379+
3380+
.field-kit__adorned--suffix > input[type="number"]::-webkit-inner-spin-button,
3381+
.field-kit__adorned--suffix > input[type="number"]::-webkit-outer-spin-button {
3382+
-webkit-appearance: none;
3383+
margin: 0;
3384+
}
3385+
3386+
/* -----------------------------------------------------------------------
3387+
* Password reveal
3388+
*
3389+
* The input and its reveal button on one line. The button is core's own
3390+
* from the profile screen -- .wp-hide-pw, whose rule sizes the eye -- so it
3391+
* is the one people have already met, and hide-if-no-js keeps it off a page
3392+
* where nothing would work it.
3393+
* -------------------------------------------------------------------- */
3394+
3395+
/* Centred rather than stretched: a flex line's default pulls the input up
3396+
to the button's height, and core sizes the two differently. The input
3397+
keeps its width class, and a full-width one gives way to the button
3398+
rather than pushing it onto the next line. */
3399+
.field-kit__password {
3400+
display: flex;
3401+
align-items: center;
3402+
gap: .25rem;
3403+
max-width: 100%;
3404+
}
3405+
3406+
.field-kit__password > input.field-kit__input,
3407+
.field-kit__password > .field-kit__adorned {
3408+
min-width: 0;
3409+
margin: 0;
3410+
}
3411+
3412+
.wp-core-ui .field-kit__password-toggle {
3413+
display: inline-flex;
3414+
flex: 0 0 auto;
3415+
align-items: center;
3416+
justify-content: center;
3417+
padding: 0 6px;
3418+
}
3419+
3420+
/* -----------------------------------------------------------------------
3421+
* Character count
3422+
* -------------------------------------------------------------------- */
3423+
3424+
/* Under the control, at its end -- which is why it borrows the control's
3425+
own width class: core's regular-text is 25em wherever it is written, so
3426+
the count is as wide as the input and its number sits under the input's
3427+
end rather than at the far edge of a settings-page cell. The field's
3428+
own .description rule supplies the spacing. */
3429+
.field-kit__count {
3430+
display: block;
3431+
color: #646970;
3432+
font-size: 12px;
3433+
text-align: end;
3434+
font-variant-numeric: tabular-nums;
3435+
}
3436+
3437+
/* Core scopes large-text to the input and the textarea, so on a span the
3438+
class does nothing until it is restated. */
3439+
.field-kit__count.large-text {
3440+
width: 99%;
3441+
}
3442+
3443+
/* A value saved before the limit was lowered. The browser stops anyone
3444+
typing past a maxlength; it does not truncate what was there. */
3445+
.field-kit__count--over {
3446+
color: #d63638;
3447+
font-weight: 600;
3448+
}
3449+
32893450
/* A row folds away to its header. `li` on purpose: a <tr> given a display of
32903451
its own leaves the table's column geometry, and its cells stop lining up
32913452
under the headers at all. A table repeater is never collapsible, but the

0 commit comments

Comments
 (0)