@material-ui/lab
Version:
Laboratory for new Material-UI modules.
90 lines (78 loc) • 2.76 kB
JavaScript
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import _extends from "@babel/runtime/helpers/esm/extends";
var _DateRangeIcon, _TimeIcon;
import * as React from 'react';
import Tab from '@material-ui/core/Tab';
import Tabs, { tabsClasses } from '@material-ui/core/Tabs';
import { styled } from '@material-ui/core/styles';
import TimeIcon from '../internal/svg-icons/Time';
import DateRangeIcon from '../internal/svg-icons/DateRange';
import { WrapperVariantContext } from '../internal/pickers/wrappers/WrapperVariantContext';
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
var viewToTab = function viewToTab(openView) {
// TODO: what happens if `openView` is `month`?
if (openView === 'day' || openView === 'year') {
return 'date';
}
return 'time';
};
var tabToView = function tabToView(tab) {
if (tab === 'date') {
return 'day';
}
return 'hours';
};
var DateTimePickerTabsRoot = styled(Tabs, {
skipSx: true
})(function (_ref) {
var styleProps = _ref.styleProps,
theme = _ref.theme;
return _extends({
boxShadow: "0 -1px 0 0 inset ".concat(theme.palette.divider)
}, styleProps.wrapperVariant === 'desktop' && _defineProperty({
order: 1,
boxShadow: "0 1px 0 0 inset ".concat(theme.palette.divider)
}, "& .".concat(tabsClasses.indicator), {
bottom: 'auto',
top: 0
}));
});
/**
* @ignore - internal component.
*/
var DateTimePickerTabs = function DateTimePickerTabs(props) {
var _props$dateRangeIcon = props.dateRangeIcon,
dateRangeIcon = _props$dateRangeIcon === void 0 ? _DateRangeIcon || (_DateRangeIcon = /*#__PURE__*/_jsx(DateRangeIcon, {})) : _props$dateRangeIcon,
onChange = props.onChange,
_props$timeIcon = props.timeIcon,
timeIcon = _props$timeIcon === void 0 ? _TimeIcon || (_TimeIcon = /*#__PURE__*/_jsx(TimeIcon, {})) : _props$timeIcon,
view = props.view;
var wrapperVariant = React.useContext(WrapperVariantContext);
var styleProps = _extends({}, props, {
wrapperVariant: wrapperVariant
});
var handleChange = function handleChange(event, value) {
onChange(tabToView(value));
};
return /*#__PURE__*/_jsxs(DateTimePickerTabsRoot, {
styleProps: styleProps,
variant: "fullWidth",
value: viewToTab(view),
onChange: handleChange,
children: [/*#__PURE__*/_jsx(Tab, {
value: "date",
"aria-label": "pick date",
icon: /*#__PURE__*/_jsx(React.Fragment, {
children: dateRangeIcon
})
}), /*#__PURE__*/_jsx(Tab, {
value: "time",
"aria-label": "pick time",
icon: /*#__PURE__*/_jsx(React.Fragment, {
children: timeIcon
})
})]
});
};
export default DateTimePickerTabs;