pre-installations and preparations
This commit is contained in:
1 parent
3e5a0329cb
commit
201d621ac3
6977 files changed
+742826
No files matched your search
+129
@@ -0,0 +1,129 @@
|
||||
'use client';
|
||||
|
||||
import _extends from "@babel/runtime/helpers/esm/extends";
|
||||
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
||||
const _excluded = ["badgeContent", "children", "invisible", "max", "slotProps", "slots", "showZero"];
|
||||
import * as React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { unstable_composeClasses as composeClasses } from '../composeClasses';
|
||||
import { useBadge } from '../useBadge';
|
||||
import { getBadgeUtilityClass } from './badgeClasses';
|
||||
import { useSlotProps } from '../utils';
|
||||
import { useClassNamesOverride } from '../utils/ClassNameConfigurator';
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
import { jsxs as _jsxs } from "react/jsx-runtime";
|
||||
const useUtilityClasses = ownerState => {
|
||||
const {
|
||||
invisible
|
||||
} = ownerState;
|
||||
const slots = {
|
||||
root: ['root'],
|
||||
badge: ['badge', invisible && 'invisible']
|
||||
};
|
||||
return composeClasses(slots, useClassNamesOverride(getBadgeUtilityClass));
|
||||
};
|
||||
/**
|
||||
*
|
||||
* Demos:
|
||||
*
|
||||
* - [Badge](https://mui.com/base-ui/react-badge/)
|
||||
*
|
||||
* API:
|
||||
*
|
||||
* - [Badge API](https://mui.com/base-ui/react-badge/components-api/#badge)
|
||||
*/
|
||||
const Badge = /*#__PURE__*/React.forwardRef(function Badge(props, forwardedRef) {
|
||||
const {
|
||||
children,
|
||||
max: maxProp = 99,
|
||||
slotProps = {},
|
||||
slots = {},
|
||||
showZero = false
|
||||
} = props,
|
||||
other = _objectWithoutPropertiesLoose(props, _excluded);
|
||||
const {
|
||||
badgeContent,
|
||||
max,
|
||||
displayValue,
|
||||
invisible
|
||||
} = useBadge(_extends({}, props, {
|
||||
max: maxProp
|
||||
}));
|
||||
const ownerState = _extends({}, props, {
|
||||
badgeContent,
|
||||
invisible,
|
||||
max,
|
||||
showZero
|
||||
});
|
||||
const classes = useUtilityClasses(ownerState);
|
||||
const Root = slots.root ?? 'span';
|
||||
const rootProps = useSlotProps({
|
||||
elementType: Root,
|
||||
externalSlotProps: slotProps.root,
|
||||
externalForwardedProps: other,
|
||||
additionalProps: {
|
||||
ref: forwardedRef
|
||||
},
|
||||
ownerState,
|
||||
className: classes.root
|
||||
});
|
||||
const BadgeComponent = slots.badge ?? 'span';
|
||||
const badgeProps = useSlotProps({
|
||||
elementType: BadgeComponent,
|
||||
externalSlotProps: slotProps.badge,
|
||||
ownerState,
|
||||
className: classes.badge
|
||||
});
|
||||
return /*#__PURE__*/_jsxs(Root, _extends({}, rootProps, {
|
||||
children: [children, /*#__PURE__*/_jsx(BadgeComponent, _extends({}, badgeProps, {
|
||||
children: displayValue
|
||||
}))]
|
||||
}));
|
||||
});
|
||||
process.env.NODE_ENV !== "production" ? Badge.propTypes /* remove-proptypes */ = {
|
||||
// ┌────────────────────────────── Warning ──────────────────────────────┐
|
||||
// │ These PropTypes are generated from the TypeScript type definitions. │
|
||||
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
|
||||
// └─────────────────────────────────────────────────────────────────────┘
|
||||
/**
|
||||
* The content rendered within the badge.
|
||||
*/
|
||||
badgeContent: PropTypes.node,
|
||||
/**
|
||||
* The badge will be added relative to this node.
|
||||
*/
|
||||
children: PropTypes.node,
|
||||
/**
|
||||
* If `true`, the badge is invisible.
|
||||
* @default false
|
||||
*/
|
||||
invisible: PropTypes.bool,
|
||||
/**
|
||||
* Max count to show.
|
||||
* @default 99
|
||||
*/
|
||||
max: PropTypes.number,
|
||||
/**
|
||||
* Controls whether the badge is hidden when `badgeContent` is zero.
|
||||
* @default false
|
||||
*/
|
||||
showZero: PropTypes.bool,
|
||||
/**
|
||||
* The props used for each slot inside the Badge.
|
||||
* @default {}
|
||||
*/
|
||||
slotProps: PropTypes.shape({
|
||||
badge: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
||||
root: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
|
||||
}),
|
||||
/**
|
||||
* The components used for each slot inside the Badge.
|
||||
* Either a string to use a HTML element or a component.
|
||||
* @default {}
|
||||
*/
|
||||
slots: PropTypes.shape({
|
||||
badge: PropTypes.elementType,
|
||||
root: PropTypes.elementType
|
||||
})
|
||||
} : void 0;
|
||||
export { Badge };
|
||||
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import { generateUtilityClasses } from '../generateUtilityClasses';
|
||||
import { generateUtilityClass } from '../generateUtilityClass';
|
||||
const COMPONENT_NAME = 'Badge';
|
||||
export function getBadgeUtilityClass(slot) {
|
||||
return generateUtilityClass(COMPONENT_NAME, slot);
|
||||
}
|
||||
export const badgeClasses = generateUtilityClasses(COMPONENT_NAME, ['root', 'badge', 'invisible']);
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
'use client';
|
||||
|
||||
export { Badge } from './Badge';
|
||||
export * from './Badge.types';
|
||||
export * from './badgeClasses';
|
||||
+155
@@ -0,0 +1,155 @@
|
||||
'use client';
|
||||
|
||||
import _extends from "@babel/runtime/helpers/esm/extends";
|
||||
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
||||
const _excluded = ["action", "children", "disabled", "focusableWhenDisabled", "onFocusVisible", "slotProps", "slots", "rootElementName"];
|
||||
import * as React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { unstable_composeClasses as composeClasses } from '../composeClasses';
|
||||
import { getButtonUtilityClass } from './buttonClasses';
|
||||
import { useButton } from '../useButton';
|
||||
import { useSlotProps } from '../utils';
|
||||
import { useClassNamesOverride } from '../utils/ClassNameConfigurator';
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
const useUtilityClasses = ownerState => {
|
||||
const {
|
||||
active,
|
||||
disabled,
|
||||
focusVisible
|
||||
} = ownerState;
|
||||
const slots = {
|
||||
root: ['root', disabled && 'disabled', focusVisible && 'focusVisible', active && 'active']
|
||||
};
|
||||
return composeClasses(slots, useClassNamesOverride(getButtonUtilityClass));
|
||||
};
|
||||
/**
|
||||
* The foundation for building custom-styled buttons.
|
||||
*
|
||||
* Demos:
|
||||
*
|
||||
* - [Button](https://mui.com/base-ui/react-button/)
|
||||
*
|
||||
* API:
|
||||
*
|
||||
* - [Button API](https://mui.com/base-ui/react-button/components-api/#button)
|
||||
*/
|
||||
const Button = /*#__PURE__*/React.forwardRef(function Button(props, forwardedRef) {
|
||||
const {
|
||||
action,
|
||||
children,
|
||||
focusableWhenDisabled = false,
|
||||
slotProps = {},
|
||||
slots = {},
|
||||
rootElementName: rootElementNameProp = 'button'
|
||||
} = props,
|
||||
other = _objectWithoutPropertiesLoose(props, _excluded);
|
||||
const buttonRef = React.useRef();
|
||||
let rootElementName = rootElementNameProp;
|
||||
if (typeof slots.root === 'string') {
|
||||
rootElementName = slots.root;
|
||||
} else if (other.href || other.to) {
|
||||
rootElementName = 'a';
|
||||
}
|
||||
const {
|
||||
active,
|
||||
focusVisible,
|
||||
setFocusVisible,
|
||||
getRootProps
|
||||
} = useButton(_extends({}, props, {
|
||||
focusableWhenDisabled,
|
||||
rootElementName
|
||||
}));
|
||||
React.useImperativeHandle(action, () => ({
|
||||
focusVisible: () => {
|
||||
setFocusVisible(true);
|
||||
buttonRef.current.focus();
|
||||
}
|
||||
}), [setFocusVisible]);
|
||||
const ownerState = _extends({}, props, {
|
||||
active,
|
||||
focusableWhenDisabled,
|
||||
focusVisible
|
||||
});
|
||||
const classes = useUtilityClasses(ownerState);
|
||||
const defaultElement = other.href || other.to ? 'a' : 'button';
|
||||
const Root = slots.root ?? defaultElement;
|
||||
const rootProps = useSlotProps({
|
||||
elementType: Root,
|
||||
getSlotProps: getRootProps,
|
||||
externalForwardedProps: other,
|
||||
externalSlotProps: slotProps.root,
|
||||
additionalProps: {
|
||||
ref: forwardedRef
|
||||
},
|
||||
ownerState,
|
||||
className: classes.root
|
||||
});
|
||||
return /*#__PURE__*/_jsx(Root, _extends({}, rootProps, {
|
||||
children: children
|
||||
}));
|
||||
});
|
||||
process.env.NODE_ENV !== "production" ? Button.propTypes /* remove-proptypes */ = {
|
||||
// ┌────────────────────────────── Warning ──────────────────────────────┐
|
||||
// │ These PropTypes are generated from the TypeScript type definitions. │
|
||||
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
|
||||
// └─────────────────────────────────────────────────────────────────────┘
|
||||
/**
|
||||
* A ref for imperative actions. It currently only supports `focusVisible()` action.
|
||||
*/
|
||||
action: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
|
||||
current: PropTypes.shape({
|
||||
focusVisible: PropTypes.func.isRequired
|
||||
})
|
||||
})]),
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
children: PropTypes.node,
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
className: PropTypes.string,
|
||||
/**
|
||||
* If `true`, the component is disabled.
|
||||
* @default false
|
||||
*/
|
||||
disabled: PropTypes.bool,
|
||||
/**
|
||||
* If `true`, allows a disabled button to receive focus.
|
||||
* @default false
|
||||
*/
|
||||
focusableWhenDisabled: PropTypes.bool,
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
href: PropTypes.string,
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
onFocusVisible: PropTypes.func,
|
||||
/**
|
||||
* The HTML element that is ultimately rendered, for example 'button' or 'a'
|
||||
* @default 'button'
|
||||
*/
|
||||
rootElementName: PropTypes /* @typescript-to-proptypes-ignore */.string,
|
||||
/**
|
||||
* The props used for each slot inside the Button.
|
||||
* @default {}
|
||||
*/
|
||||
slotProps: PropTypes.shape({
|
||||
root: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
|
||||
}),
|
||||
/**
|
||||
* The components used for each slot inside the Button.
|
||||
* Either a string to use a HTML element or a component.
|
||||
* @default {}
|
||||
*/
|
||||
slots: PropTypes.shape({
|
||||
root: PropTypes.elementType
|
||||
}),
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
to: PropTypes.string
|
||||
} : void 0;
|
||||
export { Button };
|
||||
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import { generateUtilityClass } from '../generateUtilityClass';
|
||||
import { generateUtilityClasses } from '../generateUtilityClasses';
|
||||
const COMPONENT_NAME = 'Button';
|
||||
export function getButtonUtilityClass(slot) {
|
||||
return generateUtilityClass(COMPONENT_NAME, slot);
|
||||
}
|
||||
export const buttonClasses = generateUtilityClasses(COMPONENT_NAME, ['root', 'active', 'disabled', 'focusVisible']);
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
'use client';
|
||||
|
||||
export { Button } from './Button';
|
||||
export * from './buttonClasses';
|
||||
export * from './Button.types';
|
||||
+1
@@ -0,0 +1 @@
|
||||
export { unstable_ClassNameGenerator } from '@mui/utils';
|
||||
+177
@@ -0,0 +1,177 @@
|
||||
'use client';
|
||||
|
||||
import * as React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { elementAcceptingRef, exactProp, unstable_ownerDocument as ownerDocument, unstable_useForkRef as useForkRef, unstable_useEventCallback as useEventCallback } from '@mui/utils';
|
||||
|
||||
// TODO: return `EventHandlerName extends `on${infer EventName}` ? Lowercase<EventName> : never` once generatePropTypes runs with TS 4.1
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
function mapEventPropToEvent(eventProp) {
|
||||
return eventProp.substring(2).toLowerCase();
|
||||
}
|
||||
function clickedRootScrollbar(event, doc) {
|
||||
return doc.documentElement.clientWidth < event.clientX || doc.documentElement.clientHeight < event.clientY;
|
||||
}
|
||||
/**
|
||||
* Listen for click events that occur somewhere in the document, outside of the element itself.
|
||||
* For instance, if you need to hide a menu when people click anywhere else on your page.
|
||||
*
|
||||
* Demos:
|
||||
*
|
||||
* - [Click-Away Listener](https://mui.com/base-ui/react-click-away-listener/)
|
||||
*
|
||||
* API:
|
||||
*
|
||||
* - [ClickAwayListener API](https://mui.com/base-ui/react-click-away-listener/components-api/#click-away-listener)
|
||||
*/
|
||||
function ClickAwayListener(props) {
|
||||
const {
|
||||
children,
|
||||
disableReactTree = false,
|
||||
mouseEvent = 'onClick',
|
||||
onClickAway,
|
||||
touchEvent = 'onTouchEnd'
|
||||
} = props;
|
||||
const movedRef = React.useRef(false);
|
||||
const nodeRef = React.useRef(null);
|
||||
const activatedRef = React.useRef(false);
|
||||
const syntheticEventRef = React.useRef(false);
|
||||
React.useEffect(() => {
|
||||
// Ensure that this component is not "activated" synchronously.
|
||||
// https://github.com/facebook/react/issues/20074
|
||||
setTimeout(() => {
|
||||
activatedRef.current = true;
|
||||
}, 0);
|
||||
return () => {
|
||||
activatedRef.current = false;
|
||||
};
|
||||
}, []);
|
||||
const handleRef = useForkRef(
|
||||
// @ts-expect-error TODO upstream fix
|
||||
children.ref, nodeRef);
|
||||
|
||||
// The handler doesn't take event.defaultPrevented into account:
|
||||
//
|
||||
// event.preventDefault() is meant to stop default behaviors like
|
||||
// clicking a checkbox to check it, hitting a button to submit a form,
|
||||
// and hitting left arrow to move the cursor in a text input etc.
|
||||
// Only special HTML elements have these default behaviors.
|
||||
const handleClickAway = useEventCallback(event => {
|
||||
// Given developers can stop the propagation of the synthetic event,
|
||||
// we can only be confident with a positive value.
|
||||
const insideReactTree = syntheticEventRef.current;
|
||||
syntheticEventRef.current = false;
|
||||
const doc = ownerDocument(nodeRef.current);
|
||||
|
||||
// 1. IE11 support, which trigger the handleClickAway even after the unbind
|
||||
// 2. The child might render null.
|
||||
// 3. Behave like a blur listener.
|
||||
if (!activatedRef.current || !nodeRef.current || 'clientX' in event && clickedRootScrollbar(event, doc)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Do not act if user performed touchmove
|
||||
if (movedRef.current) {
|
||||
movedRef.current = false;
|
||||
return;
|
||||
}
|
||||
let insideDOM;
|
||||
|
||||
// If not enough, can use https://github.com/DieterHolvoet/event-propagation-path/blob/master/propagationPath.js
|
||||
if (event.composedPath) {
|
||||
insideDOM = event.composedPath().indexOf(nodeRef.current) > -1;
|
||||
} else {
|
||||
insideDOM = !doc.documentElement.contains(
|
||||
// @ts-expect-error returns `false` as intended when not dispatched from a Node
|
||||
event.target) || nodeRef.current.contains(
|
||||
// @ts-expect-error returns `false` as intended when not dispatched from a Node
|
||||
event.target);
|
||||
}
|
||||
if (!insideDOM && (disableReactTree || !insideReactTree)) {
|
||||
onClickAway(event);
|
||||
}
|
||||
});
|
||||
|
||||
// Keep track of mouse/touch events that bubbled up through the portal.
|
||||
const createHandleSynthetic = handlerName => event => {
|
||||
syntheticEventRef.current = true;
|
||||
const childrenPropsHandler = children.props[handlerName];
|
||||
if (childrenPropsHandler) {
|
||||
childrenPropsHandler(event);
|
||||
}
|
||||
};
|
||||
const childrenProps = {
|
||||
ref: handleRef
|
||||
};
|
||||
if (touchEvent !== false) {
|
||||
childrenProps[touchEvent] = createHandleSynthetic(touchEvent);
|
||||
}
|
||||
React.useEffect(() => {
|
||||
if (touchEvent !== false) {
|
||||
const mappedTouchEvent = mapEventPropToEvent(touchEvent);
|
||||
const doc = ownerDocument(nodeRef.current);
|
||||
const handleTouchMove = () => {
|
||||
movedRef.current = true;
|
||||
};
|
||||
doc.addEventListener(mappedTouchEvent, handleClickAway);
|
||||
doc.addEventListener('touchmove', handleTouchMove);
|
||||
return () => {
|
||||
doc.removeEventListener(mappedTouchEvent, handleClickAway);
|
||||
doc.removeEventListener('touchmove', handleTouchMove);
|
||||
};
|
||||
}
|
||||
return undefined;
|
||||
}, [handleClickAway, touchEvent]);
|
||||
if (mouseEvent !== false) {
|
||||
childrenProps[mouseEvent] = createHandleSynthetic(mouseEvent);
|
||||
}
|
||||
React.useEffect(() => {
|
||||
if (mouseEvent !== false) {
|
||||
const mappedMouseEvent = mapEventPropToEvent(mouseEvent);
|
||||
const doc = ownerDocument(nodeRef.current);
|
||||
doc.addEventListener(mappedMouseEvent, handleClickAway);
|
||||
return () => {
|
||||
doc.removeEventListener(mappedMouseEvent, handleClickAway);
|
||||
};
|
||||
}
|
||||
return undefined;
|
||||
}, [handleClickAway, mouseEvent]);
|
||||
return /*#__PURE__*/_jsx(React.Fragment, {
|
||||
children: /*#__PURE__*/React.cloneElement(children, childrenProps)
|
||||
});
|
||||
}
|
||||
process.env.NODE_ENV !== "production" ? ClickAwayListener.propTypes /* remove-proptypes */ = {
|
||||
// ┌────────────────────────────── Warning ──────────────────────────────┐
|
||||
// │ These PropTypes are generated from the TypeScript type definitions. │
|
||||
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
|
||||
// └─────────────────────────────────────────────────────────────────────┘
|
||||
/**
|
||||
* The wrapped element.
|
||||
*/
|
||||
children: elementAcceptingRef.isRequired,
|
||||
/**
|
||||
* If `true`, the React tree is ignored and only the DOM tree is considered.
|
||||
* This prop changes how portaled elements are handled.
|
||||
* @default false
|
||||
*/
|
||||
disableReactTree: PropTypes.bool,
|
||||
/**
|
||||
* The mouse event to listen to. You can disable the listener by providing `false`.
|
||||
* @default 'onClick'
|
||||
*/
|
||||
mouseEvent: PropTypes.oneOf(['onClick', 'onMouseDown', 'onMouseUp', 'onPointerDown', 'onPointerUp', false]),
|
||||
/**
|
||||
* Callback fired when a "click away" event is detected.
|
||||
*/
|
||||
onClickAway: PropTypes.func.isRequired,
|
||||
/**
|
||||
* The touch event to listen to. You can disable the listener by providing `false`.
|
||||
* @default 'onTouchEnd'
|
||||
*/
|
||||
touchEvent: PropTypes.oneOf(['onTouchEnd', 'onTouchStart', false])
|
||||
} : void 0;
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
// eslint-disable-next-line
|
||||
ClickAwayListener['propTypes' + ''] = exactProp(ClickAwayListener.propTypes);
|
||||
}
|
||||
export { ClickAwayListener };
|
||||
+1
@@ -0,0 +1 @@
|
||||
export * from './ClickAwayListener';
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
'use client';
|
||||
|
||||
import * as React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { exactProp } from '@mui/utils';
|
||||
import { DropdownContext } from '../useDropdown/DropdownContext';
|
||||
import { useDropdown } from '../useDropdown/useDropdown';
|
||||
/**
|
||||
*
|
||||
* Demos:
|
||||
*
|
||||
* - [Menu](https://mui.com/base-ui/react-menu/)
|
||||
*
|
||||
* API:
|
||||
*
|
||||
* - [Dropdown API](https://mui.com/base-ui/react-menu/components-api/#dropdown)
|
||||
*/
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
function Dropdown(props) {
|
||||
const {
|
||||
children,
|
||||
open,
|
||||
defaultOpen,
|
||||
onOpenChange
|
||||
} = props;
|
||||
const {
|
||||
contextValue
|
||||
} = useDropdown({
|
||||
defaultOpen,
|
||||
onOpenChange,
|
||||
open
|
||||
});
|
||||
return /*#__PURE__*/_jsx(DropdownContext.Provider, {
|
||||
value: contextValue,
|
||||
children: children
|
||||
});
|
||||
}
|
||||
process.env.NODE_ENV !== "production" ? Dropdown.propTypes /* remove-proptypes */ = {
|
||||
// ┌────────────────────────────── Warning ──────────────────────────────┐
|
||||
// │ These PropTypes are generated from the TypeScript type definitions. │
|
||||
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
|
||||
// └─────────────────────────────────────────────────────────────────────┘
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
children: PropTypes.node,
|
||||
/**
|
||||
* If `true`, the dropdown is initially open.
|
||||
*/
|
||||
defaultOpen: PropTypes.bool,
|
||||
/**
|
||||
* Callback fired when the component requests to be opened or closed.
|
||||
*/
|
||||
onOpenChange: PropTypes.func,
|
||||
/**
|
||||
* Allows to control whether the dropdown is open.
|
||||
* This is a controlled counterpart of `defaultOpen`.
|
||||
*/
|
||||
open: PropTypes.bool
|
||||
} : void 0;
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
// eslint-disable-next-line
|
||||
Dropdown['propTypes' + ''] = exactProp(Dropdown.propTypes);
|
||||
}
|
||||
export { Dropdown };
|
||||
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
export * from './Dropdown';
|
||||
export * from './Dropdown.types';
|
||||
+339
@@ -0,0 +1,339 @@
|
||||
'use client';
|
||||
|
||||
/* eslint-disable consistent-return, jsx-a11y/no-noninteractive-tabindex */
|
||||
import * as React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { exactProp, elementAcceptingRef, unstable_useForkRef as useForkRef, unstable_ownerDocument as ownerDocument } from '@mui/utils';
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
import { jsxs as _jsxs } from "react/jsx-runtime";
|
||||
// Inspired by https://github.com/focus-trap/tabbable
|
||||
const candidatesSelector = ['input', 'select', 'textarea', 'a[href]', 'button', '[tabindex]', 'audio[controls]', 'video[controls]', '[contenteditable]:not([contenteditable="false"])'].join(',');
|
||||
function getTabIndex(node) {
|
||||
const tabindexAttr = parseInt(node.getAttribute('tabindex') || '', 10);
|
||||
if (!Number.isNaN(tabindexAttr)) {
|
||||
return tabindexAttr;
|
||||
}
|
||||
|
||||
// Browsers do not return `tabIndex` correctly for contentEditable nodes;
|
||||
// https://bugs.chromium.org/p/chromium/issues/detail?id=661108&q=contenteditable%20tabindex&can=2
|
||||
// so if they don't have a tabindex attribute specifically set, assume it's 0.
|
||||
// in Chrome, <details/>, <audio controls/> and <video controls/> elements get a default
|
||||
// `tabIndex` of -1 when the 'tabindex' attribute isn't specified in the DOM,
|
||||
// yet they are still part of the regular tab order; in FF, they get a default
|
||||
// `tabIndex` of 0; since Chrome still puts those elements in the regular tab
|
||||
// order, consider their tab index to be 0.
|
||||
if (node.contentEditable === 'true' || (node.nodeName === 'AUDIO' || node.nodeName === 'VIDEO' || node.nodeName === 'DETAILS') && node.getAttribute('tabindex') === null) {
|
||||
return 0;
|
||||
}
|
||||
return node.tabIndex;
|
||||
}
|
||||
function isNonTabbableRadio(node) {
|
||||
if (node.tagName !== 'INPUT' || node.type !== 'radio') {
|
||||
return false;
|
||||
}
|
||||
if (!node.name) {
|
||||
return false;
|
||||
}
|
||||
const getRadio = selector => node.ownerDocument.querySelector(`input[type="radio"]${selector}`);
|
||||
let roving = getRadio(`[name="${node.name}"]:checked`);
|
||||
if (!roving) {
|
||||
roving = getRadio(`[name="${node.name}"]`);
|
||||
}
|
||||
return roving !== node;
|
||||
}
|
||||
function isNodeMatchingSelectorFocusable(node) {
|
||||
if (node.disabled || node.tagName === 'INPUT' && node.type === 'hidden' || isNonTabbableRadio(node)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
function defaultGetTabbable(root) {
|
||||
const regularTabNodes = [];
|
||||
const orderedTabNodes = [];
|
||||
Array.from(root.querySelectorAll(candidatesSelector)).forEach((node, i) => {
|
||||
const nodeTabIndex = getTabIndex(node);
|
||||
if (nodeTabIndex === -1 || !isNodeMatchingSelectorFocusable(node)) {
|
||||
return;
|
||||
}
|
||||
if (nodeTabIndex === 0) {
|
||||
regularTabNodes.push(node);
|
||||
} else {
|
||||
orderedTabNodes.push({
|
||||
documentOrder: i,
|
||||
tabIndex: nodeTabIndex,
|
||||
node: node
|
||||
});
|
||||
}
|
||||
});
|
||||
return orderedTabNodes.sort((a, b) => a.tabIndex === b.tabIndex ? a.documentOrder - b.documentOrder : a.tabIndex - b.tabIndex).map(a => a.node).concat(regularTabNodes);
|
||||
}
|
||||
function defaultIsEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility component that locks focus inside the component.
|
||||
*
|
||||
* Demos:
|
||||
*
|
||||
* - [Focus Trap](https://mui.com/base-ui/react-focus-trap/)
|
||||
*
|
||||
* API:
|
||||
*
|
||||
* - [FocusTrap API](https://mui.com/base-ui/react-focus-trap/components-api/#focus-trap)
|
||||
*/
|
||||
function FocusTrap(props) {
|
||||
const {
|
||||
children,
|
||||
disableAutoFocus = false,
|
||||
disableEnforceFocus = false,
|
||||
disableRestoreFocus = false,
|
||||
getTabbable = defaultGetTabbable,
|
||||
isEnabled = defaultIsEnabled,
|
||||
open
|
||||
} = props;
|
||||
const ignoreNextEnforceFocus = React.useRef(false);
|
||||
const sentinelStart = React.useRef(null);
|
||||
const sentinelEnd = React.useRef(null);
|
||||
const nodeToRestore = React.useRef(null);
|
||||
const reactFocusEventTarget = React.useRef(null);
|
||||
// This variable is useful when disableAutoFocus is true.
|
||||
// It waits for the active element to move into the component to activate.
|
||||
const activated = React.useRef(false);
|
||||
const rootRef = React.useRef(null);
|
||||
// @ts-expect-error TODO upstream fix
|
||||
const handleRef = useForkRef(children.ref, rootRef);
|
||||
const lastKeydown = React.useRef(null);
|
||||
React.useEffect(() => {
|
||||
// We might render an empty child.
|
||||
if (!open || !rootRef.current) {
|
||||
return;
|
||||
}
|
||||
activated.current = !disableAutoFocus;
|
||||
}, [disableAutoFocus, open]);
|
||||
React.useEffect(() => {
|
||||
// We might render an empty child.
|
||||
if (!open || !rootRef.current) {
|
||||
return;
|
||||
}
|
||||
const doc = ownerDocument(rootRef.current);
|
||||
if (!rootRef.current.contains(doc.activeElement)) {
|
||||
if (!rootRef.current.hasAttribute('tabIndex')) {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
console.error(['MUI: The modal content node does not accept focus.', 'For the benefit of assistive technologies, ' + 'the tabIndex of the node is being set to "-1".'].join('\n'));
|
||||
}
|
||||
rootRef.current.setAttribute('tabIndex', '-1');
|
||||
}
|
||||
if (activated.current) {
|
||||
rootRef.current.focus();
|
||||
}
|
||||
}
|
||||
return () => {
|
||||
// restoreLastFocus()
|
||||
if (!disableRestoreFocus) {
|
||||
// In IE11 it is possible for document.activeElement to be null resulting
|
||||
// in nodeToRestore.current being null.
|
||||
// Not all elements in IE11 have a focus method.
|
||||
// Once IE11 support is dropped the focus() call can be unconditional.
|
||||
if (nodeToRestore.current && nodeToRestore.current.focus) {
|
||||
ignoreNextEnforceFocus.current = true;
|
||||
nodeToRestore.current.focus();
|
||||
}
|
||||
nodeToRestore.current = null;
|
||||
}
|
||||
};
|
||||
// Missing `disableRestoreFocus` which is fine.
|
||||
// We don't support changing that prop on an open FocusTrap
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [open]);
|
||||
React.useEffect(() => {
|
||||
// We might render an empty child.
|
||||
if (!open || !rootRef.current) {
|
||||
return;
|
||||
}
|
||||
const doc = ownerDocument(rootRef.current);
|
||||
const loopFocus = nativeEvent => {
|
||||
lastKeydown.current = nativeEvent;
|
||||
if (disableEnforceFocus || !isEnabled() || nativeEvent.key !== 'Tab') {
|
||||
return;
|
||||
}
|
||||
|
||||
// Make sure the next tab starts from the right place.
|
||||
// doc.activeElement refers to the origin.
|
||||
if (doc.activeElement === rootRef.current && nativeEvent.shiftKey) {
|
||||
// We need to ignore the next contain as
|
||||
// it will try to move the focus back to the rootRef element.
|
||||
ignoreNextEnforceFocus.current = true;
|
||||
if (sentinelEnd.current) {
|
||||
sentinelEnd.current.focus();
|
||||
}
|
||||
}
|
||||
};
|
||||
const contain = () => {
|
||||
const rootElement = rootRef.current;
|
||||
|
||||
// Cleanup functions are executed lazily in React 17.
|
||||
// Contain can be called between the component being unmounted and its cleanup function being run.
|
||||
if (rootElement === null) {
|
||||
return;
|
||||
}
|
||||
if (!doc.hasFocus() || !isEnabled() || ignoreNextEnforceFocus.current) {
|
||||
ignoreNextEnforceFocus.current = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// The focus is already inside
|
||||
if (rootElement.contains(doc.activeElement)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// The disableEnforceFocus is set and the focus is outside of the focus trap (and sentinel nodes)
|
||||
if (disableEnforceFocus && doc.activeElement !== sentinelStart.current && doc.activeElement !== sentinelEnd.current) {
|
||||
return;
|
||||
}
|
||||
|
||||
// if the focus event is not coming from inside the children's react tree, reset the refs
|
||||
if (doc.activeElement !== reactFocusEventTarget.current) {
|
||||
reactFocusEventTarget.current = null;
|
||||
} else if (reactFocusEventTarget.current !== null) {
|
||||
return;
|
||||
}
|
||||
if (!activated.current) {
|
||||
return;
|
||||
}
|
||||
let tabbable = [];
|
||||
if (doc.activeElement === sentinelStart.current || doc.activeElement === sentinelEnd.current) {
|
||||
tabbable = getTabbable(rootRef.current);
|
||||
}
|
||||
|
||||
// one of the sentinel nodes was focused, so move the focus
|
||||
// to the first/last tabbable element inside the focus trap
|
||||
if (tabbable.length > 0) {
|
||||
const isShiftTab = Boolean(lastKeydown.current?.shiftKey && lastKeydown.current?.key === 'Tab');
|
||||
const focusNext = tabbable[0];
|
||||
const focusPrevious = tabbable[tabbable.length - 1];
|
||||
if (typeof focusNext !== 'string' && typeof focusPrevious !== 'string') {
|
||||
if (isShiftTab) {
|
||||
focusPrevious.focus();
|
||||
} else {
|
||||
focusNext.focus();
|
||||
}
|
||||
}
|
||||
// no tabbable elements in the trap focus or the focus was outside of the focus trap
|
||||
} else {
|
||||
rootElement.focus();
|
||||
}
|
||||
};
|
||||
doc.addEventListener('focusin', contain);
|
||||
doc.addEventListener('keydown', loopFocus, true);
|
||||
|
||||
// With Edge, Safari and Firefox, no focus related events are fired when the focused area stops being a focused area.
|
||||
// for example https://bugzilla.mozilla.org/show_bug.cgi?id=559561.
|
||||
// Instead, we can look if the active element was restored on the BODY element.
|
||||
//
|
||||
// The whatwg spec defines how the browser should behave but does not explicitly mention any events:
|
||||
// https://html.spec.whatwg.org/multipage/interaction.html#focus-fixup-rule.
|
||||
const interval = setInterval(() => {
|
||||
if (doc.activeElement && doc.activeElement.tagName === 'BODY') {
|
||||
contain();
|
||||
}
|
||||
}, 50);
|
||||
return () => {
|
||||
clearInterval(interval);
|
||||
doc.removeEventListener('focusin', contain);
|
||||
doc.removeEventListener('keydown', loopFocus, true);
|
||||
};
|
||||
}, [disableAutoFocus, disableEnforceFocus, disableRestoreFocus, isEnabled, open, getTabbable]);
|
||||
const onFocus = event => {
|
||||
if (nodeToRestore.current === null) {
|
||||
nodeToRestore.current = event.relatedTarget;
|
||||
}
|
||||
activated.current = true;
|
||||
reactFocusEventTarget.current = event.target;
|
||||
const childrenPropsHandler = children.props.onFocus;
|
||||
if (childrenPropsHandler) {
|
||||
childrenPropsHandler(event);
|
||||
}
|
||||
};
|
||||
const handleFocusSentinel = event => {
|
||||
if (nodeToRestore.current === null) {
|
||||
nodeToRestore.current = event.relatedTarget;
|
||||
}
|
||||
activated.current = true;
|
||||
};
|
||||
return /*#__PURE__*/_jsxs(React.Fragment, {
|
||||
children: [/*#__PURE__*/_jsx("div", {
|
||||
tabIndex: open ? 0 : -1,
|
||||
onFocus: handleFocusSentinel,
|
||||
ref: sentinelStart,
|
||||
"data-testid": "sentinelStart"
|
||||
}), /*#__PURE__*/React.cloneElement(children, {
|
||||
ref: handleRef,
|
||||
onFocus
|
||||
}), /*#__PURE__*/_jsx("div", {
|
||||
tabIndex: open ? 0 : -1,
|
||||
onFocus: handleFocusSentinel,
|
||||
ref: sentinelEnd,
|
||||
"data-testid": "sentinelEnd"
|
||||
})]
|
||||
});
|
||||
}
|
||||
process.env.NODE_ENV !== "production" ? FocusTrap.propTypes /* remove-proptypes */ = {
|
||||
// ┌────────────────────────────── Warning ──────────────────────────────┐
|
||||
// │ These PropTypes are generated from the TypeScript type definitions. │
|
||||
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
|
||||
// └─────────────────────────────────────────────────────────────────────┘
|
||||
/**
|
||||
* A single child content element.
|
||||
*/
|
||||
children: elementAcceptingRef,
|
||||
/**
|
||||
* If `true`, the focus trap will not automatically shift focus to itself when it opens, and
|
||||
* replace it to the last focused element when it closes.
|
||||
* This also works correctly with any focus trap children that have the `disableAutoFocus` prop.
|
||||
*
|
||||
* Generally this should never be set to `true` as it makes the focus trap less
|
||||
* accessible to assistive technologies, like screen readers.
|
||||
* @default false
|
||||
*/
|
||||
disableAutoFocus: PropTypes.bool,
|
||||
/**
|
||||
* If `true`, the focus trap will not prevent focus from leaving the focus trap while open.
|
||||
*
|
||||
* Generally this should never be set to `true` as it makes the focus trap less
|
||||
* accessible to assistive technologies, like screen readers.
|
||||
* @default false
|
||||
*/
|
||||
disableEnforceFocus: PropTypes.bool,
|
||||
/**
|
||||
* If `true`, the focus trap will not restore focus to previously focused element once
|
||||
* focus trap is hidden or unmounted.
|
||||
* @default false
|
||||
*/
|
||||
disableRestoreFocus: PropTypes.bool,
|
||||
/**
|
||||
* Returns an array of ordered tabbable nodes (i.e. in tab order) within the root.
|
||||
* For instance, you can provide the "tabbable" npm dependency.
|
||||
* @param {HTMLElement} root
|
||||
*/
|
||||
getTabbable: PropTypes.func,
|
||||
/**
|
||||
* This prop extends the `open` prop.
|
||||
* It allows to toggle the open state without having to wait for a rerender when changing the `open` prop.
|
||||
* This prop should be memoized.
|
||||
* It can be used to support multiple focus trap mounted at the same time.
|
||||
* @default function defaultIsEnabled(): boolean {
|
||||
* return true;
|
||||
* }
|
||||
*/
|
||||
isEnabled: PropTypes.func,
|
||||
/**
|
||||
* If `true`, focus is locked.
|
||||
*/
|
||||
open: PropTypes.bool.isRequired
|
||||
} : void 0;
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
// eslint-disable-next-line
|
||||
FocusTrap['propTypes' + ''] = exactProp(FocusTrap.propTypes);
|
||||
}
|
||||
export { FocusTrap };
|
||||
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
export { FocusTrap } from './FocusTrap';
|
||||
export * from './FocusTrap.types';
|
||||
+199
@@ -0,0 +1,199 @@
|
||||
'use client';
|
||||
|
||||
import _extends from "@babel/runtime/helpers/esm/extends";
|
||||
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
||||
const _excluded = ["defaultValue", "children", "disabled", "error", "onChange", "required", "slotProps", "slots", "value"];
|
||||
import * as React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import useControlled from '@mui/utils/useControlled';
|
||||
import { FormControlContext } from './FormControlContext';
|
||||
import { getFormControlUtilityClass } from './formControlClasses';
|
||||
import { useSlotProps } from '../utils';
|
||||
import { unstable_composeClasses as composeClasses } from '../composeClasses';
|
||||
import { useClassNamesOverride } from '../utils/ClassNameConfigurator';
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
function hasValue(value) {
|
||||
return value != null && !(Array.isArray(value) && value.length === 0) && value !== '';
|
||||
}
|
||||
function useUtilityClasses(ownerState) {
|
||||
const {
|
||||
disabled,
|
||||
error,
|
||||
filled,
|
||||
focused,
|
||||
required
|
||||
} = ownerState;
|
||||
const slots = {
|
||||
root: ['root', disabled && 'disabled', focused && 'focused', error && 'error', filled && 'filled', required && 'required']
|
||||
};
|
||||
return composeClasses(slots, useClassNamesOverride(getFormControlUtilityClass));
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides context such as filled/focused/error/required for form inputs.
|
||||
* Relying on the context provides high flexibility and ensures that the state always stays
|
||||
* consistent across the children of the `FormControl`.
|
||||
* This context is used by the following components:
|
||||
*
|
||||
* * FormLabel
|
||||
* * FormHelperText
|
||||
* * Input
|
||||
* * InputLabel
|
||||
*
|
||||
* You can find one composition example below and more going to [the demos](https://mui.com/material-ui/react-text-field/#components).
|
||||
*
|
||||
* ```jsx
|
||||
* <FormControl>
|
||||
* <InputLabel htmlFor="my-input">Email address</InputLabel>
|
||||
* <Input id="my-input" aria-describedby="my-helper-text" />
|
||||
* <FormHelperText id="my-helper-text">We'll never share your email.</FormHelperText>
|
||||
* </FormControl>
|
||||
* ```
|
||||
*
|
||||
* ⚠️ Only one `Input` can be used within a FormControl because it create visual inconsistencies.
|
||||
* For instance, only one input can be focused at the same time, the state shouldn't be shared.
|
||||
*
|
||||
* Demos:
|
||||
*
|
||||
* - [Form Control](https://mui.com/base-ui/react-form-control/)
|
||||
* - [Input](https://mui.com/joy-ui/react-input/)
|
||||
* - [Checkbox](https://mui.com/material-ui/react-checkbox/)
|
||||
* - [Radio Group](https://mui.com/material-ui/react-radio-button/)
|
||||
* - [Switch](https://mui.com/material-ui/react-switch/)
|
||||
* - [Text Field](https://mui.com/material-ui/react-text-field/)
|
||||
*
|
||||
* API:
|
||||
*
|
||||
* - [FormControl API](https://mui.com/base-ui/react-form-control/components-api/#form-control)
|
||||
*/
|
||||
const FormControl = /*#__PURE__*/React.forwardRef(function FormControl(props, forwardedRef) {
|
||||
const {
|
||||
defaultValue,
|
||||
children,
|
||||
disabled = false,
|
||||
error = false,
|
||||
onChange,
|
||||
required = false,
|
||||
slotProps = {},
|
||||
slots = {},
|
||||
value: incomingValue
|
||||
} = props,
|
||||
other = _objectWithoutPropertiesLoose(props, _excluded);
|
||||
const [value, setValue] = useControlled({
|
||||
controlled: incomingValue,
|
||||
default: defaultValue,
|
||||
name: 'FormControl',
|
||||
state: 'value'
|
||||
});
|
||||
const filled = hasValue(value);
|
||||
const [focusedState, setFocused] = React.useState(false);
|
||||
const focused = focusedState && !disabled;
|
||||
React.useEffect(() => setFocused(isFocused => disabled ? false : isFocused), [disabled]);
|
||||
const ownerState = _extends({}, props, {
|
||||
disabled,
|
||||
error,
|
||||
filled,
|
||||
focused,
|
||||
required
|
||||
});
|
||||
const childContext = React.useMemo(() => {
|
||||
return {
|
||||
disabled,
|
||||
error,
|
||||
filled,
|
||||
focused,
|
||||
onBlur: () => {
|
||||
setFocused(false);
|
||||
},
|
||||
onChange: event => {
|
||||
setValue(event.target.value);
|
||||
onChange?.(event);
|
||||
},
|
||||
onFocus: () => {
|
||||
setFocused(true);
|
||||
},
|
||||
required,
|
||||
value: value ?? ''
|
||||
};
|
||||
}, [disabled, error, filled, focused, onChange, required, setValue, value]);
|
||||
const classes = useUtilityClasses(ownerState);
|
||||
const renderChildren = () => {
|
||||
if (typeof children === 'function') {
|
||||
return children(childContext);
|
||||
}
|
||||
return children;
|
||||
};
|
||||
const Root = slots.root ?? 'div';
|
||||
const rootProps = useSlotProps({
|
||||
elementType: Root,
|
||||
externalSlotProps: slotProps.root,
|
||||
externalForwardedProps: other,
|
||||
additionalProps: {
|
||||
ref: forwardedRef,
|
||||
children: renderChildren()
|
||||
},
|
||||
ownerState,
|
||||
className: classes.root
|
||||
});
|
||||
return /*#__PURE__*/_jsx(FormControlContext.Provider, {
|
||||
value: childContext,
|
||||
children: /*#__PURE__*/_jsx(Root, _extends({}, rootProps))
|
||||
});
|
||||
});
|
||||
process.env.NODE_ENV !== "production" ? FormControl.propTypes /* remove-proptypes */ = {
|
||||
// ┌────────────────────────────── Warning ──────────────────────────────┐
|
||||
// │ These PropTypes are generated from the TypeScript type definitions. │
|
||||
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
|
||||
// └─────────────────────────────────────────────────────────────────────┘
|
||||
/**
|
||||
* The content of the component.
|
||||
*/
|
||||
children: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.node, PropTypes.func]),
|
||||
/**
|
||||
* Class name applied to the root element.
|
||||
*/
|
||||
className: PropTypes.string,
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
defaultValue: PropTypes.any,
|
||||
/**
|
||||
* If `true`, the label, input and helper text should be displayed in a disabled state.
|
||||
* @default false
|
||||
*/
|
||||
disabled: PropTypes.bool,
|
||||
/**
|
||||
* If `true`, the label is displayed in an error state.
|
||||
* @default false
|
||||
*/
|
||||
error: PropTypes.bool,
|
||||
/**
|
||||
* Callback fired when the form element's value is modified.
|
||||
*/
|
||||
onChange: PropTypes.func,
|
||||
/**
|
||||
* If `true`, the label will indicate that the `input` is required.
|
||||
* @default false
|
||||
*/
|
||||
required: PropTypes.bool,
|
||||
/**
|
||||
* The props used for each slot inside the FormControl.
|
||||
* @default {}
|
||||
*/
|
||||
slotProps: PropTypes.shape({
|
||||
root: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
|
||||
}),
|
||||
/**
|
||||
* The components used for each slot inside the FormControl.
|
||||
* Either a string to use a HTML element or a component.
|
||||
* @default {}
|
||||
*/
|
||||
slots: PropTypes.shape({
|
||||
root: PropTypes.elementType
|
||||
}),
|
||||
/**
|
||||
* The value of the form element.
|
||||
*/
|
||||
value: PropTypes.any
|
||||
} : void 0;
|
||||
export { FormControl };
|
||||
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
import * as React from 'react';
|
||||
/**
|
||||
* @ignore - internal component.
|
||||
*/
|
||||
const FormControlContext = /*#__PURE__*/React.createContext(undefined);
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
FormControlContext.displayName = 'FormControlContext';
|
||||
}
|
||||
export { FormControlContext };
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import { generateUtilityClass } from '../generateUtilityClass';
|
||||
import { generateUtilityClasses } from '../generateUtilityClasses';
|
||||
const COMPONENT_NAME = 'FormControl';
|
||||
export function getFormControlUtilityClass(slot) {
|
||||
return generateUtilityClass(COMPONENT_NAME, slot);
|
||||
}
|
||||
export const formControlClasses = generateUtilityClasses(COMPONENT_NAME, ['root', 'disabled', 'error', 'filled', 'focused', 'required']);
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
export { FormControl } from './FormControl';
|
||||
export { FormControlContext } from './FormControlContext';
|
||||
export * from './FormControl.types';
|
||||
export * from './formControlClasses';
|
||||
export { useFormControlContext } from './useFormControlContext';
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
'use client';
|
||||
|
||||
import * as React from 'react';
|
||||
import { FormControlContext } from './FormControlContext';
|
||||
/**
|
||||
*
|
||||
* Demos:
|
||||
*
|
||||
* - [Form Control](https://mui.com/base-ui/react-form-control/#hook)
|
||||
*
|
||||
* API:
|
||||
*
|
||||
* - [useFormControlContext API](https://mui.com/base-ui/react-form-control/hooks-api/#use-form-control-context)
|
||||
*/
|
||||
export function useFormControlContext() {
|
||||
return React.useContext(FormControlContext);
|
||||
}
|
||||
+310
@@ -0,0 +1,310 @@
|
||||
'use client';
|
||||
|
||||
import _extends from "@babel/runtime/helpers/esm/extends";
|
||||
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
||||
const _excluded = ["aria-describedby", "aria-label", "aria-labelledby", "autoComplete", "autoFocus", "className", "defaultValue", "disabled", "endAdornment", "error", "id", "multiline", "name", "onClick", "onChange", "onKeyDown", "onKeyUp", "onFocus", "onBlur", "placeholder", "readOnly", "required", "startAdornment", "value", "type", "rows", "slotProps", "slots", "minRows", "maxRows"];
|
||||
import * as React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { isHostComponent } from '../utils/isHostComponent';
|
||||
import { getInputUtilityClass } from './inputClasses';
|
||||
import { useInput } from '../useInput';
|
||||
import { useSlotProps } from '../utils';
|
||||
import { unstable_composeClasses as composeClasses } from '../composeClasses';
|
||||
import { useClassNamesOverride } from '../utils/ClassNameConfigurator';
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
import { jsxs as _jsxs } from "react/jsx-runtime";
|
||||
const useUtilityClasses = ownerState => {
|
||||
const {
|
||||
disabled,
|
||||
error,
|
||||
focused,
|
||||
formControlContext,
|
||||
multiline,
|
||||
startAdornment,
|
||||
endAdornment
|
||||
} = ownerState;
|
||||
const slots = {
|
||||
root: ['root', disabled && 'disabled', error && 'error', focused && 'focused', Boolean(formControlContext) && 'formControl', multiline && 'multiline', Boolean(startAdornment) && 'adornedStart', Boolean(endAdornment) && 'adornedEnd'],
|
||||
input: ['input', disabled && 'disabled', multiline && 'multiline']
|
||||
};
|
||||
return composeClasses(slots, useClassNamesOverride(getInputUtilityClass));
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* Demos:
|
||||
*
|
||||
* - [Input](https://mui.com/base-ui/react-input/)
|
||||
*
|
||||
* API:
|
||||
*
|
||||
* - [Input API](https://mui.com/base-ui/react-input/components-api/#input)
|
||||
*/
|
||||
const Input = /*#__PURE__*/React.forwardRef(function Input(props, forwardedRef) {
|
||||
const {
|
||||
'aria-describedby': ariaDescribedby,
|
||||
'aria-label': ariaLabel,
|
||||
'aria-labelledby': ariaLabelledby,
|
||||
autoComplete,
|
||||
autoFocus,
|
||||
className,
|
||||
defaultValue,
|
||||
disabled,
|
||||
endAdornment,
|
||||
error,
|
||||
id,
|
||||
multiline = false,
|
||||
name,
|
||||
onClick,
|
||||
onChange,
|
||||
onKeyDown,
|
||||
onKeyUp,
|
||||
onFocus,
|
||||
onBlur,
|
||||
placeholder,
|
||||
readOnly,
|
||||
required,
|
||||
startAdornment,
|
||||
value,
|
||||
type: typeProp,
|
||||
rows,
|
||||
slotProps = {},
|
||||
slots = {},
|
||||
minRows,
|
||||
maxRows
|
||||
} = props,
|
||||
other = _objectWithoutPropertiesLoose(props, _excluded);
|
||||
const {
|
||||
getRootProps,
|
||||
getInputProps,
|
||||
focused,
|
||||
formControlContext,
|
||||
error: errorState,
|
||||
disabled: disabledState
|
||||
} = useInput({
|
||||
disabled,
|
||||
defaultValue,
|
||||
error,
|
||||
onBlur,
|
||||
onClick,
|
||||
onChange,
|
||||
onFocus,
|
||||
required,
|
||||
value
|
||||
});
|
||||
const type = !multiline ? typeProp ?? 'text' : undefined;
|
||||
const ownerState = _extends({}, props, {
|
||||
disabled: disabledState,
|
||||
error: errorState,
|
||||
focused,
|
||||
formControlContext,
|
||||
multiline,
|
||||
type
|
||||
});
|
||||
const classes = useUtilityClasses(ownerState);
|
||||
const propsToForward = {
|
||||
'aria-describedby': ariaDescribedby,
|
||||
'aria-label': ariaLabel,
|
||||
'aria-labelledby': ariaLabelledby,
|
||||
autoComplete,
|
||||
autoFocus,
|
||||
id,
|
||||
onKeyDown,
|
||||
onKeyUp,
|
||||
name,
|
||||
placeholder,
|
||||
readOnly,
|
||||
type
|
||||
};
|
||||
const Root = slots.root ?? 'div';
|
||||
const rootProps = useSlotProps({
|
||||
elementType: Root,
|
||||
getSlotProps: getRootProps,
|
||||
externalSlotProps: slotProps.root,
|
||||
externalForwardedProps: other,
|
||||
additionalProps: {
|
||||
ref: forwardedRef
|
||||
},
|
||||
ownerState,
|
||||
className: [classes.root, className]
|
||||
});
|
||||
const InputComponent = multiline ? slots.textarea ?? 'textarea' : slots.input ?? 'input';
|
||||
const inputProps = useSlotProps({
|
||||
elementType: InputComponent,
|
||||
getSlotProps: otherHandlers => {
|
||||
return getInputProps(_extends({}, propsToForward, otherHandlers));
|
||||
},
|
||||
externalSlotProps: slotProps.input,
|
||||
additionalProps: _extends({
|
||||
rows: multiline ? rows : undefined
|
||||
}, multiline && !isHostComponent(InputComponent) && {
|
||||
minRows: rows || minRows,
|
||||
maxRows: rows || maxRows
|
||||
}),
|
||||
ownerState,
|
||||
className: classes.input
|
||||
});
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
if (multiline) {
|
||||
if (rows) {
|
||||
if (minRows || maxRows) {
|
||||
console.warn('MUI: You can not use the `minRows` or `maxRows` props when the input `rows` prop is set.');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return /*#__PURE__*/_jsxs(Root, _extends({}, rootProps, {
|
||||
children: [startAdornment, /*#__PURE__*/_jsx(InputComponent, _extends({}, inputProps)), endAdornment]
|
||||
}));
|
||||
});
|
||||
process.env.NODE_ENV !== "production" ? Input.propTypes /* remove-proptypes */ = {
|
||||
// ┌────────────────────────────── Warning ──────────────────────────────┐
|
||||
// │ These PropTypes are generated from the TypeScript type definitions. │
|
||||
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
|
||||
// └─────────────────────────────────────────────────────────────────────┘
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
'aria-describedby': PropTypes.string,
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
'aria-label': PropTypes.string,
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
'aria-labelledby': PropTypes.string,
|
||||
/**
|
||||
* This prop helps users to fill forms faster, especially on mobile devices.
|
||||
* The name can be confusing, as it's more like an autofill.
|
||||
* You can learn more about it [following the specification](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill).
|
||||
*/
|
||||
autoComplete: PropTypes.string,
|
||||
/**
|
||||
* If `true`, the `input` element is focused during the first mount.
|
||||
*/
|
||||
autoFocus: PropTypes.bool,
|
||||
/**
|
||||
* Class name applied to the root element.
|
||||
*/
|
||||
className: PropTypes.string,
|
||||
/**
|
||||
* The default value. Use when the component is not controlled.
|
||||
*/
|
||||
defaultValue: PropTypes.any,
|
||||
/**
|
||||
* If `true`, the component is disabled.
|
||||
* The prop defaults to the value (`false`) inherited from the parent FormControl component.
|
||||
*/
|
||||
disabled: PropTypes.bool,
|
||||
/**
|
||||
* Trailing adornment for this input.
|
||||
*/
|
||||
endAdornment: PropTypes.node,
|
||||
/**
|
||||
* If `true`, the `input` will indicate an error by setting the `aria-invalid` attribute on the input and the `baseui--error` class on the root element.
|
||||
* The prop defaults to the value (`false`) inherited from the parent FormControl component.
|
||||
*/
|
||||
error: PropTypes.bool,
|
||||
/**
|
||||
* The id of the `input` element.
|
||||
*/
|
||||
id: PropTypes.string,
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
inputRef: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
|
||||
current: PropTypes.object
|
||||
})]),
|
||||
/**
|
||||
* Maximum number of rows to display when multiline option is set to true.
|
||||
*/
|
||||
maxRows: PropTypes.number,
|
||||
/**
|
||||
* Minimum number of rows to display when multiline option is set to true.
|
||||
*/
|
||||
minRows: PropTypes.number,
|
||||
/**
|
||||
* If `true`, a `textarea` element is rendered.
|
||||
* @default false
|
||||
*/
|
||||
multiline: PropTypes.bool,
|
||||
/**
|
||||
* Name attribute of the `input` element.
|
||||
*/
|
||||
name: PropTypes.string,
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
onBlur: PropTypes.func,
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
onChange: PropTypes.func,
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
onClick: PropTypes.func,
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
onFocus: PropTypes.func,
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
onKeyDown: PropTypes.func,
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
onKeyUp: PropTypes.func,
|
||||
/**
|
||||
* The short hint displayed in the `input` before the user enters a value.
|
||||
*/
|
||||
placeholder: PropTypes.string,
|
||||
/**
|
||||
* It prevents the user from changing the value of the field
|
||||
* (not from interacting with the field).
|
||||
*/
|
||||
readOnly: PropTypes.bool,
|
||||
/**
|
||||
* If `true`, the `input` element is required.
|
||||
* The prop defaults to the value (`false`) inherited from the parent FormControl component.
|
||||
*/
|
||||
required: PropTypes.bool,
|
||||
/**
|
||||
* Number of rows to display when multiline option is set to true.
|
||||
*/
|
||||
rows: PropTypes.number,
|
||||
/**
|
||||
* The props used for each slot inside the Input.
|
||||
* @default {}
|
||||
*/
|
||||
slotProps: PropTypes.shape({
|
||||
input: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
||||
root: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
|
||||
}),
|
||||
/**
|
||||
* The components used for each slot inside the InputBase.
|
||||
* Either a string to use a HTML element or a component.
|
||||
* @default {}
|
||||
*/
|
||||
slots: PropTypes.shape({
|
||||
input: PropTypes.elementType,
|
||||
root: PropTypes.elementType,
|
||||
textarea: PropTypes.elementType
|
||||
}),
|
||||
/**
|
||||
* Leading adornment for this input.
|
||||
*/
|
||||
startAdornment: PropTypes.node,
|
||||
/**
|
||||
* Type of the `input` element. It should be [a valid HTML5 input type](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#Form_%3Cinput%3E_types).
|
||||
* @default 'text'
|
||||
*/
|
||||
type: PropTypes /* @typescript-to-proptypes-ignore */.oneOf(['button', 'checkbox', 'color', 'date', 'datetime-local', 'email', 'file', 'hidden', 'image', 'month', 'number', 'password', 'radio', 'range', 'reset', 'search', 'submit', 'tel', 'text', 'time', 'url', 'week']),
|
||||
/**
|
||||
* The value of the `input` element, required for a controlled component.
|
||||
*/
|
||||
value: PropTypes.any
|
||||
} : void 0;
|
||||
export { Input };
|
||||
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
'use client';
|
||||
|
||||
export { Input } from './Input';
|
||||
export * from './Input.types';
|
||||
export * from './inputClasses';
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import { generateUtilityClass } from '../generateUtilityClass';
|
||||
import { generateUtilityClasses } from '../generateUtilityClasses';
|
||||
const COMPONENT_NAME = 'Input';
|
||||
export function getInputUtilityClass(slot) {
|
||||
return generateUtilityClass(COMPONENT_NAME, slot);
|
||||
}
|
||||
export const inputClasses = generateUtilityClasses(COMPONENT_NAME, ['root', 'formControl', 'focused', 'disabled', 'error', 'multiline', 'input', 'inputMultiline', 'inputTypeSearch', 'adornedStart', 'adornedEnd']);
|
||||
+160
@@ -0,0 +1,160 @@
|
||||
'use client';
|
||||
|
||||
import _extends from "@babel/runtime/helpers/esm/extends";
|
||||
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
||||
const _excluded = ["actions", "anchor", "children", "onItemsChange", "slotProps", "slots"];
|
||||
import * as React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { HTMLElementType, refType } from '@mui/utils';
|
||||
import { getMenuUtilityClass } from './menuClasses';
|
||||
import { useMenu } from '../useMenu';
|
||||
import { MenuProvider } from '../useMenu/MenuProvider';
|
||||
import { unstable_composeClasses as composeClasses } from '../composeClasses';
|
||||
import { Unstable_Popup as Popup } from '../Unstable_Popup';
|
||||
import { useSlotProps } from '../utils/useSlotProps';
|
||||
import { useClassNamesOverride } from '../utils/ClassNameConfigurator';
|
||||
import { ListActionTypes } from '../useList';
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
function useUtilityClasses(ownerState) {
|
||||
const {
|
||||
open
|
||||
} = ownerState;
|
||||
const slots = {
|
||||
root: ['root', open && 'expanded'],
|
||||
listbox: ['listbox', open && 'expanded']
|
||||
};
|
||||
return composeClasses(slots, useClassNamesOverride(getMenuUtilityClass));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Demos:
|
||||
*
|
||||
* - [Menu](https://mui.com/base-ui/react-menu/)
|
||||
*
|
||||
* API:
|
||||
*
|
||||
* - [Menu API](https://mui.com/base-ui/react-menu/components-api/#menu)
|
||||
*/
|
||||
const Menu = /*#__PURE__*/React.forwardRef(function Menu(props, forwardedRef) {
|
||||
const {
|
||||
actions,
|
||||
anchor: anchorProp,
|
||||
children,
|
||||
onItemsChange,
|
||||
slotProps = {},
|
||||
slots = {}
|
||||
} = props,
|
||||
other = _objectWithoutPropertiesLoose(props, _excluded);
|
||||
const {
|
||||
contextValue,
|
||||
getListboxProps,
|
||||
dispatch,
|
||||
open,
|
||||
triggerElement
|
||||
} = useMenu({
|
||||
onItemsChange,
|
||||
componentName: 'Menu'
|
||||
});
|
||||
const anchor = anchorProp ?? triggerElement;
|
||||
React.useImperativeHandle(actions, () => ({
|
||||
dispatch,
|
||||
resetHighlight: () => dispatch({
|
||||
type: ListActionTypes.resetHighlight,
|
||||
event: null
|
||||
})
|
||||
}), [dispatch]);
|
||||
const ownerState = _extends({}, props, {
|
||||
open
|
||||
});
|
||||
const classes = useUtilityClasses(ownerState);
|
||||
const Root = slots.root ?? 'div';
|
||||
const rootProps = useSlotProps({
|
||||
elementType: Root,
|
||||
externalSlotProps: slotProps.root,
|
||||
externalForwardedProps: other,
|
||||
additionalProps: {
|
||||
ref: forwardedRef,
|
||||
role: undefined
|
||||
},
|
||||
className: classes.root,
|
||||
ownerState
|
||||
});
|
||||
const Listbox = slots.listbox ?? 'ul';
|
||||
const listboxProps = useSlotProps({
|
||||
elementType: Listbox,
|
||||
getSlotProps: getListboxProps,
|
||||
externalSlotProps: slotProps.listbox,
|
||||
className: classes.listbox,
|
||||
ownerState
|
||||
});
|
||||
if (open === true && anchor == null) {
|
||||
return /*#__PURE__*/_jsx(Root, _extends({}, rootProps, {
|
||||
children: /*#__PURE__*/_jsx(Listbox, _extends({}, listboxProps, {
|
||||
children: /*#__PURE__*/_jsx(MenuProvider, {
|
||||
value: contextValue,
|
||||
children: children
|
||||
})
|
||||
}))
|
||||
}));
|
||||
}
|
||||
return /*#__PURE__*/_jsx(Popup, _extends({
|
||||
keepMounted: true
|
||||
}, rootProps, {
|
||||
open: open,
|
||||
anchor: anchor,
|
||||
slots: {
|
||||
root: Root
|
||||
},
|
||||
children: /*#__PURE__*/_jsx(Listbox, _extends({}, listboxProps, {
|
||||
children: /*#__PURE__*/_jsx(MenuProvider, {
|
||||
value: contextValue,
|
||||
children: children
|
||||
})
|
||||
}))
|
||||
}));
|
||||
});
|
||||
process.env.NODE_ENV !== "production" ? Menu.propTypes /* remove-proptypes */ = {
|
||||
// ┌────────────────────────────── Warning ──────────────────────────────┐
|
||||
// │ These PropTypes are generated from the TypeScript type definitions. │
|
||||
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
|
||||
// └─────────────────────────────────────────────────────────────────────┘
|
||||
/**
|
||||
* A ref with imperative actions that can be performed on the menu.
|
||||
*/
|
||||
actions: refType,
|
||||
/**
|
||||
* The element based on which the menu is positioned.
|
||||
*/
|
||||
anchor: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([HTMLElementType, PropTypes.object, PropTypes.func]),
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
children: PropTypes.node,
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
className: PropTypes.string,
|
||||
/**
|
||||
* Function called when the items displayed in the menu change.
|
||||
*/
|
||||
onItemsChange: PropTypes.func,
|
||||
/**
|
||||
* The props used for each slot inside the Menu.
|
||||
* @default {}
|
||||
*/
|
||||
slotProps: PropTypes.shape({
|
||||
listbox: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
||||
root: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
|
||||
}),
|
||||
/**
|
||||
* The components used for each slot inside the Menu.
|
||||
* Either a string to use a HTML element or a component.
|
||||
* @default {}
|
||||
*/
|
||||
slots: PropTypes.shape({
|
||||
listbox: PropTypes.elementType,
|
||||
root: PropTypes.elementType
|
||||
})
|
||||
} : void 0;
|
||||
export { Menu };
|
||||
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
export { Menu } from './Menu';
|
||||
export * from './menuClasses';
|
||||
export * from './Menu.types';
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import { generateUtilityClass } from '../generateUtilityClass';
|
||||
import { generateUtilityClasses } from '../generateUtilityClasses';
|
||||
const COMPONENT_NAME = 'Menu';
|
||||
export function getMenuUtilityClass(slot) {
|
||||
return generateUtilityClass(COMPONENT_NAME, slot);
|
||||
}
|
||||
export const menuClasses = generateUtilityClasses(COMPONENT_NAME, ['root', 'listbox', 'expanded']);
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
'use client';
|
||||
|
||||
import _extends from "@babel/runtime/helpers/esm/extends";
|
||||
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
||||
const _excluded = ["children", "disabled", "label", "slots", "slotProps", "focusableWhenDisabled"];
|
||||
import * as React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { useSlotProps } from '../utils';
|
||||
import { useMenuButton } from '../useMenuButton';
|
||||
import { unstable_composeClasses as composeClasses } from '../composeClasses';
|
||||
import { useClassNamesOverride } from '../utils/ClassNameConfigurator';
|
||||
import { getMenuButtonUtilityClass } from './menuButtonClasses';
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
const useUtilityClasses = ownerState => {
|
||||
const {
|
||||
active,
|
||||
disabled,
|
||||
open
|
||||
} = ownerState;
|
||||
const slots = {
|
||||
root: ['root', disabled && 'disabled', active && 'active', open && 'expanded']
|
||||
};
|
||||
return composeClasses(slots, useClassNamesOverride(getMenuButtonUtilityClass));
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* Demos:
|
||||
*
|
||||
* - [Menu](https://mui.com/base-ui/react-menu/)
|
||||
*
|
||||
* API:
|
||||
*
|
||||
* - [MenuButton API](https://mui.com/base-ui/react-menu/components-api/#menu-button)
|
||||
*/
|
||||
const MenuButton = /*#__PURE__*/React.forwardRef(function MenuButton(props, forwardedRef) {
|
||||
const {
|
||||
children,
|
||||
disabled = false,
|
||||
slots = {},
|
||||
slotProps = {},
|
||||
focusableWhenDisabled = false
|
||||
} = props,
|
||||
other = _objectWithoutPropertiesLoose(props, _excluded);
|
||||
const {
|
||||
getRootProps,
|
||||
open,
|
||||
active
|
||||
} = useMenuButton({
|
||||
disabled,
|
||||
focusableWhenDisabled,
|
||||
rootRef: forwardedRef
|
||||
});
|
||||
const ownerState = _extends({}, props, {
|
||||
open,
|
||||
active,
|
||||
disabled,
|
||||
focusableWhenDisabled
|
||||
});
|
||||
const classes = useUtilityClasses(ownerState);
|
||||
const Root = slots.root || 'button';
|
||||
const rootProps = useSlotProps({
|
||||
elementType: Root,
|
||||
getSlotProps: getRootProps,
|
||||
externalForwardedProps: other,
|
||||
externalSlotProps: slotProps.root,
|
||||
additionalProps: {
|
||||
ref: forwardedRef,
|
||||
type: 'button'
|
||||
},
|
||||
ownerState,
|
||||
className: classes.root
|
||||
});
|
||||
return /*#__PURE__*/_jsx(Root, _extends({}, rootProps, {
|
||||
children: children
|
||||
}));
|
||||
});
|
||||
process.env.NODE_ENV !== "production" ? MenuButton.propTypes /* remove-proptypes */ = {
|
||||
// ┌────────────────────────────── Warning ──────────────────────────────┐
|
||||
// │ These PropTypes are generated from the TypeScript type definitions. │
|
||||
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
|
||||
// └─────────────────────────────────────────────────────────────────────┘
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
children: PropTypes.node,
|
||||
/**
|
||||
* Class name applied to the root element.
|
||||
*/
|
||||
className: PropTypes.string,
|
||||
/**
|
||||
* If `true`, the component is disabled.
|
||||
* @default false
|
||||
*/
|
||||
disabled: PropTypes.bool,
|
||||
/**
|
||||
* If `true`, allows a disabled button to receive focus.
|
||||
* @default false
|
||||
*/
|
||||
focusableWhenDisabled: PropTypes.bool,
|
||||
/**
|
||||
* Label of the button
|
||||
*/
|
||||
label: PropTypes.string,
|
||||
/**
|
||||
* The components used for each slot inside the MenuButton.
|
||||
* Either a string to use a HTML element or a component.
|
||||
* @default {}
|
||||
*/
|
||||
slotProps: PropTypes.shape({
|
||||
root: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
|
||||
}),
|
||||
/**
|
||||
* The props used for each slot inside the MenuButton.
|
||||
* @default {}
|
||||
*/
|
||||
slots: PropTypes.shape({
|
||||
root: PropTypes.elementType
|
||||
})
|
||||
} : void 0;
|
||||
export { MenuButton };
|
||||
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
'use client';
|
||||
|
||||
export { MenuButton } from './MenuButton';
|
||||
export * from './MenuButton.types';
|
||||
export * from './menuButtonClasses';
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import { generateUtilityClass } from '../generateUtilityClass';
|
||||
import { generateUtilityClasses } from '../generateUtilityClasses';
|
||||
const COMPONENT_NAME = 'MenuButton';
|
||||
export function getMenuButtonUtilityClass(slot) {
|
||||
return generateUtilityClass(COMPONENT_NAME, slot);
|
||||
}
|
||||
export const menuButtonClasses = generateUtilityClasses(COMPONENT_NAME, ['root', 'active', 'disabled', 'expanded']);
|
||||
+147
@@ -0,0 +1,147 @@
|
||||
'use client';
|
||||
|
||||
import _extends from "@babel/runtime/helpers/esm/extends";
|
||||
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
||||
const _excluded = ["children", "disabled", "label", "id", "slotProps", "slots"];
|
||||
import * as React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { getMenuItemUtilityClass } from './menuItemClasses';
|
||||
import { useMenuItem, useMenuItemContextStabilizer } from '../useMenuItem';
|
||||
import { unstable_composeClasses as composeClasses } from '../composeClasses';
|
||||
import { useSlotProps } from '../utils/useSlotProps';
|
||||
import { useClassNamesOverride } from '../utils/ClassNameConfigurator';
|
||||
import { ListContext } from '../useList';
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
function useUtilityClasses(ownerState) {
|
||||
const {
|
||||
disabled,
|
||||
focusVisible
|
||||
} = ownerState;
|
||||
const slots = {
|
||||
root: ['root', disabled && 'disabled', focusVisible && 'focusVisible']
|
||||
};
|
||||
return composeClasses(slots, useClassNamesOverride(getMenuItemUtilityClass));
|
||||
}
|
||||
const InnerMenuItem = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef(function MenuItem(props, forwardedRef) {
|
||||
const {
|
||||
children,
|
||||
disabled: disabledProp = false,
|
||||
label,
|
||||
id,
|
||||
slotProps = {},
|
||||
slots = {}
|
||||
} = props,
|
||||
other = _objectWithoutPropertiesLoose(props, _excluded);
|
||||
const {
|
||||
getRootProps,
|
||||
disabled,
|
||||
focusVisible,
|
||||
highlighted
|
||||
} = useMenuItem({
|
||||
id,
|
||||
disabled: disabledProp,
|
||||
rootRef: forwardedRef,
|
||||
label
|
||||
});
|
||||
const ownerState = _extends({}, props, {
|
||||
disabled,
|
||||
focusVisible,
|
||||
highlighted
|
||||
});
|
||||
const classes = useUtilityClasses(ownerState);
|
||||
const Root = slots.root ?? 'li';
|
||||
const rootProps = useSlotProps({
|
||||
elementType: Root,
|
||||
getSlotProps: getRootProps,
|
||||
externalSlotProps: slotProps.root,
|
||||
externalForwardedProps: other,
|
||||
className: classes.root,
|
||||
ownerState
|
||||
});
|
||||
return /*#__PURE__*/_jsx(Root, _extends({}, rootProps, {
|
||||
children: children
|
||||
}));
|
||||
}));
|
||||
|
||||
/**
|
||||
* An unstyled menu item to be used within a Menu.
|
||||
*
|
||||
* Demos:
|
||||
*
|
||||
* - [Menu](https://mui.com/base-ui/react-menu/)
|
||||
*
|
||||
* API:
|
||||
*
|
||||
* - [MenuItem API](https://mui.com/base-ui/react-menu/components-api/#menu-item)
|
||||
*/
|
||||
const MenuItem = /*#__PURE__*/React.forwardRef(function MenuItem(props, ref) {
|
||||
const {
|
||||
id: idProp
|
||||
} = props;
|
||||
|
||||
// This wrapper component is used as a performance optimization.
|
||||
// `useMenuItemContextStabilizer` ensures that the context value
|
||||
// is stable across renders, so that the actual MenuItem re-renders
|
||||
// only when it needs to.
|
||||
const {
|
||||
contextValue,
|
||||
id
|
||||
} = useMenuItemContextStabilizer(idProp);
|
||||
return /*#__PURE__*/_jsx(ListContext.Provider, {
|
||||
value: contextValue,
|
||||
children: /*#__PURE__*/_jsx(InnerMenuItem, _extends({}, props, {
|
||||
id: id,
|
||||
ref: ref
|
||||
}))
|
||||
});
|
||||
});
|
||||
process.env.NODE_ENV !== "production" ? MenuItem.propTypes /* remove-proptypes */ = {
|
||||
// ┌────────────────────────────── Warning ──────────────────────────────┐
|
||||
// │ These PropTypes are generated from the TypeScript type definitions. │
|
||||
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
|
||||
// └─────────────────────────────────────────────────────────────────────┘
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
children: PropTypes.node,
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
className: PropTypes.string,
|
||||
/**
|
||||
* If `true`, the menu item will be disabled.
|
||||
* @default false
|
||||
*/
|
||||
disabled: PropTypes.bool,
|
||||
/**
|
||||
* If `true`, the menu item won't receive focus when the mouse moves over it.
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
disableFocusOnHover: PropTypes.bool,
|
||||
/**
|
||||
* A text representation of the menu item's content.
|
||||
* Used for keyboard text navigation matching.
|
||||
*/
|
||||
label: PropTypes.string,
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
onClick: PropTypes.func,
|
||||
/**
|
||||
* The props used for each slot inside the MenuItem.
|
||||
* @default {}
|
||||
*/
|
||||
slotProps: PropTypes.shape({
|
||||
root: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
|
||||
}),
|
||||
/**
|
||||
* The components used for each slot inside the MenuItem.
|
||||
* Either a string to use a HTML element or a component.
|
||||
* @default {}
|
||||
*/
|
||||
slots: PropTypes.shape({
|
||||
root: PropTypes.elementType
|
||||
})
|
||||
} : void 0;
|
||||
export { MenuItem };
|
||||
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
'use client';
|
||||
|
||||
export * from './MenuItem';
|
||||
export * from './MenuItem.types';
|
||||
export * from './menuItemClasses';
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import { generateUtilityClass } from '../generateUtilityClass';
|
||||
import { generateUtilityClasses } from '../generateUtilityClasses';
|
||||
const COMPONENT_NAME = 'MenuItem';
|
||||
export function getMenuItemUtilityClass(slot) {
|
||||
return generateUtilityClass(COMPONENT_NAME, slot);
|
||||
}
|
||||
export const menuItemClasses = generateUtilityClasses(COMPONENT_NAME, ['root', 'disabled', 'focusVisible']);
|
||||
+277
@@ -0,0 +1,277 @@
|
||||
'use client';
|
||||
|
||||
import _extends from "@babel/runtime/helpers/esm/extends";
|
||||
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
||||
const _excluded = ["children", "closeAfterTransition", "container", "disableAutoFocus", "disableEnforceFocus", "disableEscapeKeyDown", "disablePortal", "disableRestoreFocus", "disableScrollLock", "hideBackdrop", "keepMounted", "onBackdropClick", "onClose", "onKeyDown", "open", "onTransitionEnter", "onTransitionExited", "slotProps", "slots"];
|
||||
import * as React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { elementAcceptingRef, HTMLElementType } from '@mui/utils';
|
||||
import { useSlotProps } from '../utils';
|
||||
import { useClassNamesOverride } from '../utils/ClassNameConfigurator';
|
||||
import { unstable_composeClasses as composeClasses } from '../composeClasses';
|
||||
import { Portal } from '../Portal';
|
||||
import { unstable_useModal as useModal } from '../unstable_useModal';
|
||||
import { FocusTrap } from '../FocusTrap';
|
||||
import { getModalUtilityClass } from './modalClasses';
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
import { jsxs as _jsxs } from "react/jsx-runtime";
|
||||
const useUtilityClasses = ownerState => {
|
||||
const {
|
||||
open,
|
||||
exited
|
||||
} = ownerState;
|
||||
const slots = {
|
||||
root: ['root', !open && exited && 'hidden'],
|
||||
backdrop: ['backdrop']
|
||||
};
|
||||
return composeClasses(slots, useClassNamesOverride(getModalUtilityClass));
|
||||
};
|
||||
|
||||
/**
|
||||
* Modal is a lower-level construct that is leveraged by the following components:
|
||||
*
|
||||
* * [Dialog](https://mui.com/material-ui/api/dialog/)
|
||||
* * [Drawer](https://mui.com/material-ui/api/drawer/)
|
||||
* * [Menu](https://mui.com/material-ui/api/menu/)
|
||||
* * [Popover](https://mui.com/material-ui/api/popover/)
|
||||
*
|
||||
* If you are creating a modal dialog, you probably want to use the [Dialog](https://mui.com/material-ui/api/dialog/) component
|
||||
* rather than directly using Modal.
|
||||
*
|
||||
* This component shares many concepts with [react-overlays](https://react-bootstrap.github.io/react-overlays/#modals).
|
||||
*
|
||||
* Demos:
|
||||
*
|
||||
* - [Modal](https://mui.com/base-ui/react-modal/)
|
||||
*
|
||||
* API:
|
||||
*
|
||||
* - [Modal API](https://mui.com/base-ui/react-modal/components-api/#modal)
|
||||
*/
|
||||
const Modal = /*#__PURE__*/React.forwardRef(function Modal(props, forwardedRef) {
|
||||
const {
|
||||
children,
|
||||
closeAfterTransition = false,
|
||||
container,
|
||||
disableAutoFocus = false,
|
||||
disableEnforceFocus = false,
|
||||
disableEscapeKeyDown = false,
|
||||
disablePortal = false,
|
||||
disableRestoreFocus = false,
|
||||
disableScrollLock = false,
|
||||
hideBackdrop = false,
|
||||
keepMounted = false,
|
||||
onBackdropClick,
|
||||
open,
|
||||
slotProps = {},
|
||||
slots = {}
|
||||
} = props,
|
||||
other = _objectWithoutPropertiesLoose(props, _excluded);
|
||||
const propsWithDefaults = _extends({}, props, {
|
||||
closeAfterTransition,
|
||||
disableAutoFocus,
|
||||
disableEnforceFocus,
|
||||
disableEscapeKeyDown,
|
||||
disablePortal,
|
||||
disableRestoreFocus,
|
||||
disableScrollLock,
|
||||
hideBackdrop,
|
||||
keepMounted
|
||||
});
|
||||
const {
|
||||
getRootProps,
|
||||
getBackdropProps,
|
||||
getTransitionProps,
|
||||
portalRef,
|
||||
isTopModal,
|
||||
exited,
|
||||
hasTransition
|
||||
} = useModal(_extends({}, propsWithDefaults, {
|
||||
rootRef: forwardedRef
|
||||
}));
|
||||
const ownerState = _extends({}, propsWithDefaults, {
|
||||
exited,
|
||||
hasTransition
|
||||
});
|
||||
const classes = useUtilityClasses(ownerState);
|
||||
const childProps = {};
|
||||
if (children.props.tabIndex === undefined) {
|
||||
childProps.tabIndex = '-1';
|
||||
}
|
||||
|
||||
// It's a Transition like component
|
||||
if (hasTransition) {
|
||||
const {
|
||||
onEnter,
|
||||
onExited
|
||||
} = getTransitionProps();
|
||||
childProps.onEnter = onEnter;
|
||||
childProps.onExited = onExited;
|
||||
}
|
||||
const Root = slots.root ?? 'div';
|
||||
const rootProps = useSlotProps({
|
||||
elementType: Root,
|
||||
externalSlotProps: slotProps.root,
|
||||
externalForwardedProps: other,
|
||||
getSlotProps: getRootProps,
|
||||
className: classes.root,
|
||||
ownerState
|
||||
});
|
||||
const BackdropComponent = slots.backdrop;
|
||||
const backdropProps = useSlotProps({
|
||||
elementType: BackdropComponent,
|
||||
externalSlotProps: slotProps.backdrop,
|
||||
getSlotProps: otherHandlers => {
|
||||
return getBackdropProps(_extends({}, otherHandlers, {
|
||||
onClick: e => {
|
||||
if (onBackdropClick) {
|
||||
onBackdropClick(e);
|
||||
}
|
||||
if (otherHandlers?.onClick) {
|
||||
otherHandlers.onClick(e);
|
||||
}
|
||||
}
|
||||
}));
|
||||
},
|
||||
className: classes.backdrop,
|
||||
ownerState
|
||||
});
|
||||
if (!keepMounted && !open && (!hasTransition || exited)) {
|
||||
return null;
|
||||
}
|
||||
return /*#__PURE__*/_jsx(Portal, {
|
||||
ref: portalRef,
|
||||
container: container,
|
||||
disablePortal: disablePortal,
|
||||
children: /*#__PURE__*/_jsxs(Root, _extends({}, rootProps, {
|
||||
children: [!hideBackdrop && BackdropComponent ? /*#__PURE__*/_jsx(BackdropComponent, _extends({}, backdropProps)) : null, /*#__PURE__*/_jsx(FocusTrap, {
|
||||
disableEnforceFocus: disableEnforceFocus,
|
||||
disableAutoFocus: disableAutoFocus,
|
||||
disableRestoreFocus: disableRestoreFocus,
|
||||
isEnabled: isTopModal,
|
||||
open: open,
|
||||
children: /*#__PURE__*/React.cloneElement(children, childProps)
|
||||
})]
|
||||
}))
|
||||
});
|
||||
});
|
||||
process.env.NODE_ENV !== "production" ? Modal.propTypes /* remove-proptypes */ = {
|
||||
// ┌────────────────────────────── Warning ──────────────────────────────┐
|
||||
// │ These PropTypes are generated from the TypeScript type definitions. │
|
||||
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
|
||||
// └─────────────────────────────────────────────────────────────────────┘
|
||||
/**
|
||||
* A single child content element.
|
||||
*/
|
||||
children: elementAcceptingRef.isRequired,
|
||||
/**
|
||||
* When set to true the Modal waits until a nested Transition is completed before closing.
|
||||
* @default false
|
||||
*/
|
||||
closeAfterTransition: PropTypes.bool,
|
||||
/**
|
||||
* An HTML element or function that returns one.
|
||||
* The `container` will have the portal children appended to it.
|
||||
*
|
||||
* You can also provide a callback, which is called in a React layout effect.
|
||||
* This lets you set the container from a ref, and also makes server-side rendering possible.
|
||||
*
|
||||
* By default, it uses the body of the top-level document object,
|
||||
* so it's simply `document.body` most of the time.
|
||||
*/
|
||||
container: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([HTMLElementType, PropTypes.func]),
|
||||
/**
|
||||
* If `true`, the modal will not automatically shift focus to itself when it opens, and
|
||||
* replace it to the last focused element when it closes.
|
||||
* This also works correctly with any modal children that have the `disableAutoFocus` prop.
|
||||
*
|
||||
* Generally this should never be set to `true` as it makes the modal less
|
||||
* accessible to assistive technologies, like screen readers.
|
||||
* @default false
|
||||
*/
|
||||
disableAutoFocus: PropTypes.bool,
|
||||
/**
|
||||
* If `true`, the modal will not prevent focus from leaving the modal while open.
|
||||
*
|
||||
* Generally this should never be set to `true` as it makes the modal less
|
||||
* accessible to assistive technologies, like screen readers.
|
||||
* @default false
|
||||
*/
|
||||
disableEnforceFocus: PropTypes.bool,
|
||||
/**
|
||||
* If `true`, hitting escape will not fire the `onClose` callback.
|
||||
* @default false
|
||||
*/
|
||||
disableEscapeKeyDown: PropTypes.bool,
|
||||
/**
|
||||
* The `children` will be under the DOM hierarchy of the parent component.
|
||||
* @default false
|
||||
*/
|
||||
disablePortal: PropTypes.bool,
|
||||
/**
|
||||
* If `true`, the modal will not restore focus to previously focused element once
|
||||
* modal is hidden or unmounted.
|
||||
* @default false
|
||||
*/
|
||||
disableRestoreFocus: PropTypes.bool,
|
||||
/**
|
||||
* Disable the scroll lock behavior.
|
||||
* @default false
|
||||
*/
|
||||
disableScrollLock: PropTypes.bool,
|
||||
/**
|
||||
* If `true`, the backdrop is not rendered.
|
||||
* @default false
|
||||
*/
|
||||
hideBackdrop: PropTypes.bool,
|
||||
/**
|
||||
* Always keep the children in the DOM.
|
||||
* This prop can be useful in SEO situation or
|
||||
* when you want to maximize the responsiveness of the Modal.
|
||||
* @default false
|
||||
*/
|
||||
keepMounted: PropTypes.bool,
|
||||
/**
|
||||
* Callback fired when the backdrop is clicked.
|
||||
* @deprecated Use the `onClose` prop with the `reason` argument to handle the `backdropClick` events.
|
||||
*/
|
||||
onBackdropClick: PropTypes.func,
|
||||
/**
|
||||
* Callback fired when the component requests to be closed.
|
||||
* The `reason` parameter can optionally be used to control the response to `onClose`.
|
||||
*
|
||||
* @param {object} event The event source of the callback.
|
||||
* @param {string} reason Can be: `"escapeKeyDown"`, `"backdropClick"`.
|
||||
*/
|
||||
onClose: PropTypes.func,
|
||||
/**
|
||||
* A function called when a transition enters.
|
||||
*/
|
||||
onTransitionEnter: PropTypes.func,
|
||||
/**
|
||||
* A function called when a transition has exited.
|
||||
*/
|
||||
onTransitionExited: PropTypes.func,
|
||||
/**
|
||||
* If `true`, the component is shown.
|
||||
*/
|
||||
open: PropTypes.bool.isRequired,
|
||||
/**
|
||||
* The props used for each slot inside the Modal.
|
||||
* @default {}
|
||||
*/
|
||||
slotProps: PropTypes.shape({
|
||||
backdrop: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
||||
root: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
|
||||
}),
|
||||
/**
|
||||
* The components used for each slot inside the Modal.
|
||||
* Either a string to use a HTML element or a component.
|
||||
* @default {}
|
||||
*/
|
||||
slots: PropTypes.shape({
|
||||
backdrop: PropTypes.elementType,
|
||||
root: PropTypes.elementType
|
||||
})
|
||||
} : void 0;
|
||||
export { Modal };
|
||||
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
export { Modal } from './Modal';
|
||||
export * from './Modal.types';
|
||||
export * from './modalClasses';
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import { generateUtilityClasses } from '../generateUtilityClasses';
|
||||
import { generateUtilityClass } from '../generateUtilityClass';
|
||||
const COMPONENT_NAME = 'Modal';
|
||||
export function getModalUtilityClass(slot) {
|
||||
return generateUtilityClass(COMPONENT_NAME, slot);
|
||||
}
|
||||
export const modalClasses = generateUtilityClasses(COMPONENT_NAME, ['root', 'hidden', 'backdrop']);
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
'use client';
|
||||
|
||||
let warnedOnce = false;
|
||||
const warn = () => {
|
||||
if (!warnedOnce) {
|
||||
console.error(['Base UI: The MultiSelect component was removed from the library.', '', 'The multi-select functionality is now available in the Select component.', 'Replace <MultiSelect> with <Select multiple /> in your code to remove this error.'].join('\n'));
|
||||
warnedOnce = true;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* The foundation for building custom-styled multi-selection select components.
|
||||
*
|
||||
* @deprecated The multi-select functionality is now available in the Select component. Replace <MultiSelect> with <Select multiple /> in your code.
|
||||
* @ignore - do not document.
|
||||
*/
|
||||
export function MultiSelect() {
|
||||
warn();
|
||||
return null;
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
'use client';
|
||||
|
||||
export { MultiSelect } from './MultiSelect';
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
'use client';
|
||||
|
||||
import * as React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { exactProp, unstable_useEnhancedEffect as useEnhancedEffect } from '@mui/utils';
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
/**
|
||||
* NoSsr purposely removes components from the subject of Server Side Rendering (SSR).
|
||||
*
|
||||
* This component can be useful in a variety of situations:
|
||||
*
|
||||
* * Escape hatch for broken dependencies not supporting SSR.
|
||||
* * Improve the time-to-first paint on the client by only rendering above the fold.
|
||||
* * Reduce the rendering time on the server.
|
||||
* * Under too heavy server load, you can turn on service degradation.
|
||||
*
|
||||
* Demos:
|
||||
*
|
||||
* - [No SSR](https://mui.com/base-ui/react-no-ssr/)
|
||||
*
|
||||
* API:
|
||||
*
|
||||
* - [NoSsr API](https://mui.com/base-ui/react-no-ssr/components-api/#no-ssr)
|
||||
*/
|
||||
function NoSsr(props) {
|
||||
const {
|
||||
children,
|
||||
defer = false,
|
||||
fallback = null
|
||||
} = props;
|
||||
const [mountedState, setMountedState] = React.useState(false);
|
||||
useEnhancedEffect(() => {
|
||||
if (!defer) {
|
||||
setMountedState(true);
|
||||
}
|
||||
}, [defer]);
|
||||
React.useEffect(() => {
|
||||
if (defer) {
|
||||
setMountedState(true);
|
||||
}
|
||||
}, [defer]);
|
||||
|
||||
// We need the Fragment here to force react-docgen to recognise NoSsr as a component.
|
||||
return /*#__PURE__*/_jsx(React.Fragment, {
|
||||
children: mountedState ? children : fallback
|
||||
});
|
||||
}
|
||||
process.env.NODE_ENV !== "production" ? NoSsr.propTypes /* remove-proptypes */ = {
|
||||
// ┌────────────────────────────── Warning ──────────────────────────────┐
|
||||
// │ These PropTypes are generated from the TypeScript type definitions. │
|
||||
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
|
||||
// └─────────────────────────────────────────────────────────────────────┘
|
||||
/**
|
||||
* You can wrap a node.
|
||||
*/
|
||||
children: PropTypes.node,
|
||||
/**
|
||||
* If `true`, the component will not only prevent server-side rendering.
|
||||
* It will also defer the rendering of the children into a different screen frame.
|
||||
* @default false
|
||||
*/
|
||||
defer: PropTypes.bool,
|
||||
/**
|
||||
* The fallback content to display.
|
||||
* @default null
|
||||
*/
|
||||
fallback: PropTypes.node
|
||||
} : void 0;
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
// eslint-disable-next-line
|
||||
NoSsr['propTypes' + ''] = exactProp(NoSsr.propTypes);
|
||||
}
|
||||
export { NoSsr };
|
||||
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
'use client';
|
||||
|
||||
export { NoSsr } from './NoSsr';
|
||||
export * from './NoSsr.types';
|
||||
+148
@@ -0,0 +1,148 @@
|
||||
'use client';
|
||||
|
||||
import _extends from "@babel/runtime/helpers/esm/extends";
|
||||
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
||||
const _excluded = ["children", "disabled", "label", "slotProps", "slots", "value"];
|
||||
import * as React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { unstable_useForkRef as useForkRef } from '@mui/utils';
|
||||
import { unstable_composeClasses as composeClasses } from '../composeClasses';
|
||||
import { getOptionUtilityClass } from './optionClasses';
|
||||
import { useSlotProps } from '../utils';
|
||||
import { useOption, useOptionContextStabilizer } from '../useOption';
|
||||
import { useClassNamesOverride } from '../utils/ClassNameConfigurator';
|
||||
import { ListContext } from '../useList';
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
function useUtilityClasses(ownerState) {
|
||||
const {
|
||||
disabled,
|
||||
highlighted,
|
||||
selected
|
||||
} = ownerState;
|
||||
const slots = {
|
||||
root: ['root', disabled && 'disabled', highlighted && 'highlighted', selected && 'selected']
|
||||
};
|
||||
return composeClasses(slots, useClassNamesOverride(getOptionUtilityClass));
|
||||
}
|
||||
const InnerOption = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef(function Option(props, forwardedRef) {
|
||||
const {
|
||||
children,
|
||||
disabled = false,
|
||||
label,
|
||||
slotProps = {},
|
||||
slots = {},
|
||||
value
|
||||
} = props,
|
||||
other = _objectWithoutPropertiesLoose(props, _excluded);
|
||||
const Root = slots.root ?? 'li';
|
||||
const optionRef = React.useRef(null);
|
||||
const combinedRef = useForkRef(optionRef, forwardedRef);
|
||||
|
||||
// If `label` is not explicitly provided, the `children` are used for convenience.
|
||||
// This is used to populate the select's trigger with the selected option's label.
|
||||
const computedLabel = label ?? (typeof children === 'string' ? children : optionRef.current?.textContent?.trim());
|
||||
const {
|
||||
getRootProps,
|
||||
selected,
|
||||
highlighted,
|
||||
index
|
||||
} = useOption({
|
||||
disabled,
|
||||
label: computedLabel,
|
||||
rootRef: combinedRef,
|
||||
value
|
||||
});
|
||||
const ownerState = _extends({}, props, {
|
||||
disabled,
|
||||
highlighted,
|
||||
index,
|
||||
selected
|
||||
});
|
||||
const classes = useUtilityClasses(ownerState);
|
||||
const rootProps = useSlotProps({
|
||||
getSlotProps: getRootProps,
|
||||
elementType: Root,
|
||||
externalSlotProps: slotProps.root,
|
||||
externalForwardedProps: other,
|
||||
className: classes.root,
|
||||
ownerState
|
||||
});
|
||||
return /*#__PURE__*/_jsx(Root, _extends({}, rootProps, {
|
||||
children: children
|
||||
}));
|
||||
}));
|
||||
|
||||
/**
|
||||
* An unstyled option to be used within a Select.
|
||||
*
|
||||
* Demos:
|
||||
*
|
||||
* - [Select](https://mui.com/base-ui/react-select/)
|
||||
*
|
||||
* API:
|
||||
*
|
||||
* - [Option API](https://mui.com/base-ui/react-select/components-api/#option)
|
||||
*/
|
||||
const Option = /*#__PURE__*/React.forwardRef(function Option(props, ref) {
|
||||
const {
|
||||
value
|
||||
} = props;
|
||||
|
||||
// This wrapper component is used as a performance optimization.
|
||||
// `useOptionContextStabilizer` ensures that the context value
|
||||
// is stable across renders, so that the actual Option re-renders
|
||||
// only when it needs to.
|
||||
const {
|
||||
contextValue
|
||||
} = useOptionContextStabilizer(value);
|
||||
return /*#__PURE__*/_jsx(ListContext.Provider, {
|
||||
value: contextValue,
|
||||
children: /*#__PURE__*/_jsx(InnerOption, _extends({}, props, {
|
||||
ref: ref
|
||||
}))
|
||||
});
|
||||
});
|
||||
process.env.NODE_ENV !== "production" ? Option.propTypes /* remove-proptypes */ = {
|
||||
// ┌────────────────────────────── Warning ──────────────────────────────┐
|
||||
// │ These PropTypes are generated from the TypeScript type definitions. │
|
||||
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
|
||||
// └─────────────────────────────────────────────────────────────────────┘
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
children: PropTypes.node,
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
className: PropTypes.string,
|
||||
/**
|
||||
* If `true`, the option will be disabled.
|
||||
* @default false
|
||||
*/
|
||||
disabled: PropTypes.bool,
|
||||
/**
|
||||
* A text representation of the option's content.
|
||||
* Used for keyboard text navigation matching.
|
||||
*/
|
||||
label: PropTypes.string,
|
||||
/**
|
||||
* The props used for each slot inside the Option.
|
||||
* @default {}
|
||||
*/
|
||||
slotProps: PropTypes.shape({
|
||||
root: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
|
||||
}),
|
||||
/**
|
||||
* The components used for each slot inside the Option.
|
||||
* Either a string to use a HTML element or a component.
|
||||
* @default {}
|
||||
*/
|
||||
slots: PropTypes.shape({
|
||||
root: PropTypes.elementType
|
||||
}),
|
||||
/**
|
||||
* The value of the option.
|
||||
*/
|
||||
value: PropTypes.any.isRequired
|
||||
} : void 0;
|
||||
export { Option };
|
||||
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
'use client';
|
||||
|
||||
export * from './Option';
|
||||
export * from './Option.types';
|
||||
export * from './optionClasses';
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import { generateUtilityClass } from '../generateUtilityClass';
|
||||
import { generateUtilityClasses } from '../generateUtilityClasses';
|
||||
const COMPONENT_NAME = 'Option';
|
||||
export function getOptionUtilityClass(slot) {
|
||||
return generateUtilityClass(COMPONENT_NAME, slot);
|
||||
}
|
||||
export const optionClasses = generateUtilityClasses(COMPONENT_NAME, ['root', 'disabled', 'selected', 'highlighted']);
|
||||
+117
@@ -0,0 +1,117 @@
|
||||
'use client';
|
||||
|
||||
import _extends from "@babel/runtime/helpers/esm/extends";
|
||||
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
||||
const _excluded = ["disabled", "slotProps", "slots"];
|
||||
import * as React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { unstable_composeClasses as composeClasses } from '../composeClasses';
|
||||
import { getOptionGroupUtilityClass } from './optionGroupClasses';
|
||||
import { useSlotProps } from '../utils';
|
||||
import { useClassNamesOverride } from '../utils/ClassNameConfigurator';
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
import { jsxs as _jsxs } from "react/jsx-runtime";
|
||||
function useUtilityClasses(disabled) {
|
||||
const slots = {
|
||||
root: ['root', disabled && 'disabled'],
|
||||
label: ['label'],
|
||||
list: ['list']
|
||||
};
|
||||
return composeClasses(slots, useClassNamesOverride(getOptionGroupUtilityClass));
|
||||
}
|
||||
|
||||
/**
|
||||
* An unstyled option group to be used within a Select.
|
||||
*
|
||||
* Demos:
|
||||
*
|
||||
* - [Select](https://mui.com/base-ui/react-select/)
|
||||
*
|
||||
* API:
|
||||
*
|
||||
* - [OptionGroup API](https://mui.com/base-ui/react-select/components-api/#option-group)
|
||||
*/
|
||||
const OptionGroup = /*#__PURE__*/React.forwardRef(function OptionGroup(props, forwardedRef) {
|
||||
const {
|
||||
disabled = false,
|
||||
slotProps = {},
|
||||
slots = {}
|
||||
} = props,
|
||||
other = _objectWithoutPropertiesLoose(props, _excluded);
|
||||
const Root = slots?.root || 'li';
|
||||
const Label = slots?.label || 'span';
|
||||
const List = slots?.list || 'ul';
|
||||
const classes = useUtilityClasses(disabled);
|
||||
const rootProps = useSlotProps({
|
||||
elementType: Root,
|
||||
externalSlotProps: slotProps.root,
|
||||
externalForwardedProps: other,
|
||||
additionalProps: {
|
||||
ref: forwardedRef
|
||||
},
|
||||
ownerState: props,
|
||||
className: classes.root
|
||||
});
|
||||
const labelProps = useSlotProps({
|
||||
elementType: Label,
|
||||
externalSlotProps: slotProps.label,
|
||||
ownerState: props,
|
||||
className: classes.label
|
||||
});
|
||||
const listProps = useSlotProps({
|
||||
elementType: List,
|
||||
externalSlotProps: slotProps.list,
|
||||
ownerState: props,
|
||||
className: classes.list
|
||||
});
|
||||
return /*#__PURE__*/_jsxs(Root, _extends({}, rootProps, {
|
||||
children: [/*#__PURE__*/_jsx(Label, _extends({}, labelProps, {
|
||||
children: props.label
|
||||
})), /*#__PURE__*/_jsx(List, _extends({}, listProps, {
|
||||
children: props.children
|
||||
}))]
|
||||
}));
|
||||
});
|
||||
process.env.NODE_ENV !== "production" ? OptionGroup.propTypes /* remove-proptypes */ = {
|
||||
// ┌────────────────────────────── Warning ──────────────────────────────┐
|
||||
// │ These PropTypes are generated from the TypeScript type definitions. │
|
||||
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
|
||||
// └─────────────────────────────────────────────────────────────────────┘
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
children: PropTypes.node,
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
className: PropTypes.string,
|
||||
/**
|
||||
* If `true` all the options in the group will be disabled.
|
||||
* @default false
|
||||
*/
|
||||
disabled: PropTypes.bool,
|
||||
/**
|
||||
* The human-readable description of the group.
|
||||
*/
|
||||
label: PropTypes.node,
|
||||
/**
|
||||
* The props used for each slot inside the Input.
|
||||
* @default {}
|
||||
*/
|
||||
slotProps: PropTypes.shape({
|
||||
label: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
||||
list: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
||||
root: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
|
||||
}),
|
||||
/**
|
||||
* The components used for each slot inside the OptionGroup.
|
||||
* Either a string to use a HTML element or a component.
|
||||
* @default {}
|
||||
*/
|
||||
slots: PropTypes.shape({
|
||||
label: PropTypes.elementType,
|
||||
list: PropTypes.elementType,
|
||||
root: PropTypes.elementType
|
||||
})
|
||||
} : void 0;
|
||||
export { OptionGroup };
|
||||
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
'use client';
|
||||
|
||||
export { OptionGroup } from './OptionGroup';
|
||||
export * from './OptionGroup.types';
|
||||
export * from './optionGroupClasses';
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import { generateUtilityClass } from '../generateUtilityClass';
|
||||
import { generateUtilityClasses } from '../generateUtilityClasses';
|
||||
const COMPONENT_NAME = 'OptionGroup';
|
||||
export function getOptionGroupUtilityClass(slot) {
|
||||
return generateUtilityClass(COMPONENT_NAME, slot);
|
||||
}
|
||||
export const optionGroupClasses = generateUtilityClasses(COMPONENT_NAME, ['root', 'disabled', 'label', 'list']);
|
||||
+377
@@ -0,0 +1,377 @@
|
||||
'use client';
|
||||
|
||||
import _extends from "@babel/runtime/helpers/esm/extends";
|
||||
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
||||
const _excluded = ["anchorEl", "children", "direction", "disablePortal", "modifiers", "open", "placement", "popperOptions", "popperRef", "slotProps", "slots", "TransitionProps", "ownerState"],
|
||||
_excluded2 = ["anchorEl", "children", "container", "direction", "disablePortal", "keepMounted", "modifiers", "open", "placement", "popperOptions", "popperRef", "style", "transition", "slotProps", "slots"];
|
||||
import * as React from 'react';
|
||||
import { chainPropTypes, HTMLElementType, refType, unstable_ownerDocument as ownerDocument, unstable_useEnhancedEffect as useEnhancedEffect, unstable_useForkRef as useForkRef } from '@mui/utils';
|
||||
import { createPopper } from '@popperjs/core';
|
||||
import PropTypes from 'prop-types';
|
||||
import { unstable_composeClasses as composeClasses } from '../composeClasses';
|
||||
import { Portal } from '../Portal';
|
||||
import { getPopperUtilityClass } from './popperClasses';
|
||||
import { useSlotProps } from '../utils';
|
||||
import { useClassNamesOverride } from '../utils/ClassNameConfigurator';
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
function flipPlacement(placement, direction) {
|
||||
if (direction === 'ltr') {
|
||||
return placement;
|
||||
}
|
||||
switch (placement) {
|
||||
case 'bottom-end':
|
||||
return 'bottom-start';
|
||||
case 'bottom-start':
|
||||
return 'bottom-end';
|
||||
case 'top-end':
|
||||
return 'top-start';
|
||||
case 'top-start':
|
||||
return 'top-end';
|
||||
default:
|
||||
return placement;
|
||||
}
|
||||
}
|
||||
function resolveAnchorEl(anchorEl) {
|
||||
return typeof anchorEl === 'function' ? anchorEl() : anchorEl;
|
||||
}
|
||||
function isHTMLElement(element) {
|
||||
return element.nodeType !== undefined;
|
||||
}
|
||||
function isVirtualElement(element) {
|
||||
return !isHTMLElement(element);
|
||||
}
|
||||
const useUtilityClasses = () => {
|
||||
const slots = {
|
||||
root: ['root']
|
||||
};
|
||||
return composeClasses(slots, useClassNamesOverride(getPopperUtilityClass));
|
||||
};
|
||||
const defaultPopperOptions = {};
|
||||
const PopperTooltip = /*#__PURE__*/React.forwardRef(function PopperTooltip(props, forwardedRef) {
|
||||
const {
|
||||
anchorEl,
|
||||
children,
|
||||
direction,
|
||||
disablePortal,
|
||||
modifiers,
|
||||
open,
|
||||
placement: initialPlacement,
|
||||
popperOptions,
|
||||
popperRef: popperRefProp,
|
||||
slotProps = {},
|
||||
slots = {},
|
||||
TransitionProps
|
||||
// @ts-ignore internal logic
|
||||
// prevent from spreading to DOM, it can come from the parent component e.g. Select.
|
||||
} = props,
|
||||
other = _objectWithoutPropertiesLoose(props, _excluded);
|
||||
const tooltipRef = React.useRef(null);
|
||||
const ownRef = useForkRef(tooltipRef, forwardedRef);
|
||||
const popperRef = React.useRef(null);
|
||||
const handlePopperRef = useForkRef(popperRef, popperRefProp);
|
||||
const handlePopperRefRef = React.useRef(handlePopperRef);
|
||||
useEnhancedEffect(() => {
|
||||
handlePopperRefRef.current = handlePopperRef;
|
||||
}, [handlePopperRef]);
|
||||
React.useImperativeHandle(popperRefProp, () => popperRef.current, []);
|
||||
const rtlPlacement = flipPlacement(initialPlacement, direction);
|
||||
/**
|
||||
* placement initialized from prop but can change during lifetime if modifiers.flip.
|
||||
* modifiers.flip is essentially a flip for controlled/uncontrolled behavior
|
||||
*/
|
||||
const [placement, setPlacement] = React.useState(rtlPlacement);
|
||||
const [resolvedAnchorElement, setResolvedAnchorElement] = React.useState(resolveAnchorEl(anchorEl));
|
||||
React.useEffect(() => {
|
||||
if (popperRef.current) {
|
||||
popperRef.current.forceUpdate();
|
||||
}
|
||||
});
|
||||
React.useEffect(() => {
|
||||
if (anchorEl) {
|
||||
setResolvedAnchorElement(resolveAnchorEl(anchorEl));
|
||||
}
|
||||
}, [anchorEl]);
|
||||
useEnhancedEffect(() => {
|
||||
if (!resolvedAnchorElement || !open) {
|
||||
return undefined;
|
||||
}
|
||||
const handlePopperUpdate = data => {
|
||||
setPlacement(data.placement);
|
||||
};
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
if (resolvedAnchorElement && isHTMLElement(resolvedAnchorElement) && resolvedAnchorElement.nodeType === 1) {
|
||||
const box = resolvedAnchorElement.getBoundingClientRect();
|
||||
if (process.env.NODE_ENV !== 'test' && box.top === 0 && box.left === 0 && box.right === 0 && box.bottom === 0) {
|
||||
console.warn(['MUI: The `anchorEl` prop provided to the component is invalid.', 'The anchor element should be part of the document layout.', "Make sure the element is present in the document or that it's not display none."].join('\n'));
|
||||
}
|
||||
}
|
||||
}
|
||||
let popperModifiers = [{
|
||||
name: 'preventOverflow',
|
||||
options: {
|
||||
altBoundary: disablePortal
|
||||
}
|
||||
}, {
|
||||
name: 'flip',
|
||||
options: {
|
||||
altBoundary: disablePortal
|
||||
}
|
||||
}, {
|
||||
name: 'onUpdate',
|
||||
enabled: true,
|
||||
phase: 'afterWrite',
|
||||
fn: ({
|
||||
state
|
||||
}) => {
|
||||
handlePopperUpdate(state);
|
||||
}
|
||||
}];
|
||||
if (modifiers != null) {
|
||||
popperModifiers = popperModifiers.concat(modifiers);
|
||||
}
|
||||
if (popperOptions && popperOptions.modifiers != null) {
|
||||
popperModifiers = popperModifiers.concat(popperOptions.modifiers);
|
||||
}
|
||||
const popper = createPopper(resolvedAnchorElement, tooltipRef.current, _extends({
|
||||
placement: rtlPlacement
|
||||
}, popperOptions, {
|
||||
modifiers: popperModifiers
|
||||
}));
|
||||
handlePopperRefRef.current(popper);
|
||||
return () => {
|
||||
popper.destroy();
|
||||
handlePopperRefRef.current(null);
|
||||
};
|
||||
}, [resolvedAnchorElement, disablePortal, modifiers, open, popperOptions, rtlPlacement]);
|
||||
const childProps = {
|
||||
placement: placement
|
||||
};
|
||||
if (TransitionProps !== null) {
|
||||
childProps.TransitionProps = TransitionProps;
|
||||
}
|
||||
const classes = useUtilityClasses();
|
||||
const Root = slots.root ?? 'div';
|
||||
const rootProps = useSlotProps({
|
||||
elementType: Root,
|
||||
externalSlotProps: slotProps.root,
|
||||
externalForwardedProps: other,
|
||||
additionalProps: {
|
||||
role: 'tooltip',
|
||||
ref: ownRef
|
||||
},
|
||||
ownerState: props,
|
||||
className: classes.root
|
||||
});
|
||||
return /*#__PURE__*/_jsx(Root, _extends({}, rootProps, {
|
||||
children: typeof children === 'function' ? children(childProps) : children
|
||||
}));
|
||||
});
|
||||
|
||||
/**
|
||||
* Poppers rely on the 3rd party library [Popper.js](https://popper.js.org/docs/v2/) for positioning.
|
||||
*
|
||||
* Demos:
|
||||
*
|
||||
* - [Popper](https://mui.com/base-ui/react-popper/)
|
||||
*
|
||||
* API:
|
||||
*
|
||||
* - [Popper API](https://mui.com/base-ui/react-popper/components-api/#popper)
|
||||
*/
|
||||
const Popper = /*#__PURE__*/React.forwardRef(function Popper(props, forwardedRef) {
|
||||
const {
|
||||
anchorEl,
|
||||
children,
|
||||
container: containerProp,
|
||||
direction = 'ltr',
|
||||
disablePortal = false,
|
||||
keepMounted = false,
|
||||
modifiers,
|
||||
open,
|
||||
placement = 'bottom',
|
||||
popperOptions = defaultPopperOptions,
|
||||
popperRef,
|
||||
style,
|
||||
transition = false,
|
||||
slotProps = {},
|
||||
slots = {}
|
||||
} = props,
|
||||
other = _objectWithoutPropertiesLoose(props, _excluded2);
|
||||
const [exited, setExited] = React.useState(true);
|
||||
const handleEnter = () => {
|
||||
setExited(false);
|
||||
};
|
||||
const handleExited = () => {
|
||||
setExited(true);
|
||||
};
|
||||
if (!keepMounted && !open && (!transition || exited)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// If the container prop is provided, use that
|
||||
// If the anchorEl prop is provided, use its parent body element as the container
|
||||
// If neither are provided let the Modal take care of choosing the container
|
||||
let container;
|
||||
if (containerProp) {
|
||||
container = containerProp;
|
||||
} else if (anchorEl) {
|
||||
const resolvedAnchorEl = resolveAnchorEl(anchorEl);
|
||||
container = resolvedAnchorEl && isHTMLElement(resolvedAnchorEl) ? ownerDocument(resolvedAnchorEl).body : ownerDocument(null).body;
|
||||
}
|
||||
const display = !open && keepMounted && (!transition || exited) ? 'none' : undefined;
|
||||
const transitionProps = transition ? {
|
||||
in: open,
|
||||
onEnter: handleEnter,
|
||||
onExited: handleExited
|
||||
} : undefined;
|
||||
return /*#__PURE__*/_jsx(Portal, {
|
||||
disablePortal: disablePortal,
|
||||
container: container,
|
||||
children: /*#__PURE__*/_jsx(PopperTooltip, _extends({
|
||||
anchorEl: anchorEl,
|
||||
direction: direction,
|
||||
disablePortal: disablePortal,
|
||||
modifiers: modifiers,
|
||||
ref: forwardedRef,
|
||||
open: transition ? !exited : open,
|
||||
placement: placement,
|
||||
popperOptions: popperOptions,
|
||||
popperRef: popperRef,
|
||||
slotProps: slotProps,
|
||||
slots: slots
|
||||
}, other, {
|
||||
style: _extends({
|
||||
// Prevents scroll issue, waiting for Popper.js to add this style once initiated.
|
||||
position: 'fixed',
|
||||
// Fix Popper.js display issue
|
||||
top: 0,
|
||||
left: 0,
|
||||
display
|
||||
}, style),
|
||||
TransitionProps: transitionProps,
|
||||
children: children
|
||||
}))
|
||||
});
|
||||
});
|
||||
process.env.NODE_ENV !== "production" ? Popper.propTypes /* remove-proptypes */ = {
|
||||
// ┌────────────────────────────── Warning ──────────────────────────────┐
|
||||
// │ These PropTypes are generated from the TypeScript type definitions. │
|
||||
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
|
||||
// └─────────────────────────────────────────────────────────────────────┘
|
||||
/**
|
||||
* An HTML element, [virtualElement](https://popper.js.org/docs/v2/virtual-elements/),
|
||||
* or a function that returns either.
|
||||
* It's used to set the position of the popper.
|
||||
* The return value will passed as the reference object of the Popper instance.
|
||||
*/
|
||||
anchorEl: chainPropTypes(PropTypes.oneOfType([HTMLElementType, PropTypes.object, PropTypes.func]), props => {
|
||||
if (props.open) {
|
||||
const resolvedAnchorEl = resolveAnchorEl(props.anchorEl);
|
||||
if (resolvedAnchorEl && isHTMLElement(resolvedAnchorEl) && resolvedAnchorEl.nodeType === 1) {
|
||||
const box = resolvedAnchorEl.getBoundingClientRect();
|
||||
if (process.env.NODE_ENV !== 'test' && box.top === 0 && box.left === 0 && box.right === 0 && box.bottom === 0) {
|
||||
return new Error(['MUI: The `anchorEl` prop provided to the component is invalid.', 'The anchor element should be part of the document layout.', "Make sure the element is present in the document or that it's not display none."].join('\n'));
|
||||
}
|
||||
} else if (!resolvedAnchorEl || typeof resolvedAnchorEl.getBoundingClientRect !== 'function' || isVirtualElement(resolvedAnchorEl) && resolvedAnchorEl.contextElement != null && resolvedAnchorEl.contextElement.nodeType !== 1) {
|
||||
return new Error(['MUI: The `anchorEl` prop provided to the component is invalid.', 'It should be an HTML element instance or a virtualElement ', '(https://popper.js.org/docs/v2/virtual-elements/).'].join('\n'));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}),
|
||||
/**
|
||||
* Popper render function or node.
|
||||
*/
|
||||
children: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.node, PropTypes.func]),
|
||||
/**
|
||||
* An HTML element or function that returns one.
|
||||
* The `container` will have the portal children appended to it.
|
||||
*
|
||||
* You can also provide a callback, which is called in a React layout effect.
|
||||
* This lets you set the container from a ref, and also makes server-side rendering possible.
|
||||
*
|
||||
* By default, it uses the body of the top-level document object,
|
||||
* so it's simply `document.body` most of the time.
|
||||
*/
|
||||
container: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([HTMLElementType, PropTypes.func]),
|
||||
/**
|
||||
* Direction of the text.
|
||||
* @default 'ltr'
|
||||
*/
|
||||
direction: PropTypes.oneOf(['ltr', 'rtl']),
|
||||
/**
|
||||
* The `children` will be under the DOM hierarchy of the parent component.
|
||||
* @default false
|
||||
*/
|
||||
disablePortal: PropTypes.bool,
|
||||
/**
|
||||
* Always keep the children in the DOM.
|
||||
* This prop can be useful in SEO situation or
|
||||
* when you want to maximize the responsiveness of the Popper.
|
||||
* @default false
|
||||
*/
|
||||
keepMounted: PropTypes.bool,
|
||||
/**
|
||||
* Popper.js is based on a "plugin-like" architecture,
|
||||
* most of its features are fully encapsulated "modifiers".
|
||||
*
|
||||
* A modifier is a function that is called each time Popper.js needs to
|
||||
* compute the position of the popper.
|
||||
* For this reason, modifiers should be very performant to avoid bottlenecks.
|
||||
* To learn how to create a modifier, [read the modifiers documentation](https://popper.js.org/docs/v2/modifiers/).
|
||||
*/
|
||||
modifiers: PropTypes.arrayOf(PropTypes.shape({
|
||||
data: PropTypes.object,
|
||||
effect: PropTypes.func,
|
||||
enabled: PropTypes.bool,
|
||||
fn: PropTypes.func,
|
||||
name: PropTypes.any,
|
||||
options: PropTypes.object,
|
||||
phase: PropTypes.oneOf(['afterMain', 'afterRead', 'afterWrite', 'beforeMain', 'beforeRead', 'beforeWrite', 'main', 'read', 'write']),
|
||||
requires: PropTypes.arrayOf(PropTypes.string),
|
||||
requiresIfExists: PropTypes.arrayOf(PropTypes.string)
|
||||
})),
|
||||
/**
|
||||
* If `true`, the component is shown.
|
||||
*/
|
||||
open: PropTypes.bool.isRequired,
|
||||
/**
|
||||
* Popper placement.
|
||||
* @default 'bottom'
|
||||
*/
|
||||
placement: PropTypes.oneOf(['auto-end', 'auto-start', 'auto', 'bottom-end', 'bottom-start', 'bottom', 'left-end', 'left-start', 'left', 'right-end', 'right-start', 'right', 'top-end', 'top-start', 'top']),
|
||||
/**
|
||||
* Options provided to the [`Popper.js`](https://popper.js.org/docs/v2/constructors/#options) instance.
|
||||
* @default {}
|
||||
*/
|
||||
popperOptions: PropTypes.shape({
|
||||
modifiers: PropTypes.array,
|
||||
onFirstUpdate: PropTypes.func,
|
||||
placement: PropTypes.oneOf(['auto-end', 'auto-start', 'auto', 'bottom-end', 'bottom-start', 'bottom', 'left-end', 'left-start', 'left', 'right-end', 'right-start', 'right', 'top-end', 'top-start', 'top']),
|
||||
strategy: PropTypes.oneOf(['absolute', 'fixed'])
|
||||
}),
|
||||
/**
|
||||
* A ref that points to the used popper instance.
|
||||
*/
|
||||
popperRef: refType,
|
||||
/**
|
||||
* The props used for each slot inside the Popper.
|
||||
* @default {}
|
||||
*/
|
||||
slotProps: PropTypes.shape({
|
||||
root: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
|
||||
}),
|
||||
/**
|
||||
* The components used for each slot inside the Popper.
|
||||
* Either a string to use a HTML element or a component.
|
||||
* @default {}
|
||||
*/
|
||||
slots: PropTypes.shape({
|
||||
root: PropTypes.elementType
|
||||
}),
|
||||
/**
|
||||
* Help supporting a react-transition-group/Transition component.
|
||||
* @default false
|
||||
*/
|
||||
transition: PropTypes.bool
|
||||
} : void 0;
|
||||
export { Popper };
|
||||
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
'use client';
|
||||
|
||||
export { Popper } from './Popper';
|
||||
export { popperClasses, getPopperUtilityClass } from './popperClasses';
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import { generateUtilityClass } from '../generateUtilityClass';
|
||||
import { generateUtilityClasses } from '../generateUtilityClasses';
|
||||
const COMPONENT_NAME = 'Popper';
|
||||
export function getPopperUtilityClass(slot) {
|
||||
return generateUtilityClass(COMPONENT_NAME, slot);
|
||||
}
|
||||
export const popperClasses = generateUtilityClasses(COMPONENT_NAME, ['root']);
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
'use client';
|
||||
|
||||
import * as React from 'react';
|
||||
import * as ReactDOM from 'react-dom';
|
||||
import PropTypes from 'prop-types';
|
||||
import { exactProp, HTMLElementType, unstable_useEnhancedEffect as useEnhancedEffect, unstable_useForkRef as useForkRef, unstable_setRef as setRef } from '@mui/utils';
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
function getContainer(container) {
|
||||
return typeof container === 'function' ? container() : container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Portals provide a first-class way to render children into a DOM node
|
||||
* that exists outside the DOM hierarchy of the parent component.
|
||||
*
|
||||
* Demos:
|
||||
*
|
||||
* - [Portal](https://mui.com/base-ui/react-portal/)
|
||||
*
|
||||
* API:
|
||||
*
|
||||
* - [Portal API](https://mui.com/base-ui/react-portal/components-api/#portal)
|
||||
*/
|
||||
const Portal = /*#__PURE__*/React.forwardRef(function Portal(props, forwardedRef) {
|
||||
const {
|
||||
children,
|
||||
container,
|
||||
disablePortal = false
|
||||
} = props;
|
||||
const [mountNode, setMountNode] = React.useState(null);
|
||||
// @ts-expect-error TODO upstream fix
|
||||
const handleRef = useForkRef( /*#__PURE__*/React.isValidElement(children) ? children.ref : null, forwardedRef);
|
||||
useEnhancedEffect(() => {
|
||||
if (!disablePortal) {
|
||||
setMountNode(getContainer(container) || document.body);
|
||||
}
|
||||
}, [container, disablePortal]);
|
||||
useEnhancedEffect(() => {
|
||||
if (mountNode && !disablePortal) {
|
||||
setRef(forwardedRef, mountNode);
|
||||
return () => {
|
||||
setRef(forwardedRef, null);
|
||||
};
|
||||
}
|
||||
return undefined;
|
||||
}, [forwardedRef, mountNode, disablePortal]);
|
||||
if (disablePortal) {
|
||||
if ( /*#__PURE__*/React.isValidElement(children)) {
|
||||
const newProps = {
|
||||
ref: handleRef
|
||||
};
|
||||
return /*#__PURE__*/React.cloneElement(children, newProps);
|
||||
}
|
||||
return /*#__PURE__*/_jsx(React.Fragment, {
|
||||
children: children
|
||||
});
|
||||
}
|
||||
return /*#__PURE__*/_jsx(React.Fragment, {
|
||||
children: mountNode ? /*#__PURE__*/ReactDOM.createPortal(children, mountNode) : mountNode
|
||||
});
|
||||
});
|
||||
process.env.NODE_ENV !== "production" ? Portal.propTypes /* remove-proptypes */ = {
|
||||
// ┌────────────────────────────── Warning ──────────────────────────────┐
|
||||
// │ These PropTypes are generated from the TypeScript type definitions. │
|
||||
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
|
||||
// └─────────────────────────────────────────────────────────────────────┘
|
||||
/**
|
||||
* The children to render into the `container`.
|
||||
*/
|
||||
children: PropTypes.node,
|
||||
/**
|
||||
* An HTML element or function that returns one.
|
||||
* The `container` will have the portal children appended to it.
|
||||
*
|
||||
* You can also provide a callback, which is called in a React layout effect.
|
||||
* This lets you set the container from a ref, and also makes server-side rendering possible.
|
||||
*
|
||||
* By default, it uses the body of the top-level document object,
|
||||
* so it's simply `document.body` most of the time.
|
||||
*/
|
||||
container: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([HTMLElementType, PropTypes.func]),
|
||||
/**
|
||||
* The `children` will be under the DOM hierarchy of the parent component.
|
||||
* @default false
|
||||
*/
|
||||
disablePortal: PropTypes.bool
|
||||
} : void 0;
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
// eslint-disable-next-line
|
||||
Portal['propTypes' + ''] = exactProp(Portal.propTypes);
|
||||
}
|
||||
export { Portal };
|
||||
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
'use client';
|
||||
|
||||
export { Portal } from './Portal';
|
||||
export * from './Portal.types';
|
||||
+323
@@ -0,0 +1,323 @@
|
||||
'use client';
|
||||
|
||||
import _extends from "@babel/runtime/helpers/esm/extends";
|
||||
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
||||
var _span;
|
||||
const _excluded = ["areOptionsEqual", "autoComplete", "autoFocus", "children", "defaultValue", "defaultListboxOpen", "disabled", "getSerializedValue", "listboxId", "listboxOpen", "multiple", "name", "required", "onChange", "onListboxOpenChange", "getOptionAsString", "renderValue", "placeholder", "slotProps", "slots", "value"];
|
||||
import * as React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { unstable_useForkRef as useForkRef } from '@mui/utils';
|
||||
import { useSelect } from '../useSelect';
|
||||
import { useSlotProps } from '../utils';
|
||||
import { Popup } from '../Unstable_Popup/Popup';
|
||||
import { unstable_composeClasses as composeClasses } from '../composeClasses';
|
||||
import { getSelectUtilityClass } from './selectClasses';
|
||||
import { defaultOptionStringifier } from '../useSelect/defaultOptionStringifier';
|
||||
import { useClassNamesOverride } from '../utils/ClassNameConfigurator';
|
||||
import { SelectProvider } from '../useSelect/SelectProvider';
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
import { jsxs as _jsxs } from "react/jsx-runtime";
|
||||
function defaultRenderValue(selectedOptions) {
|
||||
if (Array.isArray(selectedOptions)) {
|
||||
return /*#__PURE__*/_jsx(React.Fragment, {
|
||||
children: selectedOptions.map(o => o.label).join(', ')
|
||||
});
|
||||
}
|
||||
return selectedOptions?.label ?? null;
|
||||
}
|
||||
function useUtilityClasses(ownerState) {
|
||||
const {
|
||||
active,
|
||||
disabled,
|
||||
open,
|
||||
focusVisible
|
||||
} = ownerState;
|
||||
const slots = {
|
||||
root: ['root', disabled && 'disabled', focusVisible && 'focusVisible', active && 'active', open && 'expanded'],
|
||||
listbox: ['listbox', disabled && 'disabled'],
|
||||
popup: ['popup']
|
||||
};
|
||||
return composeClasses(slots, useClassNamesOverride(getSelectUtilityClass));
|
||||
}
|
||||
|
||||
/**
|
||||
* The foundation for building custom-styled select components.
|
||||
*
|
||||
* Demos:
|
||||
*
|
||||
* - [Select](https://mui.com/base-ui/react-select/)
|
||||
*
|
||||
* API:
|
||||
*
|
||||
* - [Select API](https://mui.com/base-ui/react-select/components-api/#select)
|
||||
*/
|
||||
const Select = /*#__PURE__*/React.forwardRef(function Select(props, forwardedRef) {
|
||||
const {
|
||||
areOptionsEqual,
|
||||
autoComplete,
|
||||
autoFocus,
|
||||
children,
|
||||
defaultValue,
|
||||
defaultListboxOpen = false,
|
||||
disabled: disabledProp,
|
||||
getSerializedValue,
|
||||
listboxId,
|
||||
listboxOpen: listboxOpenProp,
|
||||
multiple = false,
|
||||
name,
|
||||
required = false,
|
||||
onChange,
|
||||
onListboxOpenChange,
|
||||
getOptionAsString = defaultOptionStringifier,
|
||||
renderValue: renderValueProp,
|
||||
placeholder,
|
||||
slotProps = {},
|
||||
slots = {},
|
||||
value: valueProp
|
||||
} = props,
|
||||
other = _objectWithoutPropertiesLoose(props, _excluded);
|
||||
const renderValue = renderValueProp ?? defaultRenderValue;
|
||||
const [buttonDefined, setButtonDefined] = React.useState(false);
|
||||
const buttonRef = React.useRef(null);
|
||||
const listboxRef = React.useRef(null);
|
||||
const Button = slots.root ?? 'button';
|
||||
const ListboxRoot = slots.listbox ?? 'ul';
|
||||
const PopupComponent = slots.popup ?? 'div';
|
||||
const handleButtonRefChange = React.useCallback(element => {
|
||||
setButtonDefined(element != null);
|
||||
}, []);
|
||||
const handleButtonRef = useForkRef(forwardedRef, buttonRef, handleButtonRefChange);
|
||||
React.useEffect(() => {
|
||||
if (autoFocus) {
|
||||
buttonRef.current.focus();
|
||||
}
|
||||
}, [autoFocus]);
|
||||
const {
|
||||
buttonActive,
|
||||
buttonFocusVisible,
|
||||
contextValue,
|
||||
disabled,
|
||||
getButtonProps,
|
||||
getListboxProps,
|
||||
getHiddenInputProps,
|
||||
getOptionMetadata,
|
||||
value,
|
||||
open
|
||||
} = useSelect({
|
||||
name,
|
||||
required,
|
||||
getSerializedValue,
|
||||
areOptionsEqual,
|
||||
buttonRef: handleButtonRef,
|
||||
defaultOpen: defaultListboxOpen,
|
||||
defaultValue,
|
||||
disabled: disabledProp,
|
||||
listboxId,
|
||||
multiple,
|
||||
open: listboxOpenProp,
|
||||
onChange,
|
||||
onOpenChange: onListboxOpenChange,
|
||||
getOptionAsString,
|
||||
value: valueProp,
|
||||
componentName: 'Select'
|
||||
});
|
||||
const ownerState = _extends({}, props, {
|
||||
active: buttonActive,
|
||||
defaultListboxOpen,
|
||||
disabled,
|
||||
focusVisible: buttonFocusVisible,
|
||||
open,
|
||||
multiple,
|
||||
renderValue,
|
||||
value
|
||||
});
|
||||
const classes = useUtilityClasses(ownerState);
|
||||
const buttonProps = useSlotProps({
|
||||
elementType: Button,
|
||||
getSlotProps: getButtonProps,
|
||||
externalSlotProps: slotProps.root,
|
||||
externalForwardedProps: other,
|
||||
ownerState,
|
||||
className: classes.root
|
||||
});
|
||||
const listboxProps = useSlotProps({
|
||||
elementType: ListboxRoot,
|
||||
getSlotProps: getListboxProps,
|
||||
externalSlotProps: slotProps.listbox,
|
||||
additionalProps: {
|
||||
ref: listboxRef
|
||||
},
|
||||
ownerState,
|
||||
className: classes.listbox
|
||||
});
|
||||
const popupProps = useSlotProps({
|
||||
elementType: PopupComponent,
|
||||
externalSlotProps: slotProps.popup,
|
||||
additionalProps: {
|
||||
anchor: buttonRef.current,
|
||||
keepMounted: true,
|
||||
open,
|
||||
placement: 'bottom-start',
|
||||
role: undefined
|
||||
},
|
||||
ownerState,
|
||||
className: classes.popup
|
||||
});
|
||||
let selectedOptionsMetadata;
|
||||
if (multiple) {
|
||||
selectedOptionsMetadata = value.map(v => getOptionMetadata(v)).filter(o => o !== undefined);
|
||||
} else {
|
||||
selectedOptionsMetadata = getOptionMetadata(value) ?? null;
|
||||
}
|
||||
return /*#__PURE__*/_jsxs(React.Fragment, {
|
||||
children: [/*#__PURE__*/_jsx(Button, _extends({}, buttonProps, {
|
||||
children: renderValue(selectedOptionsMetadata) ?? placeholder ?? ( // fall back to a zero-width space to prevent layout shift
|
||||
// from https://github.com/mui/material-ui/pull/24563
|
||||
_span || (_span = /*#__PURE__*/_jsx("span", {
|
||||
className: "notranslate",
|
||||
children: "\u200B"
|
||||
})))
|
||||
})), buttonDefined && /*#__PURE__*/_jsx(Popup, _extends({
|
||||
slots: {
|
||||
root: PopupComponent
|
||||
}
|
||||
}, popupProps, {
|
||||
children: /*#__PURE__*/_jsx(ListboxRoot, _extends({}, listboxProps, {
|
||||
children: /*#__PURE__*/_jsx(SelectProvider, {
|
||||
value: contextValue,
|
||||
children: children
|
||||
})
|
||||
}))
|
||||
})), /*#__PURE__*/_jsx("input", _extends({}, getHiddenInputProps(), {
|
||||
autoComplete: autoComplete
|
||||
}))]
|
||||
});
|
||||
});
|
||||
process.env.NODE_ENV !== "production" ? Select.propTypes /* remove-proptypes */ = {
|
||||
// ┌────────────────────────────── Warning ──────────────────────────────┐
|
||||
// │ These PropTypes are generated from the TypeScript type definitions. │
|
||||
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
|
||||
// └─────────────────────────────────────────────────────────────────────┘
|
||||
/**
|
||||
* A function used to determine if two options' values are equal.
|
||||
* By default, reference equality is used.
|
||||
*
|
||||
* There is a performance impact when using the `areOptionsEqual` prop (proportional to the number of options).
|
||||
* Therefore, it's recommented to use the default reference equality comparison whenever possible.
|
||||
*/
|
||||
areOptionsEqual: PropTypes.func,
|
||||
/**
|
||||
* This prop helps users to fill forms faster, especially on mobile devices.
|
||||
* The name can be confusing, as it's more like an autofill.
|
||||
* You can learn more about it [following the specification](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill).
|
||||
*/
|
||||
autoComplete: PropTypes.string,
|
||||
/**
|
||||
* If `true`, the select element is focused during the first mount
|
||||
* @default false
|
||||
*/
|
||||
autoFocus: PropTypes.bool,
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
children: PropTypes.node,
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
className: PropTypes.string,
|
||||
/**
|
||||
* If `true`, the select will be initially open.
|
||||
* @default false
|
||||
*/
|
||||
defaultListboxOpen: PropTypes.bool,
|
||||
/**
|
||||
* The default selected value. Use when the component is not controlled.
|
||||
*/
|
||||
defaultValue: PropTypes.any,
|
||||
/**
|
||||
* If `true`, the select is disabled.
|
||||
* @default false
|
||||
*/
|
||||
disabled: PropTypes.bool,
|
||||
/**
|
||||
* A function used to convert the option label to a string.
|
||||
* It's useful when labels are elements and need to be converted to plain text
|
||||
* to enable navigation using character keys on a keyboard.
|
||||
*
|
||||
* @default defaultOptionStringifier
|
||||
*/
|
||||
getOptionAsString: PropTypes.func,
|
||||
/**
|
||||
* A function to convert the currently selected value to a string.
|
||||
* Used to set a value of a hidden input associated with the select,
|
||||
* so that the selected value can be posted with a form.
|
||||
*/
|
||||
getSerializedValue: PropTypes.func,
|
||||
/**
|
||||
* `id` attribute of the listbox element.
|
||||
*/
|
||||
listboxId: PropTypes.string,
|
||||
/**
|
||||
* Controls the open state of the select's listbox.
|
||||
* @default undefined
|
||||
*/
|
||||
listboxOpen: PropTypes.bool,
|
||||
/**
|
||||
* If `true`, selecting multiple values is allowed.
|
||||
* This affects the type of the `value`, `defaultValue`, and `onChange` props.
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
multiple: PropTypes.bool,
|
||||
/**
|
||||
* Name of the element. For example used by the server to identify the fields in form submits.
|
||||
*/
|
||||
name: PropTypes.string,
|
||||
/**
|
||||
* Callback fired when an option is selected.
|
||||
*/
|
||||
onChange: PropTypes.func,
|
||||
/**
|
||||
* Callback fired when the component requests to be opened.
|
||||
* Use in controlled mode (see listboxOpen).
|
||||
*/
|
||||
onListboxOpenChange: PropTypes.func,
|
||||
/**
|
||||
* Text to show when there is no selected value.
|
||||
*/
|
||||
placeholder: PropTypes.node,
|
||||
/**
|
||||
* Function that customizes the rendering of the selected value.
|
||||
*/
|
||||
renderValue: PropTypes.func,
|
||||
/**
|
||||
* If `true`, the Select cannot be empty when submitting form.
|
||||
* @default false
|
||||
*/
|
||||
required: PropTypes.bool,
|
||||
/**
|
||||
* The props used for each slot inside the Input.
|
||||
* @default {}
|
||||
*/
|
||||
slotProps: PropTypes /* @typescript-to-proptypes-ignore */.shape({
|
||||
listbox: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
||||
popup: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
||||
root: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
|
||||
}),
|
||||
/**
|
||||
* The components used for each slot inside the Select.
|
||||
* Either a string to use a HTML element or a component.
|
||||
* @default {}
|
||||
*/
|
||||
slots: PropTypes /* @typescript-to-proptypes-ignore */.shape({
|
||||
listbox: PropTypes.elementType,
|
||||
popup: PropTypes.elementType,
|
||||
root: PropTypes.elementType
|
||||
}),
|
||||
/**
|
||||
* The selected value.
|
||||
* Set to `null` to deselect all options.
|
||||
*/
|
||||
value: PropTypes.any
|
||||
} : void 0;
|
||||
export { Select };
|
||||
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
'use client';
|
||||
|
||||
export { Select } from './Select';
|
||||
export * from './selectClasses';
|
||||
export * from './Select.types';
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import { generateUtilityClass } from '../generateUtilityClass';
|
||||
import { generateUtilityClasses } from '../generateUtilityClasses';
|
||||
const COMPONENT_NAME = 'Select';
|
||||
export function getSelectUtilityClass(slot) {
|
||||
return generateUtilityClass(COMPONENT_NAME, slot);
|
||||
}
|
||||
export const selectClasses = generateUtilityClasses(COMPONENT_NAME, ['root', 'button', 'listbox', 'popup', 'active', 'expanded', 'disabled', 'focusVisible']);
|
||||
+443
@@ -0,0 +1,443 @@
|
||||
'use client';
|
||||
|
||||
import _extends from "@babel/runtime/helpers/esm/extends";
|
||||
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
||||
const _excluded = ["aria-label", "aria-valuetext", "aria-labelledby", "className", "disableSwap", "disabled", "getAriaLabel", "getAriaValueText", "marks", "max", "min", "name", "onChange", "onChangeCommitted", "orientation", "shiftStep", "scale", "step", "tabIndex", "track", "value", "valueLabelFormat", "isRtl", "defaultValue", "slotProps", "slots"];
|
||||
import * as React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import clsx from 'clsx';
|
||||
import { chainPropTypes } from '@mui/utils';
|
||||
import { isHostComponent } from '../utils/isHostComponent';
|
||||
import { unstable_composeClasses as composeClasses } from '../composeClasses';
|
||||
import { getSliderUtilityClass } from './sliderClasses';
|
||||
import { useSlider, valueToPercent } from '../useSlider';
|
||||
import { useSlotProps } from '../utils/useSlotProps';
|
||||
import { resolveComponentProps } from '../utils/resolveComponentProps';
|
||||
import { useClassNamesOverride } from '../utils/ClassNameConfigurator';
|
||||
|
||||
// @ts-ignore
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
import { jsxs as _jsxs } from "react/jsx-runtime";
|
||||
function Identity(x) {
|
||||
return x;
|
||||
}
|
||||
const useUtilityClasses = ownerState => {
|
||||
const {
|
||||
disabled,
|
||||
dragging,
|
||||
marked,
|
||||
orientation,
|
||||
track
|
||||
} = ownerState;
|
||||
const slots = {
|
||||
root: ['root', disabled && 'disabled', dragging && 'dragging', marked && 'marked', orientation === 'vertical' && 'vertical', track === 'inverted' && 'trackInverted', track === false && 'trackFalse'],
|
||||
rail: ['rail'],
|
||||
track: ['track'],
|
||||
mark: ['mark'],
|
||||
markActive: ['markActive'],
|
||||
markLabel: ['markLabel'],
|
||||
markLabelActive: ['markLabelActive'],
|
||||
valueLabel: ['valueLabel'],
|
||||
thumb: ['thumb', disabled && 'disabled'],
|
||||
active: ['active'],
|
||||
disabled: ['disabled'],
|
||||
focusVisible: ['focusVisible']
|
||||
};
|
||||
return composeClasses(slots, useClassNamesOverride(getSliderUtilityClass));
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* Demos:
|
||||
*
|
||||
* - [Slider](https://mui.com/base-ui/react-slider/)
|
||||
*
|
||||
* API:
|
||||
*
|
||||
* - [Slider API](https://mui.com/base-ui/react-slider/components-api/#slider)
|
||||
*/
|
||||
const Slider = /*#__PURE__*/React.forwardRef(function Slider(props, forwardedRef) {
|
||||
const {
|
||||
'aria-label': ariaLabel,
|
||||
'aria-valuetext': ariaValuetext,
|
||||
'aria-labelledby': ariaLabelledby,
|
||||
className,
|
||||
disableSwap = false,
|
||||
disabled = false,
|
||||
getAriaLabel,
|
||||
getAriaValueText,
|
||||
marks: marksProp = false,
|
||||
max = 100,
|
||||
min = 0,
|
||||
orientation = 'horizontal',
|
||||
shiftStep = 10,
|
||||
scale = Identity,
|
||||
step = 1,
|
||||
track = 'normal',
|
||||
valueLabelFormat = Identity,
|
||||
isRtl = false,
|
||||
defaultValue,
|
||||
slotProps = {},
|
||||
slots = {}
|
||||
} = props,
|
||||
other = _objectWithoutPropertiesLoose(props, _excluded);
|
||||
|
||||
// all props with defaults
|
||||
// consider extracting to hook an reusing the lint rule for the variants
|
||||
const partialOwnerState = _extends({}, props, {
|
||||
marks: marksProp,
|
||||
disabled,
|
||||
disableSwap,
|
||||
isRtl,
|
||||
defaultValue,
|
||||
max,
|
||||
min,
|
||||
orientation,
|
||||
scale,
|
||||
step,
|
||||
shiftStep,
|
||||
track,
|
||||
valueLabelFormat
|
||||
});
|
||||
const {
|
||||
axisProps,
|
||||
getRootProps,
|
||||
getHiddenInputProps,
|
||||
getThumbProps,
|
||||
active,
|
||||
axis,
|
||||
range,
|
||||
focusedThumbIndex,
|
||||
dragging,
|
||||
marks,
|
||||
values,
|
||||
trackOffset,
|
||||
trackLeap,
|
||||
getThumbStyle
|
||||
} = useSlider(_extends({}, partialOwnerState, {
|
||||
rootRef: forwardedRef
|
||||
}));
|
||||
const ownerState = _extends({}, partialOwnerState, {
|
||||
marked: marks.length > 0 && marks.some(mark => mark.label),
|
||||
dragging,
|
||||
focusedThumbIndex,
|
||||
activeThumbIndex: active
|
||||
});
|
||||
const classes = useUtilityClasses(ownerState);
|
||||
const Root = slots.root ?? 'span';
|
||||
const rootProps = useSlotProps({
|
||||
elementType: Root,
|
||||
getSlotProps: getRootProps,
|
||||
externalSlotProps: slotProps.root,
|
||||
externalForwardedProps: other,
|
||||
ownerState,
|
||||
className: [classes.root, className]
|
||||
});
|
||||
const Rail = slots.rail ?? 'span';
|
||||
const railProps = useSlotProps({
|
||||
elementType: Rail,
|
||||
externalSlotProps: slotProps.rail,
|
||||
ownerState,
|
||||
className: classes.rail
|
||||
});
|
||||
const Track = slots.track ?? 'span';
|
||||
const trackProps = useSlotProps({
|
||||
elementType: Track,
|
||||
externalSlotProps: slotProps.track,
|
||||
additionalProps: {
|
||||
style: _extends({}, axisProps[axis].offset(trackOffset), axisProps[axis].leap(trackLeap))
|
||||
},
|
||||
ownerState,
|
||||
className: classes.track
|
||||
});
|
||||
const Thumb = slots.thumb ?? 'span';
|
||||
const thumbProps = useSlotProps({
|
||||
elementType: Thumb,
|
||||
getSlotProps: getThumbProps,
|
||||
externalSlotProps: slotProps.thumb,
|
||||
ownerState,
|
||||
skipResolvingSlotProps: true
|
||||
});
|
||||
const ValueLabel = slots.valueLabel;
|
||||
const valueLabelProps = useSlotProps({
|
||||
elementType: ValueLabel,
|
||||
externalSlotProps: slotProps.valueLabel,
|
||||
ownerState
|
||||
});
|
||||
const Mark = slots.mark ?? 'span';
|
||||
const markProps = useSlotProps({
|
||||
elementType: Mark,
|
||||
externalSlotProps: slotProps.mark,
|
||||
ownerState,
|
||||
className: classes.mark
|
||||
});
|
||||
const MarkLabel = slots.markLabel ?? 'span';
|
||||
const markLabelProps = useSlotProps({
|
||||
elementType: MarkLabel,
|
||||
externalSlotProps: slotProps.markLabel,
|
||||
ownerState
|
||||
});
|
||||
const Input = slots.input || 'input';
|
||||
const inputProps = useSlotProps({
|
||||
elementType: Input,
|
||||
getSlotProps: getHiddenInputProps,
|
||||
externalSlotProps: slotProps.input,
|
||||
ownerState
|
||||
});
|
||||
return /*#__PURE__*/_jsxs(Root, _extends({}, rootProps, {
|
||||
children: [/*#__PURE__*/_jsx(Rail, _extends({}, railProps)), /*#__PURE__*/_jsx(Track, _extends({}, trackProps)), marks.filter(mark => mark.value >= min && mark.value <= max).map((mark, index) => {
|
||||
const percent = valueToPercent(mark.value, min, max);
|
||||
const style = axisProps[axis].offset(percent);
|
||||
let markActive;
|
||||
if (track === false) {
|
||||
markActive = values.indexOf(mark.value) !== -1;
|
||||
} else {
|
||||
markActive = track === 'normal' && (range ? mark.value >= values[0] && mark.value <= values[values.length - 1] : mark.value <= values[0]) || track === 'inverted' && (range ? mark.value <= values[0] || mark.value >= values[values.length - 1] : mark.value >= values[0]);
|
||||
}
|
||||
return /*#__PURE__*/_jsxs(React.Fragment, {
|
||||
children: [/*#__PURE__*/_jsx(Mark, _extends({
|
||||
"data-index": index
|
||||
}, markProps, !isHostComponent(Mark) && {
|
||||
markActive
|
||||
}, {
|
||||
style: _extends({}, style, markProps.style),
|
||||
className: clsx(markProps.className, markActive && classes.markActive)
|
||||
})), mark.label != null ? /*#__PURE__*/_jsx(MarkLabel, _extends({
|
||||
"aria-hidden": true,
|
||||
"data-index": index
|
||||
}, markLabelProps, !isHostComponent(MarkLabel) && {
|
||||
markLabelActive: markActive
|
||||
}, {
|
||||
style: _extends({}, style, markLabelProps.style),
|
||||
className: clsx(classes.markLabel, markLabelProps.className, markActive && classes.markLabelActive),
|
||||
children: mark.label
|
||||
})) : null]
|
||||
}, index);
|
||||
}), values.map((value, index) => {
|
||||
const percent = valueToPercent(value, min, max);
|
||||
const style = axisProps[axis].offset(percent);
|
||||
const resolvedSlotProps = resolveComponentProps(slotProps.thumb, ownerState, {
|
||||
index,
|
||||
focused: focusedThumbIndex === index,
|
||||
active: active === index
|
||||
});
|
||||
return /*#__PURE__*/_jsxs(Thumb, _extends({
|
||||
"data-index": index
|
||||
}, thumbProps, resolvedSlotProps, {
|
||||
className: clsx(classes.thumb, thumbProps.className, resolvedSlotProps?.className, active === index && classes.active, focusedThumbIndex === index && classes.focusVisible),
|
||||
style: _extends({}, style, getThumbStyle(index), thumbProps.style, resolvedSlotProps?.style),
|
||||
children: [/*#__PURE__*/_jsx(Input, _extends({
|
||||
"data-index": index,
|
||||
"aria-label": getAriaLabel ? getAriaLabel(index) : ariaLabel,
|
||||
"aria-valuenow": scale(value),
|
||||
"aria-labelledby": ariaLabelledby,
|
||||
"aria-valuetext": getAriaValueText ? getAriaValueText(scale(value), index) : ariaValuetext,
|
||||
value: values[index]
|
||||
}, inputProps)), ValueLabel ? /*#__PURE__*/_jsx(ValueLabel, _extends({}, !isHostComponent(ValueLabel) && {
|
||||
valueLabelFormat,
|
||||
index,
|
||||
disabled
|
||||
}, valueLabelProps, {
|
||||
children: typeof valueLabelFormat === 'function' ? valueLabelFormat(scale(value), index) : valueLabelFormat
|
||||
})) : null]
|
||||
}), index);
|
||||
})]
|
||||
}));
|
||||
});
|
||||
process.env.NODE_ENV !== "production" ? Slider.propTypes /* remove-proptypes */ = {
|
||||
// ┌────────────────────────────── Warning ──────────────────────────────┐
|
||||
// │ These PropTypes are generated from the TypeScript type definitions. │
|
||||
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
|
||||
// └─────────────────────────────────────────────────────────────────────┘
|
||||
/**
|
||||
* The label of the slider.
|
||||
*/
|
||||
'aria-label': chainPropTypes(PropTypes.string, props => {
|
||||
const range = Array.isArray(props.value || props.defaultValue);
|
||||
if (range && props['aria-label'] != null) {
|
||||
return new Error('MUI: You need to use the `getAriaLabel` prop instead of `aria-label` when using a range slider.');
|
||||
}
|
||||
return null;
|
||||
}),
|
||||
/**
|
||||
* The id of the element containing a label for the slider.
|
||||
*/
|
||||
'aria-labelledby': PropTypes.string,
|
||||
/**
|
||||
* A string value that provides a user-friendly name for the current value of the slider.
|
||||
*/
|
||||
'aria-valuetext': chainPropTypes(PropTypes.string, props => {
|
||||
const range = Array.isArray(props.value || props.defaultValue);
|
||||
if (range && props['aria-valuetext'] != null) {
|
||||
return new Error('MUI: You need to use the `getAriaValueText` prop instead of `aria-valuetext` when using a range slider.');
|
||||
}
|
||||
return null;
|
||||
}),
|
||||
/**
|
||||
* The default value. Use when the component is not controlled.
|
||||
*/
|
||||
defaultValue: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.number), PropTypes.number]),
|
||||
/**
|
||||
* If `true`, the component is disabled.
|
||||
* @default false
|
||||
*/
|
||||
disabled: PropTypes.bool,
|
||||
/**
|
||||
* If `true`, the active thumb doesn't swap when moving pointer over a thumb while dragging another thumb.
|
||||
* @default false
|
||||
*/
|
||||
disableSwap: PropTypes.bool,
|
||||
/**
|
||||
* Accepts a function which returns a string value that provides a user-friendly name for the thumb labels of the slider.
|
||||
* This is important for screen reader users.
|
||||
* @param {number} index The thumb label's index to format.
|
||||
* @returns {string}
|
||||
*/
|
||||
getAriaLabel: PropTypes.func,
|
||||
/**
|
||||
* Accepts a function which returns a string value that provides a user-friendly name for the current value of the slider.
|
||||
* This is important for screen reader users.
|
||||
* @param {number} value The thumb label's value to format.
|
||||
* @param {number} index The thumb label's index to format.
|
||||
* @returns {string}
|
||||
*/
|
||||
getAriaValueText: PropTypes.func,
|
||||
/**
|
||||
* If `true` the Slider will be rendered right-to-left (with the lowest value on the right-hand side).
|
||||
* @default false
|
||||
*/
|
||||
isRtl: PropTypes.bool,
|
||||
/**
|
||||
* Marks indicate predetermined values to which the user can move the slider.
|
||||
* If `true` the marks are spaced according the value of the `step` prop.
|
||||
* If an array, it should contain objects with `value` and an optional `label` keys.
|
||||
* @default false
|
||||
*/
|
||||
marks: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.shape({
|
||||
label: PropTypes.node,
|
||||
value: PropTypes.number.isRequired
|
||||
})), PropTypes.bool]),
|
||||
/**
|
||||
* The maximum allowed value of the slider.
|
||||
* Should not be equal to min.
|
||||
* @default 100
|
||||
*/
|
||||
max: PropTypes.number,
|
||||
/**
|
||||
* The minimum allowed value of the slider.
|
||||
* Should not be equal to max.
|
||||
* @default 0
|
||||
*/
|
||||
min: PropTypes.number,
|
||||
/**
|
||||
* Name attribute of the hidden `input` element.
|
||||
*/
|
||||
name: PropTypes.string,
|
||||
/**
|
||||
* Callback function that is fired when the slider's value changed.
|
||||
*
|
||||
* @param {Event} event The event source of the callback.
|
||||
* You can pull out the new value by accessing `event.target.value` (any).
|
||||
* **Warning**: This is a generic event not a change event.
|
||||
* @param {number | number[]} value The new value.
|
||||
* @param {number} activeThumb Index of the currently moved thumb.
|
||||
*/
|
||||
onChange: PropTypes.func,
|
||||
/**
|
||||
* Callback function that is fired when the `mouseup` is triggered.
|
||||
*
|
||||
* @param {React.SyntheticEvent | Event} event The event source of the callback. **Warning**: This is a generic event not a change event.
|
||||
* @param {number | number[]} value The new value.
|
||||
*/
|
||||
onChangeCommitted: PropTypes.func,
|
||||
/**
|
||||
* The component orientation.
|
||||
* @default 'horizontal'
|
||||
*/
|
||||
orientation: PropTypes.oneOf(['horizontal', 'vertical']),
|
||||
/**
|
||||
* A transformation function, to change the scale of the slider.
|
||||
* @param {any} x
|
||||
* @returns {any}
|
||||
* @default function Identity(x) {
|
||||
* return x;
|
||||
* }
|
||||
*/
|
||||
scale: PropTypes.func,
|
||||
/**
|
||||
* The granularity with which the slider can step through values when using Page Up/Page Down or Shift + Arrow Up/Arrow Down.
|
||||
* @default 10
|
||||
*/
|
||||
shiftStep: PropTypes.number,
|
||||
/**
|
||||
* The props used for each slot inside the Slider.
|
||||
* @default {}
|
||||
*/
|
||||
slotProps: PropTypes.shape({
|
||||
input: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
||||
mark: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
||||
markLabel: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
||||
rail: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
||||
root: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
||||
thumb: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
||||
track: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
||||
valueLabel: PropTypes.oneOfType([PropTypes.any, PropTypes.func])
|
||||
}),
|
||||
/**
|
||||
* The components used for each slot inside the Slider.
|
||||
* Either a string to use a HTML element or a component.
|
||||
* @default {}
|
||||
*/
|
||||
slots: PropTypes.shape({
|
||||
input: PropTypes.elementType,
|
||||
mark: PropTypes.elementType,
|
||||
markLabel: PropTypes.elementType,
|
||||
rail: PropTypes.elementType,
|
||||
root: PropTypes.elementType,
|
||||
thumb: PropTypes.elementType,
|
||||
track: PropTypes.elementType,
|
||||
valueLabel: PropTypes.elementType
|
||||
}),
|
||||
/**
|
||||
* The granularity with which the slider can step through values. (A "discrete" slider.)
|
||||
* The `min` prop serves as the origin for the valid values.
|
||||
* We recommend (max - min) to be evenly divisible by the step.
|
||||
*
|
||||
* When step is `null`, the thumb can only be slid onto marks provided with the `marks` prop.
|
||||
* @default 1
|
||||
*/
|
||||
step: PropTypes.number,
|
||||
/**
|
||||
* Tab index attribute of the hidden `input` element.
|
||||
*/
|
||||
tabIndex: PropTypes.number,
|
||||
/**
|
||||
* The track presentation:
|
||||
*
|
||||
* - `normal` the track will render a bar representing the slider value.
|
||||
* - `inverted` the track will render a bar representing the remaining slider value.
|
||||
* - `false` the track will render without a bar.
|
||||
* @default 'normal'
|
||||
*/
|
||||
track: PropTypes.oneOf(['inverted', 'normal', false]),
|
||||
/**
|
||||
* The value of the slider.
|
||||
* For ranged sliders, provide an array with two values.
|
||||
*/
|
||||
value: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.number), PropTypes.number]),
|
||||
/**
|
||||
* The format function the value label's value.
|
||||
*
|
||||
* When a function is provided, it should have the following signature:
|
||||
*
|
||||
* - {number} value The value label's value to format
|
||||
* - {number} index The value label's index to format
|
||||
* @param {any} x
|
||||
* @returns {any}
|
||||
* @default function Identity(x) {
|
||||
* return x;
|
||||
* }
|
||||
*/
|
||||
valueLabelFormat: PropTypes.oneOfType([PropTypes.func, PropTypes.string])
|
||||
} : void 0;
|
||||
export { Slider };
|
||||
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
'use client';
|
||||
|
||||
export { Slider } from './Slider';
|
||||
export * from './Slider.types';
|
||||
export * from './sliderClasses';
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import { generateUtilityClasses } from '../generateUtilityClasses';
|
||||
import { generateUtilityClass } from '../generateUtilityClass';
|
||||
const COMPONENT_NAME = 'Slider';
|
||||
export function getSliderUtilityClass(slot) {
|
||||
return generateUtilityClass(COMPONENT_NAME, slot);
|
||||
}
|
||||
export const sliderClasses = generateUtilityClasses(COMPONENT_NAME, ['root', 'active', 'focusVisible', 'disabled', 'dragging', 'marked', 'vertical', 'trackInverted', 'trackFalse', 'rail', 'track', 'mark', 'markActive', 'markLabel', 'markLabelActive', 'thumb']);
|
||||
+164
@@ -0,0 +1,164 @@
|
||||
'use client';
|
||||
|
||||
import _extends from "@babel/runtime/helpers/esm/extends";
|
||||
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
||||
const _excluded = ["autoHideDuration", "children", "disableWindowBlurListener", "exited", "onBlur", "onClose", "onFocus", "onMouseEnter", "onMouseLeave", "open", "resumeHideDuration", "slotProps", "slots"];
|
||||
import * as React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { ClickAwayListener } from '../ClickAwayListener';
|
||||
import { unstable_composeClasses as composeClasses } from '../composeClasses';
|
||||
import { getSnackbarUtilityClass } from './snackbarClasses';
|
||||
import { useSnackbar } from '../useSnackbar';
|
||||
import { useSlotProps } from '../utils';
|
||||
import { useClassNamesOverride } from '../utils/ClassNameConfigurator';
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
const useUtilityClasses = () => {
|
||||
const slots = {
|
||||
root: ['root']
|
||||
};
|
||||
return composeClasses(slots, useClassNamesOverride(getSnackbarUtilityClass));
|
||||
};
|
||||
/**
|
||||
*
|
||||
* Demos:
|
||||
*
|
||||
* - [Snackbar](https://mui.com/base-ui/react-snackbar/)
|
||||
* - [Snackbar](https://mui.com/joy-ui/react-snackbar/)
|
||||
* - [Snackbar](https://mui.com/material-ui/react-snackbar/)
|
||||
*
|
||||
* API:
|
||||
*
|
||||
* - [Snackbar API](https://mui.com/base-ui/react-snackbar/components-api/#snackbar)
|
||||
*/
|
||||
const Snackbar = /*#__PURE__*/React.forwardRef(function Snackbar(props, forwardedRef) {
|
||||
const {
|
||||
autoHideDuration = null,
|
||||
children,
|
||||
disableWindowBlurListener = false,
|
||||
exited = true,
|
||||
onClose,
|
||||
open,
|
||||
resumeHideDuration,
|
||||
slotProps = {},
|
||||
slots = {}
|
||||
} = props,
|
||||
other = _objectWithoutPropertiesLoose(props, _excluded);
|
||||
const classes = useUtilityClasses();
|
||||
const {
|
||||
getRootProps,
|
||||
onClickAway
|
||||
} = useSnackbar(_extends({}, props, {
|
||||
autoHideDuration,
|
||||
disableWindowBlurListener,
|
||||
onClose,
|
||||
open,
|
||||
resumeHideDuration
|
||||
}));
|
||||
const ownerState = props;
|
||||
const Root = slots.root || 'div';
|
||||
const rootProps = useSlotProps({
|
||||
elementType: Root,
|
||||
getSlotProps: getRootProps,
|
||||
externalForwardedProps: other,
|
||||
externalSlotProps: slotProps.root,
|
||||
additionalProps: {
|
||||
ref: forwardedRef
|
||||
},
|
||||
ownerState,
|
||||
className: classes.root
|
||||
});
|
||||
const clickAwayListenerProps = useSlotProps({
|
||||
elementType: ClickAwayListener,
|
||||
externalSlotProps: slotProps.clickAwayListener,
|
||||
additionalProps: {
|
||||
onClickAway
|
||||
},
|
||||
ownerState
|
||||
});
|
||||
|
||||
// ClickAwayListener doesn't support ownerState
|
||||
delete clickAwayListenerProps.ownerState;
|
||||
|
||||
// So that we only render active snackbars.
|
||||
if (!open && exited) {
|
||||
return null;
|
||||
}
|
||||
return /*#__PURE__*/_jsx(ClickAwayListener, _extends({}, clickAwayListenerProps, {
|
||||
children: /*#__PURE__*/_jsx(Root, _extends({}, rootProps, {
|
||||
children: children
|
||||
}))
|
||||
}));
|
||||
});
|
||||
process.env.NODE_ENV !== "production" ? Snackbar.propTypes /* remove-proptypes */ = {
|
||||
// ┌────────────────────────────── Warning ──────────────────────────────┐
|
||||
// │ These PropTypes are generated from the TypeScript type definitions. │
|
||||
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
|
||||
// └─────────────────────────────────────────────────────────────────────┘
|
||||
/**
|
||||
* The number of milliseconds to wait before automatically calling the
|
||||
* `onClose` function. `onClose` should then set the state of the `open`
|
||||
* prop to hide the Snackbar. This behavior is disabled by default with
|
||||
* the `null` value.
|
||||
* @default null
|
||||
*/
|
||||
autoHideDuration: PropTypes.number,
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
children: PropTypes.node,
|
||||
/**
|
||||
* If `true`, the `autoHideDuration` timer will expire even if the window is not focused.
|
||||
* @default false
|
||||
*/
|
||||
disableWindowBlurListener: PropTypes.bool,
|
||||
/**
|
||||
* The prop used to handle exited transition and unmount the component.
|
||||
* @default true
|
||||
*/
|
||||
exited: PropTypes.bool,
|
||||
/**
|
||||
* Callback fired when the component requests to be closed.
|
||||
* Typically `onClose` is used to set state in the parent component,
|
||||
* which is used to control the `Snackbar` `open` prop.
|
||||
* The `reason` parameter can optionally be used to control the response to `onClose`,
|
||||
* for example ignoring `clickaway`.
|
||||
*
|
||||
* @param {React.SyntheticEvent<any> | Event} event The event source of the callback.
|
||||
* @param {string} reason Can be: `"timeout"` (`autoHideDuration` expired), `"clickaway"`, or `"escapeKeyDown"`.
|
||||
*/
|
||||
onClose: PropTypes.func,
|
||||
/**
|
||||
* If `true`, the component is shown.
|
||||
*/
|
||||
open: PropTypes.bool,
|
||||
/**
|
||||
* The number of milliseconds to wait before dismissing after user interaction.
|
||||
* If `autoHideDuration` prop isn't specified, it does nothing.
|
||||
* If `autoHideDuration` prop is specified but `resumeHideDuration` isn't,
|
||||
* we default to `autoHideDuration / 2` ms.
|
||||
*/
|
||||
resumeHideDuration: PropTypes.number,
|
||||
/**
|
||||
* The props used for each slot inside the Snackbar.
|
||||
* @default {}
|
||||
*/
|
||||
slotProps: PropTypes.shape({
|
||||
clickAwayListener: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
|
||||
children: PropTypes.element.isRequired,
|
||||
disableReactTree: PropTypes.bool,
|
||||
mouseEvent: PropTypes.oneOf(['onClick', 'onMouseDown', 'onMouseUp', 'onPointerDown', 'onPointerUp', false]),
|
||||
onClickAway: PropTypes.func,
|
||||
touchEvent: PropTypes.oneOf(['onTouchEnd', 'onTouchStart', false])
|
||||
})]),
|
||||
root: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
|
||||
}),
|
||||
/**
|
||||
* The components used for each slot inside the Snackbar.
|
||||
* Either a string to use a HTML element or a component.
|
||||
* @default {}
|
||||
*/
|
||||
slots: PropTypes.shape({
|
||||
root: PropTypes.elementType
|
||||
})
|
||||
} : void 0;
|
||||
export { Snackbar };
|
||||
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
'use client';
|
||||
|
||||
export { Snackbar } from './Snackbar';
|
||||
export * from './Snackbar.types';
|
||||
export * from './snackbarClasses';
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import { generateUtilityClass } from '../generateUtilityClass';
|
||||
import { generateUtilityClasses } from '../generateUtilityClasses';
|
||||
const COMPONENT_NAME = 'Snackbar';
|
||||
export function getSnackbarUtilityClass(slot) {
|
||||
return generateUtilityClass(COMPONENT_NAME, slot);
|
||||
}
|
||||
export const snackbarClasses = generateUtilityClasses(COMPONENT_NAME, ['root']);
|
||||
+170
@@ -0,0 +1,170 @@
|
||||
'use client';
|
||||
|
||||
import _extends from "@babel/runtime/helpers/esm/extends";
|
||||
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
||||
const _excluded = ["checked", "defaultChecked", "disabled", "onBlur", "onChange", "onFocus", "onFocusVisible", "readOnly", "required", "slotProps", "slots"];
|
||||
import * as React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { unstable_composeClasses as composeClasses } from '../composeClasses';
|
||||
import { useSwitch } from '../useSwitch';
|
||||
import { useSlotProps } from '../utils';
|
||||
import { useClassNamesOverride } from '../utils/ClassNameConfigurator';
|
||||
import { getSwitchUtilityClass } from './switchClasses';
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
import { jsxs as _jsxs } from "react/jsx-runtime";
|
||||
const useUtilityClasses = ownerState => {
|
||||
const {
|
||||
checked,
|
||||
disabled,
|
||||
focusVisible,
|
||||
readOnly
|
||||
} = ownerState;
|
||||
const slots = {
|
||||
root: ['root', checked && 'checked', disabled && 'disabled', focusVisible && 'focusVisible', readOnly && 'readOnly'],
|
||||
thumb: ['thumb'],
|
||||
input: ['input'],
|
||||
track: ['track']
|
||||
};
|
||||
return composeClasses(slots, useClassNamesOverride(getSwitchUtilityClass));
|
||||
};
|
||||
|
||||
/**
|
||||
* The foundation for building custom-styled switches.
|
||||
*
|
||||
* Demos:
|
||||
*
|
||||
* - [Switch](https://mui.com/base-ui/react-switch/)
|
||||
*
|
||||
* API:
|
||||
*
|
||||
* - [Switch API](https://mui.com/base-ui/react-switch/components-api/#switch)
|
||||
*/
|
||||
const Switch = /*#__PURE__*/React.forwardRef(function Switch(props, forwardedRef) {
|
||||
const {
|
||||
slotProps = {},
|
||||
slots = {}
|
||||
} = props,
|
||||
other = _objectWithoutPropertiesLoose(props, _excluded);
|
||||
const {
|
||||
getInputProps,
|
||||
checked,
|
||||
disabled,
|
||||
focusVisible,
|
||||
readOnly
|
||||
} = useSwitch(props);
|
||||
const ownerState = _extends({}, props, {
|
||||
checked,
|
||||
disabled,
|
||||
focusVisible,
|
||||
readOnly
|
||||
});
|
||||
const classes = useUtilityClasses(ownerState);
|
||||
const Root = slots.root ?? 'span';
|
||||
const rootProps = useSlotProps({
|
||||
elementType: Root,
|
||||
externalSlotProps: slotProps.root,
|
||||
externalForwardedProps: other,
|
||||
additionalProps: {
|
||||
ref: forwardedRef
|
||||
},
|
||||
ownerState,
|
||||
className: classes.root
|
||||
});
|
||||
const Thumb = slots.thumb ?? 'span';
|
||||
const thumbProps = useSlotProps({
|
||||
elementType: Thumb,
|
||||
externalSlotProps: slotProps.thumb,
|
||||
ownerState,
|
||||
className: classes.thumb
|
||||
});
|
||||
const Input = slots.input ?? 'input';
|
||||
const inputProps = useSlotProps({
|
||||
elementType: Input,
|
||||
getSlotProps: getInputProps,
|
||||
externalSlotProps: slotProps.input,
|
||||
ownerState,
|
||||
className: classes.input
|
||||
});
|
||||
const Track = slots.track === null ? () => null : slots.track ?? 'span';
|
||||
const trackProps = useSlotProps({
|
||||
elementType: Track,
|
||||
externalSlotProps: slotProps.track,
|
||||
ownerState,
|
||||
className: classes.track
|
||||
});
|
||||
return /*#__PURE__*/_jsxs(Root, _extends({}, rootProps, {
|
||||
children: [/*#__PURE__*/_jsx(Track, _extends({}, trackProps)), /*#__PURE__*/_jsx(Thumb, _extends({}, thumbProps)), /*#__PURE__*/_jsx(Input, _extends({}, inputProps))]
|
||||
}));
|
||||
});
|
||||
process.env.NODE_ENV !== "production" ? Switch.propTypes /* remove-proptypes */ = {
|
||||
// ┌────────────────────────────── Warning ──────────────────────────────┐
|
||||
// │ These PropTypes are generated from the TypeScript type definitions. │
|
||||
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
|
||||
// └─────────────────────────────────────────────────────────────────────┘
|
||||
/**
|
||||
* If `true`, the component is checked.
|
||||
*/
|
||||
checked: PropTypes.bool,
|
||||
/**
|
||||
* Class name applied to the root element.
|
||||
*/
|
||||
className: PropTypes.string,
|
||||
/**
|
||||
* The default checked state. Use when the component is not controlled.
|
||||
*/
|
||||
defaultChecked: PropTypes.bool,
|
||||
/**
|
||||
* If `true`, the component is disabled.
|
||||
*/
|
||||
disabled: PropTypes.bool,
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
onBlur: PropTypes.func,
|
||||
/**
|
||||
* Callback fired when the state is changed.
|
||||
*
|
||||
* @param {React.ChangeEvent<HTMLInputElement>} event The event source of the callback.
|
||||
* You can pull out the new value by accessing `event.target.value` (string).
|
||||
* You can pull out the new checked state by accessing `event.target.checked` (boolean).
|
||||
*/
|
||||
onChange: PropTypes.func,
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
onFocus: PropTypes.func,
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
onFocusVisible: PropTypes.func,
|
||||
/**
|
||||
* If `true`, the component is read only.
|
||||
*/
|
||||
readOnly: PropTypes.bool,
|
||||
/**
|
||||
* If `true`, the `input` element is required.
|
||||
*/
|
||||
required: PropTypes.bool,
|
||||
/**
|
||||
* The props used for each slot inside the Switch.
|
||||
* @default {}
|
||||
*/
|
||||
slotProps: PropTypes.shape({
|
||||
input: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
||||
root: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
||||
thumb: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
||||
track: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
|
||||
}),
|
||||
/**
|
||||
* The components used for each slot inside the Switch.
|
||||
* Either a string to use a HTML element or a component.
|
||||
* @default {}
|
||||
*/
|
||||
slots: PropTypes /* @typescript-to-proptypes-ignore */.shape({
|
||||
input: PropTypes.elementType,
|
||||
root: PropTypes.elementType,
|
||||
thumb: PropTypes.elementType,
|
||||
track: PropTypes.oneOfType([PropTypes.elementType, PropTypes.oneOf([null])])
|
||||
})
|
||||
} : void 0;
|
||||
export { Switch };
|
||||
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
'use client';
|
||||
|
||||
export { Switch } from './Switch';
|
||||
export * from './Switch.types';
|
||||
export * from './switchClasses';
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import { generateUtilityClass } from '../generateUtilityClass';
|
||||
import { generateUtilityClasses } from '../generateUtilityClasses';
|
||||
const COMPONENT_NAME = 'Switch';
|
||||
export function getSwitchUtilityClass(slot) {
|
||||
return generateUtilityClass(COMPONENT_NAME, slot);
|
||||
}
|
||||
export const switchClasses = generateUtilityClasses(COMPONENT_NAME, ['root', 'input', 'track', 'thumb', 'checked', 'disabled', 'focusVisible', 'readOnly']);
|
||||
+124
@@ -0,0 +1,124 @@
|
||||
'use client';
|
||||
|
||||
import _extends from "@babel/runtime/helpers/esm/extends";
|
||||
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
||||
const _excluded = ["action", "children", "disabled", "onChange", "onClick", "onFocus", "slotProps", "slots", "value"];
|
||||
import * as React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { unstable_useForkRef as useForkRef } from '@mui/utils';
|
||||
import { unstable_composeClasses as composeClasses } from '../composeClasses';
|
||||
import { getTabUtilityClass } from './tabClasses';
|
||||
import { useTab } from '../useTab';
|
||||
import { useSlotProps } from '../utils';
|
||||
import { useClassNamesOverride } from '../utils/ClassNameConfigurator';
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
const useUtilityClasses = ownerState => {
|
||||
const {
|
||||
selected,
|
||||
disabled
|
||||
} = ownerState;
|
||||
const slots = {
|
||||
root: ['root', selected && 'selected', disabled && 'disabled']
|
||||
};
|
||||
return composeClasses(slots, useClassNamesOverride(getTabUtilityClass));
|
||||
};
|
||||
/**
|
||||
*
|
||||
* Demos:
|
||||
*
|
||||
* - [Tabs](https://mui.com/base-ui/react-tabs/)
|
||||
*
|
||||
* API:
|
||||
*
|
||||
* - [Tab API](https://mui.com/base-ui/react-tabs/components-api/#tab)
|
||||
*/
|
||||
const Tab = /*#__PURE__*/React.forwardRef(function Tab(props, forwardedRef) {
|
||||
const {
|
||||
children,
|
||||
disabled = false,
|
||||
slotProps = {},
|
||||
slots = {},
|
||||
value
|
||||
} = props,
|
||||
other = _objectWithoutPropertiesLoose(props, _excluded);
|
||||
const tabRef = React.useRef();
|
||||
const handleRef = useForkRef(tabRef, forwardedRef);
|
||||
const {
|
||||
active,
|
||||
highlighted,
|
||||
selected,
|
||||
getRootProps
|
||||
} = useTab(_extends({}, props, {
|
||||
rootRef: handleRef,
|
||||
value
|
||||
}));
|
||||
const ownerState = _extends({}, props, {
|
||||
active,
|
||||
disabled,
|
||||
highlighted,
|
||||
selected
|
||||
});
|
||||
const classes = useUtilityClasses(ownerState);
|
||||
const TabRoot = slots.root ?? 'button';
|
||||
const tabRootProps = useSlotProps({
|
||||
elementType: TabRoot,
|
||||
getSlotProps: getRootProps,
|
||||
externalSlotProps: slotProps.root,
|
||||
externalForwardedProps: other,
|
||||
additionalProps: {
|
||||
ref: forwardedRef
|
||||
},
|
||||
ownerState,
|
||||
className: classes.root
|
||||
});
|
||||
return /*#__PURE__*/_jsx(TabRoot, _extends({}, tabRootProps, {
|
||||
children: children
|
||||
}));
|
||||
});
|
||||
process.env.NODE_ENV !== "production" ? Tab.propTypes /* remove-proptypes */ = {
|
||||
// ┌────────────────────────────── Warning ──────────────────────────────┐
|
||||
// │ These PropTypes are generated from the TypeScript type definitions. │
|
||||
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
|
||||
// └─────────────────────────────────────────────────────────────────────┘
|
||||
/**
|
||||
* A ref for imperative actions. It currently only supports `focusVisible()` action.
|
||||
*/
|
||||
action: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
|
||||
current: PropTypes.shape({
|
||||
focusVisible: PropTypes.func.isRequired
|
||||
})
|
||||
})]),
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
children: PropTypes.node,
|
||||
/**
|
||||
* If `true`, the component is disabled.
|
||||
* @default false
|
||||
*/
|
||||
disabled: PropTypes.bool,
|
||||
/**
|
||||
* Callback invoked when new value is being set.
|
||||
*/
|
||||
onChange: PropTypes.func,
|
||||
/**
|
||||
* The props used for each slot inside the Tab.
|
||||
* @default {}
|
||||
*/
|
||||
slotProps: PropTypes.shape({
|
||||
root: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
|
||||
}),
|
||||
/**
|
||||
* The components used for each slot inside the Tab.
|
||||
* Either a string to use a HTML element or a component.
|
||||
* @default {}
|
||||
*/
|
||||
slots: PropTypes.shape({
|
||||
root: PropTypes.elementType
|
||||
}),
|
||||
/**
|
||||
* You can provide your own value. Otherwise, it falls back to the child position index.
|
||||
*/
|
||||
value: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
|
||||
} : void 0;
|
||||
export { Tab };
|
||||
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
'use client';
|
||||
|
||||
export { Tab } from './Tab';
|
||||
export * from './Tab.types';
|
||||
export * from './tabClasses';
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import { generateUtilityClass } from '../generateUtilityClass';
|
||||
import { generateUtilityClasses } from '../generateUtilityClasses';
|
||||
const COMPONENT_NAME = 'Tab';
|
||||
export function getTabUtilityClass(slot) {
|
||||
return generateUtilityClass(COMPONENT_NAME, slot);
|
||||
}
|
||||
export const tabClasses = generateUtilityClasses(COMPONENT_NAME, ['root', 'selected', 'disabled']);
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
'use client';
|
||||
|
||||
import _extends from "@babel/runtime/helpers/esm/extends";
|
||||
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
||||
const _excluded = ["children", "value", "slotProps", "slots"];
|
||||
import * as React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { useSlotProps } from '../utils';
|
||||
import { unstable_composeClasses as composeClasses } from '../composeClasses';
|
||||
import { getTabPanelUtilityClass } from './tabPanelClasses';
|
||||
import { useTabPanel } from '../useTabPanel/useTabPanel';
|
||||
import { useClassNamesOverride } from '../utils/ClassNameConfigurator';
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
const useUtilityClasses = ownerState => {
|
||||
const {
|
||||
hidden
|
||||
} = ownerState;
|
||||
const slots = {
|
||||
root: ['root', hidden && 'hidden']
|
||||
};
|
||||
return composeClasses(slots, useClassNamesOverride(getTabPanelUtilityClass));
|
||||
};
|
||||
/**
|
||||
*
|
||||
* Demos:
|
||||
*
|
||||
* - [Tabs](https://mui.com/base-ui/react-tabs/)
|
||||
*
|
||||
* API:
|
||||
*
|
||||
* - [TabPanel API](https://mui.com/base-ui/react-tabs/components-api/#tab-panel)
|
||||
*/
|
||||
const TabPanel = /*#__PURE__*/React.forwardRef(function TabPanel(props, forwardedRef) {
|
||||
const {
|
||||
children,
|
||||
slotProps = {},
|
||||
slots = {}
|
||||
} = props,
|
||||
other = _objectWithoutPropertiesLoose(props, _excluded);
|
||||
const {
|
||||
hidden,
|
||||
getRootProps
|
||||
} = useTabPanel(props);
|
||||
const ownerState = _extends({}, props, {
|
||||
hidden
|
||||
});
|
||||
const classes = useUtilityClasses(ownerState);
|
||||
const TabPanelRoot = slots.root ?? 'div';
|
||||
const tabPanelRootProps = useSlotProps({
|
||||
elementType: TabPanelRoot,
|
||||
getSlotProps: getRootProps,
|
||||
externalSlotProps: slotProps.root,
|
||||
externalForwardedProps: other,
|
||||
additionalProps: {
|
||||
role: 'tabpanel',
|
||||
ref: forwardedRef
|
||||
},
|
||||
ownerState,
|
||||
className: classes.root
|
||||
});
|
||||
return /*#__PURE__*/_jsx(TabPanelRoot, _extends({}, tabPanelRootProps, {
|
||||
children: !hidden && children
|
||||
}));
|
||||
});
|
||||
process.env.NODE_ENV !== "production" ? TabPanel.propTypes /* remove-proptypes */ = {
|
||||
// ┌────────────────────────────── Warning ──────────────────────────────┐
|
||||
// │ These PropTypes are generated from the TypeScript type definitions. │
|
||||
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
|
||||
// └─────────────────────────────────────────────────────────────────────┘
|
||||
/**
|
||||
* The content of the component.
|
||||
*/
|
||||
children: PropTypes.node,
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
className: PropTypes.string,
|
||||
/**
|
||||
* The props used for each slot inside the TabPanel.
|
||||
* @default {}
|
||||
*/
|
||||
slotProps: PropTypes.shape({
|
||||
root: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
|
||||
}),
|
||||
/**
|
||||
* The components used for each slot inside the TabPanel.
|
||||
* Either a string to use a HTML element or a component.
|
||||
* @default {}
|
||||
*/
|
||||
slots: PropTypes.shape({
|
||||
root: PropTypes.elementType
|
||||
}),
|
||||
/**
|
||||
* The value of the TabPanel. It will be shown when the Tab with the corresponding value is selected.
|
||||
* If not provided, it will fall back to the index of the panel.
|
||||
* It is recommended to explicitly provide it, as it's required for the tab panel to be rendered on the server.
|
||||
*/
|
||||
value: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
|
||||
} : void 0;
|
||||
export { TabPanel };
|
||||
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
'use client';
|
||||
|
||||
export { TabPanel } from './TabPanel';
|
||||
export * from './TabPanel.types';
|
||||
export * from './tabPanelClasses';
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import { generateUtilityClass } from '../generateUtilityClass';
|
||||
import { generateUtilityClasses } from '../generateUtilityClasses';
|
||||
const COMPONENT_NAME = 'TabPanel';
|
||||
export function getTabPanelUtilityClass(slot) {
|
||||
return generateUtilityClass(COMPONENT_NAME, slot);
|
||||
}
|
||||
export const tabPanelClasses = generateUtilityClasses(COMPONENT_NAME, ['root', 'hidden']);
|
||||
+317
@@ -0,0 +1,317 @@
|
||||
'use client';
|
||||
|
||||
import _extends from "@babel/runtime/helpers/esm/extends";
|
||||
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
||||
const _excluded = ["colSpan", "count", "getItemAriaLabel", "labelDisplayedRows", "labelId", "labelRowsPerPage", "onPageChange", "onRowsPerPageChange", "page", "rowsPerPage", "rowsPerPageOptions", "selectId", "slotProps", "slots"];
|
||||
import * as React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { unstable_useId as useId, chainPropTypes, integerPropType } from '@mui/utils';
|
||||
import { useSlotProps } from '../utils';
|
||||
import { unstable_composeClasses as composeClasses } from '../composeClasses';
|
||||
import { isHostComponent } from '../utils/isHostComponent';
|
||||
import { TablePaginationActions } from './TablePaginationActions';
|
||||
import { getTablePaginationUtilityClass } from './tablePaginationClasses';
|
||||
import { useClassNamesOverride } from '../utils/ClassNameConfigurator';
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
import { createElement as _createElement } from "react";
|
||||
import { jsxs as _jsxs } from "react/jsx-runtime";
|
||||
function defaultLabelDisplayedRows({
|
||||
from,
|
||||
to,
|
||||
count
|
||||
}) {
|
||||
return `${from}–${to} of ${count !== -1 ? count : `more than ${to}`}`;
|
||||
}
|
||||
function defaultGetAriaLabel(type) {
|
||||
return `Go to ${type} page`;
|
||||
}
|
||||
const useUtilityClasses = () => {
|
||||
const slots = {
|
||||
root: ['root'],
|
||||
toolbar: ['toolbar'],
|
||||
spacer: ['spacer'],
|
||||
selectLabel: ['selectLabel'],
|
||||
select: ['select'],
|
||||
input: ['input'],
|
||||
selectIcon: ['selectIcon'],
|
||||
menuItem: ['menuItem'],
|
||||
displayedRows: ['displayedRows'],
|
||||
actions: ['actions']
|
||||
};
|
||||
return composeClasses(slots, useClassNamesOverride(getTablePaginationUtilityClass));
|
||||
};
|
||||
|
||||
/**
|
||||
* A pagination for tables.
|
||||
*
|
||||
* Demos:
|
||||
*
|
||||
* - [Table Pagination](https://mui.com/base-ui/react-table-pagination/)
|
||||
*
|
||||
* API:
|
||||
*
|
||||
* - [TablePagination API](https://mui.com/base-ui/react-table-pagination/components-api/#table-pagination)
|
||||
*/
|
||||
const TablePagination = /*#__PURE__*/React.forwardRef(function TablePagination(props, forwardedRef) {
|
||||
const {
|
||||
colSpan: colSpanProp,
|
||||
count,
|
||||
getItemAriaLabel = defaultGetAriaLabel,
|
||||
labelDisplayedRows = defaultLabelDisplayedRows,
|
||||
labelId: labelIdProp,
|
||||
labelRowsPerPage = 'Rows per page:',
|
||||
onPageChange,
|
||||
onRowsPerPageChange,
|
||||
page,
|
||||
rowsPerPage,
|
||||
rowsPerPageOptions = [10, 25, 50, 100],
|
||||
selectId: selectIdProp,
|
||||
slotProps = {},
|
||||
slots = {}
|
||||
} = props,
|
||||
other = _objectWithoutPropertiesLoose(props, _excluded);
|
||||
const ownerState = props;
|
||||
const classes = useUtilityClasses();
|
||||
let colSpan;
|
||||
const Root = slots.root ?? 'td';
|
||||
if (Root === 'td' || !isHostComponent(Root)) {
|
||||
colSpan = colSpanProp || 1000; // col-span over everything
|
||||
}
|
||||
const getLabelDisplayedRowsTo = () => {
|
||||
if (count === -1) {
|
||||
return (page + 1) * rowsPerPage;
|
||||
}
|
||||
return rowsPerPage === -1 ? count : Math.min(count, (page + 1) * rowsPerPage);
|
||||
};
|
||||
const selectId = useId(selectIdProp);
|
||||
const labelId = useId(labelIdProp);
|
||||
const rootProps = useSlotProps({
|
||||
elementType: Root,
|
||||
externalSlotProps: slotProps.root,
|
||||
externalForwardedProps: other,
|
||||
additionalProps: {
|
||||
colSpan,
|
||||
ref: forwardedRef
|
||||
},
|
||||
ownerState,
|
||||
className: classes.root
|
||||
});
|
||||
const Select = slots.select ?? 'select';
|
||||
const selectProps = useSlotProps({
|
||||
elementType: Select,
|
||||
externalSlotProps: slotProps.select,
|
||||
additionalProps: {
|
||||
value: rowsPerPage,
|
||||
id: selectId,
|
||||
onChange: event => onRowsPerPageChange && onRowsPerPageChange(event),
|
||||
'aria-label': rowsPerPage.toString(),
|
||||
'aria-labelledby': [labelId, selectId].filter(Boolean).join(' ') || undefined
|
||||
},
|
||||
ownerState,
|
||||
className: classes.select
|
||||
});
|
||||
const Actions = slots.actions ?? TablePaginationActions;
|
||||
const actionsProps = useSlotProps({
|
||||
elementType: Actions,
|
||||
externalSlotProps: slotProps.actions,
|
||||
additionalProps: {
|
||||
page,
|
||||
rowsPerPage,
|
||||
count,
|
||||
onPageChange,
|
||||
getItemAriaLabel
|
||||
},
|
||||
ownerState,
|
||||
className: classes.actions
|
||||
});
|
||||
const MenuItem = slots.menuItem ?? 'option';
|
||||
const menuItemProps = useSlotProps({
|
||||
elementType: MenuItem,
|
||||
externalSlotProps: slotProps.menuItem,
|
||||
additionalProps: {
|
||||
value: undefined
|
||||
},
|
||||
ownerState,
|
||||
className: classes.menuItem
|
||||
});
|
||||
const SelectLabel = slots.selectLabel ?? 'p';
|
||||
const selectLabelProps = useSlotProps({
|
||||
elementType: SelectLabel,
|
||||
externalSlotProps: slotProps.selectLabel,
|
||||
additionalProps: {
|
||||
id: labelId
|
||||
},
|
||||
ownerState,
|
||||
className: classes.selectLabel
|
||||
});
|
||||
const DisplayedRows = slots.displayedRows ?? 'p';
|
||||
const displayedRowsProps = useSlotProps({
|
||||
elementType: DisplayedRows,
|
||||
externalSlotProps: slotProps.displayedRows,
|
||||
ownerState,
|
||||
className: classes.displayedRows
|
||||
});
|
||||
const Toolbar = slots.toolbar ?? 'div';
|
||||
const toolbarProps = useSlotProps({
|
||||
elementType: Toolbar,
|
||||
externalSlotProps: slotProps.toolbar,
|
||||
ownerState,
|
||||
className: classes.toolbar
|
||||
});
|
||||
const Spacer = slots.spacer ?? 'div';
|
||||
const spacerProps = useSlotProps({
|
||||
elementType: Spacer,
|
||||
externalSlotProps: slotProps.spacer,
|
||||
ownerState,
|
||||
className: classes.spacer
|
||||
});
|
||||
return /*#__PURE__*/_jsx(Root, _extends({}, rootProps, {
|
||||
children: /*#__PURE__*/_jsxs(Toolbar, _extends({}, toolbarProps, {
|
||||
children: [/*#__PURE__*/_jsx(Spacer, _extends({}, spacerProps)), rowsPerPageOptions.length > 1 && /*#__PURE__*/_jsx(SelectLabel, _extends({}, selectLabelProps, {
|
||||
children: labelRowsPerPage
|
||||
})), rowsPerPageOptions.length > 1 && /*#__PURE__*/_jsx(Select, _extends({}, selectProps, {
|
||||
children: rowsPerPageOptions.map(rowsPerPageOption => /*#__PURE__*/_createElement(MenuItem, _extends({}, menuItemProps, {
|
||||
key: typeof rowsPerPageOption !== 'number' && rowsPerPageOption.label ? rowsPerPageOption.label : rowsPerPageOption,
|
||||
value: typeof rowsPerPageOption !== 'number' && rowsPerPageOption.value ? rowsPerPageOption.value : rowsPerPageOption
|
||||
}), typeof rowsPerPageOption !== 'number' && rowsPerPageOption.label ? rowsPerPageOption.label : rowsPerPageOption))
|
||||
})), /*#__PURE__*/_jsx(DisplayedRows, _extends({}, displayedRowsProps, {
|
||||
children: labelDisplayedRows({
|
||||
from: count === 0 ? 0 : page * rowsPerPage + 1,
|
||||
to: getLabelDisplayedRowsTo(),
|
||||
count: count === -1 ? -1 : count,
|
||||
page
|
||||
})
|
||||
})), /*#__PURE__*/_jsx(Actions, _extends({}, actionsProps))]
|
||||
}))
|
||||
}));
|
||||
});
|
||||
process.env.NODE_ENV !== "production" ? TablePagination.propTypes /* remove-proptypes */ = {
|
||||
// ┌────────────────────────────── Warning ──────────────────────────────┐
|
||||
// │ These PropTypes are generated from the TypeScript type definitions. │
|
||||
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
|
||||
// └─────────────────────────────────────────────────────────────────────┘
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
colSpan: PropTypes.number,
|
||||
/**
|
||||
* The total number of rows.
|
||||
*
|
||||
* To enable server side pagination for an unknown number of items, provide -1.
|
||||
*/
|
||||
count: PropTypes.number.isRequired,
|
||||
/**
|
||||
* Accepts a function which returns a string value that provides a user-friendly name for the current page.
|
||||
* This is important for screen reader users.
|
||||
*
|
||||
* For localization purposes, you can use the provided [translations](/material-ui/guides/localization/).
|
||||
* @param {string} type The link or button type to format ('first' | 'last' | 'next' | 'previous').
|
||||
* @returns {string}
|
||||
* @default function defaultGetAriaLabel(type: ItemAriaLabelType) {
|
||||
* return `Go to ${type} page`;
|
||||
* }
|
||||
*/
|
||||
getItemAriaLabel: PropTypes.func,
|
||||
/**
|
||||
* Customize the displayed rows label. Invoked with a `{ from, to, count, page }`
|
||||
* object.
|
||||
*
|
||||
* For localization purposes, you can use the provided [translations](/material-ui/guides/localization/).
|
||||
* @default function defaultLabelDisplayedRows({ from, to, count }: LabelDisplayedRowsArgs) {
|
||||
* return `${from}–${to} of ${count !== -1 ? count : `more than ${to}`}`;
|
||||
* }
|
||||
*/
|
||||
labelDisplayedRows: PropTypes.func,
|
||||
/**
|
||||
* Id of the label element within the pagination.
|
||||
*/
|
||||
labelId: PropTypes.string,
|
||||
/**
|
||||
* Customize the rows per page label.
|
||||
*
|
||||
* For localization purposes, you can use the provided [translations](/material-ui/guides/localization/).
|
||||
* @default 'Rows per page:'
|
||||
*/
|
||||
labelRowsPerPage: PropTypes.node,
|
||||
/**
|
||||
* Callback fired when the page is changed.
|
||||
*
|
||||
* @param {React.MouseEvent<HTMLButtonElement> | null} event The event source of the callback.
|
||||
* @param {number} page The page selected.
|
||||
*/
|
||||
onPageChange: PropTypes.func.isRequired,
|
||||
/**
|
||||
* Callback fired when the number of rows per page is changed.
|
||||
*
|
||||
* @param {React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>} event The event source of the callback.
|
||||
*/
|
||||
onRowsPerPageChange: PropTypes.func,
|
||||
/**
|
||||
* The zero-based index of the current page.
|
||||
*/
|
||||
page: chainPropTypes(integerPropType.isRequired, props => {
|
||||
const {
|
||||
count,
|
||||
page,
|
||||
rowsPerPage
|
||||
} = props;
|
||||
if (count === -1) {
|
||||
return null;
|
||||
}
|
||||
const newLastPage = Math.max(0, Math.ceil(count / rowsPerPage) - 1);
|
||||
if (page < 0 || page > newLastPage) {
|
||||
return new Error('MUI: The page prop of a TablePagination is out of range ' + `(0 to ${newLastPage}, but page is ${page}).`);
|
||||
}
|
||||
return null;
|
||||
}),
|
||||
/**
|
||||
* The number of rows per page.
|
||||
*
|
||||
* Set -1 to display all the rows.
|
||||
*/
|
||||
rowsPerPage: integerPropType.isRequired,
|
||||
/**
|
||||
* Customizes the options of the rows per page select field. If less than two options are
|
||||
* available, no select field will be displayed.
|
||||
* Use -1 for the value with a custom label to show all the rows.
|
||||
* @default [10, 25, 50, 100]
|
||||
*/
|
||||
rowsPerPageOptions: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.number, PropTypes.shape({
|
||||
label: PropTypes.string.isRequired,
|
||||
value: PropTypes.number.isRequired
|
||||
})]).isRequired),
|
||||
/**
|
||||
* Id of the select element within the pagination.
|
||||
*/
|
||||
selectId: PropTypes.string,
|
||||
/**
|
||||
* The props used for each slot inside the TablePagination.
|
||||
* @default {}
|
||||
*/
|
||||
slotProps: PropTypes /* @typescript-to-proptypes-ignore */.shape({
|
||||
actions: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
||||
displayedRows: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
||||
menuItem: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
||||
root: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
||||
select: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
||||
selectLabel: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
||||
spacer: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
||||
toolbar: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
|
||||
}),
|
||||
/**
|
||||
* The components used for each slot inside the TablePagination.
|
||||
* Either a string to use a HTML element or a component.
|
||||
* @default {}
|
||||
*/
|
||||
slots: PropTypes.shape({
|
||||
actions: PropTypes.elementType,
|
||||
displayedRows: PropTypes.elementType,
|
||||
menuItem: PropTypes.elementType,
|
||||
root: PropTypes.elementType,
|
||||
select: PropTypes.elementType,
|
||||
selectLabel: PropTypes.elementType,
|
||||
spacer: PropTypes.elementType,
|
||||
toolbar: PropTypes.elementType
|
||||
})
|
||||
} : void 0;
|
||||
export { TablePagination };
|
||||
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
+142
@@ -0,0 +1,142 @@
|
||||
'use client';
|
||||
|
||||
import _extends from "@babel/runtime/helpers/esm/extends";
|
||||
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
||||
const _excluded = ["count", "getItemAriaLabel", "onPageChange", "page", "rowsPerPage", "showFirstButton", "showLastButton", "direction", "ownerState", "slotProps", "slots"];
|
||||
var _span, _span2, _span3, _span4;
|
||||
import * as React from 'react';
|
||||
import { useSlotProps } from '../utils';
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
import { jsxs as _jsxs } from "react/jsx-runtime";
|
||||
function LastPageIconDefault() {
|
||||
return _span || (_span = /*#__PURE__*/_jsx("span", {
|
||||
children: '⇾|'
|
||||
}));
|
||||
}
|
||||
function FirstPageIconDefault() {
|
||||
return _span2 || (_span2 = /*#__PURE__*/_jsx("span", {
|
||||
children: '|⇽'
|
||||
}));
|
||||
}
|
||||
function NextPageIconDefault() {
|
||||
return _span3 || (_span3 = /*#__PURE__*/_jsx("span", {
|
||||
children: '⇾'
|
||||
}));
|
||||
}
|
||||
function BackPageIconDefault() {
|
||||
return _span4 || (_span4 = /*#__PURE__*/_jsx("span", {
|
||||
children: '⇽'
|
||||
}));
|
||||
}
|
||||
function defaultGetAriaLabel(type) {
|
||||
return `Go to ${type} page`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignore - internal component.
|
||||
*/
|
||||
const TablePaginationActions = /*#__PURE__*/React.forwardRef(function TablePaginationActions(props, forwardedRef) {
|
||||
const {
|
||||
count,
|
||||
getItemAriaLabel = defaultGetAriaLabel,
|
||||
onPageChange,
|
||||
page,
|
||||
rowsPerPage,
|
||||
showFirstButton = false,
|
||||
showLastButton = false,
|
||||
direction
|
||||
// @ts-ignore
|
||||
,
|
||||
|
||||
slotProps = {},
|
||||
slots = {}
|
||||
} = props,
|
||||
other = _objectWithoutPropertiesLoose(props, _excluded);
|
||||
const ownerState = props;
|
||||
const handleFirstPageButtonClick = event => {
|
||||
onPageChange(event, 0);
|
||||
};
|
||||
const handleBackButtonClick = event => {
|
||||
onPageChange(event, page - 1);
|
||||
};
|
||||
const handleNextButtonClick = event => {
|
||||
onPageChange(event, page + 1);
|
||||
};
|
||||
const handleLastPageButtonClick = event => {
|
||||
onPageChange(event, Math.max(0, Math.ceil(count / rowsPerPage) - 1));
|
||||
};
|
||||
const Root = slots.root ?? 'div';
|
||||
const rootProps = useSlotProps({
|
||||
elementType: Root,
|
||||
externalSlotProps: slotProps.root,
|
||||
externalForwardedProps: other,
|
||||
additionalProps: {
|
||||
ref: forwardedRef
|
||||
},
|
||||
ownerState
|
||||
});
|
||||
const FirstButton = slots.firstButton ?? 'button';
|
||||
const firstButtonProps = useSlotProps({
|
||||
elementType: FirstButton,
|
||||
externalSlotProps: slotProps.firstButton,
|
||||
additionalProps: {
|
||||
onClick: handleFirstPageButtonClick,
|
||||
disabled: page === 0,
|
||||
'aria-label': getItemAriaLabel('first', page),
|
||||
title: getItemAriaLabel('first', page)
|
||||
},
|
||||
ownerState
|
||||
});
|
||||
const LastButton = slots.lastButton ?? 'button';
|
||||
const lastButtonProps = useSlotProps({
|
||||
elementType: LastButton,
|
||||
externalSlotProps: slotProps.lastButton,
|
||||
additionalProps: {
|
||||
onClick: handleLastPageButtonClick,
|
||||
disabled: page >= Math.ceil(count / rowsPerPage) - 1,
|
||||
'aria-label': getItemAriaLabel('last', page),
|
||||
title: getItemAriaLabel('last', page)
|
||||
},
|
||||
ownerState
|
||||
});
|
||||
const NextButton = slots.nextButton ?? 'button';
|
||||
const nextButtonProps = useSlotProps({
|
||||
elementType: NextButton,
|
||||
externalSlotProps: slotProps.nextButton,
|
||||
additionalProps: {
|
||||
onClick: handleNextButtonClick,
|
||||
disabled: count !== -1 ? page >= Math.ceil(count / rowsPerPage) - 1 : false,
|
||||
'aria-label': getItemAriaLabel('next', page),
|
||||
title: getItemAriaLabel('next', page)
|
||||
},
|
||||
ownerState
|
||||
});
|
||||
const BackButton = slots.backButton ?? 'button';
|
||||
const backButtonProps = useSlotProps({
|
||||
elementType: BackButton,
|
||||
externalSlotProps: slotProps.backButton,
|
||||
additionalProps: {
|
||||
onClick: handleBackButtonClick,
|
||||
disabled: page === 0,
|
||||
'aria-label': getItemAriaLabel('previous', page),
|
||||
title: getItemAriaLabel('previous', page)
|
||||
},
|
||||
ownerState
|
||||
});
|
||||
const LastPageIcon = slots.lastPageIcon ?? LastPageIconDefault;
|
||||
const FirstPageIcon = slots.firstPageIcon ?? FirstPageIconDefault;
|
||||
const NextPageIcon = slots.nextPageIcon ?? NextPageIconDefault;
|
||||
const BackPageIcon = slots.backPageIcon ?? BackPageIconDefault;
|
||||
return /*#__PURE__*/_jsxs(Root, _extends({}, rootProps, {
|
||||
children: [showFirstButton && /*#__PURE__*/_jsx(FirstButton, _extends({}, firstButtonProps, {
|
||||
children: direction === 'rtl' ? /*#__PURE__*/_jsx(LastPageIcon, {}) : /*#__PURE__*/_jsx(FirstPageIcon, {})
|
||||
})), /*#__PURE__*/_jsx(BackButton, _extends({}, backButtonProps, {
|
||||
children: direction === 'rtl' ? /*#__PURE__*/_jsx(NextPageIcon, {}) : /*#__PURE__*/_jsx(BackPageIcon, {})
|
||||
})), /*#__PURE__*/_jsx(NextButton, _extends({}, nextButtonProps, {
|
||||
children: direction === 'rtl' ? /*#__PURE__*/_jsx(BackPageIcon, {}) : /*#__PURE__*/_jsx(NextPageIcon, {})
|
||||
})), showLastButton && /*#__PURE__*/_jsx(LastButton, _extends({}, lastButtonProps, {
|
||||
children: direction === 'rtl' ? /*#__PURE__*/_jsx(FirstPageIcon, {}) : /*#__PURE__*/_jsx(LastPageIcon, {})
|
||||
}))]
|
||||
}));
|
||||
});
|
||||
export { TablePaginationActions };
|
||||
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
'use client';
|
||||
|
||||
export { TablePagination } from './TablePagination';
|
||||
export * from './TablePagination.types';
|
||||
export { TablePaginationActions } from './TablePaginationActions';
|
||||
export * from './TablePaginationActions.types';
|
||||
export * from './tablePaginationClasses';
|
||||
export * from './common.types';
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import { generateUtilityClass } from '../generateUtilityClass';
|
||||
import { generateUtilityClasses } from '../generateUtilityClasses';
|
||||
const COMPONENT_NAME = 'TablePagination';
|
||||
export function getTablePaginationUtilityClass(slot) {
|
||||
return generateUtilityClass(COMPONENT_NAME, slot);
|
||||
}
|
||||
export const tablePaginationClasses = generateUtilityClasses(COMPONENT_NAME, ['root', 'toolbar', 'spacer', 'selectLabel', 'selectRoot', 'select', 'selectIcon', 'input', 'menuItem', 'displayedRows', 'actions']);
|
||||
+127
@@ -0,0 +1,127 @@
|
||||
'use client';
|
||||
|
||||
import _extends from "@babel/runtime/helpers/esm/extends";
|
||||
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
||||
const _excluded = ["children", "value", "defaultValue", "orientation", "direction", "onChange", "selectionFollowsFocus", "slotProps", "slots"];
|
||||
import * as React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { useSlotProps } from '../utils';
|
||||
import { unstable_composeClasses as composeClasses } from '../composeClasses';
|
||||
import { getTabsUtilityClass } from './tabsClasses';
|
||||
import { useTabs } from '../useTabs';
|
||||
import { TabsProvider } from '../useTabs/TabsProvider';
|
||||
import { useClassNamesOverride } from '../utils/ClassNameConfigurator';
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
const useUtilityClasses = ownerState => {
|
||||
const {
|
||||
orientation
|
||||
} = ownerState;
|
||||
const slots = {
|
||||
root: ['root', orientation]
|
||||
};
|
||||
return composeClasses(slots, useClassNamesOverride(getTabsUtilityClass));
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* Demos:
|
||||
*
|
||||
* - [Tabs](https://mui.com/base-ui/react-tabs/)
|
||||
*
|
||||
* API:
|
||||
*
|
||||
* - [Tabs API](https://mui.com/base-ui/react-tabs/components-api/#tabs)
|
||||
*/
|
||||
const Tabs = /*#__PURE__*/React.forwardRef(function Tabs(props, forwardedRef) {
|
||||
const {
|
||||
children,
|
||||
orientation = 'horizontal',
|
||||
direction = 'ltr',
|
||||
slotProps = {},
|
||||
slots = {}
|
||||
} = props,
|
||||
other = _objectWithoutPropertiesLoose(props, _excluded);
|
||||
const ownerState = _extends({}, props, {
|
||||
orientation,
|
||||
direction
|
||||
});
|
||||
const {
|
||||
contextValue
|
||||
} = useTabs(ownerState);
|
||||
const classes = useUtilityClasses(ownerState);
|
||||
const TabsRoot = slots.root ?? 'div';
|
||||
const tabsRootProps = useSlotProps({
|
||||
elementType: TabsRoot,
|
||||
externalSlotProps: slotProps.root,
|
||||
externalForwardedProps: other,
|
||||
additionalProps: {
|
||||
ref: forwardedRef
|
||||
},
|
||||
ownerState,
|
||||
className: classes.root
|
||||
});
|
||||
return /*#__PURE__*/_jsx(TabsRoot, _extends({}, tabsRootProps, {
|
||||
children: /*#__PURE__*/_jsx(TabsProvider, {
|
||||
value: contextValue,
|
||||
children: children
|
||||
})
|
||||
}));
|
||||
});
|
||||
process.env.NODE_ENV !== "production" ? Tabs.propTypes /* remove-proptypes */ = {
|
||||
// ┌────────────────────────────── Warning ──────────────────────────────┐
|
||||
// │ These PropTypes are generated from the TypeScript type definitions. │
|
||||
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
|
||||
// └─────────────────────────────────────────────────────────────────────┘
|
||||
/**
|
||||
* The content of the component.
|
||||
*/
|
||||
children: PropTypes.node,
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
className: PropTypes.string,
|
||||
/**
|
||||
* The default value. Use when the component is not controlled.
|
||||
*/
|
||||
defaultValue: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
||||
/**
|
||||
* The direction of the text.
|
||||
* @default 'ltr'
|
||||
*/
|
||||
direction: PropTypes.oneOf(['ltr', 'rtl']),
|
||||
/**
|
||||
* Callback invoked when new value is being set.
|
||||
*/
|
||||
onChange: PropTypes.func,
|
||||
/**
|
||||
* The component orientation (layout flow direction).
|
||||
* @default 'horizontal'
|
||||
*/
|
||||
orientation: PropTypes.oneOf(['horizontal', 'vertical']),
|
||||
/**
|
||||
* If `true` the selected tab changes on focus. Otherwise it only
|
||||
* changes on activation.
|
||||
*/
|
||||
selectionFollowsFocus: PropTypes.bool,
|
||||
/**
|
||||
* The props used for each slot inside the Tabs.
|
||||
* @default {}
|
||||
*/
|
||||
slotProps: PropTypes.shape({
|
||||
root: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
|
||||
}),
|
||||
/**
|
||||
* The components used for each slot inside the Tabs.
|
||||
* Either a string to use a HTML element or a component.
|
||||
* @default {}
|
||||
*/
|
||||
slots: PropTypes.shape({
|
||||
root: PropTypes.elementType
|
||||
}),
|
||||
/**
|
||||
* The value of the currently selected `Tab`.
|
||||
* If you don't want any selected `Tab`, you can set this prop to `null`.
|
||||
*/
|
||||
value: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
|
||||
} : void 0;
|
||||
export { Tabs };
|
||||
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
import * as React from 'react';
|
||||
/**
|
||||
* @ignore - internal component.
|
||||
*/
|
||||
const TabsContext = /*#__PURE__*/React.createContext(null);
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
TabsContext.displayName = 'TabsContext';
|
||||
}
|
||||
export function useTabsContext() {
|
||||
const context = React.useContext(TabsContext);
|
||||
if (context == null) {
|
||||
throw new Error('No TabsContext provided');
|
||||
}
|
||||
return context;
|
||||
}
|
||||
export { TabsContext };
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
'use client';
|
||||
|
||||
export { Tabs } from './Tabs';
|
||||
export * from './TabsContext';
|
||||
export * from './tabsClasses';
|
||||
export * from './Tabs.types';
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import { generateUtilityClass } from '../generateUtilityClass';
|
||||
import { generateUtilityClasses } from '../generateUtilityClasses';
|
||||
const COMPONENT_NAME = 'Tabs';
|
||||
export function getTabsUtilityClass(slot) {
|
||||
return generateUtilityClass(COMPONENT_NAME, slot);
|
||||
}
|
||||
export const tabsClasses = generateUtilityClasses(COMPONENT_NAME, ['root', 'horizontal', 'vertical']);
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
'use client';
|
||||
|
||||
import _extends from "@babel/runtime/helpers/esm/extends";
|
||||
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
||||
const _excluded = ["children", "slotProps", "slots"];
|
||||
import * as React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { unstable_composeClasses as composeClasses } from '../composeClasses';
|
||||
import { useSlotProps } from '../utils';
|
||||
import { getTabsListUtilityClass } from './tabsListClasses';
|
||||
import { useTabsList } from '../useTabsList';
|
||||
import { useClassNamesOverride } from '../utils/ClassNameConfigurator';
|
||||
import { TabsListProvider } from '../useTabsList/TabsListProvider';
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
const useUtilityClasses = ownerState => {
|
||||
const {
|
||||
orientation
|
||||
} = ownerState;
|
||||
const slots = {
|
||||
root: ['root', orientation]
|
||||
};
|
||||
return composeClasses(slots, useClassNamesOverride(getTabsListUtilityClass));
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* Demos:
|
||||
*
|
||||
* - [Tabs](https://mui.com/base-ui/react-tabs/)
|
||||
*
|
||||
* API:
|
||||
*
|
||||
* - [TabsList API](https://mui.com/base-ui/react-tabs/components-api/#tabs-list)
|
||||
*/
|
||||
const TabsList = /*#__PURE__*/React.forwardRef(function TabsList(props, forwardedRef) {
|
||||
const {
|
||||
children,
|
||||
slotProps = {},
|
||||
slots = {}
|
||||
} = props,
|
||||
other = _objectWithoutPropertiesLoose(props, _excluded);
|
||||
const {
|
||||
isRtl,
|
||||
orientation,
|
||||
getRootProps,
|
||||
contextValue
|
||||
} = useTabsList({
|
||||
rootRef: forwardedRef
|
||||
});
|
||||
const ownerState = _extends({}, props, {
|
||||
isRtl,
|
||||
orientation
|
||||
});
|
||||
const classes = useUtilityClasses(ownerState);
|
||||
const TabsListRoot = slots.root ?? 'div';
|
||||
const tabsListRootProps = useSlotProps({
|
||||
elementType: TabsListRoot,
|
||||
getSlotProps: getRootProps,
|
||||
externalSlotProps: slotProps.root,
|
||||
externalForwardedProps: other,
|
||||
ownerState,
|
||||
className: classes.root
|
||||
});
|
||||
return /*#__PURE__*/_jsx(TabsListProvider, {
|
||||
value: contextValue,
|
||||
children: /*#__PURE__*/_jsx(TabsListRoot, _extends({}, tabsListRootProps, {
|
||||
children: children
|
||||
}))
|
||||
});
|
||||
});
|
||||
process.env.NODE_ENV !== "production" ? TabsList.propTypes /* remove-proptypes */ = {
|
||||
// ┌────────────────────────────── Warning ──────────────────────────────┐
|
||||
// │ These PropTypes are generated from the TypeScript type definitions. │
|
||||
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
|
||||
// └─────────────────────────────────────────────────────────────────────┘
|
||||
/**
|
||||
* The content of the component.
|
||||
*/
|
||||
children: PropTypes.node,
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
className: PropTypes.string,
|
||||
/**
|
||||
* The props used for each slot inside the TabsList.
|
||||
* @default {}
|
||||
*/
|
||||
slotProps: PropTypes.shape({
|
||||
root: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
|
||||
}),
|
||||
/**
|
||||
* The components used for each slot inside the TabsList.
|
||||
* Either a string to use a HTML element or a component.
|
||||
* @default {}
|
||||
*/
|
||||
slots: PropTypes.shape({
|
||||
root: PropTypes.elementType
|
||||
})
|
||||
} : void 0;
|
||||
export { TabsList };
|
||||
Loaded 100 of 6977 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user