@material-ui/lab
Version:
Material-UI Lab - Incubator for Material-UI React components.
87 lines (76 loc) • 2.48 kB
JavaScript
import * as React from 'react';
import clsx from 'clsx';
import Tab from '@material-ui/core/Tab';
import Tabs from '@material-ui/core/Tabs';
import Paper from '@material-ui/core/Paper';
import { createStyles, withStyles, useTheme } 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';
const viewToTabIndex = openView => {
if (openView === 'date' || openView === 'year') {
return 'date';
}
return 'time';
};
const tabIndexToView = tab => {
if (tab === 'date') {
return 'date';
}
return 'hours';
};
export const styles = theme => {
const tabsBackground = theme.palette.mode === 'light' ? theme.palette.primary.main : theme.palette.background.default;
return createStyles({
root: {},
modeDesktop: {
order: 1
},
tabs: {
color: theme.palette.getContrastText(tabsBackground),
backgroundColor: tabsBackground
}
});
};
var _ref = /*#__PURE__*/React.createElement(DateRangeIcon, null);
var _ref2 = /*#__PURE__*/React.createElement(TimeIcon, null);
/**
* @ignore - internal component.
*/
const DateTimePickerTabs = props => {
const {
classes,
dateRangeIcon = _ref,
onChange,
timeIcon = _ref2,
view
} = props;
const theme = useTheme();
const wrapperVariant = React.useContext(WrapperVariantContext);
const indicatorColor = theme.palette.mode === 'light' ? 'secondary' : 'primary';
const handleChange = (e, value) => {
if (value !== viewToTabIndex(view)) {
onChange(tabIndexToView(value));
}
};
return /*#__PURE__*/React.createElement(Paper, {
className: clsx(classes.root, wrapperVariant === 'desktop' && classes.modeDesktop)
}, /*#__PURE__*/React.createElement(Tabs, {
variant: "fullWidth",
value: viewToTabIndex(view),
onChange: handleChange,
className: classes.tabs,
indicatorColor: indicatorColor
}, /*#__PURE__*/React.createElement(Tab, {
value: "date",
"aria-label": "pick date",
icon: /*#__PURE__*/React.createElement(React.Fragment, null, dateRangeIcon)
}), /*#__PURE__*/React.createElement(Tab, {
value: "time",
"aria-label": "pick time",
icon: /*#__PURE__*/React.createElement(React.Fragment, null, timeIcon)
})));
};
export default withStyles(styles, {
name: 'MuiDateTimePickerTabs'
})(DateTimePickerTabs);