Skip to content

Commit 4f2bc1c

Browse files
committed
shared(BannerBase): centralize isTextContent/hasContent in @metamask/design-system-shared and use in React & RN; rn(BannerBase): add self-start to close button for consistent alignment
1 parent 15e61b1 commit 4f2bc1c

4 files changed

Lines changed: 34 additions & 14 deletions

File tree

packages/design-system-react-native/src/components/BannerBase/BannerBase.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { hasContent, isTextContent } from '@metamask/design-system-shared';
12
import React from 'react';
23
import { GestureResponderEvent } from 'react-native';
34

@@ -18,12 +19,6 @@ import { Text } from '../Text';
1819

1920
import type { BannerBaseProps } from './BannerBase.types';
2021

21-
const isTextContent = (content: React.ReactNode): content is string | number =>
22-
typeof content === 'string' || typeof content === 'number';
23-
24-
const hasContent = (content: React.ReactNode) =>
25-
content !== null && content !== undefined;
26-
2722
export const BannerBase: React.FC<BannerBaseProps> = ({
2823
title,
2924
titleProps,
@@ -64,8 +59,8 @@ export const BannerBase: React.FC<BannerBaseProps> = ({
6459
: undefined;
6560

6661
const mergedCloseButtonTwClassName = closeButtonTwClassName
67-
? `ml-3 ${closeButtonTwClassName}`
68-
: 'ml-3';
62+
? `ml-3 self-start ${closeButtonTwClassName}`
63+
: 'ml-3 self-start';
6964

7065
return (
7166
<Box

packages/design-system-react/src/components/BannerBase/BannerBase.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { hasContent, isTextContent } from '@metamask/design-system-shared';
12
import React, { forwardRef } from 'react';
23

34
import {
@@ -18,12 +19,6 @@ import { Text } from '../Text';
1819

1920
import type { BannerBaseProps } from './BannerBase.types';
2021

21-
const isTextContent = (content: React.ReactNode): content is string | number =>
22-
typeof content === 'string' || typeof content === 'number';
23-
24-
const hasContent = (content: React.ReactNode) =>
25-
content !== null && content !== undefined;
26-
2722
export const BannerBase = forwardRef<HTMLDivElement, BannerBaseProps>(
2823
(
2924
{

packages/design-system-shared/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ export {
66
generateIconSeed,
77
} from './utils/caip-address';
88

9+
// BannerBase utils (ADR-0004)
10+
export { isTextContent, hasContent } from './utils/banner-base';
11+
912
// BadgeCount types (ADR-0003 + ADR-0004)
1013
export { BadgeCountSize, type BadgeCountPropsShared } from './types/BadgeCount';
1114

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import type { ReactNode } from 'react';
2+
3+
/**
4+
* Returns true when the provided ReactNode is plain text content that should be
5+
* wrapped with a Text component for consistent typography.
6+
*/
7+
/**
8+
* @param content - The ReactNode to test.
9+
* @returns True if content is a string or number (textual), false otherwise.
10+
*/
11+
export const isTextContent = (
12+
content: ReactNode,
13+
): content is string | number => {
14+
return typeof content === 'string' || typeof content === 'number';
15+
};
16+
17+
/**
18+
* Returns true when the provided ReactNode is present (not null/undefined).
19+
* This intentionally allows values like 0 or empty string, which are valid content.
20+
*/
21+
/**
22+
* @param content - The ReactNode to test for presence.
23+
* @returns True if content is neither null nor undefined.
24+
*/
25+
export const hasContent = (content: ReactNode): boolean => {
26+
return content !== null && content !== undefined;
27+
};

0 commit comments

Comments
 (0)