pre-installations and preparations

This commit is contained in:
MuhammadKhalilzadeh committed 2024-05-05 11:21:00 +03:30
1 parent 3e5a0329cb
commit 201d621ac3
6977 files changed
+742826

No files matched your search

+14
View File
@@ -0,0 +1,14 @@
import { PolymorphicComponent } from '../utils/PolymorphicComponent';
import { BadgeTypeMap } from './Badge.types';
/**
*
* Demos:
*
* - [Badge](https://mui.com/base-ui/react-badge/)
*
* API:
*
* - [Badge API](https://mui.com/base-ui/react-badge/components-api/#badge)
*/
declare const Badge: PolymorphicComponent<BadgeTypeMap<{}, "span">>;
export { Badge };
+130
View File
@@ -0,0 +1,130 @@
'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) {
var _slots$root, _slots$badge;
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 = slots.root) != null ? _slots$root : 'span';
const rootProps = useSlotProps({
elementType: Root,
externalSlotProps: slotProps.root,
externalForwardedProps: other,
additionalProps: {
ref: forwardedRef
},
ownerState,
className: classes.root
});
const BadgeComponent = (_slots$badge = slots.badge) != null ? _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 };
+80
View File
@@ -0,0 +1,80 @@
import * as React from 'react';
import { OverrideProps, Simplify } from '@mui/types';
import { SlotComponentProps } from '../utils';
export interface BadgeRootSlotPropsOverrides {
}
export interface BadgeBadgeSlotPropsOverrides {
}
export type BadgeOwnerState = Simplify<BadgeOwnProps & {
badgeContent: React.ReactNode;
invisible: boolean;
max: number;
showZero: boolean;
}>;
export interface BadgeOwnProps {
/**
* The content rendered within the badge.
*/
badgeContent?: React.ReactNode;
/**
* The badge will be added relative to this node.
*/
children?: React.ReactNode;
/**
* If `true`, the badge is invisible.
* @default false
*/
invisible?: boolean;
/**
* Max count to show.
* @default 99
*/
max?: number;
/**
* The props used for each slot inside the Badge.
* @default {}
*/
slotProps?: {
root?: SlotComponentProps<'span', BadgeRootSlotPropsOverrides, BadgeOwnerState>;
badge?: SlotComponentProps<'span', BadgeBadgeSlotPropsOverrides, BadgeOwnerState>;
};
/**
* The components used for each slot inside the Badge.
* Either a string to use a HTML element or a component.
* @default {}
*/
slots?: BadgeSlots;
/**
* Controls whether the badge is hidden when `badgeContent` is zero.
* @default false
*/
showZero?: boolean;
}
export interface BadgeSlots {
/**
* The component that renders the root.
* @default 'span'
*/
root?: React.ElementType;
/**
* The component that renders the badge.
* @default 'span'
*/
badge?: React.ElementType;
}
export interface BadgeTypeMap<AdditionalProps = {}, RootComponentType extends React.ElementType = 'span'> {
props: BadgeOwnProps & AdditionalProps;
defaultComponent: RootComponentType;
}
export type BadgeProps<RootComponentType extends React.ElementType = BadgeTypeMap['defaultComponent']> = OverrideProps<BadgeTypeMap<{}, RootComponentType>, RootComponentType>;
export type BadgeRootSlotProps = {
children?: React.ReactNode;
className?: string;
ownerState: BadgeOwnerState;
ref: React.Ref<HTMLSpanElement>;
};
export type BadgeBadgeSlotProps = {
className?: string;
children?: React.ReactNode;
ownerState: BadgeOwnerState;
};
+1
View File
@@ -0,0 +1 @@
export {};
+11
View File
@@ -0,0 +1,11 @@
export interface BadgeClasses {
/** Class name applied to the root element. */
root: string;
/** Class name applied to the badge `span` element. */
badge: string;
/** State class applied to the badge `span` element if `invisible={true}`. */
invisible: string;
}
export type BadgeClassKey = keyof BadgeClasses;
export declare function getBadgeUtilityClass(slot: string): string;
export declare const badgeClasses: BadgeClasses;
+7
View File
@@ -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']);
+3
View File
@@ -0,0 +1,3 @@
export { Badge } from './Badge';
export * from './Badge.types';
export * from './badgeClasses';
+5
View File
@@ -0,0 +1,5 @@
'use client';
export { Badge } from './Badge';
export * from './Badge.types';
export * from './badgeClasses';
+6
View File
@@ -0,0 +1,6 @@
{
"sideEffects": false,
"module": "./index.js",
"main": "../node/Badge/index.js",
"types": "./index.d.ts"
}
+15
View File
@@ -0,0 +1,15 @@
import { PolymorphicComponent } from '../utils/PolymorphicComponent';
import { ButtonTypeMap } from './Button.types';
/**
* 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)
*/
declare const Button: PolymorphicComponent<ButtonTypeMap<{}, "button">>;
export { Button };
+156
View File
@@ -0,0 +1,156 @@
'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) {
var _slots$root;
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 = slots.root) != null ? _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 };
+57
View File
@@ -0,0 +1,57 @@
import * as React from 'react';
import { Simplify } from '@mui/types';
import { UseButtonParameters, UseButtonRootSlotProps } from '../useButton';
import { SlotComponentProps } from '../utils';
import { PolymorphicProps } from '../utils/PolymorphicComponent';
export interface ButtonActions {
focusVisible(): void;
}
export interface ButtonRootSlotPropsOverrides {
}
export interface ButtonOwnProps extends Omit<UseButtonParameters, 'rootRef'> {
/**
* A ref for imperative actions. It currently only supports `focusVisible()` action.
*/
action?: React.Ref<ButtonActions>;
children?: React.ReactNode;
className?: string;
/**
* The props used for each slot inside the Button.
* @default {}
*/
slotProps?: {
root?: SlotComponentProps<'button', ButtonRootSlotPropsOverrides, ButtonOwnerState>;
};
/**
* The components used for each slot inside the Button.
* Either a string to use a HTML element or a component.
* @default {}
*/
slots?: ButtonSlots;
/**
* The HTML element that is ultimately rendered, for example 'button' or 'a'
* @default 'button'
*/
rootElementName?: keyof HTMLElementTagNameMap;
}
export interface ButtonSlots {
/**
* The component that renders the root.
* @default props.href || props.to ? 'a' : 'button'
*/
root?: React.ElementType;
}
export type ButtonProps<RootComponentType extends React.ElementType = ButtonTypeMap['defaultComponent']> = PolymorphicProps<ButtonTypeMap<{}, RootComponentType>, RootComponentType>;
export interface ButtonTypeMap<AdditionalProps = {}, RootComponentType extends React.ElementType = 'button'> {
props: ButtonOwnProps & AdditionalProps;
defaultComponent: RootComponentType;
}
export type ButtonOwnerState = Simplify<ButtonOwnProps & {
active: boolean;
focusVisible: boolean;
}>;
export type ButtonRootSlotProps = Simplify<UseButtonRootSlotProps & {
ownerState: ButtonOwnerState;
className?: string;
children?: React.ReactNode;
}>;
+1
View File
@@ -0,0 +1 @@
export {};
+13
View File
@@ -0,0 +1,13 @@
export interface ButtonClasses {
/** Class name applied to the root element. */
root: string;
/** State class applied to the root `button` element if `active={true}`. */
active: string;
/** State class applied to the root `button` element if `disabled={true}`. */
disabled: string;
/** State class applied to the root `button` element if `focusVisible={true}`. */
focusVisible: string;
}
export type ButtonClassKey = keyof ButtonClasses;
export declare function getButtonUtilityClass(slot: string): string;
export declare const buttonClasses: ButtonClasses;
+7
View File
@@ -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']);
+3
View File
@@ -0,0 +1,3 @@
export { Button } from './Button';
export * from './buttonClasses';
export * from './Button.types';
+5
View File
@@ -0,0 +1,5 @@
'use client';
export { Button } from './Button';
export * from './buttonClasses';
export * from './Button.types';
+6
View File
@@ -0,0 +1,6 @@
{
"sideEffects": false,
"module": "./index.js",
"main": "../node/Button/index.js",
"types": "./index.d.ts"
}
+14756
View File
File diff suppressed because it is too large. Load diff
+1
View File
@@ -0,0 +1 @@
export { unstable_ClassNameGenerator } from '@mui/utils';
+1
View File
@@ -0,0 +1 @@
export { unstable_ClassNameGenerator } from '@mui/utils';
+6
View File
@@ -0,0 +1,6 @@
{
"sideEffects": false,
"module": "./index.js",
"main": "../node/ClassNameGenerator/index.js",
"types": "./index.d.ts"
}
+46
View File
@@ -0,0 +1,46 @@
import * as React from 'react';
type ClickAwayMouseEventHandler = 'onClick' | 'onMouseDown' | 'onMouseUp' | 'onPointerDown' | 'onPointerUp';
type ClickAwayTouchEventHandler = 'onTouchStart' | 'onTouchEnd';
export interface ClickAwayListenerProps {
/**
* The wrapped element.
*/
children: React.ReactElement;
/**
* 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?: boolean;
/**
* The mouse event to listen to. You can disable the listener by providing `false`.
* @default 'onClick'
*/
mouseEvent?: ClickAwayMouseEventHandler | false;
/**
* Callback fired when a "click away" event is detected.
*/
onClickAway: (event: MouseEvent | TouchEvent) => void;
/**
* The touch event to listen to. You can disable the listener by providing `false`.
* @default 'onTouchEnd'
*/
touchEvent?: ClickAwayTouchEventHandler | false;
}
/**
* 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)
*/
declare function ClickAwayListener(props: ClickAwayListenerProps): JSX.Element;
declare namespace ClickAwayListener {
var propTypes: any;
}
export { ClickAwayListener };
+177
View File
@@ -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
View File
@@ -0,0 +1 @@
export * from './ClickAwayListener';
+1
View File
@@ -0,0 +1 @@
export * from './ClickAwayListener';
+6
View File
@@ -0,0 +1,6 @@
{
"sideEffects": false,
"module": "./index.js",
"main": "../node/ClickAwayListener/index.js",
"types": "./index.d.ts"
}
+17
View File
@@ -0,0 +1,17 @@
import * as React from 'react';
import { DropdownProps } from './Dropdown.types';
/**
*
* Demos:
*
* - [Menu](https://mui.com/base-ui/react-menu/)
*
* API:
*
* - [Dropdown API](https://mui.com/base-ui/react-menu/components-api/#dropdown)
*/
declare function Dropdown(props: DropdownProps): React.JSX.Element;
declare namespace Dropdown {
var propTypes: any;
}
export { Dropdown };
+65
View File
@@ -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 };
+17
View File
@@ -0,0 +1,17 @@
/// <reference types="react" />
export interface DropdownProps {
children: React.ReactNode;
/**
* If `true`, the dropdown is initially open.
*/
defaultOpen?: boolean;
/**
* Callback fired when the component requests to be opened or closed.
*/
onOpenChange?: (event: React.MouseEvent | React.KeyboardEvent | React.FocusEvent | null, open: boolean) => void;
/**
* Allows to control whether the dropdown is open.
* This is a controlled counterpart of `defaultOpen`.
*/
open?: boolean;
}
+1
View File
@@ -0,0 +1 @@
export {};
+2
View File
@@ -0,0 +1,2 @@
export * from './Dropdown';
export * from './Dropdown.types';
+2
View File
@@ -0,0 +1,2 @@
export * from './Dropdown';
export * from './Dropdown.types';
+6
View File
@@ -0,0 +1,6 @@
{
"sideEffects": false,
"module": "./index.js",
"main": "../node/Dropdown/index.js",
"types": "./index.d.ts"
}
+18
View File
@@ -0,0 +1,18 @@
/// <reference types="react" />
import { FocusTrapProps } from './FocusTrap.types';
/**
* 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)
*/
declare function FocusTrap(props: FocusTrapProps): JSX.Element;
declare namespace FocusTrap {
var propTypes: any;
}
export { FocusTrap };
+340
View File
@@ -0,0 +1,340 @@
'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) {
var _lastKeydown$current, _lastKeydown$current2;
const isShiftTab = Boolean(((_lastKeydown$current = lastKeydown.current) == null ? void 0 : _lastKeydown$current.shiftKey) && ((_lastKeydown$current2 = lastKeydown.current) == null ? void 0 : _lastKeydown$current2.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 };
+51
View File
@@ -0,0 +1,51 @@
import * as React from 'react';
export interface FocusTrapProps {
/**
* If `true`, focus is locked.
*/
open: boolean;
/**
* 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?: (root: HTMLElement) => ReadonlyArray<string>;
/**
* 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?: () => boolean;
/**
* A single child content element.
*/
children: React.ReactElement;
/**
* 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?: boolean;
/**
* 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?: boolean;
/**
* If `true`, the focus trap will not restore focus to previously focused element once
* focus trap is hidden or unmounted.
* @default false
*/
disableRestoreFocus?: boolean;
}
+1
View File
@@ -0,0 +1 @@
export {};
+2
View File
@@ -0,0 +1,2 @@
export { FocusTrap } from './FocusTrap';
export * from './FocusTrap.types';
+2
View File
@@ -0,0 +1,2 @@
export { FocusTrap } from './FocusTrap';
export * from './FocusTrap.types';
+6
View File
@@ -0,0 +1,6 @@
{
"sideEffects": false,
"module": "./index.js",
"main": "../node/FocusTrap/index.js",
"types": "./index.d.ts"
}
+41
View File
@@ -0,0 +1,41 @@
import { PolymorphicComponent } from '../utils/PolymorphicComponent';
import { FormControlTypeMap } from './FormControl.types';
/**
* 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)
*/
declare const FormControl: PolymorphicComponent<FormControlTypeMap<{}, "div">>;
export { FormControl };
+200
View File
@@ -0,0 +1,200 @@
'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) {
var _slots$root;
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 == null || onChange(event);
},
onFocus: () => {
setFocused(true);
},
required,
value: value != null ? 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 = slots.root) != null ? _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 };
+116
View File
@@ -0,0 +1,116 @@
import * as React from 'react';
import { Simplify } from '@mui/types';
import { PolymorphicProps, SlotComponentProps } from '../utils';
export type NativeFormControlElement = HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement;
export interface FormControlRootSlotPropsOverrides {
}
export interface FormControlOwnProps {
/**
* The content of the component.
*/
children?: React.ReactNode | ((state: FormControlState) => React.ReactNode);
/**
* Class name applied to the root element.
*/
className?: string;
defaultValue?: unknown;
/**
* If `true`, the label, input and helper text should be displayed in a disabled state.
* @default false
*/
disabled?: boolean;
/**
* If `true`, the label is displayed in an error state.
* @default false
*/
error?: boolean;
/**
* Callback fired when the form element's value is modified.
*/
onChange?: React.ChangeEventHandler<NativeFormControlElement>;
/**
* If `true`, the label will indicate that the `input` is required.
* @default false
*/
required?: boolean;
/**
* The props used for each slot inside the FormControl.
* @default {}
*/
slotProps?: {
root?: SlotComponentProps<'div', FormControlRootSlotPropsOverrides, FormControlOwnerState>;
};
/**
* The components used for each slot inside the FormControl.
* Either a string to use a HTML element or a component.
* @default {}
*/
slots?: FormControlSlots;
/**
* The value of the form element.
*/
value?: unknown;
}
export interface FormControlSlots {
/**
* The component that renders the root.
* @default 'div'
*/
root?: React.ElementType;
}
export interface FormControlTypeMap<AdditionalProps = {}, RootComponentType extends React.ElementType = 'div'> {
props: FormControlOwnProps & AdditionalProps;
defaultComponent: RootComponentType;
}
export type FormControlProps<RootComponentType extends React.ElementType = FormControlTypeMap['defaultComponent']> = PolymorphicProps<FormControlTypeMap<{}, RootComponentType>, RootComponentType>;
type NonOptionalOwnerState = 'disabled' | 'error' | 'required';
export type FormControlOwnerState = Simplify<Omit<FormControlOwnProps, NonOptionalOwnerState> & Required<Pick<FormControlProps, NonOptionalOwnerState>> & {
filled: boolean;
focused: boolean;
}>;
export type FormControlState = {
/**
* If `true`, the label, input and helper text should be displayed in a disabled state.
*/
disabled: boolean;
/**
* If `true`, the label is displayed in an error state.
*/
error: boolean;
/**
* If `true`, the form element has some value.
*/
filled: boolean;
/**
* If `true`, the form element is focused and not disabled.
*/
focused: boolean;
/**
* Callback fired when the form element has lost focus.
*/
onBlur: () => void;
/**
* Callback fired when the form element's value is modified.
*/
onChange: React.ChangeEventHandler<NativeFormControlElement>;
/**
* Callback fired when the form element receives focus.
*/
onFocus: () => void;
/**
* If `true`, the label will indicate that the `input` is required.
*/
required: boolean;
/**
* The value of the form element.
*/
value: unknown;
};
export type FormControlRootSlotProps = {
children: React.ReactNode | ((state: FormControlState) => React.ReactNode);
className?: string;
ownerState: FormControlOwnerState;
};
export interface UseFormControlContextReturnValue extends FormControlState {
}
export {};
+1
View File
@@ -0,0 +1 @@
export {};
+7
View File
@@ -0,0 +1,7 @@
import * as React from 'react';
import { FormControlState } from './FormControl.types';
/**
* @ignore - internal component.
*/
declare const FormControlContext: React.Context<FormControlState | undefined>;
export { FormControlContext };
+9
View File
@@ -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 };
+17
View File
@@ -0,0 +1,17 @@
export interface FormControlClasses {
/** Class applied to the root element. */
root: string;
/** State class applied to the root element if `disabled={true}`. */
disabled: string;
/** State class applied to the root element if `error={true}`. */
error: string;
/** State class applied to the root element if the inner input has value. */
filled: string;
/** State class applied to the root element if the inner input is focused. */
focused: string;
/** State class applied to the root element if `required={true}`. */
required: string;
}
export type FormControlClassKey = keyof FormControlClasses;
export declare function getFormControlUtilityClass(slot: string): string;
export declare const formControlClasses: FormControlClasses;
+7
View File
@@ -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
View File
@@ -0,0 +1,5 @@
export { FormControl } from './FormControl';
export { FormControlContext } from './FormControlContext';
export * from './FormControl.types';
export * from './formControlClasses';
export { useFormControlContext } from './useFormControlContext';
+5
View File
@@ -0,0 +1,5 @@
export { FormControl } from './FormControl';
export { FormControlContext } from './FormControlContext';
export * from './FormControl.types';
export * from './formControlClasses';
export { useFormControlContext } from './useFormControlContext';
+6
View File
@@ -0,0 +1,6 @@
{
"sideEffects": false,
"module": "./index.js",
"main": "../node/FormControl/index.js",
"types": "./index.d.ts"
}
+12
View File
@@ -0,0 +1,12 @@
import { UseFormControlContextReturnValue } from './FormControl.types';
/**
*
* 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 declare function useFormControlContext(): UseFormControlContextReturnValue | undefined;
+17
View File
@@ -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);
}
+14
View File
@@ -0,0 +1,14 @@
import { PolymorphicComponent } from '../utils/PolymorphicComponent';
import { InputTypeMap } from './Input.types';
/**
*
* Demos:
*
* - [Input](https://mui.com/base-ui/react-input/)
*
* API:
*
* - [Input API](https://mui.com/base-ui/react-input/components-api/#input)
*/
declare const Input: PolymorphicComponent<InputTypeMap<{}, "div">>;
export { Input };
+311
View File
@@ -0,0 +1,311 @@
'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) {
var _slots$root, _slots$textarea, _slots$input;
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 != null ? 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 = slots.root) != null ? _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 = slots.textarea) != null ? _slots$textarea : 'textarea' : (_slots$input = slots.input) != null ? _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 };
+176
View File
@@ -0,0 +1,176 @@
import * as React from 'react';
import { Simplify } from '@mui/types';
import { FormControlState } from '../FormControl';
import { UseInputParameters, UseInputRootSlotProps } from '../useInput';
import { PolymorphicProps, SlotComponentProps } from '../utils';
export interface InputRootSlotPropsOverrides {
}
export interface InputInputSlotPropsOverrides {
}
export interface SingleLineInputProps {
/**
* Maximum number of rows to display when multiline option is set to true.
*/
maxRows?: undefined;
/**
* Minimum number of rows to display when multiline option is set to true.
*/
minRows?: undefined;
/**
* If `true`, a `textarea` element is rendered.
* @default false
*/
multiline?: false;
/**
* Number of rows to display when multiline option is set to true.
*/
rows?: undefined;
/**
* 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?: React.HTMLInputTypeAttribute;
}
export interface MultiLineInputProps {
/**
* Maximum number of rows to display when multiline option is set to true.
*/
maxRows?: number;
/**
* Minimum number of rows to display when multiline option is set to true.
*/
minRows?: number;
/**
* If `true`, a `textarea` element is rendered.
* @default false
*/
multiline: true;
/**
* Number of rows to display when multiline option is set to true.
*/
rows?: number;
/**
* 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?: undefined;
}
export type InputOwnProps = (SingleLineInputProps | MultiLineInputProps) & Omit<UseInputParameters, 'error'> & {
'aria-describedby'?: string;
'aria-label'?: string;
'aria-labelledby'?: 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?: string;
/**
* If `true`, the `input` element is focused during the first mount.
*/
autoFocus?: boolean;
/**
* Class name applied to the root element.
*/
className?: string;
/**
* Trailing adornment for this input.
*/
endAdornment?: React.ReactNode;
/**
* 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?: boolean;
/**
* The id of the `input` element.
*/
id?: string;
/**
* Name attribute of the `input` element.
*/
name?: string;
onKeyDown?: React.KeyboardEventHandler<HTMLInputElement>;
onKeyUp?: React.KeyboardEventHandler<HTMLInputElement>;
/**
* The short hint displayed in the `input` before the user enters a value.
*/
placeholder?: string;
/**
* It prevents the user from changing the value of the field
* (not from interacting with the field).
*/
readOnly?: boolean;
/**
* The props used for each slot inside the Input.
* @default {}
*/
slotProps?: {
root?: SlotComponentProps<'div', InputRootSlotPropsOverrides, InputOwnerState>;
input?: SlotComponentProps<'input', InputInputSlotPropsOverrides, InputOwnerState>;
};
/**
* The components used for each slot inside the InputBase.
* Either a string to use a HTML element or a component.
* @default {}
*/
slots?: InputSlots;
/**
* Leading adornment for this input.
*/
startAdornment?: React.ReactNode;
/**
* The value of the `input` element, required for a controlled component.
*/
value?: unknown;
};
export interface InputSlots {
/**
* The component that renders the root.
* @default 'div'
*/
root?: React.ElementType;
/**
* The component that renders the input.
* @default 'input'
*/
input?: React.ElementType;
/**
* The component that renders the textarea.
* @default 'textarea'
*/
textarea?: React.ElementType;
}
export interface InputTypeMap<AdditionalProps = {}, RootComponentType extends React.ElementType = 'div'> {
props: InputOwnProps & AdditionalProps;
defaultComponent: RootComponentType;
}
export type InputProps<RootComponentType extends React.ElementType = InputTypeMap['defaultComponent']> = PolymorphicProps<InputTypeMap<{}, RootComponentType>, RootComponentType>;
export type InputOwnerState = Simplify<InputOwnProps & {
formControlContext: FormControlState | undefined;
focused: boolean;
type: React.InputHTMLAttributes<HTMLInputElement>['type'] | undefined;
}>;
export type InputRootSlotProps = Simplify<UseInputRootSlotProps & {
ownerState: InputOwnerState;
className?: string;
children?: React.ReactNode;
ref?: React.Ref<HTMLDivElement>;
}>;
export type InputInputSlotProps = Simplify<Omit<UseInputRootSlotProps, 'onClick'> & {
'aria-describedby': React.AriaAttributes['aria-describedby'];
'aria-label': React.AriaAttributes['aria-label'];
'aria-labelledby': React.AriaAttributes['aria-labelledby'];
autoComplete: string | undefined;
autoFocus: boolean | undefined;
className?: string;
id: string | undefined;
name: string | undefined;
onKeyDown: React.KeyboardEventHandler<HTMLInputElement> | undefined;
onKeyUp: React.KeyboardEventHandler<HTMLInputElement> | undefined;
ownerState: InputOwnerState;
placeholder: string | undefined;
readOnly: boolean | undefined;
ref: React.Ref<HTMLInputElement>;
type: React.HTMLInputTypeAttribute | undefined;
}>;
+1
View File
@@ -0,0 +1 @@
export {};
+3
View File
@@ -0,0 +1,3 @@
export { Input } from './Input';
export * from './Input.types';
export * from './inputClasses';
+5
View File
@@ -0,0 +1,5 @@
'use client';
export { Input } from './Input';
export * from './Input.types';
export * from './inputClasses';
+27
View File
@@ -0,0 +1,27 @@
export interface InputClasses {
/** Class name applied to the root element. */
root: string;
/** Class name applied to the root element if the component is a descendant of `FormControl`. */
formControl: string;
/** Class name applied to the root element if `startAdornment` is provided. */
adornedStart: string;
/** Class name applied to the root element if `endAdornment` is provided. */
adornedEnd: string;
/** State class applied to the root element if the component is focused. */
focused: string;
/** State class applied to the root element if `disabled={true}`. */
disabled: string;
/** State class applied to the root element if `error={true}`. */
error: string;
/** Class name applied to the root element if `multiline={true}`. */
multiline: string;
/** Class name applied to the input element. */
input: string;
/** Class name applied to the input element if `multiline={true}`. */
inputMultiline: string;
/** Class name applied to the input element if `type="search"`. */
inputTypeSearch: string;
}
export type InputClassKey = keyof InputClasses;
export declare function getInputUtilityClass(slot: string): string;
export declare const inputClasses: InputClasses;
+7
View File
@@ -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']);
+6
View File
@@ -0,0 +1,6 @@
{
"sideEffects": false,
"module": "./index.js",
"main": "../node/Input/index.js",
"types": "./index.d.ts"
}
+21
View File
@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2014 Call-Em-All
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+14
View File
@@ -0,0 +1,14 @@
import { PolymorphicComponent } from '../utils/PolymorphicComponent';
import { MenuTypeMap } from './Menu.types';
/**
*
* Demos:
*
* - [Menu](https://mui.com/base-ui/react-menu/)
*
* API:
*
* - [Menu API](https://mui.com/base-ui/react-menu/components-api/#menu)
*/
declare const Menu: PolymorphicComponent<MenuTypeMap<{}, "div">>;
export { Menu };
+161
View File
@@ -0,0 +1,161 @@
'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) {
var _slots$root, _slots$listbox;
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 != null ? 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 = slots.root) != null ? _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 = slots.listbox) != null ? _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 };
+81
View File
@@ -0,0 +1,81 @@
import * as React from 'react';
import { Simplify } from '@mui/types';
import { PolymorphicProps, SlotComponentProps } from '../utils';
import { UseMenuListboxSlotProps } from '../useMenu';
import { ListAction } from '../useList';
import { PopupProps } from '../Unstable_Popup';
export interface MenuRootSlotPropsOverrides {
}
export interface MenuListboxSlotPropsOverrides {
}
export interface MenuActions {
/**
* Dispatches an action that can cause a change to the menu's internal state.
*/
dispatch: (action: ListAction<string>) => void;
/**
* Resets the highlighted item.
*/
resetHighlight: () => void;
}
export interface MenuOwnProps {
/**
* A ref with imperative actions that can be performed on the menu.
*/
actions?: React.Ref<MenuActions>;
/**
* The element based on which the menu is positioned.
*/
anchor?: PopupProps['anchor'];
children?: React.ReactNode;
className?: string;
/**
* Function called when the items displayed in the menu change.
*/
onItemsChange?: (items: string[]) => void;
/**
* The props used for each slot inside the Menu.
* @default {}
*/
slotProps?: {
root?: SlotComponentProps<'div', MenuRootSlotPropsOverrides & PopupProps, MenuOwnerState>;
listbox?: SlotComponentProps<'ul', MenuListboxSlotPropsOverrides, MenuOwnerState>;
};
/**
* The components used for each slot inside the Menu.
* Either a string to use a HTML element or a component.
* @default {}
*/
slots?: MenuSlots;
}
export interface MenuSlots {
/**
* The component that renders the popup element.
* @default 'div'
*/
root?: React.ElementType;
/**
* The component that renders the listbox.
* @default 'ul'
*/
listbox?: React.ElementType;
}
export interface MenuTypeMap<AdditionalProps = {}, RootComponentType extends React.ElementType = 'div'> {
props: MenuOwnProps & AdditionalProps;
defaultComponent: RootComponentType;
}
export type MenuProps<RootComponentType extends React.ElementType = MenuTypeMap['defaultComponent']> = PolymorphicProps<MenuTypeMap<{}, RootComponentType>, RootComponentType>;
export type MenuOwnerState = Simplify<MenuOwnProps & {
open: boolean;
}>;
export type MenuRootSlotProps = {
children?: React.ReactNode;
className?: string;
ownerState: MenuOwnerState;
ref: React.Ref<any>;
};
export type MenuListboxSlotProps = UseMenuListboxSlotProps & {
children?: React.ReactNode;
className?: string;
ownerState: MenuOwnerState;
};
+1
View File
@@ -0,0 +1 @@
export {};
+3
View File
@@ -0,0 +1,3 @@
export { Menu } from './Menu';
export * from './menuClasses';
export * from './Menu.types';
+3
View File
@@ -0,0 +1,3 @@
export { Menu } from './Menu';
export * from './menuClasses';
export * from './Menu.types';
+11
View File
@@ -0,0 +1,11 @@
export interface MenuClasses {
/** Class name applied to the root element. */
root: string;
/** Class name applied to the listbox element. */
listbox: string;
/** State class applied to the root element if `open={true}`. */
expanded: string;
}
export type MenuClassKey = keyof MenuClasses;
export declare function getMenuUtilityClass(slot: string): string;
export declare const menuClasses: MenuClasses;
+7
View File
@@ -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']);
+6
View File
@@ -0,0 +1,6 @@
{
"sideEffects": false,
"module": "./index.js",
"main": "../node/Menu/index.js",
"types": "./index.d.ts"
}
+14
View File
@@ -0,0 +1,14 @@
import * as React from 'react';
import { MenuButtonProps } from './MenuButton.types';
/**
*
* Demos:
*
* - [Menu](https://mui.com/base-ui/react-menu/)
*
* API:
*
* - [MenuButton API](https://mui.com/base-ui/react-menu/components-api/#menu-button)
*/
declare const MenuButton: React.ForwardRefExoticComponent<MenuButtonProps & React.RefAttributes<HTMLElement>>;
export { MenuButton };
+121
View File
@@ -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 };
+50
View File
@@ -0,0 +1,50 @@
/// <reference types="react" />
import { SlotComponentProps } from '../utils/types';
export interface MenuButtonRootSlotPropsOverrides {
}
export interface MenuButtonProps {
children?: React.ReactNode;
/**
* Class name applied to the root element.
*/
className?: string;
/**
* If `true`, the component is disabled.
* @default false
*/
disabled?: boolean;
/**
* If `true`, allows a disabled button to receive focus.
* @default false
*/
focusableWhenDisabled?: boolean;
/**
* Label of the button
*/
label?: string;
/**
* The props used for each slot inside the MenuButton.
* @default {}
*/
slots?: MenuButtonSlots;
/**
* The components used for each slot inside the MenuButton.
* Either a string to use a HTML element or a component.
* @default {}
*/
slotProps?: {
root?: SlotComponentProps<'button', MenuButtonRootSlotPropsOverrides, MenuButtonOwnerState>;
};
}
export interface MenuButtonSlots {
/**
* The component that renders the root.
* @default 'button'
*/
root?: React.ElementType;
}
export type MenuButtonOwnerState = MenuButtonProps & {
active: boolean;
focusableWhenDisabled: boolean;
open: boolean;
};
+1
View File
@@ -0,0 +1 @@
export {};
+3
View File
@@ -0,0 +1,3 @@
export { MenuButton } from './MenuButton';
export * from './MenuButton.types';
export * from './menuButtonClasses';
+5
View File
@@ -0,0 +1,5 @@
'use client';
export { MenuButton } from './MenuButton';
export * from './MenuButton.types';
export * from './menuButtonClasses';
+13
View File
@@ -0,0 +1,13 @@
export interface MenuButtonClasses {
/** Class name applied to the root element. */
root: string;
/** State class applied to the root element if `active={true}`. */
active: string;
/** State class applied to the root element if `disabled={true}`. */
disabled: string;
/** State class applied to the root element if the associated menu is open. */
expanded: string;
}
export type MenuButtonClassKey = keyof MenuButtonClasses;
export declare function getMenuButtonUtilityClass(slot: string): string;
export declare const menuButtonClasses: MenuButtonClasses;
+7
View File
@@ -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']);
+6
View File
@@ -0,0 +1,6 @@
{
"sideEffects": false,
"module": "./index.js",
"main": "../node/MenuButton/index.js",
"types": "./index.d.ts"
}
+15
View File
@@ -0,0 +1,15 @@
import { PolymorphicComponent } from '../utils/PolymorphicComponent';
import { MenuItemTypeMap } from './MenuItem.types';
/**
* 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)
*/
declare const MenuItem: PolymorphicComponent<MenuItemTypeMap<{}, "li">>;
export { MenuItem };
+148
View File
@@ -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", "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) {
var _slots$root;
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 = slots.root) != null ? _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 };
+67
View File
@@ -0,0 +1,67 @@
import * as React from 'react';
import { Simplify } from '@mui/types';
import { PolymorphicProps, SlotComponentProps } from '../utils';
import { UseMenuItemRootSlotProps } from '../useMenuItem';
export interface MenuItemRootSlotPropsOverrides {
}
export type MenuItemOwnerState = Simplify<MenuItemOwnProps & {
disabled: boolean;
focusVisible: boolean;
highlighted: boolean;
}>;
export interface MenuItemOwnProps {
children?: React.ReactNode;
className?: string;
onClick?: React.MouseEventHandler<HTMLElement>;
/**
* If `true`, the menu item will be disabled.
* @default false
*/
disabled?: boolean;
/**
* The components used for each slot inside the MenuItem.
* Either a string to use a HTML element or a component.
* @default {}
*/
slots?: MenuItemSlots;
/**
* The props used for each slot inside the MenuItem.
* @default {}
*/
slotProps?: {
root?: SlotComponentProps<'li', MenuItemRootSlotPropsOverrides, MenuItemOwnerState>;
};
/**
* A text representation of the menu item's content.
* Used for keyboard text navigation matching.
*/
label?: string;
/**
* If `true`, the menu item won't receive focus when the mouse moves over it.
*
* @default false
*/
disableFocusOnHover?: boolean;
}
export interface MenuItemSlots {
/**
* The component that renders the root.
* @default 'li'
*/
root?: React.ElementType;
}
export interface MenuItemTypeMap<AdditionalProps = {}, RootComponentType extends React.ElementType = 'li'> {
props: MenuItemOwnProps & AdditionalProps;
defaultComponent: RootComponentType;
}
export type MenuItemProps<RootComponentType extends React.ElementType = MenuItemTypeMap['defaultComponent']> = PolymorphicProps<MenuItemTypeMap<{}, RootComponentType>, RootComponentType>;
export interface MenuItemState {
disabled: boolean;
highlighted: boolean;
}
export type MenuItemRootSlotProps = Simplify<UseMenuItemRootSlotProps & {
children?: React.ReactNode;
className: string;
ref: React.Ref<HTMLElement>;
ownerState: MenuItemOwnerState;
}>;
+1
View File
@@ -0,0 +1 @@
export {};
+3
View File
@@ -0,0 +1,3 @@
export * from './MenuItem';
export * from './MenuItem.types';
export * from './menuItemClasses';
+5
View File
@@ -0,0 +1,5 @@
'use client';
export * from './MenuItem';
export * from './MenuItem.types';
export * from './menuItemClasses';
+11
View File
@@ -0,0 +1,11 @@
export interface MenuItemClasses {
/** Class name applied to the root element. */
root: string;
/** State class applied to the root `button` element if `disabled={true}`. */
disabled: string;
/** State class applied to the root `button` element if `focusVisible={true}`. */
focusVisible: string;
}
export type MenuItemClassKey = keyof MenuItemClasses;
export declare function getMenuItemUtilityClass(slot: string): string;
export declare const menuItemClasses: MenuItemClasses;
+7
View File
@@ -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']);
+6
View File
@@ -0,0 +1,6 @@
{
"sideEffects": false,
"module": "./index.js",
"main": "../node/MenuItem/index.js",
"types": "./index.d.ts"
}
+25
View File
@@ -0,0 +1,25 @@
import { PolymorphicComponent } from '../utils/PolymorphicComponent';
import { ModalTypeMap } from './Modal.types';
/**
* 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)
*/
declare const Modal: PolymorphicComponent<ModalTypeMap<{}, "div">>;
export { Modal };
+278
View File
@@ -0,0 +1,278 @@
'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) {
var _slots$root;
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 = slots.root) != null ? _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 != null && 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 };
+164
View File
@@ -0,0 +1,164 @@
import * as React from 'react';
import { Simplify } from '@mui/types';
import { PortalProps } from '../Portal';
import { PolymorphicProps, SlotComponentProps } from '../utils';
export interface ModalRootSlotPropsOverrides {
}
export interface ModalBackdropSlotPropsOverrides {
}
export interface ModalOwnProps {
/**
* A single child content element.
*/
children: React.ReactElement;
/**
* When set to true the Modal waits until a nested Transition is completed before closing.
* @default false
*/
closeAfterTransition?: boolean;
/**
* 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?: PortalProps['container'];
/**
* 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?: boolean;
/**
* 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?: boolean;
/**
* If `true`, hitting escape will not fire the `onClose` callback.
* @default false
*/
disableEscapeKeyDown?: boolean;
/**
* The `children` will be under the DOM hierarchy of the parent component.
* @default false
*/
disablePortal?: PortalProps['disablePortal'];
/**
* If `true`, the modal will not restore focus to previously focused element once
* modal is hidden or unmounted.
* @default false
*/
disableRestoreFocus?: boolean;
/**
* Disable the scroll lock behavior.
* @default false
*/
disableScrollLock?: boolean;
/**
* If `true`, the backdrop is not rendered.
* @default false
*/
hideBackdrop?: boolean;
/**
* 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?: boolean;
/**
* Callback fired when the backdrop is clicked.
* @deprecated Use the `onClose` prop with the `reason` argument to handle the `backdropClick` events.
*/
onBackdropClick?: React.ReactEventHandler<{}>;
/**
* 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?: {
bivarianceHack(event: {}, reason: 'backdropClick' | 'escapeKeyDown'): void;
}['bivarianceHack'];
/**
* A function called when a transition enters.
*/
onTransitionEnter?: () => void;
/**
* A function called when a transition has exited.
*/
onTransitionExited?: () => void;
/**
* If `true`, the component is shown.
*/
open: boolean;
/**
* The props used for each slot inside the Modal.
* @default {}
*/
slotProps?: {
root?: SlotComponentProps<'div', ModalRootSlotPropsOverrides, ModalOwnerState>;
backdrop?: SlotComponentProps<'div', ModalBackdropSlotPropsOverrides, ModalOwnerState>;
};
/**
* The components used for each slot inside the Modal.
* Either a string to use a HTML element or a component.
* @default {}
*/
slots?: ModalSlots;
}
export interface ModalSlots {
/**
* The component that renders the root.
* @default 'div'
*/
root?: React.ElementType;
/**
* The component that renders the backdrop.
*/
backdrop?: React.ElementType;
}
export interface ModalTypeMap<AdditionalProps = {}, RootComponentType extends React.ElementType = 'div'> {
props: ModalOwnProps & AdditionalProps;
defaultComponent: RootComponentType;
}
export type ModalProps<RootComponentType extends React.ElementType = ModalTypeMap['defaultComponent']> = PolymorphicProps<ModalTypeMap<{}, RootComponentType>, RootComponentType>;
export type ModalOwnerState = Simplify<ModalOwnProps & {
closeAfterTransition: boolean;
disableAutoFocus: boolean;
disableEnforceFocus: boolean;
disableEscapeKeyDown: boolean;
disablePortal: boolean;
disableRestoreFocus: boolean;
disableScrollLock: boolean;
exited: boolean;
hideBackdrop: boolean;
keepMounted: boolean;
}>;
export interface ModalRootSlotProps {
children: React.ReactNode;
className?: string;
onKeyDown: React.KeyboardEventHandler;
ownerState: ModalOwnerState;
role: React.AriaRole;
}
export interface ModalBackdropSlotProps {
'aria-hidden': React.AriaAttributes['aria-hidden'];
children?: React.ReactNode;
onClick: React.MouseEventHandler;
open: boolean;
ownerState: ModalOwnerState;
}
+1
View File
@@ -0,0 +1 @@
export {};
+3
View File
@@ -0,0 +1,3 @@
export { Modal } from './Modal';
export * from './Modal.types';
export * from './modalClasses';
+3
View File
@@ -0,0 +1,3 @@
export { Modal } from './Modal';
export * from './Modal.types';
export * from './modalClasses';
+11
View File
@@ -0,0 +1,11 @@
export interface ModalClasses {
/** Class name applied to the root element. */
root: string;
/** Class name applied to the root element if the `Modal` has exited. */
hidden: string;
/** Class name applied to the backdrop element. */
backdrop: string;
}
export type ModalClassKey = keyof ModalClasses;
export declare function getModalUtilityClass(slot: string): string;
export declare const modalClasses: ModalClasses;
+7
View File
@@ -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']);
+6
View File
@@ -0,0 +1,6 @@
{
"sideEffects": false,
"module": "./index.js",
"main": "../node/Modal/index.js",
"types": "./index.d.ts"
}
Loaded 100 of 6977 files, more files were not shown because too many files have changed in this diff. Show more