chore: audit all components (#2)
Reviewed-on: #2
This commit was merged in pull request #2.
This commit is contained in:
+120
-17
@@ -205,8 +205,10 @@ fn gallery_commands() -> Vec<Command> {
|
||||
Command::new("open-settings", "Open Settings").hint("Cmd+,"),
|
||||
Command::new("toggle-theme", "Toggle Theme").hint("Shift+Cmd+T"),
|
||||
Command::new("save-all", "Save All").hint("Cmd+Alt+S"),
|
||||
Command::new("close-tab", "Close Tab").hint("Cmd+W"),
|
||||
Command::new("reload-window", "Reload Window"),
|
||||
Command::new("close-tab", "Close Tab")
|
||||
.hint("Cmd+W")
|
||||
.icon(IconRole::Close),
|
||||
Command::new("reload-window", "Reload Window").icon(IconRole::Loader),
|
||||
]
|
||||
}
|
||||
|
||||
@@ -876,27 +878,83 @@ impl Render for ButtonDemo {
|
||||
});
|
||||
});
|
||||
if variant == ButtonVariant::Destructive {
|
||||
button = button.tooltip(Tooltip::text("Removes the selected item"));
|
||||
let id = SharedString::from(format!("button-demo-{name}"));
|
||||
button = button
|
||||
.tooltip(Tooltip::anchored("Removes the selected item", id));
|
||||
}
|
||||
button
|
||||
}))
|
||||
})),
|
||||
))
|
||||
.child(demo_section(
|
||||
"icon + label",
|
||||
colors,
|
||||
h_flex()
|
||||
.flex_wrap()
|
||||
.gap_2()
|
||||
.children(variants.map(|(name, variant)| {
|
||||
let view = view.clone();
|
||||
let mut button =
|
||||
Button::new(SharedString::from(format!("button-demo-icon-{name}")))
|
||||
.label(button_label(variant))
|
||||
.icon(IconRole::Folder)
|
||||
.variant(variant)
|
||||
.on_click(move |_, _, cx| {
|
||||
view.update(cx, |demo, cx| {
|
||||
demo.clicks += 1;
|
||||
cx.notify();
|
||||
});
|
||||
});
|
||||
if variant == ButtonVariant::Destructive {
|
||||
let id = SharedString::from(format!("button-demo-icon-{name}"));
|
||||
button = button
|
||||
.tooltip(Tooltip::anchored("Removes the selected item", id));
|
||||
}
|
||||
button
|
||||
})),
|
||||
))
|
||||
.child(demo_section(
|
||||
"icon only",
|
||||
colors,
|
||||
h_flex()
|
||||
.flex_wrap()
|
||||
.gap_2()
|
||||
.children(variants.map(|(name, variant)| {
|
||||
let view = view.clone();
|
||||
let id = SharedString::from(format!("button-demo-icon-only-{name}"));
|
||||
Button::new(id.clone())
|
||||
.icon(IconRole::Folder)
|
||||
.variant(variant)
|
||||
.accessibility_label("Open the selected file")
|
||||
.tooltip(Tooltip::anchored("Opens the selected file", id))
|
||||
.on_click(move |_, _, cx| {
|
||||
view.update(cx, |demo, cx| {
|
||||
demo.clicks += 1;
|
||||
cx.notify();
|
||||
});
|
||||
})
|
||||
})),
|
||||
))
|
||||
.child(demo_section(
|
||||
"states",
|
||||
colors,
|
||||
h_flex()
|
||||
.flex_wrap()
|
||||
.gap_2()
|
||||
.child(
|
||||
Button::new("button-demo-disabled")
|
||||
.label("Disabled")
|
||||
.disabled(true),
|
||||
)
|
||||
.child(
|
||||
Button::new("button-demo-icon")
|
||||
.label("Open")
|
||||
.icon(IconRole::Folder)
|
||||
.tooltip(Tooltip::text("Opens the selected file")),
|
||||
Button::new("button-demo-loading")
|
||||
.label("Saving")
|
||||
.loading(true),
|
||||
)
|
||||
.child(
|
||||
Button::new("button-demo-icon-only")
|
||||
Button::new("button-demo-loading-icon-only")
|
||||
.icon(IconRole::Folder)
|
||||
.variant(ButtonVariant::Ghost)
|
||||
.accessibility_label("Open the selected file")
|
||||
.tooltip(Tooltip::text("Opens the selected file")),
|
||||
.accessibility_label("Saving the selected file")
|
||||
.loading(true),
|
||||
),
|
||||
))
|
||||
.child(demo_section(
|
||||
@@ -923,6 +981,7 @@ struct InputDemo {
|
||||
text: Entity<InputState>,
|
||||
password: Entity<InputState>,
|
||||
notes: Entity<InputState>,
|
||||
search: Entity<InputState>,
|
||||
_subscriptions: Vec<gpui::Subscription>,
|
||||
}
|
||||
|
||||
@@ -933,17 +992,20 @@ impl InputDemo {
|
||||
password.update(cx, |state, cx| state.set_password(true, cx));
|
||||
let notes = InputState::new(cx);
|
||||
notes.update(cx, |state, cx| state.set_multiline(true, cx));
|
||||
let search = InputState::new(cx);
|
||||
// The panel is a cached view in the dock: the value readouts re-render
|
||||
// only when the inputs it reads are notified.
|
||||
let subscriptions = vec![
|
||||
cx.observe(&text, |_, _, cx| cx.notify()),
|
||||
cx.observe(&password, |_, _, cx| cx.notify()),
|
||||
cx.observe(¬es, |_, _, cx| cx.notify()),
|
||||
cx.observe(&search, |_, _, cx| cx.notify()),
|
||||
];
|
||||
Self {
|
||||
text,
|
||||
password,
|
||||
notes,
|
||||
search,
|
||||
_subscriptions: subscriptions,
|
||||
}
|
||||
}
|
||||
@@ -956,7 +1018,36 @@ impl Render for InputDemo {
|
||||
ScrollArea::new("input-demo").size_full().p_4().child(
|
||||
v_flex()
|
||||
.gap_3()
|
||||
.child(Input::new("input-demo-text", self.text.clone()).placeholder("Type here…"))
|
||||
.child(
|
||||
Input::new("input-demo-search", self.search.clone())
|
||||
.placeholder("Search")
|
||||
.prefix(
|
||||
Button::new("input-demo-search-prefix")
|
||||
.icon(IconRole::Search)
|
||||
.variant(ButtonVariant::Ghost)
|
||||
.small()
|
||||
.accessibility_label("Search"),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
Input::new("input-demo-text", self.text.clone())
|
||||
.placeholder("Type here…")
|
||||
.suffix(
|
||||
Button::new("input-demo-clear")
|
||||
.icon(IconRole::Close)
|
||||
.variant(ButtonVariant::Ghost)
|
||||
.small()
|
||||
.accessibility_label("Clear")
|
||||
.on_click({
|
||||
let text = self.text.clone();
|
||||
move |_, window, cx| {
|
||||
text.update(cx, |state, cx| {
|
||||
state.set_value("", window, cx)
|
||||
});
|
||||
}
|
||||
}),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
Input::new("input-demo-password", self.password.clone())
|
||||
.placeholder("Password"),
|
||||
@@ -1168,7 +1259,10 @@ impl ComboboxDemo {
|
||||
)
|
||||
.selected(SharedString::from("main"))
|
||||
.placeholder("Switch branch…")
|
||||
.keep_unmatched_text(),
|
||||
.keep_unmatched_text()
|
||||
// Widths are style refinements on the builder; the popup
|
||||
// always matches whatever the combobox ends up being.
|
||||
.w(px(280.)),
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
@@ -2716,20 +2810,29 @@ impl Render for TooltipDemo {
|
||||
Button::new("tooltip-demo-destructive")
|
||||
.label("Delete")
|
||||
.variant(ButtonVariant::Destructive)
|
||||
.tooltip(Tooltip::text("Removes the selected item")),
|
||||
.tooltip(Tooltip::anchored(
|
||||
"Removes the selected item",
|
||||
"tooltip-demo-destructive",
|
||||
)),
|
||||
)
|
||||
.child(
|
||||
Button::new("tooltip-demo-icon")
|
||||
.label("Open")
|
||||
.icon(IconRole::Folder)
|
||||
.tooltip(Tooltip::text("Opens the selected file")),
|
||||
.tooltip(Tooltip::anchored(
|
||||
"Opens the selected file",
|
||||
"tooltip-demo-icon",
|
||||
)),
|
||||
)
|
||||
.child(
|
||||
Button::new("tooltip-demo-icon-only")
|
||||
.icon(IconRole::Folder)
|
||||
.variant(ButtonVariant::Ghost)
|
||||
.accessibility_label("Open the selected file")
|
||||
.tooltip(Tooltip::text("Opens the selected file")),
|
||||
.tooltip(Tooltip::anchored(
|
||||
"Opens the selected file",
|
||||
"tooltip-demo-icon-only",
|
||||
)),
|
||||
),
|
||||
))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user