-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update tailwind_field.py #163
base: main
Are you sure you want to change the base?
Conversation
@GitRon could you check this one out? |
Hi @Thutmose3! Interesting idea! But "docs or it didnt happen" - so we'd need some way to tell the users how they can use this. @smithdc1 @carltongibson What do you think about this approach? I'm still the new kid on the block 🙃 |
Ok, i'm adding a few more improvements, and will document it |
Hi @Thutmose3, I just wanted to comment that this package supports class customization by widget as follows:
CRISPY_CLASS_CONVERTERS = {
'textinput': 'dark:text-gray-100 dark:bh-gray-700'
} It's just not documented. Does this new functionality conflict with Regards. |
Oh, nice one @blasferna! Do you think you have the time to add a small snippet about it to the docs? |
Hello @GitRon,
I could add some examples to the documentation without any problem. |
Credit for this PR goes to @amitjindal as i basically copied his proposals from here: #90. This feature should not conflict with CRISPY_CLASS_CONVERTERS (I think). I also removed the hardcoded tailwind classes from select.html, and added these classes to the default_styles. Which should work as usual, and give people the posibility to easily overwrite these classes. |
@blasferna Sounds good! 👌 @Thutmose3 Sounds good as well! 🚀 |
This PR has 2 features basically:
|
@GitRon Sorry for the slow reply. I don't have a concrete preference. Goal is to parameterise the classes used. So OK. Having one clear, documented, way to do that is the answer. Beyond that, all I can say, What's the API you want to use? Keep it clean. Head there. (That's very high-level I know.)
💯 Update: I realise it was only two hours, so I won't worry about the slow reply 😅 |
@GitRon i added documentation to explain this new feature, there is still some work to improve on this, but if it's merged, i'll continue to expand on this feature. It seems the tests are failing, do you know why or can point me in the good direction? |
Hi all 👋
Completely agree. Styles can be customised already, but it's not documented. So that doesn't count. That's on me. The code currently allows you to customise by setting the styles on the form helper. Here's the draft docs for that. Happy to go with whichever option you think is best. Another thought, Textual/rich does css in python code? Any inspiration from there? (Likely not but...) |
@smithdc1 i saw the CSSContainer class, but i was unable to get it to work as i could not find good documentation about it. And it seems it will only work when using |
Thats a good point and seems about right to me. 👍 FormHelper gives more flexibility. It allows customising of styles per form. I imagine being able to switch between light and dark modes for example depending on a user setting. (Does that sound right? 🤔) I wonder if there are any other considerations to take into account. I'll have a ponder tomorrow. |
Yeah, i use FormHelper only on big/complex forms, but when starting on a new form i dont do it, only when it becomes necessary. The CSSContainer is handy as you can customize each form with different styles. But it's a bit more complex to set up. By configuring it in CRISPY_TAILWIND_STYLE it is applied on all forms uniformly, but is a bit less flexible and simpler. Both have pros/cons, but I think both can be used. Possibility to have a default config, and be able to update it on complex forms with CSSContainer. |
@Thutmose3 That sounds plausible. If you could put that thought into a few points for the docs I think it would make a good clarification. 👍 |
@Thutmose3 I agree with @carltongibson.
Please let us know when you've done that, then we can have a review-look and continue from there. Would that be fine for you? |
@carltongibson @GitRon yes will do for sure, my newborn son arrived yesterday so i'm a bit busy at the moment, but will do it once i have some more free time! |
Hi all, i just finished updating the documentation for this, can you let me know if this is ok for you? I'm using Flowbite theme for Tailwind, and i think with this setup, we could have different "default_styles" dicts in the backend with different Tailwind themes, and people can configure a setting for what theme they want and it will take these classes. But thats for another PR, once this is merged i will continue working on making this work on more fields, and cleanly move away from the "hardcoded" nature of the project. |
@GitRon, what do you think, is it ok to merge? |
Hi @Thutmose3! Hope your son is well? 🙂 I'm very busy at the moment but your are not forgotten. I'll have a look at it as soon as I find a couple of quite minutes. |
Yes doing wonderfull thanks 🙂 ok thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @Thutmose3! Sorry for the late reply! Great work, only a few things popped up!
docs/custom.txt
Outdated
----------------------------------------------------------------------------- | ||
|
||
Example: | ||
``CRISPY_TAILWIND_STYLE = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: github docs complains here about something
docs/custom.txt
Outdated
This is currently only working for the input fields and the select field. More coming soon. | ||
|
||
These are the fields you can override: | ||
CRISPY_TAILWIND_STYLE = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: might be worth marking it as python code?
"selectdate": "", | ||
"error_border": "", | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: github actions docs complains
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no clue why its still complaining about this, i tried all different variations newlines and indents to make it happy, but it still complains
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe @smithdc1 knows what to do here?
Hi @Thutmose3! Are you aware of my review some months ago? I realised that sometimes GitHub forgets to send update messages. Best |
Bumping this as I would love to see this merged in 👍 |
@GitRon this might be the wrong place to ask this question, but could you point me to or provide a clear example of how to use the CSSContainer currently to support styling my form elements? |
Hi @becurrie! We like to see this in as well, we are currently waiting for @Thutmose3 or somebody else to take on the code review findings. About the CSSContainer, maybe one of the others might be able to help out, I haven't used it so far, sorry 😔 Best from Cologne |
Hi all, sorry for late reply. Life got a little in the way! I commented/resolved the issues @GitRon |
All comments got resolved, except the warning for indentation in the docstring, i tried to fix it, but it keeps complaining. Maybe someone else can fix it? |
Hi @Thutmose3 , I noticed a minor adjustment that could resolve the syntax warnings being flagged by the For instance, on line 25 of
with:
Similarly, on line 35, change:
with:
I tested these changes in my fork, and it resolved the bot's complaints about syntax warnings. You can review the modifications in my pull request here: Thanks! |
Thanks @vagrants0140 |
@GitRon The PR is ready for merging |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Thutmose3 Thanks for all your work! I think it seems like a neat and solid solution. Just found some minor things (which I'd still like to see fixed 🙃). Maybe @smithdc1 could have a look as well. Would give me a lot of confidence to get the 👍 of a crispy veteran on this topic.
@@ -76,41 +76,54 @@ def pairwise(iterable): | |||
return zip(a, a) | |||
|
|||
|
|||
@register.filter | |||
def tailwind_field_class(field): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought: how about a unit-test? this is a massive piece of python code, though not so much complicated logic.
|
||
While our opinionated Tailwind styles may get you so far you may wish to change these. | ||
The first one is to override CRISPY_TAILWIND_STYLE in your settings. This will override the defaults for all forms. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first one is to override CRISPY_TAILWIND_STYLE in your settings. This will override the defaults for all forms. | |
The first one is to override ``CRISPY_TAILWIND_STYLE`` in your settings. This will override the defaults for all forms. |
The second way is to configure ``CSSContainer`` on a specific form. This will only work for forms that use FormHelper. | ||
This allows you to override a specific form, this is usefull for unique/complex forms. | ||
|
||
The idea is that you can easily configure all forms by overriding CRISPY_TAILWIND_STYLE in settings, and if you want to customize a specific form, you can use CSSContainer for that specific form. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea is that you can easily configure all forms by overriding CRISPY_TAILWIND_STYLE in settings, and if you want to customize a specific form, you can use CSSContainer for that specific form. | |
The idea is that you can easily configure all forms by overriding ``CRISPY_TAILWIND_STYLE`` in settings, and if you want to customize a specific form, you can use ``CSSContainer`` for that specific form. |
"selectdate": "", | ||
"error_border": "", | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe @smithdc1 knows what to do here?
No description provided.