gpt4 book ai didi

How to use Antdesign with tailwindcss together in a React Project(如何在React项目中使用Antdesign和tailwindcss)

转载 作者:bug小助手 更新时间:2023-10-25 21:59:58 31 4
gpt4 key购买 nike



I'm going to set up a new project and would like to have these two packages together, but not sure, so the question is that using Tailwindcss with antdesign Is a good practice?

我要建立一个新的项目,并希望将这两个包放在一起,但不确定,所以问题是,将Tailwincss与antDesign结合使用是一个好做法吗?


Does anyone have any experiences?

有谁有经验吗?


Each package has its own theme manager for instance for colors, typography, dark mode and so on. How do you manage theme, with tailwinds or antd or both? And why?

每个包都有自己的主题管理器,例如颜色、排版、深色模式等。你如何管理主题,顺风或逆风,或两者兼而有之?为什么?


Both packages have Grid support, which one would you prefer?

这两个程序包都支持网格,您更喜欢哪一个?


Let's have your insights?

让我们来听听你的见解?


After some research, I found these results

在一些研究之后,我发现了这些结果


Some examples that uses both libs:

使用这两个库的一些示例:


https://github.com/plamworapot/next-antd-tailwindcss

Https://github.com/plamworapot/next-antd-tailwindcss


https://github.com/dospolov/react-redux-saga-antd-tailwind-boilerplate

https://github.com/dospolov/react-redux-saga-antd-tailwind-boilerplate


https://github.com/cunhamuril/pocs

Https://github.com/cunhamuril/pocs


It recommended trying to commit to only one framework

它建议尝试只致力于一个框架


更多回答

For anyone having this problem, this Stackoverflow answer might be helpful!

对于任何有这个问题的人,这个Stackoverflow答案可能会有所帮助!

优秀答案推荐

Tailwind is pretty much a design system using utility classes to make writing css easier therefore it can be pretty much used with any other ui library just make sure to disable the default styling that Tailwind inject into your default styling by disabling the preflight option in config :

Tailwind是一个使用实用程序类的设计系统,使编写css更容易,因此它可以与任何其他ui库一起使用,只要确保禁用默认样式,Tailwind注入到您的默认样式中,通过禁用配置中的preflight选项:


module.exports = {
corePlugins: {
preflight: false,
}
}


One slight issue with using both ant-design and tailwind-css is tailwind's some of default styles will break ant-design components...

同时使用蚂蚁设计和顺风的一个小问题是,顺风的一些默认样式会破坏蚂蚁设计组件……


I recently came a cross an issue where ant-design image preview was not functioning correctly and the image was not centered.

我最近遇到了一个问题,蚂蚁设计的图像预览不能正常工作,图像没有居中。


expected result
image one

预期结果图像一


vs what I got when using tailwind with ant-design
image two

与我使用顺风和蚂蚁设计图像2时得到的对比


turns out tailwind will change default image display property from "inline-block" to "block" and breaks tailwind image preview component

原来,顺风会将默认的图像显示属性从“内联块”更改为“块”,并破坏顺风图像预览组件


I resolved my issue by reseting display property on images

我通过重置图像的显示属性解决了我的问题


img {
display: unset !important;
}

apart from this little tweaks you will be good to go using both of them

除了这个小的调整,你会很好地使用这两个



There's no problem to use Tailwind CSS and Ant Design together.

同时使用TailWind CSS和Ant Design是没有问题的。


Tailwind CSS could be used to custom styling on Ant Design components.

顺风CSS可以用来定制Ant Design组件上的样式。


Check this link to see an example with Next, Ant Design and Tailwind CSS:

点击此链接,查看Next、Ant Design和TailWind CSS的示例:


https://github.com/plamworapot/next-antd-tailwindcss

Https://github.com/plamworapot/next-antd-tailwindcss



You can use Bootstrap with ant design right? Think Tailwind same as Bootstrap. Tailwind is a CSS library you can use it with any setup and framework there no extra configurations needed. Just pass the Tailwind class names.

您可以在蚂蚁设计中使用Bootstrap,对吗?认为尾风和Bootstrap是一样的。顺风是一个css库,你可以在任何设置和框架中使用它,不需要额外的配置。只需传递TailWind类名。


