Skip to content

Commit 243cad2

Browse files
committed
feat(components): enhance documentation for various components with detailed argument descriptions and return types
1 parent 3008cb3 commit 243cad2

34 files changed

+916
-616
lines changed

src/htpy_uikit/components/_utils.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,28 @@
33

44

55
def merge_classes(base_classes: str, class_: str | None = None) -> str:
6-
"""Merge base classes with optional additional classes."""
6+
"""Merge ``base_classes`` with optional ``class_`` string.
7+
8+
Args:
9+
base_classes: Default Tailwind utility classes.
10+
class_: Optional user-supplied classes appended to the base.
11+
12+
Returns:
13+
str: Combined class string without extra whitespace.
14+
"""
715
if class_:
816
return f"{base_classes} {class_}"
917
return base_classes
1018

1119

1220
def random_string(n: int) -> str:
21+
"""Return a pseudo-random alpha string of length ``n``.
22+
23+
Args:
24+
n: Desired number of characters.
25+
26+
Returns:
27+
str: Random uppercase/lowercase ASCII letters combined via ``random.choices``.
28+
"""
29+
1330
return "".join(random.choices(string.ascii_letters, k=n))

src/htpy_uikit/components/accordion.py

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,16 @@ def accordion(
1919
class_: str | None = None,
2020
**attrs,
2121
) -> Renderable:
22-
"""
23-
Basecoat-style accordion component.
24-
25-
Based on Basecoat UI accordion implementation.
26-
Note: Basecoat doesn't have a dedicated accordion component,
27-
this uses standard HTML details/summary elements with accordion styling.
22+
"""Render a Basecoat-style accordion using native ``<details>`` elements.
2823
2924
Args:
30-
items: List of AccordionItem dictionaries with title, content, and expanded flag
31-
default_value: Title of item to expand by default
32-
class_: Additional CSS classes
33-
**attrs: Additional HTML attributes
25+
items: Sequence of accordion item definitions containing ``title`` and ``content``.
26+
default_value: Title whose panel should be expanded initially.
27+
class_: Additional CSS classes appended to the wrapping section.
28+
**attrs: Extra HTML attributes forwarded to the section element.
3429
3530
Returns:
36-
htpy.section: Accordion component
31+
Renderable: Section element containing the accordion items.
3732
"""
3833

3934
# Add class to attrs
@@ -105,14 +100,32 @@ def accordion(
105100
def accordion_single(
106101
title: str, content: Node | str, expanded: bool = False, **kwargs
107102
) -> Renderable:
108-
"""Single item accordion."""
103+
"""Render a one-item accordion helper.
104+
105+
Args:
106+
title: Accordion heading.
107+
content: Body content node or string.
108+
expanded: Whether the single item starts open.
109+
**kwargs: Additional keyword arguments forwarded to ``accordion``.
110+
111+
Returns:
112+
Renderable: Section element wrapping the single accordion entry.
113+
"""
109114
items: list[AccordionItem] = [{"title": title, "content": content, "expanded": expanded}]
110115
return accordion(items, default_value=title if expanded else None, **kwargs)
111116

112117

113118
# Convenience function for FAQ accordion
114119
def accordion_faq(questions_answers: list[tuple[str, str]], **kwargs) -> Renderable:
115-
"""FAQ accordion with questions and answers."""
120+
"""Render an FAQ-style accordion.
121+
122+
Args:
123+
questions_answers: Sequence of (question, answer) tuples.
124+
**kwargs: Additional keyword arguments forwarded to ``accordion``.
125+
126+
Returns:
127+
Renderable: Section element containing an accordion with FAQ entries.
128+
"""
116129
items: list[AccordionItem] = [
117130
{"title": question, "content": p[answer], "expanded": False}
118131
for question, answer in questions_answers

src/htpy_uikit/components/alert.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,19 @@ def alert(
2020
target_id: str | None = None,
2121
class_: str | None = None,
2222
) -> Renderable:
23-
"""Basecoat-style alert with intent-based variants.
23+
"""Render a Basecoat-style alert with optional icon and description.
2424
25-
Structure matches the reference:
26-
<div class="alert[ -destructive]">
27-
<svg/> (optional)
28-
<h2/>
29-
<section/> (optional)
30-
</div>
25+
Args:
26+
title: Primary alert text.
27+
description: Optional supporting description.
28+
variant: Visual variant; controls tone and icon (e.g., ``\"destructive\"``).
29+
show_icon: Whether to render a contextual icon.
30+
icon: Override icon renderable (takes precedence over ``variant`` default).
31+
target_id: Optional id and HTMX swap target when replacing alerts dynamically.
32+
class_: Additional CSS classes appended to the alert container.
33+
34+
Returns:
35+
Renderable: ``<div role=\"alert\">`` tree that matches Basecoat styling.
3136
"""
3237

3338
# Inline Basecoat alert classes so the component is self-contained.

src/htpy_uikit/components/alert_dialog.py

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323

2424
class AlertDialogTriggerAttrs(TypedDict):
25+
"""Attributes applied to buttons that toggle the native dialog."""
2526
type: Literal["button"]
2627
onclick: str
2728

@@ -182,11 +183,20 @@ def alert_dialog_destructive(
182183
trigger_btn_variant: ButtonVariant = "outline",
183184
**kwargs,
184185
) -> Node:
185-
"""Render a destructive alert dialog; optionally include an external trigger.
186+
"""Render a destructive alert dialog and optional trigger button.
186187
187-
If `with_trigger` is True this will also render a trigger button next to
188-
the dialog. An `id` will be generated if not provided in kwargs so the
189-
trigger can reference the dialog.
188+
Args:
189+
children: Dialog body content.
190+
title: Dialog title.
191+
description: Optional description text.
192+
with_trigger: Whether to render an accompanying trigger button.
193+
trigger_label: Label for the trigger button.
194+
trigger_attrs: Extra attributes applied to the trigger button.
195+
trigger_btn_variant: Variant passed to ``button_component`` for the trigger.
196+
**kwargs: Additional keyword arguments forwarded to ``alert_dialog``.
197+
198+
Returns:
199+
Node: Dialog renderable, optionally paired with a trigger button.
190200
"""
191201
# ensure an id is present so trigger can open the dialog
192202
dialog_id = kwargs.get("id") or f"alert-dialog-{random_string(6)}"
@@ -223,7 +233,22 @@ def confirm_dialog(
223233
trigger_btn_variant: ButtonVariant = "outline",
224234
**kwargs,
225235
) -> Node:
226-
"""Simple confirmation dialog; optionally render an external trigger."""
236+
"""Render a confirmation dialog with optional trigger button.
237+
238+
Args:
239+
message: Dialog body text.
240+
title: Dialog title.
241+
confirm_text: Label for the confirm action button.
242+
cancel_text: Label for the cancel button.
243+
with_trigger: Whether to render an accompanying trigger button.
244+
trigger_label: Label for the trigger button.
245+
trigger_attrs: Extra attributes applied to the trigger button.
246+
trigger_btn_variant: Button variant for the trigger.
247+
**kwargs: Additional keyword arguments forwarded to ``alert_dialog``.
248+
249+
Returns:
250+
Node: Dialog renderable (and trigger button when requested).
251+
"""
227252
dialog_id = kwargs.get("id") or f"alert-dialog-{random_string(6)}"
228253
kwargs["id"] = dialog_id
229254

src/htpy_uikit/components/avatar.py

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,17 @@ def avatar(
2323
class_: str | None = None,
2424
**attrs,
2525
) -> Renderable:
26-
"""
27-
Basecoat-style avatar component.
28-
29-
Based on Basecoat UI avatar implementation.
30-
Note: Basecoat doesn't have a dedicated avatar component,
31-
this uses standard img elements with avatar styling.
26+
"""Render an image avatar with Basecoat sizing tokens.
3227
3328
Args:
34-
src: Image source URL
35-
alt: Image alt text
36-
size: Avatar size
37-
class_: Additional CSS classes
38-
**attrs: Additional HTML attributes
29+
src: Image source URL.
30+
alt: Alt text describing the avatar.
31+
size: Size token mapping to Tailwind ``size-*`` classes.
32+
class_: Extra CSS classes appended to the ``img`` element.
33+
**attrs: Additional HTML attributes forwarded to the ``img`` tag.
3934
4035
Returns:
41-
htpy.img: Avatar image element
36+
Renderable: Configured ``<img>`` node.
4237
"""
4338

4439
# Base classes - following basecoat avatar styling
@@ -63,13 +58,16 @@ def avatar(
6358
def avatar_text(
6459
initials: str, *, size: AvatarSize = "md", class_: str | None = None, **attrs
6560
) -> Renderable:
66-
"""Render an initials avatar (fallback) as a centered rounded span.
61+
"""Render an initials avatar fallback as a rounded ``<span>``.
6762
6863
Args:
69-
initials: Text to show inside the avatar (e.g. "CN")
70-
size: Avatar size key (xs, sm, md, lg, xl)
71-
class_: Extra classes to append
72-
**attrs: Additional attributes for the span
64+
initials: Text or initials displayed inside the avatar.
65+
size: Size token controlling the diameter.
66+
class_: Extra CSS classes appended to the span.
67+
**attrs: Additional HTML attributes forwarded to the span.
68+
69+
Returns:
70+
Renderable: Styled ``<span>`` element with initials.
7371
"""
7472

7573
base = f"{_size_classes[size]} shrink-0 bg-muted flex items-center justify-center rounded-full text-sm font-medium"
@@ -90,9 +88,18 @@ def avatar_group(
9088
hover_expand: bool = False,
9189
class_: str | None = None,
9290
) -> Renderable:
93-
"""Render a stacked avatar group.
91+
"""Render overlapping avatar images with optional rings and hover expansion.
9492
95-
images may be list of src strings or AvatarImage dictionaries with src and alt.
93+
Args:
94+
images: List of avatar URLs or ``AvatarImage`` dicts with ``src``/``alt``.
95+
size: Size token applied to each child avatar.
96+
ring: Whether to render rings (via ``ring-2``) around each avatar.
97+
grayscale: Whether to desaturate avatars.
98+
hover_expand: Whether to animate spacing on hover.
99+
class_: Extra CSS classes appended to the container ``div``.
100+
101+
Returns:
102+
Renderable: Stacked avatar ``<div>`` containing ``<img>`` children.
96103
"""
97104
selectors = []
98105
# ring styles applied to child imgs

0 commit comments

Comments
 (0)