lurq 0.65.1

A Rust UI toolkit with typed components, retained state, reactive signals, GPU rendering, and DevTools.
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
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
//! A password input: an input whose text is masked, with a button at its end that shows it and hides it again.

use std::sync::Arc;

use super::{
  field::{FieldControl, InField},
  icon::Icon,
  icons,
  input::{Input, InputPart, InputView},
  names,
  part_style::{Length, PartStyle},
  recipe::{Interaction, Name, Recipe, ResolvedPart, ResolvedRecipe},
  shared::{fading, pressable},
  theme::{Themed, current_theme},
};
use crate::{
  app::{
    component::Component,
    ctx::Ctx,
    events::TextInputEvent,
    theme::{IconSize, PaletteColor, RadiusSize, Theme, TypographyStyle},
  },
  components::{self, Column, Row},
  core::Signal,
  layout::Alignment,
  node::{CursorIcon, Element, dimension::Dimension, node_kind::ContentKind},
};

/// The parts of a password input a recipe styles. The box, its text and its placeholder are an
/// [`Input`]'s, styled by the theme's recipe for an input.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum PasswordInputPart {
  /// The input, and the meter and what it says under it.
  Root,
  /// The masked text: the room between its dots.
  Mask,
  /// The button at the end of the box that shows the password and hides it again.
  Toggle,
  /// The meter of the password's strength: its bars side by side.
  Strength,
  /// A bar of the meter the strength does not reach.
  Bar,
  /// A bar of the meter the strength reaches, in the strength's color.
  Fill,
  /// What the meter says of the strength, under it.
  Description,
}

names!(PasswordInputPart {
  Root => "root",
  Mask => "mask",
  Toggle => "toggle",
  Strength => "strength",
  Bar => "bar",
  Fill => "fill",
  Description => "description",
});

/// The states of a password input a recipe styles, besides an input's.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum PasswordInputState {
  /// The password is shown as it is typed.
  Revealed,
  /// It takes no input.
  Disabled,
  /// It is as wide as what holds it, with its meter.
  FullWidth,
  /// It is in a fluid field ([`Field::fluid`](super::Field::fluid)): the field's label is inside its box, over
  /// what it holds.
  Fluid,
}

names!(PasswordInputState {
  Revealed => "revealed",
  Disabled => "disabled",
  FullWidth => "full_width",
  Fluid => "fluid",
});

/// How strong the app judges a password to be: what the meter under the input shows.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum PasswordStrength {
  /// One bar in the destructive color.
  Weak,
  /// Two bars in the warning color.
  Fair,
  /// Three bars in the success color.
  Good,
  /// All four bars in the success color.
  Strong,
}

names!(PasswordStrength {
  Weak => "weak",
  Fair => "fair",
  Good => "good",
  Strong => "strong",
});

impl PasswordStrength {
  /// How many of the meter's bars it fills.
  pub fn bars(self) -> usize {
    match self {
      Self::Weak => 1,
      Self::Fair => 2,
      Self::Good => 3,
      Self::Strong => 4,
    }
  }

  /// What the meter says of it unless the app says otherwise: the words of the app's locale
  /// ([`Locale::fields`](crate::core::Locale::fields)) where it is said in a render, English outside one.
  pub fn text(self) -> Arc<str> {
    let locale = super::current_locale();
    let words = &locale.fields;
    match self {
      Self::Weak => words.weak_password.clone(),
      Self::Fair => words.fair_password.clone(),
      Self::Good => words.good_password.clone(),
      Self::Strong => words.strong_password.clone(),
    }
  }
}

/// The sizes of a password input: an input's.
pub type PasswordInputSize = super::TextBoxSize;

/// What builds a password input's nodes: a theme's in place of the default one.
pub type PasswordInputRenderer = Arc<dyn Fn(PasswordInputView) -> Element + Send + Sync>;

type RevealHandler = Arc<dyn Fn(bool) + Send + Sync>;

/// A password input: an [`Input`] whose text is masked, with a button at the
/// end of the box that shows the password and hides it again.
///
/// ```
/// use lurq::{core::Signal, ui::{PasswordInput, PasswordStrength}};
///
/// let password = Signal::new(String::new());
/// let shown = Signal::new(false);
/// let input = PasswordInput::new(password.clone())
///   .placeholder("Password")
///   .bind_reveal(shown.clone())
///   .strength(Some(PasswordStrength::Good));
/// ```
///
/// It is an input in every other way: its sizes, its judgments, read only,
/// disabled, a field's label. The button that shows the password is drawn
/// unless [`reveal_button`](Self::reveal_button) says not, after the input
/// in the order of Tab, called "Show password" or "Hide password" to
/// tooling. Whether the password is shown is kept by a `Signal<bool>` the app
/// binds ([`bind_reveal`](Self::bind_reveal)), by the app itself with
/// [`reveal`](Self::reveal) and [`on_reveal`](Self::on_reveal), or, with
/// neither, by the input mounted with [`mount`](Self::mount). Converted into
/// an element with neither, it is its still form: the button turns nothing. A masked
/// password is not copied, and tooling reads only its mask; shown, it is
/// what the screen shows, to tooling too. Under the input the app may show
/// a meter of the password's strength and what it says of it.
#[derive(Clone)]
pub struct PasswordInput {
  input: Input,
  revealed: bool,
  on_reveal: Vec<RevealHandler>,
  reveal_button: bool,
  show_label: Arc<str>,
  hide_label: Arc<str>,
  strength: Option<PasswordStrength>,
  strength_text: Option<Arc<str>>,
  new_password: bool,
  full_width: bool,
  states: Vec<Name>,
  rules: Recipe,
  forced: Option<Interaction>,
  /// The id the control is given, which the password input's own parts are named after.
  id: Option<Arc<str>>,
}

impl PasswordInput {
  /// A password input bound to `value`: what is typed is set on it.
  pub fn new(value: Signal<String>) -> Self {
    Self {
      input: Input::new(value),
      revealed: false,
      on_reveal: Vec::new(),
      reveal_button: true,
      show_label: super::current_locale().fields.show_password.clone(),
      hide_label: super::current_locale().fields.hide_password.clone(),
      strength: None,
      strength_text: None,
      new_password: false,
      full_width: false,
      states: Vec::new(),
      rules: Recipe::new(),
      forced: None,
      id: None,
    }
  }

  /// What the input says while it is empty.
  pub fn placeholder(mut self, placeholder: &str) -> Self {
    self.input = self.input.placeholder(placeholder);
    self
  }

  /// A glyph of the theme's set at the start of the box: a lock.
  pub fn icon(mut self, name: impl Into<Name>) -> Self {
    self.input = self.input.icon(name);
    self
  }

  /// An [`InputSize`](super::InputSize), or a size the theme's recipe names.
  pub fn size(mut self, size: impl Into<Name>) -> Self {
    self.input = self.input.size(size);
    self
  }

  /// Whether the password is shown as it is typed, in place of its mask.
  pub fn reveal(mut self, revealed: bool) -> Self {
    self.revealed = revealed;
    self
  }

  /// Shown while `revealed` is true, which the button turns.
  pub fn bind_reveal(self, revealed: Signal<bool>) -> Self {
    let set = revealed.clone();
    self.reveal(revealed.get()).on_reveal(move |next| set.set(next))
  }

  /// Called on a press of the button with whether the password is to be shown. A second handler is called after
  /// the first.
  pub fn on_reveal(mut self, handler: impl Fn(bool) + Send + Sync + 'static) -> Self {
    self.on_reveal.push(Arc::new(handler));
    self
  }

  /// Whether the button that shows the password is drawn: it is unless the app says not.
  pub fn reveal_button(mut self, reveal_button: bool) -> Self {
    self.reveal_button = reveal_button;
    self
  }

  /// What the button is called to tooling while the password is hidden, in place of "Show password".
  pub fn show_label(mut self, label: &str) -> Self {
    self.show_label = Arc::from(label);
    self
  }

