@hyphen/hyphen-components 6.12.0 → 6.14.0

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,29 +1,20 @@
1
- import { FC, ReactNode, MouseEvent, KeyboardEvent } from 'react';
1
+ import React, { ReactNode, MouseEvent, KeyboardEvent } from 'react';
2
2
  import { AlertVariant } from './Alert.types';
3
3
  export interface AlertProps {
4
4
  /**
5
5
  * Custom class to apply to the alert.
6
6
  */
7
7
  className?: string;
8
- /**
9
- * Custom text to use as a close button.
10
- */
11
- closeText?: string;
12
8
  /**
13
9
  * Whether the alert as an icon that corresponds to its variant (Success, warning, etc.).
14
10
  */
15
11
  hasIcon?: boolean;
16
- /**
17
- * Whether the alert can be closed by the user. If `true` it will render
18
- * the 'close' icon on the right hand side of the alert.
19
- */
20
- isClosable?: boolean;
21
12
  /**
22
13
  * Renders a version of the alert with smaller padding.
23
14
  */
24
15
  isCompact?: boolean;
25
16
  /**
26
- * The text message or ReactNode to be rendered in the alert.
17
+ * @deprecated Use children instead. The text message or ReactNode to be rendered in the alert.
27
18
  */
28
19
  message?: string | ReactNode;
29
20
  /**
@@ -48,4 +39,4 @@ export interface AlertProps {
48
39
  */
49
40
  [x: string]: any;
50
41
  }
51
- export declare const Alert: FC<AlertProps>;
42
+ export declare const Alert: React.NamedExoticComponent<AlertProps>;
@@ -1,8 +1,12 @@
1
1
  import { Alert } from './Alert';
2
- import type { Meta } from '@storybook/react-vite';
2
+ import type { Meta, StoryObj } from '@storybook/react-vite';
3
3
  import React from 'react';
4
4
  declare const meta: Meta<typeof Alert>;
5
5
  export default meta;
6
- export declare const Overview: () => React.JSX.Element;
7
- export declare const Variants: () => React.JSX.Element;
8
- export declare const Closable: () => React.JSX.Element;
6
+ type Story = StoryObj<typeof Alert>;
7
+ export declare const Overview: Story;
8
+ export declare const Compact: Story;
9
+ export declare const WithCustomContent: Story;
10
+ export declare const Variants: Story;
11
+ export declare const ClosableAlert: () => React.JSX.Element;
12
+ export declare const Closable: Story;
@@ -1,8 +1,8 @@
1
- import { Meta } from '@storybook/react-vite';
2
1
  import { Badge } from './Badge';
3
- import React from 'react';
2
+ import type { Meta, StoryObj } from '@storybook/react-vite';
4
3
  declare const meta: Meta<typeof Badge>;
5
4
  export default meta;
6
- export declare const Overview: () => React.JSX.Element;
7
- export declare const Variants: () => React.JSX.Element;
8
- export declare const Sizes: () => React.JSX.Element;
5
+ type Story = StoryObj<typeof Badge>;
6
+ export declare const Overview: Story;
7
+ export declare const Variants: Story;
8
+ export declare const Sizes: Story;
@@ -1,16 +1,16 @@
1
- import React from 'react';
2
1
  import { Button } from './Button';
3
- import type { Meta } from '@storybook/react-vite';
2
+ import type { Meta, StoryObj } from '@storybook/react-vite';
4
3
  declare const meta: Meta<typeof Button>;
5
4
  export default meta;
