@mui/joy
Version:
Joy UI is an open-source React component library that implements MUI's own design principles. It's comprehensive and can be used in production out of the box.
255 lines (254 loc) • 8.91 kB
JavaScript
'use client';
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
import _extends from "@babel/runtime/helpers/esm/extends";
const _excluded = ["children", "className", "color", "invertedColors", "role", "variant", "size", "startDecorator", "endDecorator", "component", "slots", "slotProps"];
import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import { unstable_composeClasses as composeClasses } from '@mui/base';
import { unstable_capitalize as capitalize } from '@mui/utils';
import { applySolidInversion, applySoftInversion } from '../colorInversion';
import styled from '../styles/styled';
import useThemeProps from '../styles/useThemeProps';
import useSlot from '../utils/useSlot';
import { getAlertUtilityClass } from './alertClasses';
import { resolveSxValue } from '../styles/styleUtils';
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
const useUtilityClasses = ownerState => {
const {
variant,
color,
size
} = ownerState;
const slots = {
root: ['root', size && `size${capitalize(size)}`, color && `color${capitalize(color)}`, variant && `variant${capitalize(variant)}`],
startDecorator: ['startDecorator'],
endDecorator: ['endDecorator']
};
return composeClasses(slots, getAlertUtilityClass, {});
};
const AlertRoot = styled('div', {
name: 'JoyAlert',
slot: 'Root',
overridesResolver: (props, styles) => styles.root
})(({
theme,
ownerState
}) => {
const {
p,
padding,
borderRadius
} = resolveSxValue({
theme,
ownerState
}, ['p', 'padding', 'borderRadius']);
return [_extends({
'--Alert-radius': theme.vars.radius.sm,
'--Alert-decoratorChildRadius': 'max((var(--Alert-radius) - var(--variant-borderWidth, 0px)) - var(--Alert-padding), min(var(--Alert-padding) + var(--variant-borderWidth, 0px), var(--Alert-radius) / 2))',
'--Button-minHeight': 'var(--Alert-decoratorChildHeight)',
'--IconButton-size': 'var(--Alert-decoratorChildHeight)',
'--Button-radius': 'var(--Alert-decoratorChildRadius)',
'--IconButton-radius': 'var(--Alert-decoratorChildRadius)',
'--Icon-color': 'currentColor'
}, ownerState.size === 'sm' && {
'--Alert-padding': '0.5rem',
'--Alert-decoratorChildHeight': '1.5rem',
'--Icon-fontSize': theme.vars.fontSize.xl,
gap: '0.5rem'
}, ownerState.size === 'md' && {
'--Alert-padding': '0.75rem',
'--Alert-decoratorChildHeight': '2rem',
'--Icon-fontSize': theme.vars.fontSize.xl,
gap: '0.625rem'
}, ownerState.size === 'lg' && {
'--Alert-padding': '1rem',
'--Alert-decoratorChildHeight': '2.375rem',
'--Icon-fontSize': theme.vars.fontSize.xl2,
gap: '0.875rem'
}, {
backgroundColor: theme.vars.palette.background.surface,
display: 'flex',
position: 'relative',
alignItems: 'center',
padding: `var(--Alert-padding)`,
borderRadius: 'var(--Alert-radius)'
}, theme.typography[`body-${{
sm: 'xs',
md: 'sm',
lg: 'md'
}[ownerState.size]}`], {
fontWeight: theme.vars.fontWeight.md
}, ownerState.variant === 'solid' && ownerState.color && ownerState.invertedColors && applySolidInversion(ownerState.color)(theme), ownerState.variant === 'soft' && ownerState.color && ownerState.invertedColors && applySoftInversion(ownerState.color)(theme), theme.variants[ownerState.variant]?.[ownerState.color]), p !== undefined && {
'--Alert-padding': p
}, padding !== undefined && {
'--Alert-padding': padding
}, borderRadius !== undefined && {
'--Alert-radius': borderRadius
}];
});
const AlertStartDecorator = styled('span', {
name: 'JoyAlert',
slot: 'StartDecorator',
overridesResolver: (props, styles) => styles.startDecorator
})({
display: 'inherit',
flex: 'none'
});
const AlertEndDecorator = styled('span', {
name: 'JoyAlert',
slot: 'EndDecorator',
overridesResolver: (props, styles) => styles.endDecorator
})({
display: 'inherit',
flex: 'none',
marginLeft: 'auto'
});
/**
*
* Demos:
*
* - [Alert](https://mui.com/joy-ui/react-alert/)
*
* API:
*
* - [Alert API](https://mui.com/joy-ui/api/alert/)
*/
const Alert = /*#__PURE__*/React.forwardRef(function Alert(inProps, ref) {
const props = useThemeProps({
props: inProps,
name: 'JoyAlert'
});
const {
children,
className,
color = 'neutral',
invertedColors = false,
role = 'alert',
variant = 'soft',
size = 'md',
startDecorator,
endDecorator,
component,
slots = {},
slotProps = {}
} = props,
other = _objectWithoutPropertiesLoose(props, _excluded);
const ownerState = _extends({}, props, {
color,
invertedColors,
variant,
size
});
const classes = useUtilityClasses(ownerState);
const externalForwardedProps = _extends({}, other, {
component,
slots,
slotProps
});
const [SlotRoot, rootProps] = useSlot('root', {
ref,
className: clsx(classes.root, className),
elementType: AlertRoot,
externalForwardedProps,
ownerState,
additionalProps: {
role
}
});
const [SlotStartDecorator, startDecoratorProps] = useSlot('startDecorator', {
className: classes.startDecorator,
elementType: AlertStartDecorator,
externalForwardedProps,
ownerState
});
const [SlotEndDecorator, endDecoratorProps] = useSlot('endDecorator', {
className: classes.endDecorator,
elementType: AlertEndDecorator,
externalForwardedProps,
ownerState
});
return /*#__PURE__*/_jsxs(SlotRoot, _extends({}, rootProps, {
children: [startDecorator && /*#__PURE__*/_jsx(SlotStartDecorator, _extends({}, startDecoratorProps, {
children: startDecorator
})), children, endDecorator && /*#__PURE__*/_jsx(SlotEndDecorator, _extends({}, endDecoratorProps, {
children: endDecorator
}))]
}));
});
process.env.NODE_ENV !== "production" ? Alert.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,
/**
* The color of the component. It supports those theme colors that make sense for this component.
* @default 'neutral'
*/
color: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.oneOf(['danger', 'neutral', 'primary', 'success', 'warning']), PropTypes.string]),
/**
* The component used for the root node.
* Either a string to use a HTML element or a component.
*/
component: PropTypes.elementType,
/**
* Element placed after the children.
*/
endDecorator: PropTypes.node,
/**
* If `true`, the children with an implicit color prop invert their colors to match the component's variant and color.
* @default false
*/
invertedColors: PropTypes.bool,
/**
* The ARIA role attribute of the element.
* @default 'alert'
*/
role: PropTypes.string,
/**
* The size of the component.
* @default 'md'
*/
size: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.oneOf(['sm', 'md', 'lg']), PropTypes.string]),
/**
* The props used for each slot inside.
* @default {}
*/
slotProps: PropTypes.shape({
endDecorator: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
root: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
startDecorator: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
}),
/**
* The components used for each slot inside.
* @default {}
*/
slots: PropTypes.shape({
endDecorator: PropTypes.elementType,
root: PropTypes.elementType,
startDecorator: PropTypes.elementType
}),
/**
* Element placed before the children.
*/
startDecorator: PropTypes.node,
/**
* The system prop that allows defining system overrides as well as additional CSS styles.
*/
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
/**
* The [global variant](https://mui.com/joy-ui/main-features/global-variants/) to use.
* @default 'soft'
*/
variant: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.oneOf(['outlined', 'plain', 'soft', 'solid']), PropTypes.string])
} : void 0;
export default Alert;