-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui,ui-date-input): add new DateInput2 component
- Loading branch information
Showing
12 changed files
with
658 additions
and
11 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,205 @@ | ||
--- | ||
describes: DateInput | ||
--- | ||
|
||
This component is an updated version of [`DateInput`](/#DateInput) that's easier to configure for developers and use for end users. It has better accessibility and a year picker option. We recommend using this one instead and in our next major release (v10) it will replace `DateInput`. | ||
|
||
### Minimal config | ||
|
||
- ```js | ||
class Example extends React.Component { | ||
state = { value: '' } | ||
|
||
render() { | ||
return ( | ||
<DateInput2 | ||
renderLabel="Choose a date" | ||
screenReaderLabels={{ | ||
calendarIcon: 'Calendar', | ||
nextMonthButton: 'Next month', | ||
prevMonthButton: 'Previous month' | ||
}} | ||
value={this.state.value} | ||
width="20rem" | ||
onChange={(e, value) => this.setState({ value })} | ||
invalidDateErrorMessage="Invalid date" | ||
/> | ||
) | ||
} | ||
} | ||
|
||
render(<Example />) | ||
``` | ||
|
||
- ```js | ||
const Example = () => { | ||
const [value, setValue] = useState('') | ||
return ( | ||
<DateInput2 | ||
renderLabel="Choose a date" | ||
screenReaderLabels={{ | ||
calendarIcon: 'Calendar', | ||
nextMonthButton: 'Next month', | ||
prevMonthButton: 'Previous month' | ||
}} | ||
value={value} | ||
width="20rem" | ||
onChange={(e, value) => setValue(value)} | ||
invalidDateErrorMessage="Invalid date" | ||
/> | ||
) | ||
} | ||
|
||
render(<Example />) | ||
``` | ||
|
||
### With year picker | ||
|
||
- ```js | ||
class Example extends React.Component { | ||
state = { value: '' } | ||
|
||
render() { | ||
return ( | ||
<DateInput2 | ||
renderLabel="Choose a date" | ||
screenReaderLabels={{ | ||
calendarIcon: 'Calendar', | ||
nextMonthButton: 'Next month', | ||
prevMonthButton: 'Previous month' | ||
}} | ||
width="20rem" | ||
value={this.state.value} | ||
onChange={(e, value) => this.setState({ value })} | ||
invalidDateErrorMessage="Invalid date" | ||
withYearPicker={{ | ||
screenReaderLabel: 'Year picker', | ||
startYear: 1999, | ||
endYear: 2024 | ||
}} | ||
/> | ||
) | ||
} | ||
} | ||
|
||
render(<Example />) | ||
``` | ||
|
||
- ```js | ||
const Example = () => { | ||
const [value, setValue] = useState('') | ||
|
||
return ( | ||
<DateInput2 | ||
renderLabel="Choose a date" | ||
screenReaderLabels={{ | ||
calendarIcon: 'Calendar', | ||
nextMonthButton: 'Next month', | ||
prevMonthButton: 'Previous month' | ||
}} | ||
width="20rem" | ||
value={value} | ||
onChange={(e, value) => setValue(value)} | ||
invalidDateErrorMessage="Invalid date" | ||
withYearPicker={{ | ||
screenReaderLabel: 'Year picker', | ||
startYear: 1999, | ||
endYear: 2024 | ||
}} | ||
/> | ||
) | ||
} | ||
|
||
render(<Example />) | ||
``` | ||
|
||
### Inside modal | ||
|
||
```js | ||
--- | ||
type: example | ||
--- | ||
|
||
class Example extends React.Component { | ||
constructor (props) { | ||
super(props) | ||
|
||
this.state = { | ||
open: false, | ||
value: '', | ||
} | ||
} | ||
|
||
handleButtonClick = () => { | ||
this.setState(function (state) { | ||
return { open: !state.open } | ||
}) | ||
}; | ||
|
||
handleFormSubmit = e => { | ||
e.preventDefault() | ||
console.log('form submitted') | ||
this.setState(state => ({ open: false })) | ||
} | ||
|
||
renderCloseButton () { | ||
return ( | ||
<CloseButton | ||
placement="end" | ||
offset="small" | ||
onClick={this.handleButtonClick} | ||
screenReaderLabel="Close" | ||
/> | ||
) | ||
} | ||
|
||
render () { | ||
return ( | ||
<div style={{ padding: '0 0 11rem 0', margin: '0 auto' }}> | ||
<Button onClick={this.handleButtonClick}> | ||
{this.state.open ? 'Close' : 'Open'} the Modal | ||
</Button> | ||
<Modal | ||
as="form" | ||
open={this.state.open} | ||
onDismiss={() => { this.setState({ open: false }) }} | ||
onSubmit={this.handleFormSubmit} | ||
size="auto" | ||
label="Modal Dialog: Hello World" | ||
shouldCloseOnDocumentClick | ||
> | ||
<Modal.Header> | ||
{this.renderCloseButton()} | ||
<Heading>Hello World</Heading> | ||
</Modal.Header> | ||
<Modal.Body> | ||
<DateInput2 | ||
renderLabel="Choose a date" | ||
screenReaderLabels={{ | ||
calendarIcon: 'Calendar', | ||
nextMonthButton: 'Next month', | ||
prevMonthButton: 'Previous month', | ||
}} | ||
width="20rem" | ||
value={this.state.value} | ||
onChange={(e, value) => this.setState({ value })} | ||
invalidDateErrorMessage="Invalid date" | ||
withYearPicker={{ | ||
screenReaderLabel: 'Year picker', | ||
startYear: 1999, | ||
endYear: 2024 | ||
}} | ||
/> | ||
</Modal.Body> | ||
<Modal.Footer> | ||
<Button onClick={this.handleButtonClick} margin="0 x-small 0 0">Close</Button> | ||
<Button color="primary" type="submit">Submit</Button> | ||
</Modal.Footer> | ||
</Modal> | ||
</div> | ||
) | ||
} | ||
} | ||
|
||
render(<Example />) | ||
``` |
Oops, something went wrong.