84 lines
No EOL
2.1 KiB
JavaScript
84 lines
No EOL
2.1 KiB
JavaScript
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.getTimeSectionOptions = exports.getHourSectionOptions = void 0;
|
|
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;
|
|
};
|
|
exports.getHourSectionOptions = getHourSectionOptions;
|
|
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())
|
|
};
|
|
})];
|
|
};
|
|
exports.getTimeSectionOptions = getTimeSectionOptions; |