6
- export declare const Default: () => React.JSX.Element;
7
- export declare const AsChild: () => React.JSX.Element;
8
- export declare const Variants: () => React.JSX.Element;
9
- export declare const Sizes: () => React.JSX.Element;
10
- export declare const FullWidth: () => React.JSX.Element;
11
- export declare const Icons: () => React.JSX.Element;
12
- export declare const IconButton: () => React.JSX.Element;
13
- export declare const Loading: () => React.JSX.Element;
14
- export declare const Disabled: () => React.JSX.Element;
15
- export declare const Shadow: () => React.JSX.Element;
16
- export declare const InlineLink: () => React.JSX.Element;
5
+ type Story = StoryObj<typeof Button>;
6
+ export declare const Default: Story;
7
+ export declare const AsChild: Story;
8
+ export declare const Variants: Story;
9
+ export declare const Sizes: Story;
10
+ export declare const FullWidth: Story;
11
+ export declare const Icons: Story;
12
+ export declare const IconButton: Story;
13
+ export declare const Loading: Story;
14
+ export declare const Disabled: Story;
15
+ export declare const Shadow: Story;
16
+ export declare const InlineLink: Story;
@@ -557,7 +557,6 @@ var Icon = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
557
557
 
558
558
  var styles$z = {"alert":"Alert-module_alert__zP4AL","close-icon":"Alert-module_close-icon__zs4Xk","alert-heading":"Alert-module_alert-heading__VguTk","alert__default":"Alert-module_alert__default__-pcBw","alert__info":"Alert-module_alert__info__UZeOd","alert__success":"Alert-module_alert__success__o2IHF","alert__warning":"Alert-module_alert__warning__lzTY-","alert__danger":"Alert-module_alert__danger__M-XFh","alert__icon__default":"Alert-module_alert__icon__default__cCx9C","alert__icon__info":"Alert-module_alert__icon__info__2W0Bi","alert__icon__success":"Alert-module_alert__icon__success__NBCDO","alert__icon__warning":"Alert-module_alert__icon__warning__nY4hy","alert__icon__danger":"Alert-module_alert__icon__danger__NcOrf"};
559
559
 