  /// What the button is called to tooling while the password is shown, in place of "Hide password".
  pub fn hide_label(mut self, label: &str) -> Self {
    self.hide_label = Arc::from(label);
    self
  }

  /// The strength the meter under the input shows, with what it says of it. `None` draws no meter.
  pub fn strength(mut self, strength: Option<PasswordStrength>) -> Self {
    self.strength = strength;
    self
  }

  /// What the meter says of the strength, in place of "Strong password" and the others.
  pub fn strength_text(mut self, text: &str) -> Self {
    self.strength_text = Some(Arc::from(text));
    self
  }

  /// Whether the password is being chosen, not entered: the platform may offer a strong one.
  pub fn new_password(mut self, new_password: bool) -> Self {
    self.new_password = new_password;
    self
  }

  /// Whether what the input holds is wrong.
  pub fn invalid(mut self, invalid: bool) -> Self {
    self.input = self.input.invalid(invalid);
    self
  }

  /// Whether what the input holds is allowed with a caveat.
  pub fn warning(mut self, warning: bool) -> Self {
    self.input = self.input.warning(warning);
    self
  }

  /// Whether what the input holds was checked and is right.
  pub fn valid(mut self, valid: bool) -> Self {
    self.input = self.input.valid(valid);
    self
  }

  /// Whether the input can be read and not changed. A masked one cannot be copied either.
  pub fn read_only(mut self, read_only: bool) -> Self {
    self.input = self.input.read_only(read_only);
    self
  }

  /// Whether the input and its button take no input.
  pub fn disabled(mut self, disabled: bool) -> Self {
    self.input = self.input.disabled(disabled);
    self
  }

  /// What the input is called, to what reads the tree. A field gives it its label.
  pub fn label(mut self, label: &str) -> Self {
    self.input = self.input.label(label);
    self
  }

  /// Whether the input is as wide as what holds it, in place of the design's 260.
  pub fn full_width(mut self, full_width: bool) -> Self {
    self.full_width = full_width;
    self.input = self.input.full_width(full_width);
    self
  }

  /// Called before an edit is made, with what the input will hold: a handler may refuse it.
  pub fn on_input(mut self, handler: impl Fn(&TextInputEvent) + Send + Sync + 'static) -> Self {
    self.input = self.input.on_input(handler);
    self
  }

  /// The name the password has in the form it is in.
  #[cfg(feature = "form")]
  pub fn name(mut self, name: impl Into<Arc<str>>) -> Self {
    self.input = self.input.name(name);
    self
  }

  /// Puts the password input in a state the theme's recipe names, or takes it out.
  pub fn state(mut self, state: impl Into<Name>, on: bool) -> Self {
    let state = state.into();
    self.states.retain(|held| *held != state);
    if on {
      self.states.push(state);
    }
    self
  }

  /// Styles one part of this password input over what the theme gives it. The box is styled with
  /// [`input_rules`](Self::input_rules).
  pub fn style(mut self, part: impl Into<Name>, style: impl FnOnce(PartStyle) -> PartStyle) -> Self {
    self.rules = self.rules.base(part, style);
    self
  }

  /// Lays rules over the theme's recipe for this password input.
  pub fn rules(mut self, rules: &Recipe) -> Self {
    self.rules = self.rules.extend(rules);
    self
  }

  /// Lays rules over the theme's recipe for the input it is made of: its box, its text, its placeholder.
  pub fn input_rules(mut self, rules: &Recipe) -> Self {
    self.input = self.input.rules(rules);
    self
  }

  /// Draws the input as it is under the pointer or focused, with nothing pointing at it.
  pub fn force(mut self, interaction: Option<Interaction>) -> Self {
    self.forced = interaction;
    self.input = self.input.force(interaction);
    self
  }

  /// The id of the control: what is typed in and focused.
  pub fn id(mut self, id: impl Into<Arc<str>>) -> Self {
    let id = id.into();
    self.id = Some(id.clone());
    self.input = self.input.id(id);
    self
  }

  pub fn key(mut self, key: impl Into<Arc<str>>) -> Self {
    self.input = self.input.key(key);
    self
  }

