Skip to content

Commit

Permalink
feat(notice): add link
Browse files Browse the repository at this point in the history
  • Loading branch information
maximallain committed Nov 13, 2024
1 parent bd96252 commit c2abccc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/Notice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type { Equals } from "tsafe";
import { useConstCallback } from "./tools/powerhooks/useConstCallback";
import { createComponentI18nApi } from "./i18n";
import { useAnalyticsId } from "./tools/useAnalyticsId";
import { getLink, type RegisteredLinkProps } from "./link";

export type NoticeProps = (NoticeProps.NonClosable | NoticeProps.Closable) &
(NoticeProps.OptionalIcon | NoticeProps.MandatoryIcon);
Expand All @@ -25,10 +26,14 @@ export namespace NoticeProps {
type Common = {
id?: string;
className?: string;
classes?: Partial<Record<"root" | "title" | "description" | "close", string>>;
classes?: Partial<Record<"root" | "title" | "description" | "close" | "link", string>>;
title: NonNullable<ReactNode>;
description?: ReactNode;
style?: CSSProperties;
link?: {
linkProps: RegisteredLinkProps;
text: ReactNode;
};
/** Default: "info" */
severity?: NoticeProps.Severity;
};
Expand Down Expand Up @@ -91,6 +96,7 @@ export const Notice = memo(
classes = {},
title,
description,
link,
isClosable = false,
isClosed: props_isClosed,
onClose,
Expand All @@ -113,6 +119,7 @@ export const Notice = memo(

const refShouldButtonGetFocus = useRef(false);
const refShouldSetRole = useRef(false);
const { Link } = getLink();

useEffect(() => {
if (props_isClosed === undefined) {
Expand Down Expand Up @@ -191,6 +198,20 @@ export const Notice = memo(
{description}
</span>
)}
{link && (
<Link
target="_blank"
rel="noopener external"
{...link.linkProps}
className={cx(
fr.cx("fr-notice__link"),
classes.link,
link.linkProps.className
)}
>
{link.text}
</Link>
)}
</p>
{/* TODO: Use our button once we have one */}
{isClosable && (
Expand Down
9 changes: 9 additions & 0 deletions stories/Notice.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ const { meta, getStory } = getStoryFactory<NoticeProps>({
"description": {
"description": "Optional message to complete title"
},
"link": {
"description": "Optional link to display"
},
"severity": {
"description": 'Default : "info"',
"options": (() => {
Expand Down Expand Up @@ -67,6 +70,12 @@ export default meta;
export const Default = getStory({
"title": "Service maintenance is scheduled today from 12:00 to 14:00.",
"description": "All will be ok after 14:00.",
"link": {
"linkProps": {
"href": "#"
},
"text": "More information"
},
"isClosable": true,
"isClosed": undefined,
"severity": "info",
Expand Down

0 comments on commit c2abccc

Please sign in to comment.