560
- // eslint-disable-next-line import/prefer-default-export
561
560
  var ALERT_ICONS_MAP = {
562
561
  "default": {
563
562
  icon: 'c-warning'
@@ -576,18 +575,15 @@ var ALERT_ICONS_MAP = {
576
575
  }
577
576
  };
578
577
 
579
- var _excluded$O = ["className", "closeText", "hasIcon", "isCompact", "isClosable", "message", "onClose", "render", "title", "variant"];
580
- var Alert = function Alert(_ref) {
581
- var _ref$className = _ref.className,
578
+ var _excluded$O = ["children", "className", "hasIcon", "isCompact", "message", "onClose", "render", "title", "variant"];
579
+ var AlertComponent = function AlertComponent(_ref) {
580
+ var children = _ref.children,
581
+ _ref$className = _ref.className,
582
582
  className = _ref$className === void 0 ? '' : _ref$className,
583
- _ref$closeText = _ref.closeText,
584
- closeText = _ref$closeText === void 0 ? '' : _ref$closeText,
585
583
  _ref$hasIcon = _ref.hasIcon,
586
584
  hasIcon = _ref$hasIcon === void 0 ? false : _ref$hasIcon,
587
585
  _ref$isCompact = _ref.isCompact,
588
586
  isCompact = _ref$isCompact === void 0 ? false : _ref$isCompact,
589
- _ref$isClosable = _ref.isClosable,
590
- isClosable = _ref$isClosable === void 0 ? false : _ref$isClosable,
591
587
  _ref$message = _ref.message,
592
588
  message = _ref$message === void 0 ? '' : _ref$message,
593
589
  _ref$onClose = _ref.onClose,
@@ -599,11 +595,18 @@ var Alert = function Alert(_ref) {
599
595
  _ref$variant = _ref.variant,
600
596
  variant = _ref$variant === void 0 ? 'default' : _ref$variant,
601
597
  restProps = _objectWithoutPropertiesLoose(_ref, _excluded$O);
602
- var handleClose = function handleClose(event) {
598
+ var handleClose = React.useCallback(function (event) {
603
599
  if (!onClose) return;
604
600
  onClose(event);
605
- };
606
- var renderAlertIcon = function renderAlertIcon() {
601
+ }, [onClose]);
602
+ var handleCloseKeyPress = React.useCallback(function (event) {
603
+ if (event.keyCode === 13) handleClose(event);
604
+ }, [handleClose]);
605
+ var alertContainerClasses = React.useMemo(function () {
606
+ return classNames(styles$z["alert__" + variant], styles$z.alert, className);
607
+ }, [variant, className]);
608
+ var alertIcon = React.useMemo(function () {
609
+ if (!hasIcon) return null;
607
610
  return React.createElement(Box, {
608
611
  fontSize: "md",
609
612
  className: styles$z["alert__icon__" + variant]
@@ -611,11 +614,9 @@ var Alert = function Alert(_ref) {
611
614
  name: ALERT_ICONS_MAP[variant].icon,
612
615
  "data-testid": "alert-icon-" + variant + "-test-id"
613
616
  }));
614
- };
615
- var renderCloseIcon = function renderCloseIcon() {
616
- var handleCloseKeyPress = function handleCloseKeyPress(event) {
617
- if (event.keyCode === 13) handleClose(event);
618
- };
617
+ }, [hasIcon, variant]);
618
+ var closeIcon = React.useMemo(function () {
619
+ if (!onClose) return null;
619
620
  return React.createElement(Box, {
620
621
  margin: "0 0 0 auto",
621
622
  color: "secondary",
@@ -625,31 +626,37 @@ var Alert = function Alert(_ref) {
625
626
  onClick: handleClose,
626
627
  onKeyUp: handleCloseKeyPress,
627
628
  "aria-label": "dismiss"
628
- }, closeText || React.createElement(Icon, {
629
+ }, React.createElement(Icon, {
629
630
  name: "remove",
630
631
  "data-testid": "alert-close-icon-test-id"
631
632
  })));
632
- };
633
- var alertContainerClasses = classNames(styles$z["alert__" + variant], styles$z.alert, className);
633
+ }, [onClose, handleClose, handleCloseKeyPress]);
634
+ var content = React.useMemo(function () {
635
+ if (render) {
636
+ return render();
637
+ }
638
+ return React.createElement(Box, {
639
+ display: "block",
640
+ childGap: message && title ? '2xs' : undefined
641
+ }, title && React.createElement(Box, {
642
+ as: "h4",
643
+ fontSize: "sm",
644
+ fontWeight: "semibold",
645
+ className: styles$z['alert-heading']
646
+ }, title), children != null ? children : message && (typeof message === 'string' ? React.createElement("p", null, message) : message));
647
+ }, [render, message, title, children]);
634
648
  return React.createElement(Box, _extends({
635
649
  alignItems: "flex-start",
636
650
  gap: "md",
637
651
  className: alertContainerClasses,
638
652
  direction: "row",
639
- padding: isCompact ? 'xs' : 'md',
653
+ padding: isCompact ? 'md' : '2xl',
640
654
  radius: "md",
641
655
  role: "alert",
642
656
  fontSize: "sm"
643
- }, restProps), hasIcon && renderAlertIcon(), React.createElement("div", null, render ? render() : React.createElement(Box, {
644
- display: "block",
645
- childGap: message && title ? '2xs' : undefined
646
- }, title && React.createElement(Box, {
647
- as: "h4",
648
- fontSize: "sm",
649
- fontWeight: "semibold",
650
- className: styles$z['alert-heading']
651
- }, title), message && (typeof message === 'string' ? React.createElement("p", null, message) : message))), isClosable && renderCloseIcon());
657
+ }, restProps), alertIcon, React.createElement("div", null, content), closeIcon);
652
658
  };
659
+ var Alert = /*#__PURE__*/React.memo(AlertComponent);
653
660
 
654
661
  var AspectRatio = AspectRatioPrimitive__namespace.Root;
655
662