  /// Builds the password input in `theme`. Converting it into an element does this in the theme of what is being
  /// rendered.
  pub fn build(self, theme: &Theme) -> Element {
    let disabled = self.input.boxed.disabled;
    let mut case = self
      .input
      .boxed
      .case(self.states.clone())
      .state(PasswordInputState::Revealed, self.revealed)
      .state(PasswordInputState::Disabled, disabled)
      .state(PasswordInputState::FullWidth, self.full_width);
    if let Some(strength) = self.strength {
      case = case.state(strength, true);
    }
    let view = PasswordInputView {
      revealed: self.revealed,
      disabled,
      toggle_label: if self.revealed {
        self.hide_label
      } else {
        self.show_label
      },
      reveal_button: self.reveal_button,
      strength: self.strength,
      strength_text: self.strength_text.or_else(|| self.strength.map(PasswordStrength::text)),
      new_password: self.new_password,
      recipe: theme
        .resolve::<PasswordInput>(&case, Some(&self.rules))
        .owned_by(self.id.as_ref()),
      forced: self.forced,
      on_reveal: self.on_reveal,
      input: self.input.view(theme),
    };
    match theme.renderer::<PasswordInput>() {
      Some(renderer) => renderer(view),
      None => view.render(),
    }
  }
}

impl PasswordInput {
  /// The password input mounted where it is declared: where the app keeps no reveal of its own (no
  /// [`bind_reveal`](Self::bind_reveal), no [`on_reveal`](Self::on_reveal)), it keeps whether the password is
  /// shown, from render to render, and its button turns it.
  pub fn mount(self, ctx: &mut Ctx) -> Element {
    let key = self.input.key.clone();
    let props = PasswordProps { input: Arc::new(self) };
    match key {
      Some(key) => ctx.mount_keyed::<PasswordHost>(&key, props),
      None => ctx.mount::<PasswordHost>(props),
    }
  }
}

/// A password input to mount.
#[derive(Clone)]
struct PasswordProps {
  input: Arc<PasswordInput>,
}

/// A password input is built anew by every render of what holds it, so props are never the same as before.
impl PartialEq for PasswordProps {
  fn eq(&self, _: &Self) -> bool {
    false
  }
}

impl crate::app::component::DevtoolsInspectable for PasswordProps {}

/// What keeps whether a mounted password input's password is shown.
struct PasswordHost {
  revealed: Signal<bool>,
}

impl Component for PasswordHost {
  type Props = PasswordProps;

  fn create(_ctx: &mut Ctx) -> Self {
    Self {
      revealed: Signal::new(false),
    }
  }

  fn render(&self, ctx: &mut Ctx) -> impl Into<Element> {
    let input = (*ctx.props::<PasswordProps>().input).clone();
    let input = if input.on_reveal.is_empty() {
      input.bind_reveal(self.revealed.clone())
    } else {
      input
    };
    input.build(&current_theme())
  }
}

impl FieldControl for PasswordInput {
  /// Called by the field's label unless it has a name of its own, judged as the field is unless the app judged the
  /// input itself, and disabled where the field is.
  fn in_field(mut self, field: &InField) -> Element {
    self.input.boxed.in_field(field);
    self.into()
  }

  /// Told what the field says, as in `in_field`, and mounted: the same control as outside a field.
  fn mount_in_field(mut self, field: &InField, ctx: &mut Ctx) -> Element {
    self.input.boxed.in_field(field);
    self.mount(ctx)
  }

  fn has_fluid_form(&self) -> bool {
    true
  }
}

impl From<PasswordInput> for Element {
  fn from(input: PasswordInput) -> Self {
    input.build(&current_theme())
  }
}

/// A password input as a renderer sees it: the input it is made of, the style of its own parts, and its behavior.
pub struct PasswordInputView {
  /// The input the password is typed in: its box, its text, its placeholder, its icon.
  pub input: InputView,
  pub revealed: bool,
  pub disabled: bool,
  /// What the button is called to tooling: "Show password" while the password is hidden.
  pub toggle_label: Arc<str>,
  /// Whether the button is drawn.
  pub reveal_button: bool,
  pub strength: Option<PasswordStrength>,
  /// What the meter says of the strength, where it has one.
  pub strength_text: Option<Arc<str>>,
  pub new_password: bool,
  /// The style of each of the password input's own parts.
  pub recipe: ResolvedRecipe,
  forced: Option<Interaction>,
  on_reveal: Vec<RevealHandler>,
}

