UNPKG

@mui/x-data-grid-premium

Version:

The Premium plan edition of the MUI X Data Grid Components.

110 lines (109 loc) 3.22 kB
'use client'; import _extends from "@babel/runtime/helpers/esm/extends"; import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose"; const _excluded = ["className", "children"]; import * as React from 'react'; import { styled } from '@mui/material/styles'; import { vars } from '@mui/x-data-grid-pro/internals'; import composeClasses from '@mui/utils/composeClasses'; import { getDataGridUtilityClass, gridClasses } from '@mui/x-data-grid-pro'; import clsx from 'clsx'; import { useResize } from "../../hooks/utils/useResize.mjs"; import { useResizablePanelContext } from "./ResizablePanelContext.mjs"; import { useGridRootProps } from "../../hooks/utils/useGridRootProps.mjs"; import { jsx as _jsx } from "react/jsx-runtime"; const useUtilityClasses = ownerState => { const { classes, direction } = ownerState; const slots = { root: ['resizablePanelHandle', `resizablePanelHandle--${direction}`] }; return composeClasses(slots, getDataGridUtilityClass, classes); }; const ResizablePanelHandleRoot = styled('div', { name: 'MuiDataGrid', slot: 'ResizablePanelHandle', overridesResolver: (props, styles) => [{ [`&.${gridClasses['resizablePanelHandle--horizontal']}`]: styles['resizablePanelHandle--horizontal'] }, { [`&.${gridClasses['resizablePanelHandle--vertical']}`]: styles['resizablePanelHandle--vertical'] }, styles.resizablePanelHandle] })({ position: 'absolute', zIndex: 3, top: 0, left: 0, userSelect: 'none', transition: vars.transition(['border-color'], { duration: vars.transitions.duration.short, easing: vars.transitions.easing.easeInOut }), '&:hover': { borderWidth: 2, borderColor: vars.colors.interactive.selected }, variants: [{ props: { direction: 'horizontal' }, style: { height: '100%', width: 8, cursor: 'ew-resize', borderLeft: `1px solid ${vars.colors.border.base}`, touchAction: 'pan-x' } }, { props: { direction: 'vertical' }, style: { width: '100%', height: 8, cursor: 'ns-resize', borderTop: `1px solid ${vars.colors.border.base}`, touchAction: 'pan-y' } }] }); function ResizablePanelHandle(props) { const { className } = props, other = _objectWithoutPropertiesLoose(props, _excluded); const { rootRef, direction } = useResizablePanelContext(); const rootProps = useGridRootProps(); const ownerState = { classes: rootProps.classes, direction }; const classes = useUtilityClasses(ownerState); const { ref } = useResize({ direction, getInitialSize: () => { return direction === 'horizontal' ? rootRef.current.offsetWidth : rootRef.current.offsetHeight; }, onSizeChange: newSize => { if (direction === 'horizontal') { rootRef.current.style.width = `${newSize}px`; } else { rootRef.current.style.height = `${newSize}px`; } } }); return /*#__PURE__*/_jsx(ResizablePanelHandleRoot, _extends({ className: clsx(classes.root, className), ownerState: ownerState, direction: direction }, other, { ref: ref })); } export { ResizablePanelHandle };