首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PrimeReact和样式组件

PrimeReact和样式组件
EN

Stack Overflow用户
提问于 2017-09-18 10:48:54
回答 2查看 5.2K关注 0票数 7

我似乎不能用样式组件来设计PrimeReact组件。

给定下面的代码来呈现一个InputText,我的意图是改变它的宽度。但不起作用。

代码语言:javascript
复制
import styled from "styled-components";
import {InputText} from 'primereact/components/inputtext/InputText';

class Component extends React.Component {
    render() {
        return (
            <InputText/>
        )
}

const ComponentView = styled(Component)`
    .ui-inputtext {
        width: 1000px;
    }
`;
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-09-18 13:37:11

styled-components生成一个应该传递给组件的className

代码语言:javascript
复制
import styled from "styled-components";
import {InputText} from 'primereact/components/inputtext/InputText';

class Component extends React.Component {
    render() {
        return (
            <InputText className={this.props.className} /> <---- here
        )
}

const ComponentView = styled(Component)`
    .ui-inputtext {
        width: 1000px;
    }
`;

如果InputText不接受className,您可以简单地用另一个组件包装它:

代码语言:javascript
复制
import styled from "styled-components";
import {InputText} from 'primereact/components/inputtext/InputText';

class Component extends React.Component {
    render() {
        return (
            <div className={this.props.className}> <---- here
                <InputText />
            </div>
        )
}

const ComponentView = styled(Component)`
    .ui-inputtext {
        width: 1000px;
    }
`;
票数 3
EN

Stack Overflow用户

发布于 2018-09-07 18:54:03

PrimeReact有许多应用于单独的sass样式表的样式,通常结合多个类名和html标记。

为了让你的风格获胜,你需要更多的CSS特性。

解决方案是使用嵌套选择器,如下所示:

代码语言:javascript
复制
const ComponentView = styled(Component)`
&&& {
    width: 1000px;
}`

这将生成3个相同的类名,这是样式组件文档推荐的。需要更多的类名专用性吗?使用更多的&

或者你可以放一个!important。我见过这个。

或者编辑他们的sass文件

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46277433

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档