import * as React from "react"; import * as System from "~/components/system"; import * as Constants from "~/common/constants"; import moment from "moment"; import Group from "~/components/system/Group"; import SystemPage from "~/components/system/SystemPage"; import ViewSourceLink from "~/components/system/ViewSourceLink"; import CodeBlock from "~/components/system/CodeBlock"; const weekdaysOnly = (date) => { if (moment(date).day() === 0 || moment(date).day() === 6) return true; return false; }; export default class SystemPageDatepicker extends React.Component { state = { exampleOne: "", exampleTwo: "", exampleThree: "2020-07-13", }; _handleChange = (e) => { this.setState({ [e.target.name]: e.target.value }); }; render() { return ( Datepicker

The DatePicker component is used to allow the user to select a date. It returns a string in the yyyy-mm-dd form.


Imports

Import React and the DatePicker Component.

{`import * as React from "react"; import { DatePicker } from "slate-react-system";`}

Datepicker with disabled dates



Define a function to specify disabled dates. This function accepts a Date object and returns true for dates that are disabled (cannot be selected), false otherwise.
{`import moment from "moment"; const weekdaysOnly = (date) => { if (moment(date).day() === 0 || moment(date).day() === 6) return true; return false; };`}
Define the DatePicker component with the isDisabled function.
{`class ExampleOne extends React.Component { state = { exampleOne: "" }; _handleChange = (e) => this.setState({ [e.target.name]: e.target.value }); render() { return ( ); } }`}


Datepicker with minimum value



Declare the DatePicker component with a minimum value in the form of a Date or an ISO 8601 String.
{`class ExampleTwo extends React.Component { state = { exampleTwo: "" }; _handleChange = (e) => this.setState({ [e.target.name]: e.target.value }); render() { return ( ); } }`}


Datepicker with default value



Declare the DatePicker component with a default value in the form of a Date or an ISO 8601 String.
{`class ExampleThree extends React.Component { state = { exampleThree: "2020-07-13" }; _handleChange = (e) => this.setState({ [e.target.name]: e.target.value }); render() { return ( ); } }`}


Accepted React Properties

onChange ), b: "function", c: "null", d: "Function called upon an onChange event", }, { id: 2, a: ( value ), b: ["string", "Date"], c: "null", d: "The value of the datepicker. Can be used to assign default values as well", }, { id: 3, a: "name", b: "string", c: "null", d: "Input name", }, { id: 4, a: "label", b: "string", c: "null", d: "Label text", }, { id: 5, a: "description", b: "string", c: "null", d: "Description text", }, { id: 6, a: "tooltip", b: "string", c: "null", d: "Tooltip text", }, { id: 7, a: "min", b: ["string", "Date"], c: "null", d: "Earliest date allowed. String must be in yyyy-mm-dd form", }, { id: 8, a: "max", b: ["string", "Date"], c: "null", d: "Latest date allowed. String must be in yyyy-mm-dd form", }, { id: 9, a: "isDisabled", b: "function", c: "null", d: "Function that accepts a Date object and returns true if the date should be disabled (cannot be selected), false otherwise", }, ], }} />
); } }