@patternfly/react-core#DatePicker JavaScript Examples
The following examples show how to use
@patternfly/react-core#DatePicker.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: add-token-modal.js From ibutsu-server with MIT License | 5 votes |
render () {
return (
<Modal
variant={ModalVariant.small}
title="Add Token"
isOpen={this.props.isOpen}
onClose={this.onClose}
actions={[
<Button key="save" variant="primary" onClick={this.onSave}>Save</Button>,
<Button key="cancel" variant="link" onClick={this.onClose}>Cancel</Button>
]}
>
<Form>
<FormGroup
label="Name"
fieldId="token-name"
helperTextInvalid="A token name is required"
helperTextInvalidIcon={<ExclamationCircleIcon />}
validated={this.state.isNameValid ? ValidatedOptions.default : ValidatedOptions.error}
isRequired
>
<TextInput
type="text"
id="token-name"
name="token-name"
value={this.state.name}
onChange={this.onNameChange}
validated={this.state.isNameValid ? ValidatedOptions.default : ValidatedOptions.error}
isRequired
/>
</FormGroup>
<FormGroup
label="Expiry"
fieldId="token-expiry-date"
helperTextInvalid="A valid epiry date is required"
helperTextInvalidIcon={<ExclamationCircleIcon />}
validated={this.state.isExpiryValid ? ValidatedOptions.default : ValidatedOptions.error}
isRequired
>
<DatePicker
onChange={this.onExpiryDateChange}
value={this.state.expiryDate}
inputProps={{
id: "token-expiry-date",
validated: this.state.isExpiryValid ? ValidatedOptions.default : ValidatedOptions.error
}}
/>
</FormGroup>
</Form>
</Modal>
);
}
Example #2
Source File: EditRequestModal.js From access-requests-frontend with Apache License 2.0 | 4 votes |
RequestDetailsForm = ({
user = {},
targetAccount,
setTargetAccount,
targetOrg,
setTargetOrg,
start,
setStart,
end,
setEnd,
disableAccount,
disableOrgId,
isLoading,
error,
}) => {
let [startDate, setStartDate] = React.useState();
const [validatedAccount, setValidatedAccount] = React.useState(
error ? 'error' : 'default'
);
const [validatedOrgId, setValidatedOrgId] = React.useState(
error ? 'error' : 'default'
);
// https://github.com/RedHatInsights/insights-rbac/blob/master/rbac/api/cross_access/model.py#L49
const startValidator = (date) => {
if (isValidDate(date)) {
if (date < today) {
setEnd('');
return 'Start date must be today or later';
}
if (date > maxStartDate) {
setEnd('');
return 'Start date must be within 60 days of today';
}
}
return '';
};
const endValidator = (date) => {
if (isValidDate(startDate)) {
if (startDate > date) {
return 'End date must be after from date';
}
}
const maxToDate = new Date(startDate);
maxToDate.setFullYear(maxToDate.getFullYear() + 1);
if (date > maxToDate) {
return 'Access duration may not be longer than one year';
}
return '';
};
const onStartChange = (str, date) => {
setStartDate(new Date(date));
setStart(str);
if (isValidDate(date) && !startValidator(date)) {
date.setDate(date.getDate() + 7);
setEnd(dateFormat(date));
} else {
setEnd('');
}
};
const onEndChange = (str, date) => {
if (endValidator(date)) {
setEnd('');
} else {
setEnd(str);
}
};
return (
<Form onSubmit={(ev) => ev.preventDefault()} isDisabled={isLoading}>
<Title headingLevel="h2">Request details</Title>
<Split hasGutter>
<SplitItem isFilled>
<FormGroup label="First name" labelIcon={getLabelIcon('first name')}>
<TextInput id="first-name" value={user.first_name} isDisabled />
</FormGroup>
</SplitItem>
<SplitItem isFilled>
<FormGroup label="Last name" labelIcon={getLabelIcon('last name')}>
<TextInput id="last-name" value={user.last_name} isDisabled />
</FormGroup>
</SplitItem>
</Split>
<FormGroup
label="Account number"
isRequired
labelIcon={getLabelIcon('account number')}
helperText="Enter the account number you would like access to"
helperTextInvalid="Please enter a valid account number"
validated={validatedAccount}
>
<TextInput
id="account-number"
value={targetAccount}
onChange={(val) => {
setTargetAccount(val);
setValidatedAccount('default');
}}
isRequired
placeholder="Example, 8675309"
validated={validatedAccount}
isDisabled={disableAccount}
/>
</FormGroup>
<FormGroup
label="Organization id"
isRequired
labelIcon={getLabelIcon('organization id')}
helperText="Enter the organization id you would like access to"
helperTextInvalid="Please enter a valid organization id"
validated={validatedOrgId}
>
<TextInput
id="org-id"
value={targetOrg}
onChange={(val) => {
setTargetOrg(val);
setValidatedOrgId('default');
}}
isRequired
placeholder="Example, 1234567"
validated={validatedOrgId}
isDisabled={disableOrgId}
/>
</FormGroup>
<FormGroup
label="Access duration"
isRequired
labelIcon={getLabelIcon('access duration')}
>
<Split>
<SplitItem>
<DatePicker
width="300px"
aria-label="Start date"
value={start}
dateFormat={dateFormat}
dateParse={dateParse}
placeholder="mm/dd/yyyy"
onChange={onStartChange}
validators={[startValidator]}
/>
</SplitItem>
<SplitItem style={{ padding: '6px 12px 0 12px' }}>to</SplitItem>
<SplitItem>
<DatePicker
width="300px"
aria-label="End date"
value={end}
dateFormat={dateFormat}
dateParse={dateParse}
placeholder="mm/dd/yyyy"
onChange={onEndChange}
validators={[endValidator]}
rangeStart={start}
/>
</SplitItem>
</Split>
</FormGroup>
</Form>
);
}