Source code for duck.html.components.image
"""
Image components module.
Available Images:
- `Image`: Base image component.
- `CircularImage`: Rounded circular image component.
"""
from duck.html.components import NoInnerComponent
[docs]
class Image(NoInnerComponent):
"""
Basic Image component.
Args:
source (str): Image source URL.
alt (str): Image alternative text
width (str): Image width.
height (str): Image height.
"""
[docs]
def get_element(self):
return "img"
[docs]
def on_create(self):
super().on_create()
if self.kwargs.get("source"):
self.props["src"] = self.kwargs.get("source")
if self.kwargs.get("alt"):
self.props["alt"] = self.kwargs.get("alt")
if self.kwargs.get("width"):
self.style["width"] = self.kwargs.get("width")
if self.kwargs.get("height"):
self.style["height"] = self.kwargs.get("height")
[docs]
class CircularImage(Image):
"""
Circular Image component.
"""
[docs]
def on_create(self):
super().on_create()
self.style["border-radius"] = "50%"