Skip to content
This repository was archived by the owner on May 19, 2025. It is now read-only.

Commit 015e05f

Browse files
committed
Add capability to override weekStartsOn setting of locales
1 parent dd3188c commit 015e05f

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

src/components/Calendar/index.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ class Calendar extends PureComponent {
4444
this.estimateMonthSize = this.estimateMonthSize.bind(this);
4545
this.handleScroll = this.handleScroll.bind(this);
4646
this.dateOptions = { locale: props.locale };
47+
if (this.props.weekStartsOn !== undefined)
48+
this.dateOptions.weekStartsOn = this.props.weekStartsOn;
4749
this.styles = generateStyles([coreStyles, props.classNames]);
4850
this.listSizeCache = {};
4951
this.isFirstRender = true;
@@ -127,18 +129,25 @@ class Calendar extends PureComponent {
127129
date: 'date',
128130
};
129131
const targetProp = propMapper[this.props.displayMode];
130-
if (prevProps.locale !== this.props.locale) {
132+
if (this.props[targetProp] !== prevProps[targetProp]) {
133+
this.updateShownDate(this.props);
134+
}
135+
136+
if (
137+
prevProps.locale !== this.props.locale ||
138+
prevProps.weekStartsOn !== this.props.weekStartsOn
139+
) {
131140
this.dateOptions = { locale: this.props.locale };
141+
if (this.props.weekStartsOn !== undefined)
142+
this.dateOptions.weekStartsOn = this.props.weekStartsOn;
132143
this.setState({
133144
monthNames: [...Array(12).keys()].map(i => this.props.locale.localize.month(i)),
134145
});
135146
}
147+
136148
if (JSON.stringify(prevProps.scroll) !== JSON.stringify(this.props.scroll)) {
137149
this.setState({ scrollArea: this.calcScrollArea(this.props) });
138150
}
139-
if (this.props[targetProp] !== prevProps[targetProp]) {
140-
this.updateShownDate(this.props);
141-
}
142151
}
143152

144153
changeShownDate(value, mode = 'set') {
@@ -544,6 +553,7 @@ Calendar.propTypes = {
544553
dateDisplayFormat: PropTypes.string,
545554
monthDisplayFormat: PropTypes.string,
546555
weekdayDisplayFormat: PropTypes.string,
556+
weekStartsOn: PropTypes.number,
547557
dayDisplayFormat: PropTypes.string,
548558
focusedRange: PropTypes.arrayOf(PropTypes.number),
549559
initialFocusedRange: PropTypes.arrayOf(PropTypes.number),

src/components/DateRange/README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1-
#### Example: Editable Date Inputs
1+
This component extends all the props of **[Calendar](#calendar)** component. In addition to those props, it has the following props:
2+
3+
| Prop Name | Type |
4+
|---|---|
5+
| **moveRangeOnFirstSelection** | boolean |
6+
| **onRangeFocusChange** | function |
7+
| **rangeColors** | array |
8+
| **ranges** | array |
29

10+
11+
#### Example: Editable Date Inputs
312
```jsx inside Markdown
413
import {useState} from 'react'
514
const [state, setState] = useState([

src/components/DateRangePicker/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
This component wraps **[DefinedRange](#definedrange)** and **[Calendar](#calendar)** components together, and extends all the props of them.
2+
13
#### Example: 2 Month View
24

35
```jsx inside Markdown

styleguide.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ module.exports = {
109109
},
110110
{
111111
components: () => ['src/components/DateRange/index.js'],
112+
usageMode: 'hide',
112113
},
113114
{
114115
components: () => ['src/components/Calendar/index.js'],

0 commit comments

Comments
 (0)