ant-design / antd-style

css-in-js library with antd v5 token system
https://ant-design.github.io/antd-style/
MIT License
189 stars 29 forks source link

👑 [需求] 支持 container 配置 #46

Closed IamFive closed 1 year ago

IamFive commented 1 year ago

🥰 需求描述

支持使用 antdstyle-provider , 让用户自由指定css的插入位置。

https://github.com/ant-design/cssinjs#styleprovider

🧐 解决方案

  1. 支持使用 https://github.com/ant-design/cssinjs#styleprovider 的container属性
container | Tell cssinjs where to inject style in. | Element \| ShadowRoot | document.head -- | -- | -- | -- 2. emotion itself supports container too, so, explore the emotion API to user can fix this issue too.

🚑 其他信息

taiyangzaitianshang commented 1 year ago

有个相似的问题,不知是不是用的不对。使用antd-style在基于 antd 二次封装的组件库时,使用了createInstance这个API,并使用这个API返回对象中的StyleProvider去指定container,但是没有生效

<StyleProvider container={document.body}>
      <MyComponent></MyComponent>
    </StyleProvider>
github-actions[bot] commented 1 year ago

:tada: This issue has been resolved in version 3.0.1-beta.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

arvinxx commented 1 year ago

@IamFive 试试上面这个版本

IamFive commented 1 year ago

@IamFive 试试上面这个版本

  1. antd 的 style 现在可以正常插入到指定的container中了。
  2. antd-style 生成的css还是插入到了host page的document.head中。

我使用的代码如下:

import { extractStaticStyle, StyleProvider as AntdStyleProvider } from "antd-style";
  const app = (
    // <React.StrictMode>
    <ConfigProvider
      getPopupContainer={() => popupContainer}
      theme={{
        token: {
          colorPrimary: "#00b96b",
        },
        // algorithm: theme.compactAlgorithm,
      }}
    >
      <AntdStyleProvider container={head}>
      {/* <StyleProvider container={head}> */}
        <style type="text/css">{sanitize}</style>
        <style type="text/css">{a1}</style>
        <style type="text/css">{a2}</style>
        <style type="text/css">{c1}</style>
        <style type="text/css">{md2}</style>
        <style type="text/css">{md3}</style>
        <style type="text/css">{md1}</style>
        <style type="text/css">{compose}</style>
        <AppLauncher />
      {/* </StyleProvider> */}
      </AntdStyleProvider>
    </ConfigProvider>
    // </React.StrictMode>
  );
arvinxx commented 1 year ago

好像是还有点问题,我再修下

arvinxx commented 1 year ago

与 #47 重复,合并到 #47 中讨论,这个先关了

github-actions[bot] commented 1 year ago

:tada: This issue has been resolved in version 3.1.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: