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

+15
View File
@@ -0,0 +1,15 @@
import { PolymorphicComponent } from '../utils/PolymorphicComponent';
import { SwitchTypeMap } from './Switch.types';
/**
* The foundation for building custom-styled switches.
*
* Demos:
*
* - [Switch](https://mui.com/base-ui/react-switch/)
*
* API:
*
* - [Switch API](https://mui.com/base-ui/react-switch/components-api/#switch)
*/
declare const Switch: PolymorphicComponent<SwitchTypeMap<{}, "span">>;
export { Switch };
+171
View File
@@ -0,0 +1,171 @@
'use client';
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
const _excluded = ["checked", "defaultChecked", "disabled", "onBlur", "onChange", "onFocus", "onFocusVisible", "readOnly", "required", "slotProps", "slots"];
import * as React from 'react';
import PropTypes from 'prop-types';
import { unstable_composeClasses as composeClasses } from '../composeClasses';
import { useSwitch } from '../useSwitch';
import { useSlotProps } from '../utils';
import { useClassNamesOverride } from '../utils/ClassNameConfigurator';
import { getSwitchUtilityClass } from './switchClasses';
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
const useUtilityClasses = ownerState => {
const {
checked,
disabled,
focusVisible,
readOnly
} = ownerState;
const slots = {
root: ['root', checked && 'checked', disabled && 'disabled', focusVisible && 'focusVisible', readOnly && 'readOnly'],
thumb: ['thumb'],
input: ['input'],
track: ['track']
};
return composeClasses(slots, useClassNamesOverride(getSwitchUtilityClass));
};
/**
* The foundation for building custom-styled switches.
*
* Demos:
*
* - [Switch](https://mui.com/base-ui/react-switch/)
*
* API:
*
* - [Switch API](https://mui.com/base-ui/react-switch/components-api/#switch)
*/
const Switch = /*#__PURE__*/React.forwardRef(function Switch(props, forwardedRef) {
var _slots$root, _slots$thumb, _slots$input, _slots$track;
const {
slotProps = {},
slots = {}
} = props,
other = _objectWithoutPropertiesLoose(props, _excluded);
const {
getInputProps,
checked,
disabled,
focusVisible,
readOnly
} = useSwitch(props);
const ownerState = _extends({}, props, {
checked,
disabled,
focusVisible,
readOnly
});
const classes = useUtilityClasses(ownerState);
const Root = (_slots$root = slots.root) != null ? _slots$root : 'span';
const rootProps = useSlotProps({
elementType: Root,
externalSlotProps: slotProps.root,
externalForwardedProps: other,
additionalProps: {
ref: forwardedRef
},
ownerState,
className: classes.root
});
const Thumb = (_slots$thumb = slots.thumb) != null ? _slots$thumb : 'span';
const thumbProps = useSlotProps({
elementType: Thumb,
externalSlotProps: slotProps.thumb,
ownerState,
className: classes.thumb
});
const Input = (_slots$input = slots.input) != null ? _slots$input : 'input';
const inputProps = useSlotProps({
elementType: Input,
getSlotProps: getInputProps,
externalSlotProps: slotProps.input,
ownerState,
className: classes.input
});
const Track = slots.track === null ? () => null : (_slots$track = slots.track) != null ? _slots$track : 'span';
const trackProps = useSlotProps({
elementType: Track,
externalSlotProps: slotProps.track,
ownerState,
className: classes.track
});
return /*#__PURE__*/_jsxs(Root, _extends({}, rootProps, {
children: [/*#__PURE__*/_jsx(Track, _extends({}, trackProps)), /*#__PURE__*/_jsx(Thumb, _extends({}, thumbProps)), /*#__PURE__*/_jsx(Input, _extends({}, inputProps))]
}));
});
process.env.NODE_ENV !== "production" ? Switch.propTypes /* remove-proptypes */ = {
// ┌────────────────────────────── Warning ──────────────────────────────┐
// │ These PropTypes are generated from the TypeScript type definitions. │
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
// └─────────────────────────────────────────────────────────────────────┘
/**
* If `true`, the component is checked.
*/
checked: PropTypes.bool,
/**
* Class name applied to the root element.
*/
className: PropTypes.string,
/**
* The default checked state. Use when the component is not controlled.
*/
defaultChecked: PropTypes.bool,
/**
* If `true`, the component is disabled.
*/
disabled: PropTypes.bool,
/**
* @ignore
*/
onBlur: PropTypes.func,
/**
* Callback fired when the state is changed.
*
* @param {React.ChangeEvent<HTMLInputElement>} event The event source of the callback.
* You can pull out the new value by accessing `event.target.value` (string).
* You can pull out the new checked state by accessing `event.target.checked` (boolean).
*/
onChange: PropTypes.func,
/**
* @ignore
*/
onFocus: PropTypes.func,
/**
* @ignore
*/
onFocusVisible: PropTypes.func,
/**
* If `true`, the component is read only.
*/
readOnly: PropTypes.bool,
/**
* If `true`, the `input` element is required.
*/
required: PropTypes.bool,
/**
* The props used for each slot inside the Switch.
* @default {}
*/
slotProps: PropTypes.shape({
input: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
root: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
thumb: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
track: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
}),
/**
* The components used for each slot inside the Switch.
* Either a string to use a HTML element or a component.
* @default {}
*/
slots: PropTypes /* @typescript-to-proptypes-ignore */.shape({
input: PropTypes.elementType,
root: PropTypes.elementType,
thumb: PropTypes.elementType,
track: PropTypes.oneOfType([PropTypes.elementType, PropTypes.oneOf([null])])
})
} : void 0;
export { Switch };
+87
View File
@@ -0,0 +1,87 @@
/// <reference types="react" />
import { Simplify } from '@mui/types';
import { PolymorphicProps, SlotComponentProps } from '../utils';
import { UseSwitchInputSlotProps, UseSwitchParameters } from '../useSwitch';
export interface SwitchRootSlotPropsOverrides {
}
export interface SwitchThumbSlotPropsOverrides {
}
export interface SwitchInputSlotPropsOverrides {
}
export interface SwitchTrackSlotPropsOverrides {
}
export interface SwitchOwnProps extends UseSwitchParameters {
/**
* Class name applied to the root element.
*/
className?: string;
/**
* The components used for each slot inside the Switch.
* Either a string to use a HTML element or a component.
* @default {}
*/
slots?: SwitchSlots;
/**
* The props used for each slot inside the Switch.
* @default {}
*/
slotProps?: {
root?: SlotComponentProps<'span', SwitchRootSlotPropsOverrides, SwitchOwnerState>;
thumb?: SlotComponentProps<'span', SwitchThumbSlotPropsOverrides, SwitchOwnerState>;
input?: SlotComponentProps<'input', SwitchInputSlotPropsOverrides, SwitchOwnerState>;
track?: SlotComponentProps<'span', SwitchTrackSlotPropsOverrides, SwitchOwnerState>;
};
}
export interface SwitchSlots {
/**
* The component that renders the root.
* @default 'span'
*/
root?: React.ElementType;
/**
* The component that renders the input.
* @default 'input'
*/
input?: React.ElementType;
/**
* The component that renders the thumb.
* @default 'span'
*/
thumb?: React.ElementType;
/**
* The component that renders the track.
* @default 'span'
*/
track?: React.ElementType | null;
}
export interface SwitchTypeMap<AdditionalProps = {}, RootComponentType extends React.ElementType = 'span'> {
props: SwitchOwnProps & AdditionalProps;
defaultComponent: RootComponentType;
}
export type SwitchProps<RootComponentType extends React.ElementType = SwitchTypeMap['defaultComponent']> = PolymorphicProps<SwitchTypeMap<{}, RootComponentType>, RootComponentType>;
export type SwitchOwnerState = Simplify<SwitchOwnProps & {
checked: boolean;
disabled: boolean;
focusVisible: boolean;
readOnly: boolean;
}>;
export type SwitchRootSlotProps = {
ownerState: SwitchOwnerState;
className?: string;
children?: React.ReactNode;
};
export type SwitchThumbSlotProps = {
ownerState: SwitchOwnerState;
className?: string;
children?: React.ReactNode;
};
export type SwitchTrackSlotProps = {
ownerState: SwitchOwnerState;
className?: string;
children?: React.ReactNode;
};
export type SwitchInputSlotProps = Simplify<UseSwitchInputSlotProps & {
ownerState: SwitchOwnerState;
className?: string;
children?: React.ReactNode;
}>;
+1
View File
@@ -0,0 +1 @@
export {};
+3
View File
@@ -0,0 +1,3 @@
export { Switch } from './Switch';
export * from './Switch.types';
export * from './switchClasses';
+5
View File
@@ -0,0 +1,5 @@
'use client';
export { Switch } from './Switch';
export * from './Switch.types';
export * from './switchClasses';
+6
View File
@@ -0,0 +1,6 @@
{
"sideEffects": false,
"module": "./index.js",
"main": "../node/Switch/index.js",
"types": "./index.d.ts"
}
+21
View File
@@ -0,0 +1,21 @@
export interface SwitchClasses {
/** Class applied to the root element. */
root: string;
/** Class applied to the internal input element */
input: string;
/** Class applied to the track element */
track: string;
/** Class applied to the thumb element */
thumb: string;
/** State class applied to the root element if the switch is checked */
checked: string;
/** State class applied to the root element if the switch is disabled */
disabled: string;
/** State class applied to the root element if the switch has visible focus */
focusVisible: string;
/** Class applied to the root element if the switch is read-only */
readOnly: string;
}
export type SwitchClassKey = keyof SwitchClasses;
export declare function getSwitchUtilityClass(slot: string): string;
export declare const switchClasses: SwitchClasses;
+7
View File
@@ -0,0 +1,7 @@
import { generateUtilityClass } from '../generateUtilityClass';
import { generateUtilityClasses } from '../generateUtilityClasses';
const COMPONENT_NAME = 'Switch';
export function getSwitchUtilityClass(slot) {
return generateUtilityClass(COMPONENT_NAME, slot);
}
export const switchClasses = generateUtilityClasses(COMPONENT_NAME, ['root', 'input', 'track', 'thumb', 'checked', 'disabled', 'focusVisible', 'readOnly']);