@itwin/itwinui-react
Version:
A react component library for iTwinUI
152 lines (151 loc) • 4.08 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', {
value: true,
});
Object.defineProperty(exports, 'Alert', {
enumerable: true,
get: function () {
return Alert;
},
});
const _interop_require_default = require('@swc/helpers/_/_interop_require_default');
const _interop_require_wildcard = require('@swc/helpers/_/_interop_require_wildcard');
const _classnames = /*#__PURE__*/ _interop_require_default._(
require('classnames'),
);
const _react = /*#__PURE__*/ _interop_require_wildcard._(require('react'));
const _index = require('../../utils/index.js');
const _IconButton = require('../Buttons/IconButton.js');
const _Icon = require('../Icon/Icon.js');
const _Anchor = require('../Typography/Anchor.js');
const AlertContext = _react.createContext(void 0);
const AlertComponent = _react.forwardRef((props, forwardedRef) => {
let {
children,
type = 'informational',
isSticky = false,
clickableText,
clickableTextProps,
onClose,
...rest
} = props;
return _react.createElement(
Alert.Wrapper,
{
type: type,
isSticky: isSticky,
ref: forwardedRef,
...rest,
},
_react.createElement(Alert.Icon, null),
_react.createElement(
Alert.Message,
null,
children,
clickableText
? _react.createElement(Alert.Action, clickableTextProps, clickableText)
: null,
),
onClose
? _react.createElement(Alert.CloseButton, {
onClick: onClose,
})
: null,
);
});
if ('development' === process.env.NODE_ENV)
AlertComponent.displayName = 'Alert';
const AlertWrapper = _react.forwardRef((props, ref) => {
let {
children,
className,
type = 'informational',
isSticky = false,
...rest
} = props;
return _react.createElement(
_index.Box,
{
className: (0, _classnames.default)('iui-alert', className),
'data-iui-status': type,
'data-iui-variant': isSticky ? 'sticky' : void 0,
ref: ref,
...rest,
},
_react.createElement(
AlertContext.Provider,
{
value: {
type,
},
},
children,
),
);
});
if ('development' === process.env.NODE_ENV)
AlertWrapper.displayName = 'Alert.Wrapper';
const AlertIcon = _react.forwardRef((props, ref) => {
let { children, ...rest } = props;
let { type } = (0, _index.useSafeContext)(AlertContext);
let StatusIcon = _index.StatusIconMap[type];
return _react.createElement(
_Icon.Icon,
{
fill: type,
ref: ref,
...rest,
},
children ?? _react.createElement(StatusIcon, null),
);
});
if ('development' === process.env.NODE_ENV)
AlertIcon.displayName = 'Alert.Icon';
const AlertMessage = _index.polymorphic.span('iui-alert-message');
if ('development' === process.env.NODE_ENV)
AlertMessage.displayName = 'Alert.Message';
const AlertAction = _react.forwardRef((props, ref) => {
let { children, className, ...rest } = props;
let { type } = (0, _index.useSafeContext)(AlertContext);
return _react.createElement(
_Anchor.Anchor,
{
as: props.href ? 'a' : 'button',
className: (0, _classnames.default)(
'iui-button-base',
'iui-alert-link',
className,
),
underline: true,
'data-iui-status': type,
ref: ref,
...rest,
},
children,
);
});
if ('development' === process.env.NODE_ENV)
AlertAction.displayName = 'Alert.Action';
const AlertCloseButton = _react.forwardRef((props, ref) => {
let { children, ...rest } = props;
return _react.createElement(
_IconButton.IconButton,
{
styleType: 'borderless',
size: 'small',
'aria-label': 'Close',
ref: ref,
...rest,
},
children ?? _react.createElement(_index.SvgCloseSmall, null),
);
});
if ('development' === process.env.NODE_ENV)
AlertCloseButton.displayName = 'Alert.CloseButton';
const Alert = Object.assign(AlertComponent, {
Wrapper: AlertWrapper,
Icon: AlertIcon,
Message: AlertMessage,
Action: AlertAction,
CloseButton: AlertCloseButton,
});