@@ -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,60 @@ 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 (
515+ label : impl Into < Cow < ' a , str > > ,
516+ select_menu : impl Into < CreateSelectMenu < ' a > > ,
517+ ) -> Self {
518+ Self {
519+ kind : StaticU8 :: < 18 > ,
520+ label : label. into ( ) ,
521+ description : None ,
522+ component : CreateLabelComponent :: SelectMenu ( select_menu. into ( ) ) ,
523+ }
524+ }
525+
526+ /// Create a text input with a specific label.
527+ pub fn input_text (
528+ label : impl Into < Cow < ' a , str > > ,
529+ input_text : impl Into < CreateInputText < ' a > > ,
530+ ) -> Self {
531+ Self {
532+ kind : StaticU8 :: < 18 > ,
533+ label : label. into ( ) ,
534+ description : None ,
535+ component : CreateLabelComponent :: InputText ( input_text. into ( ) ) ,
536+ }
537+ }
538+
539+ /// Sets the description of this component, which will display underneath the label text.
540+ pub fn description ( mut self , description : impl Into < Cow < ' a , str > > ) -> Self {
541+ self . description = Some ( description. into ( ) ) ;
542+ self
543+ }
544+ }
545+
546+ /// An enum of all valid label components.
547+ #[ derive( Clone , Debug , Serialize ) ]
548+ #[ must_use]
549+ #[ serde( untagged) ]
550+ enum CreateLabelComponent < ' a > {
551+ SelectMenu ( CreateSelectMenu < ' a > ) ,
552+ InputText ( CreateInputText < ' a > ) ,
553+ }
554+
504555enum_number ! {
505556 #[ derive( Clone , Copy , Debug , Eq , Hash , Ord , PartialEq , PartialOrd , Deserialize , Serialize ) ]
506557 #[ cfg_attr( feature = "typesize" , derive( typesize:: derive:: TypeSize ) ) ]
@@ -893,7 +944,6 @@ pub struct CreateInputText<'a> {
893944 kind : ComponentType ,
894945 custom_id : Cow < ' a , str > ,
895946 style : InputTextStyle ,
896- label : Option < Cow < ' a , str > > ,
897947 min_length : Option < u16 > ,
898948 max_length : Option < u16 > ,
899949 required : bool ,
@@ -906,14 +956,9 @@ pub struct CreateInputText<'a> {
906956impl < ' a > CreateInputText < ' a > {
907957 /// Creates a text input with the given style, label, and custom id (a developer-defined
908958 /// 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 {
959+ pub fn new ( style : InputTextStyle , custom_id : impl Into < Cow < ' a , str > > ) -> Self {
914960 Self {
915961 style,
916- label : Some ( label. into ( ) ) ,
917962 custom_id : custom_id. into ( ) ,
918963
919964 placeholder : None ,
@@ -932,12 +977,6 @@ impl<'a> CreateInputText<'a> {
932977 self
933978 }
934979
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-
941980 /// Sets the custom id of the input text, a developer-defined identifier. Replaces the current
942981 /// value as set in [`Self::new`].
943982 pub fn custom_id ( mut self , id : impl Into < Cow < ' a , str > > ) -> Self {
0 commit comments