Added Statistics calculation
Statistics now show calculated values
This commit is contained in:
parent
fe87374e47
commit
fc0f69dacb
2147 changed files with 141321 additions and 39 deletions
491
node_modules/@mui/x-date-pickers/esm/TimeClock/TimeClock.js
generated
vendored
Normal file
491
node_modules/@mui/x-date-pickers/esm/TimeClock/TimeClock.js
generated
vendored
Normal file
|
|
@ -0,0 +1,491 @@
|
|||
'use client';
|
||||
|
||||
import _extends from "@babel/runtime/helpers/esm/extends";
|
||||
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
||||
const _excluded = ["ampm", "ampmInClock", "autoFocus", "slots", "slotProps", "value", "defaultValue", "referenceDate", "disableIgnoringDatePartForTimeValidation", "maxTime", "minTime", "disableFuture", "disablePast", "minutesStep", "shouldDisableTime", "showViewSwitcher", "onChange", "view", "views", "openTo", "onViewChange", "focusedView", "onFocusedViewChange", "className", "classes", "disabled", "readOnly", "timezone"];
|
||||
import * as React from 'react';
|
||||
import clsx from 'clsx';
|
||||
import PropTypes from 'prop-types';
|
||||
import { styled, useThemeProps } from '@mui/material/styles';
|
||||
import composeClasses from '@mui/utils/composeClasses';
|
||||
import useId from '@mui/utils/useId';
|
||||
import { usePickerAdapter, usePickerTranslations } from "../hooks/index.js";
|
||||
import { useNow } from "../internals/hooks/useUtils.js";
|
||||
import { PickersArrowSwitcher } from "../internals/components/PickersArrowSwitcher/index.js";
|
||||
import { convertValueToMeridiem, createIsAfterIgnoreDatePart } from "../internals/utils/time-utils.js";
|
||||
import { useViews } from "../internals/hooks/useViews.js";
|
||||
import { useMeridiemMode } from "../internals/hooks/date-helpers-hooks.js";
|
||||
import { PickerViewRoot } from "../internals/components/PickerViewRoot/index.js";
|
||||
import { getTimeClockUtilityClass } from "./timeClockClasses.js";
|
||||
import { Clock } from "./Clock.js";
|
||||
import { getHourNumbers, getMinutesNumbers } from "./ClockNumbers.js";
|
||||
import { useControlledValue } from "../internals/hooks/useControlledValue.js";
|
||||
import { singleItemValueManager } from "../internals/utils/valueManagers.js";
|
||||
import { useClockReferenceDate } from "../internals/hooks/useClockReferenceDate.js";
|
||||
import { usePickerPrivateContext } from "../internals/hooks/usePickerPrivateContext.js";
|
||||
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
||||
const useUtilityClasses = classes => {
|
||||
const slots = {
|
||||
root: ['root'],
|
||||
arrowSwitcher: ['arrowSwitcher']
|
||||
};
|
||||
return composeClasses(slots, getTimeClockUtilityClass, classes);
|
||||
};
|
||||
const TimeClockRoot = styled(PickerViewRoot, {
|
||||
name: 'MuiTimeClock',
|
||||
slot: 'Root'
|
||||
})({
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
position: 'relative'
|
||||
});
|
||||
const TimeClockArrowSwitcher = styled(PickersArrowSwitcher, {
|
||||
name: 'MuiTimeClock',
|
||||
slot: 'ArrowSwitcher'
|
||||
})({
|
||||
position: 'absolute',
|
||||
right: 12,
|
||||
top: 15
|
||||
});
|
||||
const TIME_CLOCK_DEFAULT_VIEWS = ['hours', 'minutes'];
|
||||
|
||||
/**
|
||||
* Demos:
|
||||
*
|
||||
* - [TimePicker](https://mui.com/x/react-date-pickers/time-picker/)
|
||||
* - [TimeClock](https://mui.com/x/react-date-pickers/time-clock/)
|
||||
*
|
||||
* API:
|
||||
*
|
||||
* - [TimeClock API](https://mui.com/x/api/date-pickers/time-clock/)
|
||||
*/
|
||||
export const TimeClock = /*#__PURE__*/React.forwardRef(function TimeClock(inProps, ref) {
|
||||
const adapter = usePickerAdapter();
|
||||
const props = useThemeProps({
|
||||
props: inProps,
|
||||
name: 'MuiTimeClock'
|
||||
});
|
||||
const {
|
||||
ampm = adapter.is12HourCycleInCurrentLocale(),
|
||||
ampmInClock = false,
|
||||
autoFocus,
|
||||
slots,
|
||||
slotProps,
|
||||
value: valueProp,
|
||||
defaultValue,
|
||||
referenceDate: referenceDateProp,
|
||||
disableIgnoringDatePartForTimeValidation = false,
|
||||
maxTime,
|
||||
minTime,
|
||||
disableFuture,
|
||||
disablePast,
|
||||
minutesStep = 1,
|
||||
shouldDisableTime,
|
||||
showViewSwitcher,
|
||||
onChange,
|
||||
view: inView,
|
||||
views = TIME_CLOCK_DEFAULT_VIEWS,
|
||||
openTo,
|
||||
onViewChange,
|
||||
focusedView,
|
||||
onFocusedViewChange,
|
||||
className,
|
||||
classes: classesProp,
|
||||
disabled,
|
||||
readOnly,
|
||||
timezone: timezoneProp
|
||||
} = props,
|
||||
other = _objectWithoutPropertiesLoose(props, _excluded);
|
||||
const {
|
||||
value,
|
||||
handleValueChange,
|
||||
timezone
|
||||
} = useControlledValue({
|
||||
name: 'TimeClock',
|
||||
timezone: timezoneProp,
|
||||
value: valueProp,
|
||||
defaultValue,
|
||||
referenceDate: referenceDateProp,
|
||||
onChange,
|
||||
valueManager: singleItemValueManager
|
||||
});
|
||||
const valueOrReferenceDate = useClockReferenceDate({
|
||||
value,
|
||||
referenceDate: referenceDateProp,
|
||||
adapter,
|
||||
props,
|
||||
timezone
|
||||
});
|
||||
const translations = usePickerTranslations();
|
||||
const now = useNow(timezone);
|
||||
const selectedId = useId();
|
||||
const {
|
||||
ownerState
|
||||
} = usePickerPrivateContext();
|
||||
const {
|
||||
view,
|
||||
setView,
|
||||
previousView,
|
||||
nextView,
|
||||
setValueAndGoToNextView
|
||||
} = useViews({
|
||||
view: inView,
|
||||
views,
|
||||
openTo,
|
||||
onViewChange,
|
||||
onChange: handleValueChange,
|
||||
focusedView,
|
||||
onFocusedViewChange
|
||||
});
|
||||
const {
|
||||
meridiemMode,
|
||||
handleMeridiemChange
|
||||
} = useMeridiemMode(valueOrReferenceDate, ampm, setValueAndGoToNextView);
|
||||
const isTimeDisabled = React.useCallback((rawValue, viewType) => {
|
||||
const isAfter = createIsAfterIgnoreDatePart(disableIgnoringDatePartForTimeValidation, adapter);
|
||||
const shouldCheckPastEnd = viewType === 'hours' || viewType === 'minutes' && views.includes('seconds');
|
||||
const containsValidTime = ({
|
||||
start,
|
||||
end
|
||||
}) => {
|
||||
if (minTime && isAfter(minTime, end)) {
|
||||
return false;
|
||||
}
|
||||
if (maxTime && isAfter(start, maxTime)) {
|
||||
return false;
|
||||
}
|
||||
if (disableFuture && isAfter(start, now)) {
|
||||
return false;
|
||||
}
|
||||
if (disablePast && isAfter(now, shouldCheckPastEnd ? end : start)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
const isValidValue = (timeValue, step = 1) => {
|
||||
if (timeValue % step !== 0) {
|
||||
return false;
|
||||
}
|
||||
if (shouldDisableTime) {
|
||||
switch (viewType) {
|
||||
case 'hours':
|
||||
return !shouldDisableTime(adapter.setHours(valueOrReferenceDate, timeValue), 'hours');
|
||||
case 'minutes':
|
||||
return !shouldDisableTime(adapter.setMinutes(valueOrReferenceDate, timeValue), 'minutes');
|
||||
case 'seconds':
|
||||
return !shouldDisableTime(adapter.setSeconds(valueOrReferenceDate, timeValue), 'seconds');
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
switch (viewType) {
|
||||
case 'hours':
|
||||
{
|
||||
const valueWithMeridiem = convertValueToMeridiem(rawValue, meridiemMode, ampm);
|
||||
const dateWithNewHours = adapter.setHours(valueOrReferenceDate, valueWithMeridiem);
|
||||
if (adapter.getHours(dateWithNewHours) !== valueWithMeridiem) {
|
||||
return true;
|
||||
}
|
||||
const start = adapter.setSeconds(adapter.setMinutes(dateWithNewHours, 0), 0);
|
||||
const end = adapter.setSeconds(adapter.setMinutes(dateWithNewHours, 59), 59);
|
||||
return !containsValidTime({
|
||||
start,
|
||||
end
|
||||
}) || !isValidValue(valueWithMeridiem);
|
||||
}
|
||||
case 'minutes':
|
||||
{
|
||||
const dateWithNewMinutes = adapter.setMinutes(valueOrReferenceDate, rawValue);
|
||||
const start = adapter.setSeconds(dateWithNewMinutes, 0);
|
||||
const end = adapter.setSeconds(dateWithNewMinutes, 59);
|
||||
return !containsValidTime({
|
||||
start,
|
||||
end
|
||||
}) || !isValidValue(rawValue, minutesStep);
|
||||
}
|
||||
case 'seconds':
|
||||
{
|
||||
const dateWithNewSeconds = adapter.setSeconds(valueOrReferenceDate, rawValue);
|
||||
const start = dateWithNewSeconds;
|
||||
const end = dateWithNewSeconds;
|
||||
return !containsValidTime({
|
||||
start,
|
||||
end
|
||||
}) || !isValidValue(rawValue);
|
||||
}
|
||||
default:
|
||||
throw new Error('not supported');
|
||||
}
|
||||
}, [ampm, valueOrReferenceDate, disableIgnoringDatePartForTimeValidation, maxTime, meridiemMode, minTime, minutesStep, shouldDisableTime, adapter, disableFuture, disablePast, now, views]);
|
||||
const viewProps = React.useMemo(() => {
|
||||
switch (view) {
|
||||
case 'hours':
|
||||
{
|
||||
const handleHoursChange = (hourValue, isFinish) => {
|
||||
const valueWithMeridiem = convertValueToMeridiem(hourValue, meridiemMode, ampm);
|
||||
setValueAndGoToNextView(adapter.setHours(valueOrReferenceDate, valueWithMeridiem), isFinish, 'hours');
|
||||
};
|
||||
const viewValue = adapter.getHours(valueOrReferenceDate);
|
||||
let viewRange;
|
||||
if (ampm) {
|
||||
if (viewValue > 12) {
|
||||
viewRange = [12, 23];
|
||||
} else {
|
||||
viewRange = [0, 11];
|
||||
}
|
||||
} else {
|
||||
viewRange = [0, 23];
|
||||
}
|
||||
return {
|
||||
onChange: handleHoursChange,
|
||||
viewValue,
|
||||
children: getHourNumbers({
|
||||
value,
|
||||
adapter,
|
||||
ampm,
|
||||
onChange: handleHoursChange,
|
||||
getClockNumberText: translations.hoursClockNumberText,
|
||||
isDisabled: hourValue => disabled || isTimeDisabled(hourValue, 'hours'),
|
||||
selectedId
|
||||
}),
|
||||
viewRange
|
||||
};
|
||||
}
|
||||
case 'minutes':
|
||||
{
|
||||
const minutesValue = adapter.getMinutes(valueOrReferenceDate);
|
||||
const handleMinutesChange = (minuteValue, isFinish) => {
|
||||
setValueAndGoToNextView(adapter.setMinutes(valueOrReferenceDate, minuteValue), isFinish, 'minutes');
|
||||
};
|
||||
return {
|
||||
viewValue: minutesValue,
|
||||
onChange: handleMinutesChange,
|
||||
children: getMinutesNumbers({
|
||||
adapter,
|
||||
value: minutesValue,
|
||||
onChange: handleMinutesChange,
|
||||
getClockNumberText: translations.minutesClockNumberText,
|
||||
isDisabled: minuteValue => disabled || isTimeDisabled(minuteValue, 'minutes'),
|
||||
selectedId
|
||||
}),
|
||||
viewRange: [0, 59]
|
||||
};
|
||||
}
|
||||
case 'seconds':
|
||||
{
|
||||
const secondsValue = adapter.getSeconds(valueOrReferenceDate);
|
||||
const handleSecondsChange = (secondValue, isFinish) => {
|
||||
setValueAndGoToNextView(adapter.setSeconds(valueOrReferenceDate, secondValue), isFinish, 'seconds');
|
||||
};
|
||||
return {
|
||||
viewValue: secondsValue,
|
||||
onChange: handleSecondsChange,
|
||||
children: getMinutesNumbers({
|
||||
adapter,
|
||||
value: secondsValue,
|
||||
onChange: handleSecondsChange,
|
||||
getClockNumberText: translations.secondsClockNumberText,
|
||||
isDisabled: secondValue => disabled || isTimeDisabled(secondValue, 'seconds'),
|
||||
selectedId
|
||||
}),
|
||||
viewRange: [0, 59]
|
||||
};
|
||||
}
|
||||
default:
|
||||
throw new Error('You must provide the type for ClockView');
|
||||
}
|
||||
}, [view, adapter, value, ampm, translations.hoursClockNumberText, translations.minutesClockNumberText, translations.secondsClockNumberText, meridiemMode, setValueAndGoToNextView, valueOrReferenceDate, isTimeDisabled, selectedId, disabled]);
|
||||
const classes = useUtilityClasses(classesProp);
|
||||
return /*#__PURE__*/_jsxs(TimeClockRoot, _extends({
|
||||
ref: ref,
|
||||
className: clsx(classes.root, className),
|
||||
ownerState: ownerState
|
||||
}, other, {
|
||||
children: [/*#__PURE__*/_jsx(Clock, _extends({
|
||||
autoFocus: autoFocus ?? !!focusedView,
|
||||
ampmInClock: ampmInClock && views.includes('hours'),
|
||||
value: value,
|
||||
type: view,
|
||||
ampm: ampm,
|
||||
minutesStep: minutesStep,
|
||||
isTimeDisabled: isTimeDisabled,
|
||||
meridiemMode: meridiemMode,
|
||||
handleMeridiemChange: handleMeridiemChange,
|
||||
selectedId: selectedId,
|
||||
disabled: disabled,
|
||||
readOnly: readOnly
|
||||
}, viewProps)), showViewSwitcher && /*#__PURE__*/_jsx(TimeClockArrowSwitcher, {
|
||||
className: classes.arrowSwitcher,
|
||||
slots: slots,
|
||||
slotProps: slotProps,
|
||||
onGoToPrevious: () => setView(previousView),
|
||||
isPreviousDisabled: !previousView,
|
||||
previousLabel: translations.openPreviousView,
|
||||
onGoToNext: () => setView(nextView),
|
||||
isNextDisabled: !nextView,
|
||||
nextLabel: translations.openNextView,
|
||||
ownerState: ownerState
|
||||
})]
|
||||
}));
|
||||
});
|
||||
if (process.env.NODE_ENV !== "production") TimeClock.displayName = "TimeClock";
|
||||
process.env.NODE_ENV !== "production" ? TimeClock.propTypes = {
|
||||
// ----------------------------- Warning --------------------------------
|
||||
// | These PropTypes are generated from the TypeScript type definitions |
|
||||
// | To update them edit the TypeScript types and run "pnpm proptypes" |
|
||||
// ----------------------------------------------------------------------
|
||||
/**
|
||||
* 12h/24h view for hour selection clock.
|
||||
* @default adapter.is12HourCycleInCurrentLocale()
|
||||
*/
|
||||
ampm: PropTypes.bool,
|
||||
/**
|
||||
* Display ampm controls under the clock (instead of in the toolbar).
|
||||
* @default false
|
||||
*/
|
||||
ampmInClock: PropTypes.bool,
|
||||
/**
|
||||
* If `true`, the main element is focused during the first mount.
|
||||
* This main element is:
|
||||
* - the element chosen by the visible view if any (i.e: the selected day on the `day` view).
|
||||
* - the `input` element if there is a field rendered.
|
||||
*/
|
||||
autoFocus: PropTypes.bool,
|
||||
/**
|
||||
* Override or extend the styles applied to the component.
|
||||
*/
|
||||
classes: PropTypes.object,
|
||||
className: PropTypes.string,
|
||||
/**
|
||||
* The default selected value.
|
||||
* Used when the component is not controlled.
|
||||
*/
|
||||
defaultValue: PropTypes.object,
|
||||
/**
|
||||
* If `true`, the component is disabled.
|
||||
* When disabled, the value cannot be changed and no interaction is possible.
|
||||
* @default false
|
||||
*/
|
||||
disabled: PropTypes.bool,
|
||||
/**
|
||||
* If `true`, disable values after the current date for date components, time for time components and both for date time components.
|
||||
* @default false
|
||||
*/
|
||||
disableFuture: PropTypes.bool,
|
||||
/**
|
||||
* Do not ignore date part when validating min/max time.
|
||||
* @default false
|
||||
*/
|
||||
disableIgnoringDatePartForTimeValidation: PropTypes.bool,
|
||||
/**
|
||||
* If `true`, disable values before the current date for date components, time for time components and both for date time components.
|
||||
* @default false
|
||||
*/
|
||||
disablePast: PropTypes.bool,
|
||||
/**
|
||||
* Controlled focused view.
|
||||
*/
|
||||
focusedView: PropTypes.oneOf(['hours', 'minutes', 'seconds']),
|
||||
/**
|
||||
* Maximal selectable time.
|
||||
* The date part of the object will be ignored unless `props.disableIgnoringDatePartForTimeValidation === true`.
|
||||
*/
|
||||
maxTime: PropTypes.object,
|
||||
/**
|
||||
* Minimal selectable time.
|
||||
* The date part of the object will be ignored unless `props.disableIgnoringDatePartForTimeValidation === true`.
|
||||
*/
|
||||
minTime: PropTypes.object,
|
||||
/**
|
||||
* Step over minutes.
|
||||
* @default 1
|
||||
*/
|
||||
minutesStep: PropTypes.number,
|
||||
/**
|
||||
* Callback fired when the value changes.
|
||||
* @template TValue The value type. It will be the same type as `value` or `null`. It can be in `[start, end]` format in case of range value.
|
||||
* @template TView The view type. Will be one of date or time views.
|
||||
* @param {TValue} value The new value.
|
||||
* @param {PickerSelectionState | undefined} selectionState Indicates if the date selection is complete.
|
||||
* @param {TView | undefined} selectedView Indicates the view in which the selection has been made.
|
||||
*/
|
||||
onChange: PropTypes.func,
|
||||
/**
|
||||
* Callback fired on focused view change.
|
||||
* @template TView Type of the view. It will vary based on the Picker type and the `views` it uses.
|
||||
* @param {TView} view The new view to focus or not.
|
||||
* @param {boolean} hasFocus `true` if the view should be focused.
|
||||
*/
|
||||
onFocusedViewChange: PropTypes.func,
|
||||
/**
|
||||
* Callback fired on view change.
|
||||
* @template TView Type of the view. It will vary based on the Picker type and the `views` it uses.
|
||||
* @param {TView} view The new view.
|
||||
*/
|
||||
onViewChange: PropTypes.func,
|
||||
/**
|
||||
* The default visible view.
|
||||
* Used when the component view is not controlled.
|
||||
* Must be a valid option from `views` list.
|
||||
*/
|
||||
openTo: PropTypes.oneOf(['hours', 'minutes', 'seconds']),
|
||||
/**
|
||||
* If `true`, the component is read-only.
|
||||
* When read-only, the value cannot be changed but the user can interact with the interface.
|
||||
* @default false
|
||||
*/
|
||||
readOnly: PropTypes.bool,
|
||||
/**
|
||||
* The date used to generate the new value when both `value` and `defaultValue` are empty.
|
||||
* @default The closest valid time using the validation props, except callbacks such as `shouldDisableTime`.
|
||||
*/
|
||||
referenceDate: PropTypes.object,
|
||||
/**
|
||||
* Disable specific time.
|
||||
* @param {PickerValidDate} value The value to check.
|
||||
* @param {TimeView} view The clock type of the timeValue.
|
||||
* @returns {boolean} If `true` the time will be disabled.
|
||||
*/
|
||||
shouldDisableTime: PropTypes.func,
|
||||
showViewSwitcher: PropTypes.bool,
|
||||
/**
|
||||
* The props used for each component slot.
|
||||
* @default {}
|
||||
*/
|
||||
slotProps: PropTypes.object,
|
||||
/**
|
||||
* Overridable component slots.
|
||||
* @default {}
|
||||
*/
|
||||
slots: PropTypes.object,
|
||||
/**
|
||||
* The system prop that allows defining system overrides as well as additional CSS styles.
|
||||
*/
|
||||
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
||||
/**
|
||||
* Choose which timezone to use for the value.
|
||||
* Example: "default", "system", "UTC", "America/New_York".
|
||||
* If you pass values from other timezones to some props, they will be converted to this timezone before being used.
|
||||
* @see See the {@link https://mui.com/x/react-date-pickers/timezone/ timezones documentation} for more details.
|
||||
* @default The timezone of the `value` or `defaultValue` prop is defined, 'default' otherwise.
|
||||
*/
|
||||
timezone: PropTypes.string,
|
||||
/**
|
||||
* The selected value.
|
||||
* Used when the component is controlled.
|
||||
*/
|
||||
value: PropTypes.object,
|
||||
/**
|
||||
* The visible view.
|
||||
* Used when the component view is controlled.
|
||||
* Must be a valid option from `views` list.
|
||||
*/
|
||||
view: PropTypes.oneOf(['hours', 'minutes', 'seconds']),
|
||||
/**
|
||||
* Available views.
|
||||
* @default ['hours', 'minutes']
|
||||
*/
|
||||
views: PropTypes.arrayOf(PropTypes.oneOf(['hours', 'minutes', 'seconds']).isRequired)
|
||||
} : void 0;
|
||||
Loading…
Add table
Add a link
Reference in a new issue