@metamask/design-system-react 0.36.0 → 0.37.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/CHANGELOG.md +20 -1
- package/dist/components/BannerBase/BannerBase.cjs +84 -8
- package/dist/components/BannerBase/BannerBase.cjs.map +1 -1
- package/dist/components/BannerBase/BannerBase.d.cts +2 -0
- package/dist/components/BannerBase/BannerBase.d.cts.map +1 -1
- package/dist/components/BannerBase/BannerBase.d.mts +2 -0
- package/dist/components/BannerBase/BannerBase.d.mts.map +1 -1
- package/dist/components/BannerBase/BannerBase.mjs +85 -9
- package/dist/components/BannerBase/BannerBase.mjs.map +1 -1
- package/dist/components/Checkbox/Checkbox.cjs +1 -1
- package/dist/components/Checkbox/Checkbox.cjs.map +1 -1
- package/dist/components/Checkbox/Checkbox.mjs +1 -1
- package/dist/components/Checkbox/Checkbox.mjs.map +1 -1
- package/dist/components/Toast/Toast.types.cjs.map +1 -1
- package/dist/components/Toast/Toast.types.d.cts +6 -0
- package/dist/components/Toast/Toast.types.d.cts.map +1 -1
- package/dist/components/Toast/Toast.types.d.mts +6 -0
- package/dist/components/Toast/Toast.types.d.mts.map +1 -1
- package/dist/components/Toast/Toast.types.mjs.map +1 -1
- package/dist/components/Toast/Toaster.cjs +9 -5
- package/dist/components/Toast/Toaster.cjs.map +1 -1
- package/dist/components/Toast/Toaster.d.cts.map +1 -1
- package/dist/components/Toast/Toaster.d.mts.map +1 -1
- package/dist/components/Toast/Toaster.mjs +9 -5
- package/dist/components/Toast/Toaster.mjs.map +1 -1
- package/dist/components/index.cjs +1 -4
- package/dist/components/index.cjs.map +1 -1
- package/dist/components/index.d.cts +0 -1
- package/dist/components/index.d.cts.map +1 -1
- package/dist/components/index.d.mts +0 -1
- package/dist/components/index.d.mts.map +1 -1
- package/dist/components/index.mjs +0 -1
- package/dist/components/index.mjs.map +1 -1
- package/package.json +2 -2
- package/dist/components/PureBlackProvider/PureBlackProvider.cjs +0 -65
- package/dist/components/PureBlackProvider/PureBlackProvider.cjs.map +0 -1
- package/dist/components/PureBlackProvider/PureBlackProvider.d.cts +0 -33
- package/dist/components/PureBlackProvider/PureBlackProvider.d.cts.map +0 -1
- package/dist/components/PureBlackProvider/PureBlackProvider.d.mts +0 -33
- package/dist/components/PureBlackProvider/PureBlackProvider.d.mts.map +0 -1
- package/dist/components/PureBlackProvider/PureBlackProvider.mjs +0 -44
- package/dist/components/PureBlackProvider/PureBlackProvider.mjs.map +0 -1
- package/dist/components/PureBlackProvider/index.cjs +0 -7
- package/dist/components/PureBlackProvider/index.cjs.map +0 -1
- package/dist/components/PureBlackProvider/index.d.cts +0 -2
- package/dist/components/PureBlackProvider/index.d.cts.map +0 -1
- package/dist/components/PureBlackProvider/index.d.mts +0 -2
- package/dist/components/PureBlackProvider/index.d.mts.map +0 -1
- package/dist/components/PureBlackProvider/index.mjs +0 -2
- package/dist/components/PureBlackProvider/index.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.37.0]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Added `showCloseButton` to `ToastOptions` for the imperative `toast(...)` API (default `true`); when `false`, the close button is hidden while auto-dismiss and `toast.dismiss()` still work ([#1446](https://github.com/MetaMask/metamask-design-system/pull/1446))
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
|
|
18
|
+
- Updated `BannerBase` to center-align compact content (title-only, description-only, or title with a single-line description or string children) and top-align multi-line stacks, custom React node children, or below-action layouts; inherited by `BannerAlert` and `Toast` ([#1447](https://github.com/MetaMask/metamask-design-system/pull/1447))
|
|
19
|
+
- **BREAKING:** Removed `PureBlackProvider` and `usePureBlack` exports ([#1450](https://github.com/MetaMask/metamask-design-system/pull/1450))
|
|
20
|
+
- Remove `PureBlackProvider` wrapping and `data-pure-black` on the document root
|
|
21
|
+
- Use semantic elevated tokens (`BackgroundElevated1`, `BackgroundElevated2`, `BorderAlternative`) for stepped surfaces instead of pure-black branching
|
|
22
|
+
- See [Migration Guide](./MIGRATION.md#from-version-0360-to-0370)
|
|
23
|
+
|
|
24
|
+
### Fixed
|
|
25
|
+
|
|
26
|
+
- Fixed `Checkbox` unselected state to use a transparent background instead of `background.default` ([#1451](https://github.com/MetaMask/metamask-design-system/pull/1451))
|
|
27
|
+
|
|
10
28
|
## [0.36.0]
|
|
11
29
|
|
|
12
30
|
### Added
|
|
@@ -479,7 +497,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
479
497
|
- Full TypeScript support with type definitions and enums
|
|
480
498
|
- Tailwind CSS integration with design token support
|
|
481
499
|
|
|
482
|
-
[Unreleased]: https://github.com/MetaMask/metamask-design-system/compare/@metamask/design-system-react@0.
|
|
500
|
+
[Unreleased]: https://github.com/MetaMask/metamask-design-system/compare/@metamask/design-system-react@0.37.0...HEAD
|
|
501
|
+
[0.37.0]: https://github.com/MetaMask/metamask-design-system/compare/@metamask/design-system-react@0.36.0...@metamask/design-system-react@0.37.0
|
|
483
502
|
[0.36.0]: https://github.com/MetaMask/metamask-design-system/compare/@metamask/design-system-react@0.35.2...@metamask/design-system-react@0.36.0
|
|
484
503
|
[0.35.2]: https://github.com/MetaMask/metamask-design-system/compare/@metamask/design-system-react@0.35.1...@metamask/design-system-react@0.35.2
|
|
485
504
|
[0.35.1]: https://github.com/MetaMask/metamask-design-system/compare/@metamask/design-system-react@0.35.0...@metamask/design-system-react@0.35.1
|
|
@@ -31,27 +31,103 @@ const Box_1 = require("../Box/index.cjs");
|
|
|
31
31
|
const Button_1 = require("../Button/index.cjs");
|
|
32
32
|
const ButtonIcon_1 = require("../ButtonIcon/index.cjs");
|
|
33
33
|
const Text_1 = require("../Text/index.cjs");
|
|
34
|
+
/** BodyMd line height — title block (`typography.sBodyMD.lineHeight`). */
|
|
35
|
+
const BODY_MD_LINE_HEIGHT = 24;
|
|
36
|
+
/** BodySm line height — description block (`typography.sBodySM.lineHeight`). */
|
|
37
|
+
const BODY_SM_LINE_HEIGHT = 22;
|
|
38
|
+
/** `mt-0.5` between title and description. */
|
|
39
|
+
const TITLE_DESCRIPTION_GAP = 2;
|
|
40
|
+
/** Sub-pixel / font rounding allowance when comparing stack height. */
|
|
41
|
+
const COMPACT_HEIGHT_TOLERANCE = 4;
|
|
34
42
|
const isTextContent = (content) => typeof content === 'string' || typeof content === 'number';
|
|
35
43
|
const hasContent = (content) => content !== null && content !== undefined;
|
|
36
|
-
|
|
44
|
+
const getCompactContentMaxHeight = ({ hasTitle, hasDescription, hasChildren, }) => {
|
|
45
|
+
let maxHeight = 0;
|
|
46
|
+
if (hasTitle) {
|
|
47
|
+
maxHeight += BODY_MD_LINE_HEIGHT;
|
|
48
|
+
}
|
|
49
|
+
if (hasDescription) {
|
|
50
|
+
if (hasTitle) {
|
|
51
|
+
maxHeight += TITLE_DESCRIPTION_GAP;
|
|
52
|
+
}
|
|
53
|
+
maxHeight += BODY_SM_LINE_HEIGHT;
|
|
54
|
+
}
|
|
55
|
+
if (hasChildren) {
|
|
56
|
+
maxHeight += BODY_MD_LINE_HEIGHT;
|
|
57
|
+
}
|
|
58
|
+
return maxHeight + COMPACT_HEIGHT_TOLERANCE;
|
|
59
|
+
};
|
|
60
|
+
exports.BannerBase = (0, react_1.forwardRef)(({ title, titleProps, description, descriptionProps, children, childrenWrapperProps, actionButtonLabel, actionButtonOnClick, actionButtonProps, actionButtonLayout = design_system_shared_1.BannerBaseActionButtonLayout.Below, startAccessory, onClose, closeButtonProps, className, backgroundColor = design_system_shared_1.BoxBackgroundColor.BackgroundDefault, ...props }, ref) => {
|
|
37
61
|
const resolvedActionButtonProps = actionButtonProps ?? {};
|
|
38
62
|
const { ariaLabel: closeButtonAriaLabel = 'Close banner', className: closeButtonClassName, ...resolvedCloseButtonProps } = closeButtonProps ?? {};
|
|
39
63
|
const shouldShowCloseButton = Boolean(onClose);
|
|
40
64
|
const shouldShowActionButton = Boolean(actionButtonOnClick);
|
|
41
65
|
const isActionButtonLayoutEnd = actionButtonLayout === design_system_shared_1.BannerBaseActionButtonLayout.End;
|
|
42
66
|
const hasActionButtonBelow = shouldShowActionButton && !isActionButtonLayoutEnd;
|
|
67
|
+
const hasTitle = hasContent(title);
|
|
68
|
+
const hasDescription = hasContent(description);
|
|
69
|
+
const hasChildren = hasContent(children);
|
|
70
|
+
// Custom nodes can't be measured reliably — keep top-aligned.
|
|
71
|
+
const hasUnmeasuredContent = (hasTitle && !isTextContent(title)) ||
|
|
72
|
+
(hasDescription && !isTextContent(description)) ||
|
|
73
|
+
(hasChildren && !isTextContent(children));
|
|
74
|
+
const contentRef = (0, react_1.useRef)(null);
|
|
75
|
+
// Multiple text blocks: default top-aligned until the stack measures as
|
|
76
|
+
// single-line per block. A single title, description, or children block
|
|
77
|
+
// always centers (including wraps).
|
|
78
|
+
const [isCompactContent, setIsCompactContent] = (0, react_1.useState)(false);
|
|
79
|
+
const isSingleTextBlock = [hasTitle, hasDescription, hasChildren].filter(Boolean).length === 1;
|
|
80
|
+
const measureContent = (0, react_1.useCallback)(() => {
|
|
81
|
+
if (hasUnmeasuredContent || hasActionButtonBelow || isSingleTextBlock) {
|
|
82
|
+
setIsCompactContent(false);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const height = contentRef.current?.getBoundingClientRect().height ?? 0;
|
|
86
|
+
const maxCompactHeight = getCompactContentMaxHeight({
|
|
87
|
+
hasTitle,
|
|
88
|
+
hasDescription,
|
|
89
|
+
hasChildren,
|
|
90
|
+
});
|
|
91
|
+
setIsCompactContent(height > 0 && height <= maxCompactHeight);
|
|
92
|
+
}, [
|
|
93
|
+
hasActionButtonBelow,
|
|
94
|
+
hasChildren,
|
|
95
|
+
hasDescription,
|
|
96
|
+
hasTitle,
|
|
97
|
+
hasUnmeasuredContent,
|
|
98
|
+
isSingleTextBlock,
|
|
99
|
+
]);
|
|
100
|
+
(0, react_1.useLayoutEffect)(() => {
|
|
101
|
+
measureContent();
|
|
102
|
+
if (typeof ResizeObserver === 'undefined' || !contentRef.current) {
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
const observer = new ResizeObserver(() => {
|
|
106
|
+
measureContent();
|
|
107
|
+
});
|
|
108
|
+
observer.observe(contentRef.current);
|
|
109
|
+
return () => {
|
|
110
|
+
observer.disconnect();
|
|
111
|
+
};
|
|
112
|
+
}, [title, description, children, measureContent]);
|
|
113
|
+
const isCenterAligned = !hasActionButtonBelow &&
|
|
114
|
+
!hasUnmeasuredContent &&
|
|
115
|
+
(hasTitle || hasDescription || hasChildren) &&
|
|
116
|
+
(isSingleTextBlock || isCompactContent);
|
|
43
117
|
const actionButton = shouldShowActionButton ? (react_1.default.createElement(Button_1.Button, { size: design_system_shared_1.ButtonSize.Md, onClick: actionButtonOnClick, ...resolvedActionButtonProps, variant: design_system_shared_1.ButtonVariant.Secondary }, actionButtonLabel)) : null;
|
|
44
|
-
return (react_1.default.createElement(Box_1.Box, { ref: ref, flexDirection: design_system_shared_1.BoxFlexDirection.Row, alignItems: design_system_shared_1.BoxAlignItems.Start, gap: 4, backgroundColor:
|
|
118
|
+
return (react_1.default.createElement(Box_1.Box, { ...props, ref: ref, flexDirection: design_system_shared_1.BoxFlexDirection.Row, alignItems: isCenterAligned ? design_system_shared_1.BoxAlignItems.Center : design_system_shared_1.BoxAlignItems.Start, gap: 4, backgroundColor: backgroundColor, paddingTop: 3, paddingBottom: hasActionButtonBelow ? 4 : 3, paddingLeft: 4, paddingRight: shouldShowCloseButton ? 2 : 4, className: (0, tw_merge_1.twMerge)('rounded-xl', className) },
|
|
45
119
|
startAccessory,
|
|
46
|
-
react_1.default.createElement(Box_1.Box, { className: "min-w-0 flex-1"
|
|
47
|
-
|
|
120
|
+
react_1.default.createElement(Box_1.Box, { className: "min-w-0 flex-1", ref: (node) => {
|
|
121
|
+
contentRef.current = node;
|
|
122
|
+
} },
|
|
123
|
+
hasTitle &&
|
|
48
124
|
(isTextContent(title) ? (react_1.default.createElement(Text_1.Text, { variant: design_system_shared_1.TextVariant.BodyMd, fontWeight: design_system_shared_1.FontWeight.Medium, ...titleProps }, title)) : (title)),
|
|
49
|
-
|
|
50
|
-
|
|
125
|
+
hasDescription && (react_1.default.createElement(Box_1.Box, { className: hasTitle ? 'mt-0.5' : undefined }, isTextContent(description) ? (react_1.default.createElement(Text_1.Text, { variant: design_system_shared_1.TextVariant.BodySm, ...descriptionProps }, description)) : (description))),
|
|
126
|
+
hasChildren &&
|
|
51
127
|
(isTextContent(children) ? (react_1.default.createElement(Text_1.Text, { variant: design_system_shared_1.TextVariant.BodyMd, ...childrenWrapperProps }, children)) : (children)),
|
|
52
128
|
hasActionButtonBelow && react_1.default.createElement(Box_1.Box, { className: "mt-2" }, actionButton)),
|
|
53
|
-
shouldShowActionButton && isActionButtonLayoutEnd && actionButton,
|
|
54
|
-
shouldShowCloseButton && (react_1.default.createElement(ButtonIcon_1.ButtonIcon, { className: (0, tw_merge_1.twMerge)('-mt-1', closeButtonClassName), iconName: design_system_shared_1.IconName.Close, size: design_system_shared_1.ButtonIconSize.Md, ariaLabel: closeButtonAriaLabel, onClick: onClose, ...resolvedCloseButtonProps }))));
|
|
129
|
+
shouldShowActionButton && isActionButtonLayoutEnd && (react_1.default.createElement(Box_1.Box, { className: "self-center" }, actionButton)),
|
|
130
|
+
shouldShowCloseButton && (react_1.default.createElement(ButtonIcon_1.ButtonIcon, { className: (0, tw_merge_1.twMerge)(!isCenterAligned && '-mt-1', closeButtonClassName), iconName: design_system_shared_1.IconName.Close, size: design_system_shared_1.ButtonIconSize.Md, ariaLabel: closeButtonAriaLabel, onClick: onClose, ...resolvedCloseButtonProps }))));
|
|
55
131
|
});
|
|
56
132
|
exports.BannerBase.displayName = 'BannerBase';
|
|
57
133
|
//# sourceMappingURL=BannerBase.cjs.map
|
|
@@ -1 +1 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MAAM,KAAM,gBAAgB,IACpD,WAAW,CACP,CACR,CAAC,CAAC,CAAC,CACF,WAAW,CACZ,CACG,CACP;YAEA,UAAU,CAAC,QAAQ,CAAC;gBACnB,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CACzB,8BAAC,WAAI,IAAC,OAAO,EAAE,kCAAW,CAAC,MAAM,KAAM,oBAAoB,IACxD,QAAQ,CACJ,CACR,CAAC,CAAC,CAAC,CACF,QAAQ,CACT,CAAC;YAEH,oBAAoB,IAAI,8BAAC,SAAG,IAAC,SAAS,EAAC,MAAM,IAAE,YAAY,CAAO,CAC/D;QAEL,sBAAsB,IAAI,uBAAuB,IAAI,YAAY;QAEjE,qBAAqB,IAAI,CACxB,8BAAC,uBAAU,IACT,SAAS,EAAE,IAAA,kBAAO,EAAC,OAAO,EAAE,oBAAoB,CAAC,EACjD,QAAQ,EAAE,+BAAQ,CAAC,KAAK,EACxB,IAAI,EAAE,qCAAc,CAAC,EAAE,EACvB,SAAS,EAAE,oBAAoB,EAC/B,OAAO,EAAE,OAAO,KACZ,wBAAwB,GAC5B,CACH,CACG,CACP,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,kBAAU,CAAC,WAAW,GAAG,YAAY,CAAC","sourcesContent":["import {\n BannerBaseActionButtonLayout,\n BoxAlignItems,\n BoxBackgroundColor,\n BoxFlexDirection,\n ButtonIconSize,\n ButtonSize,\n ButtonVariant,\n FontWeight,\n IconName,\n TextVariant,\n} from '@metamask/design-system-shared';\nimport React, { forwardRef } from 'react';\n\nimport { twMerge } from '../../utils/tw-merge';\nimport { Box } from '../Box';\nimport { Button } from '../Button';\nimport { ButtonIcon } from '../ButtonIcon';\nimport { Text } from '../Text';\n\nimport type { BannerBaseProps } from './BannerBase.types';\n\nconst isTextContent = (content: React.ReactNode): content is string | number =>\n typeof content === 'string' || typeof content === 'number';\n\nconst hasContent = (content: React.ReactNode) =>\n content !== null && content !== undefined;\n\nexport const BannerBase = forwardRef<HTMLDivElement, BannerBaseProps>(\n (\n {\n title,\n titleProps,\n description,\n descriptionProps,\n children,\n childrenWrapperProps,\n actionButtonLabel,\n actionButtonOnClick,\n actionButtonProps,\n actionButtonLayout = BannerBaseActionButtonLayout.Below,\n startAccessory,\n onClose,\n closeButtonProps,\n className,\n ...props\n },\n ref,\n ) => {\n const resolvedActionButtonProps = actionButtonProps ?? {};\n\n const {\n ariaLabel: closeButtonAriaLabel = 'Close banner',\n className: closeButtonClassName,\n ...resolvedCloseButtonProps\n } = closeButtonProps ?? {};\n\n const shouldShowCloseButton = Boolean(onClose);\n const shouldShowActionButton = Boolean(actionButtonOnClick);\n const isActionButtonLayoutEnd =\n actionButtonLayout === BannerBaseActionButtonLayout.End;\n const hasActionButtonBelow =\n shouldShowActionButton && !isActionButtonLayoutEnd;\n\n const actionButton = shouldShowActionButton ? (\n <Button\n size={ButtonSize.Md}\n onClick={actionButtonOnClick}\n {...resolvedActionButtonProps}\n variant={ButtonVariant.Secondary}\n >\n {actionButtonLabel}\n </Button>\n ) : null;\n\n return (\n <Box\n ref={ref}\n flexDirection={BoxFlexDirection.Row}\n alignItems={BoxAlignItems.Start}\n gap={4}\n backgroundColor={BoxBackgroundColor.BackgroundDefault}\n paddingTop={3}\n paddingBottom={hasActionButtonBelow ? 4 : 3}\n paddingLeft={4}\n paddingRight={shouldShowCloseButton ? 2 : 4}\n className={twMerge('rounded-xl', className)}\n {...props}\n >\n {startAccessory}\n\n <Box className=\"min-w-0 flex-1\">\n {hasContent(title) &&\n (isTextContent(title) ? (\n <Text\n variant={TextVariant.BodyMd}\n fontWeight={FontWeight.Medium}\n {...titleProps}\n >\n {title}\n </Text>\n ) : (\n title\n ))}\n\n {hasContent(description) && (\n <Box className={hasContent(title) ? 'mt-0.5' : undefined}>\n {isTextContent(description) ? (\n <Text variant={TextVariant.BodySm} {...descriptionProps}>\n {description}\n </Text>\n ) : (\n description\n )}\n </Box>\n )}\n\n {hasContent(children) &&\n (isTextContent(children) ? (\n <Text variant={TextVariant.BodyMd} {...childrenWrapperProps}>\n {children}\n </Text>\n ) : (\n children\n ))}\n\n {hasActionButtonBelow && <Box className=\"mt-2\">{actionButton}</Box>}\n </Box>\n\n {shouldShowActionButton && isActionButtonLayoutEnd && actionButton}\n\n {shouldShowCloseButton && (\n <ButtonIcon\n className={twMerge('-mt-1', closeButtonClassName)}\n iconName={IconName.Close}\n size={ButtonIconSize.Md}\n ariaLabel={closeButtonAriaLabel}\n onClick={onClose}\n {...resolvedCloseButtonProps}\n />\n )}\n </Box>\n );\n },\n);\n\nBannerBase.displayName = 'BannerBase';\n"]}
|
|
1
|
+
{"version":3,"file":"BannerBase.cjs","sourceRoot":"","sources":["../../../src/components/BannerBase/BannerBase.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yEAWwC;AACxC,+CAMe;AAEf,uDAA+C;AAC/C,0CAA6B;AAC7B,gDAAmC;AACnC,wDAA2C;AAC3C,4CAA+B;AAI/B,0EAA0E;AAC1E,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAC/B,gFAAgF;AAChF,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAC/B,8CAA8C;AAC9C,MAAM,qBAAqB,GAAG,CAAC,CAAC;AAChC,uEAAuE;AACvE,MAAM,wBAAwB,GAAG,CAAC,CAAC;AAEnC,MAAM,aAAa,GAAG,CAAC,OAAwB,EAA8B,EAAE,CAC7E,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,OAAO,KAAK,QAAQ,CAAC;AAE7D,MAAM,UAAU,GAAG,CAAC,OAAwB,EAAE,EAAE,CAC9C,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,SAAS,CAAC;AAE5C,MAAM,0BAA0B,GAAG,CAAC,EAClC,QAAQ,EACR,cAAc,EACd,WAAW,GAKZ,EAAE,EAAE;IACH,IAAI,SAAS,GAAG,CAAC,CAAC;IAElB,IAAI,QAAQ,EAAE;QACZ,SAAS,IAAI,mBAAmB,CAAC;KACl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AI,EAAE,qCAAc,CAAC,EAAE,EACvB,SAAS,EAAE,oBAAoB,EAC/B,OAAO,EAAE,OAAO,KACZ,wBAAwB,GAC5B,CACH,CACG,CACP,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,kBAAU,CAAC,WAAW,GAAG,YAAY,CAAC","sourcesContent":["import {\n BannerBaseActionButtonLayout,\n BoxAlignItems,\n BoxBackgroundColor,\n BoxFlexDirection,\n ButtonIconSize,\n ButtonSize,\n ButtonVariant,\n FontWeight,\n IconName,\n TextVariant,\n} from '@metamask/design-system-shared';\nimport React, {\n forwardRef,\n useCallback,\n useLayoutEffect,\n useRef,\n useState,\n} from 'react';\n\nimport { twMerge } from '../../utils/tw-merge';\nimport { Box } from '../Box';\nimport { Button } from '../Button';\nimport { ButtonIcon } from '../ButtonIcon';\nimport { Text } from '../Text';\n\nimport type { BannerBaseProps } from './BannerBase.types';\n\n/** BodyMd line height — title block (`typography.sBodyMD.lineHeight`). */\nconst BODY_MD_LINE_HEIGHT = 24;\n/** BodySm line height — description block (`typography.sBodySM.lineHeight`). */\nconst BODY_SM_LINE_HEIGHT = 22;\n/** `mt-0.5` between title and description. */\nconst TITLE_DESCRIPTION_GAP = 2;\n/** Sub-pixel / font rounding allowance when comparing stack height. */\nconst COMPACT_HEIGHT_TOLERANCE = 4;\n\nconst isTextContent = (content: React.ReactNode): content is string | number =>\n typeof content === 'string' || typeof content === 'number';\n\nconst hasContent = (content: React.ReactNode) =>\n content !== null && content !== undefined;\n\nconst getCompactContentMaxHeight = ({\n hasTitle,\n hasDescription,\n hasChildren,\n}: {\n hasTitle: boolean;\n hasDescription: boolean;\n hasChildren: boolean;\n}) => {\n let maxHeight = 0;\n\n if (hasTitle) {\n maxHeight += BODY_MD_LINE_HEIGHT;\n }\n if (hasDescription) {\n if (hasTitle) {\n maxHeight += TITLE_DESCRIPTION_GAP;\n }\n maxHeight += BODY_SM_LINE_HEIGHT;\n }\n if (hasChildren) {\n maxHeight += BODY_MD_LINE_HEIGHT;\n }\n\n return maxHeight + COMPACT_HEIGHT_TOLERANCE;\n};\n\nexport const BannerBase = forwardRef<HTMLDivElement, BannerBaseProps>(\n (\n {\n title,\n titleProps,\n description,\n descriptionProps,\n children,\n childrenWrapperProps,\n actionButtonLabel,\n actionButtonOnClick,\n actionButtonProps,\n actionButtonLayout = BannerBaseActionButtonLayout.Below,\n startAccessory,\n onClose,\n closeButtonProps,\n className,\n backgroundColor = BoxBackgroundColor.BackgroundDefault,\n ...props\n },\n ref,\n ) => {\n const resolvedActionButtonProps = actionButtonProps ?? {};\n\n const {\n ariaLabel: closeButtonAriaLabel = 'Close banner',\n className: closeButtonClassName,\n ...resolvedCloseButtonProps\n } = closeButtonProps ?? {};\n\n const shouldShowCloseButton = Boolean(onClose);\n const shouldShowActionButton = Boolean(actionButtonOnClick);\n const isActionButtonLayoutEnd =\n actionButtonLayout === BannerBaseActionButtonLayout.End;\n const hasActionButtonBelow =\n shouldShowActionButton && !isActionButtonLayoutEnd;\n const hasTitle = hasContent(title);\n const hasDescription = hasContent(description);\n const hasChildren = hasContent(children);\n // Custom nodes can't be measured reliably — keep top-aligned.\n const hasUnmeasuredContent =\n (hasTitle && !isTextContent(title)) ||\n (hasDescription && !isTextContent(description)) ||\n (hasChildren && !isTextContent(children));\n\n const contentRef = useRef<HTMLDivElement | null>(null);\n // Multiple text blocks: default top-aligned until the stack measures as\n // single-line per block. A single title, description, or children block\n // always centers (including wraps).\n const [isCompactContent, setIsCompactContent] = useState(false);\n const isSingleTextBlock =\n [hasTitle, hasDescription, hasChildren].filter(Boolean).length === 1;\n\n const measureContent = useCallback(() => {\n if (hasUnmeasuredContent || hasActionButtonBelow || isSingleTextBlock) {\n setIsCompactContent(false);\n return;\n }\n\n const height = contentRef.current?.getBoundingClientRect().height ?? 0;\n const maxCompactHeight = getCompactContentMaxHeight({\n hasTitle,\n hasDescription,\n hasChildren,\n });\n setIsCompactContent(height > 0 && height <= maxCompactHeight);\n }, [\n hasActionButtonBelow,\n hasChildren,\n hasDescription,\n hasTitle,\n hasUnmeasuredContent,\n isSingleTextBlock,\n ]);\n\n useLayoutEffect(() => {\n measureContent();\n\n if (typeof ResizeObserver === 'undefined' || !contentRef.current) {\n return undefined;\n }\n\n const observer = new ResizeObserver(() => {\n measureContent();\n });\n observer.observe(contentRef.current);\n\n return () => {\n observer.disconnect();\n };\n }, [title, description, children, measureContent]);\n\n const isCenterAligned =\n !hasActionButtonBelow &&\n !hasUnmeasuredContent &&\n (hasTitle || hasDescription || hasChildren) &&\n (isSingleTextBlock || isCompactContent);\n\n const actionButton = shouldShowActionButton ? (\n <Button\n size={ButtonSize.Md}\n onClick={actionButtonOnClick}\n {...resolvedActionButtonProps}\n variant={ButtonVariant.Secondary}\n >\n {actionButtonLabel}\n </Button>\n ) : null;\n\n return (\n <Box\n {...props}\n ref={ref}\n flexDirection={BoxFlexDirection.Row}\n alignItems={\n isCenterAligned ? BoxAlignItems.Center : BoxAlignItems.Start\n }\n gap={4}\n backgroundColor={backgroundColor}\n paddingTop={3}\n paddingBottom={hasActionButtonBelow ? 4 : 3}\n paddingLeft={4}\n paddingRight={shouldShowCloseButton ? 2 : 4}\n className={twMerge('rounded-xl', className)}\n >\n {startAccessory}\n\n <Box\n className=\"min-w-0 flex-1\"\n ref={(node) => {\n contentRef.current = node;\n }}\n >\n {hasTitle &&\n (isTextContent(title) ? (\n <Text\n variant={TextVariant.BodyMd}\n fontWeight={FontWeight.Medium}\n {...titleProps}\n >\n {title}\n </Text>\n ) : (\n title\n ))}\n\n {hasDescription && (\n <Box className={hasTitle ? 'mt-0.5' : undefined}>\n {isTextContent(description) ? (\n <Text variant={TextVariant.BodySm} {...descriptionProps}>\n {description}\n </Text>\n ) : (\n description\n )}\n </Box>\n )}\n\n {hasChildren &&\n (isTextContent(children) ? (\n <Text variant={TextVariant.BodyMd} {...childrenWrapperProps}>\n {children}\n </Text>\n ) : (\n children\n ))}\n\n {hasActionButtonBelow && <Box className=\"mt-2\">{actionButton}</Box>}\n </Box>\n\n {shouldShowActionButton && isActionButtonLayoutEnd && (\n <Box className=\"self-center\">{actionButton}</Box>\n )}\n\n {shouldShowCloseButton && (\n <ButtonIcon\n className={twMerge(\n !isCenterAligned && '-mt-1',\n closeButtonClassName,\n )}\n iconName={IconName.Close}\n size={ButtonIconSize.Md}\n ariaLabel={closeButtonAriaLabel}\n onClick={onClose}\n {...resolvedCloseButtonProps}\n />\n )}\n </Box>\n );\n },\n);\n\nBannerBase.displayName = 'BannerBase';\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { IconName } from "@metamask/design-system-shared";
|
|
2
2
|
import React from "react";
|
|
3
3
|
export declare const BannerBase: React.ForwardRefExoticComponent<(Omit<import("@metamask/design-system-shared").BannerBasePropsShared & Omit<import("../Box/index.cjs").BoxProps, "children"> & {
|
|
4
|
+
/** BodySm line height — description block (`typography.sBodySM.lineHeight`). */
|
|
4
5
|
titleProps?: Partial<import("../Text/index.cjs").TextProps> | undefined;
|
|
5
6
|
descriptionProps?: Partial<import("../Text/index.cjs").TextProps> | undefined;
|
|
6
7
|
childrenWrapperProps?: Partial<import("../Text/index.cjs").TextProps> | undefined;
|
|
@@ -320,6 +321,7 @@ export declare const BannerBase: React.ForwardRefExoticComponent<(Omit<import("@
|
|
|
320
321
|
isInverse?: boolean | undefined;
|
|
321
322
|
} | undefined;
|
|
322
323
|
}, "ref"> | Omit<import("@metamask/design-system-shared").BannerBasePropsShared & Omit<import("../Box/index.cjs").BoxProps, "children"> & {
|
|
324
|
+
/** BodySm line height — description block (`typography.sBodySM.lineHeight`). */
|
|
323
325
|
titleProps?: Partial<import("../Text/index.cjs").TextProps> | undefined;
|
|
324
326
|
descriptionProps?: Partial<import("../Text/index.cjs").TextProps> | undefined;
|
|
325
327
|
childrenWrapperProps?: Partial<import("../Text/index.cjs").TextProps> | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BannerBase.d.cts","sourceRoot":"","sources":["../../../src/components/BannerBase/BannerBase.tsx"],"names":[],"mappings":"AAAA,OAAO,EASL,QAAQ,EAET,uCAAuC;AACxC,OAAO,
|
|
1
|
+
{"version":3,"file":"BannerBase.d.cts","sourceRoot":"","sources":["../../../src/components/BannerBase/BannerBase.tsx"],"names":[],"mappings":"AAAA,OAAO,EASL,QAAQ,EAET,uCAAuC;AACxC,OAAO,KAMN,cAAc;AAoDf,eAAO,MAAM,UAAU;IAxCvB,gFAAgF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAAhF,gFAAgF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iDAsO/E,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { IconName } from "@metamask/design-system-shared";
|
|
2
2
|
import React from "react";
|
|
3
3
|
export declare const BannerBase: React.ForwardRefExoticComponent<(Omit<import("@metamask/design-system-shared").BannerBasePropsShared & Omit<import("../Box/index.mjs").BoxProps, "children"> & {
|
|
4
|
+
/** BodySm line height — description block (`typography.sBodySM.lineHeight`). */
|
|
4
5
|
titleProps?: Partial<import("../Text/index.mjs").TextProps> | undefined;
|
|
5
6
|
descriptionProps?: Partial<import("../Text/index.mjs").TextProps> | undefined;
|
|
6
7
|
childrenWrapperProps?: Partial<import("../Text/index.mjs").TextProps> | undefined;
|
|
@@ -320,6 +321,7 @@ export declare const BannerBase: React.ForwardRefExoticComponent<(Omit<import("@
|
|
|
320
321
|
isInverse?: boolean | undefined;
|
|
321
322
|
} | undefined;
|
|
322
323
|
}, "ref"> | Omit<import("@metamask/design-system-shared").BannerBasePropsShared & Omit<import("../Box/index.mjs").BoxProps, "children"> & {
|
|
324
|
+
/** BodySm line height — description block (`typography.sBodySM.lineHeight`). */
|
|
323
325
|
titleProps?: Partial<import("../Text/index.mjs").TextProps> | undefined;
|
|
324
326
|
descriptionProps?: Partial<import("../Text/index.mjs").TextProps> | undefined;
|
|
325
327
|
childrenWrapperProps?: Partial<import("../Text/index.mjs").TextProps> | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BannerBase.d.mts","sourceRoot":"","sources":["../../../src/components/BannerBase/BannerBase.tsx"],"names":[],"mappings":"AAAA,OAAO,EASL,QAAQ,EAET,uCAAuC;AACxC,OAAO,
|
|
1
|
+
{"version":3,"file":"BannerBase.d.mts","sourceRoot":"","sources":["../../../src/components/BannerBase/BannerBase.tsx"],"names":[],"mappings":"AAAA,OAAO,EASL,QAAQ,EAET,uCAAuC;AACxC,OAAO,KAMN,cAAc;AAoDf,eAAO,MAAM,UAAU;IAxCvB,gFAAgF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAAhF,gFAAgF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iDAsO/E,CAAC"}
|
|
@@ -5,34 +5,110 @@ function $importDefault(module) {
|
|
|
5
5
|
return module;
|
|
6
6
|
}
|
|
7
7
|
import { BannerBaseActionButtonLayout, BoxAlignItems, BoxBackgroundColor, BoxFlexDirection, ButtonIconSize, ButtonSize, ButtonVariant, FontWeight, IconName, TextVariant } from "@metamask/design-system-shared";
|
|
8
|
-
import $React, { forwardRef } from "react";
|
|
8
|
+
import $React, { forwardRef, useCallback, useLayoutEffect, useRef, useState } from "react";
|
|
9
9
|
const React = $importDefault($React);
|
|
10
10
|
import { twMerge } from "../../utils/tw-merge.mjs";
|
|
11
11
|
import { Box } from "../Box/index.mjs";
|
|
12
12
|
import { Button } from "../Button/index.mjs";
|
|
13
13
|
import { ButtonIcon } from "../ButtonIcon/index.mjs";
|
|
14
14
|
import { Text } from "../Text/index.mjs";
|
|
15
|
+
/** BodyMd line height — title block (`typography.sBodyMD.lineHeight`). */
|
|
16
|
+
const BODY_MD_LINE_HEIGHT = 24;
|
|
17
|
+
/** BodySm line height — description block (`typography.sBodySM.lineHeight`). */
|
|
18
|
+
const BODY_SM_LINE_HEIGHT = 22;
|
|
19
|
+
/** `mt-0.5` between title and description. */
|
|
20
|
+
const TITLE_DESCRIPTION_GAP = 2;
|
|
21
|
+
/** Sub-pixel / font rounding allowance when comparing stack height. */
|
|
22
|
+
const COMPACT_HEIGHT_TOLERANCE = 4;
|
|
15
23
|
const isTextContent = (content) => typeof content === 'string' || typeof content === 'number';
|
|
16
24
|
const hasContent = (content) => content !== null && content !== undefined;
|
|
17
|
-
|
|
25
|
+
const getCompactContentMaxHeight = ({ hasTitle, hasDescription, hasChildren, }) => {
|
|
26
|
+
let maxHeight = 0;
|
|
27
|
+
if (hasTitle) {
|
|
28
|
+
maxHeight += BODY_MD_LINE_HEIGHT;
|
|
29
|
+
}
|
|
30
|
+
if (hasDescription) {
|
|
31
|
+
if (hasTitle) {
|
|
32
|
+
maxHeight += TITLE_DESCRIPTION_GAP;
|
|
33
|
+
}
|
|
34
|
+
maxHeight += BODY_SM_LINE_HEIGHT;
|
|
35
|
+
}
|
|
36
|
+
if (hasChildren) {
|
|
37
|
+
maxHeight += BODY_MD_LINE_HEIGHT;
|
|
38
|
+
}
|
|
39
|
+
return maxHeight + COMPACT_HEIGHT_TOLERANCE;
|
|
40
|
+
};
|
|
41
|
+
export const BannerBase = forwardRef(({ title, titleProps, description, descriptionProps, children, childrenWrapperProps, actionButtonLabel, actionButtonOnClick, actionButtonProps, actionButtonLayout = BannerBaseActionButtonLayout.Below, startAccessory, onClose, closeButtonProps, className, backgroundColor = BoxBackgroundColor.BackgroundDefault, ...props }, ref) => {
|
|
18
42
|
const resolvedActionButtonProps = actionButtonProps ?? {};
|
|
19
43
|
const { ariaLabel: closeButtonAriaLabel = 'Close banner', className: closeButtonClassName, ...resolvedCloseButtonProps } = closeButtonProps ?? {};
|
|
20
44
|
const shouldShowCloseButton = Boolean(onClose);
|
|
21
45
|
const shouldShowActionButton = Boolean(actionButtonOnClick);
|
|
22
46
|
const isActionButtonLayoutEnd = actionButtonLayout === BannerBaseActionButtonLayout.End;
|
|
23
47
|
const hasActionButtonBelow = shouldShowActionButton && !isActionButtonLayoutEnd;
|
|
48
|
+
const hasTitle = hasContent(title);
|
|
49
|
+
const hasDescription = hasContent(description);
|
|
50
|
+
const hasChildren = hasContent(children);
|
|
51
|
+
// Custom nodes can't be measured reliably — keep top-aligned.
|
|
52
|
+
const hasUnmeasuredContent = (hasTitle && !isTextContent(title)) ||
|
|
53
|
+
(hasDescription && !isTextContent(description)) ||
|
|
54
|
+
(hasChildren && !isTextContent(children));
|
|
55
|
+
const contentRef = useRef(null);
|
|
56
|
+
// Multiple text blocks: default top-aligned until the stack measures as
|
|
57
|
+
// single-line per block. A single title, description, or children block
|
|
58
|
+
// always centers (including wraps).
|
|
59
|
+
const [isCompactContent, setIsCompactContent] = useState(false);
|
|
60
|
+
const isSingleTextBlock = [hasTitle, hasDescription, hasChildren].filter(Boolean).length === 1;
|
|
61
|
+
const measureContent = useCallback(() => {
|
|
62
|
+
if (hasUnmeasuredContent || hasActionButtonBelow || isSingleTextBlock) {
|
|
63
|
+
setIsCompactContent(false);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const height = contentRef.current?.getBoundingClientRect().height ?? 0;
|
|
67
|
+
const maxCompactHeight = getCompactContentMaxHeight({
|
|
68
|
+
hasTitle,
|
|
69
|
+
hasDescription,
|
|
70
|
+
hasChildren,
|
|
71
|
+
});
|
|
72
|
+
setIsCompactContent(height > 0 && height <= maxCompactHeight);
|
|
73
|
+
}, [
|
|
74
|
+
hasActionButtonBelow,
|
|
75
|
+
hasChildren,
|
|
76
|
+
hasDescription,
|
|
77
|
+
hasTitle,
|
|
78
|
+
hasUnmeasuredContent,
|
|
79
|
+
isSingleTextBlock,
|
|
80
|
+
]);
|
|
81
|
+
useLayoutEffect(() => {
|
|
82
|
+
measureContent();
|
|
83
|
+
if (typeof ResizeObserver === 'undefined' || !contentRef.current) {
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
const observer = new ResizeObserver(() => {
|
|
87
|
+
measureContent();
|
|
88
|
+
});
|
|
89
|
+
observer.observe(contentRef.current);
|
|
90
|
+
return () => {
|
|
91
|
+
observer.disconnect();
|
|
92
|
+
};
|
|
93
|
+
}, [title, description, children, measureContent]);
|
|
94
|
+
const isCenterAligned = !hasActionButtonBelow &&
|
|
95
|
+
!hasUnmeasuredContent &&
|
|
96
|
+
(hasTitle || hasDescription || hasChildren) &&
|
|
97
|
+
(isSingleTextBlock || isCompactContent);
|
|
24
98
|
const actionButton = shouldShowActionButton ? (React.createElement(Button, { size: ButtonSize.Md, onClick: actionButtonOnClick, ...resolvedActionButtonProps, variant: ButtonVariant.Secondary }, actionButtonLabel)) : null;
|
|
25
|
-
return (React.createElement(Box, { ref: ref, flexDirection: BoxFlexDirection.Row, alignItems: BoxAlignItems.Start, gap: 4, backgroundColor:
|
|
99
|
+
return (React.createElement(Box, { ...props, ref: ref, flexDirection: BoxFlexDirection.Row, alignItems: isCenterAligned ? BoxAlignItems.Center : BoxAlignItems.Start, gap: 4, backgroundColor: backgroundColor, paddingTop: 3, paddingBottom: hasActionButtonBelow ? 4 : 3, paddingLeft: 4, paddingRight: shouldShowCloseButton ? 2 : 4, className: twMerge('rounded-xl', className) },
|
|
26
100
|
startAccessory,
|
|
27
|
-
React.createElement(Box, { className: "min-w-0 flex-1"
|
|
28
|
-
|
|
101
|
+
React.createElement(Box, { className: "min-w-0 flex-1", ref: (node) => {
|
|
102
|
+
contentRef.current = node;
|
|
103
|
+
} },
|
|
104
|
+
hasTitle &&
|
|
29
105
|
(isTextContent(title) ? (React.createElement(Text, { variant: TextVariant.BodyMd, fontWeight: FontWeight.Medium, ...titleProps }, title)) : (title)),
|
|
30
|
-
|
|
31
|
-
|
|
106
|
+
hasDescription && (React.createElement(Box, { className: hasTitle ? 'mt-0.5' : undefined }, isTextContent(description) ? (React.createElement(Text, { variant: TextVariant.BodySm, ...descriptionProps }, description)) : (description))),
|
|
107
|
+
hasChildren &&
|
|
32
108
|
(isTextContent(children) ? (React.createElement(Text, { variant: TextVariant.BodyMd, ...childrenWrapperProps }, children)) : (children)),
|
|
33
109
|
hasActionButtonBelow && React.createElement(Box, { className: "mt-2" }, actionButton)),
|
|
34
|
-
shouldShowActionButton && isActionButtonLayoutEnd && actionButton,
|
|
35
|
-
shouldShowCloseButton && (React.createElement(ButtonIcon, { className: twMerge('-mt-1', closeButtonClassName), iconName: IconName.Close, size: ButtonIconSize.Md, ariaLabel: closeButtonAriaLabel, onClick: onClose, ...resolvedCloseButtonProps }))));
|
|
110
|
+
shouldShowActionButton && isActionButtonLayoutEnd && (React.createElement(Box, { className: "self-center" }, actionButton)),
|
|
111
|
+
shouldShowCloseButton && (React.createElement(ButtonIcon, { className: twMerge(!isCenterAligned && '-mt-1', closeButtonClassName), iconName: IconName.Close, size: ButtonIconSize.Md, ariaLabel: closeButtonAriaLabel, onClick: onClose, ...resolvedCloseButtonProps }))));
|
|
36
112
|
});
|
|
37
113
|
BannerBase.displayName = 'BannerBase';
|
|
38
114
|
//# sourceMappingURL=BannerBase.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BannerBase.mjs","sourceRoot":"","sources":["../../../src/components/BannerBase/BannerBase.tsx"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACL,4BAA4B,EAC5B,aAAa,EACb,kBAAkB,EAClB,gBAAgB,EAChB,cAAc,EACd,UAAU,EACV,aAAa,EACb,UAAU,EACV,QAAQ,EACR,WAAW,EACZ,uCAAuC;AACxC,OAAO,QAAO,EAAE,UAAU,EAAE,cAAc;;AAE1C,OAAO,EAAE,OAAO,EAAE,iCAA6B;AAC/C,OAAO,EAAE,GAAG,EAAE,yBAAe;AAC7B,OAAO,EAAE,MAAM,EAAE,4BAAkB;AACnC,OAAO,EAAE,UAAU,EAAE,gCAAsB;AAC3C,OAAO,EAAE,IAAI,EAAE,0BAAgB;AAI/B,MAAM,aAAa,GA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,CAAC,CAAC,CAAC,CACF,QAAQ,CACT,CAAC;YAEH,oBAAoB,IAAI,oBAAC,GAAG,IAAC,SAAS,EAAC,MAAM,IAAE,YAAY,CAAO,CAC/D;QAEL,sBAAsB,IAAI,uBAAuB,IAAI,YAAY;QAEjE,qBAAqB,IAAI,CACxB,oBAAC,UAAU,IACT,SAAS,EAAE,OAAO,CAAC,OAAO,EAAE,oBAAoB,CAAC,EACjD,QAAQ,EAAE,QAAQ,CAAC,KAAK,EACxB,IAAI,EAAE,cAAc,CAAC,EAAE,EACvB,SAAS,EAAE,oBAAoB,EAC/B,OAAO,EAAE,OAAO,KACZ,wBAAwB,GAC5B,CACH,CACG,CACP,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,UAAU,CAAC,WAAW,GAAG,YAAY,CAAC","sourcesContent":["import {\n BannerBaseActionButtonLayout,\n BoxAlignItems,\n BoxBackgroundColor,\n BoxFlexDirection,\n ButtonIconSize,\n ButtonSize,\n ButtonVariant,\n FontWeight,\n IconName,\n TextVariant,\n} from '@metamask/design-system-shared';\nimport React, { forwardRef } from 'react';\n\nimport { twMerge } from '../../utils/tw-merge';\nimport { Box } from '../Box';\nimport { Button } from '../Button';\nimport { ButtonIcon } from '../ButtonIcon';\nimport { Text } from '../Text';\n\nimport type { BannerBaseProps } from './BannerBase.types';\n\nconst isTextContent = (content: React.ReactNode): content is string | number =>\n typeof content === 'string' || typeof content === 'number';\n\nconst hasContent = (content: React.ReactNode) =>\n content !== null && content !== undefined;\n\nexport const BannerBase = forwardRef<HTMLDivElement, BannerBaseProps>(\n (\n {\n title,\n titleProps,\n description,\n descriptionProps,\n children,\n childrenWrapperProps,\n actionButtonLabel,\n actionButtonOnClick,\n actionButtonProps,\n actionButtonLayout = BannerBaseActionButtonLayout.Below,\n startAccessory,\n onClose,\n closeButtonProps,\n className,\n ...props\n },\n ref,\n ) => {\n const resolvedActionButtonProps = actionButtonProps ?? {};\n\n const {\n ariaLabel: closeButtonAriaLabel = 'Close banner',\n className: closeButtonClassName,\n ...resolvedCloseButtonProps\n } = closeButtonProps ?? {};\n\n const shouldShowCloseButton = Boolean(onClose);\n const shouldShowActionButton = Boolean(actionButtonOnClick);\n const isActionButtonLayoutEnd =\n actionButtonLayout === BannerBaseActionButtonLayout.End;\n const hasActionButtonBelow =\n shouldShowActionButton && !isActionButtonLayoutEnd;\n\n const actionButton = shouldShowActionButton ? (\n <Button\n size={ButtonSize.Md}\n onClick={actionButtonOnClick}\n {...resolvedActionButtonProps}\n variant={ButtonVariant.Secondary}\n >\n {actionButtonLabel}\n </Button>\n ) : null;\n\n return (\n <Box\n ref={ref}\n flexDirection={BoxFlexDirection.Row}\n alignItems={BoxAlignItems.Start}\n gap={4}\n backgroundColor={BoxBackgroundColor.BackgroundDefault}\n paddingTop={3}\n paddingBottom={hasActionButtonBelow ? 4 : 3}\n paddingLeft={4}\n paddingRight={shouldShowCloseButton ? 2 : 4}\n className={twMerge('rounded-xl', className)}\n {...props}\n >\n {startAccessory}\n\n <Box className=\"min-w-0 flex-1\">\n {hasContent(title) &&\n (isTextContent(title) ? (\n <Text\n variant={TextVariant.BodyMd}\n fontWeight={FontWeight.Medium}\n {...titleProps}\n >\n {title}\n </Text>\n ) : (\n title\n ))}\n\n {hasContent(description) && (\n <Box className={hasContent(title) ? 'mt-0.5' : undefined}>\n {isTextContent(description) ? (\n <Text variant={TextVariant.BodySm} {...descriptionProps}>\n {description}\n </Text>\n ) : (\n description\n )}\n </Box>\n )}\n\n {hasContent(children) &&\n (isTextContent(children) ? (\n <Text variant={TextVariant.BodyMd} {...childrenWrapperProps}>\n {children}\n </Text>\n ) : (\n children\n ))}\n\n {hasActionButtonBelow && <Box className=\"mt-2\">{actionButton}</Box>}\n </Box>\n\n {shouldShowActionButton && isActionButtonLayoutEnd && actionButton}\n\n {shouldShowCloseButton && (\n <ButtonIcon\n className={twMerge('-mt-1', closeButtonClassName)}\n iconName={IconName.Close}\n size={ButtonIconSize.Md}\n ariaLabel={closeButtonAriaLabel}\n onClick={onClose}\n {...resolvedCloseButtonProps}\n />\n )}\n </Box>\n );\n },\n);\n\nBannerBase.displayName = 'BannerBase';\n"]}
|
|
1
|
+
{"version":3,"file":"BannerBase.mjs","sourceRoot":"","sources":["../../../src/components/BannerBase/BannerBase.tsx"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACL,4BAA4B,EAC5B,aAAa,EACb,kBAAkB,EAClB,gBAAgB,EAChB,cAAc,EACd,UAAU,EACV,aAAa,EACb,UAAU,EACV,QAAQ,EACR,WAAW,EACZ,uCAAuC;AACxC,OAAO,QAAO,EACZ,UAAU,EACV,WAAW,EACX,eAAe,EACf,MAAM,EACN,QAAQ,EACT,cAAc;;AAEf,OAAO,EAAE,OAAO,EAAE,iCAA6B;AAC/C,OAAO,EAAE,GAAG,EAAE,yBAAe;AAC7B,OAAO,EAAE,MAAM,EAAE,4BAAkB;AACnC,OAAO,EAAE,UAAU,EAAE,gCAAsB;AAC3C,OAAO,EAAE,IAAI,EAAE,0BAAgB;AAI/B,0EAA0E;AAC1E,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAC/B,gFAAgF;AAChF,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAC/B,8CAA8C;AAC9C,MAAM,qBAAqB,GAAG,CAAC,CAAC;AAChC,uEAAuE;AACvE,MAAM,wBAAwB,GAAG,CAAC,CAAC;AAEnC,MAAM,aAAa,GAAG,CAAC,OAAwB,EAA8B,EAAE,CAC7E,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,OAAO,KAAK,QAAQ,CAAC;AAE7D,MAAM,UAAU,GAAG,CAAC,OAAwB,EAAE,EAAE,CAC9C,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,SAAS,CAAC;AAE5C,MAAM,0BAA0B,GAAG,CAAC,EAClC,QAAQ,EACR,cAAc,EACd,WAAW,GAKZ,EAAE,EAAE;IACH,IAAI,SAAS,GAAG,CAAC,CAAC;IAElB,IAAI,QAAQ,EAAE;QACZ,SAAS,IA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EACvB,SAAS,EAAE,oBAAoB,EAC/B,OAAO,EAAE,OAAO,KACZ,wBAAwB,GAC5B,CACH,CACG,CACP,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,UAAU,CAAC,WAAW,GAAG,YAAY,CAAC","sourcesContent":["import {\n BannerBaseActionButtonLayout,\n BoxAlignItems,\n BoxBackgroundColor,\n BoxFlexDirection,\n ButtonIconSize,\n ButtonSize,\n ButtonVariant,\n FontWeight,\n IconName,\n TextVariant,\n} from '@metamask/design-system-shared';\nimport React, {\n forwardRef,\n useCallback,\n useLayoutEffect,\n useRef,\n useState,\n} from 'react';\n\nimport { twMerge } from '../../utils/tw-merge';\nimport { Box } from '../Box';\nimport { Button } from '../Button';\nimport { ButtonIcon } from '../ButtonIcon';\nimport { Text } from '../Text';\n\nimport type { BannerBaseProps } from './BannerBase.types';\n\n/** BodyMd line height — title block (`typography.sBodyMD.lineHeight`). */\nconst BODY_MD_LINE_HEIGHT = 24;\n/** BodySm line height — description block (`typography.sBodySM.lineHeight`). */\nconst BODY_SM_LINE_HEIGHT = 22;\n/** `mt-0.5` between title and description. */\nconst TITLE_DESCRIPTION_GAP = 2;\n/** Sub-pixel / font rounding allowance when comparing stack height. */\nconst COMPACT_HEIGHT_TOLERANCE = 4;\n\nconst isTextContent = (content: React.ReactNode): content is string | number =>\n typeof content === 'string' || typeof content === 'number';\n\nconst hasContent = (content: React.ReactNode) =>\n content !== null && content !== undefined;\n\nconst getCompactContentMaxHeight = ({\n hasTitle,\n hasDescription,\n hasChildren,\n}: {\n hasTitle: boolean;\n hasDescription: boolean;\n hasChildren: boolean;\n}) => {\n let maxHeight = 0;\n\n if (hasTitle) {\n maxHeight += BODY_MD_LINE_HEIGHT;\n }\n if (hasDescription) {\n if (hasTitle) {\n maxHeight += TITLE_DESCRIPTION_GAP;\n }\n maxHeight += BODY_SM_LINE_HEIGHT;\n }\n if (hasChildren) {\n maxHeight += BODY_MD_LINE_HEIGHT;\n }\n\n return maxHeight + COMPACT_HEIGHT_TOLERANCE;\n};\n\nexport const BannerBase = forwardRef<HTMLDivElement, BannerBaseProps>(\n (\n {\n title,\n titleProps,\n description,\n descriptionProps,\n children,\n childrenWrapperProps,\n actionButtonLabel,\n actionButtonOnClick,\n actionButtonProps,\n actionButtonLayout = BannerBaseActionButtonLayout.Below,\n startAccessory,\n onClose,\n closeButtonProps,\n className,\n backgroundColor = BoxBackgroundColor.BackgroundDefault,\n ...props\n },\n ref,\n ) => {\n const resolvedActionButtonProps = actionButtonProps ?? {};\n\n const {\n ariaLabel: closeButtonAriaLabel = 'Close banner',\n className: closeButtonClassName,\n ...resolvedCloseButtonProps\n } = closeButtonProps ?? {};\n\n const shouldShowCloseButton = Boolean(onClose);\n const shouldShowActionButton = Boolean(actionButtonOnClick);\n const isActionButtonLayoutEnd =\n actionButtonLayout === BannerBaseActionButtonLayout.End;\n const hasActionButtonBelow =\n shouldShowActionButton && !isActionButtonLayoutEnd;\n const hasTitle = hasContent(title);\n const hasDescription = hasContent(description);\n const hasChildren = hasContent(children);\n // Custom nodes can't be measured reliably — keep top-aligned.\n const hasUnmeasuredContent =\n (hasTitle && !isTextContent(title)) ||\n (hasDescription && !isTextContent(description)) ||\n (hasChildren && !isTextContent(children));\n\n const contentRef = useRef<HTMLDivElement | null>(null);\n // Multiple text blocks: default top-aligned until the stack measures as\n // single-line per block. A single title, description, or children block\n // always centers (including wraps).\n const [isCompactContent, setIsCompactContent] = useState(false);\n const isSingleTextBlock =\n [hasTitle, hasDescription, hasChildren].filter(Boolean).length === 1;\n\n const measureContent = useCallback(() => {\n if (hasUnmeasuredContent || hasActionButtonBelow || isSingleTextBlock) {\n setIsCompactContent(false);\n return;\n }\n\n const height = contentRef.current?.getBoundingClientRect().height ?? 0;\n const maxCompactHeight = getCompactContentMaxHeight({\n hasTitle,\n hasDescription,\n hasChildren,\n });\n setIsCompactContent(height > 0 && height <= maxCompactHeight);\n }, [\n hasActionButtonBelow,\n hasChildren,\n hasDescription,\n hasTitle,\n hasUnmeasuredContent,\n isSingleTextBlock,\n ]);\n\n useLayoutEffect(() => {\n measureContent();\n\n if (typeof ResizeObserver === 'undefined' || !contentRef.current) {\n return undefined;\n }\n\n const observer = new ResizeObserver(() => {\n measureContent();\n });\n observer.observe(contentRef.current);\n\n return () => {\n observer.disconnect();\n };\n }, [title, description, children, measureContent]);\n\n const isCenterAligned =\n !hasActionButtonBelow &&\n !hasUnmeasuredContent &&\n (hasTitle || hasDescription || hasChildren) &&\n (isSingleTextBlock || isCompactContent);\n\n const actionButton = shouldShowActionButton ? (\n <Button\n size={ButtonSize.Md}\n onClick={actionButtonOnClick}\n {...resolvedActionButtonProps}\n variant={ButtonVariant.Secondary}\n >\n {actionButtonLabel}\n </Button>\n ) : null;\n\n return (\n <Box\n {...props}\n ref={ref}\n flexDirection={BoxFlexDirection.Row}\n alignItems={\n isCenterAligned ? BoxAlignItems.Center : BoxAlignItems.Start\n }\n gap={4}\n backgroundColor={backgroundColor}\n paddingTop={3}\n paddingBottom={hasActionButtonBelow ? 4 : 3}\n paddingLeft={4}\n paddingRight={shouldShowCloseButton ? 2 : 4}\n className={twMerge('rounded-xl', className)}\n >\n {startAccessory}\n\n <Box\n className=\"min-w-0 flex-1\"\n ref={(node) => {\n contentRef.current = node;\n }}\n >\n {hasTitle &&\n (isTextContent(title) ? (\n <Text\n variant={TextVariant.BodyMd}\n fontWeight={FontWeight.Medium}\n {...titleProps}\n >\n {title}\n </Text>\n ) : (\n title\n ))}\n\n {hasDescription && (\n <Box className={hasTitle ? 'mt-0.5' : undefined}>\n {isTextContent(description) ? (\n <Text variant={TextVariant.BodySm} {...descriptionProps}>\n {description}\n </Text>\n ) : (\n description\n )}\n </Box>\n )}\n\n {hasChildren &&\n (isTextContent(children) ? (\n <Text variant={TextVariant.BodyMd} {...childrenWrapperProps}>\n {children}\n </Text>\n ) : (\n children\n ))}\n\n {hasActionButtonBelow && <Box className=\"mt-2\">{actionButton}</Box>}\n </Box>\n\n {shouldShowActionButton && isActionButtonLayoutEnd && (\n <Box className=\"self-center\">{actionButton}</Box>\n )}\n\n {shouldShowCloseButton && (\n <ButtonIcon\n className={twMerge(\n !isCenterAligned && '-mt-1',\n closeButtonClassName,\n )}\n iconName={IconName.Close}\n size={ButtonIconSize.Md}\n ariaLabel={closeButtonAriaLabel}\n onClick={onClose}\n {...resolvedCloseButtonProps}\n />\n )}\n </Box>\n );\n },\n);\n\nBannerBase.displayName = 'BannerBase';\n"]}
|
|
@@ -54,7 +54,7 @@ exports.Checkbox = (0, react_1.forwardRef)(({ id, isSelected, isDisabled = false
|
|
|
54
54
|
const outerClassName = (0, tw_merge_1.twMerge)('inline-flex items-center self-start', isDisabled && 'cursor-not-allowed opacity-50', className);
|
|
55
55
|
const baseBg = isSelected
|
|
56
56
|
? 'bg-icon-default enabled:hover:bg-icon-default-hover enabled:active:bg-icon-default-pressed'
|
|
57
|
-
: 'bg-
|
|
57
|
+
: 'bg-transparent enabled:hover:bg-hover enabled:active:bg-pressed';
|
|
58
58
|
let baseBorder = 'border-default';
|
|
59
59
|
if (isSelected) {
|
|
60
60
|
baseBorder = 'border-icon-default';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Checkbox.cjs","sourceRoot":"","sources":["../../../src/components/Checkbox/Checkbox.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,+CAA+D;AAE/D,uDAA+C;AAC/C,4CAA8D;AAC9D,4CAA+B;AAIlB,QAAA,QAAQ,GAAG,IAAA,kBAAU,EAChC,CACE,EACE,EAAE,EACF,UAAU,EACV,UAAU,GAAG,KAAK,EAClB,SAAS,GAAG,KAAK,EACjB,KAAK,EACL,UAAU,EACV,QAAQ,EACR,UAAU,EACV,sBAAsB,EACtB,gBAAgB,EAChB,SAAS,EACT,KAAK,EACL,GAAG,KAAK,EACT,EACD,GAAG,EACH,EAAE;IACF,MAAM,YAAY,GAAG,CAAC,KAAoC,EAAE,EAAE;QAC5D,IAAI,UAAU,EAAE;Y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O,WACH,UAAU,EACd,SAAS,EAAE,IAAA,kBAAO,EAAC,MAAM,EAAE,UAAU,EAAE,SAAS,CAAC;YAEjD,4CAAO,KAAK,CAAQ,CACf,CACR,CAAC,CAAC,CAAC,IAAI,CACF,CACT,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,gBAAQ,CAAC,WAAW,GAAG,UAAU,CAAC","sourcesContent":["import type { ChangeEvent, KeyboardEvent } from 'react';\nimport React, { forwardRef, useImperativeHandle } from 'react';\n\nimport { twMerge } from '../../utils/tw-merge';\nimport { Icon, IconName, IconColor, IconSize } from '../Icon';\nimport { Text } from '../Text';\n\nimport type { CheckboxProps } from './Checkbox.types';\n\nexport const Checkbox = forwardRef<{ toggle: () => void }, CheckboxProps>(\n (\n {\n id,\n isSelected,\n isDisabled = false,\n isInvalid = false,\n label,\n labelProps,\n onChange,\n inputProps,\n checkboxContainerProps,\n checkedIconProps,\n className,\n style,\n ...props\n },\n ref,\n ) => {\n const handleChange = (event: ChangeEvent<HTMLInputElement>) => {\n if (isDisabled) {\n return;\n }\n onChange?.(event.target.checked);\n };\n\n const handleClick = () => {\n if (isDisabled) {\n return;\n }\n onChange?.(!isSelected);\n };\n\n const handleKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {\n if (event.key === 'Enter') {\n event.preventDefault();\n handleClick();\n }\n };\n\n useImperativeHandle(ref, () => ({ toggle: handleClick }), [handleClick]);\n\n const { className: inputClassName, ...restInputProps } = inputProps ?? {};\n const {\n className: checkboxContainerClassName,\n ...restCheckboxContainerProps\n } = checkboxContainerProps ?? {};\n const { className: checkedIconClassName, ...restCheckedIconProps } =\n checkedIconProps ?? {};\n\n const outerClassName = twMerge(\n 'inline-flex items-center self-start',\n isDisabled && 'cursor-not-allowed opacity-50',\n className,\n );\n\n const baseBg = isSelected\n ? 'bg-icon-default enabled:hover:bg-icon-default-hover enabled:active:bg-icon-default-pressed'\n : 'bg-transparent enabled:hover:bg-hover enabled:active:bg-pressed';\n let baseBorder = 'border-default';\n if (isSelected) {\n baseBorder = 'border-icon-default';\n } else if (isInvalid) {\n baseBorder = 'border-error-default';\n }\n\n // Native input is the visible control (no opacity-0) for Selenium isDisplayed().\n const inputClasses = twMerge(\n 'peer size-6 shrink-0 cursor-pointer appearance-none rounded border-2 p-0 transition-transform enabled:active:scale-95',\n 'focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-default',\n 'disabled:cursor-not-allowed',\n baseBg,\n baseBorder,\n inputClassName,\n );\n\n const wrapperClasses = twMerge(\n 'relative inline-flex size-6 items-center justify-center',\n checkboxContainerClassName,\n );\n\n const iconClasses = twMerge(\n 'pointer-events-none absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 transition peer-enabled:peer-active:scale-95',\n isSelected ? 'opacity-100' : 'opacity-0',\n checkedIconClassName,\n );\n\n return (\n <label htmlFor={id} className={outerClassName} style={style} {...props}>\n <div className={wrapperClasses} {...restCheckboxContainerProps}>\n <input\n type=\"checkbox\"\n id={id}\n checked={isSelected}\n disabled={isDisabled}\n aria-invalid={isInvalid}\n onChange={handleChange}\n onKeyDown={handleKeyDown}\n className={inputClasses}\n {...restInputProps}\n />\n <Icon\n name={IconName.Check}\n color={IconColor.IconInverse}\n size={IconSize.Sm}\n {...restCheckedIconProps}\n className={iconClasses}\n />\n </div>\n {label ? (\n <Text\n asChild\n {...labelProps}\n className={twMerge('ml-3', labelProps?.className)}\n >\n <span>{label}</span>\n </Text>\n ) : null}\n </label>\n );\n },\n);\n\nCheckbox.displayName = 'Checkbox';\n"]}
|
|
@@ -35,7 +35,7 @@ export const Checkbox = forwardRef(({ id, isSelected, isDisabled = false, isInva
|
|
|
35
35
|
const outerClassName = twMerge('inline-flex items-center self-start', isDisabled && 'cursor-not-allowed opacity-50', className);
|
|
36
36
|
const baseBg = isSelected
|
|
37
37
|
? 'bg-icon-default enabled:hover:bg-icon-default-hover enabled:active:bg-icon-default-pressed'
|
|
38
|
-
: 'bg-
|
|
38
|
+
: 'bg-transparent enabled:hover:bg-hover enabled:active:bg-pressed';
|
|
39
39
|
let baseBorder = 'border-default';
|
|
40
40
|
if (isSelected) {
|
|
41
41
|
baseBorder = 'border-icon-default';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Checkbox.mjs","sourceRoot":"","sources":["../../../src/components/Checkbox/Checkbox.tsx"],"names":[],"mappings":";;;;;;AACA,OAAO,QAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,cAAc;;AAE/D,OAAO,EAAE,OAAO,EAAE,iCAA6B;AAC/C,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,0BAAgB;AAC9D,OAAO,EAAE,IAAI,EAAE,0BAAgB;AAI/B,MAAM,CAAC,MAAM,QAAQ,GAAG,UAAU,CAChC,CACE,EACE,EAAE,EACF,UAAU,EACV,UAAU,GAAG,KAAK,EAClB,SAAS,GAAG,KAAK,EACjB,KAAK,EACL,UAAU,EACV,QAAQ,EACR,UAAU,EACV,sBAAsB,EACtB,gBAAgB,EAChB,SAAS,EACT,KAAK,EACL,GAAG,KAAK,EACT,EACD,GAAG,EACH,EAAE;IACF,MAAM,YAAY,GAAG,CAAC,KAAoC,EAAE,EAAE;QAC5D,IAAI,UAAU,EAAE;YACd,OAAO;SACR;QACD,QAAQ,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACnC,CAAC,CAAC;IAEF,MAAM,WAAW,GAAG,GAAG,EAAE;QACvB,IAAI,UAAU,EAAE;YACd,OAAO;SACR;QACD,QAAQ,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC;IAC1B,CAAC,CAAC;IAEF,MAAM,aAAa,GAAG,CAAC,KAAsC,EAAE,EAAE;QAC/D,IAAI,KAAK,CAAC,GAAG,KAAK,OAAO,EAAE;YACzB,KAAK,CAAC,cAAc,EAAE,CAAC;YACvB,WAAW,EAAE,CAAC;SACf;IACH,CAAC,CAAC;IAEF,mBA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AO,CAC1B,uHAAuH,EACvH,oHAAoH,EACpH,6BAA6B,EAC7B,MAAM,EACN,UAAU,EACV,cAAc,CACf,CAAC;IAEF,MAAM,cAAc,GAAG,OAAO,CAC5B,yDAAyD,EACzD,0BAA0B,CAC3B,CAAC;IAEF,MAAM,WAAW,GAAG,OAAO,CACzB,8HAA8H,EAC9H,UAAU,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,WAAW,EACxC,oBAAoB,CACrB,CAAC;IAEF,OAAO,CACL,+BAAO,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,cAAc,EAAE,KAAK,EAAE,KAAK,KAAM,KAAK;QACpE,6BAAK,SAAS,EAAE,cAAc,KAAM,0BAA0B;YAC5D,+BACE,IAAI,EAAC,UAAU,EACf,EAAE,EAAE,EAAE,EACN,OAAO,EAAE,UAAU,EACnB,QAAQ,EAAE,UAAU,kBACN,SAAS,EACvB,QAAQ,EAAE,YAAY,EACtB,SAAS,EAAE,aAAa,EACxB,SAAS,EAAE,YAAY,KACnB,cAAc,GAClB;YACF,oBAAC,IAAI,IACH,IAAI,EAAE,QAAQ,CAAC,KAAK,EACpB,KAAK,EAAE,SAAS,CAAC,WAAW,EAC5B,IAAI,EAAE,QAAQ,CAAC,EAAE,KACb,oBAAoB,EACxB,SAAS,EAAE,WAAW,GACtB,CACE;QACL,KAAK,CAAC,CAAC,CAAC,CACP,oBAAC,IAAI,IACH,OAAO,WACH,UAAU,EACd,SAAS,EAAE,OAAO,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,CAAC;YAEjD,kCAAO,KAAK,CAAQ,CACf,CACR,CAAC,CAAC,CAAC,IAAI,CACF,CACT,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,QAAQ,CAAC,WAAW,GAAG,UAAU,CAAC","sourcesContent":["import type { ChangeEvent, KeyboardEvent } from 'react';\nimport React, { forwardRef, useImperativeHandle } from 'react';\n\nimport { twMerge } from '../../utils/tw-merge';\nimport { Icon, IconName, IconColor, IconSize } from '../Icon';\nimport { Text } from '../Text';\n\nimport type { CheckboxProps } from './Checkbox.types';\n\nexport const Checkbox = forwardRef<{ toggle: () => void }, CheckboxProps>(\n (\n {\n id,\n isSelected,\n isDisabled = false,\n isInvalid = false,\n label,\n labelProps,\n onChange,\n inputProps,\n checkboxContainerProps,\n checkedIconProps,\n className,\n style,\n ...props\n },\n ref,\n ) => {\n const handleChange = (event: ChangeEvent<HTMLInputElement>) => {\n if (isDisabled) {\n return;\n }\n onChange?.(event.target.checked);\n };\n\n const handleClick = () => {\n if (isDisabled) {\n return;\n }\n onChange?.(!isSelected);\n };\n\n const handleKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {\n if (event.key === 'Enter') {\n event.preventDefault();\n handleClick();\n }\n };\n\n useImperativeHandle(ref, () => ({ toggle: handleClick }), [handleClick]);\n\n const { className: inputClassName, ...restInputProps } = inputProps ?? {};\n const {\n className: checkboxContainerClassName,\n ...restCheckboxContainerProps\n } = checkboxContainerProps ?? {};\n const { className: checkedIconClassName, ...restCheckedIconProps } =\n checkedIconProps ?? {};\n\n const outerClassName = twMerge(\n 'inline-flex items-center self-start',\n isDisabled && 'cursor-not-allowed opacity-50',\n className,\n );\n\n const baseBg = isSelected\n ? 'bg-icon-default enabled:hover:bg-icon-default-hover enabled:active:bg-icon-default-pressed'\n : 'bg-transparent enabled:hover:bg-hover enabled:active:bg-pressed';\n let baseBorder = 'border-default';\n if (isSelected) {\n baseBorder = 'border-icon-default';\n } else if (isInvalid) {\n baseBorder = 'border-error-default';\n }\n\n // Native input is the visible control (no opacity-0) for Selenium isDisplayed().\n const inputClasses = twMerge(\n 'peer size-6 shrink-0 cursor-pointer appearance-none rounded border-2 p-0 transition-transform enabled:active:scale-95',\n 'focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-default',\n 'disabled:cursor-not-allowed',\n baseBg,\n baseBorder,\n inputClassName,\n );\n\n const wrapperClasses = twMerge(\n 'relative inline-flex size-6 items-center justify-center',\n checkboxContainerClassName,\n );\n\n const iconClasses = twMerge(\n 'pointer-events-none absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 transition peer-enabled:peer-active:scale-95',\n isSelected ? 'opacity-100' : 'opacity-0',\n checkedIconClassName,\n );\n\n return (\n <label htmlFor={id} className={outerClassName} style={style} {...props}>\n <div className={wrapperClasses} {...restCheckboxContainerProps}>\n <input\n type=\"checkbox\"\n id={id}\n checked={isSelected}\n disabled={isDisabled}\n aria-invalid={isInvalid}\n onChange={handleChange}\n onKeyDown={handleKeyDown}\n className={inputClasses}\n {...restInputProps}\n />\n <Icon\n name={IconName.Check}\n color={IconColor.IconInverse}\n size={IconSize.Sm}\n {...restCheckedIconProps}\n className={iconClasses}\n />\n </div>\n {label ? (\n <Text\n asChild\n {...labelProps}\n className={twMerge('ml-3', labelProps?.className)}\n >\n <span>{label}</span>\n </Text>\n ) : null}\n </label>\n );\n },\n);\n\nCheckbox.displayName = 'Checkbox';\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Toast.types.cjs","sourceRoot":"","sources":["../../../src/components/Toast/Toast.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ToastPropsShared } from '@metamask/design-system-shared';\n\nimport type { BannerBaseProps } from '../BannerBase';\nimport type { IconProps } from '../Icon';\n\ntype ToastCloseButtonProps = Omit<\n NonNullable<BannerBaseProps['closeButtonProps']>,\n 'onClick'\n>;\n\n/**\n * Props for the Toast visual component.\n * Extends the platform BannerBase props with severity and an icon override.\n * `onClose` is simplified to `() => void` (no MouseEvent) to align with the\n * React Native API and the imperative `toast()` pattern.\n */\nexport type ToastProps = Omit<BannerBaseProps, 'closeButtonProps' | 'onClose'> &\n ToastPropsShared & {\n /**\n * Optional handler called when the close button is pressed.\n * When provided, a close button is shown.\n */\n onClose?: () => void;\n /**\n * Optional props passed to the severity `Icon`.\n * Only used when `severity` is not `Default` and `startAccessory` is not provided.\n */\n iconProps?: Omit<IconProps, 'name' | 'color'>;\n /**\n * Optional props for the close `ButtonIcon`.\n * `ariaLabel` defaults to `'Close toast'`.\n */\n closeButtonProps?: ToastCloseButtonProps;\n /**\n * Optional test identifier forwarded to the root Toast element.\n */\n 'data-testid'?: string;\n };\n\n/**\n * Options passed to the imperative `toast(...)` API.\n */\nexport type ToastOptions = ToastProps & {\n /**\n * When true the toast stays visible until explicitly dismissed.\n * Defaults to false.\n */\n hasNoTimeout?: boolean;\n};\n\n/**\n * Imperative handle exposed by `<Toaster ref={...} />`.\n */\nexport type ToasterRef = {\n showToast: (options: ToastOptions) => void;\n closeToast: () => void;\n};\n\n/**\n * Props for the `<Toaster />` container component.\n */\nexport type ToasterProps = {\n /**\n * Optional extra CSS classes applied to the fixed outer container.\n */\n className?: string;\n} & Omit<React.HTMLAttributes<HTMLDivElement>, 'style'>;\n"]}
|
|
1
|
+
{"version":3,"file":"Toast.types.cjs","sourceRoot":"","sources":["../../../src/components/Toast/Toast.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ToastPropsShared } from '@metamask/design-system-shared';\n\nimport type { BannerBaseProps } from '../BannerBase';\nimport type { IconProps } from '../Icon';\n\ntype ToastCloseButtonProps = Omit<\n NonNullable<BannerBaseProps['closeButtonProps']>,\n 'onClick'\n>;\n\n/**\n * Props for the Toast visual component.\n * Extends the platform BannerBase props with severity and an icon override.\n * `onClose` is simplified to `() => void` (no MouseEvent) to align with the\n * React Native API and the imperative `toast()` pattern.\n */\nexport type ToastProps = Omit<BannerBaseProps, 'closeButtonProps' | 'onClose'> &\n ToastPropsShared & {\n /**\n * Optional handler called when the close button is pressed.\n * When provided, a close button is shown.\n */\n onClose?: () => void;\n /**\n * Optional props passed to the severity `Icon`.\n * Only used when `severity` is not `Default` and `startAccessory` is not provided.\n */\n iconProps?: Omit<IconProps, 'name' | 'color'>;\n /**\n * Optional props for the close `ButtonIcon`.\n * `ariaLabel` defaults to `'Close toast'`.\n */\n closeButtonProps?: ToastCloseButtonProps;\n /**\n * Optional test identifier forwarded to the root Toast element.\n */\n 'data-testid'?: string;\n };\n\n/**\n * Options passed to the imperative `toast(...)` API.\n */\nexport type ToastOptions = ToastProps & {\n /**\n * When true the toast stays visible until explicitly dismissed.\n * Defaults to false.\n */\n hasNoTimeout?: boolean;\n /**\n * When `false`, hides the close button on the imperative toast.\n * Auto-dismiss and `toast.dismiss()` still work.\n * Defaults to `true`.\n */\n showCloseButton?: boolean;\n};\n\n/**\n * Imperative handle exposed by `<Toaster ref={...} />`.\n */\nexport type ToasterRef = {\n showToast: (options: ToastOptions) => void;\n closeToast: () => void;\n};\n\n/**\n * Props for the `<Toaster />` container component.\n */\nexport type ToasterProps = {\n /**\n * Optional extra CSS classes applied to the fixed outer container.\n */\n className?: string;\n} & Omit<React.HTMLAttributes<HTMLDivElement>, 'style'>;\n"]}
|
|
@@ -39,6 +39,12 @@ export type ToastOptions = ToastProps & {
|
|
|
39
39
|
* Defaults to false.
|
|
40
40
|
*/
|
|
41
41
|
hasNoTimeout?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* When `false`, hides the close button on the imperative toast.
|
|
44
|
+
* Auto-dismiss and `toast.dismiss()` still work.
|
|
45
|
+
* Defaults to `true`.
|
|
46
|
+
*/
|
|
47
|
+
showCloseButton?: boolean;
|
|
42
48
|
};
|
|
43
49
|
/**
|
|
44
50
|
* Imperative handle exposed by `<Toaster ref={...} />`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Toast.types.d.cts","sourceRoot":"","sources":["../../../src/components/Toast/Toast.types.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,uCAAuC;AAEvE,OAAO,KAAK,EAAE,eAAe,EAAE,gCAAsB;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,0BAAgB;AAEzC,KAAK,qBAAqB,GAAG,IAAI,CAC/B,WAAW,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAAC,EAChD,SAAS,CACV,CAAC;AAEF;;;;;GAKG;AACH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GAAG;IACtC;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;;;OAIG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,SAAS,EAAE,CAAC,OAAO,EAAE,YAAY,KAAK,IAAI,CAAC;IAC3C,UAAU,EAAE,MAAM,IAAI,CAAC;CACxB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC,EAAE,OAAO,CAAC,CAAC"}
|
|
@@ -39,6 +39,12 @@ export type ToastOptions = ToastProps & {
|
|
|
39
39
|
* Defaults to false.
|
|
40
40
|
*/
|
|
41
41
|
hasNoTimeout?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* When `false`, hides the close button on the imperative toast.
|
|
44
|
+
* Auto-dismiss and `toast.dismiss()` still work.
|
|
45
|
+
* Defaults to `true`.
|
|
46
|
+
*/
|
|
47
|
+
showCloseButton?: boolean;
|
|
42
48
|
};
|
|
43
49
|
/**
|
|
44
50
|
* Imperative handle exposed by `<Toaster ref={...} />`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Toast.types.d.mts","sourceRoot":"","sources":["../../../src/components/Toast/Toast.types.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,uCAAuC;AAEvE,OAAO,KAAK,EAAE,eAAe,EAAE,gCAAsB;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,0BAAgB;AAEzC,KAAK,qBAAqB,GAAG,IAAI,CAC/B,WAAW,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAAC,EAChD,SAAS,CACV,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,UAAU,GAAG,IAAI,CAAC,eAAe,EAAE,kBAAk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IACvB;;;;OAIG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,SAAS,EAAE,CAAC,OAAO,EAAE,YAAY,KAAK,IAAI,CAAC;IAC3C,UAAU,EAAE,MAAM,IAAI,CAAC;CACxB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC,EAAE,OAAO,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Toast.types.mjs","sourceRoot":"","sources":["../../../src/components/Toast/Toast.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ToastPropsShared } from '@metamask/design-system-shared';\n\nimport type { BannerBaseProps } from '../BannerBase';\nimport type { IconProps } from '../Icon';\n\ntype ToastCloseButtonProps = Omit<\n NonNullable<BannerBaseProps['closeButtonProps']>,\n 'onClick'\n>;\n\n/**\n * Props for the Toast visual component.\n * Extends the platform BannerBase props with severity and an icon override.\n * `onClose` is simplified to `() => void` (no MouseEvent) to align with the\n * React Native API and the imperative `toast()` pattern.\n */\nexport type ToastProps = Omit<BannerBaseProps, 'closeButtonProps' | 'onClose'> &\n ToastPropsShared & {\n /**\n * Optional handler called when the close button is pressed.\n * When provided, a close button is shown.\n */\n onClose?: () => void;\n /**\n * Optional props passed to the severity `Icon`.\n * Only used when `severity` is not `Default` and `startAccessory` is not provided.\n */\n iconProps?: Omit<IconProps, 'name' | 'color'>;\n /**\n * Optional props for the close `ButtonIcon`.\n * `ariaLabel` defaults to `'Close toast'`.\n */\n closeButtonProps?: ToastCloseButtonProps;\n /**\n * Optional test identifier forwarded to the root Toast element.\n */\n 'data-testid'?: string;\n };\n\n/**\n * Options passed to the imperative `toast(...)` API.\n */\nexport type ToastOptions = ToastProps & {\n /**\n * When true the toast stays visible until explicitly dismissed.\n * Defaults to false.\n */\n hasNoTimeout?: boolean;\n};\n\n/**\n * Imperative handle exposed by `<Toaster ref={...} />`.\n */\nexport type ToasterRef = {\n showToast: (options: ToastOptions) => void;\n closeToast: () => void;\n};\n\n/**\n * Props for the `<Toaster />` container component.\n */\nexport type ToasterProps = {\n /**\n * Optional extra CSS classes applied to the fixed outer container.\n */\n className?: string;\n} & Omit<React.HTMLAttributes<HTMLDivElement>, 'style'>;\n"]}
|
|
1
|
+
{"version":3,"file":"Toast.types.mjs","sourceRoot":"","sources":["../../../src/components/Toast/Toast.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ToastPropsShared } from '@metamask/design-system-shared';\n\nimport type { BannerBaseProps } from '../BannerBase';\nimport type { IconProps } from '../Icon';\n\ntype ToastCloseButtonProps = Omit<\n NonNullable<BannerBaseProps['closeButtonProps']>,\n 'onClick'\n>;\n\n/**\n * Props for the Toast visual component.\n * Extends the platform BannerBase props with severity and an icon override.\n * `onClose` is simplified to `() => void` (no MouseEvent) to align with the\n * React Native API and the imperative `toast()` pattern.\n */\nexport type ToastProps = Omit<BannerBaseProps, 'closeButtonProps' | 'onClose'> &\n ToastPropsShared & {\n /**\n * Optional handler called when the close button is pressed.\n * When provided, a close button is shown.\n */\n onClose?: () => void;\n /**\n * Optional props passed to the severity `Icon`.\n * Only used when `severity` is not `Default` and `startAccessory` is not provided.\n */\n iconProps?: Omit<IconProps, 'name' | 'color'>;\n /**\n * Optional props for the close `ButtonIcon`.\n * `ariaLabel` defaults to `'Close toast'`.\n */\n closeButtonProps?: ToastCloseButtonProps;\n /**\n * Optional test identifier forwarded to the root Toast element.\n */\n 'data-testid'?: string;\n };\n\n/**\n * Options passed to the imperative `toast(...)` API.\n */\nexport type ToastOptions = ToastProps & {\n /**\n * When true the toast stays visible until explicitly dismissed.\n * Defaults to false.\n */\n hasNoTimeout?: boolean;\n /**\n * When `false`, hides the close button on the imperative toast.\n * Auto-dismiss and `toast.dismiss()` still work.\n * Defaults to `true`.\n */\n showCloseButton?: boolean;\n};\n\n/**\n * Imperative handle exposed by `<Toaster ref={...} />`.\n */\nexport type ToasterRef = {\n showToast: (options: ToastOptions) => void;\n closeToast: () => void;\n};\n\n/**\n * Props for the `<Toaster />` container component.\n */\nexport type ToasterProps = {\n /**\n * Optional extra CSS classes applied to the fixed outer container.\n */\n className?: string;\n} & Omit<React.HTMLAttributes<HTMLDivElement>, 'style'>;\n"]}
|