Skip to content

Commit ad39b5d

Browse files
committed
use alert
1 parent 0558891 commit ad39b5d

File tree

2 files changed

+45
-10
lines changed

2 files changed

+45
-10
lines changed

src/components/ScheduleOption.tsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { useContext, useState } from "react";
22

3-
import { IconButton, Flex, Text, CloseButton } from "@chakra-ui/react";
3+
import { IconButton, Flex, CloseButton } from "@chakra-ui/react";
44

55
import { LuArrowLeft, LuArrowRight } from "react-icons/lu";
66
import { HydrantContext } from "../lib/hydrant";
7+
import { Alert } from "./ui/alert";
78

89
export function ScheduleOption() {
910
const [tooManyOptions, setTooManyOptions] = useState(true);
@@ -38,16 +39,20 @@ export function ScheduleOption() {
3839
</IconButton>
3940
</Flex>
4041
{tooManyOptions && totalOptions > 15 && (
41-
<Flex align="center" bg="whiteAlpha.50" gap={1} px={2} py={1}>
42-
<Text fontSize="sm">
43-
Too many options? Use the "Edit sections" button above the class
44-
description.
45-
</Text>
46-
<CloseButton
42+
<Flex align="center" gap={1} px={2} py={1}>
43+
<Alert
4744
size="sm"
48-
onClick={() => {
49-
setTooManyOptions(false);
50-
}}
45+
title='Too many options? Use the "Edit sections" button above the class description.'
46+
colorPalette="gray"
47+
endElement={
48+
<CloseButton
49+
size="sm"
50+
height={"1rem"}
51+
onClick={() => {
52+
setTooManyOptions(false);
53+
}}
54+
/>
55+
}
5156
/>
5257
</Flex>
5358
)}

src/components/ui/alert.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { Alert as ChakraAlert } from "@chakra-ui/react";
2+
import { forwardRef, type ReactNode, type ReactElement } from "react";
3+
4+
export interface AlertProps extends Omit<ChakraAlert.RootProps, "title"> {
5+
startElement?: ReactNode;
6+
endElement?: ReactNode;
7+
title?: ReactNode;
8+
icon?: ReactElement;
9+
}
10+
11+
export const Alert = forwardRef<HTMLDivElement, AlertProps>(
12+
function Alert(props, ref) {
13+
const { title, children, icon, startElement, endElement, ...rest } = props;
14+
return (
15+
<ChakraAlert.Root ref={ref} {...rest}>
16+
{/* eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing */}
17+
{startElement || <ChakraAlert.Indicator>{icon}</ChakraAlert.Indicator>}
18+
{children ? (
19+
<ChakraAlert.Content>
20+
<ChakraAlert.Title>{title}</ChakraAlert.Title>
21+
<ChakraAlert.Description>{children}</ChakraAlert.Description>
22+
</ChakraAlert.Content>
23+
) : (
24+
<ChakraAlert.Title flex="1">{title}</ChakraAlert.Title>
25+
)}
26+
{endElement}
27+
</ChakraAlert.Root>
28+
);
29+
},
30+
);

0 commit comments

Comments
 (0)