-
-
Notifications
You must be signed in to change notification settings - Fork 46.7k
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
Remove global Styles #9363
Comments
You can also try using components directly from https://github.com/react-component. |
Please address this. It's a hard blocker for our app. |
Hi, have you guys given thoughts about using a CSS-in-JS library like emotion or styled-components. It could solve lot of problems like global import for styles and scoping the styles to the ant components. Plus it could also improve theming (dynamic styles). Apologies if this has been discussed somewhere else, I couldn't find relevant discussion(s). |
@divyanshu013 I think I read it's not a top priority for them as antd is meant to include the antd style specification not just the components/javascript. Plus, this is technically mean to be a monorepo for their internal projects, so themeing for other people's brands is automatically not a top priority. That said, I'm with you, I wish it used styled-components over global styles. https://spectrum.chat/thread/ca82a625-134f-49df-9900-1b0b6342e037 |
Ok, I must admit I haven't looked at antd's less file structure that deeply, so maybe someone can shed some light on this: How big an offence is it to simply include only the component's less file? E.g. do something like import { Select } from 'antd'; Based on a quick test, it seems to work, so that made me curious... |
This is related to being able to import styles for individual components. If the styles for components were self-contained then people could opt-in or opt-out of the global reset/styles. Situation right now:
How could we make the components self contained in a non-breaking way? I think one solution could be to use Storybook to setup some isolated visual regression tests. You could generate snapshots with global styles included, then remove the global styles, and add in styles in the component less files until the tests pass, ensuring that the style is the same with or without the global styles. |
Apologies for creating a semi-duplicate issue. To consolidate conversation, I'll re-ask my somewhat different questions here.
One approach (thanks @DylanVann):
Is Ant open to:
|
Any update? |
This comment has been minimized.
This comment has been minimized.
Nice find! Are there more complex component that depend on more than one |
I do it in the same way as @fedebabrauskas, and everything seems to be working well. |
@fedebabrauskas It seems like the animation for the component would not be enabled (I tried Popover, the styles are fine but it has no animation) |
|
@phibersoft |
On Mon, Oct 11, 2021 at 19:44 WebBrother ***@***.***> wrote:
@phibersoft <https://github.com/phibersoft>
As far as I understand your idea you exclude global.less from import. Am
I right?
If so, do you have any issues with that global style, and how do you solve
them?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#9363 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ATD5G5FIWV5BXN3SMXS4D5TUGMEO5ANCNFSM4EQZ37SQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
no i just added css for my date-picker import antd/lib/time-picker/style/css
and based on that i change css for date-picker classNames in my css file
|
Another option with webpack: {
test: /\.jsx$/,
use: {
loader: 'babel-loader',
options: {
plugins: [
[
'import',
{
libraryName: 'antd',
libraryDirectory: 'es',
// `name` argument looks like `{libraryName}/{libraryDirectory}/{componentName}`
style: (name: string) => {
// exclude components without index.css file, e.g. `col` and `row` from `table`
return ['antd/es/row', 'antd/es/col'].includes(name)
? false
: `${name}/style/index.css`;
},
},
],
],
},
},
} You need to import More info in plugin docs. |
So I ran into this same issue
But after making the build, I found |
There needs to be a bundled option in |
After hours of research and testing, I've finally found a solution that works. I tried both the Added the following to my
Folder structure:
Contents of #antd {
@import '~antd/es/style/core/index.less';
@import '~antd/es/style/themes/default.less';
} NOTE: this is a solution for Webpack 5. |
I also faced this problem.Can you share the modified antd file please?Thank you ,my email is 876530150@qq.com |
I'm not sure if there are any side effects. but i solved it like this;
const fs = require('fs')
fs.writeFileSync(require.resolve('antd/es/style/core/global.less'), '')
fs.writeFileSync(require.resolve('antd/lib/style/core/global.less'), '') |
Can you show me the whole craco.config.js? |
Is there an official fix for it? I have created a content-script in my chrome extension that is making changes to the dom, the antd import statement is affecting the global styles. |
Is there an official fix for it? |
I have created a simple less plugin to solve this issue: less-plugin-remove-antd-global-styles. It works by mapping the global.less into an empty file. It works well with vite, webpack, rollup and babel-plugin-import. // webpack.config.js
const { LessPluginRemoveAntdGlobalStyles } = require('less-plugin-remove-antd-global-styles');
module.exports = {
...
{
loader: 'less-loader',
options: {
lessOptions: {
plugins: [
new LessPluginRemoveAntdGlobalStyles(),
],
},
},
},
...
}; Checkout its README for more usage. |
Can we close this issue with the release of Ant 5? If not, what needs to be done? 🎉 |
这两种写法都可以 下面的替换成一个新建的空文件即可
|
I wonder how this problem was solved. (any related PR?) |
thanks alot, that plugin saved my day |
Version
3.2.1
Environment
Any
Reproduction link
https://codesandbox.io/s/jnw46698m3
Steps to reproduce
1- Import an antd component
2- Observe global styles (h1,h6, selector, ect...)
What is expected?
Component style to be scoped and not affect the rest of the application.
What is actually happening?
When component is imported the entire HTML application (even outside of React) is styled.
This is a response to issue #9362 & #4331
The text was updated successfully, but these errors were encountered: