1
0
Fork 0

Added Statistics calculation

Statistics now show calculated values
This commit is contained in:
Techognito 2025-09-04 17:30:00 +02:00
parent fe87374e47
commit fc0f69dacb
2147 changed files with 141321 additions and 39 deletions

View file

@ -0,0 +1,17 @@
import * as React from 'react';
import { MultiSectionDigitalClockProps } from "./MultiSectionDigitalClock.types.js";
type MultiSectionDigitalClockComponent = ((props: MultiSectionDigitalClockProps & React.RefAttributes<HTMLDivElement>) => React.JSX.Element) & {
propTypes?: any;
};
/**
* Demos:
*
* - [TimePicker](https://mui.com/x/react-date-pickers/time-picker/)
* - [DigitalClock](https://mui.com/x/react-date-pickers/digital-clock/)
*
* API:
*
* - [MultiSectionDigitalClock API](https://mui.com/x/api/date-pickers/multi-section-digital-clock/)
*/
export declare const MultiSectionDigitalClock: MultiSectionDigitalClockComponent;
export {};

View file

@ -0,0 +1,513 @@
'use client';
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
const _excluded = ["ampm", "timeSteps", "autoFocus", "slots", "slotProps", "value", "defaultValue", "referenceDate", "disableIgnoringDatePartForTimeValidation", "maxTime", "minTime", "disableFuture", "disablePast", "minutesStep", "shouldDisableTime", "onChange", "view", "views", "openTo", "onViewChange", "focusedView", "onFocusedViewChange", "className", "classes", "disabled", "readOnly", "skipDisabled", "timezone"];
import * as React from 'react';
import clsx from 'clsx';
import PropTypes from 'prop-types';
import { useRtl } from '@mui/system/RtlProvider';
import { styled, useThemeProps } from '@mui/material/styles';
import useEventCallback from '@mui/utils/useEventCallback';
import composeClasses from '@mui/utils/composeClasses';
import { usePickerAdapter, usePickerTranslations } from "../hooks/index.js";
import { useNow } from "../internals/hooks/useUtils.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 { getMultiSectionDigitalClockUtilityClass } from "./multiSectionDigitalClockClasses.js";
import { MultiSectionDigitalClockSection } from "./MultiSectionDigitalClockSection.js";
import { getHourSectionOptions, getTimeSectionOptions } from "./MultiSectionDigitalClock.utils.js";
import { useControlledValue } from "../internals/hooks/useControlledValue.js";
import { singleItemValueManager } from "../internals/utils/valueManagers.js";
import { useClockReferenceDate } from "../internals/hooks/useClockReferenceDate.js";
import { formatMeridiem } from "../internals/utils/date-utils.js";
import { usePickerPrivateContext } from "../internals/hooks/usePickerPrivateContext.js";
import { jsx as _jsx } from "react/jsx-runtime";
const useUtilityClasses = classes => {
const slots = {
root: ['root']
};
return composeClasses(slots, getMultiSectionDigitalClockUtilityClass, classes);
};
const MultiSectionDigitalClockRoot = styled(PickerViewRoot, {
name: 'MuiMultiSectionDigitalClock',
slot: 'Root'
})(({
theme
}) => ({
flexDirection: 'row',
width: '100%',
borderBottom: `1px solid ${(theme.vars || theme).palette.divider}`
}));
/**
* Demos:
*
* - [TimePicker](https://mui.com/x/react-date-pickers/time-picker/)
* - [DigitalClock](https://mui.com/x/react-date-pickers/digital-clock/)
*
* API:
*
* - [MultiSectionDigitalClock API](https://mui.com/x/api/date-pickers/multi-section-digital-clock/)
*/
export const MultiSectionDigitalClock = /*#__PURE__*/React.forwardRef(function MultiSectionDigitalClock(inProps, ref) {
const adapter = usePickerAdapter();
const isRtl = useRtl();
const props = useThemeProps({
props: inProps,
name: 'MuiMultiSectionDigitalClock'
});
const {
ampm = adapter.is12HourCycleInCurrentLocale(),
timeSteps: inTimeSteps,
autoFocus,
slots,
slotProps,
value: valueProp,
defaultValue,
referenceDate: referenceDateProp,
disableIgnoringDatePartForTimeValidation = false,
maxTime,
minTime,
disableFuture,
disablePast,
minutesStep = 1,
shouldDisableTime,
onChange,
view: inView,
views: inViews = ['hours', 'minutes'],
openTo,
onViewChange,
focusedView: inFocusedView,
onFocusedViewChange,
className,
classes: classesProp,
disabled,
readOnly,
skipDisabled = false,
timezone: timezoneProp
} = props,
other = _objectWithoutPropertiesLoose(props, _excluded);
const {
value,
handleValueChange: handleRawValueChange,
timezone
} = useControlledValue({
name: 'MultiSectionDigitalClock',
timezone: timezoneProp,
value: valueProp,
defaultValue,
referenceDate: referenceDateProp,
onChange,
valueManager: singleItemValueManager
});
const translations = usePickerTranslations();
const now = useNow(timezone);
const timeSteps = React.useMemo(() => _extends({
hours: 1,
minutes: 5,
seconds: 5
}, inTimeSteps), [inTimeSteps]);
const valueOrReferenceDate = useClockReferenceDate({
value,
referenceDate: referenceDateProp,
adapter,
props,
timezone
});
const handleValueChange = useEventCallback((newValue, selectionState, selectedView) => handleRawValueChange(newValue, selectionState, selectedView));
const views = React.useMemo(() => {
if (!ampm || !inViews.includes('hours')) {
return inViews;
}
return inViews.includes('meridiem') ? inViews : [...inViews, 'meridiem'];
}, [ampm, inViews]);
const {
view,
setValueAndGoToNextView,
focusedView
} = useViews({
view: inView,
views,
openTo,
onViewChange,
onChange: handleValueChange,
focusedView: inFocusedView,
onFocusedViewChange
});
const handleMeridiemValueChange = useEventCallback(newValue => {
setValueAndGoToNextView(newValue, 'finish', 'meridiem');
});
const {
meridiemMode,
handleMeridiemChange
} = useMeridiemMode(valueOrReferenceDate, ampm, handleMeridiemValueChange, 'finish');
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 buildViewProps = React.useCallback(viewToBuild => {
switch (viewToBuild) {
case 'hours':
{
return {
onChange: hours => {
const valueWithMeridiem = convertValueToMeridiem(hours, meridiemMode, ampm);
setValueAndGoToNextView(adapter.setHours(valueOrReferenceDate, valueWithMeridiem), 'finish', 'hours');
},
items: getHourSectionOptions({
now,
value,
ampm,
adapter,
isDisabled: hours => isTimeDisabled(hours, 'hours'),
timeStep: timeSteps.hours,
resolveAriaLabel: translations.hoursClockNumberText,
valueOrReferenceDate
})
};
}
case 'minutes':
{
return {
onChange: minutes => {
setValueAndGoToNextView(adapter.setMinutes(valueOrReferenceDate, minutes), 'finish', 'minutes');
},
items: getTimeSectionOptions({
value: adapter.getMinutes(valueOrReferenceDate),
adapter,
isDisabled: minutes => isTimeDisabled(minutes, 'minutes'),
resolveLabel: minutes => adapter.format(adapter.setMinutes(now, minutes), 'minutes'),
timeStep: timeSteps.minutes,
hasValue: !!value,
resolveAriaLabel: translations.minutesClockNumberText
})
};
}
case 'seconds':
{
return {
onChange: seconds => {
setValueAndGoToNextView(adapter.setSeconds(valueOrReferenceDate, seconds), 'finish', 'seconds');
},
items: getTimeSectionOptions({
value: adapter.getSeconds(valueOrReferenceDate),
adapter,
isDisabled: seconds => isTimeDisabled(seconds, 'seconds'),
resolveLabel: seconds => adapter.format(adapter.setSeconds(now, seconds), 'seconds'),
timeStep: timeSteps.seconds,
hasValue: !!value,
resolveAriaLabel: translations.secondsClockNumberText
})
};
}
case 'meridiem':
{
const amLabel = formatMeridiem(adapter, 'am');
const pmLabel = formatMeridiem(adapter, 'pm');
return {
onChange: handleMeridiemChange,
items: [{
value: 'am',
label: amLabel,
isSelected: () => !!value && meridiemMode === 'am',
isFocused: () => !!valueOrReferenceDate && meridiemMode === 'am',
ariaLabel: amLabel
}, {
value: 'pm',
label: pmLabel,
isSelected: () => !!value && meridiemMode === 'pm',
isFocused: () => !!valueOrReferenceDate && meridiemMode === 'pm',
ariaLabel: pmLabel
}]
};
}
default:
throw new Error(`Unknown view: ${viewToBuild} found.`);
}
}, [now, value, ampm, adapter, timeSteps.hours, timeSteps.minutes, timeSteps.seconds, translations.hoursClockNumberText, translations.minutesClockNumberText, translations.secondsClockNumberText, meridiemMode, setValueAndGoToNextView, valueOrReferenceDate, isTimeDisabled, handleMeridiemChange]);
const viewsToRender = React.useMemo(() => {
if (!isRtl) {
return views;
}
const digitViews = views.filter(v => v !== 'meridiem');
digitViews.reverse();
if (views.includes('meridiem')) {
digitViews.push('meridiem');
}
return digitViews;
}, [isRtl, views]);
const viewTimeOptions = React.useMemo(() => {
return views.reduce((result, currentView) => {
return _extends({}, result, {
[currentView]: buildViewProps(currentView)
});
}, {});
}, [views, buildViewProps]);
const {
ownerState
} = usePickerPrivateContext();
const classes = useUtilityClasses(classesProp);
return /*#__PURE__*/_jsx(MultiSectionDigitalClockRoot, _extends({
ref: ref,
className: clsx(classes.root, className),
ownerState: ownerState,
role: "group"
}, other, {
children: viewsToRender.map(timeView => /*#__PURE__*/_jsx(MultiSectionDigitalClockSection, {
items: viewTimeOptions[timeView].items,
onChange: viewTimeOptions[timeView].onChange,
active: view === timeView,
autoFocus: autoFocus || focusedView === timeView,
disabled: disabled,
readOnly: readOnly,
slots: slots,
slotProps: slotProps,
skipDisabled: skipDisabled,
"aria-label": translations.selectViewText(timeView)
}, timeView))
}));
});
if (process.env.NODE_ENV !== "production") MultiSectionDigitalClock.displayName = "MultiSectionDigitalClock";
process.env.NODE_ENV !== "production" ? MultiSectionDigitalClock.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,
/**
* 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', 'meridiem', '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', 'meridiem', '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,
/**
* If `true`, disabled digital clock items will not be rendered.
* @default false
*/
skipDisabled: PropTypes.bool,
/**
* The props used for each component slot.
* @default {}
*/
slotProps: PropTypes.object,
/**
* Overrideable 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]),
/**
* The time steps between two time unit options.
* For example, if `timeSteps.minutes = 8`, then the available minute options will be `[0, 8, 16, 24, 32, 40, 48, 56]`.
* @default{ hours: 1, minutes: 5, seconds: 5 }
*/
timeSteps: PropTypes.shape({
hours: PropTypes.number,
minutes: PropTypes.number,
seconds: PropTypes.number
}),
/**
* 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', 'meridiem', 'minutes', 'seconds']),
/**
* Available views.
* @default ['hours', 'minutes']
*/
views: PropTypes.arrayOf(PropTypes.oneOf(['hours', 'meridiem', 'minutes', 'seconds']).isRequired)
} : void 0;

View file

@ -0,0 +1,48 @@
import * as React from 'react';
import { SlotComponentProps } from '@mui/utils/types';
import MenuItem from '@mui/material/MenuItem';
import { MultiSectionDigitalClockClasses } from "./multiSectionDigitalClockClasses.js";
import { BaseClockProps, ExportedBaseClockProps, MultiSectionDigitalClockOnlyProps } from "../internals/models/props/time.js";
import { MultiSectionDigitalClockSectionProps } from "./MultiSectionDigitalClockSection.js";
import { TimeViewWithMeridiem } from "../internals/models/index.js";
export interface MultiSectionDigitalClockOption<TSectionValue extends number | string> {
isDisabled?: (value: TSectionValue) => boolean;
isSelected: (value: TSectionValue) => boolean;
isFocused: (value: TSectionValue) => boolean;
label: string;
value: TSectionValue;
ariaLabel: string;
}
export interface ExportedMultiSectionDigitalClockProps extends ExportedBaseClockProps, MultiSectionDigitalClockOnlyProps {}
export interface MultiSectionDigitalClockViewProps<TSectionValue extends number | string> extends Pick<MultiSectionDigitalClockSectionProps<TSectionValue>, 'onChange' | 'items'> {}
export interface MultiSectionDigitalClockSlots {
/**
* Component responsible for rendering a single multi section digital clock section item.
* @default MenuItem from '@mui/material'
*/
digitalClockSectionItem?: React.ElementType;
}
export interface MultiSectionDigitalClockSlotProps {
digitalClockSectionItem?: SlotComponentProps<typeof MenuItem, {}, Record<string, any>>;
}
export interface MultiSectionDigitalClockProps extends ExportedMultiSectionDigitalClockProps, BaseClockProps<TimeViewWithMeridiem> {
/**
* Available views.
* @default ['hours', 'minutes']
*/
views?: readonly TimeViewWithMeridiem[];
/**
* Override or extend the styles applied to the component.
*/
classes?: Partial<MultiSectionDigitalClockClasses>;
/**
* Overrideable component slots.
* @default {}
*/
slots?: MultiSectionDigitalClockSlots;
/**
* The props used for each component slot.
* @default {}
*/
slotProps?: MultiSectionDigitalClockSlotProps;
}

View file

@ -0,0 +1 @@
export {};

View file

@ -0,0 +1,41 @@
import { MuiPickersAdapter, PickerValidDate } from "../models/index.js";
import { MultiSectionDigitalClockOption } from "./MultiSectionDigitalClock.types.js";
interface GetHoursSectionOptionsParameters {
now: PickerValidDate;
value: PickerValidDate | null;
adapter: MuiPickersAdapter;
ampm: boolean;
isDisabled: (value: number) => boolean;
timeStep: number;
resolveAriaLabel: (value: string) => string;
valueOrReferenceDate: PickerValidDate;
}
export declare const getHourSectionOptions: ({
now,
value,
adapter,
ampm,
isDisabled,
resolveAriaLabel,
timeStep,
valueOrReferenceDate
}: GetHoursSectionOptionsParameters) => MultiSectionDigitalClockOption<number>[];
interface GetTimeSectionOptionsParameters {
value: number | null;
adapter: MuiPickersAdapter;
isDisabled: (value: number) => boolean;
timeStep: number;
resolveLabel: (value: number) => string;
hasValue?: boolean;
resolveAriaLabel: (value: string) => string;
}
export declare const getTimeSectionOptions: ({
value,
adapter,
isDisabled,
timeStep,
resolveLabel,
resolveAriaLabel,
hasValue
}: GetTimeSectionOptionsParameters) => MultiSectionDigitalClockOption<number>[];
export {};

View file

@ -0,0 +1,76 @@
export const getHourSectionOptions = ({
now,
value,
adapter,
ampm,
isDisabled,
resolveAriaLabel,
timeStep,
valueOrReferenceDate
}) => {
const currentHours = value ? adapter.getHours(value) : null;
const result = [];
const isSelected = (hour, overriddenCurrentHours) => {
const resolvedCurrentHours = overriddenCurrentHours ?? currentHours;
if (resolvedCurrentHours === null) {
return false;
}
if (ampm) {
if (hour === 12) {
return resolvedCurrentHours === 12 || resolvedCurrentHours === 0;
}
return resolvedCurrentHours === hour || resolvedCurrentHours - 12 === hour;
}
return resolvedCurrentHours === hour;
};
const isFocused = hour => {
return isSelected(hour, adapter.getHours(valueOrReferenceDate));
};
const endHour = ampm ? 11 : 23;
for (let hour = 0; hour <= endHour; hour += timeStep) {
let label = adapter.format(adapter.setHours(now, hour), ampm ? 'hours12h' : 'hours24h');
const ariaLabel = resolveAriaLabel(parseInt(label, 10).toString());
label = adapter.formatNumber(label);
result.push({
value: hour,
label,
isSelected,
isDisabled,
isFocused,
ariaLabel
});
}
return result;
};
export const getTimeSectionOptions = ({
value,
adapter,
isDisabled,
timeStep,
resolveLabel,
resolveAriaLabel,
hasValue = true
}) => {
const isSelected = timeValue => {
if (value === null) {
return false;
}
return hasValue && value === timeValue;
};
const isFocused = timeValue => {
return value === timeValue;
};
return [...Array.from({
length: Math.ceil(60 / timeStep)
}, (_, index) => {
const timeValue = timeStep * index;
return {
value: timeValue,
label: adapter.formatNumber(resolveLabel(timeValue)),
isDisabled,
isSelected,
isFocused,
ariaLabel: resolveAriaLabel(timeValue.toString())
};
})];
};

