u0ui 0.3.12

Carbon UI: IBM Carbon v11 visuals with a shadcn-style API for GPUI Kit
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
//! Stepper: a compact number input (`Stepper` in `src/ghost/primitives.jsx`,
//! Carbon `NumberInput` with its buttons on the right and a controllable width).
//!
//! - **Behavior**: Kit's [`InputState`] owns editing; the draft is parsed and
//!   clamped to `min`/`max` on blur (Enter blurs). ↑/↓ add or subtract `step`
//!   from the draft (or the value). The −/+ buttons are out of the Tab order
//!   (`tabIndex={-1}`) and disable at the bounds.
//! - **Appearance** (`.g-stepper`): `field-01` fill, 1px `border-strong-01`
//!   bottom rule, 2px inset `focus` outline while editing, `support-error`
//!   outline when invalid; buttons `density-field-md` square with a 1px
//!   `border-subtle-01` left rule and `field-hover-01` hover; disabled at 50%
//!   opacity without the rule.
//! - **Read-only** (`.cds--number--readonly`): transparent fill, `border-subtle`
//!   rule, the value focusable and copyable, the buttons `icon-disabled` and inert.
//!
//! ```ignore
//! Stepper::new("parallel").label("Max parallel agents").default_value(3.).min(1.).max(8.).helper_text("1–8")
//! Stepper::new("timeout").label("Timeout").default_value(30.).min(5.).step(5.).unit("min").width(rems(8.))
//! ```
use super::parts::{self, rem};
use crate::{
    components::form,
    density,
    icons::{CarbonIcon, Icon},
    theme::{LayerLevel, color},
    tokens::ColorRole,
};
use gpui_kit::{
    App, AppContext as _, Context, CursorStyle, ElementId, Entity, FocusHandle, Focusable as _,
    Hsla, InteractiveElement, IntoElement, MouseButton, ParentElement, Rems, RenderOnce,
    SharedString, StatefulInteractiveElement as _, Styled, Subscription, Window,
    component::input::{InputEvent, InputState, MoveDown, MoveUp},
    div,
    prelude::FluentBuilder as _,
    px,
};
use std::rc::Rc;

/// The number of decimals in `step` (`String(step).split('.')[1].length`).
pub fn step_decimals(step: f64) -> usize {
    let s = format_number(step);
    s.split_once('.').map_or(0, |(_, frac)| frac.len())
}

/// `clamp`: `+Math.min(max, Math.max(min, n)).toFixed(dec)`.
pub fn clamp(n: f64, min: f64, max: f64, step: f64) -> f64 {
    let v = n.max(min).min(max);
    let dec = step_decimals(step) as i32;
    let f = 10f64.powi(dec);
    (v * f).round() / f
}

/// `String(v)` for the values a stepper holds (`3`, `0.5`, `-2.25`).
pub fn format_number(v: f64) -> String {
    if v == v.trunc() && v.abs() < 1e15 {
        format!("{}", v as i64)
    } else {
        format!("{v}")
    }
}

/// `parseFloat(draft)`: the longest leading decimal number (after leading
/// whitespace), or `None` (`NaN`).
pub fn parse_float(text: &str) -> Option<f64> {
    let t = text.trim_start();
    let bytes = t.as_bytes();
    let mut end = 0;
    let mut seen_dot = false;
    let mut best = None;
    if end < bytes.len() && (bytes[end] == b'-' || bytes[end] == b'+') {
        end += 1;
    }
    while end < bytes.len() {
        match bytes[end] {
            b'0'..=b'9' => {
                end += 1;
                best = Some(end);
            }
            b'.' if !seen_dot => {
                seen_dot = true;
                end += 1;
            }
            _ => break,
        }
    }
    best.and_then(|e| t[..e].parse().ok())
}

/// The value a key or button press sets: `clamp(base ± step)`.
pub fn stepped(base: f64, dir: f64, min: f64, max: f64, step: f64) -> f64 {
    clamp(base + dir * step, min, max, step)
}

/// The `.g-stepper` box colors on [`LayerLevel::One`]: (fill, bottom rule, outline).
pub fn box_look(focused: bool, invalid: bool, disabled: bool) -> (Hsla, Hsla, Hsla) {
    box_look_on(LayerLevel::One, focused, invalid, disabled)
}

