Skip to content

Commit

Permalink
refactor(callouttitle): replaces string literal for callout with a co…
Browse files Browse the repository at this point in the history
…nstant
  • Loading branch information
codemonkey800 committed Jan 17, 2024
1 parent 12480ea commit c18e9c9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { AlertTitleProps } from "@mui/material/AlertTitle";
import { CALLOUT_TITLE_DISPLAY_NAME } from "../../constants";
import { StyledCalloutTitle } from "./style";

const CalloutTitle = ({ children }: AlertTitleProps): JSX.Element => {
return <StyledCalloutTitle>{children}</StyledCalloutTitle>;
};

// Display name required to ensure Callout expand works correctly.
CalloutTitle.displayName = "CalloutTitle";
CalloutTitle.displayName = CALLOUT_TITLE_DISPLAY_NAME;

export default CalloutTitle;
1 change: 1 addition & 0 deletions packages/components/src/core/Callout/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const CALLOUT_TITLE_DISPLAY_NAME = "CalloutTitle";
3 changes: 2 additions & 1 deletion packages/components/src/core/Callout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Grow } from "@mui/material";
import React, { useEffect, useState } from "react";
import ButtonIcon from "../ButtonIcon";
import Icon from "../Icon";
import { CALLOUT_TITLE_DISPLAY_NAME } from "./constants";
import { StyledCallout } from "./style";

const SDS_STAGE_OPEN = "open";
Expand Down Expand Up @@ -101,7 +102,7 @@ const Callout = ({

const firstChildIsCalloutTitle =
Array.isArray(children) &&
children[0]?.type?.displayName === "CalloutTitle";
children[0]?.type?.displayName === CALLOUT_TITLE_DISPLAY_NAME;

if (firstChildIsCalloutTitle) {
[calloutTitle, ...calloutContent] = children;
Expand Down

0 comments on commit c18e9c9

Please sign in to comment.