aws-northstar
Version:
NorthStar Design System
57 lines (53 loc) • 3.36 kB
JavaScript
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
/** *******************************************************************************************************************
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License").
You may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. *
******************************************************************************************************************** */
import React, { useState } from 'react';
import { KeyboardTimePicker, MuiPickersUtilsProvider } from '@material-ui/pickers';
import DateFnsUtils from '@date-io/date-fns';
import useUniqueId from '../../hooks/useUniqueId';
/**
* A time picker control provides a simple way to select a time of day. Time is represented by an ISO 8601 date string,
* where the date part can be ignored.
*/
const TimePicker = (_a) => {
var { value, placeholder = 'HH:MM', twentyFourHourClock, name, disabled, readOnly, autofocus, controlId, label, ariaLabelledby, ariaDescribedby, ariaRequired, onChange } = _a, props = __rest(_a, ["value", "placeholder", "twentyFourHourClock", "name", "disabled", "readOnly", "autofocus", "controlId", "label", "ariaLabelledby", "ariaDescribedby", "ariaRequired", "onChange"]);
const id = useUniqueId(controlId);
const [selectedDate, setSelectedDate] = useState(value || null);
const handleDateChange = (date) => {
onChange === null || onChange === void 0 ? void 0 : onChange(date);
setSelectedDate(date || null);
};
return (React.createElement(MuiPickersUtilsProvider, { utils: DateFnsUtils },
React.createElement(KeyboardTimePicker, { id: id, "data-testid": props['data-testid'], PopoverProps: {
anchorOrigin: {
vertical: 'bottom',
horizontal: 'left',
},
}, variant: "inline", inputVariant: "outlined", disableToolbar: false, ampm: !twentyFourHourClock, name: name, readOnly: readOnly, value: selectedDate, disabled: disabled, required: ariaRequired, placeholder: placeholder, autoFocus: autofocus, onChange: handleDateChange, inputProps: {
'aria-label': label,
'aria-labelledby': ariaLabelledby,
'aria-describedby': ariaDescribedby,
'aria-required': ariaRequired,
} })));
};
export default TimePicker;