/// The `.g-stepper` box colors on `level`: (fill, bottom rule, outline).
pub fn box_look_on(
    level: LayerLevel,
    focused: bool,
    invalid: bool,
    disabled: bool,
) -> (Hsla, Hsla, Hsla) {
    let clear = Hsla::transparent_black();
    let fill = color(level.field());
    // `.g-stepper--disabled { border-bottom-color: transparent }`.
    let rule = if disabled {
        clear
    } else {
        color(level.border_strong())
    };
    // `.g-stepper:focus-within { outline-color: focus }`, then the later
    // `.g-field--invalid .g-stepper { outline-color: support-error }` wins.
    let outline = if invalid {
        color(ColorRole::SupportError)
    } else if focused {
        color(ColorRole::Focus)
    } else {
        clear
    };
    (fill, rule, outline)
}

/// The read-only box colors on [`LayerLevel::One`]: (fill, bottom rule, outline).
pub fn readonly_box_look(focused: bool) -> (Hsla, Hsla, Hsla) {
    readonly_box_look_on(LayerLevel::One, focused)
}

/// The read-only box colors on `level` (fill, bottom rule, outline):
/// `.cds--number--readonly input { background: transparent; border-block-end-color:
/// var(--border-subtle) }`, still outlined in `focus` while focused.
pub fn readonly_box_look_on(level: LayerLevel, focused: bool) -> (Hsla, Hsla, Hsla) {
    let clear = Hsla::transparent_black();
    let outline = if focused {
        color(ColorRole::Focus)
    } else {
        clear
    };
    (clear, color(level.border_subtle()), outline)
}

/// `.g-stepper-input { width: calc(5ch + 20px) }` (t3.css), border-box: `ch`
/// is the advance of IBM Plex Sans "0" (600/1000 em) at 14px, so 42 + 20 = 62px.
pub const INPUT_WIDTH_PX: f32 = 5. * 0.6 * 14. + 20.;

type ValueHandler = Rc<dyn Fn(f64, &mut Window, &mut App)>;

struct Model {
    value: f64,
    input: Entity<InputState>,
    editing: bool,
    min: f64,
    max: f64,
    step: f64,
    controlled: bool,
    on_change: Option<ValueHandler>,
    /// Where Enter leaves focus (see [`parts::nav_anchor`]).
    anchor: FocusHandle,
    _subscription: Subscription,
}

impl Model {
    fn set(&mut self, v: f64, window: &mut Window, cx: &mut Context<Self>) {
        if !self.controlled {
            self.value = v;
        }
        self.editing = false;
        let text = format_number(if self.controlled { v } else { self.value });
        self.input.update(cx, |s, cx| s.set_value(text, window, cx));
        if let Some(f) = self.on_change.clone() {
            f(v, window, cx);
        }
        cx.notify();
    }

    /// `base`: the parsed draft while editing, else the value.
    fn base(&self, cx: &App) -> f64 {
        if self.editing {
            parse_float(&self.input.read(cx).value()).unwrap_or(self.value)
        } else {
            self.value
        }
    }

    fn commit(&mut self, window: &mut Window, cx: &mut Context<Self>) {
        if !self.editing {
            return;
        }
        // `onBlur: const n = parseFloat(draft); if (!isNaN(n)) set(clamp(n)); setDraft(null)`.
        match parse_float(&self.input.read(cx).value()) {
            Some(n) => self.set(clamp(n, self.min, self.max, self.step), window, cx),
            None => {
                self.editing = false;
                let text = format_number(self.value);
                self.input.update(cx, |s, cx| s.set_value(text, window, cx));
                cx.notify();
            }
        }
    }
}

/// A compact number input. See the module docs.
#[derive(IntoElement)]
pub struct Stepper {
    id: ElementId,
    label: Option<SharedString>,
    value: Option<f64>,
    default_value: f64,
    min: f64,
    max: f64,
    step: f64,
    unit: Option<SharedString>,
    disabled: bool,
    readonly: bool,
    invalid: bool,
    invalid_text: Option<SharedString>,
    helper_text: Option<SharedString>,
    width: Rems,
    level: LayerLevel,
    decrease_label: SharedString,
    increase_label: SharedString,
    on_value_change: Option<ValueHandler>,
}

impl Stepper {
    /// A stepper with a stable `id` (uncontrolled, default value 0).
    pub fn new(id: impl Into<ElementId>) -> Self {
        Self {
            id: id.into(),
            label: None,
            value: None,
            default_value: 0.,
            min: f64::NEG_INFINITY,
            max: f64::INFINITY,
            step: 1.,
            unit: None,
            disabled: false,
            readonly: false,
            invalid: false,
            invalid_text: None,
            helper_text: None,
            // `width = '7rem'`.
            width: gpui_kit::rems(7.),
            level: LayerLevel::One,
            // The reference's `aria-label`s; override per locale.
            decrease_label: "Decrease".into(),
            increase_label: "Increase".into(),
            on_value_change: None,
        }
    }