View file

@ -0,0 +1,33 @@
import * as React from 'react';
import { MultiSectionDigitalClockSectionClasses } from "./multiSectionDigitalClockSectionClasses.js";
import type { MultiSectionDigitalClockOption, MultiSectionDigitalClockSlots, MultiSectionDigitalClockSlotProps } from "./MultiSectionDigitalClock.types.js";
import { FormProps } from "../internals/models/formProps.js";
import { PickerOwnerState } from "../models/pickers.js";
export interface ExportedMultiSectionDigitalClockSectionProps {
className?: string;
classes?: Partial<MultiSectionDigitalClockSectionClasses>;
slots?: MultiSectionDigitalClockSlots;
slotProps?: MultiSectionDigitalClockSlotProps;
}
export interface MultiSectionDigitalClockSectionProps<TSectionValue extends number | string> extends FormProps, ExportedMultiSectionDigitalClockSectionProps {
autoFocus?: boolean;
items: MultiSectionDigitalClockOption<TSectionValue>[];
onChange: (value: TSectionValue) => void;
active?: boolean;
skipDisabled?: boolean;
role?: string;
}
export interface MultiSectionDigitalClockSectionOwnerState extends PickerOwnerState {
/**
* `true` if this is not the initial render of the digital clock.
*/
hasDigitalClockAlreadyBeenRendered: boolean;
}
type MultiSectionDigitalClockSectionComponent = <TSectionValue extends number | string>(props: MultiSectionDigitalClockSectionProps<TSectionValue> & React.RefAttributes<HTMLUListElement>) => React.JSX.Element & {
propTypes?: any;
};
/**
* @ignore - internal component.
*/
export declare const MultiSectionDigitalClockSection: MultiSectionDigitalClockSectionComponent;
export {};

View file

