open_lark/card/components/interactive_components/
multi_select_static.rs1use serde::{Deserialize, Serialize};
2
3use crate::card::components::{
4 content_components::plain_text::PlainText,
5 interactive_components::{input::InputConfirm, select_static::SelectStaticOption},
6};
7
8#[derive(Debug, Serialize, Deserialize)]
10pub struct MultiSelectStatic {
11 tag: String,
13 #[serde(skip_serializing_if = "Option::is_none")]
18 r#type: Option<String>,
19 #[serde(skip_serializing_if = "Option::is_none")]
24 name: Option<String>,
25 #[serde(skip_serializing_if = "Option::is_none")]
27 placeholder: Option<PlainText>,
28 #[serde(skip_serializing_if = "Option::is_none")]
37 width: Option<String>,
38 #[serde(skip_serializing_if = "Option::is_none")]
46 required: Option<bool>,
47 #[serde(skip_serializing_if = "Option::is_none")]
52 disabled: Option<bool>,
53 #[serde(skip_serializing_if = "Option::is_none")]
55 selected_values: Option<Vec<String>>,
56 #[serde(skip_serializing_if = "Option::is_none")]
58 options: Option<Vec<SelectStaticOption>>,
59 #[serde(skip_serializing_if = "Option::is_none")]
64 confirm: Option<InputConfirm>,
65}
66
67impl Default for MultiSelectStatic {
68 fn default() -> Self {
69 Self {
70 tag: "multi_select_static".to_string(),
71 r#type: None,
72 name: None,
73 required: None,
74 disabled: None,
75 placeholder: None,
76 width: None,
77 options: None,
78 confirm: None,
79 selected_values: None,
80 }
81 }
82}
83
84impl MultiSelectStatic {
85 pub fn new() -> Self {
86 Self::default()
87 }
88
89 pub fn r#type(mut self, r#type: &str) -> Self {
90 self.r#type = Some(r#type.to_string());
91 self
92 }
93
94 pub fn name(mut self, name: &str) -> Self {
95 self.name = Some(name.to_string());
96 self
97 }
98
99 pub fn required(mut self, required: bool) -> Self {
100 self.required = Some(required);
101 self
102 }
103
104 pub fn disabled(mut self, disabled: bool) -> Self {
105 self.disabled = Some(disabled);
106 self
107 }
108
109 pub fn placeholder(mut self, placeholder: PlainText) -> Self {
110 self.placeholder = Some(placeholder);
111 self
112 }
113
114 pub fn width(mut self, width: &str) -> Self {
115 self.width = Some(width.to_string());
116 self
117 }
118
119 pub fn values(mut self, values: Vec<&str>) -> Self {
120 self.selected_values = Some(values.iter().map(|v| v.to_string()).collect());
121 self
122 }
123
124 pub fn options(mut self, options: Vec<SelectStaticOption>) -> Self {
125 self.options = Some(options);
126 self
127 }
128
129 pub fn confirm(mut self, confirm: InputConfirm) -> Self {
130 self.confirm = Some(confirm);
131 self
132 }
133}
134
135#[cfg(test)]
136mod test {
137 use serde_json::json;
138
139 use crate::card::{
140 components::{
141 content_components::plain_text::PlainText,
142 interactive_components::{
143 multi_select_static::MultiSelectStatic, select_static::SelectStaticOption,
144 },
145 },
146 icon::FeishuCardTextIcon,
147 };
148
149 #[test]
150 fn test_select_static() {
151 let select_static = MultiSelectStatic::new()
152 .r#type("default")
153 .name("multi_select_departments")
154 .required(true)
155 .disabled(false)
156 .placeholder(PlainText::text("默认提示文本"))
157 .width("default")
158 .values(vec![])
159 .options(vec![SelectStaticOption::new("我是交互组件", "selectDemo1")
160 .icon(
161 FeishuCardTextIcon::new()
162 .token("chat-forbidden_outlined")
163 .color("orange")
164 .img_key("img_v2_38811724"),
165 )
166 .value("selectDemo1")]);
167
168 let json = json!({
169 "tag": "multi_select_static", "type": "default", "name":"multi_select_departments", "required": true, "disabled": false, "placeholder": {
175 "tag": "plain_text",
177 "content": "默认提示文本"
178 },
179 "width": "default", "selected_values": [], "options": [
182 {
184 "text": {
185 "tag": "plain_text",
187 "content": "我是交互组件"
188 },
189 "icon": {
190 "tag": "standard_icon", "token": "chat-forbidden_outlined", "color": "orange", "img_key": "img_v2_38811724" },
196 "value": "selectDemo1" }
198 ],
199 });
200
201 assert_eq!(serde_json::to_value(&select_static).unwrap(), json);
202 }
203}