Skip to content

Commit d54ae8c

Browse files
Added base styles
Co-authored-by: Jonathan Grahl <[email protected]>
1 parent 50f6cb6 commit d54ae8c

File tree

2 files changed

+52
-14
lines changed

2 files changed

+52
-14
lines changed

crispy_tailwind/templatetags/tailwind_field.py

Lines changed: 33 additions & 6 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": "",
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):

tests/test_filter.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,48 +27,59 @@ 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">
3537
<label for="id_password1" class="block text-gray-700 text-sm font-bold mb-2">password
3638
<span class="asteriskField">*</span>
3739
</label>
38-
<input type="password" name="password1" maxlength="30" class="textinput textInput "
40+
<input type="password" name="password1" maxlength="30" class="passwordinput"
3941
required id="id_password1"> </div>
4042
4143
<div id="div_id_password2" class=" mb-3">
4244
<label for="id_password2" class="block text-gray-700 text-sm font-bold mb-2">
4345
re-enter password<span class="asteriskField">*</span> </label>
44-
<input type="password" name="password2" maxlength="30" class="textinput textInput "
46+
<input type="password" name="password2" maxlength="30" class="passwordinput"
4547
required id="id_password2"> </div>
4648
4749
<div id="div_id_first_name" class=" mb-3">
4850
<label for="id_first_name" class="block text-gray-700 text-sm font-bold mb-2">
4951
first name<span class="asteriskField">*</span> </label>
50-
<input type="text" name="first_name" maxlength="5" class="textinput textInput inputtext tailwind-text"
52+
<input type="text" name="first_name" maxlength="5" class="textinput textInput inputtext w-full rounded-lg
53+
border appearance-none py-2 border-gray-300 bg-white text-gray-700 focus:outline-none px-4 block
54+
leading-normal"
5155
required id="id_first_name"> </div>
5256
5357
<div id="div_id_last_name" class=" mb-3">
5458
<label for="id_last_name" class="block text-gray-700 text-sm font-bold mb-2">
5559
last name<span class="asteriskField">*</span> </label>
56-
<input type="text" name="last_name" maxlength="5" class="textinput textInput inputtext tailwind-text"
60+
<input type="text" name="last_name" maxlength="5"
61+
class="textinput textInput inputtext w-full rounded-lg border appearance-none py-2 border-gray-300 bg-white
62+
text-gray-700 focus:outline-none px-4 block leading-normal"
5763
required id="id_last_name"> </div>
5864
5965
<div id="div_id_datetime_field" class=" mb-3">
6066
<label for="id_datetime_field_0" class="block text-gray-700 text-sm font-bold mb-2">
6167
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">
68+
<input type="text" name="datetime_field_0" class="dateinput rounded-lg focus:outline border appearance-none
69+
py-2 mr-2 border-gray-300 bg-white text-gray-700 focus:outline-none px-4 leading-normal " required
70+
id="id_datetime_field_0">
71+
<input type="text" name="datetime_field_1" class="timeinput rounded-lg focus:outline border appearance-none
72+
py-2 mr-2 border-gray-300 bg-white text-gray-700 focus:outline-none px-4 leading-normal " required
73+
id="id_datetime_field_1">
6474
</div>
6575
6676
<div id="div_id_tos_accepted" class=" mb-3">
6777
<label for="id_tos_accepted" class="block text-gray-700 text-sm font-bold mb-2">
6878
terms of service<span class="asteriskField">*</span> </label>
6979
<div class=" mb-3">
7080
<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">
81+
<select class="block appearance-none w-full bg-gray-200 border border-gray-200 text-gray-700 py-3 px-4 pr-8
82+
rounded leading-tight focus:outline-none focus:bg-white focus:border-gray-500" name="tos_accepted">
7283
<option value="accepted">Accepted</option>
7384
<option value="not_accepted">Not accepted</option>
7485
</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)