@ -0,0 +1,210 @@
'use client';
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
const _excluded = ["autoFocus", "onChange", "className", "classes", "disabled", "readOnly", "items", "active", "slots", "slotProps", "skipDisabled"];
import * as React from 'react';
import clsx from 'clsx';
import { alpha, styled, useThemeProps } from '@mui/material/styles';
import composeClasses from '@mui/utils/composeClasses';
import MenuList from '@mui/material/MenuList';
import MenuItem from '@mui/material/MenuItem';
import useForkRef from '@mui/utils/useForkRef';
import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
import { getMultiSectionDigitalClockSectionUtilityClass } from "./multiSectionDigitalClockSectionClasses.js";
import { DIGITAL_CLOCK_VIEW_HEIGHT, MULTI_SECTION_CLOCK_SECTION_WIDTH } from "../internals/constants/dimensions.js";
import { getFocusedListItemIndex } from "../internals/utils/utils.js";
import { usePickerPrivateContext } from "../internals/hooks/usePickerPrivateContext.js";
import { jsx as _jsx } from "react/jsx-runtime";
const useUtilityClasses = classes => {
const slots = {
root: ['root'],
item: ['item']
};
return composeClasses(slots, getMultiSectionDigitalClockSectionUtilityClass, classes);
};
const MultiSectionDigitalClockSectionRoot = styled(MenuList, {
name: 'MuiMultiSectionDigitalClockSection',
slot: 'Root'
})(({
theme
}) => ({
maxHeight: DIGITAL_CLOCK_VIEW_HEIGHT,
width: 56,
padding: 0,
overflow: 'hidden',
scrollbarWidth: 'thin',
'@media (prefers-reduced-motion: no-preference)': {
scrollBehavior: 'auto'
},
'@media (pointer: fine)': {
'&:hover': {
overflowY: 'auto'
}
},
'@media (pointer: none), (pointer: coarse)': {
overflowY: 'auto'
},
'&:not(:first-of-type)': {
borderLeft: `1px solid ${(theme.vars || theme).palette.divider}`
},
'&::after': {
display: 'block',
content: '""',
// subtracting the height of one item, extra margin and borders to make sure the max height is correct
height: 'calc(100% - 40px - 6px)'
},
variants: [{
props: {
hasDigitalClockAlreadyBeenRendered: true
},
style: {
'@media (prefers-reduced-motion: no-preference)': {
scrollBehavior: 'smooth'
}
}
}]
}));
const MultiSectionDigitalClockSectionItem = styled(MenuItem, {
name: 'MuiMultiSectionDigitalClockSection',
slot: 'Item'
})(({
theme
}) => ({
padding: 8,
margin: '2px 4px',
width: MULTI_SECTION_CLOCK_SECTION_WIDTH,
justifyContent: 'center',
'&:first-of-type': {
marginTop: 4
},
'&:hover': {
backgroundColor: theme.vars ? `rgba(${theme.vars.palette.primary.mainChannel} / ${theme.vars.palette.action.hoverOpacity})` : alpha(theme.palette.primary.main, theme.palette.action.hoverOpacity)
},
'&.Mui-selected': {
backgroundColor: (theme.vars || theme).palette.primary.main,
color: (theme.vars || theme).palette.primary.contrastText,
'&:focus-visible, &:hover': {
backgroundColor: (theme.vars || theme).palette.primary.dark
}
},
'&.Mui-focusVisible': {
backgroundColor: theme.vars ? `rgba(${theme.vars.palette.primary.mainChannel} / ${theme.vars.palette.action.focusOpacity})` : alpha(theme.palette.primary.main, theme.palette.action.focusOpacity)
}
}));
/**
* @ignore - internal component.
*/
export const MultiSectionDigitalClockSection = /*#__PURE__*/React.forwardRef(function MultiSectionDigitalClockSection(inProps, ref) {
const containerRef = React.useRef(null);
const handleRef = useForkRef(ref, containerRef);
const previousActive = React.useRef(null);
const props = useThemeProps({
props: inProps,
name: 'MuiMultiSectionDigitalClockSection'
});
const {
autoFocus,
onChange,
className,
classes: classesProp,
disabled,
readOnly,
items,
active,
slots,
slotProps,
skipDisabled
} = props,
other = _objectWithoutPropertiesLoose(props, _excluded);
const {
ownerState: pickerOwnerState
} = usePickerPrivateContext();
const ownerState = _extends({}, pickerOwnerState, {
hasDigitalClockAlreadyBeenRendered: !!containerRef.current
});
const classes = useUtilityClasses(classesProp);
const DigitalClockSectionItem = slots?.digitalClockSectionItem ?? MultiSectionDigitalClockSectionItem;
useEnhancedEffect(() => {
if (containerRef.current === null) {
return;
}
const activeItem = containerRef.current.querySelector('[role="option"][tabindex="0"], [role="option"][aria-selected="true"]');
if (active && autoFocus && activeItem) {
activeItem.focus();
}
if (!activeItem || previousActive.current === activeItem) {
return;
}
previousActive.current = activeItem;
const offsetTop = activeItem.offsetTop;
// Subtracting the 4px of extra margin intended for the first visible section item
containerRef.current.scrollTop = offsetTop - 4;
});
const focusedOptionIndex = items.findIndex(item => item.isFocused(item.value));
const handleKeyDown = event => {
switch (event.key) {
case 'PageUp':
{
const newIndex = getFocusedListItemIndex(containerRef.current) - 5;
const children = containerRef.current.children;
const newFocusedIndex = Math.max(0, newIndex);
const childToFocus = children[newFocusedIndex];
if (childToFocus) {
childToFocus.focus();
}
event.preventDefault();
break;
}
case 'PageDown':
{
const newIndex = getFocusedListItemIndex(containerRef.current) + 5;
const children = containerRef.current.children;
const newFocusedIndex = Math.min(children.length - 1, newIndex);
const childToFocus = children[newFocusedIndex];
if (childToFocus) {
childToFocus.focus();
}
event.preventDefault();
break;
}
default:
}
};
return /*#__PURE__*/_jsx(MultiSectionDigitalClockSectionRoot, _extends({
ref: handleRef,
className: clsx(classes.root, className),
ownerState: ownerState,
autoFocusItem: autoFocus && active,
role: "listbox",
onKeyDown: handleKeyDown
}, other, {
children: items.map((option, index) => {
const isItemDisabled = option.isDisabled?.(option.value);
const isDisabled = disabled || isItemDisabled;
if (skipDisabled && isDisabled) {
return null;
}
const isSelected = option.isSelected(option.value);
const tabIndex = focusedOptionIndex === index || focusedOptionIndex === -1 && index === 0 ? 0 : -1;
return /*#__PURE__*/_jsx(DigitalClockSectionItem, _extends({
onClick: () => !readOnly && onChange(option.value),
selected: isSelected,
disabled: isDisabled,
disableRipple: readOnly,
role: "option"
// aria-readonly is not supported here and does not have any effect
,
"aria-disabled": readOnly || isDisabled || undefined,
"aria-label": option.ariaLabel,
"aria-selected": isSelected,
tabIndex: tabIndex,
className: classes.item
}, slotProps?.digitalClockSectionItem, {
children: option.label
}), option.label);
})
}));
});
if (process.env.NODE_ENV !== "production") MultiSectionDigitalClockSection.displayName = "MultiSectionDigitalClockSection";

