Skip to content

Commit dd3f497

Browse files
Added base styles
Co-authored-by: Jonathan Grahl <[email protected]>
1 parent 159df01 commit dd3f497

File tree

2 files changed

+63
-21
lines changed

2 files changed

+63
-21
lines changed

crispy_tailwind/templatetags/tailwind_field.py

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,38 @@ def pairwise(iterable):
7777

7878
class CrispyTailwindFieldNode(template.Node):
7979

80-
default_styles = {"text": "tailwind-text", "radioselect": " tailwind-radio"}
80+
base_input = (
81+
"bg-white focus:outline-none border border-gray-300 rounded-lg py-2 px-4 block w-full "
82+
"appearance-none leading-normal text-gray-700"
83+
)
84+
85+
default_styles = {
86+
"text": base_input,
87+
"number": base_input,
88+
"radioselect": "",
89+
"email": base_input,
90+
"url": base_input,
91+
"password": base_input,
92+
"hidden": "",
93+
"multiplehidden": "",
94+
"file": "",
95+
"clearablefile": "",
96+
"textarea": base_input,
97+
"date": base_input,
98+
"datetime": base_input,
99+
"time": base_input,
100+
"checkbox": "",
101+
"select": "",
102+
"nullbooleanselect": "",
103+
"selectmultiple": "",
104+
"radioselect": "",
105+
"checkboxselectmultiple": "",
106+
"multi": "",
107+
"splitdatetime": "text-gray-700 bg-white focus:outline border border-gray-300 leading-normal px-4 "
108+
"appearance-none rounded-lg py-2 focus:outline-none mr-2",
109+
"splithiddendatetime": "",
110+
"selectdate": "",
111+
}
81112

82113
default_container = CSSContainer(default_styles)
83114

@@ -113,11 +144,7 @@ def render(self, context): # noqa: C901
113144
if isinstance(attrs, dict):
114145
attrs = [attrs] * len(widgets)
115146

116-
converters = {
117-
"textinput": "textinput textInput",
118-
"fileinput": "fileinput fileUpload",
119-
"passwordinput": "textinput textInput",
120-
}
147+
converters = {}
121148
converters.update(getattr(settings, "CRISPY_CLASS_CONVERTERS", {}))
122149

123150
for widget, attr in zip(widgets, attrs):
@@ -131,7 +158,6 @@ def render(self, context): # noqa: C901
131158
css_class = class_name
132159

133160
# Added additional code for Tailwind
134-
135161
if template_pack == "tailwind":
136162
css_container = context.get("css_container", self.default_container)
137163
if css_container:

tests/test_filter.py

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,48 +27,64 @@ def test_crispy_filter(self):
2727
<div id="div_id_email" class=" mb-3">
2828
<label for="id_email" class="block text-gray-700 text-sm font-bold mb-2">email<span class="asteriskField">
2929
*</span> </label>
30-
<input type="text" name="email" maxlength="30" class="textinput textInput inputtext tailwind-text"
30+
<input type="text" name="email" maxlength="30" class="textinput textInput inputtext w-full rounded-lg """
31+
"""border appearance-none py-2 border-gray-300 bg-white text-gray-700 focus:outline-none px-4 block """
32+
"""leading-normal"
3133
required id="id_email">
3234
<small id="hint_id_email" class="text-gray-600">Insert your email</small> </div>
3335
3436
<div id="div_id_password1" class=" mb-3">
35-
<label for="id_password1" class="block text-gray-700 text-sm font-bold mb-2">password
36-
<span class="asteriskField">*</span>
37+
<label for="id_password1" class="block text-gray-700 text-sm font-bold mb-2">password<span
38+
class="asteriskField">*</span>
3739
</label>
38-
<input type="password" name="password1" maxlength="30" class="textinput textInput "
39-
required id="id_password1"> </div>
40+
<input type="password" name="password1" maxlength="30"
41+
class="passwordinput w-full rounded-lg """
42+
"""border appearance-none py-2 border-gray-300 bg-white text-gray-700 focus:outline-none px-4 block """
43+
"""leading-normal" required id="id_password1">
44+
</div>
4045
4146
<div id="div_id_password2" class=" mb-3">
4247
<label for="id_password2" class="block text-gray-700 text-sm font-bold mb-2">
4348
re-enter password<span class="asteriskField">*</span> </label>
44-
<input type="password" name="password2" maxlength="30" class="textinput textInput "
49+
<input type="password" name="password2" maxlength="30"
50+
class="passwordinput w-full rounded-lg """
51+
"""border appearance-none py-2 border-gray-300 bg-white text-gray-700 focus:outline-none px-4 block """
52+
"""leading-normal"
4553
required id="id_password2"> </div>
4654
4755
<div id="div_id_first_name" class=" mb-3">
4856
<label for="id_first_name" class="block text-gray-700 text-sm font-bold mb-2">
4957
first name<span class="asteriskField">*</span> </label>
50-
<input type="text" name="first_name" maxlength="5" class="textinput textInput inputtext tailwind-text"
51-
required id="id_first_name"> </div>
58+
<input type="text" name="first_name" maxlength="5" class="textinput textInput inputtext w-full """
59+
"""rounded-lg border appearance-none py-2 border-gray-300 bg-white text-gray-700 focus:outline-none """
60+
'px-4 block leading-normal"'
61+
"""required id="id_first_name"> </div>
5262
5363
<div id="div_id_last_name" class=" mb-3">
5464
<label for="id_last_name" class="block text-gray-700 text-sm font-bold mb-2">
5565
last name<span class="asteriskField">*</span> </label>
56-
<input type="text" name="last_name" maxlength="5" class="textinput textInput inputtext tailwind-text"
57-
required id="id_last_name"> </div>
66+
<input type="text" name="last_name" maxlength="5"
67+
class="textinput textInput inputtext w-full rounded-lg border appearance-none py-2 border-gray-300 """
68+
"""bg-white text-gray-700 focus:outline-none px-4 block leading-normal" required id="id_last_name"> """
69+
"""</div>
5870
5971
<div id="div_id_datetime_field" class=" mb-3">
6072
<label for="id_datetime_field_0" class="block text-gray-700 text-sm font-bold mb-2">
6173
date time<span class="asteriskField">*</span> </label>
62-
<input type="text" name="datetime_field_0" class="dateinput " required id="id_datetime_field_0">
63-
<input type="text" name="datetime_field_1" class="timeinput " required id="id_datetime_field_1">
64-
</div>
74+
<input type="text" name="datetime_field_0"
75+
class="dateinput rounded-lg focus:outline border appearance-none py-2 mr-2 border-gray-300 bg-white """
76+
"""text-gray-700 focus:outline-none px-4 leading-normal" required id="id_datetime_field_0">
77+
<input type="text" name="datetime_field_1" class="timeinput rounded-lg focus:outline border """
78+
"""appearance-none py-2 mr-2 border-gray-300 bg-white text-gray-700 focus:outline-none px-4 """
79+
"""leading-normal" required id="id_datetime_field_1"> </div>
6580
6681
<div id="div_id_tos_accepted" class=" mb-3">
6782
<label for="id_tos_accepted" class="block text-gray-700 text-sm font-bold mb-2">
6883
terms of service<span class="asteriskField">*</span> </label>
6984
<div class=" mb-3">
7085
<div class="relative">
71-
<select class="block appearance-none w-full bg-gray-200 border border-gray-200 text-gray-700 py-3 px-4 pr-8 rounded leading-tight focus:outline-none focus:bg-white focus:border-gray-500" name="tos_accepted">
86+
<select class="block appearance-none w-full bg-gray-200 border border-gray-200 text-gray-700 py-3 px-4 """
87+
"""pr-8 rounded leading-tight focus:outline-none focus:bg-white focus:border-gray-500" name="tos_accepted">
7288
<option value="accepted">Accepted</option>
7389
<option value="not_accepted">Not accepted</option>
7490
</select><div class="pointer-events-none absolute inset-y-0 right-0 flex items-center px-2 text-gray-700">

0 commit comments

Comments
 (0)