@darajs/ui-notifications 0.4.8
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/LICENSE +201 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/notification-payload.d.ts +27 -0
- package/dist/notification-payload.d.ts.map +1 -0
- package/dist/notification-payload.js +2 -0
- package/dist/notification-payload.js.map +1 -0
- package/dist/notification-wrapper.d.ts +26 -0
- package/dist/notification-wrapper.d.ts.map +1 -0
- package/dist/notification-wrapper.js +88 -0
- package/dist/notification-wrapper.js.map +1 -0
- package/dist/notification.d.ts +18 -0
- package/dist/notification.d.ts.map +1 -0
- package/dist/notification.js +122 -0
- package/dist/notification.js.map +1 -0
- package/dist/use-notifications.d.ts +30 -0
- package/dist/use-notifications.d.ts.map +1 -0
- package/dist/use-notifications.js +29 -0
- package/dist/use-notifications.js.map +1 -0
- package/package.json +64 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2023 Impulse Innovations Ltd.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023 Impulse Innovations Limited
|
|
3
|
+
*
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
export { NotificationPayload } from './notification-payload';
|
|
18
|
+
export { default as NotificationWrapper, NotificationContext } from './notification-wrapper';
|
|
19
|
+
export { useNotifications, UseNotificationsInterface } from './use-notifications';
|
|
20
|
+
export { default as Notification } from './notification';
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7F,OAAO,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAClF,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAiBA,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7F,OAAO,EAAE,gBAAgB,EAA6B,MAAM,qBAAqB,CAAC;AAClF,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023 Impulse Innovations Limited
|
|
3
|
+
*
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import { Status } from '@darajs/ui-utils';
|
|
18
|
+
/**
|
|
19
|
+
* The Data structure for defining a notification
|
|
20
|
+
*/
|
|
21
|
+
export interface NotificationPayload {
|
|
22
|
+
key: string;
|
|
23
|
+
message: string;
|
|
24
|
+
status: Status;
|
|
25
|
+
title?: string;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=notification-payload.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notification-payload.d.ts","sourceRoot":"","sources":["../src/notification-payload.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAChC,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notification-payload.js","sourceRoot":"","sources":["../src/notification-payload.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Subject } from 'rxjs';
|
|
3
|
+
import { NotificationPayload } from './notification-payload';
|
|
4
|
+
/**
|
|
5
|
+
* The main notification context, it exposes a stream of notifications to anything wanting to consume them as well as a
|
|
6
|
+
* generic push method for sending a new one
|
|
7
|
+
* Additionally, it exposes a callback for when the notification is too small and more details are needed and clicked
|
|
8
|
+
*/
|
|
9
|
+
export declare const NotificationContext: React.Context<{
|
|
10
|
+
notifications$: Subject<NotificationPayload>;
|
|
11
|
+
onMoreDetailsClick: any;
|
|
12
|
+
push: (notification: NotificationPayload) => void;
|
|
13
|
+
}>;
|
|
14
|
+
interface NotificationWrapperProps {
|
|
15
|
+
/** Optional, pass through of the native style property */
|
|
16
|
+
style?: React.CSSProperties;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The notification wrapper adds an invisible container to the right hand side of the application that feeds
|
|
20
|
+
* notifications in from the bottom by subscribing to the notifications$ stream on context
|
|
21
|
+
*
|
|
22
|
+
* @param props the component props
|
|
23
|
+
*/
|
|
24
|
+
declare function NotificationWrapper(props: NotificationWrapperProps): JSX.Element;
|
|
25
|
+
export default NotificationWrapper;
|
|
26
|
+
//# sourceMappingURL=notification-wrapper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notification-wrapper.d.ts","sourceRoot":"","sources":["../src/notification-wrapper.tsx"],"names":[],"mappings":"AAiBA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAO/B,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AA4B7D;;;;GAIG;AACH,eAAO,MAAM,mBAAmB;;;yBAGP,mBAAmB;EAC1C,CAAC;AAIH,UAAU,wBAAwB;IAC9B,0DAA0D;IAC1D,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;CAC/B;AAED;;;;;GAKG;AACH,iBAAS,mBAAmB,CAAC,KAAK,EAAE,wBAAwB,GAAG,GAAG,CAAC,OAAO,CA6CzE;AAED,eAAe,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright 2023 Impulse Innovations Limited
|
|
4
|
+
*
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
import { useCallback, useContext, useEffect, useState } from 'react';
|
|
19
|
+
import * as React from 'react';
|
|
20
|
+
import { Subject } from 'rxjs';
|
|
21
|
+
import { delay } from 'rxjs/operators';
|
|
22
|
+
import styled from '@darajs/styled-components';
|
|
23
|
+
import { useSubscription } from '@darajs/ui-utils';
|
|
24
|
+
import Notification from './notification';
|
|
25
|
+
const Container = styled.div `
|
|
26
|
+
pointer-events: none;
|
|
27
|
+
|
|
28
|
+
position: fixed;
|
|
29
|
+
z-index: 6000;
|
|
30
|
+
right: 1rem;
|
|
31
|
+
|
|
32
|
+
display: flex;
|
|
33
|
+
flex-direction: column;
|
|
34
|
+
gap: 1rem;
|
|
35
|
+
align-items: center;
|
|
36
|
+
justify-content: flex-end;
|
|
37
|
+
|
|
38
|
+
width: 324px;
|
|
39
|
+
height: 100%;
|
|
40
|
+
padding: 0.75rem 0;
|
|
41
|
+
`;
|
|
42
|
+
const baseNotifications$ = new Subject();
|
|
43
|
+
/**
|
|
44
|
+
* The main notification context, it exposes a stream of notifications to anything wanting to consume them as well as a
|
|
45
|
+
* generic push method for sending a new one
|
|
46
|
+
* Additionally, it exposes a callback for when the notification is too small and more details are needed and clicked
|
|
47
|
+
*/
|
|
48
|
+
export const NotificationContext = React.createContext({
|
|
49
|
+
notifications$: baseNotifications$,
|
|
50
|
+
onMoreDetailsClick: null,
|
|
51
|
+
push: (notification) => baseNotifications$.next(notification),
|
|
52
|
+
});
|
|
53
|
+
const EXPIRY = 9900; // Set to just below 10s so notifications close before polling occurs
|
|
54
|
+
/**
|
|
55
|
+
* The notification wrapper adds an invisible container to the right hand side of the application that feeds
|
|
56
|
+
* notifications in from the bottom by subscribing to the notifications$ stream on context
|
|
57
|
+
*
|
|
58
|
+
* @param props the component props
|
|
59
|
+
*/
|
|
60
|
+
function NotificationWrapper(props) {
|
|
61
|
+
const [notifications, setNotifications] = useState([]);
|
|
62
|
+
const wrapSub = useSubscription();
|
|
63
|
+
const { notifications$, onMoreDetailsClick } = useContext(NotificationContext);
|
|
64
|
+
// Subscribe to the notifications stream and add them to the list of notifications to render
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
if (notifications$) {
|
|
67
|
+
wrapSub(notifications$.subscribe({
|
|
68
|
+
next: (notification) => {
|
|
69
|
+
setNotifications((prev) => [...prev.filter((n) => n.key !== notification.key), notification]);
|
|
70
|
+
},
|
|
71
|
+
}));
|
|
72
|
+
}
|
|
73
|
+
}, [notifications$, wrapSub]);
|
|
74
|
+
// Subscribe to the notifications stream delayed by 10s and remove notifications from the list
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
wrapSub(notifications$.pipe(delay(EXPIRY)).subscribe({
|
|
77
|
+
next: (notification) => {
|
|
78
|
+
setNotifications((prev) => prev.filter(({ key }) => notification.key !== key));
|
|
79
|
+
},
|
|
80
|
+
}));
|
|
81
|
+
}, [notifications$, wrapSub]);
|
|
82
|
+
const onDismiss = useCallback((key) => {
|
|
83
|
+
setNotifications((prev) => prev.filter((notification) => notification.key !== key));
|
|
84
|
+
}, []);
|
|
85
|
+
return (_jsx(Container, { style: props.style, children: notifications.map((notification) => (_jsx(Notification, { notification: notification, onDismiss: onDismiss, onMoreDetailsClick: onMoreDetailsClick }, notification.key))) }));
|
|
86
|
+
}
|
|
87
|
+
export default NotificationWrapper;
|
|
88
|
+
//# sourceMappingURL=notification-wrapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notification-wrapper.js","sourceRoot":"","sources":["../src/notification-wrapper.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACrE,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAEvC,OAAO,MAAM,MAAM,2BAA2B,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEnD,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAG1C,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAA;;;;;;;;;;;;;;;;CAgB3B,CAAC;AAQF,MAAM,kBAAkB,GAAG,IAAI,OAAO,EAAuB,CAAC;AAE9D;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,CAAC,aAAa,CAAC;IACnD,cAAc,EAAE,kBAAkB;IAClC,kBAAkB,EAAE,IAAI;IACxB,IAAI,EAAE,CAAC,YAAiC,EAAE,EAAE,CAAC,kBAAkB,CAAC,IAAI,CAAC,YAAY,CAAC;CACrF,CAAC,CAAC;AAEH,MAAM,MAAM,GAAG,IAAI,CAAC,CAAC,qEAAqE;AAO1F;;;;;GAKG;AACH,SAAS,mBAAmB,CAAC,KAA+B;IACxD,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAG,QAAQ,CAA6B,EAAE,CAAC,CAAC;IACnF,MAAM,OAAO,GAAG,eAAe,EAAE,CAAC;IAClC,MAAM,E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CACH,KAAC,SAAS,IAAC,KAAK,EAAE,KAAK,CAAC,KAAK,YACxB,aAAa,CAAC,GAAG,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,CACjC,KAAC,YAAY,IAET,YAAY,EAAE,YAAY,EAC1B,SAAS,EAAE,SAAS,EACpB,kBAAkB,EAAE,kBAAkB,IAHjC,YAAY,CAAC,GAAG,CAIvB,CACL,CAAC,GACM,CACf,CAAC;AACN,CAAC;AAED,eAAe,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { NotificationPayload } from './notification-payload';
|
|
2
|
+
export interface NotificationProps {
|
|
3
|
+
/** The notification to render */
|
|
4
|
+
notification: NotificationPayload;
|
|
5
|
+
/** Handler to trigger the dismissal of the notification */
|
|
6
|
+
onDismiss?: (key: string) => void | Promise<void>;
|
|
7
|
+
/** Optional handler to trigger when the more details button is clicked */
|
|
8
|
+
onMoreDetailsClick?: (e: React.MouseEvent<HTMLButtonElement, MouseEvent>, notification: NotificationPayload) => void;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Simple display component for a notification, will pick up the status, title and message and display them. Also
|
|
12
|
+
* renders a dismiss button in the top right corner.
|
|
13
|
+
*
|
|
14
|
+
* @param props the component props
|
|
15
|
+
*/
|
|
16
|
+
declare function Notification(props: NotificationProps): JSX.Element;
|
|
17
|
+
export default Notification;
|
|
18
|
+
//# sourceMappingURL=notification.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notification.d.ts","sourceRoot":"","sources":["../src/notification.tsx"],"names":[],"mappings":"AAsBA,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAgH7D,MAAM,WAAW,iBAAiB;IAC9B,iCAAiC;IACjC,YAAY,EAAE,mBAAmB,CAAC;IAClC,2DAA2D;IAC3D,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAClD,0EAA0E;IAC1E,kBAAkB,CAAC,EAAE,CACjB,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,iBAAiB,EAAE,UAAU,CAAC,EAClD,YAAY,EAAE,mBAAmB,KAChC,IAAI,CAAC;CACb;AAED;;;;;GAKG;AACH,iBAAS,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,GAAG,CAAC,OAAO,CAuB3D;AAED,eAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright 2023 Impulse Innovations Limited
|
|
4
|
+
*
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
import { mix } from 'polished';
|
|
19
|
+
import styled, { theme } from '@darajs/styled-components';
|
|
20
|
+
import { CircleCheck, CircleInfo, CircleXmark, Cross, TriangleExclamation } from '@darajs/ui-icons';
|
|
21
|
+
import { Status, getStatusColor } from '@darajs/ui-utils';
|
|
22
|
+
const NotificationWrapper = styled.div `
|
|
23
|
+
pointer-events: auto;
|
|
24
|
+
|
|
25
|
+
display: flex;
|
|
26
|
+
align-items: center;
|
|
27
|
+
justify-content: space-between;
|
|
28
|
+
|
|
29
|
+
width: 22rem;
|
|
30
|
+
height: ${(props) => (props.hasTitle ? '5.625rem' : '4.375rem')};
|
|
31
|
+
padding: 1rem;
|
|
32
|
+
|
|
33
|
+
color: ${(props) => getStatusColor(props.status, props.theme.colors)};
|
|
34
|
+
|
|
35
|
+
background-color: ${(props) => mix(0.1, getStatusColor(props.status, props.theme.colors), props.theme.colors.background)};
|
|
36
|
+
border: 1px solid ${(props) => getStatusColor(props.status, props.theme.colors)};
|
|
37
|
+
border-radius: 0.25rem;
|
|
38
|
+
box-shadow: 0 2px 4px rgb(0 0 0 / 10%);
|
|
39
|
+
`;
|
|
40
|
+
const Message = styled.div `
|
|
41
|
+
display: flex;
|
|
42
|
+
flex-direction: column;
|
|
43
|
+
|
|
44
|
+
width: 15.75rem;
|
|
45
|
+
|
|
46
|
+
font-size: 1rem;
|
|
47
|
+
line-height: 1.1875rem;
|
|
48
|
+
`;
|
|
49
|
+
// -webkit-box worked in Chrome, Safari and Firefox so we will be ignoring linting here as it was the simplest solution
|
|
50
|
+
const Heading = styled.h2 `
|
|
51
|
+
overflow: hidden;
|
|
52
|
+
display: -webkit-box; /* stylelint-disable-line value-no-vendor-prefix */
|
|
53
|
+
-webkit-box-orient: vertical;
|
|
54
|
+
|
|
55
|
+
font-size: 1rem;
|
|
56
|
+
font-weight: 700;
|
|
57
|
+
text-overflow: ellipsis;
|
|
58
|
+
|
|
59
|
+
-webkit-line-clamp: 1;
|
|
60
|
+
`;
|
|
61
|
+
const Body = styled.span `
|
|
62
|
+
overflow: hidden;
|
|
63
|
+
display: -webkit-box; /* stylelint-disable-line value-no-vendor-prefix */
|
|
64
|
+
-webkit-box-orient: vertical;
|
|
65
|
+
|
|
66
|
+
font-weight: 400;
|
|
67
|
+
line-height: 1.25rem;
|
|
68
|
+
text-overflow: ellipsis;
|
|
69
|
+
|
|
70
|
+
-webkit-line-clamp: ${(props) => (props.moreDetailsShown ? 1 : 2)};
|
|
71
|
+
`;
|
|
72
|
+
const Icon = styled.div `
|
|
73
|
+
display: flex;
|
|
74
|
+
|
|
75
|
+
svg {
|
|
76
|
+
width: 1.5rem;
|
|
77
|
+
height: 1.3125rem;
|
|
78
|
+
color: ${(props) => getStatusColor(props.status, props.theme.colors)};
|
|
79
|
+
}
|
|
80
|
+
`;
|
|
81
|
+
const MoreDetailsButton = styled.button `
|
|
82
|
+
cursor: pointer;
|
|
83
|
+
|
|
84
|
+
display: flex;
|
|
85
|
+
|
|
86
|
+
padding-left: 0;
|
|
87
|
+
|
|
88
|
+
color: ${() => theme.colors.grey4};
|
|
89
|
+
|
|
90
|
+
background: transparent;
|
|
91
|
+
border: none;
|
|
92
|
+
|
|
93
|
+
:hover {
|
|
94
|
+
text-decoration: underline;
|
|
95
|
+
}
|
|
96
|
+
`;
|
|
97
|
+
const CloseBtn = styled(Cross) `
|
|
98
|
+
height: 1.2rem;
|
|
99
|
+
color: ${(props) => getStatusColor(props.status, props.theme.colors)};
|
|
100
|
+
`;
|
|
101
|
+
function getIcon(status) {
|
|
102
|
+
if ([Status.ERROR, Status.FAILED].includes(status)) {
|
|
103
|
+
return _jsx(CircleXmark, {});
|
|
104
|
+
}
|
|
105
|
+
if ([Status.CANCELED, Status.WARNING].includes(status)) {
|
|
106
|
+
return _jsx(TriangleExclamation, {});
|
|
107
|
+
}
|
|
108
|
+
return status === Status.SUCCESS ? _jsx(CircleCheck, {}) : _jsx(CircleInfo, {});
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Simple display component for a notification, will pick up the status, title and message and display them. Also
|
|
112
|
+
* renders a dismiss button in the top right corner.
|
|
113
|
+
*
|
|
114
|
+
* @param props the component props
|
|
115
|
+
*/
|
|
116
|
+
function Notification(props) {
|
|
117
|
+
const isOverflowing = props.notification.message.length > 30;
|
|
118
|
+
const showMoreDetails = props.onMoreDetailsClick && isOverflowing;
|
|
119
|
+
return (_jsxs(NotificationWrapper, { hasTitle: !!props.notification.title, status: props.notification.status, children: [_jsx(Icon, { status: props.notification.status, children: getIcon(props.notification.status) }), _jsxs(Message, { children: [_jsx(Heading, { children: props.notification.title }), _jsx(Body, { moreDetailsShown: showMoreDetails, children: props.notification.message }), showMoreDetails && (_jsx(MoreDetailsButton, { onClick: (e) => props.onMoreDetailsClick(e, props.notification), type: "button", children: "Details >" }))] }), _jsx(CloseBtn, { asButton: true, onClick: () => props.onDismiss(props.notification.key), status: props.notification.status })] }));
|
|
120
|
+
}
|
|
121
|
+
export default Notification;
|
|
122
|
+
//# sourceMappingURL=notification.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notification.js","sourceRoot":"","sources":["../src/notification.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B,OAAO,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACpG,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAiB1D,MAAM,mBAAmB,GAAG,MAAM,CAAC,GAAG,CAA0B;;;;;;;;cAQlD,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC;;;aAGtD,CAAC,KAAK,EAAE,EAAE,CAAC,cAAc,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC;;wBAEhD,CAAC,KAAK,EAAE,EAAE,CAC1B,GAAG,CAAC,GAAG,EAAE,cAAc,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC;wBACzE,CAAC,KAAK,EAAE,EAAE,CAAC,cAAc,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC;;;C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innovations Limited
|
|
3
|
+
*
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import { CurriedFunction2 } from 'lodash';
|
|
18
|
+
import { NotificationPayload } from './notification-payload';
|
|
19
|
+
export interface UseNotificationsInterface {
|
|
20
|
+
pushErrorNotification: CurriedFunction2<string, Error, void>;
|
|
21
|
+
pushNotification: (notification: NotificationPayload) => void;
|
|
22
|
+
pushWarningNotification: CurriedFunction2<string, Error, void>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* A helper hook that exposes some helpful methods for defining notifications quickly based of error messages. The error
|
|
26
|
+
* and warning functions are both curried so they can easily be dropped into error handling call backs with only the
|
|
27
|
+
* title defined
|
|
28
|
+
*/
|
|
29
|
+
export declare function useNotifications(): UseNotificationsInterface;
|
|
30
|
+
//# sourceMappingURL=use-notifications.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-notifications.d.ts","sourceRoot":"","sources":["../src/use-notifications.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAM1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAO7D,MAAM,WAAW,yBAAyB;IACtC,qBAAqB,EAAE,gBAAgB,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;IAC7D,gBAAgB,EAAE,CAAC,YAAY,EAAE,mBAAmB,KAAK,IAAI,CAAC;IAC9D,uBAAuB,EAAE,gBAAgB,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;CAClE;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,yBAAyB,CAyB5D"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import curry from 'lodash/curry';
|
|
2
|
+
import React, { useContext } from 'react';
|
|
3
|
+
import { Status } from '@darajs/ui-utils';
|
|
4
|
+
import { NotificationContext } from './notification-wrapper';
|
|
5
|
+
/**
|
|
6
|
+
* A helper hook that exposes some helpful methods for defining notifications quickly based of error messages. The error
|
|
7
|
+
* and warning functions are both curried so they can easily be dropped into error handling call backs with only the
|
|
8
|
+
* title defined
|
|
9
|
+
*/
|
|
10
|
+
export function useNotifications() {
|
|
11
|
+
const { push } = useContext(NotificationContext);
|
|
12
|
+
const curriedPush = React.useCallback((status) => curry((title, err) => {
|
|
13
|
+
const message = (err === null || err === void 0 ? void 0 : err.status) ? `${err.status}: ${err.message}` : err.message;
|
|
14
|
+
push({
|
|
15
|
+
key: title,
|
|
16
|
+
message,
|
|
17
|
+
status,
|
|
18
|
+
title: `${status.toUpperCase()}: ${title}`,
|
|
19
|
+
});
|
|
20
|
+
}), [push]);
|
|
21
|
+
const pushErrorNotification = React.useMemo(() => curriedPush(Status.ERROR), [curriedPush]);
|
|
22
|
+
const pushWarningNotification = React.useMemo(() => curriedPush(Status.WARNING), [curriedPush]);
|
|
23
|
+
return {
|
|
24
|
+
pushErrorNotification,
|
|
25
|
+
pushNotification: push,
|
|
26
|
+
pushWarningNotification,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=use-notifications.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-notifications.js","sourceRoot":"","sources":["../src/use-notifications.tsx"],"names":[],"mappings":"AAiBA,OAAO,KAAK,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
|
+
{
|
|
2
|
+
"name": "@darajs/ui-notifications",
|
|
3
|
+
"version": "0.4.8",
|
|
4
|
+
"description": "Notification system for the Dara UI Framework",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.js",
|
|
7
|
+
"jsnext:main": "dist/index.js",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "rimraf dist && tsc",
|
|
10
|
+
"lint": "eslint src --ext .tsx --max-warnings 0 && stylelint './src/**/*.tsx'",
|
|
11
|
+
"format": "prettier src --write",
|
|
12
|
+
"format:check": "prettier src --check",
|
|
13
|
+
"lint:fix": "eslint src --ext .tsx --max-warnings 0 --fix && stylelint './src/**/*.tsx' --fix",
|
|
14
|
+
"test-watch": "jest --watch",
|
|
15
|
+
"storybook": "start-storybook -p 6006",
|
|
16
|
+
"build-storybook": "build-storybook"
|
|
17
|
+
},
|
|
18
|
+
"author": "Krzysztof Bielikowicz <krzysztof@causalens.com>",
|
|
19
|
+
"license": "Apache-2.0",
|
|
20
|
+
"prettier": "@darajs/prettier-config",
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@darajs/eslint-config": "0.4.8",
|
|
23
|
+
"@darajs/prettier-config": "0.4.8",
|
|
24
|
+
"@darajs/stylelint-config": "0.4.8",
|
|
25
|
+
"@storybook/addon-a11y": "^6.5.16",
|
|
26
|
+
"@storybook/addon-actions": "^6.5.16",
|
|
27
|
+
"@storybook/addon-essentials": "^6.5.16",
|
|
28
|
+
"@storybook/addon-links": "^6.5.16",
|
|
29
|
+
"@storybook/addon-styling": "^0.3.2",
|
|
30
|
+
"@storybook/builder-webpack5": "^6.5.16",
|
|
31
|
+
"@storybook/manager-webpack5": "^6.5.16",
|
|
32
|
+
"@storybook/react": "^6.5.16",
|
|
33
|
+
"@storybook/theming": "^6.5.16",
|
|
34
|
+
"@types/jest": "^25.2.3",
|
|
35
|
+
"@types/lodash": "^4.14.155",
|
|
36
|
+
"@types/react": "^18.0",
|
|
37
|
+
"@types/styled-components": "^5.1.26",
|
|
38
|
+
"eslint": "^8.1.0",
|
|
39
|
+
"jest": "^29.5.0",
|
|
40
|
+
"prettier": "^3.0.0",
|
|
41
|
+
"react-test-renderer": "^17.0",
|
|
42
|
+
"rimraf": "^3.0.2",
|
|
43
|
+
"storybook-dark-mode": "^2.1.1",
|
|
44
|
+
"stylelint": "^15.0.0",
|
|
45
|
+
"ts-jest": "^29.1.0",
|
|
46
|
+
"typescript": "^5.0.4"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@darajs/styled-components": "0.4.8",
|
|
50
|
+
"@darajs/ui-icons": "0.4.8",
|
|
51
|
+
"@darajs/ui-utils": "0.4.8",
|
|
52
|
+
"lodash": "4.17.21",
|
|
53
|
+
"polished": "^4.1.1",
|
|
54
|
+
"react": "^18.0",
|
|
55
|
+
"rxjs": "^7.0.0"
|
|
56
|
+
},
|
|
57
|
+
"files": [
|
|
58
|
+
"dist"
|
|
59
|
+
],
|
|
60
|
+
"publishConfig": {
|
|
61
|
+
"access": "public"
|
|
62
|
+
},
|
|
63
|
+
"gitHead": "28ec9380d883a6f5f0fcd05f27beda7e412fa95f"
|
|
64
|
+
}
|