Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,16 @@ print(page.render(pretty=True))
pip install nitro-ui
```

### Claude Code Skill
### AI Assistant Integration

Add NitroUI as a skill in [Claude Code](https://claude.ai/code) for AI-assisted HTML generation:
Add NitroUI knowledge to your AI coding assistant:

```bash
npx skills add nitrosh/nitro-ui
```

This enables AI assistants like Claude Code to understand NitroUI and generate correct HTML code.

## Quick Examples

### Dynamic Content
Expand Down Expand Up @@ -421,11 +423,11 @@ black src/ tests/

## Ecosystem

- **[nitro-cli](https://github.com/nitrosh/nitro-cli)** - Static site generator
- **[nitro-ui](https://github.com/nitrosh/nitro-ui)** - Programmatic HTML generation
- **[nitro-datastore](https://github.com/nitrosh/nitro-datastore)** - Data loading with dot notation access
- **[nitro-dispatch](https://github.com/nitrosh/nitro-dispatch)** - Plugin system
- **[nitro-validate](https://github.com/nitrosh/nitro-validate)** - Data validation
- **[nitro-cli](https://github.com/nitrosh/nitro-cli)** - Python-powered static site generator
- **[nitro-datastore](https://github.com/nitrosh/nitro-datastore)** - Schema-free JSON data store with dot notation access
- **[nitro-dispatch](https://github.com/nitrosh/nitro-dispatch)** - Framework-agnostic plugin system
- **[nitro-image](https://github.com/nitrosh/nitro-image)** - Fast, friendly image processing for the web
- **[nitro-validate](https://github.com/nitrosh/nitro-validate)** - Dependency-free data validation

## License

Expand Down
8 changes: 5 additions & 3 deletions SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -850,10 +850,12 @@ form = Form(
)
```

All `Field.*` methods accept an optional `id` parameter (defaults to `name` when omitted) and forward any additional keyword arguments (including `hx_*`) to the underlying input via `**attrs`.

### Text Fields

```python
Field.text(name, label=None, required=False, min_length=None, max_length=None, pattern=None, placeholder=None, value=None, wrapper=None, **attrs)
Field.text(name, label=None, required=False, min_length=None, max_length=None, pattern=None, placeholder=None, value=None, id=None, wrapper=None, **attrs)
Field.email(name, label=None, required=False, placeholder=None, value=None, wrapper=None, **attrs)
Field.password(name, label=None, required=False, min_length=None, max_length=None, placeholder=None, wrapper=None, **attrs)
Field.url(name, label=None, required=False, placeholder=None, value=None, wrapper=None, **attrs)
Expand Down Expand Up @@ -883,8 +885,8 @@ Field.select("priority", [{"value": "1", "label": "Low", "disabled": True}]) #
# Pre-selected value
Field.select("country", ["USA", "Canada"], value="Canada", label="Country")

# Checkbox (label wraps input)
Field.checkbox("terms", label="I agree to the Terms", required=True)
# Checkbox (label wraps input, accepts checked=True and value="on")
Field.checkbox("terms", label="I agree to the Terms", required=True, checked=False)

# Radio buttons (wrapped in fieldset)
Field.radio("plan", [("free", "Free"), ("pro", "Pro")], label="Select Plan", value="free")
Expand Down
6 changes: 3 additions & 3 deletions examples/attributes_and_styles.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def constructor_attributes():
print()

# Link with target and rel
link = Link(
link = Anchor(
"External Link",
href="https://example.com",
target="_blank",
Expand Down Expand Up @@ -216,8 +216,8 @@ def aria_attributes():

# Navigation with ARIA landmark
nav = Nav(
Link("Home", href="/"),
Link("About", href="/about"),
Anchor("Home", href="/"),
Anchor("About", href="/about"),
aria_label="Main navigation",
role="navigation",
)
Expand Down
30 changes: 15 additions & 15 deletions examples/basic_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ def document_structure():
Meta(charset="utf-8"),
Meta(name="viewport", content="width=device-width, initial-scale=1.0"),
Meta(name="description", content="A website built with NitroUI"),
HtmlLink(rel="stylesheet", href="/css/styles.css"),
HtmlLink(rel="icon", href="/favicon.ico"),
Link(rel="stylesheet", href="/css/styles.css"),
Link(rel="icon", href="/favicon.ico"),
Script(src="/js/main.js", defer="true"),
),
Body(
Header(
Nav(
Link("Home", href="/"),
Link("About", href="/about"),
Link("Contact", href="/contact"),
Anchor("Home", href="/"),
Anchor("About", href="/about"),
Anchor("Contact", href="/contact"),
)
),
Main(H1("Welcome"), Paragraph("This is the main content area.")),
Expand Down Expand Up @@ -77,7 +77,7 @@ def text_elements():
", ",
Ins("inserted text"),
", and ",
Link("hyperlinks", href="https://example.com"),
Anchor("hyperlinks", href="https://example.com"),
".",
),
Blockquote(
Expand Down Expand Up @@ -106,9 +106,9 @@ def layout_elements():
Header(
H1("Site Title"),
Nav(
Link("Home", href="/"),
Link("Products", href="/products"),
Link("About", href="/about"),
Anchor("Home", href="/"),
Anchor("Products", href="/products"),
Anchor("About", href="/about"),
),
),
Main(
Expand All @@ -129,9 +129,9 @@ def layout_elements():
Aside(
H3("Related Links"),
UnorderedList(
ListItem(Link("Link 1", href="#")),
ListItem(Link("Link 2", href="#")),
ListItem(Link("Link 3", href="#")),
ListItem(Anchor("Link 1", href="#")),
ListItem(Anchor("Link 2", href="#")),
ListItem(Anchor("Link 3", href="#")),
),
),
),
Expand Down Expand Up @@ -230,9 +230,9 @@ def conditional_rendering():
if user["is_admin"]:
header.append(
Nav(
Link("Dashboard", href="/dashboard"),
Link("Users", href="/users"),
Link("Settings", href="/settings"),
Anchor("Dashboard", href="/dashboard"),
Anchor("Users", href="/users"),
Anchor("Settings", href="/settings"),
class_name="admin-nav",
)
)
Expand Down
28 changes: 14 additions & 14 deletions examples/context_managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ def nested_context_managers():
with Header(class_name="site-header") as header:
header.append(H1("My Website"))
with Nav(class_name="main-nav") as nav:
nav.append(Link("Home", href="/"))
nav.append(Link("About", href="/about"))
nav.append(Link("Contact", href="/contact"))
nav.append(Anchor("Home", href="/"))
nav.append(Anchor("About", href="/about"))
nav.append(Anchor("Contact", href="/contact"))
header.append(nav)
page.append(header)

Expand All @@ -60,7 +60,7 @@ def comparison_with_regular():

# Regular nesting (constructor-based)
regular = Div(
Header(H1("Title"), Nav(Link("Home", href="/"), Link("About", href="/about"))),
Header(H1("Title"), Nav(Anchor("Home", href="/"), Anchor("About", href="/about"))),
Main(Article(H2("Article"), Paragraph("Content"))),
Footer(Paragraph("Footer")),
id="regular",
Expand All @@ -74,8 +74,8 @@ def comparison_with_regular():
with Header() as header:
header.append(H1("Title"))
with Nav() as nav:
nav.append(Link("Home", href="/"))
nav.append(Link("About", href="/about"))
nav.append(Anchor("Home", href="/"))
nav.append(Anchor("About", href="/about"))
header.append(nav)
context.append(header)

Expand Down Expand Up @@ -139,16 +139,16 @@ def conditional_with_context():

with Nav(class_name="user-nav") as nav:
if is_logged_in:
nav.append(Link("Profile", href="/profile"))
nav.append(Link("Settings", href="/settings"))
nav.append(Anchor("Profile", href="/profile"))
nav.append(Anchor("Settings", href="/settings"))

if is_admin:
nav.append(Link("Admin Panel", href="/admin"))
nav.append(Anchor("Admin Panel", href="/admin"))

nav.append(Link("Logout", href="/logout"))
nav.append(Anchor("Logout", href="/logout"))
else:
nav.append(Link("Login", href="/login"))
nav.append(Link("Sign Up", href="/signup"))
nav.append(Anchor("Login", href="/login"))
nav.append(Anchor("Sign Up", href="/signup"))

header.append(nav)

Expand Down Expand Up @@ -273,7 +273,7 @@ def complex_layout_with_context():
with UnorderedList() as menu:
for item in sidebar_items:
with ListItem() as li:
li.append(Link(item, href=f"/{item.lower()}"))
li.append(Anchor(item, href=f"/{item.lower()}"))
menu.append(li)
nav.append(menu)
sidebar.append(nav)
Expand Down Expand Up @@ -331,7 +331,7 @@ def mixing_styles_in_context():
# Regular nesting for simple structures
container.append(
Header(
H1("Title"), Nav(Link("Link 1", href="#1"), Link("Link 2", href="#2"))
H1("Title"), Nav(Anchor("Link 1", href="#1"), Anchor("Link 2", href="#2"))
)
)

Expand Down
4 changes: 2 additions & 2 deletions examples/custom_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def __init__(self, text, href="#", active=False, **kwargs):

self.add_attribute("class", "nav-item")

link = Link(text, href=href, class_name="nav-link")
link = Anchor(text, href=href, class_name="nav-link")
if active:
link.add_attribute("class", "nav-link active")
link.add_style("font-weight", "600")
Expand All @@ -308,7 +308,7 @@ def __init__(self, brand, *items, **kwargs):

# Brand
self.append(
Link(brand, href="/", class_name="navbar-brand").add_styles(
Anchor(brand, href="/", class_name="navbar-brand").add_styles(
{
"font-size": "20px",
"font-weight": "700",
Expand Down
Loading
Loading