mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-12-05 11:15:01 +03:00
fix(desktop): match explorer card and sidebar hover styles
This commit is contained in:
1 parent
db6580abe7
commit
faa28f603b
5 files changed
+141
-19
No files matched your search
@@ -86,7 +86,7 @@ fn workspace_card(
|
||||
.h(px(32.0))
|
||||
.rounded(px(4.0))
|
||||
.cursor_pointer()
|
||||
.hover(move |s| s.bg(palette.bg_hover))
|
||||
.hover(move |s| s.bg(palette.hover_color))
|
||||
.child(
|
||||
div()
|
||||
.size(px(22.0))
|
||||
@@ -270,6 +270,10 @@ fn new_doc_menu(
|
||||
cx: &Context<DesktopShellView>,
|
||||
) -> Stateful<ui::Div> {
|
||||
let id = "desktop.sidebar.new_doc_menu";
|
||||
let menu_palette = DesktopPalette {
|
||||
hover_overlay: palette.hover_color,
|
||||
..palette
|
||||
};
|
||||
popup_panel(id, 164.0, palette, trigger_bounds, cx).children(
|
||||
[
|
||||
(
|
||||
@@ -287,7 +291,7 @@ fn new_doc_menu(
|
||||
]
|
||||
.into_iter()
|
||||
.map(|(action, icon, label, mode)| {
|
||||
nav_row(action, icon, label, false, palette)
|
||||
nav_row(action, icon, label, false, menu_palette)
|
||||
.snapshot(action, Some(id))
|
||||
.on_click(cx.listener(move |this, _, window, cx| {
|
||||
this.state.sidebar.dismiss_popups();
|
||||
@@ -322,7 +326,7 @@ fn button(
|
||||
.flex_shrink(0.0)
|
||||
.rounded(px(4.0))
|
||||
.cursor_pointer()
|
||||
.hover(move |s| s.bg(palette.bg_hover))
|
||||
.hover(move |s| s.bg(palette.hover_color))
|
||||
.flex()
|
||||
.items_center()
|
||||
.justify_center()
|
||||
|
||||
@@ -9,7 +9,7 @@ use ui::{
|
||||
use ui_tokens::FONT_SANS;
|
||||
|
||||
use crate::{
|
||||
DOC_ICON_SVG, DesktopFlexExt, DesktopPalette, JOURNAL_ICON_SVG, SETTINGS_ICON_SVG,
|
||||
DesktopFlexExt, DesktopPalette, JOURNAL_ICON_SVG, SETTINGS_ICON_SVG,
|
||||
doc_store::DesktopDocStore,
|
||||
sidebar_tree::{SidebarRowIndex, TreeGroup, nav_row, render_tree_rows},
|
||||
split_view::DesktopRoute,
|
||||
@@ -160,7 +160,7 @@ pub(crate) fn render_sidebar(
|
||||
let routes = [
|
||||
(
|
||||
DesktopRoute::AllDocs,
|
||||
DOC_ICON_SVG,
|
||||
ui_tokens::icons::ALL_DOCS.svg.as_bytes(),
|
||||
matches!(active_route, DesktopRoute::AllDocs),
|
||||
),
|
||||
(DesktopRoute::Journals, JOURNAL_ICON_SVG, journal_selected),
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
use affine_store::directory::DocMode;
|
||||
use ui::{
|
||||
AnyElement, App, Div, FontWeight, InteractiveElement, IntoElement, ParentElement, SharedString,
|
||||
StatefulInteractiveElement, Styled, div, prelude::FluentBuilder as _, px, svg,
|
||||
AnyElement, App, BoxShadow, Div, FontWeight, InteractiveElement, IntoElement, ParentElement,
|
||||
SharedString, StatefulInteractiveElement, Styled, div, hsla, prelude::FluentBuilder as _, px,
|
||||
svg,
|
||||
};
|
||||
use ui_tokens::icons::MORE_HORIZONTAL;
|
||||
use ui_tokens::{ThemeMode, icons::MORE_HORIZONTAL};
|
||||
|
||||
use super::{Controls, DocAction, Menu};
|
||||
use crate::{
|
||||
DOC_ICON_SVG, DesktopFlexExt, DesktopPalette, EDGELESS_ICON_SVG,
|
||||
doc_store::DesktopDocMeta,
|
||||
theme_color, theme_tokens_for,
|
||||
views_extra::{
|
||||
display_time, resolve_tag_color,
|
||||
scroll::{DocRowKey, doc_identity},
|
||||
@@ -40,6 +42,7 @@ pub(super) fn doc_row(
|
||||
state.selected.contains(&doc.id),
|
||||
),
|
||||
palette,
|
||||
theme,
|
||||
controls,
|
||||
))
|
||||
});
|
||||
@@ -79,6 +82,7 @@ fn doc_item(
|
||||
grid: bool,
|
||||
(selecting, selected): (bool, bool),
|
||||
palette: DesktopPalette,
|
||||
theme: ThemeMode,
|
||||
controls: &Controls,
|
||||
) -> AnyElement {
|
||||
let id = doc.id.clone();
|
||||
@@ -100,14 +104,7 @@ fn doc_item(
|
||||
)
|
||||
.group(group.clone())
|
||||
.min_w_0()
|
||||
.rounded(px(6.0))
|
||||
.cursor_pointer()
|
||||
.hover(move |style| style.bg(palette.hover_overlay))
|
||||
.bg(if selected {
|
||||
palette.bg_active
|
||||
} else {
|
||||
ui::transparent_black()
|
||||
});
|
||||
.cursor_pointer();
|
||||
let mut base = if selecting {
|
||||
base.on_click(controls.change(move |state, _| {
|
||||
if !state.selected.remove(&check_id) {
|
||||
@@ -186,14 +183,49 @@ fn doc_item(
|
||||
.text_color(palette.text_muted)
|
||||
.child(display_time(Some(doc.updated_at_ms)));
|
||||
if grid {
|
||||
let tokens = theme_tokens_for(theme);
|
||||
let card_bg = theme_color(
|
||||
tokens,
|
||||
"--affine-v2-layer-background-mobile-secondary",
|
||||
tokens.background_secondary,
|
||||
);
|
||||
let (border, hover_border) = if selected {
|
||||
let primary = theme_color(
|
||||
tokens,
|
||||
"--affine-v2-layer-insideBorder-primaryBorder",
|
||||
tokens.primary,
|
||||
);
|
||||
(primary, primary)
|
||||
} else {
|
||||
(
|
||||
theme_color(
|
||||
tokens,
|
||||
"--affine-v2-layer-insideBorder-border",
|
||||
tokens.border,
|
||||
),
|
||||
theme_color(tokens, "--affine-v2-pagelist-hoverBorder", tokens.border),
|
||||
)
|
||||
};
|
||||
let shadow =
|
||||
BoxShadow::new(px(0.0), px(2.0), hsla(0.0, 0.0, 0.0, 0.05)).blur_radius(px(3.0));
|
||||
let hover_shadow =
|
||||
BoxShadow::new(px(0.0), px(4.0), hsla(0.0, 0.0, 0.0, 0.10)).blur_radius(px(6.0));
|
||||
base.flex()
|
||||
.flex_1()
|
||||
.flex_col()
|
||||
.min_h(px(148.0))
|
||||
.p(px(12.0))
|
||||
.p(px(16.0))
|
||||
.gap(px(8.0))
|
||||
.rounded(px(12.0))
|
||||
.bg(card_bg)
|
||||
.border_1()
|
||||
.border_color(palette.border)
|
||||
.border_color(border)
|
||||
.shadow([shadow].into_iter().collect())
|
||||
.hover(move |style| {
|
||||
style
|
||||
.border_color(hover_border)
|
||||
.shadow([hover_shadow].into_iter().collect())
|
||||
})
|
||||
.child(title_row.child(more))
|
||||
.child(
|
||||
div()
|
||||
@@ -214,6 +246,13 @@ fn doc_item(
|
||||
.min_h(px(38.0))
|
||||
.px(px(8.0))
|
||||
.py(px(4.0))
|
||||
.rounded(px(4.0))
|
||||
.bg(if selected {
|
||||
palette.bg_active
|
||||
} else {
|
||||
ui::transparent_black()
|
||||
})
|
||||
.hover(move |style| style.bg(palette.hover_overlay))
|
||||
.child(title_row.flex_1().min_w(px(96.0)))
|
||||
.child(tags)
|
||||
.child(timestamp)
|
||||
|
||||
@@ -521,7 +521,7 @@ fn day_button(
|
||||
style.bg(if day == selected {
|
||||
palette.accent
|
||||
} else {
|
||||
palette.bg_hover
|
||||
palette.hover_color
|
||||
})
|
||||
})
|
||||
.focus_visible(move |style| style.border_1().border_color(palette.accent))
|
||||
|
||||
@@ -84,6 +84,85 @@ fn explorer_list_and_row_menu_use_their_own_hover_colors() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn explorer_grid_hover_keeps_card_fill_and_highlights_the_edge() -> Result<()> {
|
||||
let card = "desktop.list.doc.doc-sync";
|
||||
for (theme, fill, border, hover_border) in [
|
||||
(ThemeMode::Light, 255, 230, 230),
|
||||
(ThemeMode::Dark, 37, 65, 122),
|
||||
] {
|
||||
let mut state = DesktopAppState::seed_showcase(theme, "2026-12-02");
|
||||
state.navigate_active_pane(DesktopRoute::AllDocs);
|
||||
let shell = Shell::new(state)?;
|
||||
shell.click("desktop.explorer.grid")?;
|
||||
let primary = [30, 150, 235];
|
||||
for (selected, expected_border, expected_hover_border) in [
|
||||
(false, [border; 3], [hover_border; 3]),
|
||||
(true, primary, primary),
|
||||
] {
|
||||
if selected {
|
||||
shell.click("desktop.explorer.select")?;
|
||||
shell.click(card)?;
|
||||
}
|
||||
let bounds = shell.bounds(card)?;
|
||||
let x = (bounds.x + bounds.width * 0.75) as u32;
|
||||
let top = bounds.y as u32;
|
||||
let inside = (bounds.y + bounds.height * 0.62) as u32;
|
||||
let below = (bounds.y + bounds.height + 3.0) as u32;
|
||||
let grid_pixels = || {
|
||||
shell.frame(|window| {
|
||||
let image = window.render_to_image()?;
|
||||
Ok([inside, top, below].map(|y| image.get_pixel(x, y).0))
|
||||
})
|
||||
};
|
||||
|
||||
shell.hover(point(px(1278.0), px(798.0)));
|
||||
let [background, border_before, shadow_before] = grid_pixels()?;
|
||||
check_rgb(background, [fill; 3], "grid card background");
|
||||
check_rgb(border_before, expected_border, "grid card border");
|
||||
shell.hover(point(px(x as f32 + 0.5), px(inside as f32 + 0.5)));
|
||||
let [hover_fill, border_after, shadow_after] = grid_pixels()?;
|
||||
assert_eq!(hover_fill, background, "{theme:?}: card fill");
|
||||
check_rgb(
|
||||
border_after,
|
||||
expected_hover_border,
|
||||
"hovered grid card border",
|
||||
);
|
||||
assert!(
|
||||
shadow_after[0] < shadow_before[0],
|
||||
"{theme:?}: hover shadow {shadow_before:?} became {shadow_after:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sidebar_new_document_menu_uses_menu_hover_color() -> Result<()> {
|
||||
for theme in [ThemeMode::Light, ThemeMode::Dark] {
|
||||
let shell = Shell::new(DesktopAppState::seed_showcase(theme, "2026-12-02"))?;
|
||||
shell.click("desktop.sidebar.new_doc_options")?;
|
||||
shell.bounds("desktop.sidebar.new_doc_menu")?;
|
||||
for id in [
|
||||
"desktop.sidebar.menu_new_page",
|
||||
"desktop.sidebar.new_edgeless",
|
||||
] {
|
||||
shell.check_hover(id, 0.85, Some(palette_for(theme).hover_color))?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn check_rgb(pixel: [u8; 4], expected: [u8; 3], label: &str) {
|
||||
assert_eq!(pixel[3], 255, "{label}: surface alpha");
|
||||
for (actual, expected) in pixel.into_iter().zip(expected) {
|
||||
assert!(
|
||||
actual.abs_diff(expected) <= 1,
|
||||
"{label}: channel {actual}, expected {expected}, pixel {pixel:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
struct Shell {
|
||||
app: ApplicationHandle,
|
||||
handle: WindowHandle<DesktopShellView>,
|
||||
|
||||
Reference in new issue
Block a user