@televet/kibble-ui 1.17.10-beta.43w39py.13 → 1.17.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,21 +1,19 @@
1
- import React, { ReactNode } from 'react';
1
+ import React from 'react';
2
2
  import { AlertProps as CAlertProps } from '@chakra-ui/react';
3
3
  import { IconProps } from 'components/MediaAndIcons';
4
4
  import { AlertVariant } from './alert.types';
5
5
  import { ButtonProps } from 'components/Forms/Button';
6
6
  import { TextProps } from 'components/Typography/Text';
7
7
  import { Status } from '../feedback.types';
8
- import { HeadingProps } from '../../Typography';
9
8
  export interface AlertProps extends CAlertProps {
10
- children?: ReactNode;
11
9
  status?: AlertVariant | Status;
12
10
  showIcon?: boolean;
13
11
  iconProps?: IconProps;
14
12
  showButton?: boolean;
15
13
  buttonProps?: ButtonProps;
16
14
  buttonTitle?: string;
17
- alertTitle?: string;
18
- titleProps?: HeadingProps;
15
+ alertTitle: string;
16
+ titleProps?: TextProps;
19
17
  description?: string;
20
18
  descriptionProps?: TextProps;
21
19
  showCloseButton?: boolean;
@@ -0,0 +1,7 @@
1
+ import { AlertButtonAlignment } from '../../alert.types';
2
+ import { ButtonProps } from 'components/Forms/Button';
3
+ export interface AlertButtonProps extends ButtonProps {
4
+ alignment: AlertButtonAlignment;
5
+ pairedWithCloseButton?: boolean;
6
+ }
7
+ export declare const AlertButton: ({ alignment, variant, size, pairedWithCloseButton, ...rest }: AlertButtonProps) => JSX.Element;
@@ -0,0 +1,7 @@
1
+ import { AlertVariant } from '../../alert.types';
2
+ import { IconProps } from 'components/MediaAndIcons/Icon';
3
+ import { Status } from '../../../feedback.types';
4
+ export interface AlertIconProps extends IconProps {
5
+ status: AlertVariant | Status;
6
+ }
7
+ export declare const AlertIcon: ({ status, ...rest }: AlertIconProps) => JSX.Element;
@@ -1,4 +1,6 @@
1
1
  export { Alert as CAlert } from '@chakra-ui/react';
2
+ export * from './components/AlertButton/alertButton.component';
3
+ export * from './components/AlertIcon/alertIcon.component';
2
4
  export * from './alert.component';
3
5
  export * from './alert.types';
4
6
  export * from './alert.config';
@@ -1,5 +1,3 @@
1
1
  export * from './Alert';
2
2
  export * from './Toast';
3
3
  export * from './Spinner';
4
- export * from './feedback.types';
5
- export * from './feedback.model';
@@ -1,13 +1,11 @@
1
1
  import { ModalFooterProps as ChakraModalFooterProps } from '@chakra-ui/react';
2
2
  export interface ModalFooterButtonProps extends ChakraModalFooterProps {
3
- mixpanelName?: string;
4
3
  submitText?: string;
5
4
  isLoading?: boolean;
6
- loadingText?: string;
7
5
  isDisabled?: boolean;
8
6
  isDestructive?: boolean;
9
7
  onSubmit?: () => void;
10
8
  allowCancel?: boolean;
11
9
  onCancel?: () => void;
12
10
  }
13
- export declare const ModalFooterButtons: ({ submitText, isLoading, loadingText, isDisabled, isDestructive, mixpanelName, children, onSubmit, allowCancel, onCancel, ...rest }: ModalFooterButtonProps) => JSX.Element;
11
+ export declare const ModalFooterButtons: ({ submitText, isLoading, isDisabled, isDestructive, children, onSubmit, allowCancel, onCancel, ...rest }: ModalFooterButtonProps) => JSX.Element;
@@ -1,6 +1,5 @@
1
1
  export * from './modal.types';
2
2
  export * as BetaModal from './modal.component';
3
- export * from './modal.component';
4
3
  export * from './components/ModalHeader/modalHeader.component';
5
4
  export * from './components/ModalCloseButton/modalCloseButton.component';
6
5
  export * from './components/ModalBody/modalBody.component';
package/build/index.js CHANGED
@@ -3450,21 +3450,6 @@ var Logo = function (_a) {
3450
3450
  };
3451
3451
  Logo.displayName = 'Logo';
3452
3452
 
3453
- exports.AlertVariant = void 0;
3454
- (function (AlertVariant) {
3455
- AlertVariant["Error"] = "error";
3456
- AlertVariant["Warning"] = "warning";
3457
- AlertVariant["Success"] = "success";
3458
- AlertVariant["Info"] = "info";
3459
- })(exports.AlertVariant || (exports.AlertVariant = {}));
3460
- exports.AlertStatusIcon = void 0;
3461
- (function (AlertStatusIcon) {
3462
- AlertStatusIcon["error"] = "warningSign";
3463
- AlertStatusIcon["warning"] = "warningSign";
3464
- AlertStatusIcon["success"] = "checkmark";
3465
- AlertStatusIcon["info"] = "infoCircleOutlined";
3466
- })(exports.AlertStatusIcon || (exports.AlertStatusIcon = {}));
3467
-
3468
3453
  var Button = React.forwardRef(function (props, ref) {
3469
3454
  var _a = useTheme(), components = _a.components, fontWeights = _a.fontWeights, radii = _a.radii;
3470
3455
  var _b = components.Button[props.variant || 'primary'], variant = _b.variant, light = _b.light, dark = _b.dark;
@@ -3721,6 +3706,38 @@ var ButtonSizeConfig = {
3721
3706
  },
3722
3707
  };
3723
3708
 
3709
+ var AlertButton = function (_a) {
3710
+ var alignment = _a.alignment, _b = _a.variant, variant = _b === void 0 ? 'secondary' : _b, _c = _a.size, size = _c === void 0 ? 'xs' : _c, _d = _a.pairedWithCloseButton, pairedWithCloseButton = _d === void 0 ? false : _d, rest = __rest(_a, ["alignment", "variant", "size", "pairedWithCloseButton"]);
3711
+ return (React__default["default"].createElement(Button, __assign({ size: size, variant: variant }, rest, (alignment === 'bottom' && { mt: 2, mb: 1 }), (alignment === 'right' && pairedWithCloseButton && { mr: 2 })), rest.children));
3712
+ };
3713
+
3714
+ var AlertIconColorMap = {
3715
+ info: 'active',
3716
+ success: 'success',
3717
+ error: 'error',
3718
+ warning: 'warning',
3719
+ };
3720
+ var AlertIcon = function (_a) {
3721
+ var status = _a.status, rest = __rest(_a, ["status"]);
3722
+ var color = react.useColorModeValue(AlertIconColorMap[status], 'currentColor');
3723
+ return React__default["default"].createElement(Icon, __assign({ color: color, size: "lg" }, rest));
3724
+ };
3725
+
3726
+ exports.AlertVariant = void 0;
3727
+ (function (AlertVariant) {
3728
+ AlertVariant["Error"] = "error";
3729
+ AlertVariant["Warning"] = "warning";
3730
+ AlertVariant["Success"] = "success";
3731
+ AlertVariant["Info"] = "info";
3732
+ })(exports.AlertVariant || (exports.AlertVariant = {}));
3733
+ exports.AlertStatusIcon = void 0;
3734
+ (function (AlertStatusIcon) {
3735
+ AlertStatusIcon["error"] = "warningSign";
3736
+ AlertStatusIcon["warning"] = "warningSign";
3737
+ AlertStatusIcon["success"] = "checkmark";
3738
+ AlertStatusIcon["info"] = "infoCircleOutlined";
3739
+ })(exports.AlertStatusIcon || (exports.AlertStatusIcon = {}));
3740
+
3724
3741
  var DrawerConfig = {
3725
3742
  variants: {
3726
3743
  alwaysOpen: {
@@ -4664,7 +4681,7 @@ var Select = function (_a) {
4664
4681
  }
4665
4682
  return (React__default["default"].createElement(MenuProvider, { menuItems: allOptions },
4666
4683
  React__default["default"].createElement(MenuContainer, { matchWidth: true, isLazy: true },
4667
- React__default["default"].createElement(react.Select, __assign({ icon: React__default["default"].createElement(Icon, { name: "chevronDown", size: size }), as: react.MenuButton, _focus: {
4684
+ React__default["default"].createElement(react.Select, __assign({ as: react.MenuButton, _focus: {
4668
4685
  boxShadow: "0 0 0 1px ".concat(colors.border.light.focus, " !important"),
4669
4686
  borderColor: colors.border.light.focus,
4670
4687
  }, ref: selectRef, onClick: function (event) { return event.stopPropagation(); }, type: "button", className: "Select__MenuButton", maxW: maxW, style: { minHeight: { xs: 24, sm: 32, md: 40, lg: 48 }[size] } }, flexibleHeightProps, domProps),
@@ -15110,7 +15127,7 @@ var ModalFooter = function (_a) {
15110
15127
  };
15111
15128
 
15112
15129
  var ModalFooterButtons = function (_a) {
15113
- var _b = _a.submitText, submitText = _b === void 0 ? 'Submit' : _b, isLoading = _a.isLoading, loadingText = _a.loadingText, isDisabled = _a.isDisabled, isDestructive = _a.isDestructive, mixpanelName = _a.mixpanelName; _a.children; var onSubmit = _a.onSubmit, _c = _a.allowCancel, allowCancel = _c === void 0 ? true : _c, onCancel = _a.onCancel, rest = __rest(_a, ["submitText", "isLoading", "loadingText", "isDisabled", "isDestructive", "mixpanelName", "children", "onSubmit", "allowCancel", "onCancel"]);
15130
+ var _b = _a.submitText, submitText = _b === void 0 ? 'Submit' : _b, isLoading = _a.isLoading, isDisabled = _a.isDisabled, isDestructive = _a.isDestructive; _a.children; var onSubmit = _a.onSubmit, _c = _a.allowCancel, allowCancel = _c === void 0 ? true : _c, onCancel = _a.onCancel, rest = __rest(_a, ["submitText", "isLoading", "isDisabled", "isDestructive", "children", "onSubmit", "allowCancel", "onCancel"]);
15114
15131
  var onClose = react.useModalContext().onClose;
15115
15132
  var handleCancel = function () {
15116
15133
  if (onCancel) {
@@ -15122,7 +15139,7 @@ var ModalFooterButtons = function (_a) {
15122
15139
  React__default["default"].createElement(react.Flex, { w: "100%" },
15123
15140
  allowCancel && (React__default["default"].createElement(Button, { variant: "tertiary", onClick: handleCancel }, "Cancel")),
15124
15141
  React__default["default"].createElement(react.Spacer, null),
15125
- React__default["default"].createElement(Button, { "data-mixpanel-name": mixpanelName, onClick: onSubmit, isLoading: isLoading, loadingText: loadingText, isDisabled: isDisabled, variant: isDestructive ? 'primaryDestructive' : 'primary' }, submitText))));
15142
+ React__default["default"].createElement(Button, { onClick: onSubmit, isLoading: isLoading, isDisabled: isDisabled, variant: isDestructive ? 'primaryDestructive' : 'primary' }, submitText))));
15126
15143
  };
15127
15144
 
15128
15145
  var Popover = function (_a) {
@@ -15273,43 +15290,71 @@ var TextConfig = {
15273
15290
  },
15274
15291
  };
15275
15292
 
15276
- var LightStatusVariantMap = {
15277
- info: 'info',
15278
- success: 'success',
15279
- warning: 'warning',
15280
- error: 'error',
15281
- };
15282
- var DarkStatusVariantMap = {
15283
- info: 'infoDark',
15284
- success: 'successDark',
15285
- warning: 'warningDark',
15286
- error: 'errorDark',
15287
- };
15288
- var AlertIconColorMap = {
15289
- info: 'active',
15290
- success: 'success',
15291
- error: 'error',
15292
- warning: 'warning',
15293
+ function useWindowSize() {
15294
+ // Initialize state with undefined width/height so server and client renders match
15295
+ // Learn more here: https://joshwcomeau.com/react/the-perils-of-rehydration/
15296
+ var _a = __read(React.useState({
15297
+ width: undefined,
15298
+ height: undefined,
15299
+ }), 2), windowSize = _a[0], setWindowSize = _a[1];
15300
+ React.useEffect(function () {
15301
+ // Handler to call on window resize
15302
+ function handleResize() {
15303
+ // Set window width/height to state
15304
+ setWindowSize({
15305
+ width: window.innerWidth,
15306
+ height: window.innerHeight,
15307
+ });
15308
+ }
15309
+ // Add event listener
15310
+ window.addEventListener('resize', handleResize);
15311
+ // Call handler right away so state gets updated with initial window size
15312
+ handleResize();
15313
+ // Remove event listener on cleanup
15314
+ return function () { return window.removeEventListener('resize', handleResize); };
15315
+ }, []); // Empty array ensures that effect is only run on mount
15316
+ return windowSize;
15317
+ }
15318
+
15319
+ var useOverflowingText = function (text, textRef) {
15320
+ var size = useWindowSize();
15321
+ var _a = __read(React.useState(false), 2), isTextOverFlowing = _a[0], setIsTextOverFlowing = _a[1];
15322
+ var onCheckTextOverFlowing = React.useCallback(function (containerRefValue) {
15323
+ var _a;
15324
+ if (containerRefValue && containerRefValue.current) {
15325
+ var lines = (_a = containerRefValue.current) === null || _a === void 0 ? void 0 : _a.children[0].getClientRects().length;
15326
+ return lines > 1;
15327
+ }
15328
+ return false;
15329
+ }, []);
15330
+ React.useEffect(function () {
15331
+ // if size of window changes, or if title length changes, check if text is overflowing
15332
+ var isOverFlowing = onCheckTextOverFlowing(textRef);
15333
+ setIsTextOverFlowing(isOverFlowing);
15334
+ }, [size, text, onCheckTextOverFlowing, textRef]);
15335
+ return isTextOverFlowing;
15293
15336
  };
15294
15337
 
15295
15338
  var Alert = function (_a) {
15296
15339
  var children = _a.children, _b = _a.status, status = _b === void 0 ? exports.AlertVariant.Success : _b, _c = _a.showIcon, showIcon = _c === void 0 ? true : _c, iconProps = _a.iconProps, _d = _a.showButton, showButton = _d === void 0 ? false : _d, buttonProps = _a.buttonProps, buttonTitle = _a.buttonTitle, alertTitle = _a.alertTitle, titleProps = _a.titleProps, description = _a.description, descriptionProps = _a.descriptionProps, _e = _a.showCloseButton, showCloseButton = _e === void 0 ? true : _e, onClose = _a.onClose, rest = __rest(_a, ["children", "status", "showIcon", "iconProps", "showButton", "buttonProps", "buttonTitle", "alertTitle", "titleProps", "description", "descriptionProps", "showCloseButton", "onClose"]);
15297
- var alertVariant = react.useColorModeValue(LightStatusVariantMap[status], DarkStatusVariantMap[status]);
15298
- var iconColor = react.useColorModeValue(AlertIconColorMap[status], 'currentColor');
15299
- return (React__default["default"].createElement(react.Alert, __assign({ justifyContent: "space-between", overflow: "visible", variant: alertVariant, pl: 3, pr: showCloseButton ? 2 : 3, pb: description || children ? 3 : 2 }, rest),
15300
- React__default["default"].createElement(react.Flex, { w: "100%" },
15301
- showIcon && (React__default["default"].createElement(react.Box, { mr: 2 },
15302
- React__default["default"].createElement(Icon, __assign({ color: iconColor, size: "lg", name: (iconProps === null || iconProps === void 0 ? void 0 : iconProps.name) || exports.AlertStatusIcon[status] }, iconProps)))),
15303
- React__default["default"].createElement(react.Flex, { flexGrow: 1 },
15304
- React__default["default"].createElement(react.Flex, { alignItems: "flex-start", flexDirection: description ? 'column' : 'row', flexWrap: "wrap", w: "100%", justify: "space-between", align: "center" },
15305
- alertTitle && (React__default["default"].createElement(react.Box, { pt: 0.5, pr: 1, flexGrow: 1 },
15306
- React__default["default"].createElement(Heading, __assign({ size: "sm", colorToken: "default" }, titleProps), alertTitle))),
15307
- description && (React__default["default"].createElement(react.Box, { flexGrow: 1, pb: 2 },
15308
- React__default["default"].createElement(Text, __assign({ as: "p", size: "md" }, descriptionProps), description))),
15309
- children,
15310
- showButton && (React__default["default"].createElement(Button, __assign({ size: "xs", variant: "secondary" }, buttonProps), buttonTitle)))),
15311
- showCloseButton && (React__default["default"].createElement(react.Box, { ml: 2 },
15312
- React__default["default"].createElement(Button, { variant: "ghostNeutral", iconName: "close", size: "xs", onClick: onClose }))))));
15340
+ var titleRef = React.useRef(null);
15341
+ var isTitleOverflowing = useOverflowingText(alertTitle, titleRef);
15342
+ var showButtonInline = showButton && !description && !isTitleOverflowing;
15343
+ var showButtonBottom = (showButton && description) || (showButton && !description && isTitleOverflowing);
15344
+ return (React__default["default"].createElement(react.Alert, __assign({ justifyContent: "space-between", overflow: "visible", variant: status, pl: 3, pr: showCloseButton ? 2 : 3 }, rest),
15345
+ React__default["default"].createElement(react.HStack, { justifyContent: "space-between", w: "100%" },
15346
+ showIcon && (React__default["default"].createElement(react.Flex, { alignSelf: "flex-start" },
15347
+ React__default["default"].createElement(AlertIcon, __assign({ status: status, name: (iconProps === null || iconProps === void 0 ? void 0 : iconProps.name) || exports.AlertStatusIcon[status] }, iconProps)))),
15348
+ React__default["default"].createElement(react.Flex, __assign({ width: "100%", flexDirection: "column" }, (showIcon && { ml: 2 })),
15349
+ React__default["default"].createElement(react.Flex, { alignItems: "flex-start", w: "100%", justifyContent: "space-between" },
15350
+ React__default["default"].createElement(react.Box, { ref: titleRef, mr: showButtonInline || showCloseButton ? 2 : 0 },
15351
+ React__default["default"].createElement(Text, __assign({ size: "md", variant: "semibold" }, titleProps), alertTitle)),
15352
+ React__default["default"].createElement(react.Flex, { alignItems: "center" },
15353
+ showButtonInline && (React__default["default"].createElement(AlertButton, __assign({ alignment: "right" }, buttonProps, { pairedWithCloseButton: showCloseButton }), buttonTitle)),
15354
+ showCloseButton && React__default["default"].createElement(Button, { variant: "ghostNeutral", iconName: "close", size: "xs", onClick: onClose }))),
15355
+ description && (React__default["default"].createElement(Text, __assign({ size: "md" }, descriptionProps), description)),
15356
+ children,
15357
+ React__default["default"].createElement(react.Box, null, showButtonBottom && (React__default["default"].createElement(AlertButton, __assign({ alignment: "bottom" }, buttonProps), buttonTitle)))))));
15313
15358
  };
15314
15359
 
15315
15360
  var AlertConfig = {
@@ -21739,11 +21784,17 @@ function getToastPlacement(position, dir) {
21739
21784
  return (_a = logical === null || logical === void 0 ? void 0 : logical[dir]) !== null && _a !== void 0 ? _a : position;
21740
21785
  }
21741
21786
 
21787
+ var StatusVariantMap = {
21788
+ info: 'infoDark',
21789
+ success: 'successDark',
21790
+ warning: 'warningDark',
21791
+ error: 'errorDark',
21792
+ };
21742
21793
  var Toast = function (props) {
21743
21794
  var _a = props.status, status = _a === void 0 ? 'info' : _a, id = props.id, title = props.title, isClosable = props.isClosable, onClose = props.onClose, description = props.description, buttonTitle = props.buttonTitle, onButtonClick = props.onButtonClick, _b = props.hideIcon, hideIcon = _b === void 0 ? false : _b;
21744
21795
  var buttonProps = { onClick: onButtonClick };
21745
21796
  return (React__namespace.createElement(react.DarkMode, null,
21746
- React__namespace.createElement(Alert, { id: id, alertTitle: title, buttonTitle: buttonTitle, description: description, showIcon: !hideIcon, status: status, showCloseButton: isClosable, onClose: onClose, variant: DarkStatusVariantMap[status], showButton: !!onButtonClick && !!buttonTitle, buttonProps: buttonProps })));
21797
+ React__namespace.createElement(Alert, { id: id, alertTitle: title, buttonTitle: buttonTitle, description: description, showIcon: !hideIcon, status: status, showCloseButton: isClosable, onClose: onClose, variant: StatusVariantMap[status], showButton: !!onButtonClick && !!buttonTitle, buttonProps: buttonProps })));
21747
21798
  };
21748
21799
  var defaults = {
21749
21800
  title: '',
@@ -24771,8 +24822,9 @@ Object.defineProperty(exports, 'useRadioGroup', {
24771
24822
  get: function () { return react.useRadioGroup; }
24772
24823
  });
24773
24824
  exports.Alert = Alert;
24825
+ exports.AlertButton = AlertButton;
24774
24826
  exports.AlertConfig = AlertConfig;
24775
- exports.AlertIconColorMap = AlertIconColorMap;
24827
+ exports.AlertIcon = AlertIcon;
24776
24828
  exports.Avatar = Avatar;
24777
24829
  exports.AvatarConfig = AvatarConfig;
24778
24830
  exports.AvatarGroup = AvatarGroup;
@@ -24783,7 +24835,6 @@ exports.ButtonVariantConfig = ButtonVariantConfig;
24783
24835
  exports.Checkbox = Checkbox$1;
24784
24836
  exports.CheckboxConfig = CheckboxConfig;
24785
24837
  exports.CheckboxGroup = WrappedCheckboxGroup;
24786
- exports.DarkStatusVariantMap = DarkStatusVariantMap;
24787
24838
  exports.DatePicker = DatePicker;
24788
24839
  exports.DatePickerContext = DatePickerContext;
24789
24840
  exports.DrawerConfig = DrawerConfig;
@@ -24791,13 +24842,11 @@ exports.Heading = Heading;
24791
24842
  exports.HeadingConfig = HeadingConfig;
24792
24843
  exports.Icon = Icon;
24793
24844
  exports.KibbleThemeProvider = KibbleThemeProvider;
24794
- exports.LightStatusVariantMap = LightStatusVariantMap;
24795
24845
  exports.Logo = Logo;
24796
24846
  exports.Menu = Menu;
24797
24847
  exports.MenuConfig = MenuConfig;
24798
24848
  exports.MenuContext = MenuContext;
24799
24849
  exports.MenuItemConfig = MenuItemConfig;
24800
- exports.Modal = Modal;
24801
24850
  exports.ModalBody = ModalBody;
24802
24851
  exports.ModalCloseButton = ModalCloseButton;
24803
24852
  exports.ModalFooter = ModalFooter;