tfy-web-components 0.0.19 → 0.0.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -4
- package/dist/..d.ts +46 -0
- package/dist/Accordion.d.ts +8 -9
- package/dist/Alert.d.ts +73 -0
- package/dist/AudioPlayer.d.ts +10 -0
- package/dist/Avatar.d.ts +19 -0
- package/dist/Badge.d.ts +2 -1
- package/dist/CopyField.d.ts +1 -0
- package/dist/CustomDrawer.d.ts +8 -1
- package/dist/DropdownMenu.d.ts +25 -0
- package/dist/IconButton.d.ts +4 -2
- package/dist/ImagesPreview.d.ts +12 -0
- package/dist/Input-CnGhA18d.js +74283 -0
- package/dist/Input-CnGhA18d.js.map +1 -0
- package/dist/Markdown.d.ts +103 -0
- package/dist/Modal.d.ts +12 -0
- package/dist/MonacoEditorCore-xfpJ6z-E.js +113 -0
- package/dist/MonacoEditorCore-xfpJ6z-E.js.map +1 -0
- package/dist/OpenUiFenceBlock-CsVY6kwA.js +20 -0
- package/dist/OpenUiFenceBlock-CsVY6kwA.js.map +1 -0
- package/dist/OutlinedRadio.d.ts +9 -0
- package/dist/RootFontSizeContext-7vgn7Y_k.js +22 -0
- package/dist/RootFontSizeContext-7vgn7Y_k.js.map +1 -0
- package/dist/SimpleCodeEditor.d.ts +63 -0
- package/dist/Skeleton.d.ts +7 -0
- package/dist/ThumbsFeedback.d.ts +18 -0
- package/dist/ToggleButton.d.ts +42 -0
- package/dist/UserMessage.d.ts +15 -0
- package/dist/UserMessageEdit.d.ts +16 -0
- package/dist/_commonjsHelpers-DWwsNxpa.js +9 -0
- package/dist/_commonjsHelpers-DWwsNxpa.js.map +1 -0
- package/dist/agent-chat.d.ts +222 -0
- package/dist/classNames-Dy-RXSjS.js +9 -0
- package/dist/{classNames-CC5emYUV.js.map → classNames-Dy-RXSjS.js.map} +1 -1
- package/dist/components/atoms/Accordion.d.ts +5 -6
- package/dist/components/atoms/Accordion.es.js +9 -7
- package/dist/components/atoms/Accordion.es.js.map +1 -1
- package/dist/components/atoms/AudioPlayer.d.ts +6 -0
- package/dist/components/atoms/AudioPlayer.es.js +1424 -0
- package/dist/components/atoms/AudioPlayer.es.js.map +1 -0
- package/dist/components/atoms/Avatar.d.ts +10 -0
- package/dist/components/atoms/Avatar.es.js +62 -0
- package/dist/components/atoms/Avatar.es.js.map +1 -0
- package/dist/components/atoms/Badge.d.ts +2 -1
- package/dist/components/atoms/Badge.es.js +9 -1
- package/dist/components/atoms/Badge.es.js.map +1 -1
- package/dist/components/atoms/Button.es.js +2 -2
- package/dist/components/atoms/IconButton.d.ts +4 -2
- package/dist/components/atoms/IconButton.es.js +23 -7
- package/dist/components/atoms/IconButton.es.js.map +1 -1
- package/dist/components/atoms/IconProvider.es.js +28 -2
- package/dist/components/atoms/IconProvider.es.js.map +1 -1
- package/dist/components/atoms/Modal.d.ts +8 -0
- package/dist/components/atoms/Modal.es.js +19 -0
- package/dist/components/atoms/Modal.es.js.map +1 -0
- package/dist/components/atoms/OutlinedRadio.d.ts +5 -0
- package/dist/components/atoms/OutlinedRadio.es.js +29 -0
- package/dist/components/atoms/OutlinedRadio.es.js.map +1 -0
- package/dist/components/atoms/Skeleton.d.ts +4 -0
- package/dist/components/atoms/Skeleton.es.js +9 -0
- package/dist/components/atoms/Skeleton.es.js.map +1 -0
- package/dist/components/atoms/Spinner.es.js +1 -1
- package/dist/components/atoms/Switch.es.js +1 -18
- package/dist/components/atoms/Switch.es.js.map +1 -1
- package/dist/components/atoms/TabButton.es.js +1 -1
- package/dist/components/atoms/TabPanel.es.js +1 -1
- package/dist/components/atoms/Tooltip.es.js +1 -1
- package/dist/components/molecules/Alert.d.ts +26 -0
- package/dist/components/molecules/Alert.es.js +135 -0
- package/dist/components/molecules/Alert.es.js.map +1 -0
- package/dist/components/molecules/CopyField.d.ts +1 -0
- package/dist/components/molecules/CopyField.es.js +12 -74192
- package/dist/components/molecules/CopyField.es.js.map +1 -1
- package/dist/components/molecules/CustomDrawer.d.ts +8 -1
- package/dist/components/molecules/CustomDrawer.es.js +118 -48
- package/dist/components/molecules/CustomDrawer.es.js.map +1 -1
- package/dist/components/molecules/Dialog.es.js +2570 -1519
- package/dist/components/molecules/Dialog.es.js.map +1 -1
- package/dist/components/molecules/DropdownMenu.d.ts +18 -0
- package/dist/components/molecules/DropdownMenu.es.js +104 -0
- package/dist/components/molecules/DropdownMenu.es.js.map +1 -0
- package/dist/components/molecules/ImagesPreview.d.ts +8 -0
- package/dist/components/molecules/ImagesPreview.es.js +186 -0
- package/dist/components/molecules/ImagesPreview.es.js.map +1 -0
- package/dist/components/molecules/Input.es.js +2 -2
- package/dist/components/molecules/Markdown.d.ts +1 -0
- package/dist/components/molecules/Markdown.es.js +345 -0
- package/dist/components/molecules/Markdown.es.js.map +1 -0
- package/dist/components/molecules/Notify.es.js +6 -1023
- package/dist/components/molecules/Notify.es.js.map +1 -1
- package/dist/components/molecules/SimpleCodeEditor.d.ts +56 -0
- package/dist/components/molecules/SimpleCodeEditor.es.js +784 -0
- package/dist/components/molecules/SimpleCodeEditor.es.js.map +1 -0
- package/dist/components/molecules/ThumbsFeedback.d.ts +13 -0
- package/dist/components/molecules/ThumbsFeedback.es.js +98 -0
- package/dist/components/molecules/ThumbsFeedback.es.js.map +1 -0
- package/dist/components/molecules/ToggleButton.d.ts +37 -0
- package/dist/components/molecules/ToggleButton.es.js +72 -0
- package/dist/components/molecules/ToggleButton.es.js.map +1 -0
- package/dist/components/molecules/agent-chat/UserMessage.d.ts +11 -0
- package/dist/components/molecules/agent-chat/UserMessage.es.js +40 -0
- package/dist/components/molecules/agent-chat/UserMessage.es.js.map +1 -0
- package/dist/components/molecules/agent-chat/UserMessageEdit.d.ts +12 -0
- package/dist/components/molecules/agent-chat/UserMessageEdit.es.js +33 -0
- package/dist/components/molecules/agent-chat/UserMessageEdit.es.js.map +1 -0
- package/dist/components/molecules/agent-chat.d.ts +1 -0
- package/dist/components/molecules/agent-chat.es.js +935 -0
- package/dist/components/molecules/agent-chat.es.js.map +1 -0
- package/dist/components/theme/theme.d.ts +1 -0
- package/dist/components/theme/theme.es.js +12 -1
- package/dist/components/theme/theme.es.js.map +1 -1
- package/dist/components/theme/useTheme.d.ts +7 -0
- package/dist/components/theme/useTheme.es.js +35 -20
- package/dist/components/theme/useTheme.es.js.map +1 -1
- package/dist/components/theme/utils.es.js +1 -1
- package/dist/index.es.js +12 -4
- package/dist/index.es.js.map +1 -1
- package/dist/{isTypedArray-CoDTnA8U.js → isTypedArray-CLAk7Q1f.js} +30 -30
- package/dist/isTypedArray-CLAk7Q1f.js.map +1 -0
- package/dist/style.css +1 -1
- package/dist/tailwindPreset.d.ts +140 -0
- package/dist/tailwindPreset.es.js +100 -0
- package/dist/tailwindPreset.es.js.map +1 -0
- package/dist/theme.css +163 -0
- package/dist/theme.d.ts +2 -0
- package/dist/useTheme.d.ts +7 -0
- package/package.json +49 -3
- package/dist/_commonjsHelpers-CcAunmGO.js +0 -34
- package/dist/_commonjsHelpers-CcAunmGO.js.map +0 -1
- package/dist/classNames-CC5emYUV.js +0 -9
- package/dist/isTypedArray-CoDTnA8U.js.map +0 -1
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import Radio from "@mui/material/Radio";
|
|
3
|
+
import { c as classNames } from "../../classNames-Dy-RXSjS.js";
|
|
4
|
+
const SIZE = 16;
|
|
5
|
+
const wrapperStyle = { width: SIZE, height: SIZE };
|
|
6
|
+
const OutlinedRadioIcon = ({ checked = false }) => /* @__PURE__ */ jsx(
|
|
7
|
+
"div",
|
|
8
|
+
{
|
|
9
|
+
className: classNames("w-4 h-4 shrink-0 box-border rounded-full border border-gray-300", {
|
|
10
|
+
"border-[0.3125rem] border-violet-500": checked
|
|
11
|
+
})
|
|
12
|
+
}
|
|
13
|
+
);
|
|
14
|
+
const radioSx = { p: 0, m: 0, width: "100%", height: "100%" };
|
|
15
|
+
const OutlinedRadio = (props) => /* @__PURE__ */ jsx("div", { className: "relative inline-flex shrink-0 items-start justify-start leading-none", style: wrapperStyle, children: /* @__PURE__ */ jsx(
|
|
16
|
+
Radio,
|
|
17
|
+
{
|
|
18
|
+
disableRipple: true,
|
|
19
|
+
size: "small",
|
|
20
|
+
...props,
|
|
21
|
+
icon: /* @__PURE__ */ jsx(OutlinedRadioIcon, {}),
|
|
22
|
+
checkedIcon: /* @__PURE__ */ jsx(OutlinedRadioIcon, { checked: true }),
|
|
23
|
+
sx: radioSx
|
|
24
|
+
}
|
|
25
|
+
) });
|
|
26
|
+
export {
|
|
27
|
+
OutlinedRadio as default
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=OutlinedRadio.es.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OutlinedRadio.es.js","sources":["../../../src/components/atoms/OutlinedRadio.tsx"],"sourcesContent":["import React from 'react'\nimport Radio, { RadioProps } from '@mui/material/Radio'\n\nimport classNames from '@/utils/classNames'\n\nconst SIZE = 16\nconst wrapperStyle = { width: SIZE, height: SIZE }\n\nconst OutlinedRadioIcon: React.FC<{ checked?: boolean }> = ({ checked = false }) => (\n <div\n className={classNames('w-4 h-4 shrink-0 box-border rounded-full border border-gray-300', {\n 'border-[0.3125rem] border-violet-500': checked,\n })}\n />\n)\n\nexport type OutlinedRadioProps = Omit<RadioProps, 'icon' | 'checkedIcon'>\n\nconst radioSx = { p: 0, m: 0, width: '100%', height: '100%' }\n\nconst OutlinedRadio: React.FC<OutlinedRadioProps> = (props) => (\n <div className=\"relative inline-flex shrink-0 items-start justify-start leading-none\" style={wrapperStyle}>\n <Radio\n disableRipple\n size=\"small\"\n {...props}\n icon={<OutlinedRadioIcon />}\n checkedIcon={<OutlinedRadioIcon checked />}\n sx={radioSx}\n />\n </div>\n)\n\nexport default OutlinedRadio\n"],"names":[],"mappings":";;;AAKA,MAAM,OAAO;AACb,MAAM,eAAe,EAAE,OAAO,MAAM,QAAQ,KAAA;AAE5C,MAAM,oBAAqD,CAAC,EAAE,UAAU,YACtE;AAAA,EAAC;AAAA,EAAA;AAAA,IACC,WAAW,WAAW,mEAAmE;AAAA,MACvF,wCAAwC;AAAA,IAAA,CACzC;AAAA,EAAA;AACH;AAKF,MAAM,UAAU,EAAE,GAAG,GAAG,GAAG,GAAG,OAAO,QAAQ,QAAQ,OAAA;AAErD,MAAM,gBAA8C,CAAC,UACnD,oBAAC,SAAI,WAAU,wEAAuE,OAAO,cAC3F,UAAA;AAAA,EAAC;AAAA,EAAA;AAAA,IACC,eAAa;AAAA,IACb,MAAK;AAAA,IACJ,GAAG;AAAA,IACJ,0BAAO,mBAAA,EAAkB;AAAA,IACzB,aAAa,oBAAC,mBAAA,EAAkB,SAAO,KAAA,CAAC;AAAA,IACxC,IAAI;AAAA,EAAA;AACN,EAAA,CACF;"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import MuiSkeleton from "@mui/material/Skeleton";
|
|
3
|
+
const Skeleton = (props) => {
|
|
4
|
+
return /* @__PURE__ */ jsx(MuiSkeleton, { animation: "wave", ...props });
|
|
5
|
+
};
|
|
6
|
+
export {
|
|
7
|
+
Skeleton as default
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=Skeleton.es.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Skeleton.es.js","sources":["../../../src/components/atoms/Skeleton.tsx"],"sourcesContent":["import React from 'react'\nimport { default as MuiSkeleton, SkeletonProps } from '@mui/material/Skeleton'\n\nconst Skeleton = (props: SkeletonProps) => {\n return <MuiSkeleton animation=\"wave\" {...props} />\n}\n\nexport default Skeleton\n"],"names":[],"mappings":";;AAGA,MAAM,WAAW,CAAC,UAAyB;AACzC,SAAO,oBAAC,aAAA,EAAY,WAAU,QAAQ,GAAG,OAAO;AAClD;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { c as classNames } from "../../classNames-
|
|
2
|
+
import { c as classNames } from "../../classNames-Dy-RXSjS.js";
|
|
3
3
|
const Spinner = ({ className, small, big, medium, center, type = "normal" }) => {
|
|
4
4
|
const isDefault = () => type === "normal";
|
|
5
5
|
const classes = classNames({
|
|
@@ -2,24 +2,7 @@ import styled from "@mui/material/styles/styled";
|
|
|
2
2
|
import NativeSwitch from "@mui/material/Switch";
|
|
3
3
|
import { colors } from "../theme/theme.es.js";
|
|
4
4
|
import { useTheme } from "../theme/useTheme.es.js";
|
|
5
|
-
import {
|
|
6
|
-
const getRootFontSize = () => {
|
|
7
|
-
const width = window.innerWidth;
|
|
8
|
-
switch (true) {
|
|
9
|
-
case width >= 3840:
|
|
10
|
-
return 32;
|
|
11
|
-
case width >= 2880:
|
|
12
|
-
return 24;
|
|
13
|
-
case width >= 2400:
|
|
14
|
-
return 20;
|
|
15
|
-
default:
|
|
16
|
-
return 16;
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
const RootFontSizeContext = createContext({
|
|
20
|
-
rootFontSize: getRootFontSize()
|
|
21
|
-
});
|
|
22
|
-
const useRootFontSize = () => useContext(RootFontSizeContext);
|
|
5
|
+
import { u as useRootFontSize } from "../../RootFontSizeContext-7vgn7Y_k.js";
|
|
23
6
|
const getDimensions = (widthMultiple, heightMultiple, thumbWidthMultiple, rootFontSize) => {
|
|
24
7
|
const WIDTH = widthMultiple * rootFontSize;
|
|
25
8
|
const HEIGHT = heightMultiple * rootFontSize;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Switch.es.js","sources":["../../../src/
|
|
1
|
+
{"version":3,"file":"Switch.es.js","sources":["../../../src/components/atoms/Switch.tsx"],"sourcesContent":["import styled from '@mui/material/styles/styled'\nimport NativeSwitch from '@mui/material/Switch'\n\nimport { colors } from '@/components/theme/theme'\nimport useTheme from '@/components/theme/useTheme'\n\nimport { useRootFontSize } from '@/contexts/RootFontSizeContext'\n\ninterface InputHTMLAttributesExtended extends React.InputHTMLAttributes<HTMLInputElement> {\n 'data-test'?: string\n}\n\nexport interface StyledSwitchProps {\n inputProps?: InputHTMLAttributesExtended\n widthMultiple?: number\n heightMultiple?: number\n thumbWidthMultiple?: number\n}\n\nconst getDimensions = (\n widthMultiple: number,\n heightMultiple: number,\n thumbWidthMultiple: number,\n rootFontSize: number,\n) => {\n const WIDTH = widthMultiple * rootFontSize\n const HEIGHT = heightMultiple * rootFontSize\n const THUMB_WIDTH = thumbWidthMultiple * rootFontSize\n\n return { WIDTH, HEIGHT, THUMB_WIDTH }\n}\n\nconst Switch = styled(NativeSwitch, {\n shouldForwardProp: (prop: string) => !['widthMultiple', 'heightMultiple', 'thumbWidthMultiple'].includes(prop),\n})<StyledSwitchProps>(({ theme, widthMultiple = 2, heightMultiple = 1, thumbWidthMultiple = 0.9375 }) => {\n const { isDark } = useTheme()\n const { rootFontSize } = useRootFontSize()\n const { WIDTH, HEIGHT, THUMB_WIDTH } = getDimensions(widthMultiple, heightMultiple, thumbWidthMultiple, rootFontSize)\n return {\n width: WIDTH,\n height: HEIGHT,\n padding: 0,\n display: 'flex',\n '&:active': {\n '& .MuiSwitch-thumb': {\n width: THUMB_WIDTH,\n },\n '& .MuiSwitch-switchBase.Mui-checked': {\n transform: 'translateX(1rem)',\n },\n },\n '& .MuiSwitch-switchBase': {\n padding: 2,\n '&.Mui-checked': {\n transform: `translateX(${WIDTH - THUMB_WIDTH - 1}px)`,\n color: '#fff',\n '& + .MuiSwitch-track': {\n opacity: 1,\n background: isDark\n ? colors.indigo[500]\n : 'radial-gradient(84.37% 84.37% at 50% 100%, #2900CE 0%, #5429FF 100%), linear-gradient(0deg, #5501E1 40.19%, #2F5FFF 111.1%)',\n },\n },\n },\n '& .MuiSwitch-thumb': {\n boxShadow: '0 0.125rem 0.25rem 0 rgb(0 35 11 / 20%)',\n width: '0.75rem',\n height: '0.75rem',\n borderRadius: '0.375rem',\n transition: theme.transitions.create(['width'], {\n duration: 200,\n }),\n },\n '& .MuiSwitch-track': {\n borderRadius: '0.5rem',\n opacity: 1,\n backgroundColor: isDark ? colors.gray[500] : colors.gray[200],\n boxSizing: 'border-box',\n },\n }\n})\n\nexport default Switch\n"],"names":[],"mappings":";;;;;AAmBA,MAAM,gBAAgB,CACpB,eACA,gBACA,oBACA,iBACG;AACH,QAAM,QAAQ,gBAAgB;AAC9B,QAAM,SAAS,iBAAiB;AAChC,QAAM,cAAc,qBAAqB;AAEzC,SAAO,EAAE,OAAO,QAAQ,YAAA;AAC1B;AAEA,MAAM,SAAS,OAAO,cAAc;AAAA,EAClC,mBAAmB,CAAC,SAAiB,CAAC,CAAC,iBAAiB,kBAAkB,oBAAoB,EAAE,SAAS,IAAI;AAC/G,CAAC,EAAqB,CAAC,EAAE,OAAO,gBAAgB,GAAG,iBAAiB,GAAG,qBAAqB,aAAa;AACvG,QAAM,EAAE,OAAA,IAAW,SAAA;AACnB,QAAM,EAAE,aAAA,IAAiB,gBAAA;AACzB,QAAM,EAAE,OAAO,QAAQ,YAAA,IAAgB,cAAc,eAAe,gBAAgB,oBAAoB,YAAY;AACpH,SAAO;AAAA,IACL,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,SAAS;AAAA,IACT,YAAY;AAAA,MACV,sBAAsB;AAAA,QACpB,OAAO;AAAA,MAAA;AAAA,MAET,uCAAuC;AAAA,QACrC,WAAW;AAAA,MAAA;AAAA,IACb;AAAA,IAEF,2BAA2B;AAAA,MACzB,SAAS;AAAA,MACT,iBAAiB;AAAA,QACf,WAAW,cAAc,QAAQ,cAAc,CAAC;AAAA,QAChD,OAAO;AAAA,QACP,wBAAwB;AAAA,UACtB,SAAS;AAAA,UACT,YAAY,SACR,OAAO,OAAO,GAAG,IACjB;AAAA,QAAA;AAAA,MACN;AAAA,IACF;AAAA,IAEF,sBAAsB;AAAA,MACpB,WAAW;AAAA,MACX,OAAO;AAAA,MACP,QAAQ;AAAA,MACR,cAAc;AAAA,MACd,YAAY,MAAM,YAAY,OAAO,CAAC,OAAO,GAAG;AAAA,QAC9C,UAAU;AAAA,MAAA,CACX;AAAA,IAAA;AAAA,IAEH,sBAAsB;AAAA,MACpB,cAAc;AAAA,MACd,SAAS;AAAA,MACT,iBAAiB,SAAS,OAAO,KAAK,GAAG,IAAI,OAAO,KAAK,GAAG;AAAA,MAC5D,WAAW;AAAA,IAAA;AAAA,EACb;AAEJ,CAAC;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import Tab from "@mui/material/Tab";
|
|
3
3
|
import Tooltip from "@mui/material/Tooltip";
|
|
4
|
-
import { c as classNames } from "../../classNames-
|
|
4
|
+
import { c as classNames } from "../../classNames-Dy-RXSjS.js";
|
|
5
5
|
import IconProvider from "./IconProvider.es.js";
|
|
6
6
|
const TabButton = ({ icon, text, tooltip, textClassName, iconSize, isActive, ...props }) => /* @__PURE__ */ jsx(
|
|
7
7
|
Tab,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { c as classNames } from "../../classNames-
|
|
2
|
+
import { c as classNames } from "../../classNames-Dy-RXSjS.js";
|
|
3
3
|
const TabPanel = ({ children, id, isActive, className, activeClassName, ...other }) => {
|
|
4
4
|
return /* @__PURE__ */ jsx(
|
|
5
5
|
"div",
|
|
@@ -3,7 +3,7 @@ import * as React from "react";
|
|
|
3
3
|
import styled from "@mui/material/styles/styled";
|
|
4
4
|
import Tooltip, { tooltipClasses } from "@mui/material/Tooltip";
|
|
5
5
|
import { colors } from "../theme/theme.es.js";
|
|
6
|
-
import { c as classNames } from "../../classNames-
|
|
6
|
+
import { c as classNames } from "../../classNames-Dy-RXSjS.js";
|
|
7
7
|
const getSize = (size) => {
|
|
8
8
|
let height = 380;
|
|
9
9
|
let width = 250;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type ButtonProps } from '../../components/atoms/Button';
|
|
3
|
+
import { type ModalProps } from '../../components/atoms/Modal';
|
|
4
|
+
export type AlertProps = Omit<ModalProps, 'children'> & {
|
|
5
|
+
title: string;
|
|
6
|
+
message: string | JSX.Element | React.ReactNode;
|
|
7
|
+
onConfirm: () => Promise<void>;
|
|
8
|
+
onError?: (e: unknown) => void;
|
|
9
|
+
onCloseAfterConfirm?: () => void;
|
|
10
|
+
confirmButtonText?: string;
|
|
11
|
+
confirmString?: string;
|
|
12
|
+
confirmStringMessage?: string | JSX.Element;
|
|
13
|
+
confirmStringEntity?: string;
|
|
14
|
+
confirmButtonIcon?: ButtonProps['icon'];
|
|
15
|
+
confirmButtonClasses?: string;
|
|
16
|
+
confirmButtonDisabled?: boolean;
|
|
17
|
+
cancelButtonText?: string;
|
|
18
|
+
messageClasses?: string;
|
|
19
|
+
titleClasses?: string;
|
|
20
|
+
hideCancel?: boolean;
|
|
21
|
+
formClasses?: string;
|
|
22
|
+
onClose: (forced: boolean, afterConfirm: boolean) => void;
|
|
23
|
+
dataTestPrefix?: string;
|
|
24
|
+
};
|
|
25
|
+
declare const Alert: React.FC<AlertProps>;
|
|
26
|
+
export default Alert;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import classNames from "classnames";
|
|
4
|
+
import { Button } from "../atoms/Button.es.js";
|
|
5
|
+
import Modal from "../atoms/Modal.es.js";
|
|
6
|
+
import { t as toDataTestId } from "../../Notification-BT4CZ69U.js";
|
|
7
|
+
import { I as Input } from "../../Input-CnGhA18d.js";
|
|
8
|
+
const Alert = ({
|
|
9
|
+
title,
|
|
10
|
+
message,
|
|
11
|
+
onConfirm,
|
|
12
|
+
onClose,
|
|
13
|
+
onError,
|
|
14
|
+
onCloseAfterConfirm,
|
|
15
|
+
confirmString,
|
|
16
|
+
confirmStringMessage,
|
|
17
|
+
confirmStringEntity,
|
|
18
|
+
confirmButtonText,
|
|
19
|
+
confirmButtonIcon,
|
|
20
|
+
confirmButtonClasses,
|
|
21
|
+
confirmButtonDisabled,
|
|
22
|
+
cancelButtonText,
|
|
23
|
+
messageClasses,
|
|
24
|
+
titleClasses,
|
|
25
|
+
formClasses,
|
|
26
|
+
hideCancel = false,
|
|
27
|
+
dataTestPrefix,
|
|
28
|
+
...rest
|
|
29
|
+
}) => {
|
|
30
|
+
const [loading, setLoading] = useState(false);
|
|
31
|
+
const [confirmInput, setConfirmInput] = useState("");
|
|
32
|
+
const shouldDisable = confirmString ? confirmString !== confirmInput : false;
|
|
33
|
+
const onConfirmClick = async () => {
|
|
34
|
+
if (shouldDisable) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
setLoading(true);
|
|
38
|
+
try {
|
|
39
|
+
await onConfirm();
|
|
40
|
+
} catch (e) {
|
|
41
|
+
onError == null ? void 0 : onError(e);
|
|
42
|
+
setLoading(false);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
setLoading(false);
|
|
46
|
+
onClose(false, true);
|
|
47
|
+
onCloseAfterConfirm == null ? void 0 : onCloseAfterConfirm();
|
|
48
|
+
};
|
|
49
|
+
return /* @__PURE__ */ jsx(
|
|
50
|
+
Modal,
|
|
51
|
+
{
|
|
52
|
+
...rest,
|
|
53
|
+
onClose: () => {
|
|
54
|
+
if (!loading) {
|
|
55
|
+
onClose(false, false);
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
children: /* @__PURE__ */ jsxs(
|
|
59
|
+
"form",
|
|
60
|
+
{
|
|
61
|
+
className: classNames("modal-box p-4 rounded-lg dark:bg-gray-250", formClasses),
|
|
62
|
+
"data-test": toDataTestId("alert-modal", dataTestPrefix),
|
|
63
|
+
onSubmit: (e) => {
|
|
64
|
+
e.stopPropagation();
|
|
65
|
+
e.preventDefault();
|
|
66
|
+
onConfirmClick();
|
|
67
|
+
},
|
|
68
|
+
children: [
|
|
69
|
+
/* @__PURE__ */ jsx(
|
|
70
|
+
"h3",
|
|
71
|
+
{
|
|
72
|
+
className: classNames("font-bold text-xl text-gray-850", titleClasses),
|
|
73
|
+
"data-test": toDataTestId("alert-title", dataTestPrefix),
|
|
74
|
+
children: title
|
|
75
|
+
}
|
|
76
|
+
),
|
|
77
|
+
typeof message === "string" ? /* @__PURE__ */ jsx(
|
|
78
|
+
"div",
|
|
79
|
+
{
|
|
80
|
+
className: classNames("py-3 text-sm text-gray-650", messageClasses),
|
|
81
|
+
"data-test": toDataTestId("alert-message", dataTestPrefix),
|
|
82
|
+
children: message
|
|
83
|
+
}
|
|
84
|
+
) : message,
|
|
85
|
+
confirmString && /* @__PURE__ */ jsx(
|
|
86
|
+
Input,
|
|
87
|
+
{
|
|
88
|
+
text: confirmStringMessage || /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
89
|
+
"Type ",
|
|
90
|
+
/* @__PURE__ */ jsx("span", { className: "font-bold", children: confirmStringEntity || confirmString }),
|
|
91
|
+
" to continue:"
|
|
92
|
+
] }),
|
|
93
|
+
name: "confirm-string",
|
|
94
|
+
value: confirmInput,
|
|
95
|
+
className: "input-sm py-2",
|
|
96
|
+
wrapperClasses: "mt-1",
|
|
97
|
+
onChange: (e) => setConfirmInput(e.target.value)
|
|
98
|
+
}
|
|
99
|
+
),
|
|
100
|
+
/* @__PURE__ */ jsxs("div", { className: "modal-action mt-3", children: [
|
|
101
|
+
!hideCancel && /* @__PURE__ */ jsx(
|
|
102
|
+
Button.Secondary,
|
|
103
|
+
{
|
|
104
|
+
type: "reset",
|
|
105
|
+
text: cancelButtonText || "Cancel",
|
|
106
|
+
onClick: () => {
|
|
107
|
+
onClose(true, false);
|
|
108
|
+
},
|
|
109
|
+
disabled: loading,
|
|
110
|
+
dataTestId: toDataTestId("alert-cancel-btn", dataTestPrefix)
|
|
111
|
+
}
|
|
112
|
+
),
|
|
113
|
+
/* @__PURE__ */ jsx(
|
|
114
|
+
Button.Primary,
|
|
115
|
+
{
|
|
116
|
+
type: "submit",
|
|
117
|
+
text: confirmButtonText || "Yes",
|
|
118
|
+
icon: confirmButtonIcon,
|
|
119
|
+
loading,
|
|
120
|
+
disabled: shouldDisable || confirmButtonDisabled,
|
|
121
|
+
dataTestId: toDataTestId("alert-confirm-btn", dataTestPrefix),
|
|
122
|
+
autoFocus: true
|
|
123
|
+
}
|
|
124
|
+
)
|
|
125
|
+
] })
|
|
126
|
+
]
|
|
127
|
+
}
|
|
128
|
+
)
|
|
129
|
+
}
|
|
130
|
+
);
|
|
131
|
+
};
|
|
132
|
+
export {
|
|
133
|
+
Alert as default
|
|
134
|
+
};
|
|
135
|
+
//# sourceMappingURL=Alert.es.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Alert.es.js","sources":["../../../src/components/molecules/Alert.tsx"],"sourcesContent":["import React, { useState } from 'react'\nimport classNames from 'classnames'\n\nimport { Button, type ButtonProps } from '@/components/atoms/Button'\nimport Modal, { type ModalProps } from '@/components/atoms/Modal'\n\nimport { toDataTestId } from '@/utils/conversions'\n\nimport Input from './Input'\n\nexport type AlertProps = Omit<ModalProps, 'children'> & {\n title: string\n message: string | JSX.Element | React.ReactNode\n onConfirm: () => Promise<void>\n onError?: (e: unknown) => void\n onCloseAfterConfirm?: () => void\n confirmButtonText?: string\n confirmString?: string\n confirmStringMessage?: string | JSX.Element\n confirmStringEntity?: string\n confirmButtonIcon?: ButtonProps['icon']\n confirmButtonClasses?: string\n confirmButtonDisabled?: boolean\n cancelButtonText?: string\n messageClasses?: string\n titleClasses?: string\n hideCancel?: boolean\n formClasses?: string\n onClose: (forced: boolean, afterConfirm: boolean) => void\n dataTestPrefix?: string\n}\n\nconst Alert: React.FC<AlertProps> = ({\n title,\n message,\n onConfirm,\n onClose,\n onError,\n onCloseAfterConfirm,\n confirmString,\n confirmStringMessage,\n confirmStringEntity,\n confirmButtonText,\n confirmButtonIcon,\n confirmButtonClasses,\n confirmButtonDisabled,\n cancelButtonText,\n messageClasses,\n titleClasses,\n formClasses,\n hideCancel = false,\n dataTestPrefix,\n ...rest\n}) => {\n const [loading, setLoading] = useState(false)\n const [confirmInput, setConfirmInput] = useState('')\n const shouldDisable = confirmString ? confirmString !== confirmInput : false\n const onConfirmClick = async () => {\n if (shouldDisable) {\n return\n }\n setLoading(true)\n try {\n await onConfirm()\n } catch (e) {\n onError?.(e)\n setLoading(false)\n return\n }\n setLoading(false)\n onClose(false, true)\n onCloseAfterConfirm?.()\n }\n\n return (\n <Modal\n {...rest}\n onClose={() => {\n if (!loading) {\n onClose(false, false)\n }\n }}\n >\n <form\n className={classNames('modal-box p-4 rounded-lg dark:bg-gray-250', formClasses)}\n data-test={toDataTestId('alert-modal', dataTestPrefix)}\n onSubmit={(e) => {\n e.stopPropagation()\n e.preventDefault()\n onConfirmClick()\n }}\n >\n <h3\n className={classNames('font-bold text-xl text-gray-850', titleClasses)}\n data-test={toDataTestId('alert-title', dataTestPrefix)}\n >\n {title}\n </h3>\n {typeof message === 'string' ? (\n <div\n className={classNames('py-3 text-sm text-gray-650', messageClasses)}\n data-test={toDataTestId('alert-message', dataTestPrefix)}\n >\n {message}\n </div>\n ) : (\n message\n )}\n {confirmString && (\n <Input\n text={\n confirmStringMessage || (\n <>\n Type <span className=\"font-bold\">{confirmStringEntity || confirmString}</span> to continue:\n </>\n )\n }\n name=\"confirm-string\"\n value={confirmInput}\n className=\"input-sm py-2\"\n wrapperClasses=\"mt-1\"\n onChange={(e) => setConfirmInput(e.target.value)}\n />\n )}\n <div className=\"modal-action mt-3\">\n {!hideCancel && (\n <Button.Secondary\n type=\"reset\"\n text={cancelButtonText || 'Cancel'}\n onClick={() => {\n onClose(true, false)\n }}\n disabled={loading}\n dataTestId={toDataTestId('alert-cancel-btn', dataTestPrefix)}\n />\n )}\n <Button.Primary\n type=\"submit\"\n text={confirmButtonText || 'Yes'}\n icon={confirmButtonIcon}\n loading={loading}\n disabled={shouldDisable || confirmButtonDisabled}\n dataTestId={toDataTestId('alert-confirm-btn', dataTestPrefix)}\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