perspective_viewer/components/style_controls/number_string_format/style_section.rs
1// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
2// ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃
3// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃
4// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃
5// ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃
6// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
7// ┃ Copyright (c) 2017, the Perspective Authors. ┃
8// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
9// ┃ This file is part of the Perspective library, distributed under the terms ┃
10// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
11// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
12
13use yew::html;
14
15use super::CustomNumberFormat;
16use crate::components::form::select_field::SelectEnumField;
17use crate::components::style_controls::{CustomNumberFormatMsg, NumberStyle};
18use crate::config::*;
19
20impl CustomNumberFormat {
21 pub fn style_section(&self, ctx: &yew::prelude::Context<Self>) -> yew::prelude::Html {
22 let section = match &self.config._style {
23 Some(NumberFormatStyle::Currency(style)) => Some(html! {
24 <>
25 <SelectEnumField<CurrencyCode>
26 label="currency"
27 on_change={ctx.link().callback(CustomNumberFormatMsg::CurrencyCode)}
28 current_value={style.currency}
29 />
30 <SelectEnumField<CurrencyDisplay>
31 label="currency-display"
32 on_change={ctx.link().callback(CustomNumberFormatMsg::CurrencyDisplay)}
33 current_value={style.currency_display.unwrap_or_default()}
34 />
35 <SelectEnumField<CurrencySign>
36 label="currency-sign"
37 on_change={ctx.link().callback(CustomNumberFormatMsg::CurrencySign)}
38 current_value={style.currency_sign.unwrap_or_default()}
39 />
40 </>
41 }),
42 Some(NumberFormatStyle::Unit(style)) => Some(html!(
43 <>
44 <SelectEnumField<Unit>
45 label="unit"
46 on_change={ctx.link().callback(CustomNumberFormatMsg::Unit)}
47 current_value={style.unit}
48 />
49 <SelectEnumField<UnitDisplay>
50 label="unit-display"
51 on_change={ctx.link().callback(CustomNumberFormatMsg::UnitDisplay)}
52 current_value={style.unit_display.unwrap_or_default()}
53 />
54 </>
55 )),
56 _ => None,
57 };
58 html! {
59 <>
60 <SelectEnumField<NumberStyle>
61 label="style"
62 current_value={self.style}
63 on_change={ctx.link().callback(CustomNumberFormatMsg::StyleChanged)}
64 />
65 { section }
66 </>
67 }
68 }
69}