    /// The layer the field sits on (`LayerLevel::One` paints `field-01`,
    /// `LayerLevel::Two` `field-02`).
    pub fn level(mut self, level: LayerLevel) -> Self {
        self.level = level;
        self
    }

    /// The label above the field.
    pub fn label(mut self, label: impl Into<SharedString>) -> Self {
        self.label = Some(label.into());
        self
    }

    /// Control the value (the caller updates it from [`Self::on_value_change`]).
    pub fn value(mut self, value: f64) -> Self {
        self.value = Some(value);
        self
    }

    /// The initial value when uncontrolled.
    pub fn default_value(mut self, value: f64) -> Self {
        self.default_value = value;
        self
    }

    /// Lower bound (default −∞).
    pub fn min(mut self, min: f64) -> Self {
        self.min = min;
        self
    }

    /// Upper bound (default +∞).
    pub fn max(mut self, max: f64) -> Self {
        self.max = max;
        self
    }

    /// Increment for ↑/↓ and the buttons (default 1); its decimals set the rounding.
    pub fn step(mut self, step: f64) -> Self {
        self.step = step;
        self
    }

    /// A unit after the number (`min`, `MB`).
    pub fn unit(mut self, unit: impl Into<SharedString>) -> Self {
        self.unit = Some(unit.into());
        self
    }

    /// Disabled.
    pub fn disabled(mut self, disabled: bool) -> Self {
        self.disabled = disabled;
        self
    }

    /// Read-only (`readOnly`): the value can be focused, selected and copied
    /// but not changed; the buttons draw in `icon-disabled` and do nothing
    /// (`.cds--number--readonly .cds--number__control-btn { color: var(--icon-disabled);
    /// pointer-events: none }`).
    pub fn readonly(mut self, readonly: bool) -> Self {
        self.readonly = readonly;
        self
    }

    /// Invalid: `support-error` outline; shows `invalid_text` instead of the helper.
    pub fn invalid(mut self, invalid: bool) -> Self {
        self.invalid = invalid;
        self
    }

    /// The error message when invalid.
    pub fn invalid_text(mut self, text: impl Into<SharedString>) -> Self {
        self.invalid_text = Some(text.into());
        self
    }

    /// Helper text under the field.
    pub fn helper_text(mut self, text: impl Into<SharedString>) -> Self {
        self.helper_text = Some(text.into());
        self
    }

    /// The field width (default 7rem).
    pub fn width(mut self, width: Rems) -> Self {
        self.width = width;
        self
    }

    /// Accessible names of the −/+ buttons (default "Decrease" / "Increase").
    pub fn button_labels(
        mut self,
        decrease: impl Into<SharedString>,
        increase: impl Into<SharedString>,
    ) -> Self {
        self.decrease_label = decrease.into();
        self.increase_label = increase.into();
        self
    }

    /// Called with each new value.
    pub fn on_value_change(mut self, f: impl Fn(f64, &mut Window, &mut App) + 'static) -> Self {
        self.on_value_change = Some(Rc::new(f));
        self
    }
}

impl RenderOnce for Stepper {
    fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
        let id = self.id.clone();
        let initial = self.value.unwrap_or(self.default_value);
        let model = window.use_keyed_state((id.clone(), "stepper"), cx, |window, cx| {
            let input =
                cx.new(|cx| InputState::new(window, cx).default_value(format_number(initial)));
            let subscription =
                cx.subscribe_in(&input, window, |this: &mut Model, _, e, window, cx| {
                    match e {
                        InputEvent::Change => {
                            this.editing = true;
                            cx.notify();
                        }
                        InputEvent::Blur => this.commit(window, cx),
                        InputEvent::PressEnter { .. } => {
                            // `if (e.key === 'Enter') e.currentTarget.blur()`. Chromium
                            // keeps the Tab starting point at the blurred input, so
                            // focus rests on an anchor beside it instead of nowhere.
                            this.commit(window, cx);
                            this.anchor.focus(window, cx);
                        }
                        InputEvent::Focus => {}
                    }
                });
            Model {
                value: initial,
                input,
                editing: false,
                min: f64::NEG_INFINITY,
                max: f64::INFINITY,
                step: 1.,
                controlled: false,
                on_change: None,
                anchor: cx.focus_handle(),
                _subscription: subscription,
            }
        });
        // Refresh the props the model's handlers read.
        model.update(cx, |m, cx| {
            m.min = self.min;
            m.max = self.max;
            m.step = self.step;
            m.on_change = self.on_value_change.clone();
            m.controlled = self.value.is_some();
            if let Some(v) = self.value
                && (v != m.value)
            {
                m.value = v;
                if !m.editing {
                    let text = format_number(v);
                    m.input.update(cx, |s, cx| s.set_value(text, window, cx));
                }
            }
        });
        let (value, input, anchor) = {
            let m = model.read(cx);
            (m.value, m.input.clone(), m.anchor.clone())
        };
        let focused = input.read(cx).focus_handle(cx).is_focused(window);
        let level = self.level;
        let (fill, rule, outline) = if self.readonly && !self.disabled {
            readonly_box_look_on(level, focused)
        } else {
            box_look_on(level, focused, self.invalid, self.disabled)
        };
        let readonly = self.readonly;
        let field_h = density::current().field().px_value();

