@mezzanine-ui/react 1.0.0-canary.2 → 1.0.0-canary.3

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.
Files changed (113) hide show
  1. package/AlertBanner/AlertBanner.d.ts +93 -0
  2. package/AlertBanner/AlertBanner.js +135 -0
  3. package/AlertBanner/index.d.ts +2 -0
  4. package/AlertBanner/index.js +1 -0
  5. package/{Overlay/Overlay.d.ts → Backdrop/Backdrop.d.ts} +12 -16
  6. package/Backdrop/Backdrop.js +33 -0
  7. package/Backdrop/index.d.ts +2 -0
  8. package/Backdrop/index.js +1 -0
  9. package/Badge/Badge.d.ts +20 -14
  10. package/Badge/Badge.js +14 -16
  11. package/Badge/BadgeContainer.d.ts +1 -1
  12. package/Badge/BadgeContainer.js +1 -1
  13. package/Badge/index.d.ts +1 -2
  14. package/Badge/typings.d.ts +42 -0
  15. package/Button/Button.js +2 -2
  16. package/Calendar/CalendarContext.js +1 -1
  17. package/DismissButton/DismissButton.d.ts +34 -0
  18. package/DismissButton/DismissButton.js +19 -0
  19. package/DismissButton/index.d.ts +3 -0
  20. package/DismissButton/index.js +5 -0
  21. package/Drawer/Drawer.js +2 -2
  22. package/Dropdown/Dropdown.js +12 -22
  23. package/InlineMessage/InlineMessage.d.ts +33 -0
  24. package/InlineMessage/InlineMessage.js +37 -0
  25. package/InlineMessage/InlineMessageGroup.d.ts +24 -0
  26. package/InlineMessage/InlineMessageGroup.js +21 -0
  27. package/InlineMessage/index.d.ts +4 -0
  28. package/InlineMessage/index.js +2 -0
  29. package/Message/Message.d.ts +4 -2
  30. package/Message/Message.js +85 -8
  31. package/Message/MessageTimerController.d.ts +14 -0
  32. package/Message/MessageTimerController.js +27 -0
  33. package/Modal/Modal.js +2 -2
  34. package/Modal/useModalContainer.d.ts +1 -1
  35. package/Modal/useModalContainer.js +2 -4
  36. package/Navigation/NavigationSubMenu.js +15 -26
  37. package/Notifier/NotifierManager.d.ts +15 -2
  38. package/Notifier/NotifierManager.js +60 -18
  39. package/Notifier/createNotifier.d.ts +9 -0
  40. package/Notifier/createNotifier.js +3 -2
  41. package/Notifier/typings.d.ts +3 -1
  42. package/PageFooter/PageFooter.d.ts +58 -8
  43. package/PageFooter/PageFooter.js +34 -3
  44. package/Popover/Popover.js +4 -8
  45. package/Popper/Popper.d.ts +15 -10
  46. package/Popper/Popper.js +88 -17
  47. package/Popper/index.d.ts +1 -1
  48. package/Portal/Portal.d.ts +13 -5
  49. package/Portal/Portal.js +25 -10
  50. package/Portal/index.d.ts +2 -0
  51. package/Portal/index.js +1 -0
  52. package/Portal/portalRegistry.d.ts +17 -0
  53. package/Portal/portalRegistry.js +99 -0
  54. package/Provider/ConfigProvider.d.ts +1 -0
  55. package/Provider/ConfigProvider.js +1 -0
  56. package/ResultState/ResultState.d.ts +36 -0
  57. package/ResultState/ResultState.js +24 -0
  58. package/ResultState/index.d.ts +2 -0
  59. package/ResultState/index.js +1 -0
  60. package/Skeleton/Skeleton.d.ts +10 -3
  61. package/Skeleton/Skeleton.js +12 -4
  62. package/Spin/Spin.d.ts +39 -0
  63. package/{Loading/Loading.js → Spin/Spin.js} +8 -8
  64. package/Spin/index.d.ts +2 -0
  65. package/Spin/index.js +1 -0
  66. package/Stepper/Step.d.ts +1 -35
  67. package/Stepper/Step.js +43 -10
  68. package/Stepper/Stepper.d.ts +1 -14
  69. package/Stepper/Stepper.js +49 -15
  70. package/Stepper/index.d.ts +3 -2
  71. package/Stepper/index.js +1 -0
  72. package/Stepper/typings.d.ts +77 -0
  73. package/Stepper/useStepDistance.d.ts +10 -0
  74. package/Stepper/useStepDistance.js +81 -0
  75. package/Stepper/useStepper.d.ts +21 -0
  76. package/Stepper/useStepper.js +26 -0
  77. package/Table/Table.js +2 -2
  78. package/Table/TableBody.js +2 -2
  79. package/Tag/Tag.d.ts +2 -25
  80. package/Tag/Tag.js +14 -13
  81. package/Tag/index.d.ts +1 -1
  82. package/Tag/typings.d.ts +79 -0
  83. package/Toggle/Toggle.d.ts +46 -0
  84. package/Toggle/Toggle.js +29 -0
  85. package/Toggle/index.d.ts +3 -0
  86. package/Toggle/index.js +1 -0
  87. package/Tooltip/Tooltip.d.ts +13 -2
  88. package/Tooltip/Tooltip.js +48 -10
  89. package/Tooltip/useDelayMouseEnterLeave.d.ts +1 -2
  90. package/Tooltip/useDelayMouseEnterLeave.js +0 -4
  91. package/Tree/TreeNode.js +5 -5
  92. package/_internal/InputTriggerPopper/InputTriggerPopper.js +14 -24
  93. package/_internal/SlideFadeOverlay/SlideFadeOverlay.d.ts +2 -2
  94. package/_internal/SlideFadeOverlay/SlideFadeOverlay.js +4 -27
  95. package/hooks/useScrollLock.d.ts +28 -0
  96. package/hooks/useScrollLock.js +134 -0
  97. package/index.d.ts +87 -80
  98. package/index.js +74 -69
  99. package/package.json +7 -7
  100. package/utils/get-css-variable-value.d.ts +1 -0
  101. package/utils/get-css-variable-value.js +9 -0
  102. package/Loading/Loading.d.ts +0 -33
  103. package/Loading/index.d.ts +0 -2
  104. package/Loading/index.js +0 -1
  105. package/Overlay/Overlay.js +0 -31
  106. package/Overlay/index.d.ts +0 -2
  107. package/Overlay/index.js +0 -1
  108. package/Switch/Switch.d.ts +0 -43
  109. package/Switch/Switch.js +0 -29
  110. package/Switch/index.d.ts +0 -3
  111. package/Switch/index.js +0 -1
  112. package/utils/scroll-lock.d.ts +0 -2
  113. package/utils/scroll-lock.js +0 -24
