kelt-ui-kit-react 1.2.6 → 1.2.7
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/dist/index.js +65 -60
- package/dist/style.css +1 -1
- package/dist/toaster/store/useToasterStore.d.ts +1 -0
- package/package.json +1 -1
- package/src/App.tsx +2 -0
- package/src/index.css +1 -1
- package/src/toaster/Toaster.tsx +10 -2
- package/src/toaster/Toaster.view.tsx +22 -1
- package/src/toaster/store/useToasterStore.tsx +2 -0
- package/src/toaster/toaster.css +31 -1
package/package.json
CHANGED
package/src/App.tsx
CHANGED
|
@@ -6,12 +6,14 @@ import { AppMenu } from "./App.menu";
|
|
|
6
6
|
import { AppRoutes } from "./App.routes";
|
|
7
7
|
import { Header } from "./header/Header";
|
|
8
8
|
import { OverlayProvider } from "./overlayPanel/overlay.context";
|
|
9
|
+
import { Toaster } from "./toaster/Toaster";
|
|
9
10
|
|
|
10
11
|
const App: React.FC = () => (
|
|
11
12
|
<StrictMode>
|
|
12
13
|
<OverlayProvider>
|
|
13
14
|
<Router>
|
|
14
15
|
<div className="main-layout">
|
|
16
|
+
<Toaster />
|
|
15
17
|
<Header />
|
|
16
18
|
<div className="d-flex h-100">
|
|
17
19
|
<AppMenu />
|
package/src/index.css
CHANGED
package/src/toaster/Toaster.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useEffect } from "react";
|
|
1
|
+
import { useCallback, useEffect } from "react";
|
|
2
2
|
import ReactDOM from "react-dom";
|
|
3
3
|
import { Icon } from "../icon/Icon";
|
|
4
4
|
import { useToasterStore } from "./store/useToasterStore";
|
|
@@ -13,8 +13,11 @@ export const Toaster = () => {
|
|
|
13
13
|
children,
|
|
14
14
|
duration,
|
|
15
15
|
hideToast,
|
|
16
|
+
close,
|
|
16
17
|
} = useToasterStore();
|
|
17
|
-
|
|
18
|
+
const onClose = useCallback(() => {
|
|
19
|
+
hideToast();
|
|
20
|
+
}, [hideToast]);
|
|
18
21
|
useEffect(() => {
|
|
19
22
|
if (!visible) return;
|
|
20
23
|
const timer = setTimeout(() => {
|
|
@@ -30,6 +33,11 @@ export const Toaster = () => {
|
|
|
30
33
|
|
|
31
34
|
return ReactDOM.createPortal(
|
|
32
35
|
<div className={`toaster toaster-${severity}`}>
|
|
36
|
+
{close && (
|
|
37
|
+
<div className="toaster--close" onClick={onClose}>
|
|
38
|
+
<Icon classIcon="bi-x" />
|
|
39
|
+
</div>
|
|
40
|
+
)}
|
|
33
41
|
<div>
|
|
34
42
|
{severity === "info" && <Icon classIcon="bi-info-circle" />}
|
|
35
43
|
{severity === "success" && <Icon classIcon="bi-check-circle" />}
|
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
import { Button } from "../button/Button";
|
|
3
|
+
import { useToasterStore } from "./store/useToasterStore";
|
|
4
|
+
|
|
1
5
|
export const ToasterView = (): JSX.Element => {
|
|
2
|
-
|
|
6
|
+
const { showToast } = useToasterStore();
|
|
7
|
+
const handleClickToast = useCallback(() => {
|
|
8
|
+
showToast("This is a toast message", {
|
|
9
|
+
description: "This is a description for the toast message.",
|
|
10
|
+
severity: "warning",
|
|
11
|
+
duration: 10000,
|
|
12
|
+
children: <div>Additional content can go here.</div>,
|
|
13
|
+
});
|
|
14
|
+
}, [showToast]);
|
|
15
|
+
return (
|
|
16
|
+
<div>
|
|
17
|
+
<Button
|
|
18
|
+
title="Show Toast"
|
|
19
|
+
onClick={handleClickToast}
|
|
20
|
+
className="btn btn-primary"
|
|
21
|
+
/>
|
|
22
|
+
</div>
|
|
23
|
+
);
|
|
3
24
|
};
|
|
@@ -7,6 +7,7 @@ type ToasterState = {
|
|
|
7
7
|
children?: React.ReactNode;
|
|
8
8
|
visible: boolean;
|
|
9
9
|
duration: number;
|
|
10
|
+
close?: boolean;
|
|
10
11
|
showToast: (
|
|
11
12
|
title: string,
|
|
12
13
|
options?: {
|
|
@@ -25,6 +26,7 @@ export const useToasterStore = create<ToasterState>((set) => ({
|
|
|
25
26
|
severity: "info",
|
|
26
27
|
visible: false,
|
|
27
28
|
duration: 2500,
|
|
29
|
+
close: true,
|
|
28
30
|
children: null,
|
|
29
31
|
showToast: (title, options = {}) =>
|
|
30
32
|
set(() => ({
|
package/src/toaster/toaster.css
CHANGED
|
@@ -11,17 +11,47 @@
|
|
|
11
11
|
width: 300px;
|
|
12
12
|
border-radius: 4px;
|
|
13
13
|
border: 1px solid #dede;
|
|
14
|
+
.toaster--close {
|
|
15
|
+
position: absolute;
|
|
16
|
+
top: 2px;
|
|
17
|
+
right: 2px;
|
|
18
|
+
color: #333;
|
|
19
|
+
cursor: pointer;
|
|
20
|
+
.bi {
|
|
21
|
+
font-size: 1.2rem;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
14
24
|
&.toaster-info {
|
|
15
25
|
border-color: #004aad66;
|
|
26
|
+
.toaster--close {
|
|
27
|
+
bi {
|
|
28
|
+
color: #004aad;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
16
31
|
}
|
|
17
32
|
&.toaster-success {
|
|
18
33
|
border-color: #28a7458c;
|
|
34
|
+
.toaster--close {
|
|
35
|
+
.bi {
|
|
36
|
+
color: #28a745;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
19
39
|
}
|
|
20
40
|
&.toaster-warning {
|
|
21
|
-
border-color: #
|
|
41
|
+
border-color: #ec942c;
|
|
42
|
+
.toaster--close {
|
|
43
|
+
bi {
|
|
44
|
+
color: #ec942c;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
22
47
|
}
|
|
23
48
|
&.toaster-error {
|
|
24
49
|
border-color: #dc35457d;
|
|
50
|
+
.toaster--close {
|
|
51
|
+
bi {
|
|
52
|
+
color: #dc3545;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
25
55
|
}
|
|
26
56
|
.title {
|
|
27
57
|
font-weight: 500;
|