@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.
- package/dist/components/Alert/Alert.d.ts +3 -12
- package/dist/components/Alert/Alert.stories.d.ts +8 -4
- package/dist/components/Badge/Badge.stories.d.ts +5 -5
- package/dist/components/Button/Button.stories.d.ts +13 -13
- package/dist/hyphen-components.cjs.development.js +36 -29
- package/dist/hyphen-components.cjs.development.js.map +1 -1
- package/dist/hyphen-components.cjs.production.min.js +1 -1
- package/dist/hyphen-components.cjs.production.min.js.map +1 -1
- package/dist/hyphen-components.esm.js +37 -30
- package/dist/hyphen-components.esm.js.map +1 -1
- package/package.json +3 -3
- package/src/components/Alert/Alert.constants.ts +0 -1
- package/src/components/Alert/Alert.stories.tsx +102 -47
- package/src/components/Alert/Alert.test.tsx +2 -66
- package/src/components/Alert/Alert.tsx +78 -65
- package/src/components/Badge/Badge.stories.tsx +69 -22
- package/src/components/Button/Button.stories.tsx +265 -127
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
import React__default, { forwardRef, Children, createElement, cloneElement, useLayoutEffect, useEffect, createContext, useState,
|
|
3
|
+
import React__default, { forwardRef, Children, createElement, cloneElement, memo, useCallback, useMemo, useLayoutEffect, useEffect, createContext, useState, useContext } from 'react';
|
|
4
4
|
import classNames from 'classnames';
|
|
5
5
|
import icons from '@hyphen/hyphen-design-tokens/build/assets/icons/react';
|
|
6
6
|
import * as AspectRatioPrimitive from '@radix-ui/react-aspect-ratio';
|
|
@@ -528,7 +528,6 @@ var Icon = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
528
528
|
|
|
529
529
|
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"};
|
|
530
530
|
|
|
531
|
-
// eslint-disable-next-line import/prefer-default-export
|
|
532
531
|
var ALERT_ICONS_MAP = {
|
|
533
532
|
"default": {
|
|
534
533
|
icon: 'c-warning'
|
|
@@ -547,18 +546,15 @@ var ALERT_ICONS_MAP = {
|
|
|
547
546
|
}
|
|
548
547
|
};
|
|
549
548
|
|
|
550
|
-
var _excluded$O = ["
|
|
551
|
-
var
|
|
552
|
-
var
|
|
549
|
+
var _excluded$O = ["children", "className", "hasIcon", "isCompact", "message", "onClose", "render", "title", "variant"];
|
|
550
|
+
var AlertComponent = function AlertComponent(_ref) {
|
|
551
|
+
var children = _ref.children,
|
|
552
|
+
_ref$className = _ref.className,
|
|
553
553
|
className = _ref$className === void 0 ? '' : _ref$className,
|
|
554
|
-
_ref$closeText = _ref.closeText,
|
|
555
|
-
closeText = _ref$closeText === void 0 ? '' : _ref$closeText,
|
|
556
554
|
_ref$hasIcon = _ref.hasIcon,
|
|
557
555
|
hasIcon = _ref$hasIcon === void 0 ? false : _ref$hasIcon,
|
|
558
556
|
_ref$isCompact = _ref.isCompact,
|
|
559
557
|
isCompact = _ref$isCompact === void 0 ? false : _ref$isCompact,
|
|
560
|
-
_ref$isClosable = _ref.isClosable,
|
|
561
|
-
isClosable = _ref$isClosable === void 0 ? false : _ref$isClosable,
|
|
562
558
|
_ref$message = _ref.message,
|
|
563
559
|
message = _ref$message === void 0 ? '' : _ref$message,
|
|
564
560
|
_ref$onClose = _ref.onClose,
|
|
@@ -570,11 +566,18 @@ var Alert = function Alert(_ref) {
|
|
|
570
566
|
_ref$variant = _ref.variant,
|
|
571
567
|
variant = _ref$variant === void 0 ? 'default' : _ref$variant,
|
|
572
568
|
restProps = _objectWithoutPropertiesLoose(_ref, _excluded$O);
|
|
573
|
-
var handleClose = function
|
|
569
|
+
var handleClose = useCallback(function (event) {
|
|
574
570
|
if (!onClose) return;
|
|
575
571
|
onClose(event);
|
|
576
|
-
};
|
|
577
|
-
var
|
|
572
|
+
}, [onClose]);
|
|
573
|
+
var handleCloseKeyPress = useCallback(function (event) {
|
|
574
|
+
if (event.keyCode === 13) handleClose(event);
|
|
575
|
+
}, [handleClose]);
|
|
576
|
+
var alertContainerClasses = useMemo(function () {
|
|
577
|
+
return classNames(styles$z["alert__" + variant], styles$z.alert, className);
|
|
578
|
+
}, [variant, className]);
|
|
579
|
+
var alertIcon = useMemo(function () {
|
|
580
|
+
if (!hasIcon) return null;
|
|
578
581
|
return React__default.createElement(Box, {
|
|
579
582
|
fontSize: "md",
|
|
580
583
|
className: styles$z["alert__icon__" + variant]
|
|
@@ -582,11 +585,9 @@ var Alert = function Alert(_ref) {
|
|
|
582
585
|
name: ALERT_ICONS_MAP[variant].icon,
|
|
583
586
|
"data-testid": "alert-icon-" + variant + "-test-id"
|
|
584
587
|
}));
|
|
585
|
-
};
|
|
586
|
-
var
|
|
587
|
-
|
|
588
|
-
if (event.keyCode === 13) handleClose(event);
|
|
589
|
-
};
|
|
588
|
+
}, [hasIcon, variant]);
|
|
589
|
+
var closeIcon = useMemo(function () {
|
|
590
|
+
if (!onClose) return null;
|
|
590
591
|
return React__default.createElement(Box, {
|
|
591
592
|
margin: "0 0 0 auto",
|
|
592
593
|
color: "secondary",
|
|
@@ -596,31 +597,37 @@ var Alert = function Alert(_ref) {
|
|
|
596
597
|
onClick: handleClose,
|
|
597
598
|
onKeyUp: handleCloseKeyPress,
|
|
598
599
|
"aria-label": "dismiss"
|
|
599
|
-
},
|
|
600
|
+
}, React__default.createElement(Icon, {
|
|
600
601
|
name: "remove",
|
|
601
602
|
"data-testid": "alert-close-icon-test-id"
|
|
602
603
|
})));
|
|
603
|
-
};
|
|
604
|
-
var
|
|
604
|
+
}, [onClose, handleClose, handleCloseKeyPress]);
|
|
605
|
+
var content = useMemo(function () {
|
|
606
|
+
if (render) {
|
|
607
|
+
return render();
|
|
608
|
+
}
|
|
609
|
+
return React__default.createElement(Box, {
|
|
610
|
+
display: "block",
|
|
611
|
+
childGap: message && title ? '2xs' : undefined
|
|
612
|
+
}, title && React__default.createElement(Box, {
|
|
613
|
+
as: "h4",
|
|
614
|
+
fontSize: "sm",
|
|
615
|
+
fontWeight: "semibold",
|
|
616
|
+
className: styles$z['alert-heading']
|
|
617
|
+
}, title), children != null ? children : message && (typeof message === 'string' ? React__default.createElement("p", null, message) : message));
|
|
618
|
+
}, [render, message, title, children]);
|
|
605
619
|
return React__default.createElement(Box, _extends({
|
|
606
620
|
alignItems: "flex-start",
|
|
607
621
|
gap: "md",
|
|
608
622
|
className: alertContainerClasses,
|
|
609
623
|
direction: "row",
|
|
610
|
-
padding: isCompact ? '
|
|
624
|
+
padding: isCompact ? 'md' : '2xl',
|
|
611
625
|
radius: "md",
|
|
612
626
|
role: "alert",
|
|
613
627
|
fontSize: "sm"
|
|
614
|
-
}, restProps),
|
|
615
|
-
display: "block",
|
|
616
|
-
childGap: message && title ? '2xs' : undefined
|
|
617
|
-
}, title && React__default.createElement(Box, {
|
|
618
|
-
as: "h4",
|
|
619
|
-
fontSize: "sm",
|
|
620
|
-
fontWeight: "semibold",
|
|
621
|
-
className: styles$z['alert-heading']
|
|
622
|
-
}, title), message && (typeof message === 'string' ? React__default.createElement("p", null, message) : message))), isClosable && renderCloseIcon());
|
|
628
|
+
}, restProps), alertIcon, React__default.createElement("div", null, content), closeIcon);
|
|
623
629
|
};
|
|
630
|
+
var Alert = /*#__PURE__*/memo(AlertComponent);
|
|
624
631
|
|
|
625
632
|
var AspectRatio = AspectRatioPrimitive.Root;
|
|
626
633
|
|