Skip to content

Commit

Permalink
input and label fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
phernandez committed Oct 27, 2024
1 parent 3875712 commit 3f8c181
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 17 deletions.
12 changes: 4 additions & 8 deletions components/ui/Checkbox.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,11 @@
<input
type="checkbox"
id="{{ attrs.get('id', '') }}"
class="{{ className }}
text-black accent-black rounded
border-zinc-200 dark:border-zinc-50
focus:ring-2 focus:ring-offset-2
focus:ring-black dark:focus:ring-white
dark:focus:ring-2 dark:focus:ring-offset-2
"
class="{{ className }} text-black accent-black rounded border-zinc-200 dark:border-zinc-50 focus:ring-2 focus:ring-offset-2 focus:ring-black dark:focus:ring-white dark:focus:ring-2 dark:focus:ring-offset-2"
{% if checked %}checked{% endif %}
{% if disabled %}disabled{% endif %}
/>
<label for="{{ attrs.get('id', '') }}" class="ml-2 text-sm">{{ label }}</label>
{% if label %}
<label for="{{ attrs.get('id', '') }}" class="ml-2 text-sm">{{ label }}</label>
{% endif %}
</div>
4 changes: 2 additions & 2 deletions components/ui/FormLabel.jinja
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{#def
for_id: str,
htmlFor: str,
className: str = "",
error: bool = False
#}
<label
for="{{ for_id }}"
for="{{ htmlFor }}"
class="{% if error %}text-red-500 dark:text-red-800{% endif %} {{ className }} block text-sm font-medium leading-6"
>
{{ content }}
Expand Down
6 changes: 2 additions & 4 deletions components/ui/Label.jinja
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
{#def
for_id: str = "",
htmlFor: str = "",
className: str = "",
disabled: bool = False
#}
{% set baseclassName = "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70" %}
<label
for="{{ for_id }}"
for="{{ htmlFor }}"
class="{{ baseclassName }} {{ className }}"
{% if disabled %}disabled{% endif %}
{{ attrs.render() }}
>
{{ content }}
Expand Down
2 changes: 1 addition & 1 deletion documentation/backend/templates/form.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Form method="GET" action="">
<FormItem id="email-field">
<FormLabel for_id="email">Email Address</FormLabel>
<FormLabel htmlFor="email">Email Address</FormLabel>
<Input
id="email"
placeholder="Email"
Expand Down
2 changes: 1 addition & 1 deletion documentation/backend/templates/form_errors.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<Form method="GET" action="">
<FormItem id="email-field">
<FormLabel for_id="emalocil" :error="{{ error }}">Email Address</FormLabel>
<FormLabel htmlFor="emalocil" :error="{{ error }}">Email Address</FormLabel>
<Input
id="email"
type="email"
Expand Down
4 changes: 4 additions & 0 deletions documentation/backend/templates/input_button.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div class="flex w-full max-w-sm items-center space-x-2">
<Input type="email" placeholder="Email"/>
<Button type="submit">Subscribe</Button>
</div>
4 changes: 4 additions & 0 deletions documentation/backend/templates/input_file.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div class="w-full space-y-2">
<Label htmlFor="picture">Picture</Label>
<Input id="picture" type="file"/>
</div>
4 changes: 4 additions & 0 deletions documentation/backend/templates/input_peer_disabled.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div class="w-full space-y-2">
<Label for="email" disabled="true">Email Address</Label>
<Input id="email" type="text" class="peer" disabled/>
</div>
4 changes: 4 additions & 0 deletions documentation/backend/templates/label.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div class="flex items-center space-x-2">
<Checkbox id="terms" />
<Label htmlFor="terms">Accept terms and conditions</Label>
</div>
41 changes: 40 additions & 1 deletion documentation/docs/components/input.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Form
# Input

Displays a form input field.

Expand Down Expand Up @@ -79,3 +79,42 @@ style="width: 100%; height: 200px; border: none;">
```html
{% include-markdown "../../backend/templates/input_label.html" %}
```

### File

=== "Preview"
<iframe
src="{{ preview_url}}/components/input?option=file"
style="width: 100%; height: 200px; border: none;">
</iframe>

=== "Code"
```html
{% include-markdown "../../backend/templates/input_file.html" %}
```

### Button

=== "Preview"
<iframe
src="{{ preview_url}}/components/input?option=button"
style="width: 100%; height: 200px; border: none;">
</iframe>

=== "Code"
```html
{% include-markdown "../../backend/templates/input_button.html" %}
```

### Peer Disabled

=== "Preview"
<iframe
src="{{ preview_url}}/components/input?option=peer_disabled"
style="width: 100%; height: 200px; border: none;">
</iframe>

=== "Code"
```html
{% include-markdown "../../backend/templates/input_peer_disabled.html" %}
```
32 changes: 32 additions & 0 deletions documentation/docs/components/label.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Label

Displays a label for a form field.

## Preview

<iframe
src="{{ preview_url}}/components/label"
style="width: 100%; height: 200px; border: none;">
</iframe>

## Props

| Prop | Type | Default | Description |
|-------------|---------|---------|-------------------------------------------|
| `htmlFor` | String | `False` | The id of the field the label refers to. |
| `className` | String | `""` | Additional CSS classes for customization. |

## Components

=== "Label.jinja"
{% raw %}
```jinja
{% include '../../../components/ui/Label.jinja' %}
```
{% endraw %}

## Usage

```html
{% include-markdown "../../backend/templates/label.html" %}
```

0 comments on commit 3f8c181

Please sign in to comment.