mirror of
https://github.com/nextui-org/nextui.git
synced 2025-12-08 19:26:11 +00:00
* feat(alert): began the work on alert component
* fix(readme): making correction
* chore(deps): change to 2.0.0
* chore(docs): update README.md
* feat(theme): init alert tv
* chore(alert): update package.json
* feat(alert): init alert storybook structure
* chore(changeset): add changeset
* chore(changeset): change to minor
* chore(alert): revise alert package.json
* feat(alert): init test structure
* chore(deps): pnpm-lock.yaml
* feat(alert): initailized theme and basic structure
* feat(alert): completed use-alert.ts and alert.tsx
* feat(alert): remove innerWrapper, replace helperWrapper with mainWrapper, adding isCloseable prop
* feat(alert): adding isCloseable prop to baseWrapper dependency
* feat(alert): setting the default value of isCloseable prop to true
* feat(alert): moving CloseIcon inside the button
* feat(alert): updated package.json
* feat(alert): default variant and default story
* feat(alert): adding color and radius stories
* feat(alert): completed the styling
* feat(alert): add stories for isCloseable prop and restyle other stories
* feat(alert): correcting ref type
* feat(alert): add test cases
* feat(alert): remove startContent and endContent props
* feat(alert): make styling more accurate
* feat(alert): fixed default props
* feat(alert): fixed theme docs
* feat(alert): add logic for icons
* feat(alert): begin to add docs
* chore(alert): implement the changes suggested in code review
* feat(alert): add onclose prop to alert
* feat(alert): add test cases
* docs(alert): add onClose event
* feat(docs): add alert to routes.json
* fix(alert): correct the text colors
* docs(alert): fix imports and syntax errors
* chore(alert): implement the changes suggested in code review
* chore(alert): lint the code and change isCloseable to isClosable
* chore(alert): lint the code
* chore(alert): run pnpm i
* fix(alert): fix the logic for close button and add test case
* docs(alert): fix docs, change isCloseable to isClosable and change docs for isClosable property
* chore(alert): add the support for RTL, refactor the code and fix the typos
* docs(alert): grammer issues fix
* fix(alert): replace rtl with ms
* chore(alert): custom style and custom implementation, remove isClosable={false}, refactor, fix typos
* chore(alert): linting and implement coderabbit suggestions
* chore(alert): refactor and typos fix
* chore(alert): add import for closeIcon
* chore(alert): add props for closeIcon
* chore(alert): refactor fixes
* chore(alert): implement ryo-manba's suggestion on close Icon
* chore(alert): make alert more responsive
* chore(alert): fix grammer issues suggested by coderabbit
* fix(alert): add max-w property to make alert responsive
* chore(alert): improve responsiveness and refactor alertIcon
* chore(alert): add missing dependency to useMemo
* chore(alert): implement coderabbit's suggestions
* chore(alert): update docs and refactor
* chore(alert): refactor alertIcon and implement coderabbit's suggestion
* chore: fixes
---------
Co-authored-by: Abhinav Agarwal <abhinavagrawal700@gmail.com>
Co-authored-by: WK Wong <wingkwong.code@gmail.com>
Co-authored-by: Abhinav Agarwal <78839973+abhinav700@users.noreply.github.com>
143 lines
3.6 KiB
TypeScript
143 lines
3.6 KiB
TypeScript
const InfoCircleIcon = `export const InfoCircleIcon = (props) => (
|
|
<svg
|
|
fill="none"
|
|
height="24"
|
|
viewBox="0 0 24 24"
|
|
width="24"
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
{...props}
|
|
>
|
|
<path
|
|
d="M12 22C17.51 22 22 17.51 22 12C22 6.49 17.51 2 12 2C6.49 2 2 6.49 2 12C2 17.51 6.49 22 12 22ZM12.75 16C12.75 16.41 12.41 16.75 12 16.75C11.59 16.75 11.25 16.41 11.25 16L11.25 11C11.25 10.59 11.59 10.25 12 10.25C12.41 10.25 12.75 10.59 12.75 11L12.75 16ZM11.08 7.62C11.13 7.49 11.2 7.39 11.29 7.29C11.39 7.2 11.5 7.13 11.62 7.08C11.74 7.03 11.87 7 12 7C12.13 7 12.26 7.03 12.38 7.08C12.5 7.13 12.61 7.2 12.71 7.29C12.8 7.39 12.87 7.49 12.92 7.62C12.97 7.74 13 7.87 13 8C13 8.13 12.97 8.26 12.92 8.38C12.87 8.5 12.8 8.61 12.71 8.71C12.61 8.8 12.5 8.87 12.38 8.92C12.14 9.02 11.86 9.02 11.62 8.92C11.5 8.87 11.39 8.8 11.29 8.71C11.2 8.61 11.13 8.5 11.08 8.38C11.03 8.26 11 8.13 11 8C11 7.87 11.03 7.74 11.08 7.62Z"
|
|
/>
|
|
</svg>
|
|
);`;
|
|
|
|
const CloseIcon = `export const CloseIcon = (props) => (
|
|
<svg
|
|
aria-hidden="true"
|
|
fill="none"
|
|
focusable="false"
|
|
height="1em"
|
|
role="presentation"
|
|
stroke="currentColor"
|
|
strokeLinecap="round"
|
|
strokeLinejoin="round"
|
|
strokeWidth={2}
|
|
viewBox="0 0 24 24"
|
|
width="1em"
|
|
{...props}
|
|
>
|
|
<path d="M18 6L6 18M6 6l12 12" />
|
|
</svg>
|
|
);`;
|
|
|
|
const App = `import React, {forwardRef, useMemo} from "react";
|
|
import {useAlert} from "@nextui-org/react";
|
|
import {InfoCircleIcon} from "./InfoCircleIcon";
|
|
import {CloseIcon} from "./CloseIcon"
|
|
|
|
const styles = {
|
|
base: [
|
|
"bg-slate-100",
|
|
"border",
|
|
"shadow",
|
|
"hover:bg-slate-200",
|
|
"focus-within:!bg-slate-100",
|
|
"dark:bg-slate-900",
|
|
"dark:hover:bg-slate-800",
|
|
"dark:border-slate-800",
|
|
"dark:focus-within:!bg-slate-900",
|
|
"cursor-pointer"
|
|
],
|
|
title: [
|
|
"text-base",
|
|
"text-slate-500",
|
|
"font-bold"
|
|
],
|
|
description: [
|
|
"text-base",
|
|
"text-slate-500",
|
|
],
|
|
}
|
|
|
|
const MyAlert = forwardRef((props, ref) => {
|
|
const {
|
|
title,
|
|
description,
|
|
isClosable,
|
|
domRef,
|
|
handleClose,
|
|
getBaseProps,
|
|
getMainWrapperProps,
|
|
getDescriptionProps,
|
|
getTitleProps,
|
|
getCloseButtonProps,
|
|
color,
|
|
isVisible,
|
|
onClose,
|
|
getCloseIconProps,
|
|
getAlertIconProps,
|
|
} = useAlert({
|
|
...props,
|
|
ref,
|
|
// this is just for the example, the props bellow should be passed by the parent component
|
|
title: "Email Sent!!",
|
|
description: "You will get a reply soon",
|
|
// custom styles
|
|
classNames: {
|
|
...styles,
|
|
},
|
|
});
|
|
|
|
const mainWrapper = useMemo(() => {
|
|
return (
|
|
<div {...getMainWrapperProps()}>
|
|
{title && <div {...getTitleProps()}>{title}</div>}
|
|
<div {...getDescriptionProps()}>{description}</div>
|
|
</div>
|
|
);
|
|
}, [title, description, getMainWrapperProps, getTitleProps, getDescriptionProps]);
|
|
|
|
const baseWrapper = useMemo(() => {
|
|
return isVisible ? (
|
|
<div ref={domRef} {...getBaseProps()}>
|
|
<InfoCircleIcon {...getAlertIconProps()} />
|
|
{mainWrapper}
|
|
{(isClosable || onClose) && (
|
|
<button onClick={handleClose} {...getCloseButtonProps()}>
|
|
<CloseIcon />
|
|
</button>
|
|
)}
|
|
</div>
|
|
) : null;
|
|
}, [
|
|
mainWrapper,
|
|
isClosable,
|
|
getCloseButtonProps,
|
|
isVisible,
|
|
domRef,
|
|
getBaseProps,
|
|
handleClose,
|
|
color,
|
|
onClose,
|
|
getAlertIconProps,
|
|
]);
|
|
|
|
return <>{baseWrapper}</>;
|
|
});
|
|
|
|
MyAlert.displayName = "MyAlert";
|
|
|
|
export default MyAlert;`;
|
|
|
|
const react = {
|
|
"/App.jsx": App,
|
|
"/InfoCircleIcon": InfoCircleIcon,
|
|
"/CloseIcon": CloseIcon,
|
|
};
|
|
|
|
export default {
|
|
...react,
|
|
};
|