Skip to main content

euv_ui/component/rating/view/
struct.rs

1use super::*;
2
3/// The star glyph size of the `euv_rating` component.
4///
5/// The steps follow the shared monochrome type scale, one step below the
6/// `euv_icon` `Xl` glyph so a five-star row stays compact.
7#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
8pub enum EuvRatingSize {
9    /// A 14px star for dense table cells.
10    Sm,
11    /// An 18px star, the default size for list rows.
12    #[default]
13    Md,
14    /// A 24px star for standalone ratings.
15    Lg,
16}
17
18impl EuvRatingSize {
19    /// Returns the star glyph edge length in pixels for this size.
20    ///
21    /// # Returns
22    ///
23    /// - `i32` - The edge length in pixels: 14 for `Sm`, 18 for `Md`, 24 for
24    ///   `Lg`.
25    pub fn px(&self) -> i32 {
26        match self {
27            EuvRatingSize::Sm => 14,
28            EuvRatingSize::Md => 18,
29            EuvRatingSize::Lg => 24,
30        }
31    }
32}
33
34/// Props for the `euv_rating` component.
35///
36/// Defines the strongly-typed interface for the star rating. The value and
37/// scale live in caller-owned signals so a parent can drive the rating and
38/// receive updates when `readonly` is false.
39#[derive(Clone, CustomDebug, Default)]
40pub struct EuvRatingProps {
41    /// The current rating value, which may be fractional for half stars.
42    pub value: Signal<f64>,
43    /// The maximum rating value, the number of stars rendered.
44    pub max: Signal<f64>,
45    /// Whether the rating is display-only, suppressing the fill overlay.
46    pub readonly: Signal<bool>,
47    /// The star glyph size.
48    pub size: EuvRatingSize,
49}