-
- {title ? (
- hideTitle ? (
-
- {title}
-
- ) : (
+
+
+ {icon && variant === 'info' ? icon : iconForVariant[variant]}
+
+
+ {title ? (
+ hideTitle ? (
+
{title}
- )
- ) : null}
- {description ? {description} : null}
- {children}
-
- {hasActions ?
: null}
+
+ ) : (
+
{title}
+ )
+ ) : null}
+ {description ?
{description} : null}
+ {children}
- {dismissible ? (
-
- ) : null}
-
-
+ {hasActions ?
: null}
+
+ {dismissible ? (
+
+ ) : null}
+
)
})
@@ -342,9 +371,8 @@ export type BannerTitleProps
= {
export function BannerTitle(props: BannerTitleProps) {
const {as: Heading = 'h2', className, children, ...rest} = props
- const banner = useBanner()
return (
-
+
{children}
)
@@ -399,14 +427,3 @@ export function BannerSecondaryAction({children, className, ...rest}: BannerSeco
)
}
-
-type BannerContextValue = {titleId: string}
-const BannerContext = createContext(null)
-
-function useBanner(): BannerContextValue {
- const value = useContext(BannerContext)
- if (value) {
- return value
- }
- throw new Error('Component must be used within a component')
-}
diff --git a/packages/react/src/Banner/__snapshots__/Banner.test.tsx.snap b/packages/react/src/Banner/__snapshots__/Banner.test.tsx.snap
index 3a1a9768fbc..34992a57706 100644
--- a/packages/react/src/Banner/__snapshots__/Banner.test.tsx.snap
+++ b/packages/react/src/Banner/__snapshots__/Banner.test.tsx.snap
@@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
-exports[`Banner should throw an error if no title is provided 1`] = `"The Banner component requires a title to be provided as the \`title\` prop or through \`Banner.Title\`"`;
+exports[`Banner should throw an error if no title is provided 1`] = `"Expected a title to be provided to the component with the \`title\` prop or through \`\` but no title was found"`;
diff --git a/packages/react/src/internal/hooks/useMergedRefs.ts b/packages/react/src/internal/hooks/useMergedRefs.ts
new file mode 100644
index 00000000000..7c67f20fadc
--- /dev/null
+++ b/packages/react/src/internal/hooks/useMergedRefs.ts
@@ -0,0 +1,16 @@
+import {useCallback} from 'react'
+
+export function useMergedRefs(
+ ...refs: Array | React.ForwardedRef | React.RefCallback>
+): React.RefCallback {
+ return useCallback((instance: T) => {
+ for (const ref of refs) {
+ if (typeof ref === 'function') {
+ ref(instance)
+ } else if (ref) {
+ ref.current = instance
+ }
+ }
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, refs)
+}