@material-ui/lab
Version:
Laboratory for new Material-UI modules.
110 lines (88 loc) • 4.62 kB
JavaScript
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var React = _interopRequireWildcard(require("react"));
var _Typography = _interopRequireDefault(require("@material-ui/core/Typography"));
var _styles = require("@material-ui/core/styles");
var _unstyled = require("@material-ui/unstyled");
var _PickersToolbar = _interopRequireDefault(require("../internal/pickers/PickersToolbar"));
var _useUtils = require("../internal/pickers/hooks/useUtils");
var _shared = require("./shared");
var _jsxRuntime = require("react/jsx-runtime");
const _excluded = ["date", "isLandscape", "isMobileKeyboardViewOpen", "onChange", "toggleMobileKeyboardView", "toolbarFormat", "toolbarPlaceholder", "toolbarTitle", "views"];
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
const classes = (0, _unstyled.generateUtilityClasses)('PrivateDatePickerToolbar', ['penIcon']);
const DatePickerToolbarRoot = (0, _styles.styled)(_PickersToolbar.default, {
skipSx: true
})({
[`& .${classes.penIcon}`]: {
position: 'relative',
top: 4
}
});
const DatePickerToolbarTitle = (0, _styles.styled)(_Typography.default, {
skipSx: true
})(({
styleProps
}) => (0, _extends2.default)({}, styleProps.isLandscape && {
margin: 'auto 16px auto auto'
}));
/**
* @ignore - internal component.
*/
const DatePickerToolbar = /*#__PURE__*/React.forwardRef(function DatePickerToolbar(props, ref) {
const {
date,
isLandscape,
isMobileKeyboardViewOpen,
toggleMobileKeyboardView,
toolbarFormat,
toolbarPlaceholder = '––',
toolbarTitle = 'Select date',
views
} = props,
other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
const utils = (0, _useUtils.useUtils)();
const dateText = React.useMemo(() => {
if (!date) {
return toolbarPlaceholder;
}
if (toolbarFormat) {
return utils.formatByString(date, toolbarFormat);
}
if ((0, _shared.isYearOnlyView)(views)) {
return utils.format(date, 'year');
}
if ((0, _shared.isYearAndMonthViews)(views)) {
return utils.format(date, 'month');
} // Little localization hack (Google is doing the same for android native pickers):
// For english localization it is convenient to include weekday into the date "Mon, Jun 1".
// For other locales using strings like "June 1", without weekday.
return /en/.test(utils.getCurrentLocaleCode()) ? utils.format(date, 'normalDateWithWeekday') : utils.format(date, 'normalDate');
}, [date, toolbarFormat, toolbarPlaceholder, utils, views]);
const styleProps = props;
return /*#__PURE__*/(0, _jsxRuntime.jsx)(DatePickerToolbarRoot, (0, _extends2.default)({
ref: ref,
toolbarTitle: toolbarTitle,
isMobileKeyboardViewOpen: isMobileKeyboardViewOpen,
toggleMobileKeyboardView: toggleMobileKeyboardView,
isLandscape: isLandscape,
penIconClassName: classes.penIcon,
styleProps: styleProps
}, other, {
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(DatePickerToolbarTitle, {
variant: "h4",
align: isLandscape ? 'left' : 'center',
styleProps: styleProps,
children: dateText
})
}));
});
var _default = DatePickerToolbar;
exports.default = _default;
;