@@ -21,8 +21,6 @@ impl<const VAL: u8> Serialize for StaticU8<VAL> {
2121pub enum CreateActionRow < ' a > {
2222 Buttons ( Cow < ' a , [ CreateButton < ' a > ] > ) ,
2323 SelectMenu ( CreateSelectMenu < ' a > ) ,
24- /// Only valid in modals!
25- InputText ( CreateInputText < ' a > ) ,
2624}
2725
2826impl < ' a > CreateActionRow < ' a > {
@@ -33,10 +31,6 @@ impl<'a> CreateActionRow<'a> {
3331 pub fn select_menu ( select_menu : impl Into < CreateSelectMenu < ' a > > ) -> Self {
3432 Self :: SelectMenu ( select_menu. into ( ) )
3533 }
36-
37- pub fn input_text ( input_text : impl Into < CreateInputText < ' a > > ) -> Self {
38- Self :: InputText ( input_text. into ( ) )
39- }
4034}
4135
4236impl serde:: Serialize for CreateActionRow < ' _ > {
@@ -49,7 +43,6 @@ impl serde::Serialize for CreateActionRow<'_> {
4943 match self {
5044 CreateActionRow :: Buttons ( buttons) => map. serialize_entry ( "components" , & buttons) ?,
5145 CreateActionRow :: SelectMenu ( select) => map. serialize_entry ( "components" , & [ select] ) ?,
52- CreateActionRow :: InputText ( input) => map. serialize_entry ( "components" , & [ input] ) ?,
5346 }
5447
5548 map. end ( )
@@ -105,6 +98,10 @@ pub enum CreateComponent<'a> {
10598 ///
10699 /// A container is a flexible component that can hold multiple nested components.
107100 Container ( CreateContainer < ' a > ) ,
101+ /// Represents a label component (V2).
102+ ///
103+ /// A label is used to hold other components in a modal.
104+ Label ( CreateLabel < ' a > ) ,
108105}
109106
110107/// A builder to create a section component, supports up to a max of **3** components with an
@@ -501,6 +498,54 @@ impl<'a> CreateContainer<'a> {
501498 }
502499}
503500
501+ /// A builder for creating a label that can hold an [`InputText`] or [`SelectMenu`].
502+ #[ derive( Clone , Debug , Serialize ) ]
503+ #[ must_use]
504+ pub struct CreateLabel < ' a > {
505+ #[ serde( rename = "type" ) ]
506+ kind : StaticU8 < 18 > ,
507+ label : Cow < ' a , str > ,
508+ description : Option < Cow < ' a , str > > ,
509+ component : CreateLabelComponent < ' a > ,
510+ }
511+
512+ impl < ' a > CreateLabel < ' a > {
513+ /// Create a select menu with a specific label.
514+ pub fn select_menu ( label : impl Into < Cow < ' a , str > > , select_menu : CreateSelectMenu < ' a > ) -> Self {
515+ Self {
516+ kind : StaticU8 :: < 18 > ,
517+ label : label. into ( ) ,
518+ description : None ,
519+ component : CreateLabelComponent :: SelectMenu ( select_menu) ,
520+ }
521+ }
522+
523+ /// Create a text input with a specific label.
524+ pub fn input_text ( label : impl Into < Cow < ' a , str > > , input_text : CreateInputText < ' a > ) -> Self {
525+ Self {
526+ kind : StaticU8 :: < 18 > ,
527+ label : label. into ( ) ,
528+ description : None ,
529+ component : CreateLabelComponent :: InputText ( input_text) ,
530+ }
531+ }
532+
533+ /// Sets the description of this component, which will display underneath the label text.
534+ pub fn description ( mut self , description : impl Into < Cow < ' a , str > > ) -> Self {
535+ self . description = Some ( description. into ( ) ) ;
536+ self
537+ }
538+ }
539+
540+ /// An enum of all valid label components.
541+ #[ derive( Clone , Debug , Serialize ) ]
542+ #[ must_use]
543+ #[ serde( untagged) ]
544+ enum CreateLabelComponent < ' a > {
545+ SelectMenu ( CreateSelectMenu < ' a > ) ,
546+ InputText ( CreateInputText < ' a > ) ,
547+ }
548+
504549enum_number ! {
505550 #[ derive( Clone , Copy , Debug , Eq , Hash , Ord , PartialEq , PartialOrd , Deserialize , Serialize ) ]
506551 #[ cfg_attr( feature = "typesize" , derive( typesize:: derive:: TypeSize ) ) ]
@@ -893,7 +938,6 @@ pub struct CreateInputText<'a> {
893938 kind : ComponentType ,
894939 custom_id : Cow < ' a , str > ,
895940 style : InputTextStyle ,
896- label : Option < Cow < ' a , str > > ,
897941 min_length : Option < u16 > ,
898942 max_length : Option < u16 > ,
899943 required : bool ,
@@ -906,14 +950,9 @@ pub struct CreateInputText<'a> {
906950impl < ' a > CreateInputText < ' a > {
907951 /// Creates a text input with the given style, label, and custom id (a developer-defined
908952 /// identifier), leaving all other fields empty.
909- pub fn new (
910- style : InputTextStyle ,
911- label : impl Into < Cow < ' a , str > > ,
912- custom_id : impl Into < Cow < ' a , str > > ,
913- ) -> Self {
953+ pub fn new ( style : InputTextStyle , custom_id : impl Into < Cow < ' a , str > > ) -> Self {
914954 Self {
915955 style,
916- label : Some ( label. into ( ) ) ,
917956 custom_id : custom_id. into ( ) ,
918957
919958 placeholder : None ,
@@ -932,12 +971,6 @@ impl<'a> CreateInputText<'a> {
932971 self
933972 }
934973
935- /// Sets the label of this input text. Replaces the current value as set in [`Self::new`].
936- pub fn label ( mut self , label : impl Into < Cow < ' a , str > > ) -> Self {
937- self . label = Some ( label. into ( ) ) ;
938- self
939- }
940-
941974 /// Sets the custom id of the input text, a developer-defined identifier. Replaces the current
942975 /// value as set in [`Self::new`].
943976 pub fn custom_id ( mut self , id : impl Into < Cow < ' a , str > > ) -> Self {
0 commit comments