impl PasswordInputView {
  /// The style of a part, as this password input is to be drawn.
  pub fn part(&self, part: impl Into<Name>) -> ResolvedPart {
    self.recipe.part(part).forced(self.forced)
  }

  pub fn theme(&self) -> &Theme {
    self.recipe.theme()
  }

  /// The side of the button, in pixels.
  fn toggle_side(&self) -> f32 {
    match self
      .part(PasswordInputPart::Toggle)
      .rest()
      .width
      .and_then(|width| width.resolve(self.theme()))
    {
      Some(Dimension::Px(px)) => px,
      _ => 0.0,
    }
  }

  /// Whether the button is drawn: it is unless the app said not.
  pub fn has_toggle(&self) -> bool {
    self.reveal_button
  }

  /// The input's text input, masked unless the password is shown, and keeping room at its end for the button.
  /// Shown or not, it holds a password to the platform, which may offer to fill it in.
  pub fn control(&self) -> components::TextInput {
    let content = if self.new_password {
      ContentKind::NewPassword
    } else {
      ContentKind::Password
    };
    let mut control = self.input.control().content(content);
    control = if self.revealed {
      control.unmask()
    } else {
      let spacing = self.part(PasswordInputPart::Mask).rest().text.letter_spacing;
      let control = control.mask();
      // The dots are spaced, and not the placeholder: its own style again after the spacing, which sets both.
      match spacing {
        Some(spacing) => control
          .letter_spacing(spacing)
          .placeholder_style(self.input.placeholder_style()),
        None => control,
      }
    };
    if self.has_toggle() {
      control = control.padding_right(self.input.end_room(self.toggle_side()));
    }
    control
  }

  /// The button that shows the password and hides it again: the eye, a stop of Tab after the input.
  pub fn toggle(&self) -> Option<components::Button> {
    if !self.has_toggle() {
      return None;
    }
    let part = self.part(PasswordInputPart::Toggle);
    let side = part.rest().width.unwrap_or(Length::Icon(IconSize::Md));
    let mut toggle = pressable(&part, self.disabled)
      .describe("a11y_role", "button")
      .describe("a11y_name", self.toggle_label.clone())
      .describe("a11y_pressed", if self.revealed { "true" } else { "false" })
      .child(
        Icon::new(if self.revealed { icons::EYE_OFF } else { icons::EYE })
          .size(side)
          .build(self.theme()),
      );
    if !self.disabled {
      let (handlers, next) = (self.on_reveal.clone(), !self.revealed);
      toggle = toggle.on_click(move |_| {
        for handler in &handlers {
          handler(next);
        }
      });
    }
    Some(toggle)
  }

  /// The meter of the strength: four bars, as many filled as the strength reaches.
  pub fn strength_meter(&self) -> Option<Row> {
    let filled = self.strength?.bars();
    let (bar, full) = (self.part(PasswordInputPart::Bar), self.part(PasswordInputPart::Fill));
    // As wide as the input: the column that holds them stretches it.
    let mut meter = Row::new().part(&self.part(PasswordInputPart::Strength));
    for index in 0..4 {
      meter = meter.child(Row::new().flex(1.0).part(if index < filled { &full } else { &bar }));
    }
    Some(meter)
  }

  /// What the meter says of the strength.
  pub fn description(&self) -> Option<Row> {
    let text = self.strength_text.as_ref()?;
    let part = self.part(PasswordInputPart::Description);
    Some(Row::new().part(&part).child(part.text(text)))
  }

