Skip to main content

teksilo_core/styles/
card_style.rs

1// SPDX-License-Identifier: MPL-2.0
2// SPDX-FileCopyrightText: 2026 FernTech
3
4//! Tier-3 style protocol for `Card`. See `docs/styling-system.md`.
5
6use std::rc::Rc;
7
8use serde::{Deserialize, Serialize};
9
10use crate::build_context::BuildContext;
11use crate::color_prop::ColorProp;
12use crate::signal::{Prop, Signal};
13use crate::widget_id::WidgetId;
14
15#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Default, Serialize, Deserialize)]
16pub enum CardVariant {
17    Plain,
18    #[default]
19    Elevated,
20    Outlined,
21    Filled,
22}
23
24#[derive(Clone, Debug)]
25pub struct CardStyleConfig {
26    /// Pre-built content subtree wrapped by the card's chrome.
27    pub content: WidgetId,
28    /// `Some(signal)` if the card is interactive (hover lifts elevation).
29    pub is_hovered: Option<Signal<bool>>,
30    pub variant: CardVariant,
31    /// Caller overrides — when `Some`, the style should use these
32    /// values instead of the variant's defaults. Custom styles may
33    /// ignore them.
34    pub background_override: Option<ColorProp>,
35    pub corner_radius_override: Option<Prop<f32>>,
36    pub padding_override: Option<Prop<f32>>,
37    /// Optional caller-supplied shadow override (replaces variant's
38    /// default shadow).
39    pub shadow_override: Option<teksilo_tokens::Shadow>,
40}
41
42pub trait CardStyle: 'static {
43    fn make_body(&self, cfg: &CardStyleConfig, ctx: &mut BuildContext) -> WidgetId;
44}
45
46pub type SharedCardStyle = Rc<dyn CardStyle>;