diff --git a/apps/storybook/stories/banner.stories.tsx b/apps/storybook/stories/banner.stories.tsx new file mode 100644 index 00000000..4054f470 --- /dev/null +++ b/apps/storybook/stories/banner.stories.tsx @@ -0,0 +1,53 @@ +import React, { useState } from 'react'; +import type { ComponentMeta } from '@storybook/react'; +import type { BannerSize } from '@tih/ui'; +import { Banner } from '@tih/ui'; + +const bannerSizes: ReadonlyArray = ['xs', 'sm', 'md']; + +export default { + argTypes: { + children: { + control: 'text', + }, + size: { + control: { type: 'select' }, + options: bannerSizes, + }, + }, + component: Banner, + title: 'Banner', +} as ComponentMeta; + +export const Basic = { + args: { + children: 'This notice is going to change your life', + size: 'md', + }, +}; + +export function Sizes() { + const [isShown, setIsShown] = useState(true); + const [isShown2, setIsShown2] = useState(true); + const [isShown3, setIsShown3] = useState(true); + return ( +
+ {isShown && ( + setIsShown(false)}> + This notice is going to change your life unless you close it. + + )} + {isShown2 && ( + setIsShown2(false)}> + This smaller notice is going to change your life unless you close it. + + )} + {isShown3 && ( + setIsShown3(false)}> + This even smaller notice is going to change your life unless you close + it. + + )} +
+ ); +} diff --git a/packages/ui/src/Banner/Banner.tsx b/packages/ui/src/Banner/Banner.tsx new file mode 100644 index 00000000..41403cbb --- /dev/null +++ b/packages/ui/src/Banner/Banner.tsx @@ -0,0 +1,50 @@ +import clsx from 'clsx'; +import React from 'react'; +import { XMarkIcon } from '@heroicons/react/24/outline'; + +export type BannerSize = 'md' | 'sm' | 'xs'; + +type Props = Readonly<{ + children: React.ReactNode; + onHide?: () => void; + size?: BannerSize; +}>; + +export default function Banner({ children, size = 'md', onHide }: Props) { + return ( +
+
+
+

{children}

+
+ {onHide != null && ( +
+ +
+ )} +
+
+ ); +} diff --git a/packages/ui/src/index.tsx b/packages/ui/src/index.tsx index 1a7d77fa..da2ecf15 100644 --- a/packages/ui/src/index.tsx +++ b/packages/ui/src/index.tsx @@ -4,6 +4,9 @@ export { default as Alert } from './Alert/Alert'; // Badge export * from './Badge/Badge'; export { default as Badge } from './Badge/Badge'; +// Banner +export * from './Banner/Banner'; +export { default as Banner } from './Banner/Banner'; // Button export * from './Button/Button'; export { default as Button } from './Button/Button';