@australiangreens/ag-internal-components 0.0.17 → 0.0.19
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/cjs/index.js
CHANGED
|
@@ -1,2 +1,376 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __spreadValues = (a, b) => {
|
|
10
|
+
for (var prop in b || (b = {}))
|
|
11
|
+
if (__hasOwnProp.call(b, prop))
|
|
12
|
+
__defNormalProp(a, prop, b[prop]);
|
|
13
|
+
if (__getOwnPropSymbols)
|
|
14
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
15
|
+
if (__propIsEnum.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
}
|
|
18
|
+
return a;
|
|
19
|
+
};
|
|
20
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
21
|
+
var __objRest = (source, exclude) => {
|
|
22
|
+
var target = {};
|
|
23
|
+
for (var prop in source)
|
|
24
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
25
|
+
target[prop] = source[prop];
|
|
26
|
+
if (source != null && __getOwnPropSymbols)
|
|
27
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
28
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
29
|
+
target[prop] = source[prop];
|
|
30
|
+
}
|
|
31
|
+
return target;
|
|
32
|
+
};
|
|
33
|
+
var __publicField = (obj, key, value) => {
|
|
34
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
35
|
+
return value;
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
38
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
39
|
+
const react = require("react");
|
|
40
|
+
const Button = require("@mui/material/Button");
|
|
41
|
+
const Paper = require("@mui/material/Paper");
|
|
42
|
+
const Typography = require("@mui/material/Typography");
|
|
43
|
+
const styles = require("@mui/material/styles");
|
|
44
|
+
const Snackbar = require("@mui/material/Snackbar");
|
|
45
|
+
const Alert = require("@mui/material/Alert");
|
|
46
|
+
const LinearProgress = require("@mui/material/LinearProgress");
|
|
47
|
+
const CircularProgress = require("@mui/material/CircularProgress");
|
|
48
|
+
const agError = require("@australiangreens/ag-error");
|
|
49
|
+
function ExampleComponent({ text }) {
|
|
50
|
+
const [num, setNum] = react.useState(0);
|
|
51
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
52
|
+
/* @__PURE__ */ jsxRuntime.jsx(Typography, { variant: "h6", color: "inherit", component: "div", sx: { fontSize: "22px" }, children: "Hello world" }),
|
|
53
|
+
/* @__PURE__ */ jsxRuntime.jsx(Typography, { variant: "caption", display: "block", children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: "Just ensuring MUI is working as planned as a peer dependency. v0.0.11" }) }),
|
|
54
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
55
|
+
Button,
|
|
56
|
+
{
|
|
57
|
+
variant: "outlined",
|
|
58
|
+
onClick: () => setNum((oldNum) => oldNum + 1),
|
|
59
|
+
"aria-label": "Increment",
|
|
60
|
+
children: "Hello I am a button"
|
|
61
|
+
}
|
|
62
|
+
),
|
|
63
|
+
/* @__PURE__ */ jsxRuntime.jsxs("p", { children: [
|
|
64
|
+
"This is some text: ",
|
|
65
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: text })
|
|
66
|
+
] }),
|
|
67
|
+
/* @__PURE__ */ jsxRuntime.jsxs(Paper, { children: [
|
|
68
|
+
"This number will incremember when button pressed: ",
|
|
69
|
+
num
|
|
70
|
+
] })
|
|
71
|
+
] });
|
|
72
|
+
}
|
|
73
|
+
const internalAGSystemsTheme = styles.createTheme({
|
|
74
|
+
palette: {
|
|
75
|
+
primary: {
|
|
76
|
+
main: "#007236",
|
|
77
|
+
dark: "#005221",
|
|
78
|
+
light: "#00A04E",
|
|
79
|
+
contrastText: "#FFFFFF"
|
|
80
|
+
},
|
|
81
|
+
secondary: {
|
|
82
|
+
main: "#662D91",
|
|
83
|
+
dark: "#440E62",
|
|
84
|
+
light: "#93268F",
|
|
85
|
+
contrastText: "#FFFFFF"
|
|
86
|
+
},
|
|
87
|
+
error: {
|
|
88
|
+
main: "#D32F2F",
|
|
89
|
+
dark: "#C62828",
|
|
90
|
+
light: "#EF5350"
|
|
91
|
+
},
|
|
92
|
+
info: {
|
|
93
|
+
main: "#0288D1",
|
|
94
|
+
dark: "#01579B",
|
|
95
|
+
light: "#03A9F4"
|
|
96
|
+
},
|
|
97
|
+
success: {
|
|
98
|
+
main: "#0288D1",
|
|
99
|
+
dark: "#01579B",
|
|
100
|
+
light: "#03A9F4"
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
components: {
|
|
104
|
+
MuiTextField: {
|
|
105
|
+
defaultProps: { color: "secondary" }
|
|
106
|
+
},
|
|
107
|
+
MuiToggleButtonGroup: {
|
|
108
|
+
defaultProps: { color: "secondary" }
|
|
109
|
+
},
|
|
110
|
+
MuiCheckbox: {
|
|
111
|
+
defaultProps: { color: "secondary" }
|
|
112
|
+
},
|
|
113
|
+
MuiSelect: {
|
|
114
|
+
defaultProps: { color: "secondary" }
|
|
115
|
+
},
|
|
116
|
+
MuiSwitch: {
|
|
117
|
+
defaultProps: { color: "secondary" }
|
|
118
|
+
},
|
|
119
|
+
MuiFormControl: {
|
|
120
|
+
defaultProps: { color: "secondary" }
|
|
121
|
+
},
|
|
122
|
+
MuiMenuItem: {
|
|
123
|
+
// Setting defaultProps for color on MenuItem does not work, so update manually
|
|
124
|
+
styleOverrides: {
|
|
125
|
+
root: ({ theme }) => ({
|
|
126
|
+
"&.Mui-selected": {
|
|
127
|
+
backgroundColor: styles.alpha(
|
|
128
|
+
theme.palette.secondary.main,
|
|
129
|
+
theme.palette.action.selectedOpacity
|
|
130
|
+
),
|
|
131
|
+
"&:hover": {
|
|
132
|
+
backgroundColor: styles.alpha(
|
|
133
|
+
theme.palette.secondary.main,
|
|
134
|
+
theme.palette.action.selectedOpacity
|
|
135
|
+
)
|
|
136
|
+
},
|
|
137
|
+
"&.Mui-focusVisible": {
|
|
138
|
+
backgroundColor: styles.alpha(
|
|
139
|
+
theme.palette.secondary.main,
|
|
140
|
+
theme.palette.action.focusOpacity
|
|
141
|
+
)
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
})
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
typography: {
|
|
149
|
+
// I couldn't think of what to call this. It is an attempt to match
|
|
150
|
+
// https://www.figma.com/file/atonRPl2YD9A1NCntbDtKR/List-Filter-and-Product-Concept?node-id=1187%3A43730
|
|
151
|
+
// but not sure if line height should be changed
|
|
152
|
+
explainer: {
|
|
153
|
+
fontSize: "14px",
|
|
154
|
+
marginBlockStart: "1em"
|
|
155
|
+
},
|
|
156
|
+
h3: {
|
|
157
|
+
fontSize: "1rem",
|
|
158
|
+
fontWeight: 700
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
const fed21Theme = styles.createTheme({
|
|
163
|
+
palette: {
|
|
164
|
+
primary: {
|
|
165
|
+
dark: "#00A651",
|
|
166
|
+
light: "#A3D39C",
|
|
167
|
+
main: "#007236",
|
|
168
|
+
contrastText: "#FFF"
|
|
169
|
+
},
|
|
170
|
+
warning: {
|
|
171
|
+
main: "#F5871F",
|
|
172
|
+
light: "#FCC589",
|
|
173
|
+
dark: "#A2590A",
|
|
174
|
+
contrastText: "#FFF"
|
|
175
|
+
},
|
|
176
|
+
secondary: {
|
|
177
|
+
main: "#662D91",
|
|
178
|
+
light: "#BD8CBF",
|
|
179
|
+
dark: "#440E62",
|
|
180
|
+
contrastText: "#FFF"
|
|
181
|
+
},
|
|
182
|
+
error: {
|
|
183
|
+
main: "#D43C95",
|
|
184
|
+
light: "#8F2064",
|
|
185
|
+
dark: "#F9CDE0",
|
|
186
|
+
contrastText: "#FFF"
|
|
187
|
+
},
|
|
188
|
+
info: {
|
|
189
|
+
main: "#00A88D",
|
|
190
|
+
light: "#ADDCCF",
|
|
191
|
+
dark: "#005243",
|
|
192
|
+
contrastText: "#FFF"
|
|
193
|
+
},
|
|
194
|
+
success: {
|
|
195
|
+
main: "#00A651",
|
|
196
|
+
light: "#A3D39C",
|
|
197
|
+
dark: "#007236",
|
|
198
|
+
contrastText: "#FFF"
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
typography: {
|
|
202
|
+
// I couldn't think of what to call this. It is an attempt to match
|
|
203
|
+
// https://www.figma.com/file/atonRPl2YD9A1NCntbDtKR/List-Filter-and-Product-Concept?node-id=1187%3A43730
|
|
204
|
+
// but not sure if line height should be changed
|
|
205
|
+
explainer: {
|
|
206
|
+
fontSize: "14px",
|
|
207
|
+
marginBlockStart: "1em"
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
function AgThemeProvider({
|
|
212
|
+
name = "internal",
|
|
213
|
+
children
|
|
214
|
+
}) {
|
|
215
|
+
const theme = name === "internal" ? internalAGSystemsTheme : name === "fed21" ? fed21Theme : void 0;
|
|
216
|
+
return /* @__PURE__ */ jsxRuntime.jsx(styles.ThemeProvider, { theme, children });
|
|
217
|
+
}
|
|
218
|
+
class ContextError extends agError.AgError {
|
|
219
|
+
}
|
|
220
|
+
__publicField(ContextError, "errorName", "ContextError");
|
|
221
|
+
const stub = () => {
|
|
222
|
+
throw new ContextError("SaladBarContext can only be used in a child of a <SaladBarProvider>");
|
|
223
|
+
};
|
|
224
|
+
const notstub = (key) => {
|
|
225
|
+
throw new ContextError("SaladBarContext can only be used in a child of a <SaladBarProvider>");
|
|
226
|
+
};
|
|
227
|
+
const defaultValue = {
|
|
228
|
+
enqueueNotification: stub,
|
|
229
|
+
enqueueSuccessNotification: stub,
|
|
230
|
+
enqueueInfoNotification: stub,
|
|
231
|
+
enqueueWarningNotification: stub,
|
|
232
|
+
enqueueErrorNotification: stub,
|
|
233
|
+
removeNotification: notstub
|
|
234
|
+
};
|
|
235
|
+
const SaladBarContext = react.createContext(defaultValue);
|
|
236
|
+
const defaultSnackbarProps = {
|
|
237
|
+
autoHideDuration: 6e3,
|
|
238
|
+
anchorOrigin: { vertical: "top", horizontal: "center" },
|
|
239
|
+
// The default is false. If we prefer timer to continue when window loses
|
|
240
|
+
// focus, change to true
|
|
241
|
+
disableWindowBlurListener: false
|
|
242
|
+
};
|
|
243
|
+
const defaultEnqueueNotificationOptions = {
|
|
244
|
+
message: "",
|
|
245
|
+
severity: "info",
|
|
246
|
+
variant: "standard",
|
|
247
|
+
progressIndicator: void 0
|
|
248
|
+
// Can use 'circular' or 'linear'
|
|
249
|
+
};
|
|
250
|
+
const MAX_QUEUE_LENGTH = 100;
|
|
251
|
+
const MAX_QUEUE_HIT_REPORT_INTERVAL = 2e3;
|
|
252
|
+
const SALADBAR_INDEX = 2e3;
|
|
253
|
+
const generateNotificationKey = (() => {
|
|
254
|
+
let previousKey = 0;
|
|
255
|
+
return () => {
|
|
256
|
+
previousKey += 1;
|
|
257
|
+
return previousKey;
|
|
258
|
+
};
|
|
259
|
+
})();
|
|
260
|
+
const alertWithLinearProgressStyle = {
|
|
261
|
+
borderBottomLeftRadius: "0px",
|
|
262
|
+
borderBottomRightRadius: "0px"
|
|
263
|
+
};
|
|
264
|
+
function SaladBarProvider(_a) {
|
|
265
|
+
var _b = _a, { children } = _b, snackbarProps = __objRest(_b, ["children"]);
|
|
266
|
+
var _a2;
|
|
267
|
+
const [open, setOpen] = react.useState(false);
|
|
268
|
+
const queueRef = react.useRef([]);
|
|
269
|
+
const limitLastHitAt = react.useRef(Date.now());
|
|
270
|
+
const limitHitCountSinceLastReport = react.useRef(0);
|
|
271
|
+
const enqueueNotification = (notification = {}) => {
|
|
272
|
+
limitHitCountSinceLastReport.current += 1;
|
|
273
|
+
if (queueRef.current.length >= MAX_QUEUE_LENGTH) {
|
|
274
|
+
if (Date.now() - limitLastHitAt.current >= MAX_QUEUE_HIT_REPORT_INTERVAL) {
|
|
275
|
+
limitLastHitAt.current = Date.now();
|
|
276
|
+
console.error(
|
|
277
|
+
`SaladBarProvider: MAX_QUEUE_LENGTH (${MAX_QUEUE_LENGTH}) hit ${limitHitCountSinceLastReport.current} times in last ${MAX_QUEUE_HIT_REPORT_INTERVAL}ms)`
|
|
278
|
+
);
|
|
279
|
+
limitHitCountSinceLastReport.current = 0;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
const newNotification = __spreadValues(__spreadProps(__spreadValues({}, defaultEnqueueNotificationOptions), {
|
|
283
|
+
key: generateNotificationKey()
|
|
284
|
+
}), notification);
|
|
285
|
+
queueRef.current.push(newNotification);
|
|
286
|
+
if (queueRef.current.length === 1)
|
|
287
|
+
setOpen(true);
|
|
288
|
+
return newNotification.key;
|
|
289
|
+
};
|
|
290
|
+
const enqueueSuccessNotification = (message = "", options = {}) => enqueueNotification(__spreadValues({ message, severity: "success" }, options));
|
|
291
|
+
const enqueueInfoNotification = (message = "", options = {}) => enqueueNotification(__spreadValues({ message, severity: "info" }, options));
|
|
292
|
+
const enqueueWarningNotification = (message = "", options = {}) => enqueueNotification(__spreadValues({ message, severity: "warning" }, options));
|
|
293
|
+
const enqueueErrorNotification = (message = "", options = {}) => enqueueNotification(__spreadValues({ message, severity: "error" }, options));
|
|
294
|
+
const removeNotification = (key) => {
|
|
295
|
+
const index = queueRef.current.findIndex((x) => x.key === key);
|
|
296
|
+
if (index === -1)
|
|
297
|
+
return;
|
|
298
|
+
if (index === 0) {
|
|
299
|
+
setOpen(false);
|
|
300
|
+
return queueRef.current[0];
|
|
301
|
+
}
|
|
302
|
+
return queueRef.current.splice(index, 1);
|
|
303
|
+
};
|
|
304
|
+
const handleClose = (_event) => {
|
|
305
|
+
setOpen(false);
|
|
306
|
+
};
|
|
307
|
+
const handleExit = () => {
|
|
308
|
+
};
|
|
309
|
+
const handleExited = () => {
|
|
310
|
+
queueRef.current.shift();
|
|
311
|
+
if (queueRef.current.length > 0)
|
|
312
|
+
setOpen(true);
|
|
313
|
+
};
|
|
314
|
+
const currentNotification = (_a2 = queueRef.current[0]) != null ? _a2 : __spreadValues({}, defaultEnqueueNotificationOptions);
|
|
315
|
+
const currentNotificationSnackbarProps = {};
|
|
316
|
+
if ("autoHideDuration" in currentNotification) {
|
|
317
|
+
currentNotificationSnackbarProps.autoHideDuration = currentNotification.autoHideDuration;
|
|
318
|
+
}
|
|
319
|
+
const snackbarFinalProps = __spreadValues(__spreadValues({}, defaultSnackbarProps), snackbarProps);
|
|
320
|
+
return (
|
|
321
|
+
// Should be resolved when we move to React >= 18
|
|
322
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
323
|
+
// @ts-ignore
|
|
324
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
325
|
+
SaladBarContext.Provider,
|
|
326
|
+
{
|
|
327
|
+
value: {
|
|
328
|
+
enqueueNotification,
|
|
329
|
+
enqueueSuccessNotification,
|
|
330
|
+
enqueueInfoNotification,
|
|
331
|
+
enqueueWarningNotification,
|
|
332
|
+
enqueueErrorNotification,
|
|
333
|
+
removeNotification
|
|
334
|
+
},
|
|
335
|
+
children: [
|
|
336
|
+
children,
|
|
337
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
338
|
+
Snackbar,
|
|
339
|
+
__spreadProps(__spreadValues(__spreadValues({}, snackbarFinalProps), currentNotificationSnackbarProps), {
|
|
340
|
+
open,
|
|
341
|
+
onClose: handleClose,
|
|
342
|
+
TransitionProps: {
|
|
343
|
+
onExited: handleExited,
|
|
344
|
+
onExit: handleExit
|
|
345
|
+
},
|
|
346
|
+
sx: { zIndex: SALADBAR_INDEX },
|
|
347
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
348
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
349
|
+
Alert,
|
|
350
|
+
{
|
|
351
|
+
onClose: handleClose,
|
|
352
|
+
severity: currentNotification.severity,
|
|
353
|
+
variant: "filled",
|
|
354
|
+
icon: currentNotification.progressIndicator === "circular" ? /* @__PURE__ */ jsxRuntime.jsx(CircularProgress, { size: "1em" }) : void 0,
|
|
355
|
+
style: currentNotification.progressIndicator === "linear" ? alertWithLinearProgressStyle : void 0,
|
|
356
|
+
children: currentNotification.message
|
|
357
|
+
}
|
|
358
|
+
),
|
|
359
|
+
currentNotification.progressIndicator === "linear" && /* @__PURE__ */ jsxRuntime.jsx(LinearProgress, { color: "primary" })
|
|
360
|
+
] })
|
|
361
|
+
})
|
|
362
|
+
)
|
|
363
|
+
]
|
|
364
|
+
}
|
|
365
|
+
)
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
function useSaladBar() {
|
|
369
|
+
return react.useContext(SaladBarContext);
|
|
370
|
+
}
|
|
371
|
+
exports.AgThemeProvider = AgThemeProvider;
|
|
372
|
+
exports.ContextError = ContextError;
|
|
373
|
+
exports.ExampleComponent = ExampleComponent;
|
|
374
|
+
exports.SaladBarProvider = SaladBarProvider;
|
|
375
|
+
exports.useSaladBar = useSaladBar;
|
|
2
376
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/components/ExampleComponent/index.tsx","../../src/providers/AgTheme/themes.ts","../../src/providers/AgTheme/index.tsx","../../src/errors/ContextError.ts","../../src/providers/SaladBar/SaladBarContext.ts","../../src/providers/SaladBar/defaults.ts","../../src/providers/SaladBar/SaladBarProvider.tsx","../../src/providers/SaladBar/useSaladBar.ts"],"sourcesContent":["import { useState } from 'react';\nimport Button from '@mui/material/Button';\nimport Paper from '@mui/material/Paper';\nimport Typography from '@mui/material/Typography';\n\nexport interface ExampleComponentProps {\n text: string;\n}\n\nexport default function ExampleComponent({ text }: ExampleComponentProps) {\n const [num, setNum] = useState(0);\n\n return (\n <>\n <Typography variant=\"h6\" color=\"inherit\" component=\"div\" sx={{ fontSize: '22px' }}>\n Hello world\n </Typography>\n\n <Typography variant=\"caption\" display=\"block\">\n <span>Just ensuring MUI is working as planned as a peer dependency. v0.0.11</span>\n </Typography>\n <Button\n variant=\"outlined\"\n onClick={() => setNum((oldNum) => oldNum + 1)}\n aria-label=\"Increment\"\n >\n Hello I am a button\n </Button>\n <p>\n This is some text: <span>{text}</span>\n </p>\n <Paper>This number will incremember when button pressed: {num}</Paper>\n </>\n );\n}\n","import { alpha, createTheme } from '@mui/material/styles';\n\nexport const internalAGSystemsTheme = createTheme({\n palette: {\n primary: {\n main: '#007236',\n dark: '#005221',\n light: '#00A04E',\n contrastText: '#FFFFFF',\n },\n secondary: {\n main: '#662D91',\n dark: '#440E62',\n light: '#93268F',\n contrastText: '#FFFFFF',\n },\n error: {\n main: '#D32F2F',\n dark: '#C62828',\n light: '#EF5350',\n },\n info: {\n main: '#0288D1',\n dark: '#01579B',\n light: '#03A9F4',\n },\n success: {\n main: '#0288D1',\n dark: '#01579B',\n light: '#03A9F4',\n },\n },\n components: {\n MuiTextField: {\n defaultProps: { color: 'secondary' },\n },\n MuiToggleButtonGroup: {\n defaultProps: { color: 'secondary' },\n },\n MuiCheckbox: {\n defaultProps: { color: 'secondary' },\n },\n MuiSelect: {\n defaultProps: { color: 'secondary' },\n },\n MuiSwitch: {\n defaultProps: { color: 'secondary' },\n },\n MuiFormControl: {\n defaultProps: { color: 'secondary' },\n },\n MuiMenuItem: {\n // Setting defaultProps for color on MenuItem does not work, so update manually\n styleOverrides: {\n root: ({ theme }) => ({\n '&.Mui-selected': {\n backgroundColor: alpha(\n theme.palette.secondary.main,\n theme.palette.action.selectedOpacity\n ),\n '&:hover': {\n backgroundColor: alpha(\n theme.palette.secondary.main,\n theme.palette.action.selectedOpacity\n ),\n },\n '&.Mui-focusVisible': {\n backgroundColor: alpha(\n theme.palette.secondary.main,\n theme.palette.action.focusOpacity\n ),\n },\n },\n }),\n },\n },\n },\n typography: {\n // I couldn't think of what to call this. It is an attempt to match\n // https://www.figma.com/file/atonRPl2YD9A1NCntbDtKR/List-Filter-and-Product-Concept?node-id=1187%3A43730\n // but not sure if line height should be changed\n explainer: {\n fontSize: '14px',\n marginBlockStart: '1em',\n },\n h3: {\n fontSize: '1rem',\n fontWeight: 700,\n },\n },\n});\n\nexport const fed21Theme = createTheme({\n palette: {\n primary: {\n dark: '#00A651',\n light: '#A3D39C',\n main: '#007236',\n contrastText: '#FFF',\n },\n warning: {\n main: '#F5871F',\n light: '#FCC589',\n dark: '#A2590A',\n contrastText: '#FFF',\n },\n secondary: {\n main: '#662D91',\n light: '#BD8CBF',\n dark: '#440E62',\n contrastText: '#FFF',\n },\n error: {\n main: '#D43C95',\n light: '#8F2064',\n dark: '#F9CDE0',\n contrastText: '#FFF',\n },\n info: {\n main: '#00A88D',\n light: '#ADDCCF',\n dark: '#005243',\n contrastText: '#FFF',\n },\n success: {\n main: '#00A651',\n light: '#A3D39C',\n dark: '#007236',\n contrastText: '#FFF',\n },\n },\n typography: {\n // I couldn't think of what to call this. It is an attempt to match\n // https://www.figma.com/file/atonRPl2YD9A1NCntbDtKR/List-Filter-and-Product-Concept?node-id=1187%3A43730\n // but not sure if line height should be changed\n explainer: {\n fontSize: '14px',\n marginBlockStart: '1em',\n },\n },\n});\n","import { PropsWithChildren } from 'react';\nimport { ThemeProvider } from '@mui/material/styles';\n\nimport { internalAGSystemsTheme, fed21Theme } from './themes';\n\nexport type AgThemeName = 'internal' | 'fed21';\n\nexport interface AgThemeProviderProps {\n name?: AgThemeName;\n}\n\nexport default function AgThemeProvider({\n name = 'internal',\n children,\n}: PropsWithChildren<AgThemeProviderProps>) {\n const theme =\n name === 'internal' ? internalAGSystemsTheme : name === 'fed21' ? fed21Theme : undefined;\n\n // Should be resolved when we move to React >= 18\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n return <ThemeProvider theme={theme}>{children}</ThemeProvider>;\n}\n","import { AgError } from '@australiangreens/ag-error';\n\n// Superclass for errors involving React context.\nexport class ContextError extends AgError {\n static errorName = 'ContextError';\n}\n","import { createContext } from 'react';\n\nimport { ContextError } from '../../errors/ContextError';\n\nconst stub: () => void = () => {\n throw new ContextError('SaladBarContext can only be used in a child of a <SaladBarProvider>');\n};\n\nexport type NotificationType = {\n key: number;\n message: string;\n severity: 'success' | 'info' | 'warning' | 'error' | undefined;\n variant: 'standard' | 'outlined' | 'filled' | undefined;\n progressIndicator: string | undefined;\n autoHideDuration: number | undefined;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nconst notstub = (key: unknown): NotificationType | NotificationType[] | void => {\n throw new ContextError('SaladBarContext can only be used in a child of a <SaladBarProvider>');\n};\n\ntype SaladBarContextFunction = typeof stub | typeof notstub;\n\ntype SaladBarContextType = {\n enqueueNotification: SaladBarContextFunction; // Call as enqueueNotification(options)\n // where options include message and severity of 'error' ,'warning', 'info' or\n // 'success'\n enqueueSuccessNotification: SaladBarContextFunction; // Call as const key =\n // enqueueSuccessNotification(msg),\n enqueueInfoNotification: SaladBarContextFunction; // Call as const key =\n // enqueueInfoNotification(msg),\n enqueueWarningNotification: SaladBarContextFunction; // Call as const key =\n // enqueueWarningNotification(msg),\n enqueueErrorNotification: SaladBarContextFunction; // Call as const key =\n // enqueueErrorNotification(msg),\n removeNotification: SaladBarContextFunction; // Call as enqueueErrorNotification(key),\n};\n\n// The defaultValue argument is only used when a component does not have a\n// matching Provider above it in the tree. See\n// https://reactjs.org/docs/context.html#reactcreatecontext\n// Using createContext doesn't itself maintain any type of state exactly, it\n// just provides a way for children to access shared references.\nconst defaultValue = {\n enqueueNotification: stub,\n enqueueSuccessNotification: stub,\n enqueueInfoNotification: stub,\n enqueueWarningNotification: stub,\n enqueueErrorNotification: stub,\n removeNotification: notstub,\n} as SaladBarContextType;\n\n/**\n * @returns A SaladBarContext\n */\nconst SaladBarContext = createContext(defaultValue);\n\nexport default SaladBarContext;\n","// The default props passed to the underlying Snackbar component\nimport { SnackbarOrigin } from '@mui/material/Snackbar';\n\nexport const defaultSnackbarProps = {\n autoHideDuration: 6000,\n anchorOrigin: { vertical: 'top', horizontal: 'center' } as SnackbarOrigin,\n\n // The default is false. If we prefer timer to continue when window loses\n // focus, change to true\n disableWindowBlurListener: false,\n};\n\nexport const defaultEnqueueNotificationOptions = {\n message: '',\n severity: 'info',\n variant: 'standard',\n progressIndicator: undefined, // Can use 'circular' or 'linear'\n};\n","import React, { useRef, useState } from 'react';\nimport Snackbar from '@mui/material/Snackbar';\nimport Alert from '@mui/material/Alert';\nimport LinearProgress from '@mui/material/LinearProgress';\nimport CircularProgress from '@mui/material/CircularProgress';\n\nimport SaladBarContext, { NotificationType } from './SaladBarContext';\nimport { defaultSnackbarProps, defaultEnqueueNotificationOptions } from './defaults';\n\nconst MAX_QUEUE_LENGTH = 100;\nconst MAX_QUEUE_HIT_REPORT_INTERVAL = 2000;\nconst SALADBAR_INDEX = 2000;\n\n// No need to use uuids, just use an incremented value\nconst generateNotificationKey = (() => {\n let previousKey = 0;\n return () => {\n previousKey += 1;\n return previousKey;\n };\n})();\n\nconst alertWithLinearProgressStyle = {\n borderBottomLeftRadius: '0px',\n borderBottomRightRadius: '0px',\n};\n\ntype SaladBarProps = {\n children: React.ReactNode;\n};\n\nconst SaladBar = ({ children, ...snackbarProps }: SaladBarProps) => {\n const [open, setOpen] = useState(false);\n\n // We use a ref instead of a state to store the actual data, because we want\n // queue to be persistent across the whole lifetime of component. I considered\n // using yocto-queue because it would be O(1) instead of O(n), but its not\n // designed to access the head without removing it and its not going to make\n // much difference anyway.\n const queueRef = useRef<NotificationType[]>([]);\n\n const limitLastHitAt = useRef(Date.now());\n const limitHitCountSinceLastReport = useRef(0);\n\n const enqueueNotification = (notification = {}) => {\n limitHitCountSinceLastReport.current += 1;\n if (queueRef.current.length >= MAX_QUEUE_LENGTH) {\n // If the queue length is hit, probably stuck in some sort of loop, so\n // don't want to spam logs instantly so space it out\n if (Date.now() - limitLastHitAt.current >= MAX_QUEUE_HIT_REPORT_INTERVAL) {\n limitLastHitAt.current = Date.now();\n console.error(\n `SaladBarProvider: MAX_QUEUE_LENGTH (${MAX_QUEUE_LENGTH}) hit ${limitHitCountSinceLastReport.current} times in last ${MAX_QUEUE_HIT_REPORT_INTERVAL}ms)`\n );\n limitHitCountSinceLastReport.current = 0;\n }\n }\n\n const newNotification = {\n ...defaultEnqueueNotificationOptions,\n key: generateNotificationKey(), // Can be overridden.\n ...notification, // This could result in collisons, but unlikely.\n };\n\n // Add to the end of queue\n queueRef.current.push(newNotification as NotificationType);\n\n // If the queue was previously empty, then open the snackbar. We don't do it\n // whenever enqueueNotification is called since it will mess up transitions\n if (queueRef.current.length === 1) setOpen(true);\n\n return newNotification.key;\n };\n\n const enqueueSuccessNotification = (message = '', options = {}) =>\n enqueueNotification({ message, severity: 'success', ...options });\n\n const enqueueInfoNotification = (message = '', options = {}) =>\n enqueueNotification({ message, severity: 'info', ...options });\n\n const enqueueWarningNotification = (message = '', options = {}) =>\n enqueueNotification({ message, severity: 'warning', ...options });\n\n const enqueueErrorNotification = (message = '', options = {}) =>\n enqueueNotification({ message, severity: 'error', ...options });\n\n /**\n * Remove the notification with specified key from the queue. If the key is\n * not found, immediately returns null.\n *\n * @param key - The key as returned from enqueue...() function.\n *\n * @returns The removed notification\n */\n const removeNotification = (key: unknown) => {\n const index = queueRef.current.findIndex((x) => x.key === key);\n if (index === -1) return;\n\n if (index === 0) {\n // If its at the front of the queue, it is either currently being\n // displayed or in process of being closed. Either way, we can just set\n // open to false\n setOpen(false);\n return queueRef.current[0];\n }\n // Otherwise we just remove it from the queue, it won't need to transition\n return queueRef.current.splice(index, 1);\n };\n\n // Callback fired when the component requests to be closed\n // const handleClose = (_event, reason) => {\n // // We ignore click away, letting user continue with UI while its still\n // // displayed\n // if (reason === 'clickaway') return;\n\n // setOpen(false);\n // };\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const handleClose = (_event: Event | React.SyntheticEvent<Element, Event>) => {\n // We ignore click away, letting user continue with UI while its still\n // displayed\n\n setOpen(false);\n };\n\n // Callback fired before the transition is exiting.\n const handleExit = () => {};\n\n // Callback fired when the transition has exited.\n const handleExited = () => {\n // Remove head of queue\n queueRef.current.shift();\n\n // If there is still something on the queue, then re-open\n if (queueRef.current.length > 0) setOpen(true);\n };\n\n // The notification to display is the one at head of queue\n const currentNotification = queueRef.current[0] ?? {\n ...defaultEnqueueNotificationOptions,\n };\n\n // Can also override certain props on a notification level\n const currentNotificationSnackbarProps: { autoHideDuration?: number } = {};\n // Probably a better way of doing this\n if ('autoHideDuration' in currentNotification) {\n currentNotificationSnackbarProps.autoHideDuration = currentNotification.autoHideDuration;\n }\n\n // Note the order of props in Snackbar, we don't allow overriding open and\n // onClose.\n\n const snackbarFinalProps = { ...defaultSnackbarProps, ...snackbarProps };\n\n return (\n // Should be resolved when we move to React >= 18\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n <SaladBarContext.Provider\n value={{\n enqueueNotification,\n enqueueSuccessNotification,\n enqueueInfoNotification,\n enqueueWarningNotification,\n enqueueErrorNotification,\n removeNotification,\n }}\n >\n {children}\n <Snackbar\n {...snackbarFinalProps}\n {...currentNotificationSnackbarProps}\n open={open}\n onClose={handleClose}\n TransitionProps={{\n onExited: handleExited,\n onExit: handleExit,\n }}\n sx={{ zIndex: SALADBAR_INDEX }}\n >\n <div>\n <Alert\n onClose={handleClose}\n severity={currentNotification.severity}\n variant={'filled'}\n icon={\n currentNotification.progressIndicator === 'circular' ? (\n <CircularProgress size=\"1em\" />\n ) : undefined\n }\n style={\n currentNotification.progressIndicator === 'linear'\n ? alertWithLinearProgressStyle\n : undefined\n }\n >\n {currentNotification.message}\n </Alert>\n {currentNotification.progressIndicator === 'linear' && <LinearProgress color=\"primary\" />}\n </div>\n </Snackbar>\n </SaladBarContext.Provider>\n );\n};\n\nexport default SaladBar;\n","import { useContext } from 'react';\nimport SaladBarContext from './SaladBarContext';\n\n/**\n * Use the `useSaladBar` hook in components to access the enqueueNotification()\n * method to add a snackbar message to queue.\n *\n * Example:\n *\n * ```js\n * const {\n * enqueueNotification,\n * enqueueSuccessNotification,\n * enqueueInfoNotification,\n * enqueueWarningNotification,\n * enqueueErrorNotification,\n * } = useSaladBar();\n * ...\n * enqueueNotification({message: 'hello', severity: 'info'});\n * // or\n * enqueueInfoNotification('hello');\n * ```\n */\nexport default function useSaladBar() {\n return useContext(SaladBarContext);\n}\n"],"names":["ExampleComponent","text","num","setNum","useState","jsxs","Fragment","jsx","Typography","Button","oldNum","Paper","internalAGSystemsTheme","createTheme","theme","alpha","fed21Theme","AgThemeProvider","name","children","ThemeProvider","ContextError","AgError","__publicField","stub","notstub","key","defaultValue","SaladBarContext","createContext","defaultSnackbarProps","defaultEnqueueNotificationOptions","MAX_QUEUE_LENGTH","MAX_QUEUE_HIT_REPORT_INTERVAL","SALADBAR_INDEX","generateNotificationKey","previousKey","alertWithLinearProgressStyle","SaladBar","_a","_b","snackbarProps","__objRest","open","setOpen","queueRef","useRef","limitLastHitAt","limitHitCountSinceLastReport","enqueueNotification","notification","newNotification","__spreadValues","__spreadProps","enqueueSuccessNotification","message","options","enqueueInfoNotification","enqueueWarningNotification","enqueueErrorNotification","removeNotification","index","x","handleClose","_event","handleExit","handleExited","currentNotification","currentNotificationSnackbarProps","snackbarFinalProps","Snackbar","Alert","CircularProgress","LinearProgress","useSaladBar","useContext"],"mappings":"ylCASwB,SAAAA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AAAC,EACA,mBAAAC,CACF,EAEC,SAAA,CAAAzC,EACDZ,EAAA,IAAC+D,EAAAjB,EAAAD,IAAA,GACKiB,GACAD,GAFL,CAGC,KAAAzB,EACA,QAASoB,EACT,gBAAiB,CACf,SAAUG,EACV,OAAQD,CACV,EACA,GAAI,CAAE,OAAQ/B,EAAe,EAE7B,gBAAC,MACC,CAAA,SAAA,CAAA3B,EAAA,IAACgE,EAAA,CACC,QAASR,EACT,SAAUI,EAAoB,SAC9B,QAAS,SACT,KACEA,EAAoB,oBAAsB,iBACvCK,EAAiB,CAAA,KAAK,MAAM,EAC3B,OAEN,MACEL,EAAoB,oBAAsB,SACtC9B,GACA,OAGL,SAAoB8B,EAAA,OAAA,CACvB,EACCA,EAAoB,oBAAsB,UAAa5D,EAAAA,IAAAkE,EAAA,CAAe,MAAM,UAAU,CAAA,EACzF,CAAA,EACF,CAAA,CAAA,CACF,CAEJ,ECrLA,SAAwBC,IAAc,CACpC,OAAOC,EAAAA,WAAW/C,CAAe,CACnC"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/components/ExampleComponent/index.tsx","../../src/providers/AgTheme/themes.ts","../../src/providers/AgTheme/index.tsx","../../src/errors/ContextError.ts","../../src/providers/SaladBar/SaladBarContext.ts","../../src/providers/SaladBar/defaults.ts","../../src/providers/SaladBar/SaladBarProvider.tsx","../../src/providers/SaladBar/useSaladBar.ts"],"sourcesContent":["import { useState } from 'react';\nimport Button from '@mui/material/Button';\nimport Paper from '@mui/material/Paper';\nimport Typography from '@mui/material/Typography';\n\nexport interface ExampleComponentProps {\n text: string;\n}\n\nexport default function ExampleComponent({ text }: ExampleComponentProps) {\n const [num, setNum] = useState(0);\n\n return (\n <>\n <Typography variant=\"h6\" color=\"inherit\" component=\"div\" sx={{ fontSize: '22px' }}>\n Hello world\n </Typography>\n\n <Typography variant=\"caption\" display=\"block\">\n <span>Just ensuring MUI is working as planned as a peer dependency. v0.0.11</span>\n </Typography>\n <Button\n variant=\"outlined\"\n onClick={() => setNum((oldNum) => oldNum + 1)}\n aria-label=\"Increment\"\n >\n Hello I am a button\n </Button>\n <p>\n This is some text: <span>{text}</span>\n </p>\n <Paper>This number will incremember when button pressed: {num}</Paper>\n </>\n );\n}\n","import { alpha, createTheme } from '@mui/material/styles';\n\nexport const internalAGSystemsTheme = createTheme({\n palette: {\n primary: {\n main: '#007236',\n dark: '#005221',\n light: '#00A04E',\n contrastText: '#FFFFFF',\n },\n secondary: {\n main: '#662D91',\n dark: '#440E62',\n light: '#93268F',\n contrastText: '#FFFFFF',\n },\n error: {\n main: '#D32F2F',\n dark: '#C62828',\n light: '#EF5350',\n },\n info: {\n main: '#0288D1',\n dark: '#01579B',\n light: '#03A9F4',\n },\n success: {\n main: '#0288D1',\n dark: '#01579B',\n light: '#03A9F4',\n },\n },\n components: {\n MuiTextField: {\n defaultProps: { color: 'secondary' },\n },\n MuiToggleButtonGroup: {\n defaultProps: { color: 'secondary' },\n },\n MuiCheckbox: {\n defaultProps: { color: 'secondary' },\n },\n MuiSelect: {\n defaultProps: { color: 'secondary' },\n },\n MuiSwitch: {\n defaultProps: { color: 'secondary' },\n },\n MuiFormControl: {\n defaultProps: { color: 'secondary' },\n },\n MuiMenuItem: {\n // Setting defaultProps for color on MenuItem does not work, so update manually\n styleOverrides: {\n root: ({ theme }) => ({\n '&.Mui-selected': {\n backgroundColor: alpha(\n theme.palette.secondary.main,\n theme.palette.action.selectedOpacity\n ),\n '&:hover': {\n backgroundColor: alpha(\n theme.palette.secondary.main,\n theme.palette.action.selectedOpacity\n ),\n },\n '&.Mui-focusVisible': {\n backgroundColor: alpha(\n theme.palette.secondary.main,\n theme.palette.action.focusOpacity\n ),\n },\n },\n }),\n },\n },\n },\n typography: {\n // I couldn't think of what to call this. It is an attempt to match\n // https://www.figma.com/file/atonRPl2YD9A1NCntbDtKR/List-Filter-and-Product-Concept?node-id=1187%3A43730\n // but not sure if line height should be changed\n explainer: {\n fontSize: '14px',\n marginBlockStart: '1em',\n },\n h3: {\n fontSize: '1rem',\n fontWeight: 700,\n },\n },\n});\n\nexport const fed21Theme = createTheme({\n palette: {\n primary: {\n dark: '#00A651',\n light: '#A3D39C',\n main: '#007236',\n contrastText: '#FFF',\n },\n warning: {\n main: '#F5871F',\n light: '#FCC589',\n dark: '#A2590A',\n contrastText: '#FFF',\n },\n secondary: {\n main: '#662D91',\n light: '#BD8CBF',\n dark: '#440E62',\n contrastText: '#FFF',\n },\n error: {\n main: '#D43C95',\n light: '#8F2064',\n dark: '#F9CDE0',\n contrastText: '#FFF',\n },\n info: {\n main: '#00A88D',\n light: '#ADDCCF',\n dark: '#005243',\n contrastText: '#FFF',\n },\n success: {\n main: '#00A651',\n light: '#A3D39C',\n dark: '#007236',\n contrastText: '#FFF',\n },\n },\n typography: {\n // I couldn't think of what to call this. It is an attempt to match\n // https://www.figma.com/file/atonRPl2YD9A1NCntbDtKR/List-Filter-and-Product-Concept?node-id=1187%3A43730\n // but not sure if line height should be changed\n explainer: {\n fontSize: '14px',\n marginBlockStart: '1em',\n },\n },\n});\n","import { PropsWithChildren } from 'react';\nimport { ThemeProvider } from '@mui/material/styles';\n\nimport { internalAGSystemsTheme, fed21Theme } from './themes';\n\nexport type AgThemeName = 'internal' | 'fed21';\n\nexport interface AgThemeProviderProps {\n name?: AgThemeName;\n}\n\nexport default function AgThemeProvider({\n name = 'internal',\n children,\n}: PropsWithChildren<AgThemeProviderProps>) {\n const theme =\n name === 'internal' ? internalAGSystemsTheme : name === 'fed21' ? fed21Theme : undefined;\n\n // Should be resolved when we move to React >= 18\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n return <ThemeProvider theme={theme}>{children}</ThemeProvider>;\n}\n","import { AgError } from '@australiangreens/ag-error';\n\n// Superclass for errors involving React context.\nexport class ContextError extends AgError {\n static errorName = 'ContextError';\n}\n","import { createContext } from 'react';\n\nimport { ContextError } from '../../errors/ContextError';\n\nconst stub: () => void = () => {\n throw new ContextError('SaladBarContext can only be used in a child of a <SaladBarProvider>');\n};\n\nexport type NotificationType = {\n key: number;\n message: string;\n severity: 'success' | 'info' | 'warning' | 'error' | undefined;\n variant: 'standard' | 'outlined' | 'filled' | undefined;\n progressIndicator: string | undefined;\n autoHideDuration: number | undefined;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nconst notstub = (key: unknown): NotificationType | NotificationType[] | void => {\n throw new ContextError('SaladBarContext can only be used in a child of a <SaladBarProvider>');\n};\n\ntype SaladBarContextFunction = typeof stub | typeof notstub;\n\ntype SaladBarContextType = {\n enqueueNotification: SaladBarContextFunction; // Call as enqueueNotification(options)\n // where options include message and severity of 'error' ,'warning', 'info' or\n // 'success'\n enqueueSuccessNotification: SaladBarContextFunction; // Call as const key =\n // enqueueSuccessNotification(msg),\n enqueueInfoNotification: SaladBarContextFunction; // Call as const key =\n // enqueueInfoNotification(msg),\n enqueueWarningNotification: SaladBarContextFunction; // Call as const key =\n // enqueueWarningNotification(msg),\n enqueueErrorNotification: SaladBarContextFunction; // Call as const key =\n // enqueueErrorNotification(msg),\n removeNotification: SaladBarContextFunction; // Call as enqueueErrorNotification(key),\n};\n\n// The defaultValue argument is only used when a component does not have a\n// matching Provider above it in the tree. See\n// https://reactjs.org/docs/context.html#reactcreatecontext\n// Using createContext doesn't itself maintain any type of state exactly, it\n// just provides a way for children to access shared references.\nconst defaultValue = {\n enqueueNotification: stub,\n enqueueSuccessNotification: stub,\n enqueueInfoNotification: stub,\n enqueueWarningNotification: stub,\n enqueueErrorNotification: stub,\n removeNotification: notstub,\n} as SaladBarContextType;\n\n/**\n * @returns A SaladBarContext\n */\nconst SaladBarContext = createContext(defaultValue);\n\nexport default SaladBarContext;\n","// The default props passed to the underlying Snackbar component\nimport { SnackbarOrigin } from '@mui/material/Snackbar';\n\nexport const defaultSnackbarProps = {\n autoHideDuration: 6000,\n anchorOrigin: { vertical: 'top', horizontal: 'center' } as SnackbarOrigin,\n\n // The default is false. If we prefer timer to continue when window loses\n // focus, change to true\n disableWindowBlurListener: false,\n};\n\nexport const defaultEnqueueNotificationOptions = {\n message: '',\n severity: 'info',\n variant: 'standard',\n progressIndicator: undefined, // Can use 'circular' or 'linear'\n};\n","import React, { useRef, useState } from 'react';\nimport Snackbar from '@mui/material/Snackbar';\nimport Alert from '@mui/material/Alert';\nimport LinearProgress from '@mui/material/LinearProgress';\nimport CircularProgress from '@mui/material/CircularProgress';\n\nimport SaladBarContext, { NotificationType } from './SaladBarContext';\nimport { defaultSnackbarProps, defaultEnqueueNotificationOptions } from './defaults';\n\nconst MAX_QUEUE_LENGTH = 100;\nconst MAX_QUEUE_HIT_REPORT_INTERVAL = 2000;\nconst SALADBAR_INDEX = 2000;\n\n// No need to use uuids, just use an incremented value\nconst generateNotificationKey = (() => {\n let previousKey = 0;\n return () => {\n previousKey += 1;\n return previousKey;\n };\n})();\n\nconst alertWithLinearProgressStyle = {\n borderBottomLeftRadius: '0px',\n borderBottomRightRadius: '0px',\n};\n\ntype SaladBarProps = {\n children: React.ReactNode;\n};\n\nexport default function SaladBarProvider({ children, ...snackbarProps }: SaladBarProps) {\n const [open, setOpen] = useState(false);\n\n // We use a ref instead of a state to store the actual data, because we want\n // queue to be persistent across the whole lifetime of component. I considered\n // using yocto-queue because it would be O(1) instead of O(n), but its not\n // designed to access the head without removing it and its not going to make\n // much difference anyway.\n const queueRef = useRef<NotificationType[]>([]);\n\n const limitLastHitAt = useRef(Date.now());\n const limitHitCountSinceLastReport = useRef(0);\n\n const enqueueNotification = (notification = {}) => {\n limitHitCountSinceLastReport.current += 1;\n if (queueRef.current.length >= MAX_QUEUE_LENGTH) {\n // If the queue length is hit, probably stuck in some sort of loop, so\n // don't want to spam logs instantly so space it out\n if (Date.now() - limitLastHitAt.current >= MAX_QUEUE_HIT_REPORT_INTERVAL) {\n limitLastHitAt.current = Date.now();\n console.error(\n `SaladBarProvider: MAX_QUEUE_LENGTH (${MAX_QUEUE_LENGTH}) hit ${limitHitCountSinceLastReport.current} times in last ${MAX_QUEUE_HIT_REPORT_INTERVAL}ms)`\n );\n limitHitCountSinceLastReport.current = 0;\n }\n }\n\n const newNotification = {\n ...defaultEnqueueNotificationOptions,\n key: generateNotificationKey(), // Can be overridden.\n ...notification, // This could result in collisons, but unlikely.\n };\n\n // Add to the end of queue\n queueRef.current.push(newNotification as NotificationType);\n\n // If the queue was previously empty, then open the snackbar. We don't do it\n // whenever enqueueNotification is called since it will mess up transitions\n if (queueRef.current.length === 1) setOpen(true);\n\n return newNotification.key;\n };\n\n const enqueueSuccessNotification = (message = '', options = {}) =>\n enqueueNotification({ message, severity: 'success', ...options });\n\n const enqueueInfoNotification = (message = '', options = {}) =>\n enqueueNotification({ message, severity: 'info', ...options });\n\n const enqueueWarningNotification = (message = '', options = {}) =>\n enqueueNotification({ message, severity: 'warning', ...options });\n\n const enqueueErrorNotification = (message = '', options = {}) =>\n enqueueNotification({ message, severity: 'error', ...options });\n\n /**\n * Remove the notification with specified key from the queue. If the key is\n * not found, immediately returns null.\n *\n * @param key - The key as returned from enqueue...() function.\n *\n * @returns The removed notification\n */\n const removeNotification = (key: unknown) => {\n const index = queueRef.current.findIndex((x) => x.key === key);\n if (index === -1) return;\n\n if (index === 0) {\n // If its at the front of the queue, it is either currently being\n // displayed or in process of being closed. Either way, we can just set\n // open to false\n setOpen(false);\n return queueRef.current[0];\n }\n // Otherwise we just remove it from the queue, it won't need to transition\n return queueRef.current.splice(index, 1);\n };\n\n // Callback fired when the component requests to be closed\n // const handleClose = (_event, reason) => {\n // // We ignore click away, letting user continue with UI while its still\n // // displayed\n // if (reason === 'clickaway') return;\n\n // setOpen(false);\n // };\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const handleClose = (_event: Event | React.SyntheticEvent<Element, Event>) => {\n // We ignore click away, letting user continue with UI while its still\n // displayed\n\n setOpen(false);\n };\n\n // Callback fired before the transition is exiting.\n const handleExit = () => {};\n\n // Callback fired when the transition has exited.\n const handleExited = () => {\n // Remove head of queue\n queueRef.current.shift();\n\n // If there is still something on the queue, then re-open\n if (queueRef.current.length > 0) setOpen(true);\n };\n\n // The notification to display is the one at head of queue\n const currentNotification = queueRef.current[0] ?? {\n ...defaultEnqueueNotificationOptions,\n };\n\n // Can also override certain props on a notification level\n const currentNotificationSnackbarProps: { autoHideDuration?: number } = {};\n // Probably a better way of doing this\n if ('autoHideDuration' in currentNotification) {\n currentNotificationSnackbarProps.autoHideDuration = currentNotification.autoHideDuration;\n }\n\n // Note the order of props in Snackbar, we don't allow overriding open and\n // onClose.\n\n const snackbarFinalProps = { ...defaultSnackbarProps, ...snackbarProps };\n\n return (\n // Should be resolved when we move to React >= 18\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n <SaladBarContext.Provider\n value={{\n enqueueNotification,\n enqueueSuccessNotification,\n enqueueInfoNotification,\n enqueueWarningNotification,\n enqueueErrorNotification,\n removeNotification,\n }}\n >\n {children}\n <Snackbar\n {...snackbarFinalProps}\n {...currentNotificationSnackbarProps}\n open={open}\n onClose={handleClose}\n TransitionProps={{\n onExited: handleExited,\n onExit: handleExit,\n }}\n sx={{ zIndex: SALADBAR_INDEX }}\n >\n <div>\n <Alert\n onClose={handleClose}\n severity={currentNotification.severity}\n variant={'filled'}\n icon={\n currentNotification.progressIndicator === 'circular' ? (\n <CircularProgress size=\"1em\" />\n ) : undefined\n }\n style={\n currentNotification.progressIndicator === 'linear'\n ? alertWithLinearProgressStyle\n : undefined\n }\n >\n {currentNotification.message}\n </Alert>\n {currentNotification.progressIndicator === 'linear' && <LinearProgress color=\"primary\" />}\n </div>\n </Snackbar>\n </SaladBarContext.Provider>\n );\n}\n","import { useContext } from 'react';\nimport SaladBarContext from './SaladBarContext';\n\n/**\n * Use the `useSaladBar` hook in components to access the enqueueNotification()\n * method to add a snackbar message to queue.\n *\n * Example:\n *\n * ```js\n * const {\n * enqueueNotification,\n * enqueueSuccessNotification,\n * enqueueInfoNotification,\n * enqueueWarningNotification,\n * enqueueErrorNotification,\n * } = useSaladBar();\n * ...\n * enqueueNotification({message: 'hello', severity: 'info'});\n * // or\n * enqueueInfoNotification('hello');\n * ```\n */\nexport default function useSaladBar() {\n return useContext(SaladBarContext);\n}\n"],"names":["useState","jsxs","Fragment","jsx","createTheme","alpha","ThemeProvider","AgError","createContext","useRef","_a","useContext"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASwB,SAAA,iBAAiB,EAAE,QAA+B;AACxE,QAAM,CAAC,KAAK,MAAM,IAAIA,eAAS,CAAC;AAEhC,SAEIC,2BAAA,KAAAC,qBAAA,EAAA,UAAA;AAAA,IAAAC,2BAAA,IAAC,YAAW,EAAA,SAAQ,MAAK,OAAM,WAAU,WAAU,OAAM,IAAI,EAAE,UAAU,OAAO,GAAG,UAEnF,eAAA;AAAA,IAEAA,2BAAAA,IAAC,cAAW,SAAQ,WAAU,SAAQ,SACpC,UAAAA,2BAAAA,IAAC,QAAK,EAAA,UAAA,wEAAA,CAAqE,EAC7E,CAAA;AAAA,IACAA,2BAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,SAAQ;AAAA,QACR,SAAS,MAAM,OAAO,CAAC,WAAW,SAAS,CAAC;AAAA,QAC5C,cAAW;AAAA,QACZ,UAAA;AAAA,MAAA;AAAA,IAED;AAAA,oCACC,KAAE,EAAA,UAAA;AAAA,MAAA;AAAA,MACkBA,2BAAAA,IAAC,UAAM,UAAK,KAAA,CAAA;AAAA,IAAA,GACjC;AAAA,oCACC,OAAM,EAAA,UAAA;AAAA,MAAA;AAAA,MAAmD;AAAA,IAAA,GAAI;AAAA,EAChE,EAAA,CAAA;AAEJ;AChCO,MAAM,yBAAyBC,OAAAA,YAAY;AAAA,EAChD,SAAS;AAAA,IACP,SAAS;AAAA,MACP,MAAM;AAAA,MACN,MAAM;AAAA,MACN,OAAO;AAAA,MACP,cAAc;AAAA,IAChB;AAAA,IACA,WAAW;AAAA,MACT,MAAM;AAAA,MACN,MAAM;AAAA,MACN,O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|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __objRest = (source, exclude) => {
|
|
21
|
+
var target = {};
|
|
22
|
+
for (var prop in source)
|
|
23
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
+
target[prop] = source[prop];
|
|
25
|
+
if (source != null && __getOwnPropSymbols)
|
|
26
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
}
|
|
30
|
+
return target;
|
|
21
31
|
};
|
|
22
|
-
var
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
import
|
|
27
|
-
import
|
|
28
|
-
import
|
|
29
|
-
import
|
|
30
|
-
import
|
|
31
|
-
import
|
|
32
|
-
import
|
|
33
|
-
import
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
32
|
+
var __publicField = (obj, key, value) => {
|
|
33
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
34
|
+
return value;
|
|
35
|
+
};
|
|
36
|
+
import { jsxs, Fragment, jsx } from "react/jsx-runtime";
|
|
37
|
+
import { useState, createContext, useRef, useContext } from "react";
|
|
38
|
+
import Button from "@mui/material/Button";
|
|
39
|
+
import Paper from "@mui/material/Paper";
|
|
40
|
+
import Typography from "@mui/material/Typography";
|
|
41
|
+
import { createTheme, alpha, ThemeProvider } from "@mui/material/styles";
|
|
42
|
+
import Snackbar from "@mui/material/Snackbar";
|
|
43
|
+
import Alert from "@mui/material/Alert";
|
|
44
|
+
import LinearProgress from "@mui/material/LinearProgress";
|
|
45
|
+
import CircularProgress from "@mui/material/CircularProgress";
|
|
46
|
+
import { AgError } from "@australiangreens/ag-error";
|
|
47
|
+
function ExampleComponent({ text }) {
|
|
48
|
+
const [num, setNum] = useState(0);
|
|
49
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
50
|
+
/* @__PURE__ */ jsx(Typography, { variant: "h6", color: "inherit", component: "div", sx: { fontSize: "22px" }, children: "Hello world" }),
|
|
51
|
+
/* @__PURE__ */ jsx(Typography, { variant: "caption", display: "block", children: /* @__PURE__ */ jsx("span", { children: "Just ensuring MUI is working as planned as a peer dependency. v0.0.11" }) }),
|
|
52
|
+
/* @__PURE__ */ jsx(
|
|
53
|
+
Button,
|
|
41
54
|
{
|
|
42
55
|
variant: "outlined",
|
|
43
|
-
onClick: () =>
|
|
56
|
+
onClick: () => setNum((oldNum) => oldNum + 1),
|
|
44
57
|
"aria-label": "Increment",
|
|
45
58
|
children: "Hello I am a button"
|
|
46
59
|
}
|
|
47
60
|
),
|
|
48
|
-
/* @__PURE__ */
|
|
61
|
+
/* @__PURE__ */ jsxs("p", { children: [
|
|
49
62
|
"This is some text: ",
|
|
50
|
-
/* @__PURE__ */
|
|
63
|
+
/* @__PURE__ */ jsx("span", { children: text })
|
|
51
64
|
] }),
|
|
52
|
-
/* @__PURE__ */
|
|
65
|
+
/* @__PURE__ */ jsxs(Paper, { children: [
|
|
53
66
|
"This number will incremember when button pressed: ",
|
|
54
|
-
|
|
67
|
+
num
|
|
55
68
|
] })
|
|
56
69
|
] });
|
|
57
70
|
}
|
|
58
|
-
const
|
|
71
|
+
const internalAGSystemsTheme = createTheme({
|
|
59
72
|
palette: {
|
|
60
73
|
primary: {
|
|
61
74
|
main: "#007236",
|
|
@@ -107,22 +120,22 @@ const ae = M({
|
|
|
107
120
|
MuiMenuItem: {
|
|
108
121
|
// Setting defaultProps for color on MenuItem does not work, so update manually
|
|
109
122
|
styleOverrides: {
|
|
110
|
-
root: ({ theme
|
|
123
|
+
root: ({ theme }) => ({
|
|
111
124
|
"&.Mui-selected": {
|
|
112
|
-
backgroundColor:
|
|
113
|
-
|
|
114
|
-
|
|
125
|
+
backgroundColor: alpha(
|
|
126
|
+
theme.palette.secondary.main,
|
|
127
|
+
theme.palette.action.selectedOpacity
|
|
115
128
|
),
|
|
116
129
|
"&:hover": {
|
|
117
|
-
backgroundColor:
|
|
118
|
-
|
|
119
|
-
|
|
130
|
+
backgroundColor: alpha(
|
|
131
|
+
theme.palette.secondary.main,
|
|
132
|
+
theme.palette.action.selectedOpacity
|
|
120
133
|
)
|
|
121
134
|
},
|
|
122
135
|
"&.Mui-focusVisible": {
|
|
123
|
-
backgroundColor:
|
|
124
|
-
|
|
125
|
-
|
|
136
|
+
backgroundColor: alpha(
|
|
137
|
+
theme.palette.secondary.main,
|
|
138
|
+
theme.palette.action.focusOpacity
|
|
126
139
|
)
|
|
127
140
|
}
|
|
128
141
|
}
|
|
@@ -143,7 +156,8 @@ const ae = M({
|
|
|
143
156
|
fontWeight: 700
|
|
144
157
|
}
|
|
145
158
|
}
|
|
146
|
-
})
|
|
159
|
+
});
|
|
160
|
+
const fed21Theme = createTheme({
|
|
147
161
|
palette: {
|
|
148
162
|
primary: {
|
|
149
163
|
dark: "#00A651",
|
|
@@ -192,107 +206,155 @@ const ae = M({
|
|
|
192
206
|
}
|
|
193
207
|
}
|
|
194
208
|
});
|
|
195
|
-
function
|
|
196
|
-
name
|
|
197
|
-
children
|
|
209
|
+
function AgThemeProvider({
|
|
210
|
+
name = "internal",
|
|
211
|
+
children
|
|
198
212
|
}) {
|
|
199
|
-
|
|
213
|
+
const theme = name === "internal" ? internalAGSystemsTheme : name === "fed21" ? fed21Theme : void 0;
|
|
214
|
+
return /* @__PURE__ */ jsx(ThemeProvider, { theme, children });
|
|
200
215
|
}
|
|
201
|
-
class
|
|
216
|
+
class ContextError extends AgError {
|
|
202
217
|
}
|
|
203
|
-
|
|
204
|
-
const
|
|
205
|
-
throw new
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
218
|
+
__publicField(ContextError, "errorName", "ContextError");
|
|
219
|
+
const stub = () => {
|
|
220
|
+
throw new ContextError("SaladBarContext can only be used in a child of a <SaladBarProvider>");
|
|
221
|
+
};
|
|
222
|
+
const notstub = (key) => {
|
|
223
|
+
throw new ContextError("SaladBarContext can only be used in a child of a <SaladBarProvider>");
|
|
224
|
+
};
|
|
225
|
+
const defaultValue = {
|
|
226
|
+
enqueueNotification: stub,
|
|
227
|
+
enqueueSuccessNotification: stub,
|
|
228
|
+
enqueueInfoNotification: stub,
|
|
229
|
+
enqueueWarningNotification: stub,
|
|
230
|
+
enqueueErrorNotification: stub,
|
|
231
|
+
removeNotification: notstub
|
|
232
|
+
};
|
|
233
|
+
const SaladBarContext = createContext(defaultValue);
|
|
234
|
+
const defaultSnackbarProps = {
|
|
216
235
|
autoHideDuration: 6e3,
|
|
217
236
|
anchorOrigin: { vertical: "top", horizontal: "center" },
|
|
218
237
|
// The default is false. If we prefer timer to continue when window loses
|
|
219
238
|
// focus, change to true
|
|
220
|
-
disableWindowBlurListener:
|
|
221
|
-
}
|
|
239
|
+
disableWindowBlurListener: false
|
|
240
|
+
};
|
|
241
|
+
const defaultEnqueueNotificationOptions = {
|
|
222
242
|
message: "",
|
|
223
243
|
severity: "info",
|
|
224
244
|
variant: "standard",
|
|
225
245
|
progressIndicator: void 0
|
|
226
246
|
// Can use 'circular' or 'linear'
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
247
|
+
};
|
|
248
|
+
const MAX_QUEUE_LENGTH = 100;
|
|
249
|
+
const MAX_QUEUE_HIT_REPORT_INTERVAL = 2e3;
|
|
250
|
+
const SALADBAR_INDEX = 2e3;
|
|
251
|
+
const generateNotificationKey = (() => {
|
|
252
|
+
let previousKey = 0;
|
|
253
|
+
return () => {
|
|
254
|
+
previousKey += 1;
|
|
255
|
+
return previousKey;
|
|
256
|
+
};
|
|
257
|
+
})();
|
|
258
|
+
const alertWithLinearProgressStyle = {
|
|
231
259
|
borderBottomLeftRadius: "0px",
|
|
232
260
|
borderBottomRightRadius: "0px"
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
var
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
261
|
+
};
|
|
262
|
+
function SaladBarProvider(_a) {
|
|
263
|
+
var _b = _a, { children } = _b, snackbarProps = __objRest(_b, ["children"]);
|
|
264
|
+
var _a2;
|
|
265
|
+
const [open, setOpen] = useState(false);
|
|
266
|
+
const queueRef = useRef([]);
|
|
267
|
+
const limitLastHitAt = useRef(Date.now());
|
|
268
|
+
const limitHitCountSinceLastReport = useRef(0);
|
|
269
|
+
const enqueueNotification = (notification = {}) => {
|
|
270
|
+
limitHitCountSinceLastReport.current += 1;
|
|
271
|
+
if (queueRef.current.length >= MAX_QUEUE_LENGTH) {
|
|
272
|
+
if (Date.now() - limitLastHitAt.current >= MAX_QUEUE_HIT_REPORT_INTERVAL) {
|
|
273
|
+
limitLastHitAt.current = Date.now();
|
|
274
|
+
console.error(
|
|
275
|
+
`SaladBarProvider: MAX_QUEUE_LENGTH (${MAX_QUEUE_LENGTH}) hit ${limitHitCountSinceLastReport.current} times in last ${MAX_QUEUE_HIT_REPORT_INTERVAL}ms)`
|
|
276
|
+
);
|
|
277
|
+
limitHitCountSinceLastReport.current = 0;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
const newNotification = __spreadValues(__spreadProps(__spreadValues({}, defaultEnqueueNotificationOptions), {
|
|
281
|
+
key: generateNotificationKey()
|
|
282
|
+
}), notification);
|
|
283
|
+
queueRef.current.push(newNotification);
|
|
284
|
+
if (queueRef.current.length === 1)
|
|
285
|
+
setOpen(true);
|
|
286
|
+
return newNotification.key;
|
|
287
|
+
};
|
|
288
|
+
const enqueueSuccessNotification = (message = "", options = {}) => enqueueNotification(__spreadValues({ message, severity: "success" }, options));
|
|
289
|
+
const enqueueInfoNotification = (message = "", options = {}) => enqueueNotification(__spreadValues({ message, severity: "info" }, options));
|
|
290
|
+
const enqueueWarningNotification = (message = "", options = {}) => enqueueNotification(__spreadValues({ message, severity: "warning" }, options));
|
|
291
|
+
const enqueueErrorNotification = (message = "", options = {}) => enqueueNotification(__spreadValues({ message, severity: "error" }, options));
|
|
292
|
+
const removeNotification = (key) => {
|
|
293
|
+
const index = queueRef.current.findIndex((x) => x.key === key);
|
|
294
|
+
if (index === -1)
|
|
295
|
+
return;
|
|
296
|
+
if (index === 0) {
|
|
297
|
+
setOpen(false);
|
|
298
|
+
return queueRef.current[0];
|
|
299
|
+
}
|
|
300
|
+
return queueRef.current.splice(index, 1);
|
|
301
|
+
};
|
|
302
|
+
const handleClose = (_event) => {
|
|
303
|
+
setOpen(false);
|
|
304
|
+
};
|
|
305
|
+
const handleExit = () => {
|
|
306
|
+
};
|
|
307
|
+
const handleExited = () => {
|
|
308
|
+
queueRef.current.shift();
|
|
309
|
+
if (queueRef.current.length > 0)
|
|
310
|
+
setOpen(true);
|
|
311
|
+
};
|
|
312
|
+
const currentNotification = (_a2 = queueRef.current[0]) != null ? _a2 : __spreadValues({}, defaultEnqueueNotificationOptions);
|
|
313
|
+
const currentNotificationSnackbarProps = {};
|
|
314
|
+
if ("autoHideDuration" in currentNotification) {
|
|
315
|
+
currentNotificationSnackbarProps.autoHideDuration = currentNotification.autoHideDuration;
|
|
316
|
+
}
|
|
317
|
+
const snackbarFinalProps = __spreadValues(__spreadValues({}, defaultSnackbarProps), snackbarProps);
|
|
256
318
|
return (
|
|
257
319
|
// Should be resolved when we move to React >= 18
|
|
258
320
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
259
321
|
// @ts-ignore
|
|
260
|
-
/* @__PURE__ */
|
|
261
|
-
|
|
322
|
+
/* @__PURE__ */ jsxs(
|
|
323
|
+
SaladBarContext.Provider,
|
|
262
324
|
{
|
|
263
325
|
value: {
|
|
264
|
-
enqueueNotification
|
|
265
|
-
enqueueSuccessNotification
|
|
266
|
-
enqueueInfoNotification
|
|
267
|
-
enqueueWarningNotification
|
|
268
|
-
enqueueErrorNotification
|
|
269
|
-
removeNotification
|
|
326
|
+
enqueueNotification,
|
|
327
|
+
enqueueSuccessNotification,
|
|
328
|
+
enqueueInfoNotification,
|
|
329
|
+
enqueueWarningNotification,
|
|
330
|
+
enqueueErrorNotification,
|
|
331
|
+
removeNotification
|
|
270
332
|
},
|
|
271
333
|
children: [
|
|
272
|
-
|
|
273
|
-
/* @__PURE__ */
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
open
|
|
277
|
-
onClose:
|
|
334
|
+
children,
|
|
335
|
+
/* @__PURE__ */ jsx(
|
|
336
|
+
Snackbar,
|
|
337
|
+
__spreadProps(__spreadValues(__spreadValues({}, snackbarFinalProps), currentNotificationSnackbarProps), {
|
|
338
|
+
open,
|
|
339
|
+
onClose: handleClose,
|
|
278
340
|
TransitionProps: {
|
|
279
|
-
onExited:
|
|
280
|
-
onExit:
|
|
341
|
+
onExited: handleExited,
|
|
342
|
+
onExit: handleExit
|
|
281
343
|
},
|
|
282
|
-
sx: { zIndex:
|
|
283
|
-
children: /* @__PURE__ */
|
|
284
|
-
/* @__PURE__ */
|
|
285
|
-
|
|
344
|
+
sx: { zIndex: SALADBAR_INDEX },
|
|
345
|
+
children: /* @__PURE__ */ jsxs("div", { children: [
|
|
346
|
+
/* @__PURE__ */ jsx(
|
|
347
|
+
Alert,
|
|
286
348
|
{
|
|
287
|
-
onClose:
|
|
288
|
-
severity:
|
|
349
|
+
onClose: handleClose,
|
|
350
|
+
severity: currentNotification.severity,
|
|
289
351
|
variant: "filled",
|
|
290
|
-
icon:
|
|
291
|
-
style:
|
|
292
|
-
children:
|
|
352
|
+
icon: currentNotification.progressIndicator === "circular" ? /* @__PURE__ */ jsx(CircularProgress, { size: "1em" }) : void 0,
|
|
353
|
+
style: currentNotification.progressIndicator === "linear" ? alertWithLinearProgressStyle : void 0,
|
|
354
|
+
children: currentNotification.message
|
|
293
355
|
}
|
|
294
356
|
),
|
|
295
|
-
|
|
357
|
+
currentNotification.progressIndicator === "linear" && /* @__PURE__ */ jsx(LinearProgress, { color: "primary" })
|
|
296
358
|
] })
|
|
297
359
|
})
|
|
298
360
|
)
|
|
@@ -300,15 +362,15 @@ const d = () => {
|
|
|
300
362
|
}
|
|
301
363
|
)
|
|
302
364
|
);
|
|
303
|
-
}
|
|
304
|
-
function
|
|
305
|
-
return
|
|
365
|
+
}
|
|
366
|
+
function useSaladBar() {
|
|
367
|
+
return useContext(SaladBarContext);
|
|
306
368
|
}
|
|
307
369
|
export {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
370
|
+
AgThemeProvider,
|
|
371
|
+
ContextError,
|
|
372
|
+
ExampleComponent,
|
|
373
|
+
SaladBarProvider,
|
|
374
|
+
useSaladBar
|
|
313
375
|
};
|
|
314
376
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/components/ExampleComponent/index.tsx","../../src/providers/AgTheme/themes.ts","../../src/providers/AgTheme/index.tsx","../../src/errors/ContextError.ts","../../src/providers/SaladBar/SaladBarContext.ts","../../src/providers/SaladBar/defaults.ts","../../src/providers/SaladBar/SaladBarProvider.tsx","../../src/providers/SaladBar/useSaladBar.ts"],"sourcesContent":["import { useState } from 'react';\nimport Button from '@mui/material/Button';\nimport Paper from '@mui/material/Paper';\nimport Typography from '@mui/material/Typography';\n\nexport interface ExampleComponentProps {\n text: string;\n}\n\nexport default function ExampleComponent({ text }: ExampleComponentProps) {\n const [num, setNum] = useState(0);\n\n return (\n <>\n <Typography variant=\"h6\" color=\"inherit\" component=\"div\" sx={{ fontSize: '22px' }}>\n Hello world\n </Typography>\n\n <Typography variant=\"caption\" display=\"block\">\n <span>Just ensuring MUI is working as planned as a peer dependency. v0.0.11</span>\n </Typography>\n <Button\n variant=\"outlined\"\n onClick={() => setNum((oldNum) => oldNum + 1)}\n aria-label=\"Increment\"\n >\n Hello I am a button\n </Button>\n <p>\n This is some text: <span>{text}</span>\n </p>\n <Paper>This number will incremember when button pressed: {num}</Paper>\n </>\n );\n}\n","import { alpha, createTheme } from '@mui/material/styles';\n\nexport const internalAGSystemsTheme = createTheme({\n palette: {\n primary: {\n main: '#007236',\n dark: '#005221',\n light: '#00A04E',\n contrastText: '#FFFFFF',\n },\n secondary: {\n main: '#662D91',\n dark: '#440E62',\n light: '#93268F',\n contrastText: '#FFFFFF',\n },\n error: {\n main: '#D32F2F',\n dark: '#C62828',\n light: '#EF5350',\n },\n info: {\n main: '#0288D1',\n dark: '#01579B',\n light: '#03A9F4',\n },\n success: {\n main: '#0288D1',\n dark: '#01579B',\n light: '#03A9F4',\n },\n },\n components: {\n MuiTextField: {\n defaultProps: { color: 'secondary' },\n },\n MuiToggleButtonGroup: {\n defaultProps: { color: 'secondary' },\n },\n MuiCheckbox: {\n defaultProps: { color: 'secondary' },\n },\n MuiSelect: {\n defaultProps: { color: 'secondary' },\n },\n MuiSwitch: {\n defaultProps: { color: 'secondary' },\n },\n MuiFormControl: {\n defaultProps: { color: 'secondary' },\n },\n MuiMenuItem: {\n // Setting defaultProps for color on MenuItem does not work, so update manually\n styleOverrides: {\n root: ({ theme }) => ({\n '&.Mui-selected': {\n backgroundColor: alpha(\n theme.palette.secondary.main,\n theme.palette.action.selectedOpacity\n ),\n '&:hover': {\n backgroundColor: alpha(\n theme.palette.secondary.main,\n theme.palette.action.selectedOpacity\n ),\n },\n '&.Mui-focusVisible': {\n backgroundColor: alpha(\n theme.palette.secondary.main,\n theme.palette.action.focusOpacity\n ),\n },\n },\n }),\n },\n },\n },\n typography: {\n // I couldn't think of what to call this. It is an attempt to match\n // https://www.figma.com/file/atonRPl2YD9A1NCntbDtKR/List-Filter-and-Product-Concept?node-id=1187%3A43730\n // but not sure if line height should be changed\n explainer: {\n fontSize: '14px',\n marginBlockStart: '1em',\n },\n h3: {\n fontSize: '1rem',\n fontWeight: 700,\n },\n },\n});\n\nexport const fed21Theme = createTheme({\n palette: {\n primary: {\n dark: '#00A651',\n light: '#A3D39C',\n main: '#007236',\n contrastText: '#FFF',\n },\n warning: {\n main: '#F5871F',\n light: '#FCC589',\n dark: '#A2590A',\n contrastText: '#FFF',\n },\n secondary: {\n main: '#662D91',\n light: '#BD8CBF',\n dark: '#440E62',\n contrastText: '#FFF',\n },\n error: {\n main: '#D43C95',\n light: '#8F2064',\n dark: '#F9CDE0',\n contrastText: '#FFF',\n },\n info: {\n main: '#00A88D',\n light: '#ADDCCF',\n dark: '#005243',\n contrastText: '#FFF',\n },\n success: {\n main: '#00A651',\n light: '#A3D39C',\n dark: '#007236',\n contrastText: '#FFF',\n },\n },\n typography: {\n // I couldn't think of what to call this. It is an attempt to match\n // https://www.figma.com/file/atonRPl2YD9A1NCntbDtKR/List-Filter-and-Product-Concept?node-id=1187%3A43730\n // but not sure if line height should be changed\n explainer: {\n fontSize: '14px',\n marginBlockStart: '1em',\n },\n },\n});\n","import { PropsWithChildren } from 'react';\nimport { ThemeProvider } from '@mui/material/styles';\n\nimport { internalAGSystemsTheme, fed21Theme } from './themes';\n\nexport type AgThemeName = 'internal' | 'fed21';\n\nexport interface AgThemeProviderProps {\n name?: AgThemeName;\n}\n\nexport default function AgThemeProvider({\n name = 'internal',\n children,\n}: PropsWithChildren<AgThemeProviderProps>) {\n const theme =\n name === 'internal' ? internalAGSystemsTheme : name === 'fed21' ? fed21Theme : undefined;\n\n // Should be resolved when we move to React >= 18\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n return <ThemeProvider theme={theme}>{children}</ThemeProvider>;\n}\n","import { AgError } from '@australiangreens/ag-error';\n\n// Superclass for errors involving React context.\nexport class ContextError extends AgError {\n static errorName = 'ContextError';\n}\n","import { createContext } from 'react';\n\nimport { ContextError } from '../../errors/ContextError';\n\nconst stub: () => void = () => {\n throw new ContextError('SaladBarContext can only be used in a child of a <SaladBarProvider>');\n};\n\nexport type NotificationType = {\n key: number;\n message: string;\n severity: 'success' | 'info' | 'warning' | 'error' | undefined;\n variant: 'standard' | 'outlined' | 'filled' | undefined;\n progressIndicator: string | undefined;\n autoHideDuration: number | undefined;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nconst notstub = (key: unknown): NotificationType | NotificationType[] | void => {\n throw new ContextError('SaladBarContext can only be used in a child of a <SaladBarProvider>');\n};\n\ntype SaladBarContextFunction = typeof stub | typeof notstub;\n\ntype SaladBarContextType = {\n enqueueNotification: SaladBarContextFunction; // Call as enqueueNotification(options)\n // where options include message and severity of 'error' ,'warning', 'info' or\n // 'success'\n enqueueSuccessNotification: SaladBarContextFunction; // Call as const key =\n // enqueueSuccessNotification(msg),\n enqueueInfoNotification: SaladBarContextFunction; // Call as const key =\n // enqueueInfoNotification(msg),\n enqueueWarningNotification: SaladBarContextFunction; // Call as const key =\n // enqueueWarningNotification(msg),\n enqueueErrorNotification: SaladBarContextFunction; // Call as const key =\n // enqueueErrorNotification(msg),\n removeNotification: SaladBarContextFunction; // Call as enqueueErrorNotification(key),\n};\n\n// The defaultValue argument is only used when a component does not have a\n// matching Provider above it in the tree. See\n// https://reactjs.org/docs/context.html#reactcreatecontext\n// Using createContext doesn't itself maintain any type of state exactly, it\n// just provides a way for children to access shared references.\nconst defaultValue = {\n enqueueNotification: stub,\n enqueueSuccessNotification: stub,\n enqueueInfoNotification: stub,\n enqueueWarningNotification: stub,\n enqueueErrorNotification: stub,\n removeNotification: notstub,\n} as SaladBarContextType;\n\n/**\n * @returns A SaladBarContext\n */\nconst SaladBarContext = createContext(defaultValue);\n\nexport default SaladBarContext;\n","// The default props passed to the underlying Snackbar component\nimport { SnackbarOrigin } from '@mui/material/Snackbar';\n\nexport const defaultSnackbarProps = {\n autoHideDuration: 6000,\n anchorOrigin: { vertical: 'top', horizontal: 'center' } as SnackbarOrigin,\n\n // The default is false. If we prefer timer to continue when window loses\n // focus, change to true\n disableWindowBlurListener: false,\n};\n\nexport const defaultEnqueueNotificationOptions = {\n message: '',\n severity: 'info',\n variant: 'standard',\n progressIndicator: undefined, // Can use 'circular' or 'linear'\n};\n","import React, { useRef, useState } from 'react';\nimport Snackbar from '@mui/material/Snackbar';\nimport Alert from '@mui/material/Alert';\nimport LinearProgress from '@mui/material/LinearProgress';\nimport CircularProgress from '@mui/material/CircularProgress';\n\nimport SaladBarContext, { NotificationType } from './SaladBarContext';\nimport { defaultSnackbarProps, defaultEnqueueNotificationOptions } from './defaults';\n\nconst MAX_QUEUE_LENGTH = 100;\nconst MAX_QUEUE_HIT_REPORT_INTERVAL = 2000;\nconst SALADBAR_INDEX = 2000;\n\n// No need to use uuids, just use an incremented value\nconst generateNotificationKey = (() => {\n let previousKey = 0;\n return () => {\n previousKey += 1;\n return previousKey;\n };\n})();\n\nconst alertWithLinearProgressStyle = {\n borderBottomLeftRadius: '0px',\n borderBottomRightRadius: '0px',\n};\n\ntype SaladBarProps = {\n children: React.ReactNode;\n};\n\nconst SaladBar = ({ children, ...snackbarProps }: SaladBarProps) => {\n const [open, setOpen] = useState(false);\n\n // We use a ref instead of a state to store the actual data, because we want\n // queue to be persistent across the whole lifetime of component. I considered\n // using yocto-queue because it would be O(1) instead of O(n), but its not\n // designed to access the head without removing it and its not going to make\n // much difference anyway.\n const queueRef = useRef<NotificationType[]>([]);\n\n const limitLastHitAt = useRef(Date.now());\n const limitHitCountSinceLastReport = useRef(0);\n\n const enqueueNotification = (notification = {}) => {\n limitHitCountSinceLastReport.current += 1;\n if (queueRef.current.length >= MAX_QUEUE_LENGTH) {\n // If the queue length is hit, probably stuck in some sort of loop, so\n // don't want to spam logs instantly so space it out\n if (Date.now() - limitLastHitAt.current >= MAX_QUEUE_HIT_REPORT_INTERVAL) {\n limitLastHitAt.current = Date.now();\n console.error(\n `SaladBarProvider: MAX_QUEUE_LENGTH (${MAX_QUEUE_LENGTH}) hit ${limitHitCountSinceLastReport.current} times in last ${MAX_QUEUE_HIT_REPORT_INTERVAL}ms)`\n );\n limitHitCountSinceLastReport.current = 0;\n }\n }\n\n const newNotification = {\n ...defaultEnqueueNotificationOptions,\n key: generateNotificationKey(), // Can be overridden.\n ...notification, // This could result in collisons, but unlikely.\n };\n\n // Add to the end of queue\n queueRef.current.push(newNotification as NotificationType);\n\n // If the queue was previously empty, then open the snackbar. We don't do it\n // whenever enqueueNotification is called since it will mess up transitions\n if (queueRef.current.length === 1) setOpen(true);\n\n return newNotification.key;\n };\n\n const enqueueSuccessNotification = (message = '', options = {}) =>\n enqueueNotification({ message, severity: 'success', ...options });\n\n const enqueueInfoNotification = (message = '', options = {}) =>\n enqueueNotification({ message, severity: 'info', ...options });\n\n const enqueueWarningNotification = (message = '', options = {}) =>\n enqueueNotification({ message, severity: 'warning', ...options });\n\n const enqueueErrorNotification = (message = '', options = {}) =>\n enqueueNotification({ message, severity: 'error', ...options });\n\n /**\n * Remove the notification with specified key from the queue. If the key is\n * not found, immediately returns null.\n *\n * @param key - The key as returned from enqueue...() function.\n *\n * @returns The removed notification\n */\n const removeNotification = (key: unknown) => {\n const index = queueRef.current.findIndex((x) => x.key === key);\n if (index === -1) return;\n\n if (index === 0) {\n // If its at the front of the queue, it is either currently being\n // displayed or in process of being closed. Either way, we can just set\n // open to false\n setOpen(false);\n return queueRef.current[0];\n }\n // Otherwise we just remove it from the queue, it won't need to transition\n return queueRef.current.splice(index, 1);\n };\n\n // Callback fired when the component requests to be closed\n // const handleClose = (_event, reason) => {\n // // We ignore click away, letting user continue with UI while its still\n // // displayed\n // if (reason === 'clickaway') return;\n\n // setOpen(false);\n // };\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const handleClose = (_event: Event | React.SyntheticEvent<Element, Event>) => {\n // We ignore click away, letting user continue with UI while its still\n // displayed\n\n setOpen(false);\n };\n\n // Callback fired before the transition is exiting.\n const handleExit = () => {};\n\n // Callback fired when the transition has exited.\n const handleExited = () => {\n // Remove head of queue\n queueRef.current.shift();\n\n // If there is still something on the queue, then re-open\n if (queueRef.current.length > 0) setOpen(true);\n };\n\n // The notification to display is the one at head of queue\n const currentNotification = queueRef.current[0] ?? {\n ...defaultEnqueueNotificationOptions,\n };\n\n // Can also override certain props on a notification level\n const currentNotificationSnackbarProps: { autoHideDuration?: number } = {};\n // Probably a better way of doing this\n if ('autoHideDuration' in currentNotification) {\n currentNotificationSnackbarProps.autoHideDuration = currentNotification.autoHideDuration;\n }\n\n // Note the order of props in Snackbar, we don't allow overriding open and\n // onClose.\n\n const snackbarFinalProps = { ...defaultSnackbarProps, ...snackbarProps };\n\n return (\n // Should be resolved when we move to React >= 18\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n <SaladBarContext.Provider\n value={{\n enqueueNotification,\n enqueueSuccessNotification,\n enqueueInfoNotification,\n enqueueWarningNotification,\n enqueueErrorNotification,\n removeNotification,\n }}\n >\n {children}\n <Snackbar\n {...snackbarFinalProps}\n {...currentNotificationSnackbarProps}\n open={open}\n onClose={handleClose}\n TransitionProps={{\n onExited: handleExited,\n onExit: handleExit,\n }}\n sx={{ zIndex: SALADBAR_INDEX }}\n >\n <div>\n <Alert\n onClose={handleClose}\n severity={currentNotification.severity}\n variant={'filled'}\n icon={\n currentNotification.progressIndicator === 'circular' ? (\n <CircularProgress size=\"1em\" />\n ) : undefined\n }\n style={\n currentNotification.progressIndicator === 'linear'\n ? alertWithLinearProgressStyle\n : undefined\n }\n >\n {currentNotification.message}\n </Alert>\n {currentNotification.progressIndicator === 'linear' && <LinearProgress color=\"primary\" />}\n </div>\n </Snackbar>\n </SaladBarContext.Provider>\n );\n};\n\nexport default SaladBar;\n","import { useContext } from 'react';\nimport SaladBarContext from './SaladBarContext';\n\n/**\n * Use the `useSaladBar` hook in components to access the enqueueNotification()\n * method to add a snackbar message to queue.\n *\n * Example:\n *\n * ```js\n * const {\n * enqueueNotification,\n * enqueueSuccessNotification,\n * enqueueInfoNotification,\n * enqueueWarningNotification,\n * enqueueErrorNotification,\n * } = useSaladBar();\n * ...\n * enqueueNotification({message: 'hello', severity: 'info'});\n * // or\n * enqueueInfoNotification('hello');\n * ```\n */\nexport default function useSaladBar() {\n return useContext(SaladBarContext);\n}\n"],"names":["ExampleComponent","text","num","setNum","useState","jsxs","Fragment","jsx","Typography","Button","oldNum","Paper","internalAGSystemsTheme","createTheme","theme","alpha","fed21Theme","AgThemeProvider","name","children","ThemeProvider","ContextError","AgError","__publicField","stub","notstub","key","defaultValue","SaladBarContext","createContext","defaultSnackbarProps","defaultEnqueueNotificationOptions","MAX_QUEUE_LENGTH","MAX_QUEUE_HIT_REPORT_INTERVAL","SALADBAR_INDEX","generateNotificationKey","previousKey","alertWithLinearProgressStyle","SaladBar","_a","_b","snackbarProps","__objRest","open","setOpen","queueRef","useRef","limitLastHitAt","limitHitCountSinceLastReport","enqueueNotification","notification","newNotification","__spreadValues","__spreadProps","enqueueSuccessNotification","message","options","enqueueInfoNotification","enqueueWarningNotification","enqueueErrorNotification","removeNotification","index","x","handleClose","_event","handleExit","handleExited","currentNotification","currentNotificationSnackbarProps","snackbarFinalProps","Snackbar","Alert","CircularProgress","LinearProgress","useSaladBar","useContext"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASwB,SAAAA,GAAiB,EAAE,MAAAC,KAA+B;AACxE,QAAM,CAACC,GAAKC,CAAM,IAAIC,EAAS,CAAC;AAEhC,SAEI,gBAAAC,EAAAC,GAAA,EAAA,UAAA;AAAA,IAAA,gBAAAC,EAACC,GAAW,EAAA,SAAQ,MAAK,OAAM,WAAU,WAAU,OAAM,IAAI,EAAE,UAAU,OAAO,GAAG,UAEnF,eAAA;AAAA,IAEA,gBAAAD,EAACC,KAAW,SAAQ,WAAU,SAAQ,SACpC,UAAA,gBAAAD,EAAC,QAAK,EAAA,UAAA,wEAAA,CAAqE,EAC7E,CAAA;AAAA,IACA,gBAAAA;AAAA,MAACE;AAAA,MAAA;AAAA,QACC,SAAQ;AAAA,QACR,SAAS,MAAMN,EAAO,CAACO,MAAWA,IAAS,CAAC;AAAA,QAC5C,cAAW;AAAA,QACZ,UAAA;AAAA,MAAA;AAAA,IAED;AAAA,sBACC,KAAE,EAAA,UAAA;AAAA,MAAA;AAAA,MACkB,gBAAAH,EAAC,UAAM,UAAKN,EAAA,CAAA;AAAA,IAAA,GACjC;AAAA,sBACCU,GAAM,EAAA,UAAA;AAAA,MAAA;AAAA,MAAmDT;AAAA,IAAA,GAAI;AAAA,EAChE,EAAA,CAAA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AAW/C,CAAe;AACnC;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/components/ExampleComponent/index.tsx","../../src/providers/AgTheme/themes.ts","../../src/providers/AgTheme/index.tsx","../../src/errors/ContextError.ts","../../src/providers/SaladBar/SaladBarContext.ts","../../src/providers/SaladBar/defaults.ts","../../src/providers/SaladBar/SaladBarProvider.tsx","../../src/providers/SaladBar/useSaladBar.ts"],"sourcesContent":["import { useState } from 'react';\nimport Button from '@mui/material/Button';\nimport Paper from '@mui/material/Paper';\nimport Typography from '@mui/material/Typography';\n\nexport interface ExampleComponentProps {\n text: string;\n}\n\nexport default function ExampleComponent({ text }: ExampleComponentProps) {\n const [num, setNum] = useState(0);\n\n return (\n <>\n <Typography variant=\"h6\" color=\"inherit\" component=\"div\" sx={{ fontSize: '22px' }}>\n Hello world\n </Typography>\n\n <Typography variant=\"caption\" display=\"block\">\n <span>Just ensuring MUI is working as planned as a peer dependency. v0.0.11</span>\n </Typography>\n <Button\n variant=\"outlined\"\n onClick={() => setNum((oldNum) => oldNum + 1)}\n aria-label=\"Increment\"\n >\n Hello I am a button\n </Button>\n <p>\n This is some text: <span>{text}</span>\n </p>\n <Paper>This number will incremember when button pressed: {num}</Paper>\n </>\n );\n}\n","import { alpha, createTheme } from '@mui/material/styles';\n\nexport const internalAGSystemsTheme = createTheme({\n palette: {\n primary: {\n main: '#007236',\n dark: '#005221',\n light: '#00A04E',\n contrastText: '#FFFFFF',\n },\n secondary: {\n main: '#662D91',\n dark: '#440E62',\n light: '#93268F',\n contrastText: '#FFFFFF',\n },\n error: {\n main: '#D32F2F',\n dark: '#C62828',\n light: '#EF5350',\n },\n info: {\n main: '#0288D1',\n dark: '#01579B',\n light: '#03A9F4',\n },\n success: {\n main: '#0288D1',\n dark: '#01579B',\n light: '#03A9F4',\n },\n },\n components: {\n MuiTextField: {\n defaultProps: { color: 'secondary' },\n },\n MuiToggleButtonGroup: {\n defaultProps: { color: 'secondary' },\n },\n MuiCheckbox: {\n defaultProps: { color: 'secondary' },\n },\n MuiSelect: {\n defaultProps: { color: 'secondary' },\n },\n MuiSwitch: {\n defaultProps: { color: 'secondary' },\n },\n MuiFormControl: {\n defaultProps: { color: 'secondary' },\n },\n MuiMenuItem: {\n // Setting defaultProps for color on MenuItem does not work, so update manually\n styleOverrides: {\n root: ({ theme }) => ({\n '&.Mui-selected': {\n backgroundColor: alpha(\n theme.palette.secondary.main,\n theme.palette.action.selectedOpacity\n ),\n '&:hover': {\n backgroundColor: alpha(\n theme.palette.secondary.main,\n theme.palette.action.selectedOpacity\n ),\n },\n '&.Mui-focusVisible': {\n backgroundColor: alpha(\n theme.palette.secondary.main,\n theme.palette.action.focusOpacity\n ),\n },\n },\n }),\n },\n },\n },\n typography: {\n // I couldn't think of what to call this. It is an attempt to match\n // https://www.figma.com/file/atonRPl2YD9A1NCntbDtKR/List-Filter-and-Product-Concept?node-id=1187%3A43730\n // but not sure if line height should be changed\n explainer: {\n fontSize: '14px',\n marginBlockStart: '1em',\n },\n h3: {\n fontSize: '1rem',\n fontWeight: 700,\n },\n },\n});\n\nexport const fed21Theme = createTheme({\n palette: {\n primary: {\n dark: '#00A651',\n light: '#A3D39C',\n main: '#007236',\n contrastText: '#FFF',\n },\n warning: {\n main: '#F5871F',\n light: '#FCC589',\n dark: '#A2590A',\n contrastText: '#FFF',\n },\n secondary: {\n main: '#662D91',\n light: '#BD8CBF',\n dark: '#440E62',\n contrastText: '#FFF',\n },\n error: {\n main: '#D43C95',\n light: '#8F2064',\n dark: '#F9CDE0',\n contrastText: '#FFF',\n },\n info: {\n main: '#00A88D',\n light: '#ADDCCF',\n dark: '#005243',\n contrastText: '#FFF',\n },\n success: {\n main: '#00A651',\n light: '#A3D39C',\n dark: '#007236',\n contrastText: '#FFF',\n },\n },\n typography: {\n // I couldn't think of what to call this. It is an attempt to match\n // https://www.figma.com/file/atonRPl2YD9A1NCntbDtKR/List-Filter-and-Product-Concept?node-id=1187%3A43730\n // but not sure if line height should be changed\n explainer: {\n fontSize: '14px',\n marginBlockStart: '1em',\n },\n },\n});\n","import { PropsWithChildren } from 'react';\nimport { ThemeProvider } from '@mui/material/styles';\n\nimport { internalAGSystemsTheme, fed21Theme } from './themes';\n\nexport type AgThemeName = 'internal' | 'fed21';\n\nexport interface AgThemeProviderProps {\n name?: AgThemeName;\n}\n\nexport default function AgThemeProvider({\n name = 'internal',\n children,\n}: PropsWithChildren<AgThemeProviderProps>) {\n const theme =\n name === 'internal' ? internalAGSystemsTheme : name === 'fed21' ? fed21Theme : undefined;\n\n // Should be resolved when we move to React >= 18\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n return <ThemeProvider theme={theme}>{children}</ThemeProvider>;\n}\n","import { AgError } from '@australiangreens/ag-error';\n\n// Superclass for errors involving React context.\nexport class ContextError extends AgError {\n static errorName = 'ContextError';\n}\n","import { createContext } from 'react';\n\nimport { ContextError } from '../../errors/ContextError';\n\nconst stub: () => void = () => {\n throw new ContextError('SaladBarContext can only be used in a child of a <SaladBarProvider>');\n};\n\nexport type NotificationType = {\n key: number;\n message: string;\n severity: 'success' | 'info' | 'warning' | 'error' | undefined;\n variant: 'standard' | 'outlined' | 'filled' | undefined;\n progressIndicator: string | undefined;\n autoHideDuration: number | undefined;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nconst notstub = (key: unknown): NotificationType | NotificationType[] | void => {\n throw new ContextError('SaladBarContext can only be used in a child of a <SaladBarProvider>');\n};\n\ntype SaladBarContextFunction = typeof stub | typeof notstub;\n\ntype SaladBarContextType = {\n enqueueNotification: SaladBarContextFunction; // Call as enqueueNotification(options)\n // where options include message and severity of 'error' ,'warning', 'info' or\n // 'success'\n enqueueSuccessNotification: SaladBarContextFunction; // Call as const key =\n // enqueueSuccessNotification(msg),\n enqueueInfoNotification: SaladBarContextFunction; // Call as const key =\n // enqueueInfoNotification(msg),\n enqueueWarningNotification: SaladBarContextFunction; // Call as const key =\n // enqueueWarningNotification(msg),\n enqueueErrorNotification: SaladBarContextFunction; // Call as const key =\n // enqueueErrorNotification(msg),\n removeNotification: SaladBarContextFunction; // Call as enqueueErrorNotification(key),\n};\n\n// The defaultValue argument is only used when a component does not have a\n// matching Provider above it in the tree. See\n// https://reactjs.org/docs/context.html#reactcreatecontext\n// Using createContext doesn't itself maintain any type of state exactly, it\n// just provides a way for children to access shared references.\nconst defaultValue = {\n enqueueNotification: stub,\n enqueueSuccessNotification: stub,\n enqueueInfoNotification: stub,\n enqueueWarningNotification: stub,\n enqueueErrorNotification: stub,\n removeNotification: notstub,\n} as SaladBarContextType;\n\n/**\n * @returns A SaladBarContext\n */\nconst SaladBarContext = createContext(defaultValue);\n\nexport default SaladBarContext;\n","// The default props passed to the underlying Snackbar component\nimport { SnackbarOrigin } from '@mui/material/Snackbar';\n\nexport const defaultSnackbarProps = {\n autoHideDuration: 6000,\n anchorOrigin: { vertical: 'top', horizontal: 'center' } as SnackbarOrigin,\n\n // The default is false. If we prefer timer to continue when window loses\n // focus, change to true\n disableWindowBlurListener: false,\n};\n\nexport const defaultEnqueueNotificationOptions = {\n message: '',\n severity: 'info',\n variant: 'standard',\n progressIndicator: undefined, // Can use 'circular' or 'linear'\n};\n","import React, { useRef, useState } from 'react';\nimport Snackbar from '@mui/material/Snackbar';\nimport Alert from '@mui/material/Alert';\nimport LinearProgress from '@mui/material/LinearProgress';\nimport CircularProgress from '@mui/material/CircularProgress';\n\nimport SaladBarContext, { NotificationType } from './SaladBarContext';\nimport { defaultSnackbarProps, defaultEnqueueNotificationOptions } from './defaults';\n\nconst MAX_QUEUE_LENGTH = 100;\nconst MAX_QUEUE_HIT_REPORT_INTERVAL = 2000;\nconst SALADBAR_INDEX = 2000;\n\n// No need to use uuids, just use an incremented value\nconst generateNotificationKey = (() => {\n let previousKey = 0;\n return () => {\n previousKey += 1;\n return previousKey;\n };\n})();\n\nconst alertWithLinearProgressStyle = {\n borderBottomLeftRadius: '0px',\n borderBottomRightRadius: '0px',\n};\n\ntype SaladBarProps = {\n children: React.ReactNode;\n};\n\nexport default function SaladBarProvider({ children, ...snackbarProps }: SaladBarProps) {\n const [open, setOpen] = useState(false);\n\n // We use a ref instead of a state to store the actual data, because we want\n // queue to be persistent across the whole lifetime of component. I considered\n // using yocto-queue because it would be O(1) instead of O(n), but its not\n // designed to access the head without removing it and its not going to make\n // much difference anyway.\n const queueRef = useRef<NotificationType[]>([]);\n\n const limitLastHitAt = useRef(Date.now());\n const limitHitCountSinceLastReport = useRef(0);\n\n const enqueueNotification = (notification = {}) => {\n limitHitCountSinceLastReport.current += 1;\n if (queueRef.current.length >= MAX_QUEUE_LENGTH) {\n // If the queue length is hit, probably stuck in some sort of loop, so\n // don't want to spam logs instantly so space it out\n if (Date.now() - limitLastHitAt.current >= MAX_QUEUE_HIT_REPORT_INTERVAL) {\n limitLastHitAt.current = Date.now();\n console.error(\n `SaladBarProvider: MAX_QUEUE_LENGTH (${MAX_QUEUE_LENGTH}) hit ${limitHitCountSinceLastReport.current} times in last ${MAX_QUEUE_HIT_REPORT_INTERVAL}ms)`\n );\n limitHitCountSinceLastReport.current = 0;\n }\n }\n\n const newNotification = {\n ...defaultEnqueueNotificationOptions,\n key: generateNotificationKey(), // Can be overridden.\n ...notification, // This could result in collisons, but unlikely.\n };\n\n // Add to the end of queue\n queueRef.current.push(newNotification as NotificationType);\n\n // If the queue was previously empty, then open the snackbar. We don't do it\n // whenever enqueueNotification is called since it will mess up transitions\n if (queueRef.current.length === 1) setOpen(true);\n\n return newNotification.key;\n };\n\n const enqueueSuccessNotification = (message = '', options = {}) =>\n enqueueNotification({ message, severity: 'success', ...options });\n\n const enqueueInfoNotification = (message = '', options = {}) =>\n enqueueNotification({ message, severity: 'info', ...options });\n\n const enqueueWarningNotification = (message = '', options = {}) =>\n enqueueNotification({ message, severity: 'warning', ...options });\n\n const enqueueErrorNotification = (message = '', options = {}) =>\n enqueueNotification({ message, severity: 'error', ...options });\n\n /**\n * Remove the notification with specified key from the queue. If the key is\n * not found, immediately returns null.\n *\n * @param key - The key as returned from enqueue...() function.\n *\n * @returns The removed notification\n */\n const removeNotification = (key: unknown) => {\n const index = queueRef.current.findIndex((x) => x.key === key);\n if (index === -1) return;\n\n if (index === 0) {\n // If its at the front of the queue, it is either currently being\n // displayed or in process of being closed. Either way, we can just set\n // open to false\n setOpen(false);\n return queueRef.current[0];\n }\n // Otherwise we just remove it from the queue, it won't need to transition\n return queueRef.current.splice(index, 1);\n };\n\n // Callback fired when the component requests to be closed\n // const handleClose = (_event, reason) => {\n // // We ignore click away, letting user continue with UI while its still\n // // displayed\n // if (reason === 'clickaway') return;\n\n // setOpen(false);\n // };\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const handleClose = (_event: Event | React.SyntheticEvent<Element, Event>) => {\n // We ignore click away, letting user continue with UI while its still\n // displayed\n\n setOpen(false);\n };\n\n // Callback fired before the transition is exiting.\n const handleExit = () => {};\n\n // Callback fired when the transition has exited.\n const handleExited = () => {\n // Remove head of queue\n queueRef.current.shift();\n\n // If there is still something on the queue, then re-open\n if (queueRef.current.length > 0) setOpen(true);\n };\n\n // The notification to display is the one at head of queue\n const currentNotification = queueRef.current[0] ?? {\n ...defaultEnqueueNotificationOptions,\n };\n\n // Can also override certain props on a notification level\n const currentNotificationSnackbarProps: { autoHideDuration?: number } = {};\n // Probably a better way of doing this\n if ('autoHideDuration' in currentNotification) {\n currentNotificationSnackbarProps.autoHideDuration = currentNotification.autoHideDuration;\n }\n\n // Note the order of props in Snackbar, we don't allow overriding open and\n // onClose.\n\n const snackbarFinalProps = { ...defaultSnackbarProps, ...snackbarProps };\n\n return (\n // Should be resolved when we move to React >= 18\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n <SaladBarContext.Provider\n value={{\n enqueueNotification,\n enqueueSuccessNotification,\n enqueueInfoNotification,\n enqueueWarningNotification,\n enqueueErrorNotification,\n removeNotification,\n }}\n >\n {children}\n <Snackbar\n {...snackbarFinalProps}\n {...currentNotificationSnackbarProps}\n open={open}\n onClose={handleClose}\n TransitionProps={{\n onExited: handleExited,\n onExit: handleExit,\n }}\n sx={{ zIndex: SALADBAR_INDEX }}\n >\n <div>\n <Alert\n onClose={handleClose}\n severity={currentNotification.severity}\n variant={'filled'}\n icon={\n currentNotification.progressIndicator === 'circular' ? (\n <CircularProgress size=\"1em\" />\n ) : undefined\n }\n style={\n currentNotification.progressIndicator === 'linear'\n ? alertWithLinearProgressStyle\n : undefined\n }\n >\n {currentNotification.message}\n </Alert>\n {currentNotification.progressIndicator === 'linear' && <LinearProgress color=\"primary\" />}\n </div>\n </Snackbar>\n </SaladBarContext.Provider>\n );\n}\n","import { useContext } from 'react';\nimport SaladBarContext from './SaladBarContext';\n\n/**\n * Use the `useSaladBar` hook in components to access the enqueueNotification()\n * method to add a snackbar message to queue.\n *\n * Example:\n *\n * ```js\n * const {\n * enqueueNotification,\n * enqueueSuccessNotification,\n * enqueueInfoNotification,\n * enqueueWarningNotification,\n * enqueueErrorNotification,\n * } = useSaladBar();\n * ...\n * enqueueNotification({message: 'hello', severity: 'info'});\n * // or\n * enqueueInfoNotification('hello');\n * ```\n */\nexport default function useSaladBar() {\n return useContext(SaladBarContext);\n}\n"],"names":["_a"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASwB,SAAA,iBAAiB,EAAE,QAA+B;AACxE,QAAM,CAAC,KAAK,MAAM,IAAI,SAAS,CAAC;AAEhC,SAEI,qBAAA,UAAA,EAAA,UAAA;AAAA,IAAA,oBAAC,YAAW,EAAA,SAAQ,MAAK,OAAM,WAAU,WAAU,OAAM,IAAI,EAAE,UAAU,OAAO,GAAG,UAEnF,eAAA;AAAA,IAEA,oBAAC,cAAW,SAAQ,WAAU,SAAQ,SACpC,UAAA,oBAAC,QAAK,EAAA,UAAA,wEAAA,CAAqE,EAC7E,CAAA;AAAA,IACA;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,SAAQ;AAAA,QACR,SAAS,MAAM,OAA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gBACC,oBAAoB,sBAAsB,YAAa,oBAAA,gBAAA,EAAe,OAAM,WAAU;AAAA,cAAA,GACzF;AAAA,YAAA;AAAA,UACF;AAAA,QAAA;AAAA,MAAA;AAAA,IACF;AAAA;AAEJ;ACrLA,SAAwB,cAAc;AACpC,SAAO,WAAW,eAAe;AACnC;"}
|
|
@@ -2,6 +2,6 @@ import React from 'react';
|
|
|
2
2
|
type SaladBarProps = {
|
|
3
3
|
children: React.ReactNode;
|
|
4
4
|
};
|
|
5
|
-
|
|
6
|
-
export
|
|
5
|
+
export default function SaladBarProvider({ children, ...snackbarProps }: SaladBarProps): JSX.Element;
|
|
6
|
+
export {};
|
|
7
7
|
//# sourceMappingURL=SaladBarProvider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SaladBarProvider.d.ts","sourceRoot":"","sources":["../../../../src/providers/SaladBar/SaladBarProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA2B,MAAM,OAAO,CAAC;AA2BhD,KAAK,aAAa,GAAG;IACnB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,CAAC;AAEF,
|
|
1
|
+
{"version":3,"file":"SaladBarProvider.d.ts","sourceRoot":"","sources":["../../../../src/providers/SaladBar/SaladBarProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA2B,MAAM,OAAO,CAAC;AA2BhD,KAAK,aAAa,GAAG;IACnB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,EAAE,QAAQ,EAAE,GAAG,aAAa,EAAE,EAAE,aAAa,eA6KrF"}
|
package/package.json
CHANGED