  /// How the default renderer builds a password input: the input with its button over the end of the box, and the
  /// meter and its message under it.
  pub fn render(self) -> Element {
    let end = self.toggle().map(|toggle| Row::new().child(toggle));
    let input = self.input.render_with_end(self.control(), end);
    let (meter, message) = (self.strength_meter(), self.description());
    if meter.is_none() && message.is_none() {
      return input.into();
    }
    // The input keeps its width; the meter and its message are as wide as it is.
    let mut root = Column::new()
      .align_items(Alignment::Stretch)
      .part(&self.part(PasswordInputPart::Root));
    // A column that stretches what it holds is as wide as the room it has: it is as wide as the input is.
    if let Some(width) = self
      .input
      .part(InputPart::Root)
      .rest()
      .width
      .and_then(|width| width.resolve(self.theme()))
    {
      // The most it takes: in a narrower room it is as wide as the room, and the input with it.
      root = root.width(width).max_width(Dimension::Pct(100.0));
    }
    let mut root = root.child(input);
    if let Some(meter) = meter {
      root = root.child(meter);
    }
    if let Some(message) = message {
      root = root.child(message);
    }
    root.into()
  }
}

impl crate::ui::Styled for PasswordInput {
  type Component = Self;

  fn rules(self, rules: &crate::ui::Recipe) -> Self {
    Self::rules(self, rules)
  }

  fn state(self, state: impl Into<crate::ui::Name>, on: bool) -> Self {
    Self::state(self, state, on)
  }
}

impl Themed for PasswordInput {
  const NAME: &'static str = "password_input";
  type Renderer = PasswordInputRenderer;

  fn parts() -> crate::ui::Declared {
    PasswordInputPart::declared()
  }

  fn states() -> crate::ui::Declared {
    PasswordInputState::declared()
  }

  /// The design's password input (`pencil/lurq-design-system.pen`, Password Input): an input whose dots are 1
  /// apart, with an eye of 16 in the muted foreground at the end of the box, 12 from its edge and 8 after the text.
  /// Under it, 8 apart, a meter of four bars 4 high and 4 apart, fully round, on the input's color where the
  /// strength does not reach and in the strength's color where it does, and a message in a caption's type in that
  /// color: destructive for a weak password, warning for a fair one, success for a good or a strong one. The eye
  /// is in the foreground under the pointer and while the password is shown. In a fluid field the box is the input's
  /// fluid one, the eye on the line of the password, and the meter under the box as wide as the field.
  fn recipe() -> Recipe {
    use PaletteColor::{Destructive, Foreground, Input, MutedForeground, Success, Warning};
    use PasswordInputPart::{Bar, Description, Fill, Mask, Root, Strength, Toggle};
    let recipe = Recipe::new()
      .base(Root, |s| s.gap(8.0))
      .state(PasswordInputState::FullWidth, Root, |s| s.width(Length::Fill))
      .state(PasswordInputState::Fluid, Root, |s| s.width(Length::Fill))
      .base(Mask, |s| s.letter_spacing(1.0))
      .base(Toggle, |s| {
        fading(
          s.square(IconSize::Md)
            .radius(RadiusSize::Sm)
            .foreground(MutedForeground)
            .cursor(CursorIcon::Pointer),
        )
      })
      .hovered(Toggle, |s| s.foreground(Foreground))
      .focus_visible(Toggle, |s| s.focus_ring())
      .state(PasswordInputState::Revealed, Toggle, |s| s.foreground(Foreground))
      .state(PasswordInputState::Disabled, Toggle, |s| s.cursor(CursorIcon::Default))
      .base(Strength, |s| s.gap(4.0))
      .base(Bar, |s| s.height(4.0).radius(RadiusSize::Full).background(Input))
      .base(Fill, |s| s.height(4.0).radius(RadiusSize::Full).background(Success))
      .base(Description, |s| {
        s.typography(TypographyStyle::Caption).foreground(Success)
      });
    [(PasswordStrength::Weak, Destructive), (PasswordStrength::Fair, Warning)]
      .into_iter()
      .fold(recipe, |recipe, (strength, color)| {
        recipe
          .state(strength, Fill, |s| s.background(color.clone()))
          .state(strength, Description, |s| s.foreground(color))
      })
  }
}