我想改变 react-datepicker 的风格:
1.修改输入框为自定义样式
2.更改日历的样式和语言
我看到一篇帖子(关于 datepicker 的自定义输入字段,[react-datepicker 组件] https://github.com/Hacker0x01/react-datepicker/blob/master/docs/datepicker.md)谈论替换整个组件。我可以直接编辑样式而不编写新组件吗?如果是,我怎样才能做到这一点?此外,我不知道如何更改日历。如何找出我应该更改哪个组件?
import React, {Component} from 'react';
import {render} from 'react-dom';
import moment from 'moment';
import DatePicker from 'react-datepicker';
import 'react-datepicker/dist/react-datepicker.css';
const Input = ({onChange, placeholder, value, isSecure, id, onClick}) => (
<input
style={{backgroundColor:"black"}}
onChange={onChange}
placeholder={placeholder}
value={value}
isSecure={isSecure}
id={id}
onClick={onClick}
/>
);
const NoClickInput = ({onClick, ...props}) => <Input {...props} />;
class App extends Component {
state = {
startDate: moment(),
endDate: moment()
};
render() {
const {startDate, endDate} = this.state;
return (
<div>
<div>Start:</div>
<DatePicker
selected={startDate}
selectsStart
startDate={startDate}
endDate={endDate}
onChange={date=>this.setState({startDate})}
/>
<div>End:</div>
<DatePicker
selected={endDate}
selectsEnd
startDate={startDate}
endDate={endDate}
onChange={date => this.setState({ endDate })}
/>
</div>
);
}
}
render(<App />, document.getElementById('root'));