pre-installations and preparations
This commit is contained in:
1 parent
3e5a0329cb
commit
201d621ac3
6977 files changed
+742826
No files matched your search
+46
@@ -0,0 +1,46 @@
|
||||
'use client';
|
||||
|
||||
import * as React from 'react';
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
var defaultContextValue = {
|
||||
disableDefaultClasses: false
|
||||
};
|
||||
var ClassNameConfiguratorContext = /*#__PURE__*/React.createContext(defaultContextValue);
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
ClassNameConfiguratorContext.displayName = 'ClassNameConfiguratorContext';
|
||||
}
|
||||
/**
|
||||
* @ignore - internal hook.
|
||||
*
|
||||
* Wraps the `generateUtilityClass` function and controls how the classes are generated.
|
||||
* Currently it only affects whether the classes are applied or not.
|
||||
*
|
||||
* @returns Function to be called with the `generateUtilityClass` function specific to a component to generate the classes.
|
||||
*/
|
||||
export function useClassNamesOverride(generateUtilityClass) {
|
||||
var _React$useContext = React.useContext(ClassNameConfiguratorContext),
|
||||
disableDefaultClasses = _React$useContext.disableDefaultClasses;
|
||||
return function (slot) {
|
||||
if (disableDefaultClasses) {
|
||||
return '';
|
||||
}
|
||||
return generateUtilityClass(slot);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows to configure the components within to not apply any built-in classes.
|
||||
*/
|
||||
export function ClassNameConfigurator(props) {
|
||||
var disableDefaultClasses = props.disableDefaultClasses,
|
||||
children = props.children;
|
||||
var contextValue = React.useMemo(function () {
|
||||
return {
|
||||
disableDefaultClasses: disableDefaultClasses != null ? disableDefaultClasses : false
|
||||
};
|
||||
}, [disableDefaultClasses]);
|
||||
return /*#__PURE__*/_jsx(ClassNameConfiguratorContext.Provider, {
|
||||
value: contextValue,
|
||||
children: children
|
||||
});
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
import _extends from "@babel/runtime/helpers/esm/extends";
|
||||
import { isHostComponent } from './isHostComponent';
|
||||
|
||||
/**
|
||||
* Type of the ownerState based on the type of an element it applies to.
|
||||
* This resolves to the provided OwnerState for React components and `undefined` for host components.
|
||||
* Falls back to `OwnerState | undefined` when the exact type can't be determined in development time.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Appends the ownerState object to the props, merging with the existing one if necessary.
|
||||
*
|
||||
* @param elementType Type of the element that owns the `existingProps`. If the element is a DOM node or undefined, `ownerState` is not applied.
|
||||
* @param otherProps Props of the element.
|
||||
* @param ownerState
|
||||
*/
|
||||
export function appendOwnerState(elementType, otherProps, ownerState) {
|
||||
if (elementType === undefined || isHostComponent(elementType)) {
|
||||
return otherProps;
|
||||
}
|
||||
return _extends({}, otherProps, {
|
||||
ownerState: _extends({}, otherProps.ownerState, ownerState)
|
||||
});
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
export function areArraysEqual(array1, array2) {
|
||||
var itemComparer = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function (a, b) {
|
||||
return a === b;
|
||||
};
|
||||
return array1.length === array2.length && array1.every(function (value, index) {
|
||||
return itemComparer(value, array2[index]);
|
||||
});
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
import _extends from "@babel/runtime/helpers/esm/extends";
|
||||
/**
|
||||
* Combines the two get*Props functions from Base UI hooks into one.
|
||||
* Useful when a hook uses two other hooks behind the scenes
|
||||
* (such as useSelect that depends on useList and useButton for its root slot).
|
||||
*
|
||||
* The resulting function will return the combined props.
|
||||
* They are merged from left to right, similarly to how Object.assign works.
|
||||
*
|
||||
* The getSecondProps function will receive the result of the getFirstProps function as its argument,
|
||||
* so its event handlers can call the previous handlers and act depending on its result.
|
||||
*
|
||||
* @param getFirstProps - A getter function that returns the props for the first slot. It receives the external event handlers as its argument.
|
||||
* @param getSecondProps - A getter function that returns the props for the second slot. It receives the result of the getFirstProps function as its argument.
|
||||
*/
|
||||
export function combineHooksSlotProps(getFirstProps, getSecondProps) {
|
||||
return function getCombinedProps() {
|
||||
var external = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
||||
var firstResult = _extends({}, external, getFirstProps(external));
|
||||
var result = _extends({}, firstResult, getSecondProps(firstResult));
|
||||
return result;
|
||||
};
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Extracts event handlers from a given object.
|
||||
* A prop is considered an event handler if it is a function and its name starts with `on`.
|
||||
*
|
||||
* @param object An object to extract event handlers from.
|
||||
* @param excludeKeys An array of keys to exclude from the returned object.
|
||||
*/
|
||||
export function extractEventHandlers(object) {
|
||||
var excludeKeys = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
||||
if (object === undefined) {
|
||||
return {};
|
||||
}
|
||||
var result = {};
|
||||
Object.keys(object).filter(function (prop) {
|
||||
return prop.match(/^on[A-Z]/) && typeof object[prop] === 'function' && !excludeKeys.includes(prop);
|
||||
}).forEach(function (prop) {
|
||||
result[prop] = object[prop];
|
||||
});
|
||||
return result;
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
'use client';
|
||||
|
||||
export { appendOwnerState } from './appendOwnerState';
|
||||
export { areArraysEqual } from './areArraysEqual';
|
||||
export { ClassNameConfigurator } from './ClassNameConfigurator';
|
||||
export { extractEventHandlers } from './extractEventHandlers';
|
||||
export { isHostComponent } from './isHostComponent';
|
||||
export { resolveComponentProps } from './resolveComponentProps';
|
||||
export { useRootElementName } from './useRootElementName';
|
||||
export { useSlotProps } from './useSlotProps';
|
||||
export { mergeSlotProps } from './mergeSlotProps';
|
||||
export { prepareForSlot } from './prepareForSlot';
|
||||
export * from './PolymorphicComponent';
|
||||
export * from './types';
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* Determines if a given element is a DOM element name (i.e. not a React component).
|
||||
*/
|
||||
export function isHostComponent(element) {
|
||||
return typeof element === 'string';
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
import _extends from "@babel/runtime/helpers/esm/extends";
|
||||
import clsx from 'clsx';
|
||||
import { extractEventHandlers } from './extractEventHandlers';
|
||||
import { omitEventHandlers } from './omitEventHandlers';
|
||||
/**
|
||||
* Merges the slot component internal props (usually coming from a hook)
|
||||
* with the externally provided ones.
|
||||
*
|
||||
* The merge order is (the latter overrides the former):
|
||||
* 1. The internal props (specified as a getter function to work with get*Props hook result)
|
||||
* 2. Additional props (specified internally on a Base UI component)
|
||||
* 3. External props specified on the owner component. These should only be used on a root slot.
|
||||
* 4. External props specified in the `slotProps.*` prop.
|
||||
* 5. The `className` prop - combined from all the above.
|
||||
* @param parameters
|
||||
* @returns
|
||||
*/
|
||||
export function mergeSlotProps(parameters) {
|
||||
var getSlotProps = parameters.getSlotProps,
|
||||
additionalProps = parameters.additionalProps,
|
||||
externalSlotProps = parameters.externalSlotProps,
|
||||
externalForwardedProps = parameters.externalForwardedProps,
|
||||
className = parameters.className;
|
||||
if (!getSlotProps) {
|
||||
// The simpler case - getSlotProps is not defined, so no internal event handlers are defined,
|
||||
// so we can simply merge all the props without having to worry about extracting event handlers.
|
||||
var _joinedClasses = clsx(additionalProps == null ? void 0 : additionalProps.className, className, externalForwardedProps == null ? void 0 : externalForwardedProps.className, externalSlotProps == null ? void 0 : externalSlotProps.className);
|
||||
var _mergedStyle = _extends({}, additionalProps == null ? void 0 : additionalProps.style, externalForwardedProps == null ? void 0 : externalForwardedProps.style, externalSlotProps == null ? void 0 : externalSlotProps.style);
|
||||
var _props = _extends({}, additionalProps, externalForwardedProps, externalSlotProps);
|
||||
if (_joinedClasses.length > 0) {
|
||||
_props.className = _joinedClasses;
|
||||
}
|
||||
if (Object.keys(_mergedStyle).length > 0) {
|
||||
_props.style = _mergedStyle;
|
||||
}
|
||||
return {
|
||||
props: _props,
|
||||
internalRef: undefined
|
||||
};
|
||||
}
|
||||
|
||||
// In this case, getSlotProps is responsible for calling the external event handlers.
|
||||
// We don't need to include them in the merged props because of this.
|
||||
|
||||
var eventHandlers = extractEventHandlers(_extends({}, externalForwardedProps, externalSlotProps));
|
||||
var componentsPropsWithoutEventHandlers = omitEventHandlers(externalSlotProps);
|
||||
var otherPropsWithoutEventHandlers = omitEventHandlers(externalForwardedProps);
|
||||
var internalSlotProps = getSlotProps(eventHandlers);
|
||||
|
||||
// The order of classes is important here.
|
||||
// Emotion (that we use in libraries consuming Base UI) depends on this order
|
||||
// to properly override style. It requires the most important classes to be last
|
||||
// (see https://github.com/mui/material-ui/pull/33205) for the related discussion.
|
||||
var joinedClasses = clsx(internalSlotProps == null ? void 0 : internalSlotProps.className, additionalProps == null ? void 0 : additionalProps.className, className, externalForwardedProps == null ? void 0 : externalForwardedProps.className, externalSlotProps == null ? void 0 : externalSlotProps.className);
|
||||
var mergedStyle = _extends({}, internalSlotProps == null ? void 0 : internalSlotProps.style, additionalProps == null ? void 0 : additionalProps.style, externalForwardedProps == null ? void 0 : externalForwardedProps.style, externalSlotProps == null ? void 0 : externalSlotProps.style);
|
||||
var props = _extends({}, internalSlotProps, additionalProps, otherPropsWithoutEventHandlers, componentsPropsWithoutEventHandlers);
|
||||
if (joinedClasses.length > 0) {
|
||||
props.className = joinedClasses;
|
||||
}
|
||||
if (Object.keys(mergedStyle).length > 0) {
|
||||
props.style = mergedStyle;
|
||||
}
|
||||
return {
|
||||
props: props,
|
||||
internalRef: internalSlotProps.ref
|
||||
};
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* Removes event handlers from the given object.
|
||||
* A field is considered an event handler if it is a function with a name beginning with `on`.
|
||||
*
|
||||
* @param object Object to remove event handlers from.
|
||||
* @returns Object with event handlers removed.
|
||||
*/
|
||||
export function omitEventHandlers(object) {
|
||||
if (object === undefined) {
|
||||
return {};
|
||||
}
|
||||
var result = {};
|
||||
Object.keys(object).filter(function (prop) {
|
||||
return !(prop.match(/^on[A-Z]/) && typeof object[prop] === 'function');
|
||||
}).forEach(function (prop) {
|
||||
result[prop] = object[prop];
|
||||
});
|
||||
return result;
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
import _extends from "@babel/runtime/helpers/esm/extends";
|
||||
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
||||
import * as React from 'react';
|
||||
export function prepareForSlot(Component) {
|
||||
return /*#__PURE__*/React.forwardRef(function Slot(props, ref) {
|
||||
var ownerState = props.ownerState,
|
||||
other = _objectWithoutProperties(props, ["ownerState"]);
|
||||
return /*#__PURE__*/React.createElement(Component, _extends({}, other, {
|
||||
ref: ref
|
||||
}));
|
||||
});
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* If `componentProps` is a function, calls it with the provided `ownerState`.
|
||||
* Otherwise, just returns `componentProps`.
|
||||
*/
|
||||
export function resolveComponentProps(componentProps, ownerState, slotState) {
|
||||
if (typeof componentProps === 'function') {
|
||||
return componentProps(ownerState, slotState);
|
||||
}
|
||||
return componentProps;
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
+135
@@ -0,0 +1,135 @@
|
||||
'use client';
|
||||
|
||||
import _extends from "@babel/runtime/helpers/esm/extends";
|
||||
import * as React from 'react';
|
||||
function areEqual(a, b) {
|
||||
return a === b;
|
||||
}
|
||||
var EMPTY_OBJECT = {};
|
||||
var NOOP = function NOOP() {};
|
||||
|
||||
/**
|
||||
* Gets the current state augmented with controlled values from the outside.
|
||||
* If a state item has a corresponding controlled value, it will be used instead of the internal state.
|
||||
*/
|
||||
function getControlledState(internalState, controlledProps) {
|
||||
var augmentedState = _extends({}, internalState);
|
||||
Object.keys(controlledProps).forEach(function (key) {
|
||||
if (controlledProps[key] !== undefined) {
|
||||
augmentedState[key] = controlledProps[key];
|
||||
}
|
||||
});
|
||||
return augmentedState;
|
||||
}
|
||||
/**
|
||||
* Defines an effect that compares the next state with the previous state and calls
|
||||
* the `onStateChange` callback if the state has changed.
|
||||
* The comparison is done based on the `stateComparers` parameter.
|
||||
*/
|
||||
function useStateChangeDetection(parameters) {
|
||||
var nextState = parameters.nextState,
|
||||
initialState = parameters.initialState,
|
||||
stateComparers = parameters.stateComparers,
|
||||
onStateChange = parameters.onStateChange,
|
||||
controlledProps = parameters.controlledProps,
|
||||
lastActionRef = parameters.lastActionRef;
|
||||
var internalPreviousStateRef = React.useRef(initialState);
|
||||
React.useEffect(function () {
|
||||
if (lastActionRef.current === null) {
|
||||
// Detect changes only if an action has been dispatched.
|
||||
return;
|
||||
}
|
||||
var previousState = getControlledState(internalPreviousStateRef.current, controlledProps);
|
||||
Object.keys(nextState).forEach(function (key) {
|
||||
var _stateComparers$key;
|
||||
// go through all state keys and compare them with the previous state
|
||||
var stateComparer = (_stateComparers$key = stateComparers[key]) != null ? _stateComparers$key : areEqual;
|
||||
var nextStateItem = nextState[key];
|
||||
var previousStateItem = previousState[key];
|
||||
if (previousStateItem == null && nextStateItem != null || previousStateItem != null && nextStateItem == null || previousStateItem != null && nextStateItem != null && !stateComparer(nextStateItem, previousStateItem)) {
|
||||
var _event, _type;
|
||||
onStateChange == null || onStateChange((_event = lastActionRef.current.event) != null ? _event : null, key, nextStateItem, (_type = lastActionRef.current.type) != null ? _type : '', nextState);
|
||||
}
|
||||
});
|
||||
internalPreviousStateRef.current = nextState;
|
||||
lastActionRef.current = null;
|
||||
}, [internalPreviousStateRef, nextState, lastActionRef, onStateChange, stateComparers, controlledProps]);
|
||||
}
|
||||
|
||||
/**
|
||||
* The alternative to `React.useReducer` that lets you control the state from the outside.
|
||||
*
|
||||
* It can be used in an uncontrolled mode, similar to `React.useReducer`, or in a controlled mode, when the state is controlled by the props.
|
||||
* It also supports partially controlled state, when some state items are controlled and some are not.
|
||||
*
|
||||
* The controlled state items are provided via the `controlledProps` parameter.
|
||||
* When a reducer action is dispatched, the internal state is updated with the new values.
|
||||
* A change event (`onStateChange`) is then triggered (for each changed state item) if the new state is different from the previous state.
|
||||
* This event can be used to update the controlled values.
|
||||
*
|
||||
* The comparison of the previous and next states is done using the `stateComparers` parameter.
|
||||
* If a state item has a corresponding comparer, it will be used to determine if the state has changed.
|
||||
* This is useful when the state item is an object and you want to compare only a subset of its properties or if it's an array and you want to compare its contents.
|
||||
*
|
||||
* An additional feature is the `actionContext` parameter. It allows you to add additional properties to every action object,
|
||||
* similarly to how React context is implicitly available to every component.
|
||||
*
|
||||
* @template State - The type of the state calculated by the reducer.
|
||||
* @template Action - The type of the actions that can be dispatched.
|
||||
* @template ActionContext - The type of the additional properties that will be added to every action object.
|
||||
*
|
||||
* @ignore - internal hook.
|
||||
*/
|
||||
export function useControllableReducer(parameters) {
|
||||
var lastActionRef = React.useRef(null);
|
||||
var reducer = parameters.reducer,
|
||||
initialState = parameters.initialState,
|
||||
_parameters$controlle = parameters.controlledProps,
|
||||
controlledProps = _parameters$controlle === void 0 ? EMPTY_OBJECT : _parameters$controlle,
|
||||
_parameters$stateComp = parameters.stateComparers,
|
||||
stateComparers = _parameters$stateComp === void 0 ? EMPTY_OBJECT : _parameters$stateComp,
|
||||
_parameters$onStateCh = parameters.onStateChange,
|
||||
onStateChange = _parameters$onStateCh === void 0 ? NOOP : _parameters$onStateCh,
|
||||
actionContext = parameters.actionContext,
|
||||
_parameters$component = parameters.componentName,
|
||||
componentName = _parameters$component === void 0 ? '' : _parameters$component;
|
||||
var controlledPropsRef = React.useRef(controlledProps);
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
// eslint-disable-next-line react-hooks/rules-of-hooks
|
||||
React.useEffect(function () {
|
||||
Object.keys(controlledProps).forEach(function (key) {
|
||||
if (controlledPropsRef.current[key] !== undefined && controlledProps[key] === undefined) {
|
||||
console.error("useControllableReducer: ".concat(componentName ? "The ".concat(componentName, " component") : 'A component', " is changing a controlled prop to be uncontrolled: ").concat(key));
|
||||
}
|
||||
if (controlledPropsRef.current[key] === undefined && controlledProps[key] !== undefined) {
|
||||
console.error("useControllableReducer: ".concat(componentName ? "The ".concat(componentName, " component") : 'A component', " is changing an uncontrolled prop to be controlled: ").concat(key));
|
||||
}
|
||||
});
|
||||
}, [controlledProps, componentName]);
|
||||
}
|
||||
|
||||
// The reducer that is passed to React.useReducer is wrapped with a function that augments the state with controlled values.
|
||||
var reducerWithControlledState = React.useCallback(function (state, action) {
|
||||
lastActionRef.current = action;
|
||||
var controlledState = getControlledState(state, controlledProps);
|
||||
var newState = reducer(controlledState, action);
|
||||
return newState;
|
||||
}, [controlledProps, reducer]);
|
||||
var _React$useReducer = React.useReducer(reducerWithControlledState, initialState),
|
||||
nextState = _React$useReducer[0],
|
||||
dispatch = _React$useReducer[1]; // The action that is passed to dispatch is augmented with the actionContext.
|
||||
var dispatchWithContext = React.useCallback(function (action) {
|
||||
dispatch(_extends({}, action, {
|
||||
context: actionContext
|
||||
}));
|
||||
}, [actionContext]);
|
||||
useStateChangeDetection({
|
||||
nextState: nextState,
|
||||
initialState: initialState,
|
||||
stateComparers: stateComparers != null ? stateComparers : EMPTY_OBJECT,
|
||||
onStateChange: onStateChange != null ? onStateChange : NOOP,
|
||||
controlledProps: controlledProps,
|
||||
lastActionRef: lastActionRef
|
||||
});
|
||||
return [getControlledState(nextState, controlledProps), dispatchWithContext];
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
'use client';
|
||||
|
||||
import * as React from 'react';
|
||||
/**
|
||||
* @ignore - internal hook.
|
||||
*/
|
||||
export function useForcedRerendering() {
|
||||
var _React$useState = React.useState({}),
|
||||
setState = _React$useState[1];
|
||||
return React.useCallback(function () {
|
||||
setState({});
|
||||
}, []);
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
'use client';
|
||||
|
||||
import * as React from 'react';
|
||||
export function createMessageBus() {
|
||||
var listeners = new Map();
|
||||
function subscribe(topic, callback) {
|
||||
var topicListeners = listeners.get(topic);
|
||||
if (!topicListeners) {
|
||||
topicListeners = new Set([callback]);
|
||||
listeners.set(topic, topicListeners);
|
||||
} else {
|
||||
topicListeners.add(callback);
|
||||
}
|
||||
return function () {
|
||||
topicListeners.delete(callback);
|
||||
if (topicListeners.size === 0) {
|
||||
listeners.delete(topic);
|
||||
}
|
||||
};
|
||||
}
|
||||
function publish(topic) {
|
||||
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
||||
args[_key - 1] = arguments[_key];
|
||||
}
|
||||
var topicListeners = listeners.get(topic);
|
||||
if (topicListeners) {
|
||||
topicListeners.forEach(function (callback) {
|
||||
return callback.apply(void 0, args);
|
||||
});
|
||||
}
|
||||
}
|
||||
return {
|
||||
subscribe: subscribe,
|
||||
publish: publish
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignore - internal hook.
|
||||
*/
|
||||
export function useMessageBus() {
|
||||
var bus = React.useRef();
|
||||
if (!bus.current) {
|
||||
bus.current = createMessageBus();
|
||||
}
|
||||
return bus.current;
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
'use client';
|
||||
|
||||
import * as React from 'react';
|
||||
/**
|
||||
* @ignore - do not document.
|
||||
*
|
||||
* Use this function determine the host element correctly on the server (in a SSR context, for example Next.js)
|
||||
*/
|
||||
export function useRootElementName(parameters) {
|
||||
var _parameters$rootEleme = parameters.rootElementName,
|
||||
rootElementNameProp = _parameters$rootEleme === void 0 ? '' : _parameters$rootEleme,
|
||||
componentName = parameters.componentName;
|
||||
var _React$useState = React.useState(rootElementNameProp.toUpperCase()),
|
||||
rootElementName = _React$useState[0],
|
||||
setRootElementName = _React$useState[1];
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
// eslint-disable-next-line react-hooks/rules-of-hooks
|
||||
React.useEffect(function () {
|
||||
if (rootElementNameProp && rootElementName !== rootElementNameProp.toUpperCase()) {
|
||||
console.error("useRootElementName: the `rootElementName` prop of ".concat(componentName ? "the ".concat(componentName, " component") : 'a component', " expected the '").concat(rootElementNameProp, "' element, but a '").concat(rootElementName.toLowerCase(), "' was rendered instead"), 'This may cause hydration issues in an SSR context, for example in a Next.js app');
|
||||
}
|
||||
}, [rootElementNameProp, rootElementName, componentName]);
|
||||
}
|
||||
var updateRootElementName = React.useCallback(function (instance) {
|
||||
var _instance$tagName;
|
||||
setRootElementName((_instance$tagName = instance == null ? void 0 : instance.tagName) != null ? _instance$tagName : '');
|
||||
}, []);
|
||||
return [rootElementName, updateRootElementName];
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
'use client';
|
||||
|
||||
import _extends from "@babel/runtime/helpers/esm/extends";
|
||||
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
||||
import { unstable_useForkRef as useForkRef } from '@mui/utils';
|
||||
import { appendOwnerState } from './appendOwnerState';
|
||||
import { mergeSlotProps } from './mergeSlotProps';
|
||||
import { resolveComponentProps } from './resolveComponentProps';
|
||||
/**
|
||||
* @ignore - do not document.
|
||||
* Builds the props to be passed into the slot of an unstyled component.
|
||||
* It merges the internal props of the component with the ones supplied by the user, allowing to customize the behavior.
|
||||
* If the slot component is not a host component, it also merges in the `ownerState`.
|
||||
*
|
||||
* @param parameters.getSlotProps - A function that returns the props to be passed to the slot component.
|
||||
*/
|
||||
export function useSlotProps(parameters) {
|
||||
var _parameters$additiona;
|
||||
var elementType = parameters.elementType,
|
||||
externalSlotProps = parameters.externalSlotProps,
|
||||
ownerState = parameters.ownerState,
|
||||
_parameters$skipResol = parameters.skipResolvingSlotProps,
|
||||
skipResolvingSlotProps = _parameters$skipResol === void 0 ? false : _parameters$skipResol,
|
||||
rest = _objectWithoutProperties(parameters, ["elementType", "externalSlotProps", "ownerState", "skipResolvingSlotProps"]);
|
||||
var resolvedComponentsProps = skipResolvingSlotProps ? {} : resolveComponentProps(externalSlotProps, ownerState);
|
||||
var _mergeSlotProps = mergeSlotProps(_extends({}, rest, {
|
||||
externalSlotProps: resolvedComponentsProps
|
||||
})),
|
||||
mergedProps = _mergeSlotProps.props,
|
||||
internalRef = _mergeSlotProps.internalRef;
|
||||
var ref = useForkRef(internalRef, resolvedComponentsProps == null ? void 0 : resolvedComponentsProps.ref, (_parameters$additiona = parameters.additionalProps) == null ? void 0 : _parameters$additiona.ref);
|
||||
var props = appendOwnerState(elementType, _extends({}, mergedProps, {
|
||||
ref: ref
|
||||
}), ownerState);
|
||||
return props;
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
'use client';
|
||||
|
||||
import * as React from 'react';
|
||||
var TEXT_NAVIGATION_RESET_TIMEOUT = 500; // milliseconds
|
||||
|
||||
/**
|
||||
* @ignore - internal hook.
|
||||
*
|
||||
* Provides a handler for text navigation.
|
||||
* It's used to navigate a list by typing the first letters of the options.
|
||||
*
|
||||
* @param callback A function to be called when the navigation should be performed.
|
||||
* @returns A function to be used in a keydown event handler.
|
||||
*/
|
||||
export function useTextNavigation(callback) {
|
||||
var textCriteriaRef = React.useRef({
|
||||
searchString: '',
|
||||
lastTime: null
|
||||
});
|
||||
return React.useCallback(function (event) {
|
||||
if (event.key.length === 1 && event.key !== ' ') {
|
||||
var textCriteria = textCriteriaRef.current;
|
||||
var lowerKey = event.key.toLowerCase();
|
||||
var currentTime = performance.now();
|
||||
if (textCriteria.searchString.length > 0 && textCriteria.lastTime && currentTime - textCriteria.lastTime > TEXT_NAVIGATION_RESET_TIMEOUT) {
|
||||
textCriteria.searchString = lowerKey;
|
||||
} else if (textCriteria.searchString.length !== 1 || lowerKey !== textCriteria.searchString) {
|
||||
// If there is just one character in the buffer and the key is the same, do not append
|
||||
textCriteria.searchString += lowerKey;
|
||||
}
|
||||
textCriteria.lastTime = currentTime;
|
||||
callback(textCriteria.searchString, event);
|
||||
}
|
||||
}, [callback]);
|
||||
}
|
||||
Reference in new issue
Block a user