@julseb-lib/react 0.0.45 → 0.0.47
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 +392 -378
- package/dist/index.es.js +2643 -2625
- package/dist/index.umd.js +500 -486
- package/dist/lib/components/Toast/Toast.tsx +11 -14
- package/dist/lib/components/Toast/Toaster.tsx +15 -26
- package/dist/lib/components/Toast/styles.tsx +53 -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
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
IconContainer,
|
|
13
13
|
CloseButton,
|
|
14
14
|
Timer,
|
|
15
|
+
Title,
|
|
15
16
|
} from "./styles"
|
|
16
17
|
import type { ILibToast } from "./types"
|
|
17
18
|
|
|
@@ -28,7 +29,7 @@ const CLOSE_ICON_SIZE = 24
|
|
|
28
29
|
* @prop toasterPosition?: "top-left" | "top-right" | "bottom-left" | "bottom-right"
|
|
29
30
|
* @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
31
|
* @prop hideCloseButton?: boolean
|
|
31
|
-
* @prop status?: "success" | "error" | "warning" | "info"
|
|
32
|
+
* @prop status?: "success" | "error" | "warning" | "info"
|
|
32
33
|
* @prop options?: LibToastOptions
|
|
33
34
|
*
|
|
34
35
|
* @type LibToastOptions
|
|
@@ -55,10 +56,11 @@ export const Toast = forwardRef<HTMLDivElement, ILibToast>(
|
|
|
55
56
|
title,
|
|
56
57
|
id = uuid(),
|
|
57
58
|
options,
|
|
58
|
-
|
|
59
|
+
maxWidth = 400,
|
|
59
60
|
toasterPosition,
|
|
60
61
|
role = "alert",
|
|
61
62
|
hideCloseButton,
|
|
63
|
+
status,
|
|
62
64
|
...rest
|
|
63
65
|
},
|
|
64
66
|
ref
|
|
@@ -93,10 +95,8 @@ export const Toast = forwardRef<HTMLDivElement, ILibToast>(
|
|
|
93
95
|
role={role}
|
|
94
96
|
id={id}
|
|
95
97
|
className={classNames(className, { Open: isOpen })}
|
|
96
|
-
$
|
|
97
|
-
$
|
|
98
|
-
$shadow={toastStyle?.shadow}
|
|
99
|
-
$textColor={toastStyle?.textColor || "font"}
|
|
98
|
+
$status={status}
|
|
99
|
+
$maxWidth={maxWidth}
|
|
100
100
|
$toasterPosition={toasterPosition}
|
|
101
101
|
{...rest}
|
|
102
102
|
>
|
|
@@ -126,14 +126,13 @@ export const Toast = forwardRef<HTMLDivElement, ILibToast>(
|
|
|
126
126
|
</IconContainer>
|
|
127
127
|
)}
|
|
128
128
|
|
|
129
|
-
<
|
|
130
|
-
tag="h6"
|
|
131
|
-
as="p"
|
|
129
|
+
<Title
|
|
132
130
|
data-testid={testid && `${testid}.TitleContainer.Title`}
|
|
133
131
|
className={className && "Title"}
|
|
132
|
+
tag="strong"
|
|
134
133
|
>
|
|
135
134
|
{title}
|
|
136
|
-
</
|
|
135
|
+
</Title>
|
|
137
136
|
|
|
138
137
|
{!hideCloseButton && (
|
|
139
138
|
<IconContainer
|
|
@@ -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,
|
|
@@ -10,56 +11,51 @@ import {
|
|
|
10
11
|
SPACERS,
|
|
11
12
|
TRANSITIONS,
|
|
12
13
|
setDefaultTheme,
|
|
14
|
+
Text,
|
|
13
15
|
} from "../../"
|
|
14
16
|
import type {
|
|
15
17
|
LibAllColors,
|
|
16
|
-
ILibBorder,
|
|
17
|
-
LibShadows,
|
|
18
18
|
LibToasterPosition,
|
|
19
|
+
LibToastStatus,
|
|
19
20
|
} from "../../types"
|
|
20
21
|
|
|
21
22
|
const OpenFromLeft = keyframes`
|
|
22
|
-
|
|
23
|
+
0% { transform: translateX(-100%); }
|
|
23
24
|
|
|
24
|
-
|
|
25
|
+
100% { transform: translateX(0); }
|
|
25
26
|
`
|
|
26
27
|
|
|
27
28
|
const CloseFromLeft = keyframes`
|
|
28
|
-
|
|
29
|
+
0% { transform: translateX(0); }
|
|
29
30
|
|
|
30
|
-
|
|
31
|
+
100% { transform: translateX(-100%); }
|
|
31
32
|
`
|
|
32
33
|
|
|
33
34
|
const OpenFromRight = keyframes`
|
|
34
|
-
|
|
35
|
+
0% { transform: translateX(100%); }
|
|
35
36
|
|
|
36
|
-
|
|
37
|
+
100% { transform: translateX(0); }
|
|
37
38
|
`
|
|
38
39
|
|
|
39
40
|
const CloseFromRight = keyframes`
|
|
40
|
-
|
|
41
|
+
0% { transform: translateX(0); }
|
|
41
42
|
|
|
42
|
-
|
|
43
|
+
100% { transform: translateX(100%); }
|
|
43
44
|
`
|
|
44
45
|
|
|
45
46
|
const StyledToast = styled.div<{
|
|
46
|
-
$
|
|
47
|
-
$textColor: LibAllColors
|
|
48
|
-
$border: ILibBorder
|
|
49
|
-
$shadow?: LibShadows
|
|
47
|
+
$status: LibToastStatus
|
|
50
48
|
$toasterPosition?: LibToasterPosition
|
|
49
|
+
$maxWidth: string | number
|
|
51
50
|
}>`
|
|
52
51
|
position: relative;
|
|
53
52
|
width: 100%;
|
|
53
|
+
max-width: ${({ $maxWidth }) => stringifyPx($maxWidth)};
|
|
54
54
|
padding: ${SPACERS.S};
|
|
55
55
|
border-radius: ${RADIUSES.M};
|
|
56
|
-
background-color: ${({ theme, $backgroundColor }) =>
|
|
57
|
-
Mixins.AllColors($backgroundColor, theme)};
|
|
58
|
-
color: ${({ theme, $textColor }) => Mixins.AllColors($textColor, theme)};
|
|
59
56
|
transition: ${TRANSITIONS.SHORT};
|
|
57
|
+
border: 1px solid;
|
|
60
58
|
overflow: hidden;
|
|
61
|
-
${({ $border }) => Mixins.Border($border)};
|
|
62
|
-
${({ $shadow }) => Mixins.Shadow($shadow)};
|
|
63
59
|
|
|
64
60
|
${({ $toasterPosition }) => {
|
|
65
61
|
const speedAndFunction = "200ms ease"
|
|
@@ -87,6 +83,36 @@ const StyledToast = styled.div<{
|
|
|
87
83
|
return null
|
|
88
84
|
}
|
|
89
85
|
}}
|
|
86
|
+
|
|
87
|
+
${({ $status, theme }) => {
|
|
88
|
+
switch ($status) {
|
|
89
|
+
case "success":
|
|
90
|
+
return css`
|
|
91
|
+
background-color: ${Mixins.AllColors("success-50", theme)};
|
|
92
|
+
border-color: ${Mixins.AllColors("success", theme)};
|
|
93
|
+
`
|
|
94
|
+
case "error":
|
|
95
|
+
return css`
|
|
96
|
+
background-color: ${Mixins.AllColors("danger-50", theme)};
|
|
97
|
+
border-color: ${Mixins.AllColors("danger", theme)};
|
|
98
|
+
`
|
|
99
|
+
case "warning":
|
|
100
|
+
return css`
|
|
101
|
+
background-color: ${Mixins.AllColors("warning-50", theme)};
|
|
102
|
+
border-color: ${Mixins.AllColors("warning", theme)};
|
|
103
|
+
`
|
|
104
|
+
case "info":
|
|
105
|
+
return css`
|
|
106
|
+
background-color: ${Mixins.AllColors(
|
|
107
|
+
"secondary-50",
|
|
108
|
+
theme
|
|
109
|
+
)};
|
|
110
|
+
border-color: ${Mixins.AllColors("secondary", theme)};
|
|
111
|
+
`
|
|
112
|
+
default:
|
|
113
|
+
return null
|
|
114
|
+
}
|
|
115
|
+
}}
|
|
90
116
|
`
|
|
91
117
|
|
|
92
118
|
const TitleContainer = styled.div`
|
|
@@ -136,9 +162,9 @@ const CloseButton = styled.button`
|
|
|
136
162
|
`
|
|
137
163
|
|
|
138
164
|
const Progress = keyframes`
|
|
139
|
-
|
|
165
|
+
0% { width: 100%; }
|
|
140
166
|
|
|
141
|
-
|
|
167
|
+
100% { width: 0; }
|
|
142
168
|
`
|
|
143
169
|
|
|
144
170
|
const Timer = styled.span<{
|
|
@@ -198,6 +224,10 @@ const StyledToaster = styled.div<{ $position: LibToasterPosition }>`
|
|
|
198
224
|
}}
|
|
199
225
|
`
|
|
200
226
|
|
|
227
|
+
const Title = styled(Text)`
|
|
228
|
+
width: 100%;
|
|
229
|
+
` as any
|
|
230
|
+
|
|
201
231
|
setDefaultTheme([
|
|
202
232
|
StyledToast,
|
|
203
233
|
TitleContainer,
|
|
@@ -205,6 +235,7 @@ setDefaultTheme([
|
|
|
205
235
|
CloseButton,
|
|
206
236
|
Timer,
|
|
207
237
|
StyledToaster,
|
|
238
|
+
Title,
|
|
208
239
|
])
|
|
209
240
|
|
|
210
241
|
export {
|
|
@@ -214,4 +245,5 @@ export {
|
|
|
214
245
|
CloseButton,
|
|
215
246
|
Timer,
|
|
216
247
|
StyledToaster,
|
|
248
|
+
Title,
|
|
217
249
|
}
|
|
@@ -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
|