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
//! The shared keyed item for the pickers.
//!
//! HeroUI v3's collection components keep a stable `Key` separate from each
//! item's `textValue`: `value` / `defaultValue` / `disabledKeys`, the selection
//! callbacks and form submission address items by key, while filtering and the
//! visible text use the label. A label cannot serve as that key -- two items
//! may share one, and then they alias each other's selection, disabled state
//! and row identity -- so the keyed pickers take [`PickerItem`]s, following
//! the `ListBoxItem` / `Tag` / `TabItem` precedent.
use gpui::SharedString;
/// One item of a keyed picker collection.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct PickerItem {
key: SharedString,
label: SharedString,
}
impl PickerItem {
pub fn new(key: impl Into<SharedString>, label: impl Into<SharedString>) -> Self {
Self {
key: key.into(),
label: label.into(),
}
}
/// The stable `Key` the selection, `disabledKeys` and callbacks address.
pub fn key(&self) -> &SharedString {
&self.key
}
/// The visible `textValue` the filtering and rendering use.
pub fn label(&self) -> &SharedString {
&self.label
}
}