        let mut button =
            |key: &'static str, icon: CarbonIcon, label: SharedString, dir: f64, at_bound: bool| {
                let model = model.clone();
                let inert = readonly && !self.disabled;
                let disabled = self.disabled || at_bound || inert;
                let hovered = window.use_keyed_state(
                    (ElementId::from((id.clone(), key)), "hover"),
                    cx,
                    |_, _| false,
                );
                let is_hovered = *hovered.read(cx) && !disabled;
                gpui_kit::base::Button::new((id.clone(), key))
                    .tab_stop(false)
                    .disabled(disabled)
                    .accessibility_label(label)
                    .flex()
                    // The buttons keep `flex-shrink: 1`: once the input's
                    // fixed width and the unit are placed they share what is
                    // left of the box (25px each in a 7rem stepper).
                    .flex_shrink(1.)
                    .min_w_0()
                    .items_center()
                    .justify_center()
                    .w(rem(field_h))
                    .h(rem(field_h))
                    // `border-left: 1px solid var(--border-subtle)`.
                    .border_l(px(1.))
                    .border_color(color(level.border_subtle()))
                    // `:hover:not(:disabled) { background: var(--field-hover) }`.
                    .when(is_hovered, |b| b.bg(color(level.field_hover())))
                    .cursor(if inert {
                        CursorStyle::Arrow
                    } else if disabled {
                        CursorStyle::OperationNotAllowed
                    } else {
                        CursorStyle::PointingHand
                    })
                    .on_hover(move |h, _, cx| {
                        hovered.update(cx, |v, cx| {
                            if *v != *h {
                                *v = *h;
                                cx.notify();
                            }
                        })
                    })
                    .child(
                        Icon::carbon(icon)
                            .size_length(px(14.))
                            .color(color(if disabled {
                                ColorRole::IconDisabled
                            } else {
                                ColorRole::IconPrimary
                            })),
                    )
                    .on_click(move |_, window, cx| {
                        model.update(cx, |m, cx| {
                            // `onClick={() => set(clamp(v ± step))}` from the value.
                            let v = stepped(m.value, dir, m.min, m.max, m.step);
                            m.set(v, window, cx);
                        })
                    })
            };
        let dec = button(
            "dec",
            CarbonIcon::Subtract,
            self.decrease_label.clone(),
            -1.,
            value <= self.min,
        );
        let inc = button(
            "inc",
            CarbonIcon::Add,
            self.increase_label.clone(),
            1.,
            value >= self.max,
        );

        let key = |dir: f64| {
            let model = model.clone();
            move |window: &mut Window, cx: &mut App| {
                model.update(cx, |m, cx| {
                    let v = stepped(m.base(cx), dir, m.min, m.max, m.step);
                    m.set(v, window, cx);
                })
            }
        };
        let up = key(1.);
        let down = key(-1.);

        let body = div()
            .id((id.clone(), "box"))
            .relative()
            .flex()
            .items_center()
            .w(self.width)
            .min_h(rem(field_h))
            .bg(fill)
            .when(self.disabled, |d| d.opacity(0.5))
            .when(!self.disabled, |this| {
                this.when(!readonly, |this| {
                    this.capture_action(move |_: &MoveUp, window, cx| {
                        up(window, cx);
                        cx.stop_propagation();
                    })
                    .capture_action(move |_: &MoveDown, window, cx| {
                        down(window, cx);
                        cx.stop_propagation();
                    })
                })
                .on_mouse_down(MouseButton::Left, {
                    let focus = input.read(cx).focus_handle(cx);
                    move |_, window, cx| focus.focus(window, cx)
                })
            })
            .child(
                // `.g-stepper-input { padding: 0 var(--spacing-03) 0 var(--spacing-04);
                // font-variant-numeric: tabular-nums }`, then t3.css `.g-stepper-input
                // { flex: none; width: calc(5ch + 20px) }` and `{ text-align: right;
                // padding-right: 6px }`.
                div()
                    .flex()
                    .flex_none()
                    .w(rem(INPUT_WIDTH_PX))
                    .h(rem(field_h))
                    .pl(rem(12.))
                    .pr(rem(6.))
                    .items_center()
                    .cursor(if self.disabled {
                        CursorStyle::OperationNotAllowed
                    } else {
                        CursorStyle::IBeam
                    })
                    .child(
                        parts::editor(&input)
                            .disabled(self.disabled)
                            .readonly(self.readonly)
                            .when_some(self.label.clone(), |e, l| e.aria_label(l))
                            .text_right()
                            .text_color(color(ColorRole::TextPrimary)),
                    ),
            )
            .child(parts::nav_anchor(
                (id.clone(), "anchor"),
                &anchor,
                Some(input.read(cx).focus_handle(cx)),
                cx,
            ))
            .when_some(self.unit.clone(), |this, unit| {
                // `.g-stepper-unit { padding-right: spacing-03; font-size: 0.75rem; color: text-secondary }`.
                this.child(
                    div()
                        .flex_none()
                        .pr(rem(8.))
                        .text_size(rem(12.))
                        .text_color(color(ColorRole::TextSecondary))
                        .child(unit),
                )
            })
            .child(dec)
            .child(inc)
            .child(form::bottom_rule(rule))
            .child(form::inset_outline(2., outline));

        let message = if self.invalid && self.invalid_text.is_some() {
            self.invalid_text.clone().map(parts::error)
        } else {
            self.helper_text.clone().map(parts::helper)
        };
        parts::field()
            .when_some(self.label.clone(), |f, l| f.child(parts::label(l)))
            .child(body)
            .children(message)
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::{CarbonTheme, theme::color_in};

    #[test]
    fn clamp_rounds_to_the_step_decimals() {
        assert_eq!(step_decimals(1.), 0);
        assert_eq!(step_decimals(0.25), 2);
        assert_eq!(clamp(12., f64::NEG_INFINITY, 10., 1.), 10.);
        assert_eq!(clamp(0.1 + 0.2, 0., 1., 0.1), 0.3);
        assert_eq!(clamp(-3., 1., 8., 1.), 1.);
        assert_eq!(stepped(30., -1., 5., f64::INFINITY, 5.), 25.);
        assert_eq!(stepped(5., -1., 5., f64::INFINITY, 5.), 5.);
    }

    #[test]
    fn parse_float_matches_js() {
        assert_eq!(parse_float("42"), Some(42.));
        assert_eq!(parse_float("  3.5kg"), Some(3.5));
        assert_eq!(parse_float("-2"), Some(-2.));
        assert_eq!(parse_float(".5"), Some(0.5));
        assert_eq!(parse_float("abc"), None);
        assert_eq!(parse_float(""), None);
        assert_eq!(parse_float("-"), None);
        assert_eq!(format_number(3.), "3");
        assert_eq!(format_number(0.5), "0.5");
    }

    #[test]
    fn input_is_five_ch_plus_twenty() {
        // refrender --computed `.g-stepper-input`: 62px wide in every stepper.
        assert_eq!(INPUT_WIDTH_PX, 62.);
    }

    #[test]
    fn box_states_follow_g_stepper() {
        crate::theme::tests_set(CarbonTheme::G10);
        let c = |r| color_in(CarbonTheme::G10, r);
        let (fill, rule, outline) = box_look(false, false, false);
        assert_eq!(fill, c(ColorRole::Field01));
        assert_eq!(rule, c(ColorRole::BorderStrong01));
        assert_eq!(outline, Hsla::transparent_black());
        assert_eq!(box_look(true, false, false).2, c(ColorRole::Focus));
        // The invalid rule comes later in the cascade than `:focus-within`.
        assert_eq!(box_look(true, true, false).2, c(ColorRole::SupportError));
        assert_eq!(box_look(false, false, true).1, Hsla::transparent_black());
        let (fill, rule, outline) = readonly_box_look(false);
        assert_eq!(fill, Hsla::transparent_black());
        assert_eq!(rule, c(ColorRole::BorderSubtle01));
        assert_eq!(outline, Hsla::transparent_black());
        assert_eq!(readonly_box_look(true).2, c(ColorRole::Focus));
        let (fill2, rule2, _) = box_look_on(LayerLevel::Two, false, false, false);
        assert_eq!(fill2, c(ColorRole::Field02));
        assert_eq!(rule2, c(ColorRole::BorderStrong02));
        assert_eq!(
            readonly_box_look_on(LayerLevel::Two, false).1,
            c(ColorRole::BorderSubtle02)
        );
    }
}