modal
probo.styles.frameworks.bs5.components.modal
BS5Modal
Bases: BS5Component
A comprehensive manager for Bootstrap 5 Modal components.
Modals are positioned over everything else in the document and remove scroll from the
so that modal content scrolls instead. This class manages the complex nested structure (Dialog > Content > Header/Body/Footer) and facilitates the creation of external trigger buttons linked via data-attributes.Attributes:
| Name | Type | Description |
|---|---|---|
attrs |
Dict[str, Any]
|
Attributes for the root modal container. |
modal_parts |
List[str]
|
Collection of rendered fragments (header, body, footer). |
render_constraints |
Optional[Dict[str, Any]]
|
State validation schema. |
modal_classes |
List[str]
|
CSS classes for the root element (defaults to 'modal fade'). |
tag |
str
|
The HTML tag for the root container (defaults to 'div'). |
triggers |
List[BS5Element]
|
Collection of button elements that toggle this modal. |
__init__(render_constraints=None, is_fade=True, **attrs)
Initializes the modal with structural placeholders and accessibility roles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
render_constraints
|
dict
|
State validation properties. |
None
|
is_fade
|
bool
|
If True, adds the 'fade' animation class. |
True
|
**attrs
|
Any
|
Attributes including the mandatory 'Id' for targeting. |
{}
|
add_modal_body(content, **attrs)
Constructs and appends the primary modal body section.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
|
Any
|
The HTML or text content for the body. |
required |
**attrs
|
Any
|
Additional attributes for the body container. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
Enables fluent method chaining. |
add_modal_footer(content, **attrs)
Constructs and appends the modal footer section.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
|
Any
|
The HTML or text content for the footer. |
required |
**attrs
|
Any
|
Additional attributes for the footer container. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
Enables fluent method chaining. |
add_modal_header(other_content='', title=None, **attrs)
Constructs and appends the modal header section.
Automatically includes a close button (X) aligned to the right.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other_content
|
Any
|
Optional additional HTML content for the header. |
''
|
title
|
str
|
Text for the 'modal-title' element. |
None
|
**attrs
|
Any
|
Additional attributes for the header container. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
Enables fluent method chaining. |
add_trigger_btn(content, variant='primary', **attrs)
Creates a button that targets and toggles this modal instance.
The modal must have an 'Id' attribute defined in the constructor for the trigger to function correctly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
|
Any
|
The text or HTML for the button label. |
required |
variant
|
str
|
The Bootstrap color variant for the button. |
'primary'
|
**attrs
|
Any
|
Additional attributes for the trigger button. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
Enables fluent method chaining. |
before_render(**props)
Assembles the nested modal hierarchy before final rendering.
This method wraps the collected modal parts (header, body, footer) into the required 'modal-dialog' and 'modal-content' containers.