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 { SelectType } from './Select.types';
/**
* The foundation for building custom-styled select components.
*
* Demos:
*
* - [Select](https://mui.com/base-ui/react-select/)
*
* API:
*
* - [Select API](https://mui.com/base-ui/react-select/components-api/#select)
*/
declare const Select: SelectType;
export { Select };
+326
View File
@@ -0,0 +1,326 @@
'use client';
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
var _span;
const _excluded = ["areOptionsEqual", "autoComplete", "autoFocus", "children", "defaultValue", "defaultListboxOpen", "disabled", "getSerializedValue", "listboxId", "listboxOpen", "multiple", "name", "required", "onChange", "onListboxOpenChange", "getOptionAsString", "renderValue", "placeholder", "slotProps", "slots", "value"];
import * as React from 'react';
import PropTypes from 'prop-types';
import { unstable_useForkRef as useForkRef } from '@mui/utils';
import { useSelect } from '../useSelect';
import { useSlotProps } from '../utils';
import { Popup } from '../Unstable_Popup/Popup';
import { unstable_composeClasses as composeClasses } from '../composeClasses';
import { getSelectUtilityClass } from './selectClasses';
import { defaultOptionStringifier } from '../useSelect/defaultOptionStringifier';
import { useClassNamesOverride } from '../utils/ClassNameConfigurator';
import { SelectProvider } from '../useSelect/SelectProvider';
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
function defaultRenderValue(selectedOptions) {
var _selectedOptions$labe;
if (Array.isArray(selectedOptions)) {
return /*#__PURE__*/_jsx(React.Fragment, {
children: selectedOptions.map(o => o.label).join(', ')
});
}
return (_selectedOptions$labe = selectedOptions == null ? void 0 : selectedOptions.label) != null ? _selectedOptions$labe : null;
}
function useUtilityClasses(ownerState) {
const {
active,
disabled,
open,
focusVisible
} = ownerState;
const slots = {
root: ['root', disabled && 'disabled', focusVisible && 'focusVisible', active && 'active', open && 'expanded'],
listbox: ['listbox', disabled && 'disabled'],
popup: ['popup']
};
return composeClasses(slots, useClassNamesOverride(getSelectUtilityClass));
}
/**
* The foundation for building custom-styled select components.
*
* Demos:
*
* - [Select](https://mui.com/base-ui/react-select/)
*
* API:
*
* - [Select API](https://mui.com/base-ui/react-select/components-api/#select)
*/
const Select = /*#__PURE__*/React.forwardRef(function Select(props, forwardedRef) {
var _slots$root, _slots$listbox, _slots$popup, _ref, _renderValue;
const {
areOptionsEqual,
autoComplete,
autoFocus,
children,
defaultValue,
defaultListboxOpen = false,
disabled: disabledProp,
getSerializedValue,
listboxId,
listboxOpen: listboxOpenProp,
multiple = false,
name,
required = false,
onChange,
onListboxOpenChange,
getOptionAsString = defaultOptionStringifier,
renderValue: renderValueProp,
placeholder,
slotProps = {},
slots = {},
value: valueProp
} = props,
other = _objectWithoutPropertiesLoose(props, _excluded);
const renderValue = renderValueProp != null ? renderValueProp : defaultRenderValue;
const [buttonDefined, setButtonDefined] = React.useState(false);
const buttonRef = React.useRef(null);
const listboxRef = React.useRef(null);
const Button = (_slots$root = slots.root) != null ? _slots$root : 'button';
const ListboxRoot = (_slots$listbox = slots.listbox) != null ? _slots$listbox : 'ul';
const PopupComponent = (_slots$popup = slots.popup) != null ? _slots$popup : 'div';
const handleButtonRefChange = React.useCallback(element => {
setButtonDefined(element != null);
}, []);
const handleButtonRef = useForkRef(forwardedRef, buttonRef, handleButtonRefChange);
React.useEffect(() => {
if (autoFocus) {
buttonRef.current.focus();
}
}, [autoFocus]);
const {
buttonActive,
buttonFocusVisible,
contextValue,
disabled,
getButtonProps,
getListboxProps,
getHiddenInputProps,
getOptionMetadata,
value,
open
} = useSelect({
name,
required,
getSerializedValue,
areOptionsEqual,
buttonRef: handleButtonRef,
defaultOpen: defaultListboxOpen,
defaultValue,
disabled: disabledProp,
listboxId,
multiple,
open: listboxOpenProp,
onChange,
onOpenChange: onListboxOpenChange,
getOptionAsString,
value: valueProp,
componentName: 'Select'
});
const ownerState = _extends({}, props, {
active: buttonActive,
defaultListboxOpen,
disabled,
focusVisible: buttonFocusVisible,
open,
multiple,
renderValue,
value
});
const classes = useUtilityClasses(ownerState);
const buttonProps = useSlotProps({
elementType: Button,
getSlotProps: getButtonProps,
externalSlotProps: slotProps.root,
externalForwardedProps: other,
ownerState,
className: classes.root
});
const listboxProps = useSlotProps({
elementType: ListboxRoot,
getSlotProps: getListboxProps,
externalSlotProps: slotProps.listbox,
additionalProps: {
ref: listboxRef
},
ownerState,
className: classes.listbox
});
const popupProps = useSlotProps({
elementType: PopupComponent,
externalSlotProps: slotProps.popup,
additionalProps: {
anchor: buttonRef.current,
keepMounted: true,
open,
placement: 'bottom-start',
role: undefined
},
ownerState,
className: classes.popup
});
let selectedOptionsMetadata;
if (multiple) {
selectedOptionsMetadata = value.map(v => getOptionMetadata(v)).filter(o => o !== undefined);
} else {
var _getOptionMetadata;
selectedOptionsMetadata = (_getOptionMetadata = getOptionMetadata(value)) != null ? _getOptionMetadata : null;
}
return /*#__PURE__*/_jsxs(React.Fragment, {
children: [/*#__PURE__*/_jsx(Button, _extends({}, buttonProps, {
children: (_ref = (_renderValue = renderValue(selectedOptionsMetadata)) != null ? _renderValue : placeholder) != null ? _ref : // fall back to a zero-width space to prevent layout shift
// from https://github.com/mui/material-ui/pull/24563
_span || (_span = /*#__PURE__*/_jsx("span", {
className: "notranslate",
children: "\u200B"
}))
})), buttonDefined && /*#__PURE__*/_jsx(Popup, _extends({
slots: {
root: PopupComponent
}
}, popupProps, {
children: /*#__PURE__*/_jsx(ListboxRoot, _extends({}, listboxProps, {
children: /*#__PURE__*/_jsx(SelectProvider, {
value: contextValue,
children: children
})
}))
})), /*#__PURE__*/_jsx("input", _extends({}, getHiddenInputProps(), {
autoComplete: autoComplete
}))]
});
});
process.env.NODE_ENV !== "production" ? Select.propTypes /* remove-proptypes */ = {
// ┌────────────────────────────── Warning ──────────────────────────────┐
// │ These PropTypes are generated from the TypeScript type definitions. │
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
// └─────────────────────────────────────────────────────────────────────┘
/**
* A function used to determine if two options' values are equal.
* By default, reference equality is used.
*
* There is a performance impact when using the `areOptionsEqual` prop (proportional to the number of options).
* Therefore, it's recommented to use the default reference equality comparison whenever possible.
*/
areOptionsEqual: PropTypes.func,
/**
* This prop helps users to fill forms faster, especially on mobile devices.
* The name can be confusing, as it's more like an autofill.
* You can learn more about it [following the specification](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill).
*/
autoComplete: PropTypes.string,
/**
* If `true`, the select element is focused during the first mount
* @default false
*/
autoFocus: PropTypes.bool,
/**
* @ignore
*/
children: PropTypes.node,
/**
* @ignore
*/
className: PropTypes.string,
/**
* If `true`, the select will be initially open.
* @default false
*/
defaultListboxOpen: PropTypes.bool,
/**
* The default selected value. Use when the component is not controlled.
*/
defaultValue: PropTypes.any,
/**
* If `true`, the select is disabled.
* @default false
*/
disabled: PropTypes.bool,
/**
* A function used to convert the option label to a string.
* It's useful when labels are elements and need to be converted to plain text
* to enable navigation using character keys on a keyboard.
*
* @default defaultOptionStringifier
*/
getOptionAsString: PropTypes.func,
/**
* A function to convert the currently selected value to a string.
* Used to set a value of a hidden input associated with the select,
* so that the selected value can be posted with a form.
*/
getSerializedValue: PropTypes.func,
/**
* `id` attribute of the listbox element.
*/
listboxId: PropTypes.string,
/**
* Controls the open state of the select's listbox.
* @default undefined
*/
listboxOpen: PropTypes.bool,
/**
* If `true`, selecting multiple values is allowed.
* This affects the type of the `value`, `defaultValue`, and `onChange` props.
*
* @default false
*/
multiple: PropTypes.bool,
/**
* Name of the element. For example used by the server to identify the fields in form submits.
*/
name: PropTypes.string,
/**
* Callback fired when an option is selected.
*/
onChange: PropTypes.func,
/**
* Callback fired when the component requests to be opened.
* Use in controlled mode (see listboxOpen).
*/
onListboxOpenChange: PropTypes.func,
/**
* Text to show when there is no selected value.
*/
placeholder: PropTypes.node,
/**
* Function that customizes the rendering of the selected value.
*/
renderValue: PropTypes.func,
/**
* If `true`, the Select cannot be empty when submitting form.
* @default false
*/
required: PropTypes.bool,
/**
* The props used for each slot inside the Input.
* @default {}
*/
slotProps: PropTypes /* @typescript-to-proptypes-ignore */.shape({
listbox: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
popup: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
root: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
}),
/**
* The components used for each slot inside the Select.
* Either a string to use a HTML element or a component.
* @default {}
*/
slots: PropTypes /* @typescript-to-proptypes-ignore */.shape({
listbox: PropTypes.elementType,
popup: PropTypes.elementType,
root: PropTypes.elementType
}),
/**
* The selected value.
* Set to `null` to deselect all options.
*/
value: PropTypes.any
} : void 0;
export { Select };
+177
View File
@@ -0,0 +1,177 @@
import * as React from 'react';
import { Simplify } from '@mui/types';
import { SelectValue, UseSelectButtonSlotProps, UseSelectListboxSlotProps } from '../useSelect';
import { SelectOption } from '../useOption';
import { PopupProps } from '../Unstable_Popup';
import { PolymorphicProps, SlotComponentProps } from '../utils';
export interface SelectRootSlotPropsOverrides {
}
export interface SelectListboxSlotPropsOverrides {
}
export interface SelectPopupSlotPropsOverrides {
}
export interface SelectOwnProps<OptionValue extends {}, Multiple extends boolean> {
/**
* A function used to determine if two options' values are equal.
* By default, reference equality is used.
*
* There is a performance impact when using the `areOptionsEqual` prop (proportional to the number of options).
* Therefore, it's recommented to use the default reference equality comparison whenever possible.
*/
areOptionsEqual?: (a: OptionValue, b: OptionValue) => boolean;
/**
* 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 select element is focused during the first mount
* @default false
*/
autoFocus?: boolean;
children?: React.ReactNode;
className?: string;
/**
* If `true`, the select will be initially open.
* @default false
*/
defaultListboxOpen?: boolean;
/**
* The default selected value. Use when the component is not controlled.
*/
defaultValue?: SelectValue<OptionValue, Multiple>;
/**
* If `true`, the select is disabled.
* @default false
*/
disabled?: boolean;
/**
* A function to convert the currently selected value to a string.
* Used to set a value of a hidden input associated with the select,
* so that the selected value can be posted with a form.
*/
getSerializedValue?: (option: SelectValue<SelectOption<OptionValue>, Multiple>) => React.InputHTMLAttributes<HTMLInputElement>['value'];
/**
* `id` attribute of the listbox element.
*/
listboxId?: string;
/**
* Controls the open state of the select's listbox.
* @default undefined
*/
listboxOpen?: boolean;
/**
* If `true`, selecting multiple values is allowed.
* This affects the type of the `value`, `defaultValue`, and `onChange` props.
*
* @default false
*/
multiple?: Multiple;
/**
* Name of the element. For example used by the server to identify the fields in form submits.
*/
name?: string;
/**
* Callback fired when an option is selected.
*/
onChange?: (event: React.MouseEvent | React.KeyboardEvent | React.FocusEvent | null, value: SelectValue<OptionValue, Multiple>) => void;
/**
* Callback fired when the component requests to be opened.
* Use in controlled mode (see listboxOpen).
*/
onListboxOpenChange?: (isOpen: boolean) => void;
/**
* A function used to convert the option label to a string.
* It's useful when labels are elements and need to be converted to plain text
* to enable navigation using character keys on a keyboard.
*
* @default defaultOptionStringifier
*/
getOptionAsString?: (option: SelectOption<OptionValue>) => string;
/**
* Function that customizes the rendering of the selected value.
*/
renderValue?: (option: SelectValue<SelectOption<OptionValue>, Multiple>) => React.ReactNode;
/**
* Text to show when there is no selected value.
*/
placeholder?: React.ReactNode;
/**
* The props used for each slot inside the Input.
* @default {}
*/
slotProps?: {
root?: SlotComponentProps<'button', SelectRootSlotPropsOverrides, SelectOwnerState<OptionValue, Multiple>>;
listbox?: SlotComponentProps<'ul', SelectListboxSlotPropsOverrides, SelectOwnerState<OptionValue, Multiple>>;
popup?: SlotComponentProps<'div', SelectPopupSlotPropsOverrides & PopupProps, SelectOwnerState<OptionValue, Multiple>>;
};
/**
* If `true`, the Select cannot be empty when submitting form.
* @default false
*/
required?: boolean;
/**
* The components used for each slot inside the Select.
* Either a string to use a HTML element or a component.
* @default {}
*/
slots?: SelectSlots;
/**
* The selected value.
* Set to `null` to deselect all options.
*/
value?: SelectValue<OptionValue, Multiple>;
}
export interface SelectSlots {
/**
* The component that renders the root.
* @default 'button'
*/
root?: React.ElementType;
/**
* The component that renders the listbox.
* @default 'ul'
*/
listbox?: React.ElementType;
/**
* The component that wraps the popup.
* @default 'div'
*/
popup?: React.ElementType;
}
export interface SelectTypeMap<OptionValue extends {}, Multiple extends boolean, AdditionalProps = {}, RootComponentType extends React.ElementType = 'button'> {
props: SelectOwnProps<OptionValue, Multiple> & AdditionalProps;
defaultComponent: RootComponentType;
}
export type SelectProps<OptionValue extends {}, Multiple extends boolean, RootComponentType extends React.ElementType = SelectTypeMap<OptionValue, Multiple>['defaultComponent']> = PolymorphicProps<SelectTypeMap<OptionValue, Multiple, {}, RootComponentType>, RootComponentType>;
export interface SelectType {
<OptionValue extends {}, Multiple extends boolean = false, RootComponentType extends React.ElementType = SelectTypeMap<OptionValue, Multiple>['defaultComponent']>(props: PolymorphicProps<SelectTypeMap<OptionValue, Multiple>, RootComponentType>): JSX.Element | null;
propTypes?: any;
displayName?: string | undefined;
}
export type SelectOwnerState<OptionValue extends {}, Multiple extends boolean> = Simplify<SelectOwnProps<OptionValue, Multiple> & {
active: boolean;
disabled: boolean;
focusVisible: boolean;
open: boolean;
}>;
export type SelectRootSlotProps<OptionValue extends {}, Multiple extends boolean> = Simplify<UseSelectButtonSlotProps & {
className?: string;
children?: React.ReactNode;
ownerState: SelectOwnerState<OptionValue, Multiple>;
}>;
export type SelectListboxSlotProps<OptionValue extends {}, Multiple extends boolean> = Simplify<UseSelectListboxSlotProps & {
className?: string;
children?: React.ReactNode;
ownerState: SelectOwnerState<OptionValue, Multiple>;
}>;
export type SelectPopupSlotProps<OptionValue extends {}, Multiple extends boolean> = {
anchor: PopupProps['anchor'];
children?: React.ReactNode;
className?: string;
keepMounted: PopupProps['keepMounted'];
open: PopupProps['open'];
ownerState: SelectOwnerState<OptionValue, Multiple>;
placement: PopupProps['placement'];
};
+1
View File
@@ -0,0 +1 @@
export {};
+3
View File
@@ -0,0 +1,3 @@
export { Select } from './Select';
export * from './selectClasses';
export * from './Select.types';
+5
View File
@@ -0,0 +1,5 @@
'use client';
export { Select } from './Select';
export * from './selectClasses';
export * from './Select.types';
+6
View File
@@ -0,0 +1,6 @@
{
"sideEffects": false,
"module": "./index.js",
"main": "../node/Select/index.js",
"types": "./index.d.ts"
}
+19
View File
@@ -0,0 +1,19 @@
export interface SelectClasses {
/** Class name applied to the root element. */
root: string;
/** Class name applied to the listbox element. */
listbox: string;
/** Class name applied to the popper element. */
popup: string;
/** State class applied to the root `button` element if `active={true}`. */
active: string;
/** State class applied to the root `button` element if `expanded={true}`. */
expanded: string;
/** State class applied to the root `button` element and the listbox 'ul' element if `disabled={true}`. */
disabled: string;
/** State class applied to the root `button` element if `focusVisible={true}`. */
focusVisible: string;
}
export type SelectClassKey = keyof SelectClasses;
export declare function getSelectUtilityClass(slot: string): string;
export declare const selectClasses: SelectClasses;
+7
View File
@@ -0,0 +1,7 @@
import { generateUtilityClass } from '../generateUtilityClass';
import { generateUtilityClasses } from '../generateUtilityClasses';
const COMPONENT_NAME = 'Select';
export function getSelectUtilityClass(slot) {
return generateUtilityClass(COMPONENT_NAME, slot);
}
export const selectClasses = generateUtilityClasses(COMPONENT_NAME, ['root', 'button', 'listbox', 'popup', 'active', 'expanded', 'disabled', 'focusVisible']);