@@ -0,0 +1,93 @@
1
+ import type { Key, MouseEvent, ReactElement } from 'react';
2
+ import { AlertBannerSeverity } from '@mezzanine-ui/core/alert-banner';
3
+ import { IconDefinition } from '@mezzanine-ui/icons';
4
+ import { ButtonPropsBase } from '../Button';
5
+ import { Notifier, NotifierConfig, NotifierData } from '../Notifier';
6
+ import { NativeElementPropsWithoutKeyAndRef } from '../utils/jsx-types';
7
+ export interface AlertBannerAction extends Omit<ButtonPropsBase, 'children'> {
8
+ /**
9
+ * The text content of the button.
10
+ */
11
+ content?: string;
12
+ /**
13
+ * Callback when the button is clicked.
14
+ */
15
+ onClick: (event: MouseEvent<HTMLButtonElement>) => void;
16
+ }
17
+ export type AlertBannerConfigProps = NotifierConfig;
18
+ export interface AlertBannerData extends Omit<NotifierData, 'onClose'>, AlertBannerConfigProps {
19
+ /**
20
+ * The action buttons to be rendered on the right side of the banner.
21
+ * Maximum 2 actions, minimum 0 (will not display if empty).
22
+ */
23
+ actions?: AlertBannerAction[];
24
+ /**
25
+ * Whether to show the close button.
26
+ */
27
+ closable?: boolean;
28
+ /**
29
+ * @internal
30
+ */
31
+ createdAt?: number;
32
+ /**
33
+ * Custom icon. Defaults to severity icon when omitted.
34
+ */
35
+ icon?: IconDefinition;
36
+ /**
37
+ * Main message displayed in the banner.
38
+ */
39
+ message: string;
40
+ /**
41
+ * Callback when the banner is closed.
42
+ */
43
+ onClose?: () => void;
44
+ /**
45
+ * The key of alert banner.
46
+ */
47
+ reference?: Key;
48
+ /**
49
+ * The severity of the banner.
50
+ */
51
+ severity: AlertBannerSeverity;
52
+ }
53
+ export interface AlertBannerProps extends Omit<NativeElementPropsWithoutKeyAndRef<'div'>, 'children' | 'title'> {
54
+ /**
55
+ * The action buttons to be rendered on the right side of the banner.
56
+ * Maximum 2 actions, minimum 0 (will not display if empty).
57
+ */
58
+ actions?: AlertBannerAction[];
59
+ /**
60
+ * Whether to show the close button.
61
+ */
62
+ closable?: boolean;
63
+ /**
64
+ * Disable portal rendering. Only used internally by grouped rendering.
65
+ * @internal
66
+ */
67
+ disablePortal?: boolean;
68
+ /**
69
+ * Custom icon. Defaults to severity icon when omitted.
70
+ */
71
+ icon?: IconDefinition;
72
+ /**
73
+ * Main message displayed in the banner.
74
+ */
75
+ message: string;
76
+ /**
77
+ * Callback when the banner is closed.
78
+ */
79
+ onClose?: () => void;
80
+ /**
81
+ * The severity of the banner.
82
+ */
83
+ severity: AlertBannerSeverity;
84
+ }
85
+ export type AlertBannerType = ((props: AlertBannerData) => ReactElement | null) & Notifier<AlertBannerData, AlertBannerConfigProps> & Record<string, (message: AlertBannerData['message'], props?: Omit<AlertBannerData, 'message' | 'severity' | 'icon'> & {
86
+ key?: Key;
87
+ }) => Key>;
88
+ /**
89
+ * The react component for `mezzanine` alert banner.
90
+ */
91
+ export declare const AlertBannerComponent: import("react").ForwardRefExoticComponent<AlertBannerProps & import("react").RefAttributes<HTMLDivElement>>;
92
+ declare const AlertBanner: AlertBannerType;
93
+ export default AlertBanner;
@@ -0,0 +1,135 @@
1
+ 'use client';
2
+ import { jsx, jsxs } from 'react/jsx-runtime';
3
+ import { useCallback, forwardRef, useState, useEffect } from 'react';
4
+ import { alertBannerIcons, alertBannerClasses, alertBannerGroupClasses } from '@mezzanine-ui/core/alert-banner';
5
+ import Button from '../Button/Button.js';
6
+ import DismissButton from '../DismissButton/DismissButton.js';
7
+ import Icon from '../Icon/Icon.js';
8
+ import Portal from '../Portal/Portal.js';
9
+ import cx from 'clsx';
10
+ import { createNotifier } from '../Notifier/createNotifier.js';
11
+
12
+ function getPriority(severity) {
13
+ if (severity === 'info') {
14
+ return 1;
15
+ }
16
+ return 0;
17
+ }
18
+ function sortAlertNotifiers(notifiers) {
19
+ return [...notifiers].sort((a, b) => {
20
+ const priorityDiff = getPriority(a.severity) - getPriority(b.severity);
21
+ if (priorityDiff !== 0) {
22
+ return priorityDiff;
23
+ }
24
+ if (a.createdAt !== b.createdAt) {
25
+ return b.createdAt - a.createdAt;
26
+ }
27
+ return 0;
28
+ });
29
+ }
30
+ /**
31
+ * The react component for `mezzanine` alert banner.
32
+ */
33
+ const AlertBannerComponent = forwardRef(function AlertBanner(props, ref) {
34
+ var _a;
35
+ const { actions, className, closable = true, disablePortal = false, icon, message, onClose, severity, ...rest } = props;
36
+ const [visible, setVisible] = useState(true);
37
+ const handleClose = useCallback(() => {
38
+ setVisible(false);
39
+ if (onClose) {
40
+ onClose();
41
+ }
42
+ }, [onClose]);
43
+ useEffect(() => {
44
+ if (actions && actions.length > 2) {
45
+ console.warn('AlertBanner: actions maximum is 2');
46
+ }
47
+ }, [actions]);
48
+ if (!visible) {
49
+ return null;
50
+ }
51
+ const resolvedIcon = icon !== null && icon !== void 0 ? icon : alertBannerIcons[severity];
52
+ const showCloseButton = closable !== null && closable !== void 0 ? closable : Boolean(onClose);
53
+ const validActions = (_a = actions === null || actions === void 0 ? void 0 : actions.slice(0, 2)) !== null && _a !== void 0 ? _a : []; // Maximum support 2 actions
54
+ const hasActions = validActions.length > 0;
55
+ const actionsArea = hasActions ? (jsx("div", { className: alertBannerClasses.actions, children: validActions.map((action, index) => {
56
+ const { content, onClick, ...buttonProps } = action;
57
+ return (jsx(Button, { onClick: onClick, size: "minor", variant: "inverse", ...buttonProps, children: content }, index));
58
+ }) })) : null;
59
+ const dismissButtonArea = showCloseButton ? (jsx(DismissButton, { className: alertBannerClasses.close, onClick: handleClose, type: "standard", variant: "inverse" })) : null;
60
+ const { maxCount: _maxCount, instanceKey: _instanceKey, ...restProps } = rest;
61
+ const content = (jsxs("div", { ...restProps, ref: ref, "aria-live": "polite", className: cx(alertBannerClasses.host, alertBannerClasses.severity(severity), className), role: "status", children: [jsxs("div", { className: alertBannerClasses.body, children: [jsx(Icon, { className: alertBannerClasses.icon, icon: resolvedIcon }), jsx("span", { className: alertBannerClasses.message, children: message })] }), jsxs("div", { className: alertBannerClasses.controls, children: [actionsArea, dismissButtonArea] })] }));
62
+ if (disablePortal) {
63
+ return content;
64
+ }
65
+ return jsx(Portal, { layer: "alert", children: content });
66
+ });
67
+ const AlertBanner = ((props) => {
68
+ const { message, reference, onClose: onCloseProp, maxCount: _maxCount, createdAt: _createdAt, ...restProps } = props;
69
+ const onClose = useCallback(() => {
70
+ if (onCloseProp) {
71
+ onCloseProp();
72
+ }
73
+ if (reference) {
74
+ AlertBanner.remove(reference);
75
+ }
76
+ }, [onCloseProp, reference]);
77
+ return (jsx(AlertBannerComponent, { ...restProps, message: message, onClose: onClose }));
78
+ });
79
+ function initializeAlertBannerNotifier() {
80
+ const notifier = createNotifier({
81
+ maxCount: undefined,
82
+ render: (notifierProps) => {
83
+ const { key, reference: _reference, onClose: onCloseProp, createdAt: _createdAt, ...restProps } = notifierProps;
84
+ return (jsx(AlertBannerComponent, { ...restProps, disablePortal: true, onClose: () => {
85
+ if (onCloseProp) {
86
+ onCloseProp();
87
+ }
88
+ notifier.remove(key);
89
+ } }));
90
+ },
91
+ renderContainer: (children) => (jsx(Portal, { layer: "alert", children: jsx("div", { className: alertBannerGroupClasses.host, children: children }) })),
92
+ sortBeforeUpdate: sortAlertNotifiers,
93
+ });
94
+ return notifier;
95
+ }
96
+ const alertBannerNotifier = initializeAlertBannerNotifier();
97
+ AlertBanner.add = (notifier) => {
98
+ var _a;
99
+ return alertBannerNotifier.add({
100
+ ...notifier,
101
+ createdAt: (_a = notifier.createdAt) !== null && _a !== void 0 ? _a : Date.now(),
102
+ });
103
+ };
104
+ AlertBanner.config = alertBannerNotifier.config;
105
+ AlertBanner.destroy = alertBannerNotifier.destroy;
106
+ AlertBanner.remove = alertBannerNotifier.remove;
107
+ AlertBanner.getConfig = alertBannerNotifier.getConfig;
108
+ const severities = [
109
+ // support severity: info, warning, error
110
+ {
111
+ key: 'info',
112
+ icon: alertBannerIcons.info,
113
+ },
114
+ {
115
+ key: 'warning',
116
+ icon: alertBannerIcons.warning,
117
+ },
118
+ {
119
+ key: 'error',
120
+ icon: alertBannerIcons.error,
121
+ },
122
+ ];
123
+ const validSeverities = ['info', 'warning', 'error'];
124
+ severities.forEach((severity) => {
125
+ AlertBanner[severity.key] = (message, props) => AlertBanner.add({
126
+ ...props,
127
+ message,
128
+ severity: validSeverities.includes(severity.key)
129
+ ? severity.key
130
+ : 'info',
131
+ icon: severity.icon,
132
+ });
133
+ });
134
+
135
+ export { AlertBannerComponent, AlertBanner as default };
@@ -0,0 +1,2 @@
1
+ export { default } from './AlertBanner';
2
+ export type { AlertBannerProps } from './AlertBanner';
@@ -0,0 +1 @@
1
+ export { default } from './AlertBanner.js';
@@ -1,22 +1,18 @@
1
1
  import { MouseEventHandler } from 'react';
