twilight_model/channel/message/component/checkbox_group.rs
1use serde::{Deserialize, Serialize};
2
3/// A group of selectable checkboxes within a modal.
4/// Checkbox groups are only available in modals and must be put inside a label
5///
6/// Fields' default values may be used by setting them to [`None`].
7#[derive(Clone, Debug, Eq, Hash, PartialEq, Deserialize, Serialize)]
8pub struct CheckboxGroup {
9 /// Developer defined identifier.
10 ///
11 /// Between 1-100 characters
12 pub custom_id: String,
13 /// Optional identifier for the component.
14 #[serde(skip_serializing_if = "Option::is_none")]
15 pub id: Option<i32>,
16 /// Maximum number of items that can be checked.
17 ///
18 /// Must be between 1-10.
19 ///
20 /// Defaults to the number of options given.
21 #[serde(skip_serializing_if = "Option::is_none")]
22 pub max_values: Option<u8>,
23 /// Minimum number of options that must be selected.
24 ///
25 /// Must be between 0 and 10, inclusive.
26 ///
27 /// Defaults to `1`.
28 ///
29 /// If set to `0`, [`required`] must be `false`.
30 #[serde(skip_serializing_if = "Option::is_none")]
31 pub min_values: Option<u8>,
32 /// List of checkbox options.
33 ///
34 /// Must be between 1-10 options.
35 pub options: Vec<CheckboxGroupOption>,
36 /// Whether at least one option must be selected.
37 ///
38 /// Defaults to `true`.
39 ///
40 /// If [`min_values`] is set to `0`, this must be `false`.
41 #[serde(skip_serializing_if = "Option::is_none")]
42 pub required: Option<bool>,
43}
44
45/// Selectable checkbox options put into the checkbox group
46#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
47pub struct CheckboxGroupOption {
48 /// If the option is selected by default.
49 ///
50 /// Set to false if None is given
51 #[serde(skip_serializing_if = "Option::is_none")]
52 pub default: Option<bool>,
53 /// Optional description for the option.
54 ///
55 /// Up to 100 characters
56 #[serde(skip_serializing_if = "Option::is_none")]
57 pub description: Option<String>,
58 /// User-facing label of the option.
59 ///
60 /// Must be between 1-100 characters
61 pub label: String,
62 /// Developer defined identifier.
63 ///
64 /// Must be between 1-100 characters
65 pub value: String,
66}