View file

@ -0,0 +1,7 @@
export { MultiSectionDigitalClock } from "./MultiSectionDigitalClock.js";
export type { MultiSectionDigitalClockProps, MultiSectionDigitalClockSlots, MultiSectionDigitalClockSlotProps } from "./MultiSectionDigitalClock.types.js";
export { multiSectionDigitalClockSectionClasses } from "./multiSectionDigitalClockSectionClasses.js";
export type { MultiSectionDigitalClockSectionClasses, MultiSectionDigitalClockSectionClassKey } from "./multiSectionDigitalClockSectionClasses.js";
export type { ExportedMultiSectionDigitalClockSectionProps } from "./MultiSectionDigitalClockSection.js";
export { multiSectionDigitalClockClasses, getMultiSectionDigitalClockUtilityClass } from "./multiSectionDigitalClockClasses.js";
export type { MultiSectionDigitalClockClasses, MultiSectionDigitalClockClassKey } from "./multiSectionDigitalClockClasses.js";

View file

@ -0,0 +1,3 @@
export { MultiSectionDigitalClock } from "./MultiSectionDigitalClock.js";
export { multiSectionDigitalClockSectionClasses } from "./multiSectionDigitalClockSectionClasses.js";
export { multiSectionDigitalClockClasses, getMultiSectionDigitalClockUtilityClass } from "./multiSectionDigitalClockClasses.js";

View file

@ -0,0 +1,7 @@
export interface MultiSectionDigitalClockClasses {
/** Styles applied to the root element. */
root: string;
}
export type MultiSectionDigitalClockClassKey = keyof MultiSectionDigitalClockClasses;
export declare function getMultiSectionDigitalClockUtilityClass(slot: string): string;
export declare const multiSectionDigitalClockClasses: MultiSectionDigitalClockClasses;

View file

@ -0,0 +1,6 @@
import generateUtilityClass from '@mui/utils/generateUtilityClass';
import generateUtilityClasses from '@mui/utils/generateUtilityClasses';
export function getMultiSectionDigitalClockUtilityClass(slot) {
return generateUtilityClass('MuiMultiSectionDigitalClock', slot);
}
export const multiSectionDigitalClockClasses = generateUtilityClasses('MuiMultiSectionDigitalClock', ['root']);

View file

@ -0,0 +1,9 @@
export interface MultiSectionDigitalClockSectionClasses {
/** Styles applied to the root (list) element. */
root: string;
/** Styles applied to the list item (by default: MenuItem) element. */
item: string;
}
export type MultiSectionDigitalClockSectionClassKey = keyof MultiSectionDigitalClockSectionClasses;
export declare function getMultiSectionDigitalClockSectionUtilityClass(slot: string): string;
export declare const multiSectionDigitalClockSectionClasses: MultiSectionDigitalClockSectionClasses;

View file

@ -0,0 +1,6 @@
import generateUtilityClass from '@mui/utils/generateUtilityClass';
import generateUtilityClasses from '@mui/utils/generateUtilityClasses';
export function getMultiSectionDigitalClockSectionUtilityClass(slot) {
return generateUtilityClass('MuiMultiSectionDigitalClockSection', slot);
}
export const multiSectionDigitalClockSectionClasses = generateUtilityClasses('MuiMultiSectionDigitalClockSection', ['root', 'item']);