Skip to content

removed css-modules dependency. #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,3 @@ const MyComponent = () => (
```

For more examples [take a look at here](https://github.com/evandhq/react-persian-datepicker/blob/master/examples/src/components/App.js#L43).

Note that you need `css-loader` for `/\.css$/` files enabled to have the styles working as we use css modules to put classnames in place. Otherwise, you'll have to pass an object of class names (like a css module) as `styles` prop. This way, you can develop your own stylesheet for the calendar according to the [basic one](https://github.com/evandhq/react-persian-datepicker/blob/master/src/styles/basic.css). The only thing that you will need to do is to require the css file that you made and pass it as `styles` prop to either `Calendar` or `DatePicker`.
3 changes: 2 additions & 1 deletion src/components/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Day from './Day';
import { getDaysOfMonth } from '../utils/moment-helper';
import moment from 'moment-jalali';
import onClickOutside from 'react-onclickoutside';
import { defaultStyles } from './DefaultStyles';

// Load Persian localisation
moment.loadPersian();
Expand All @@ -30,7 +31,7 @@ export class Calendar extends Component {
};

static defaultProps = {
styles: require('../styles/basic.css'),
styles: { ...defaultStyles, ...require('../styles/basic.css') },
containerProps: {}
};

Expand Down
25 changes: 14 additions & 11 deletions src/components/DatePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ export default class DatePicker extends Component {
inputFormat: PropTypes.string,
removable: PropTypes.bool,
timePickerComponent: PropTypes.func,
styles: PropTypes.object,
calendarStyles: PropTypes.object,
calendarContainerProps: PropTypes.object
};

static defaultProps = {
inputFormat: 'jYYYY/jM/jD',
styles: require('../styles/basic.css'),
calendarStyles: require('../styles/basic.css'),
calendarContainerProps: {}
};
Expand Down Expand Up @@ -129,10 +131,10 @@ export default class DatePicker extends Component {
className={className}
type="text"
ref="input"
onFocus={this.handleFocus.bind(this) }
onBlur={this.handleBlur.bind(this) }
onChange={this.handleInputChange.bind(this) }
onClick={this.handleInputClick.bind(this) }
onFocus={this.handleFocus.bind(this)}
onBlur={this.handleBlur.bind(this)}
onChange={this.handleInputChange.bind(this)}
onClick={this.handleInputClick.bind(this)}
value={inputValue}
/>
</div>
Expand All @@ -142,6 +144,7 @@ export default class DatePicker extends Component {
renderCalendar() {
const { momentValue } = this.state;
const { timePickerComponent: TimePicker, onChange, min, max, defaultMonth, calendarStyles, calendarContainerProps } = this.props;
const styles = this.props.styles || calendarStyles;

return (
<div>
Expand All @@ -150,10 +153,10 @@ export default class DatePicker extends Component {
max={max}
selectedDay={momentValue}
defaultMonth={defaultMonth}
onSelect={this.handleSelectDay.bind(this) }
onClickOutside={this.handleClickOutsideCalendar.bind(this) }
onSelect={this.handleSelectDay.bind(this)}
onClickOutside={this.handleClickOutsideCalendar.bind(this)}
outsideClickIgnoreClass={outsideClickIgnoreClass}
styles={calendarStyles}
styles={styles}
containerProps={calendarContainerProps}
>
{
Expand All @@ -162,7 +165,7 @@ export default class DatePicker extends Component {
min={min}
max={max}
momentValue={momentValue}
setMomentValue={this.setMomentValue.bind(this) }
setMomentValue={this.setMomentValue.bind(this)}
/>
) : null
}
Expand All @@ -172,7 +175,7 @@ export default class DatePicker extends Component {
}

removeDate() {
const {onChange} = this.props;
const { onChange } = this.props;
if (onChange) {
onChange('');
}
Expand All @@ -187,8 +190,8 @@ export default class DatePicker extends Component {

return (
<TetherComponent attachment="top center">
{ this.renderInput() }
{ isOpen ? this.renderCalendar() : null }
{this.renderInput()}
{isOpen ? this.renderCalendar() : null}
</TetherComponent>
);
}
Expand Down
13 changes: 13 additions & 0 deletions src/components/DefaultStyles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export const defaultStyles = {
calendarContainer: 'calendarContainer',
heading: 'heading',
prev: 'prev',
next: 'next',
title: 'title',
dayWrapper: 'dayWrapper',
currentMonth: 'currentMonth',
daysOfWeek: 'daysOfWeek',
monthsList: 'monthsList',
selected: 'selected',
dayPickerContainer: 'dayPickerContainer'
};