@julseb-lib/react 0.0.45 → 0.0.46
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.cjs.js +246 -234
- package/dist/index.es.js +1610 -1594
- package/dist/index.umd.js +384 -372
- package/dist/lib/components/Toast/Toast.tsx +7 -10
- package/dist/lib/components/Toast/Toaster.tsx +15 -26
- package/dist/lib/components/Toast/styles.tsx +46 -21
- package/dist/lib/components/Toast/types.ts +1 -10
- package/dist/lib/types/component-items.ts +1 -1
- package/dist/lib/types/type-values.ts +0 -1
- package/package.json +1 -1
|
@@ -28,7 +28,7 @@ const CLOSE_ICON_SIZE = 24
|
|
|
28
28
|
* @prop toasterPosition?: "top-left" | "top-right" | "bottom-left" | "bottom-right"
|
|
29
29
|
* @prop toastStyle?: { maxWidth?: string | number; border?: { style?: CssBorderStyle; width?: "xxl" | "xl" | "l" | "m" | "s" | "xs" | "xxs" | number | "0px"; color?: Any color from the library }; backgroundColor?: Any color from the library; textColor?: Any color from the library; shadow?: "xxl" | "xl" | "l" | "m" | "s" | "xs" }
|
|
30
30
|
* @prop hideCloseButton?: boolean
|
|
31
|
-
* @prop status?: "success" | "error" | "warning" | "info"
|
|
31
|
+
* @prop status?: "success" | "error" | "warning" | "info"
|
|
32
32
|
* @prop options?: LibToastOptions
|
|
33
33
|
*
|
|
34
34
|
* @type LibToastOptions
|
|
@@ -55,10 +55,11 @@ export const Toast = forwardRef<HTMLDivElement, ILibToast>(
|
|
|
55
55
|
title,
|
|
56
56
|
id = uuid(),
|
|
57
57
|
options,
|
|
58
|
-
|
|
58
|
+
maxWidth = 400,
|
|
59
59
|
toasterPosition,
|
|
60
60
|
role = "alert",
|
|
61
61
|
hideCloseButton,
|
|
62
|
+
status,
|
|
62
63
|
...rest
|
|
63
64
|
},
|
|
64
65
|
ref
|
|
@@ -93,10 +94,8 @@ export const Toast = forwardRef<HTMLDivElement, ILibToast>(
|
|
|
93
94
|
role={role}
|
|
94
95
|
id={id}
|
|
95
96
|
className={classNames(className, { Open: isOpen })}
|
|
96
|
-
$
|
|
97
|
-
$
|
|
98
|
-
$shadow={toastStyle?.shadow}
|
|
99
|
-
$textColor={toastStyle?.textColor || "font"}
|
|
97
|
+
$status={status}
|
|
98
|
+
$maxWidth={maxWidth}
|
|
100
99
|
$toasterPosition={toasterPosition}
|
|
101
100
|
{...rest}
|
|
102
101
|
>
|
|
@@ -199,11 +198,9 @@ export const Toast = forwardRef<HTMLDivElement, ILibToast>(
|
|
|
199
198
|
<Timer
|
|
200
199
|
data-testid={testid && `${testid}.Timer`}
|
|
201
200
|
className={className && "Timer"}
|
|
202
|
-
$duration={options?.duration
|
|
201
|
+
$duration={options?.duration ?? 3000}
|
|
203
202
|
$backgroundColor={
|
|
204
|
-
options?.timerBackgroundColor
|
|
205
|
-
toastStyle?.border?.color ||
|
|
206
|
-
"gray-200"
|
|
203
|
+
options?.timerBackgroundColor ?? "success-200"
|
|
207
204
|
}
|
|
208
205
|
/>
|
|
209
206
|
)}
|
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
import { forwardRef } from "react"
|
|
4
4
|
import { uuid } from "@julseb-lib/utils"
|
|
5
|
-
import { Loader } from "../Loader"
|
|
6
5
|
import { Toast } from "./Toast"
|
|
7
|
-
import type { LibAllColors } from "../../types"
|
|
6
|
+
import type { LibAllColors, LibToastStatus } from "../../types"
|
|
8
7
|
import { StyledToaster } from "./styles"
|
|
9
8
|
import type { ILibToaster } from "./types"
|
|
10
9
|
|
|
@@ -12,44 +11,37 @@ const DEFAULT_ICON_SIZE = 16
|
|
|
12
11
|
|
|
13
12
|
const toastStatusStyles: {
|
|
14
13
|
[key: string]: {
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
status: LibToastStatus
|
|
15
|
+
timerColor: LibAllColors
|
|
17
16
|
iconLeftColor: LibAllColors
|
|
18
17
|
iconLeft?: JSX.Element
|
|
19
18
|
iconLeftSize: number
|
|
20
19
|
}
|
|
21
20
|
} = {
|
|
22
21
|
success: {
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
status: "success",
|
|
23
|
+
timerColor: "success",
|
|
25
24
|
iconLeftColor: "success",
|
|
26
25
|
iconLeftSize: DEFAULT_ICON_SIZE,
|
|
27
26
|
},
|
|
28
27
|
error: {
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
status: "error",
|
|
29
|
+
timerColor: "danger",
|
|
31
30
|
iconLeftColor: "danger",
|
|
32
31
|
iconLeftSize: DEFAULT_ICON_SIZE,
|
|
33
32
|
},
|
|
34
33
|
warning: {
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
status: "warning",
|
|
35
|
+
timerColor: "warning",
|
|
37
36
|
iconLeftColor: "warning",
|
|
38
37
|
iconLeftSize: DEFAULT_ICON_SIZE,
|
|
39
38
|
},
|
|
40
39
|
info: {
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
status: "info",
|
|
41
|
+
timerColor: "primary",
|
|
43
42
|
iconLeftColor: "primary",
|
|
44
43
|
iconLeftSize: DEFAULT_ICON_SIZE,
|
|
45
44
|
},
|
|
46
|
-
loading: {
|
|
47
|
-
backgroundColor: "white",
|
|
48
|
-
borderColor: "gray",
|
|
49
|
-
iconLeftColor: "gray",
|
|
50
|
-
iconLeftSize: DEFAULT_ICON_SIZE,
|
|
51
|
-
iconLeft: <Loader size={DEFAULT_ICON_SIZE} borderWidth={2} />,
|
|
52
|
-
},
|
|
53
45
|
}
|
|
54
46
|
|
|
55
47
|
/**
|
|
@@ -110,7 +102,7 @@ export const Toaster = forwardRef<HTMLDivElement, ILibToaster>(
|
|
|
110
102
|
{...rest}
|
|
111
103
|
>
|
|
112
104
|
{toasts.map(toast => {
|
|
113
|
-
const styles = toastStatusStyles[status || "success"]
|
|
105
|
+
const styles = toastStatusStyles[toast.status || "success"]
|
|
114
106
|
|
|
115
107
|
return (
|
|
116
108
|
<Toast
|
|
@@ -160,15 +152,12 @@ export const Toaster = forwardRef<HTMLDivElement, ILibToaster>(
|
|
|
160
152
|
body: toast.options?.body,
|
|
161
153
|
id: toast.options?.id || toast.id,
|
|
162
154
|
timerBackgroundColor:
|
|
163
|
-
toast.options?.timerBackgroundColor ||
|
|
164
|
-
styles.
|
|
155
|
+
toast.options?.timerBackgroundColor ||
|
|
156
|
+
styles.timerColor,
|
|
165
157
|
...toastsOptions,
|
|
166
158
|
...toast.options,
|
|
167
159
|
}}
|
|
168
|
-
|
|
169
|
-
backgroundColor: styles.backgroundColor,
|
|
170
|
-
border: { color: styles.borderColor },
|
|
171
|
-
}}
|
|
160
|
+
status={toast.status}
|
|
172
161
|
key={uuid()}
|
|
173
162
|
/>
|
|
174
163
|
)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/*=============================================== Toast styles ===============================================*/
|
|
2
2
|
|
|
3
3
|
import styled, { keyframes, css } from "styled-components"
|
|
4
|
+
import { stringifyPx } from "@julseb-lib/utils"
|
|
4
5
|
import {
|
|
5
6
|
MEDIA,
|
|
6
7
|
FONT_SIZES,
|
|
@@ -13,53 +14,47 @@ import {
|
|
|
13
14
|
} from "../../"
|
|
14
15
|
import type {
|
|
15
16
|
LibAllColors,
|
|
16
|
-
ILibBorder,
|
|
17
|
-
LibShadows,
|
|
18
17
|
LibToasterPosition,
|
|
18
|
+
LibToastStatus,
|
|
19
19
|
} from "../../types"
|
|
20
20
|
|
|
21
21
|
const OpenFromLeft = keyframes`
|
|
22
|
-
|
|
22
|
+
0% { transform: translateX(-100%); }
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
100% { transform: translateX(0); }
|
|
25
25
|
`
|
|
26
26
|
|
|
27
27
|
const CloseFromLeft = keyframes`
|
|
28
|
-
|
|
28
|
+
0% { transform: translateX(0); }
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
100% { transform: translateX(-100%); }
|
|
31
31
|
`
|
|
32
32
|
|
|
33
33
|
const OpenFromRight = keyframes`
|
|
34
|
-
|
|
34
|
+
0% { transform: translateX(100%); }
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
100% { transform: translateX(0); }
|
|
37
37
|
`
|
|
38
38
|
|
|
39
39
|
const CloseFromRight = keyframes`
|
|
40
|
-
|
|
40
|
+
0% { transform: translateX(0); }
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
100% { transform: translateX(100%); }
|
|
43
43
|
`
|
|
44
44
|
|
|
45
45
|
const StyledToast = styled.div<{
|
|
46
|
-
$
|
|
47
|
-
$textColor: LibAllColors
|
|
48
|
-
$border: ILibBorder
|
|
49
|
-
$shadow?: LibShadows
|
|
46
|
+
$status: LibToastStatus
|
|
50
47
|
$toasterPosition?: LibToasterPosition
|
|
48
|
+
$maxWidth: string | number
|
|
51
49
|
}>`
|
|
52
50
|
position: relative;
|
|
53
51
|
width: 100%;
|
|
52
|
+
max-width: ${({ $maxWidth }) => stringifyPx($maxWidth)};
|
|
54
53
|
padding: ${SPACERS.S};
|
|
55
54
|
border-radius: ${RADIUSES.M};
|
|
56
|
-
background-color: ${({ theme, $backgroundColor }) =>
|
|
57
|
-
Mixins.AllColors($backgroundColor, theme)};
|
|
58
|
-
color: ${({ theme, $textColor }) => Mixins.AllColors($textColor, theme)};
|
|
59
55
|
transition: ${TRANSITIONS.SHORT};
|
|
56
|
+
border: 1px solid;
|
|
60
57
|
overflow: hidden;
|
|
61
|
-
${({ $border }) => Mixins.Border($border)};
|
|
62
|
-
${({ $shadow }) => Mixins.Shadow($shadow)};
|
|
63
58
|
|
|
64
59
|
${({ $toasterPosition }) => {
|
|
65
60
|
const speedAndFunction = "200ms ease"
|
|
@@ -87,6 +82,36 @@ const StyledToast = styled.div<{
|
|
|
87
82
|
return null
|
|
88
83
|
}
|
|
89
84
|
}}
|
|
85
|
+
|
|
86
|
+
${({ $status, theme }) => {
|
|
87
|
+
switch ($status) {
|
|
88
|
+
case "success":
|
|
89
|
+
return css`
|
|
90
|
+
background-color: ${Mixins.AllColors("success-50", theme)};
|
|
91
|
+
border-color: ${Mixins.AllColors("success", theme)};
|
|
92
|
+
`
|
|
93
|
+
case "error":
|
|
94
|
+
return css`
|
|
95
|
+
background-color: ${Mixins.AllColors("danger-50", theme)};
|
|
96
|
+
border-color: ${Mixins.AllColors("danger", theme)};
|
|
97
|
+
`
|
|
98
|
+
case "warning":
|
|
99
|
+
return css`
|
|
100
|
+
background-color: ${Mixins.AllColors("warning-50", theme)};
|
|
101
|
+
border-color: ${Mixins.AllColors("warning", theme)};
|
|
102
|
+
`
|
|
103
|
+
case "info":
|
|
104
|
+
return css`
|
|
105
|
+
background-color: ${Mixins.AllColors(
|
|
106
|
+
"secondary-50",
|
|
107
|
+
theme
|
|
108
|
+
)};
|
|
109
|
+
border-color: ${Mixins.AllColors("secondary", theme)};
|
|
110
|
+
`
|
|
111
|
+
default:
|
|
112
|
+
return null
|
|
113
|
+
}
|
|
114
|
+
}}
|
|
90
115
|
`
|
|
91
116
|
|
|
92
117
|
const TitleContainer = styled.div`
|
|
@@ -136,9 +161,9 @@ const CloseButton = styled.button`
|
|
|
136
161
|
`
|
|
137
162
|
|
|
138
163
|
const Progress = keyframes`
|
|
139
|
-
|
|
164
|
+
0% { width: 100%; }
|
|
140
165
|
|
|
141
|
-
|
|
166
|
+
100% { width: 0; }
|
|
142
167
|
`
|
|
143
168
|
|
|
144
169
|
const Timer = styled.span<{
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
/*=============================================== Toast types ===============================================*/
|
|
2
2
|
|
|
3
3
|
import type {
|
|
4
|
-
LibAllColors,
|
|
5
|
-
ILibBorder,
|
|
6
4
|
LibComponentBase,
|
|
7
|
-
LibShadows,
|
|
8
5
|
LibToasterPosition,
|
|
9
6
|
LibToast,
|
|
10
7
|
LibToastOptions,
|
|
@@ -13,13 +10,7 @@ import type {
|
|
|
13
10
|
export interface ILibToast extends LibComponentBase<HTMLDivElement>, LibToast {
|
|
14
11
|
title: string
|
|
15
12
|
toasterPosition?: LibToasterPosition
|
|
16
|
-
|
|
17
|
-
maxWidth?: string | number
|
|
18
|
-
border?: ILibBorder
|
|
19
|
-
backgroundColor?: LibAllColors
|
|
20
|
-
textColor?: LibAllColors
|
|
21
|
-
shadow?: LibShadows
|
|
22
|
-
}
|
|
13
|
+
maxWidth?: string | number
|
|
23
14
|
hideCloseButton?: boolean
|
|
24
15
|
}
|
|
25
16
|
|
|
@@ -276,7 +276,7 @@ export interface LibToastOptions extends LibComponentItemBase<HTMLDivElement> {
|
|
|
276
276
|
* @prop ref?: ForwardedRef<HTMLDivElement>
|
|
277
277
|
* @prop title: string
|
|
278
278
|
* @prop id?: string
|
|
279
|
-
* @prop status?: "success" | "error" | "warning" | "info"
|
|
279
|
+
* @prop status?: "success" | "error" | "warning" | "info"
|
|
280
280
|
* @prop options?: LibToastOptions
|
|
281
281
|
*
|
|
282
282
|
* @type LibToastOptions
|