@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,29 +1,20 @@
|
|
|
1
|
-
import {
|
|
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:
|
|
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
|
-
|
|
7
|
-
export declare const
|
|
8
|
-
export declare const
|
|
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
|
|
2
|
+
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
4
3
|
declare const meta: Meta<typeof Badge>;
|
|
5
4
|
export default meta;
|
|
6
|
-
|
|
7
|
-
export declare const
|
|
8
|
-
export declare const
|
|
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
|
-
|
|
7
|
-
export declare const
|
|
8
|
-
export declare const
|
|
9
|
-
export declare const
|
|
10
|
-
export declare const
|
|
11
|
-
export declare const
|
|
12
|
-
export declare const
|
|
13
|
-
export declare const
|
|
14
|
-
export declare const
|
|
15
|
-
export declare const
|
|
16
|
-
export declare const
|
|
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 = ["
|
|
580
|
-
var
|
|
581
|
-
var
|
|
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
|
|
598
|
+
var handleClose = React.useCallback(function (event) {
|
|
603
599
|
if (!onClose) return;
|
|
604
600
|
onClose(event);
|
|
605
|
-
};
|
|
606
|
-
var
|
|
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
|
|
616
|
-
|
|
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
|
-
},
|
|
629
|
+
}, React.createElement(Icon, {
|
|
629
630
|
name: "remove",
|
|
630
631
|
"data-testid": "alert-close-icon-test-id"
|
|
631
632
|
})));
|
|
632
|
-
};
|
|
633
|
-
var
|
|
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 ? '
|
|
653
|
+
padding: isCompact ? 'md' : '2xl',
|
|
640
654
|
radius: "md",
|
|
641
655
|
role: "alert",
|
|
642
656
|
fontSize: "sm"
|
|
643
|
-
}, restProps),
|
|
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
|
|