2
+ import { BackdropVariant } from '@mezzanine-ui/core/backdrop';
2
3
  import { NativeElementPropsWithoutKeyAndRef } from '../utils/jsx-types';
3
4
  import { PortalProps } from '../Portal';
4
- export interface OverlayProps extends Pick<PortalProps, 'children' | 'container' | 'disablePortal'>, NativeElementPropsWithoutKeyAndRef<'div'> {
5
+ export interface BackdropProps extends Pick<PortalProps, 'children' | 'container' | 'disablePortal'>, NativeElementPropsWithoutKeyAndRef<'div'> {
5
6
  /**
6
7
  * Controls whether to disable closing element while backdrop clicked.
7
8
  * @default false
8
9
  */
9
10
  disableCloseOnBackdropClick?: boolean;
10
11
  /**
11
- * Whether to hide backdrop.
12
+ * Controls whether to disable scroll locking when backdrop is open.
12
13
  * @default false
13
14
  */
14
- hideBackdrop?: boolean;
15
- /**
16
- * Whether to set backdrop invisible
17
- * @default false
18
- */
19
- invisibleBackdrop?: boolean;
15
+ disableScrollLock?: boolean;
20
16
  /**
21
17
  * Click handler for backdrop.
22
18
  */
@@ -25,19 +21,19 @@ export interface OverlayProps extends Pick<PortalProps, 'children' | 'container'
25
21
  * Callback fired while the element will be closed.
26
22
  */
27
23
  onClose?: VoidFunction;
28
- /**
29
- * Overlay is use on top of a component(surface)
30
- * @default false
31
- */
32
- onSurface?: boolean;
33
24
  /**
34
25
  * Controls whether to show the element.
35
26
  * @default false
36
27
  */
37
28
  open?: boolean;
29
+ /**
30
+ * The variant of backdrop.
31
+ * @default 'dark'
32
+ */
33
+ variant?: BackdropVariant;
38
34
  }
39
35
  /**
40
- * The react component for `mezzanine` overlay.
36
+ * The react component for `mezzanine` backdrop.
41
37
  */
42
- declare const Overlay: import("react").ForwardRefExoticComponent<OverlayProps & import("react").RefAttributes<HTMLDivElement>>;
43
- export default Overlay;
38
+ declare const Backdrop: import("react").ForwardRefExoticComponent<BackdropProps & import("react").RefAttributes<HTMLDivElement>>;
39
+ export default Backdrop;
@@ -0,0 +1,33 @@
1
+ 'use client';
2
+ import { jsx, jsxs } from 'react/jsx-runtime';
3
+ import { forwardRef } from 'react';
4
+ import { backdropClasses } from '@mezzanine-ui/core/backdrop';
5
+ import { useScrollLock } from '../hooks/useScrollLock.js';
6
+ import Portal from '../Portal/Portal.js';
7
+ import Fade from '../Transition/Fade.js';
8
+ import cx from 'clsx';
9
+
10
+ /**
11
+ * The react component for `mezzanine` backdrop.
12
+ */
13
+ const Backdrop = forwardRef(function Backdrop(props, ref) {
14
+ const { children, className, container, disableCloseOnBackdropClick = false, disablePortal, disableScrollLock = false, onBackdropClick, onClose, open = false, variant = 'dark', ...rest } = props;
15
+ // Lock body scroll when backdrop is open
16
+ useScrollLock({ enabled: open && !disableScrollLock });
17
+ // When using custom container or disablePortal, overlay should be absolutely positioned
18
+ // When using default Portal (to #mzn-portal-container), overlay uses relative positioning
19
+ const applyAbsolutePosition = Boolean(disablePortal || container);
20
+ return (jsx(Portal, { container: container, disablePortal: disablePortal, layer: "default", children: jsxs("div", { ...rest, ref: ref, "aria-hidden": !open, className: cx(backdropClasses.host, {
21
+ [backdropClasses.hostAbsolute]: applyAbsolutePosition,
22
+ [backdropClasses.hostOpen]: open,
23
+ }, className), role: "presentation", children: [jsx(Fade, { in: open, children: jsx("div", { "aria-hidden": "true", className: cx(backdropClasses.backdrop, backdropClasses.backdropVariant(variant)), onClick: (event) => {
24
+ if (!disableCloseOnBackdropClick && onClose) {
25
+ onClose();
26
+ }
27
+ if (onBackdropClick) {
28
+ onBackdropClick(event);
29
+ }
30
+ } }) }), jsx("div", { className: backdropClasses.content, children: children })] }) }));
31
+ });
32
+
33
+ export { Backdrop as default };
@@ -0,0 +1,2 @@
1
+ export type { BackdropProps } from './Backdrop';
2
+ export { default } from './Backdrop';
@@ -0,0 +1 @@
1
+ export { default } from './Backdrop.js';
package/Badge/Badge.d.ts CHANGED
@@ -1,18 +1,24 @@
1
- import { NativeElementPropsWithoutKeyAndRef } from '../utils/jsx-types';
2
- export interface BadgeProps extends Omit<NativeElementPropsWithoutKeyAndRef<'span'>, 'color'> {
3
- /**
4
- * It `true`, ignore passed children and display as a dot.
5
- * @default false
6
- */
7
- dot?: boolean;
8
- /**
9
- * If the children is number and greater than overflowCount, it will show overflowCount suffixed with a "+".
10
- * @default 99
11
- */
12
- overflowCount?: number;
13
- }
1
+ import { BadgeCountVariant } from '@mezzanine-ui/core/badge';
14
2
  /**
15
3
  * The react component for `mezzanine` badge.
16
4
  */
17
- declare const Badge: import("react").ForwardRefExoticComponent<BadgeProps & import("react").RefAttributes<HTMLSpanElement>>;
5
+ declare const Badge: import("react").ForwardRefExoticComponent<(Omit<Omit<NativeElementPropsWithoutKeyAndRef<"span">, "children"> & {
6
+ children?: never;
7
+ count: number;
8
+ overflowCount?: number;
9
+ text?: never;
10
+ variant: BadgeCountVariant;
11
+ }, "ref"> | Omit<Omit<NativeElementPropsWithoutKeyAndRef<"span">, "children"> & {
12
+ children?: never;
13
+ count?: never;
14
+ overflowCount?: never;
15
+ text?: string;
16
+ variant: import("@mezzanine-ui/core/badge").BadgeDotVariant;
17
+ }, "ref"> | Omit<Omit<NativeElementPropsWithoutKeyAndRef<"span">, "children"> & {
18
+ children?: import("react").ReactNode;
19
+ count?: never;
20
+ overflowCount?: never;
21
+ text?: never;
22
+ variant: import("@mezzanine-ui/core/badge").BadgeDotVariant;
23
+ }, "ref">) & import("react").RefAttributes<HTMLSpanElement>>;
18
24
  export default Badge;
package/Badge/Badge.js CHANGED
@@ -1,27 +1,25 @@
1
- import { jsx } from 'react/jsx-runtime';
1
+ import { jsxs, jsx } from 'react/jsx-runtime';
2
2
  import { forwardRef } from 'react';
3
3
  import { badgeClasses } from '@mezzanine-ui/core/badge';
4
4
  import cx from 'clsx';
5
5
 
6
+ const isCountVariant = (variant) => [
7
+ 'count-alert',
8
+ 'count-inactive',
9
+ 'count-inverse',
10
+ 'count-brand',
11
+ 'count-info',
12
+ ].includes(variant);
6
13
  /**
7
14
  * The react component for `mezzanine` badge.
8
15
  */
9
16
  const Badge = forwardRef(function Badge(props, ref) {
10
- const { children: childrenProp, className, dot = false, overflowCount = 99, ...rest } = props;
11
- let children;
12
- if (!dot) {
13
- if (typeof childrenProp === 'number') {
14
- const count = childrenProp;
15
- children = count > overflowCount ? `${overflowCount}+` : count;
16
- }
17
- else {
18
- children = childrenProp;
19
- }
20
- }
21
- return (jsx("span", { ...rest, ref: ref, className: cx(badgeClasses.host, {
22
- [badgeClasses.dot]: dot,
23
- [badgeClasses.hide]: !dot && children === 0,
24
- }, className), children: children }));
17
+ const { children, count, className, overflowCount, text, variant, ...rest } = props;
18
+ return (jsxs("div", { className: badgeClasses.container(!!children), children: [jsx("span", { ...rest, ref: ref, className: cx(badgeClasses.host, badgeClasses.variant(variant), { [badgeClasses.hide]: isCountVariant(variant) && count === 0 }, className), children: isCountVariant(variant)
19
+ ? overflowCount && count > overflowCount
20
+ ? `${overflowCount}+`
21
+ : count
22
+ : text }), children] }));
25
23
  });
26
24
 
27
25
  export { Badge as default };
@@ -1,7 +1,7 @@
1
1
  import { NativeElementPropsWithoutKeyAndRef } from '../utils/jsx-types';
2
2
  export type BadgeContainerProps = NativeElementPropsWithoutKeyAndRef<'span'>;
3
3
  /**
4
- * The react component for `mezzanine` badge container.
4
+ * @deprecated Use `Badge` component instead.
5
5
  */
6
6
  declare const BadgeContainer: import("react").ForwardRefExoticComponent<BadgeContainerProps & import("react").RefAttributes<HTMLSpanElement>>;
7
7
  export default BadgeContainer;
@@ -4,7 +4,7 @@ import { badgeClasses } from '@mezzanine-ui/core/badge';
4
4
  import cx from 'clsx';
5
5
 
6
6
  /**
7
- * The react component for `mezzanine` badge container.
7
+ * @deprecated Use `Badge` component instead.
8
8
  */
9
9
  const BadgeContainer = forwardRef(function BadgeContainer(props, ref) {
10
10
  const { children, className, ...rest } = props;
package/Badge/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- export type { BadgeProps } from './Badge';
1
+ export type { BadgeProps } from './typings';
2
2
  export { default } from './Badge';
3
3
  export { default as BadgeContainer } from './BadgeContainer';
4
- export type { BadgeContainerProps } from './BadgeContainer';
@@ -0,0 +1,42 @@
1
+ import { BadgeCountVariant, BadgeDotVariant } from '@mezzanine-ui/core/badge';
2
+ import { ReactNode } from 'react';
3
+ import { NativeElementPropsWithoutKeyAndRef } from 'react/src/utils/jsx-types';
4
+ export type BadgeProps = Omit<NativeElementPropsWithoutKeyAndRef<'span'>, 'children'> & BadgeVariantProps;
5
+ type BadgeVariantProps = BadgeCountProps | BadgeDotWithTextProps | BadgeDotProps;
6
+ type BadgeCountProps = {
7
+ /** Badge renders internally, so children is disabled for count badges. */
8
+ children?: never;
9
+ /** Base number rendered inside the badge when using the count variant. */
10
+ count: number;
11
+ /**
12
+ * If the children is number and greater than overflowCount, it will show overflowCount suffixed with a "+".
13
+ * Only available on count badge.
14
+ */
15
+ overflowCount?: number;
16
+ /** Additional label is not supported for count badges. */
17
+ text?: never;
18
+ /** Controls the visual style (dot vs count variants) and enables the related overflow/hide rules. */
19
+ variant: BadgeCountVariant;
20
+ };
21
+ type BadgeDotWithTextProps = {
22
+ /** Dot badges with text do not render children content. */
23
+ children?: never;
24
+ /** Count is disabled when rendering dot badges. */
25
+ count?: never;
26
+ /** Overflow handling is only meaningful in count mode. */
27
+ overflowCount?: never;
28
+ /** Optional string displayed next to the dot badge. */
29
+ text?: string;
30
+ variant: BadgeDotVariant;
31
+ };
32
+ type BadgeDotProps = {
33
+ /** Content rendered next to the dot badge, commonly an anchor or icon. */
34
+ children?: ReactNode;
35
+ /** Count is disabled when rendering dot badges. */
36
+ count?: never;
37
+ /** Overflow handling is only meaningful in count mode. */
38
+ overflowCount?: never;
39
+ text?: never;
40
+ variant: BadgeDotVariant;
41
+ };
42
+ export {};
package/Button/Button.js CHANGED
@@ -17,14 +17,14 @@ const Button = forwardRef(function Button(props, ref) {
17
17
  const hasLeadingIcon = (icon === null || icon === void 0 ? void 0 : icon.position) === 'leading' && !isIconOnly;
18
18
  const hasTrailingIcon = (icon === null || icon === void 0 ? void 0 : icon.position) === 'trailing' && !isIconOnly;
19
19
  // Loading 狀態下的 icon
20
- const loadingIcon = jsx(Icon, { icon: SpinnerIcon, spin: true });
20
+ const loadingIcon = jsx(Icon, { icon: SpinnerIcon, spin: true, size: 16 });
21
21
  // 渲染 icon 內容
22
22
  const renderIcon = () => {
23
23
  if (loading) {
24
24
  return loadingIcon;
25
25
  }
26
26
  if (icon) {
27
- return jsx(Icon, { icon: icon.src });
27
+ return jsx(Icon, { icon: icon.src, size: 16 });
28
28
  }
29
29
  return null;
30
30
  };
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
  import { jsx } from 'react/jsx-runtime';
3
- import { createContext, useContext, useMemo } from 'react';
3
+ import { createContext, useMemo, useContext } from 'react';
4
4
 
5
5
  const CalendarContext = createContext(undefined);
6
6
  function useCalendarContext() {
@@ -0,0 +1,34 @@
1
+ import { DismissButtonEmbeddedVariant, DismissButtonStandardVariant } from '@mezzanine-ui/core/dismiss-button';
2
+ import { NativeElementPropsWithoutKeyAndRef } from '../utils/jsx-types';
3
+ type DismissButtonCommonProps = Omit<NativeElementPropsWithoutKeyAndRef<'button'>, 'onClick' | 'type'> & {
4
+ /**
5
+ * Called when user clicks or activates the button (via mouse or keyboard).
6
+ */
7
+ onClick?: React.MouseEventHandler<HTMLButtonElement>;
8
+ };
9
+ type DismissButtonStandardProps = DismissButtonCommonProps & {
10
+ /**
11
+ * Dismiss Button Contextual type.
12
+ */
13
+ type?: 'standard';
14
+ /**
15
+ * Visual variant for standard type.
16
+ */
17
+ variant?: DismissButtonStandardVariant;
18
+ };
19
+ type DismissButtonEmbeddedProps = DismissButtonCommonProps & {
20
+ /**
21
+ * Dismiss Button Contextual type.
22
+ */
23
+ type: 'embedded';
24
+ /**
25
+ * Visual variant for embedded type.
26
+ */
27
+ variant?: DismissButtonEmbeddedVariant;
28
+ };
29
+ export type DismissButtonProps = DismissButtonEmbeddedProps | DismissButtonStandardProps;
30
+ /**
31
+ * Mezzanine dismiss/close button.
32
+ */
33
+ declare const DismissButton: import("react").ForwardRefExoticComponent<DismissButtonProps & import("react").RefAttributes<HTMLButtonElement>>;
34
+ export default DismissButton;
@@ -0,0 +1,19 @@
1
+ 'use client';
2
+ import { jsx } from 'react/jsx-runtime';
3
+ import { forwardRef } from 'react';
4
+ import { CloseIcon } from '@mezzanine-ui/icons';
5
+ import { dismissButtonClasses } from '@mezzanine-ui/core/dismiss-button';
6
+ import Icon from '../Icon/Icon.js';
7
+ import cx from 'clsx';
8
+
9
+ /**
10
+ * Mezzanine dismiss/close button.
11
+ */
12
+ const DismissButton = forwardRef(function DismissButton(props, ref) {
13
+ const { className, onClick, type: typeProp, variant, ...rest } = props;
14
+ const type = typeProp !== null && typeProp !== void 0 ? typeProp : 'standard';
15
+ const resolvedVariant = variant !== null && variant !== void 0 ? variant : (type === 'standard' ? 'base' : 'contrast');
16
+ return (jsx("button", { ...rest, ref: ref, "aria-label": "Close", className: cx(dismissButtonClasses.host, dismissButtonClasses.type(type), dismissButtonClasses.variant(resolvedVariant), className), onClick: onClick, type: "button", children: jsx(Icon, { className: dismissButtonClasses.icon, icon: CloseIcon }) }));
17
+ });
18
+
19
+ export { DismissButton as default };
@@ -0,0 +1,3 @@
1
+ import DismissButton from './DismissButton';
2
+ export type { DismissButtonProps } from './DismissButton';
3
+ export default DismissButton;
@@ -0,0 +1,5 @@
1
+ import DismissButton from './DismissButton.js';
2
+
3
+
4
+
5
+ export { DismissButton as default };
package/Drawer/Drawer.js CHANGED
@@ -5,14 +5,14 @@ import SlideFadeOverlay from '../_internal/SlideFadeOverlay/SlideFadeOverlay.js'
5
5
  import cx from 'clsx';
6
6
 
7
7
  const Drawer = forwardRef((props, ref) => {
8
- const { className, children, container, disableCloseOnBackdropClick = false, disableCloseOnEscapeKeyDown = false, disablePortal, hideBackdrop, invisibleBackdrop, onBackdropClick, onClose, open, placement = 'left', ...rest } = props;
8
+ const { className, children, container, disableCloseOnBackdropClick = false, disableCloseOnEscapeKeyDown = false, disablePortal, onBackdropClick, onClose, open, placement = 'left', ...rest } = props;
9
9
  const slideFadeDirection = useMemo(() => ({
10
10
  top: 'down',
11
11
  left: 'right',
12
12
  right: 'left',
13
13
  bottom: 'up',
14
14
  }), []);
15
- return (jsx(SlideFadeOverlay, { className: drawerClasses.overlay, container: container, direction: slideFadeDirection[placement], disableCloseOnBackdropClick: disableCloseOnBackdropClick, disableCloseOnEscapeKeyDown: disableCloseOnEscapeKeyDown, disablePortal: disablePortal, hideBackdrop: hideBackdrop, invisibleBackdrop: invisibleBackdrop, onBackdropClick: onBackdropClick, onClose: onClose, open: open, ref: ref, children: jsx("div", { ...rest, className: cx(drawerClasses.host, drawerClasses[placement], className), children: children }) }));
15
+ return (jsx(SlideFadeOverlay, { className: drawerClasses.overlay, container: container, direction: slideFadeDirection[placement], disableCloseOnBackdropClick: disableCloseOnBackdropClick, disableCloseOnEscapeKeyDown: disableCloseOnEscapeKeyDown, disablePortal: disablePortal, onBackdropClick: onBackdropClick, onClose: onClose, open: open, ref: ref, children: jsx("div", { ...rest, className: cx(drawerClasses.host, drawerClasses[placement], className), children: children }) }));
16
16
  });
17
17
 
18
18
  export { Drawer as default };
@@ -1,29 +1,19 @@
1
1
  import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
2
2
  import { forwardRef, useRef } from 'react';
3
+ import { size } from '@floating-ui/react-dom';
3
4
  import { useClickAway } from '../hooks/useClickAway.js';
4
5
  import { useComposeRefs } from '../hooks/useComposeRefs.js';
5
6
  import Popper from '../Popper/Popper.js';
6
7
 
7
- const popperOptions = {
8
- modifiers: [
9
- {
10
- name: 'sameWidth',
11
- enabled: true,
12
- phase: 'beforeWrite',
13
- requires: ['computeStyles'],
14
- fn: ({ state }) => {
15
- const reassignState = state;
16
- reassignState.styles.popper.width = 'auto';
17
- reassignState.styles.popper.minWidth = `${state.rects.reference.width}px`;
18
- },
19
- effect: ({ state }) => {
20
- const reassignState = state;
21
- reassignState.elements.popper.style.width = 'auto';
22
- reassignState.elements.popper.style.minWidth = `${state.elements.reference.getBoundingClientRect().width}px`;
23
- },
24
- },
25
- ],
26
- };
8
+ // Middleware to make the dropdown menu have the same width as the reference element
9
+ const sameWidthMiddleware = size({
10
+ apply({ rects, elements }) {
11
+ Object.assign(elements.floating.style, {
12
+ width: 'auto',
13
+ minWidth: `${rects.reference.width}px`,
14
+ });
15
+ },
16
+ });
27
17
  const Dropdown = forwardRef(function Dropdown(props, ref) {
28
18
  var _a;
29
19
  const { children, disableClickAway = false, menu, onClose, popperProps, ...rest } = props;
@@ -31,7 +21,7 @@ const Dropdown = forwardRef(function Dropdown(props, ref) {
31
21
  const popperRef = useRef(null);
32
22
  const composedRef = useComposeRefs([ref, popperRef]);
33
23
  const open = popperProps === null || popperProps === void 0 ? void 0 : popperProps.open;
34
- const modifiers = ((_a = popperProps === null || popperProps === void 0 ? void 0 : popperProps.options) === null || _a === void 0 ? void 0 : _a.modifiers) || [];
24
+ const middleware = ((_a = popperProps === null || popperProps === void 0 ? void 0 : popperProps.options) === null || _a === void 0 ? void 0 : _a.middleware) || [];
35
25
  useClickAway(() => {
36
26
  if (!open || disableClickAway || !onClose) {
37
27
  return;
@@ -45,7 +35,7 @@ const Dropdown = forwardRef(function Dropdown(props, ref) {
45
35
  return (jsxs(Fragment, { children: [children(anchor), jsx(Popper, { ...popperProps, ref: composedRef, ...rest, anchor: anchor, options: {
46
36
  placement: 'top-start',
47
37
  ...popperProps === null || popperProps === void 0 ? void 0 : popperProps.options,
48
- modifiers: [...(popperOptions.modifiers || []), ...modifiers],
38
+ middleware: [sameWidthMiddleware, ...middleware],
49
39
  }, children: menu })] }));
50
40
  });
51
41