利用styled-component修改Ant Design 樣式


如果你搜索了這個問題,肯定也遇到了和我一樣的困惑,又想用Ant Design的組件,有些樣式自己又想使用styled-component修改,標簽名沖突怎么辦? 直接上代碼把....

import React from 'react';
import { Input, Button, List } from 'antd'; 
import { btnStyle, inputStyle, listStyle } from './style'

const TodoListUI = (props) => {
    return (
        <div style={{ margin: '20px' }}>
            <Input style={inputStyle}value={props.inputValue} onChange={props.handleInputChange} />
            <Button style={btnStyle}type="danger" onClick={props.handleBtnClick}>提交</Button>
            <List style={listStyle}bordered dataSource={props.list}
                renderItem={
                    (item, index) => <List.Item onClick={() => { props.handleItemDelete(index) }}>{item}</List.Item>}
            />
        </div>
    )
}
export default TodoListUI;

style.js (就是寫css代碼的文件)

import  styled  from 'styled-components';

export const btnStyle = {
  background:'pink'
}
export const inputStyle={
    width:'300px',
    margin:'20px',
}
export const listStyle={
    width:'300px',
    margin:'20px',
}

現在大概知道怎么用了吧。在style.js文件里直接定義好你需要自定義的css代碼,在UI組件里直接引入即可修改antd的原有樣式。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM