Skip to main content

Django integration for Zooy UI framework with Carbon Design System widgets

Project description

django-zooy

Django form widgets for Carbon Design System and Zooy UI framework.

Installation

pip install django-zooy
# settings.py
INSTALLED_APPS = [
    'django_zooy',
]

Quick Start

from django import forms
from django_zooy import CarbonFormMixin
from django_zooy.carbon import CarbonTextInput, CarbonEmailInput

class ContactForm(CarbonFormMixin, forms.Form):
    name = forms.CharField(widget=CarbonTextInput())
    email = forms.EmailField(widget=CarbonEmailInput())

The CarbonFormMixin automatically injects field labels, help text, validation states, and required attributes into Carbon widgets.

Widgets

Carbon Design System

from django_zooy.carbon import (
    CarbonTextInput,      # <cds-text-input>
    CarbonEmailInput,     # <cds-text-input type="email">
    CarbonPasswordInput,  # <cds-password-input>
    CarbonURLInput,       # <cds-text-input type="url">
    CarbonTelInput,       # <cds-text-input type="tel">
    CarbonNumberInput,    # <cds-text-input type="number">
    CarbonSearchInput,    # <cds-text-input type="search">
    CarbonTextarea,       # <cds-textarea>
)

Widget Configuration

Python snake_case attributes are automatically converted to Carbon's kebab-case:

CarbonTextInput(attrs={
    'label': 'Username',
    'helper_text': 'Enter your username',
    'placeholder': 'johndoe',
    'invalid': False,
    'invalid_text': 'Username is required',
    'size': 'md',  # sm, md, lg
    'enable_counter': True,
    'max_count': 50,
})

Boolean attributes render without values:

  • required=Truerequired
  • disabled=Truedisabled
  • invalid=Trueinvalid

Form Mixins

CarbonFormMixin

Automatically configures Carbon widgets with form field metadata:

class MyForm(CarbonFormMixin, forms.ModelForm):
    class Meta:
        model = User
        fields = ['username', 'email']
        widgets = {
            'username': CarbonTextInput(),
            'email': CarbonEmailInput(),
        }

Auto-injected attributes:

  • label from field.label
  • required from field.required
  • helper-text from field.help_text
  • disabled from field.disabled
  • invalid and invalid-text from validation errors

Works with Form, ModelForm, and custom form classes. Only affects Carbon widgets.

ZooyFormMixin

Base mixin for Zooy UI integration. Use CarbonFormMixin for Carbon widgets.

Carbon Icons and Pictograms

Server-side SVG rendering of Carbon Design System icons and pictograms. No JavaScript required.

Setup

# settings.py
CARBON_ICONS_PATH = BASE_DIR / 'carbon' / 'icons'
CARBON_PICTOGRAMS_PATH = BASE_DIR / 'carbon' / 'pictograms'  # Optional
# Download icons only
python manage.py fetch_carbon_assets icons

# Download pictograms only
python manage.py fetch_carbon_assets pictograms

# Download both
python manage.py fetch_carbon_assets all

Downloads 2,000+ icons and pictograms from npm to the specified paths.

Usage

{% load carbon %}
{% carbon_icon "save" %}
{% carbon_icon "edit" 20 %}
{% carbon_icon "delete" 16 slot="icon" class="text-red-500" %}

Arguments:

  • name (required) - Icon name from Carbon icons library
  • size (optional) - 16, 20, 24, or 32. Default: 16
  • **attrs (optional) - HTML attributes (slot, class, data-*, etc.)

Missing icons render nothing and log: CARBON ICON MISSING: "icon-name" size=16 at /path/to/icon.svg

Management Command Options

# Force re-download (overwrites existing files)
python manage.py fetch_carbon_assets icons --force
python manage.py fetch_carbon_assets all --force

Add to deployment pipeline:

# Download icons only
RUN python manage.py fetch_carbon_assets icons

# Or download both icons and pictograms
RUN python manage.py fetch_carbon_assets all

API Reference

CarbonWidgetMixin

Base class for all Carbon widgets. Provides:

  • Automatic snake_case → kebab-case attribute conversion
  • Boolean attribute handling
  • Default size (md)
  • Size constants: SIZE_SMALL, SIZE_MEDIUM, SIZE_LARGE

CarbonTextInput

Tooltip constants:

  • Alignment: TOOLTIP_ALIGN_START, TOOLTIP_ALIGN_CENTER, TOOLTIP_ALIGN_END
  • Direction: TOOLTIP_DIR_TOP, TOOLTIP_DIR_RIGHT, TOOLTIP_DIR_BOTTOM, TOOLTIP_DIR_LEFT

Supported attributes:

  • Standard: label, placeholder, required, disabled, readonly
  • Validation: invalid, invalid_text, warn, warn_text
  • Display: size, hide_label, inline
  • Counter: enable_counter, max_count
  • Tooltip: tooltip_alignment, tooltip_direction

CarbonPasswordInput

Same as CarbonTextInput with show_password_visibility_toggle=True by default.

Additional attributes:

  • hide_password_label - Tooltip text for hide password
  • show_password_label - Tooltip text for show password

CarbonTextarea

Same attributes as CarbonTextInput plus:

  • rows - Number of visible text lines
  • cols - Visible width of the text control

Development

git clone https://github.com/trinity-telecomms/django-zooy
cd django-zooy
uv sync --all-extras --all-groups
pytest
ruff check .

Build and Publish

# Update version in pyproject.toml
uv sync --upgrade --all-extras --all-groups
pytest
rm -rf dist/ build/ *.egg-info/
uv build
uv publish

License

MIT License. See LICENCE for details.

Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_zooy-0.2.0.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_zooy-0.2.0-py3-none-any.whl (18.9 kB view details)

Uploaded Python 3

File details

Details for the file django_zooy-0.2.0.tar.gz.

File metadata

  • Download URL: django_zooy-0.2.0.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.13

File hashes

Hashes for django_zooy-0.2.0.tar.gz
Algorithm Hash digest
SHA256 86f9bec6182e377e24abb4e7ae1aa87b95f7c13bd0d14d5e0c8bcdbc9485d20d
MD5 13fa3d7e2159e3b3b7230600164db7dd
BLAKE2b-256 325d7abdbab506b61d24eb2b668de24a63d36ced14bf4237a4f17889f5c2b6d2

See more details on using hashes here.

File details

Details for the file django_zooy-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_zooy-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4048944a84267371217f3b26912658adbbf436140a4a08286d722e19535130e5
MD5 c81142baa5a70c7ae5da3256f22d1e95
BLAKE2b-256 f6cc7c33a00240fa96b4550116ea4be67d563e686f672f40e12078a6ed6f427c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page