@material-ui/lab
Version:
Laboratory for new Material-UI modules.
72 lines (68 loc) • 2.65 kB
JavaScript
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import _extends from "@babel/runtime/helpers/esm/extends";
import * as React from 'react';
import clsx from 'clsx';
import { styled } from '@material-ui/core/styles';
import { generateUtilityClasses } from '@material-ui/unstyled';
import { CLOCK_WIDTH, CLOCK_HOUR_WIDTH } from './shared';
import { jsx as _jsx } from "react/jsx-runtime";
export var classes = generateUtilityClasses('PrivateClockNumber', ['selected', 'disabled']);
var ClockNumberRoot = styled('span', {
skipSx: true
})(function (_ref) {
var _extends2;
var theme = _ref.theme,
styleProps = _ref.styleProps;
return _extends((_extends2 = {
height: CLOCK_HOUR_WIDTH,
width: CLOCK_HOUR_WIDTH,
position: 'absolute',
left: "calc((100% - ".concat(CLOCK_HOUR_WIDTH, "px) / 2)"),
display: 'inline-flex',
justifyContent: 'center',
alignItems: 'center',
borderRadius: '50%',
color: theme.palette.text.primary,
'&:focused': {
backgroundColor: theme.palette.background.paper
}
}, _defineProperty(_extends2, "&.".concat(classes.selected), {
color: theme.palette.primary.contrastText
}), _defineProperty(_extends2, "&.".concat(classes.disabled), {
pointerEvents: 'none',
color: theme.palette.text.disabled
}), _extends2), styleProps.inner && _extends({}, theme.typography.body2, {
color: theme.palette.text.secondary
}));
});
/**
* @ignore - internal component.
*/
function ClockNumber(props) {
var className = props.className,
disabled = props.disabled,
index = props.index,
inner = props.inner,
label = props.label,
selected = props.selected,
other = _objectWithoutProperties(props, ["className", "disabled", "index", "inner", "label", "selected"]);
var styleProps = props;
var angle = index % 12 / 12 * Math.PI * 2 - Math.PI / 2;
var length = (CLOCK_WIDTH - CLOCK_HOUR_WIDTH - 2) / 2 * (inner ? 0.65 : 1);
var x = Math.round(Math.cos(angle) * length);
var y = Math.round(Math.sin(angle) * length);
return /*#__PURE__*/_jsx(ClockNumberRoot, _extends({
className: clsx(className, selected && classes.selected, disabled && classes.disabled),
"aria-disabled": disabled ? true : undefined,
"aria-selected": selected ? true : undefined,
role: "option",
style: {
transform: "translate(".concat(x, "px, ").concat(y + (CLOCK_WIDTH - CLOCK_HOUR_WIDTH) / 2, "px")
},
styleProps: styleProps
}, other, {
children: label
}));
}
export default ClockNumber;