When it comes to theming. It's a context. Ant design will grab it's context and tailwind grab it's. We don't need to think or worry about it

当谈到主题时。这是一个背景。蚂蚁设计会抓住它的背景,顺风抓住它。我们不需要考虑或担心它



Well for me I needed to use tailwind to override the default ant design css styling so what I ended up doing was adding important:true to the tailwind config object (as per tailwind docs tailwind config docs for important config)

对我来说,我需要使用顺风来覆盖默认的Ant设计CSS样式,所以我最后做的是添加了重要的内容:对顺风配置对象的真(根据顺风文档,顺风配置文档中的重要配置)


module.exports = {
....,
important:true,
};

I know some people frown at using important (as do I) but I think this is one of the uses it was created for.

我知道有些人不喜欢使用重要(我也是),但我认为这是创建它的目的之一。



Use https://www.npmjs.com/package/antd-css-utilities

使用https://www.npmjs.com/package/antd-css-utilities


It was created to solve this specific problem. It includes most of the utility CSS inspired by Tailwind and Bootstrap. It also supports Intellisense

它是为了解决这个特定的问题而创建的。它包含了大部分受TailWind和Bootstrap启发的实用工具css。它还支持智能感知


更多回答

I did this but what if in future i want to have preflights for a specific page or pages, i mean i have an application which is in ant design and a landing page which i want it to be tailwind only and i need preflights for it.

我这样做了,但如果在未来我想要有一个或多个特定页面的飞行前检查,我的意思是,我有一个应用程序,这是蚂蚁设计和着陆页面,我希望它是顺风的,我需要它的飞行前检查。

I think you can use multiple config files as new feature in trailwindcss 3.2, I haven't tested yes but reach to docs you will have enough details there tailwindcss.com/blog/…

我认为你可以使用多个配置文件作为Trailwincs3.2中的新功能,我还没有测试过是的,但联系文档你会有足够的详细信息在tailwincss.com/Blog/…上

oh, i didn't know thank you, but i finally figured it out how to fix it using a trick: stackoverflow.com/questions/75124039/…

哦,我不知道谢谢,但我终于想出了一个诀窍来修复它:Stackoverflow.com/Questions/75124039/…

Cavalherio how do you manage the theme, with tailwinds or antd or both? and why?

Cavalherio你是如何管理主题的,是顺风还是顺风,还是两者兼而有之?为什么?

Thanks, There would be two options for Grid, which one is your choice and why?

谢谢,网格有两个选项,您选择哪一个?为什么?

I reckon bootstrap is similar to ant design, both provide prebuilt components. and Tailwind is like Css and just is a utility-first CSS framework without any components.

我认为Bootstrap类似于蚂蚁设计,都提供了预置组件。而TailWind就像是一个没有任何组件的实用程序优先的CSS框架。

My suggestions or personal recommendation is use Tailwind for the layouting. Like the Grid, Column, and Flex Which mean basic Layout usage. When it comes to a react based component feature like A data table that time use Ant deisgn. So if I tell it simply, For any thing that is require JS based feature you can use Ant for it. And when you need CSS feature use tailwind.

我的建议或个人建议是使用TailWind进行布局。比如Grid、Column和Flex,它们表示基本的布局用法。当涉及到基于Reaction的组件特性(如数据表)时,请使用Ant deisgn。因此,如果我简单地说,对于任何需要基于JS特性的东西,都可以使用Ant。当您需要css功能时,使用顺风功能。

A ant design data table has filtering and searching feature and Tailwind has supper flexibility in making anything responsive. So if you look closely both has their benefits. You just need to match your needs and use that one.

蚂蚁设计数据表具有过滤和搜索功能,尾风具有超强的灵活性,可以做出任何响应。因此,如果你仔细观察,两者都有各自的好处。你只需要匹配你的需求并使用它。

If you pass a class name that always have more power than the ant design class names. I think if you pass the tailwind class names in the ant design component that will override antd styles by tailwind. I will try it in a codesandbox and share with you sooner

如果您传递的类名总是比Ant设计类名更强大。我认为,如果您在Ant设计组件中传递顺风类名称,它将通过顺风覆盖antd样式。我会在密码箱里试一试,并尽快与你分享

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com