UNPKG

aws-northstar

Version:
85 lines (81 loc) 4.7 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; 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; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); /** ******************************************************************************************************************* 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. * ******************************************************************************************************************** */ const react_1 = __importStar(require("react")); const pickers_1 = require("@material-ui/pickers"); const date_fns_1 = __importDefault(require("@date-io/date-fns")); const useUniqueId_1 = __importDefault(require("../../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 = (0, useUniqueId_1.default)(controlId); const [selectedDate, setSelectedDate] = (0, react_1.useState)(value || null); const handleDateChange = (date) => { onChange === null || onChange === void 0 ? void 0 : onChange(date); setSelectedDate(date || null); }; return (react_1.default.createElement(pickers_1.MuiPickersUtilsProvider, { utils: date_fns_1.default }, react_1.default.createElement(pickers_1.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, } }))); }; exports.default = TimePicker;