Skip to content

Commit c2a4d68

Browse files
committed
[Form] add tailwindcss form theme docs
1 parent 452ea2b commit c2a4d68

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed

form/tailwindcss2.rst

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
Tailwind CSS 2 Form Theme
2+
=========================
3+
4+
.. versionadded:: 5.3
5+
6+
The Tailwind CSS 2 Form Theme was introduced in Symfony 5.3 as an
7+
:doc:`experimental feature </contributing/code/experimental>`.
8+
9+
Symfony provides a minimal form theme for `Tailwind CSS`_. Tailwind is a *utility first*
10+
CSS framework and provides *unlimited ways* to customize your forms. Tailwind 2.0 has
11+
an official `form plugin`_ that provides a basic form reset that standardizes their look
12+
on all browsers. This form theme requires this plugin and adds a few basic tailwind
13+
classes so out of the box, your forms will look decent. Customization is almost always
14+
going to be required so this theme makes that easy.
15+
16+
To use, first be sure you have installed and integrated `Tailwind CSS 2.0`_ and the
17+
`form plugin`_. Follow their respective documentation to install.
18+
19+
If you prefer to use the Tailwind theme on a form to form basis, include the
20+
``form_theme`` tag in the templates where those forms are used:
21+
22+
.. code-block:: html+twig
23+
24+
{# ... #}
25+
{# this tag only applies to the forms defined in this template #}
26+
{% form_theme form 'tailwind_2_layout.html.twig' %}
27+
28+
{% block body %}
29+
<h1>User Sign Up:</h1>
30+
{{ form(form) }}
31+
{% endblock %}
32+
33+
Customization
34+
-------------
35+
36+
Customizing css classes is especially important for this theme.
37+
38+
Twig Form Functions
39+
~~~~~~~~~~~~~~~~~~~
40+
41+
.. code-block:: twig
42+
43+
{{ form_row(form.title, {
44+
row_class: 'my row classes',
45+
label_class: 'my label classes',
46+
error_item_class: 'my error item classes',
47+
widget_class: 'my widget classes',
48+
widget_disabled_class: 'my disabled widget classes',
49+
widget_errors_class: 'my widget with error classes',
50+
}) }}
51+
52+
.. note::
53+
54+
When customizing the classes this way the defaults provided by the theme
55+
are *overridden* opposed to merged as is the case with other themes. This
56+
enables you to take full control of the classes without worrying about
57+
*undoing* the generic defaults the theme provides.
58+
59+
Project Specific Form Layout
60+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
61+
62+
.. code-block:: twig
63+
64+
{% use 'tailwind_2_layout.html.twig' %}
65+
66+
{%- block form_row -%}
67+
{%- set row_class = row_class|default('my row classes') -%}
68+
{{- parent() -}}
69+
{%- endblock form_row -%}
70+
71+
{%- block widget_attributes -%}
72+
{%- set widget_class = widget_class|default('my widget classes') -%}
73+
{%- set widget_disabled_class = widget_disabled_class|default('my disabled widget classes') -%}
74+
{%- set widget_errors_class = widget_errors_class|default('my widget with error classes') -%}
75+
{{- parent() -}}
76+
{%- endblock widget_attributes -%}
77+
78+
{%- block form_label -%}
79+
{%- set label_class = label_class|default('my label classes') -%}
80+
{{- parent() -}}
81+
{%- endblock form_label -%}
82+
83+
{%- block form_help -%}
84+
{%- set help_class = help_class|default('my label classes') -%}
85+
{{- parent() -}}
86+
{%- endblock form_help -%}
87+
88+
{%- block form_errors -%}
89+
{%- set error_item_class = error_item_class|default('my error item classes') -%}
90+
{{- parent() -}}
91+
{%- endblock form_errors -%}
92+
93+
.. _`Tailwind CSS`: https://tailwindcss.com
94+
.. _`Tailwind CSS 2.0`: https://tailwindcss.com/docs/installation
95+
.. _`form plugin`: https://github.com/tailwindlabs/tailwindcss-forms

forms.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,7 @@ Form Themes and Customization:
10431043
:maxdepth: 1
10441044

10451045
/form/bootstrap4
1046+
/form/tailwindcss2
10461047
/form/form_customization
10471048
/form/form_themes
10481049

0 commit comments

Comments
 (0)