Skip to content

Commit

Permalink
Add capability to override weekStartsOn setting of locales
Browse files Browse the repository at this point in the history
  • Loading branch information
onurkerimov committed Jan 10, 2020
1 parent dd3188c commit 015e05f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
18 changes: 14 additions & 4 deletions src/components/Calendar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class Calendar extends PureComponent {
this.estimateMonthSize = this.estimateMonthSize.bind(this);
this.handleScroll = this.handleScroll.bind(this);
this.dateOptions = { locale: props.locale };
if (this.props.weekStartsOn !== undefined)
this.dateOptions.weekStartsOn = this.props.weekStartsOn;
this.styles = generateStyles([coreStyles, props.classNames]);
this.listSizeCache = {};
this.isFirstRender = true;
Expand Down Expand Up @@ -127,18 +129,25 @@ class Calendar extends PureComponent {
date: 'date',
};
const targetProp = propMapper[this.props.displayMode];
if (prevProps.locale !== this.props.locale) {
if (this.props[targetProp] !== prevProps[targetProp]) {
this.updateShownDate(this.props);
}

if (
prevProps.locale !== this.props.locale ||
prevProps.weekStartsOn !== this.props.weekStartsOn
) {
this.dateOptions = { locale: this.props.locale };
if (this.props.weekStartsOn !== undefined)
this.dateOptions.weekStartsOn = this.props.weekStartsOn;
this.setState({
monthNames: [...Array(12).keys()].map(i => this.props.locale.localize.month(i)),
});
}

if (JSON.stringify(prevProps.scroll) !== JSON.stringify(this.props.scroll)) {
this.setState({ scrollArea: this.calcScrollArea(this.props) });
}
if (this.props[targetProp] !== prevProps[targetProp]) {
this.updateShownDate(this.props);
}
}

changeShownDate(value, mode = 'set') {
Expand Down Expand Up @@ -544,6 +553,7 @@ Calendar.propTypes = {
dateDisplayFormat: PropTypes.string,
monthDisplayFormat: PropTypes.string,
weekdayDisplayFormat: PropTypes.string,
weekStartsOn: PropTypes.number,
dayDisplayFormat: PropTypes.string,
focusedRange: PropTypes.arrayOf(PropTypes.number),
initialFocusedRange: PropTypes.arrayOf(PropTypes.number),
Expand Down
11 changes: 10 additions & 1 deletion src/components/DateRange/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
#### Example: Editable Date Inputs
This component extends all the props of **[Calendar](#calendar)** component. In addition to those props, it has the following props:

| Prop Name | Type |
|---|---|
| **moveRangeOnFirstSelection** | boolean |
| **onRangeFocusChange** | function |
| **rangeColors** | array |
| **ranges** | array |


#### Example: Editable Date Inputs
```jsx inside Markdown
import {useState} from 'react'
const [state, setState] = useState([
Expand Down
2 changes: 2 additions & 0 deletions src/components/DateRangePicker/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
This component wraps **[DefinedRange](#definedrange)** and **[Calendar](#calendar)** components together, and extends all the props of them.

#### Example: 2 Month View

```jsx inside Markdown
Expand Down
1 change: 1 addition & 0 deletions styleguide.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ module.exports = {
},
{
components: () => ['src/components/DateRange/index.js'],
usageMode: 'hide',
},
{
components: () => ['src/components/Calendar/index.js'],
Expand Down

0 comments on commit 015e05f

Please sign in to comment.