pre-installations and preparations
This commit is contained in:
1 parent
3e5a0329cb
commit
201d621ac3
6977 files changed
+742826
No files matched your search
+14
@@ -0,0 +1,14 @@
|
||||
import { OptionType } from './Option.types';
|
||||
/**
|
||||
* An unstyled option to be used within a Select.
|
||||
*
|
||||
* Demos:
|
||||
*
|
||||
* - [Select](https://mui.com/base-ui/react-select/)
|
||||
*
|
||||
* API:
|
||||
*
|
||||
* - [Option API](https://mui.com/base-ui/react-select/components-api/#option)
|
||||
*/
|
||||
declare const Option: OptionType;
|
||||
export { Option };
|
||||
+149
@@ -0,0 +1,149 @@
|
||||
'use client';
|
||||
|
||||
import _extends from "@babel/runtime/helpers/esm/extends";
|
||||
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
||||
const _excluded = ["children", "disabled", "label", "slotProps", "slots", "value"];
|
||||
import * as React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { unstable_useForkRef as useForkRef } from '@mui/utils';
|
||||
import { unstable_composeClasses as composeClasses } from '../composeClasses';
|
||||
import { getOptionUtilityClass } from './optionClasses';
|
||||
import { useSlotProps } from '../utils';
|
||||
import { useOption, useOptionContextStabilizer } from '../useOption';
|
||||
import { useClassNamesOverride } from '../utils/ClassNameConfigurator';
|
||||
import { ListContext } from '../useList';
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
function useUtilityClasses(ownerState) {
|
||||
const {
|
||||
disabled,
|
||||
highlighted,
|
||||
selected
|
||||
} = ownerState;
|
||||
const slots = {
|
||||
root: ['root', disabled && 'disabled', highlighted && 'highlighted', selected && 'selected']
|
||||
};
|
||||
return composeClasses(slots, useClassNamesOverride(getOptionUtilityClass));
|
||||
}
|
||||
const InnerOption = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef(function Option(props, forwardedRef) {
|
||||
var _slots$root, _optionRef$current;
|
||||
const {
|
||||
children,
|
||||
disabled = false,
|
||||
label,
|
||||
slotProps = {},
|
||||
slots = {},
|
||||
value
|
||||
} = props,
|
||||
other = _objectWithoutPropertiesLoose(props, _excluded);
|
||||
const Root = (_slots$root = slots.root) != null ? _slots$root : 'li';
|
||||
const optionRef = React.useRef(null);
|
||||
const combinedRef = useForkRef(optionRef, forwardedRef);
|
||||
|
||||
// If `label` is not explicitly provided, the `children` are used for convenience.
|
||||
// This is used to populate the select's trigger with the selected option's label.
|
||||
const computedLabel = label != null ? label : typeof children === 'string' ? children : (_optionRef$current = optionRef.current) == null || (_optionRef$current = _optionRef$current.textContent) == null ? void 0 : _optionRef$current.trim();
|
||||
const {
|
||||
getRootProps,
|
||||
selected,
|
||||
highlighted,
|
||||
index
|
||||
} = useOption({
|
||||
disabled,
|
||||
label: computedLabel,
|
||||
rootRef: combinedRef,
|
||||
value
|
||||
});
|
||||
const ownerState = _extends({}, props, {
|
||||
disabled,
|
||||
highlighted,
|
||||
index,
|
||||
selected
|
||||
});
|
||||
const classes = useUtilityClasses(ownerState);
|
||||
const rootProps = useSlotProps({
|
||||
getSlotProps: getRootProps,
|
||||
elementType: Root,
|
||||
externalSlotProps: slotProps.root,
|
||||
externalForwardedProps: other,
|
||||
className: classes.root,
|
||||
ownerState
|
||||
});
|
||||
return /*#__PURE__*/_jsx(Root, _extends({}, rootProps, {
|
||||
children: children
|
||||
}));
|
||||
}));
|
||||
|
||||
/**
|
||||
* An unstyled option to be used within a Select.
|
||||
*
|
||||
* Demos:
|
||||
*
|
||||
* - [Select](https://mui.com/base-ui/react-select/)
|
||||
*
|
||||
* API:
|
||||
*
|
||||
* - [Option API](https://mui.com/base-ui/react-select/components-api/#option)
|
||||
*/
|
||||
const Option = /*#__PURE__*/React.forwardRef(function Option(props, ref) {
|
||||
const {
|
||||
value
|
||||
} = props;
|
||||
|
||||
// This wrapper component is used as a performance optimization.
|
||||
// `useOptionContextStabilizer` ensures that the context value
|
||||
// is stable across renders, so that the actual Option re-renders
|
||||
// only when it needs to.
|
||||
const {
|
||||
contextValue
|
||||
} = useOptionContextStabilizer(value);
|
||||
return /*#__PURE__*/_jsx(ListContext.Provider, {
|
||||
value: contextValue,
|
||||
children: /*#__PURE__*/_jsx(InnerOption, _extends({}, props, {
|
||||
ref: ref
|
||||
}))
|
||||
});
|
||||
});
|
||||
process.env.NODE_ENV !== "production" ? Option.propTypes /* remove-proptypes */ = {
|
||||
// ┌────────────────────────────── Warning ──────────────────────────────┐
|
||||
// │ These PropTypes are generated from the TypeScript type definitions. │
|
||||
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
|
||||
// └─────────────────────────────────────────────────────────────────────┘
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
children: PropTypes.node,
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
className: PropTypes.string,
|
||||
/**
|
||||
* If `true`, the option will be disabled.
|
||||
* @default false
|
||||
*/
|
||||
disabled: PropTypes.bool,
|
||||
/**
|
||||
* A text representation of the option's content.
|
||||
* Used for keyboard text navigation matching.
|
||||
*/
|
||||
label: PropTypes.string,
|
||||
/**
|
||||
* The props used for each slot inside the Option.
|
||||
* @default {}
|
||||
*/
|
||||
slotProps: PropTypes.shape({
|
||||
root: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
|
||||
}),
|
||||
/**
|
||||
* The components used for each slot inside the Option.
|
||||
* Either a string to use a HTML element or a component.
|
||||
* @default {}
|
||||
*/
|
||||
slots: PropTypes.shape({
|
||||
root: PropTypes.elementType
|
||||
}),
|
||||
/**
|
||||
* The value of the option.
|
||||
*/
|
||||
value: PropTypes.any.isRequired
|
||||
} : void 0;
|
||||
export { Option };
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
import * as React from 'react';
|
||||
import { Simplify } from '@mui/types';
|
||||
import { UseOptionRootSlotProps } from '../useOption';
|
||||
import { PolymorphicProps, SlotComponentProps } from '../utils';
|
||||
export interface OptionRootSlotPropsOverrides {
|
||||
}
|
||||
export interface OptionOwnProps<OptionValue> {
|
||||
/**
|
||||
* The value of the option.
|
||||
*/
|
||||
value: OptionValue;
|
||||
children?: React.ReactNode;
|
||||
/**
|
||||
* If `true`, the option will be disabled.
|
||||
* @default false
|
||||
*/
|
||||
disabled?: boolean;
|
||||
className?: string;
|
||||
/**
|
||||
* The props used for each slot inside the Option.
|
||||
* @default {}
|
||||
*/
|
||||
slotProps?: {
|
||||
root?: SlotComponentProps<'li', OptionRootSlotPropsOverrides, OptionOwnerState<OptionValue>>;
|
||||
};
|
||||
/**
|
||||
* The components used for each slot inside the Option.
|
||||
* Either a string to use a HTML element or a component.
|
||||
* @default {}
|
||||
*/
|
||||
slots?: OptionSlots;
|
||||
/**
|
||||
* A text representation of the option's content.
|
||||
* Used for keyboard text navigation matching.
|
||||
*/
|
||||
label?: string;
|
||||
}
|
||||
export interface OptionSlots {
|
||||
/**
|
||||
* The component that renders the root.
|
||||
* @default 'li'
|
||||
*/
|
||||
root?: React.ElementType;
|
||||
}
|
||||
export interface OptionTypeMap<OptionValue, AdditionalProps = {}, RootComponentType extends React.ElementType = 'li'> {
|
||||
props: OptionOwnProps<OptionValue> & AdditionalProps;
|
||||
defaultComponent: RootComponentType;
|
||||
}
|
||||
export type OptionProps<OptionValue, RootComponentType extends React.ElementType = OptionTypeMap<OptionValue>['defaultComponent']> = PolymorphicProps<OptionTypeMap<OptionValue, {}, RootComponentType>, RootComponentType>;
|
||||
export interface OptionType {
|
||||
<OptionValue, RootComponentType extends React.ElementType = OptionTypeMap<OptionValue>['defaultComponent']>(props: PolymorphicProps<OptionTypeMap<OptionValue>, RootComponentType>): JSX.Element | null;
|
||||
propTypes?: any;
|
||||
displayName?: string | undefined;
|
||||
}
|
||||
export type OptionOwnerState<OptionValue> = Simplify<OptionOwnProps<OptionValue> & {
|
||||
selected: boolean;
|
||||
highlighted: boolean;
|
||||
index: number;
|
||||
}>;
|
||||
export type OptionRootSlotProps<OptionValue> = Simplify<UseOptionRootSlotProps & {
|
||||
children?: React.ReactNode;
|
||||
className: string;
|
||||
ref: React.Ref<HTMLElement>;
|
||||
ownerState: OptionOwnerState<OptionValue>;
|
||||
}>;
|
||||
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
export * from './Option';
|
||||
export * from './Option.types';
|
||||
export * from './optionClasses';
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
'use client';
|
||||
|
||||
export * from './Option';
|
||||
export * from './Option.types';
|
||||
export * from './optionClasses';
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
export interface OptionClasses {
|
||||
/** Class name applied to the root element. */
|
||||
root: string;
|
||||
/** State class applied to the root `li` element if `disabled={true}`. */
|
||||
disabled: string;
|
||||
/** State class applied to the root `li` element if `selected={true}`. */
|
||||
selected: string;
|
||||
/** State class applied to the root `li` element if `highlighted={true}`. */
|
||||
highlighted: string;
|
||||
}
|
||||
export type OptionClassKey = keyof OptionClasses;
|
||||
export declare function getOptionUtilityClass(slot: string): string;
|
||||
export declare const optionClasses: OptionClasses;
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import { generateUtilityClass } from '../generateUtilityClass';
|
||||
import { generateUtilityClasses } from '../generateUtilityClasses';
|
||||
const COMPONENT_NAME = 'Option';
|
||||
export function getOptionUtilityClass(slot) {
|
||||
return generateUtilityClass(COMPONENT_NAME, slot);
|
||||
}
|
||||
export const optionClasses = generateUtilityClasses(COMPONENT_NAME, ['root', 'disabled', 'selected', 'highlighted']);
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"module": "./index.js",
|
||||
"main": "../node/Option/index.js",
|
||||
"types": "./index.d.ts"
|
||||
}
|
||||
Reference in new issue
Block a user