ant-design / antd-style Goto Github PK
View Code? Open in Web Editor NEWcss-in-js library with antd v5 token system
Home Page: https://ant-design.github.io/antd-style/
License: MIT License
css-in-js library with antd v5 token system
Home Page: https://ant-design.github.io/antd-style/
License: MIT License
使用antd的ConfigProvider包裹并切换主题, 没有使用ThemeProvider包裹,在使用createStyles的时候怎么获取当前antd的主题模式,
在createStyles里面的参数appearance一直都是light
@Keyframes、@media是什么样的写法。。
控制台输出:
cx(label): acss-17f3slo
styles.label: acss-1o3nxki-pages-Home-label
const useStyles = createStyles(({ css, cx }) => {
const label = css`
color: red;
`;
const box1 = css`
&:hover {
font-weight: 600;
.${cx(label)} {
color: green;
}
}
`;
const box2 = css`
&:hover {
font-weight: 600;
.${cx(label)} {
color: blue;
}
}
`;
console.log('cx(label):', cx(label));
return {
box1,
box2,
label,
};
});
const Home: React.FC = () => {
const { styles } = useStyles();
console.log('styles.label:', styles.label);
return (
<>
<div className={styles.box1}>
<span className={styles.label}>box1-lable</span>
</div>
<div className={styles.box2}>
<span className={styles.label}>box2-lable</span>
</div>
</>
);
};
支持使用 antd
的 style-provider
, 让用户自由指定css的插入位置。
https://github.com/ant-design/cssinjs#styleprovider
container | Tell cssinjs where to inject style in. | Element | ShadowRoot | document.head |
---|
可以从全局导入 cx
方法:
import { cx } from 'antd-style'
有些组件里面用到了全局的 原子类
但又不需要使用 createStyles
创建额外的样式
这样的话我就可以把 classnames
去掉让代码看着舒服一点
官网 文档
和 使用案例
的链接是错误的
import { createStyles, ThemeProvider } from 'antd-style';
const useStyles = createStyles(({ stylish, cx, css, token }) => {
return {
btn: {
color: 'red'
}
};
});
const App = () => {
const { styles } = useStyles();
return (
<div className={styles.btn}>
按钮
</div>
);
};
export default () => {
return (
<ThemeProvider>
<App />
</ThemeProvider>
);
};
umi4框架 & antd4
请问在Gatsby内如何使用ssr, 是否有类似emotion/ssr的api
gatsby-ssr.jsx
import * as React from "react";
import { renderToString } from "react-dom/server";
import { extractCritical } from "@emotion/server";
import { cache } from "@emotion/css";
import { CacheProvider } from "@emotion/react";
export const replaceRenderer = ({
replaceBodyHTMLString,
bodyComponent,
setHeadComponents,
}) => {
const { html, ids, css } = extractCritical(
renderToString(<CacheProvider value={cache}>{bodyComponent}</CacheProvider>)
);
setHeadComponents([
<style
key="emotion"
data-emotion={`css ${ids.join(" ")}`}
dangerouslySetInnerHTML={{
__html: css,
}}
/>,
]);
replaceBodyHTMLString(html);
};
rc
branch failed. 🚨I recommend you give this issue a high priority, so other packages depending on you can benefit from your bug fixes and new features again.
You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can fix this 💪.
Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.
Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the rc
branch. You can also manually restart the failed CI job that runs semantic-release.
If you are not sure how to resolve this, here are some links that can help you:
If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.
An npm token must be created and set in the NPM_TOKEN
environment variable on your CI environment.
Please make sure to create an npm token and to set it in the NPM_TOKEN
environment variable on your CI environment. The token must allow to publish to the registry https://registry.npmjs.org
.
Good luck with your project ✨
Your semantic-release bot 📦🚀
ERROR in ./node_modules/core-util-is/lib/util.js 86:0-52
Module not found: Error: Can't resolve 'buffer' in '/projects/node_modules/core-util-is/lib'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "buffer": require.resolve("buffer/") }'
- install 'buffer'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "buffer": false }
ERROR in ./node_modules/duplexer2/node_modules/safe-buffer/index.js 2:13-30
Module not found: Error: Can't resolve 'buffer' in '/projects/node_modules/duplexer2/node_modules/safe-buffer'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "buffer": require.resolve("buffer/") }'
- install 'buffer'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "buffer": false }
ERROR in ./node_modules/multipipe/index.js 6:18-47
Module not found: Error: Can't resolve 'stream' in '/projects/node_modules/multipipe'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "stream": require.resolve("stream-browserify") }'
- install 'stream-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "stream": false }
ERROR in ./node_modules/readable-stream/lib/_stream_readable.js 29:13-37
Module not found: Error: Can't resolve 'buffer' in '/projects/node_modules/readable-stream/lib'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "buffer": require.resolve("buffer/") }'
- install 'buffer'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "buffer": false }
ERROR in ./node_modules/readable-stream/lib/_stream_readable.js 41:13-30
Module not found: Error: Can't resolve 'stream' in '/projects/node_modules/readable-stream/lib'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "stream": require.resolve("stream-browserify") }'
- install 'stream-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "stream": false }
ERROR in ./node_modules/readable-stream/lib/_stream_writable.js 29:13-37
Module not found: Error: Can't resolve 'buffer' in '/projects/node_modules/readable-stream/lib'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "buffer": require.resolve("buffer/") }'
- install 'buffer'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "buffer": false }
ERROR in ./node_modules/readable-stream/lib/_stream_writable.js 39:13-30
Module not found: Error: Can't resolve 'stream' in '/projects/node_modules/readable-stream/lib'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "stream": require.resolve("stream-browserify") }'
- install 'stream-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "stream": false }
ERROR in ./node_modules/readable-stream/readable.js 1:13-30
Module not found: Error: Can't resolve 'stream' in '/projects/node_modules/readable-stream'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "stream": require.resolve("stream-browserify") }'
- install 'stream-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "stream": false }
ERROR in ./node_modules/readable-stream/readable.js 10:2-36
Module not found: Error: Can't resolve 'stream' in '/projects/node_modules/readable-stream'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "stream": require.resolve("stream-browserify") }'
- install 'stream-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "stream": false }
ERROR in ./node_modules/string_decoder/index.js 22:13-37
Module not found: Error: Can't resolve 'buffer' in '/projects/node_modules/string_decoder'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "buffer": require.resolve("buffer/") }'
- install 'buffer'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "buffer": false }
ERROR in ./node_modules/through/index.js 1:13-30
Module not found: Error: Can't resolve 'stream' in '/projects/node_modules/through'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "stream": require.resolve("stream-browserify") }'
- install 'stream-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "stream": false }
添加antd-style就会报错,移除就恢复正常
有就覆盖,没有就使用默认
通过ThemeProvider传入customToken,内容为compValue为50,在ASDiv组件内,通过createStyles创建useStyles,而函数参数token内,获取的token['compValue']有时候为空。下面有截图
import React from 'react';
import ASDiv from '@/components/ASDiv';
import { ThemeProvider } from 'antd-style';
export default () => {
return (
<>
<ThemeProvider customToken={{ 'compValue': 50 }}>
<ASDiv/>
</ThemeProvider>
<hr />
<ASDiv/>
</>
);
};
import React from 'react';
import { createStyles } from 'antd-style';
const useStyles = createStyles(({css, token}) => {
console.log('token', token['compValue']);
return {
myFont: css`
height: var(--custom-height, 32px);
font-size: var(--custom-font, 32px);
`
}
});
interface IProps {
}
const ASDiv: React.FC<IProps> = () => {
const {styles } = useStyles();
return (
<div className={styles.myFont}>
myFont
</div>);
};
export default ASDiv;
const useStyles = createStyles(({ token }) => ({
resizeHandleOuter: {
position: 'relative',
flex: 1,
marginInline: token.paddingMD,
backgroundColor: token.colorBgLayout,
borderRadius: token.borderRadius,
transition: 'background-color .2s linear',
[`&[data-resize-handle-active]`]: {
backgroundColor: token.colorFill
}
},
icon: {
position: 'absolute',
width: '1em',
height: '1em',
left: 'calc(50% - 0.5rem)',
top: 'calc(50% - 0.5rem)',
color: token.colorTextQuaternary,
fontSize: token.fontSize
}
}))
我怎么实现 resizeHandleOuter
active 时改变 icon
的样式:
[`&[data-resize-handle-active]`]: {
backgroundColor: token.colorFill,
// 这里怎么写呢,还是只能单独用一个 className?
[`& .icon`]: {
color: 'red'
}
}
我在实现明暗模式切换的时候,看文档里面appearance
和themeMode
这两个都可以做到,想问一下这两个属性是有什么区别吗?否则为什么要单独分开?
仓库没有锁版本,CI里自动安装的依赖都是最新的,ant deisign在5.8.0版本的一个改动,把config-provider/context里export出来的MappingAlgorithm这个类型给干掉了,导致lint一直跑不过
具体PR见 https://github.com/ant-design/ant-design/pull/43810/files
lint可以跑过,锁版本
删掉依赖重新装一次,跑一下pnpm run ci就能复现
appearance 和 themeMode 有什么不同吗?为什么不要一个设置就好,什么时候该用 appearance 什么时候该用 themeMode ,感觉全用 themeMode 也可以满足所有场景?
vite 构建报错:
Failed to resolve import "@ant-design/cssinjs" from "..\..\node_modules\.pnpm\[email protected]_gvtcr5js3etfbgihn2dqh7o57u\node_modules\antd-style\es\index.js". Does the file exist?
13:45:18 [vite] Internal server error: Failed to resolve import "@ant-design/cssinjs" from "..\..\node_modules\.pnpm\[email protected]_gvtcr5js3etfbgihn2dqh7o57u\node_modules\antd-style\es\index.js". Does the file exist?
@ant-design/cssinjs
对用户来讲不应该是透明的吗?
写了一段测试代码, 但是为什么字没有变红?
import React, { useEffect, useRef, useState } from 'react'
import { Layout, Menu, Button } from 'antd';
// style
import { createStyles, css } from 'antd-style'
const useStyles = createStyles({
head: css`
color: 'red';
`
})
// style
const { Content, Sider, Header } = Layout;
export default function MyLayout() {
const { styles } = useStyles();
return (
<Layout>
<Layout>
<Sider theme='light'>
aaaaa
</Sider>
<Layout>
<div ><b className={styles.head} >123</b></div>
<Content style={{minHeight: '100%', backgroundColor: '#fff'}}>
<Button type="primary">11</Button>
</Content>
</Layout>
</Layout>
</Layout>
)
}
css:not(:last-child): { }
当我写完一个样式,我去dom节点查找的时候,无法精准的知道样式加在那个元素上了。全部都是class=“ant-css-XXXX”
https://ant-design-antd-style-preview-pr-7.surge.sh/api/create-stylish 简介的第二段 "又会有很多重复的代码,一但
设计师要求统一调整设计风格"
中的但
应为旦
StyleProvider的container属性不起作用,主要是iframe中使用组件的场景样式会丢失的问题
1、使用createInstance创建新的样式实例
2、样式实例的API做一个组件,然后用StyleProvider包裹这个组件,并指定container为document.body
组件对应的style标签被插入到document.body中,但是实际上仍然在head中
使用react-router v6,路由用的懒加载,第一次/about切到/user就会闪动,再来回切正常。这个你知道有解决方案吗?
从代码中看出,主题只支持系统 暗黑和亮色的 假如我想增加紧凑主题是没办法实现的 我想暗黑和紧凑一起使用
是否可以开放algorithm参数给使用者自行增加
Any chance of using this library with class components?
I tried to make HOC that passes useStyle hook properties to the class component, but now it's not possible to pass classname like className={styles.name}
because antd-style generates random class name.
迁移过程中 less语法中使用到的 :global 怎么处理,之前有部分场景需要通过:global 去覆盖组件样式,迁移过程中这部分代码如何处理。
:global(.ant-btn-link) {
padding: 0px;
font-size: 12px;
}
antd4 & umi4
...
针对使用 cssinjs 完全新写的组件,我们建议仍然使用 { hashPriority: 'high' } 配置。并将所有样式实现放置在 css 中,有需要的部分再额外添加 className。这样有两点好处:
...
这句话怎么理解?
现在 ant-design-vue 也已经跟上v5的版本了, 希望支持一下vue
无
无
样式权重会被antd样式覆盖,有相关权重提升方案吗?
感觉可以 antd-style 开放 context ,context 上增加 set 方法
umijs/umi#11142 (reply in thread)
This change breaks ThemeProvider
rendering.
It makes perfect sense, since ReactNode
cannot be returned byReact.FC
安装依赖时提示:
pnpm add antd-style@beta -w
Packages: +41
+++++++++++++++++++++++++++++++++++++++++
Progress: resolved 276, reused 264, downloaded 12, added 25, done
dependencies:
+ antd-style 3.0.0-beta.8
WARN Issues with peer dependencies found
.
└─┬ antd-style 3.0.0-beta.8
└─┬ use-merge-value 1.0.2
└── ✕ unmet peer [email protected]: found 18.2.0
业务开发,基于antd的二次开发,message、modal需要重写样式,如何通过antd-style去进行样式覆盖呢?
antd-style会像@ant-design/cssinjs一样带来更好的性能吗
class变量 嵌套生成的css会合并成一个class
.button-wrapper {
margin-top: 24px;
${buttonClass} {
font-size: 20px;
}
}
buttonClass 的 样式 会合并到 .button-wrapper里
const useStyles = createStyles(({ css }) => {
const buttonClass = css`
background-color: #3498db;
border: none;
border-radius: 4px;
color: #fff;
cursor: pointer;
font-size: 16px;
padding: 12px 24px;
&:hover {
background-color: #2980b9;
}
`
const containerClass = css`
display: flex;
flex-direction: column;
align-items: center;
.button-wrapper {
margin-top: 24px;
${buttonClass} {
font-size: 20px;
}
}
`
return {
buttonClass,
containerClass,
}
})
function MyComponent() {
const { styles } = useStyles()
return (
<div className={styles.containerClass}>
<p>Some content here</p>
<div className="button-wrapper">
<button className={styles.buttonClass}>Click me</button>
</div>
</div>
);
}
使用createInstance创建的styleProvider的props类型不对
import { legacyLogicalPropertiesTransformer } from "@ant-design/cssinjs";
<StyleProvider transformers={[legacyLogicalPropertiesTransformer]}}></StyleProvider>
不会提示类型错误
1、同时定义ThemeProvider的customToken,内容为a="ThemeProvider.custom"。
2、组件内部定义通过createInstance定义了customToken,内容为a="createInstance.custom"
3、组件在使用时
3.1 如果外部没有包ThemeProvider的话,在组件中createStyles里面获取到的a内容为a="createInstance.custom"。
3.2 如果外部有包ThemeProvider的话,在组件中createStyles里面获取到的a内容为a="ThemeProvider.custom"。
3.3 如果外部有包ThemeProvider的话,但ThemeProvider没有传递a="ThemeProvider.custom",则在组件中createStyles里面获取到的a内容为undefined,请问ThemeProvider的customToken和组件内容的createInstance里面的customToken可以融合吗?这样看起来是互斥的。
export default () => {
return (
<>
<ThemeProvider customToken={{ 'a': 'ThemeProvider.custom' }}>
<ASDiv/>
</ThemeProvider>
<hr />
</>
);
};
interface LogoListToken {
}
const { createStyles } = createInstance<LogoListToken>({
customToken: {
'a': 'createInstance.custom',
},
});
const useStyles = createStyles(({css, cx, token}) => {
console.log('a', token['a']);
return {
container: css`
height: 300px;
`
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.