@onepercentio/one-ui 0.2.6 → 0.4.0
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/cypress/support/commands.ts +37 -0
- package/cypress/support/component-index.html +12 -0
- package/cypress/support/component.ts +39 -0
- package/cypress/support/{index.js → e2e.js} +0 -0
- package/dist/__test__/utils.d.ts +0 -1
- package/dist/__test__/utils.js +3 -35
- package/dist/__test__/utils.js.map +1 -1
- package/dist/components/AdaptiveButton/AdaptiveButton.js +8 -2
- package/dist/components/AdaptiveButton/AdaptiveButton.js.map +1 -1
- package/dist/components/AdaptiveButton/AdaptiveButton.module.scss +2 -1
- package/dist/components/AdaptiveButton/AdaptiveButton.stories.js +1 -1
- package/dist/components/AdaptiveButton/AdaptiveButton.stories.js.map +1 -1
- package/dist/components/AdaptiveSidebar/AdaptiveSidebar.d.ts +6 -2
- package/dist/components/AdaptiveSidebar/AdaptiveSidebar.js +10 -7
- package/dist/components/AdaptiveSidebar/AdaptiveSidebar.js.map +1 -1
- package/dist/components/AdaptiveSidebar/AdaptiveSidebar.module.scss +2 -1
- package/dist/components/AdaptiveSidebar/AdaptiveSidebar.stories.d.ts +3 -2
- package/dist/components/AnchoredTooltip/AnchoredTooltip.js +1 -1
- package/dist/components/AnchoredTooltip/AnchoredTooltip.js.map +1 -1
- package/dist/components/AnchoredTooltip/AnchoredTooltip.module.scss +1 -0
- package/dist/components/EmailInput/EmailInput.d.ts +4 -2
- package/dist/components/EmailInput/EmailInput.stories.d.ts +4 -2
- package/dist/components/Form/Form.d.ts +14 -8
- package/dist/components/Form/Form.js +11 -1
- package/dist/components/Form/Form.js.map +1 -1
- package/dist/components/Input/Input.d.ts +7 -3
- package/dist/components/Input/Input.js +2 -1
- package/dist/components/Input/Input.js.map +1 -1
- package/dist/components/Input/Input.module.scss +1 -0
- package/dist/components/Input/Input.stories.d.ts +3 -1
- package/dist/components/InstantCounter/InstantCounter.js +3 -3
- package/dist/components/InstantCounter/InstantCounter.js.map +1 -1
- package/dist/components/PasswordInput/PasswordInput.d.ts +3 -1
- package/dist/components/Portal/Portal.d.ts +11 -0
- package/dist/components/Portal/Portal.js +27 -0
- package/dist/components/Portal/Portal.js.map +1 -0
- package/dist/components/Portal/Portal.module.scss +3 -0
- package/dist/components/Portal/index.d.ts +1 -0
- package/dist/components/Portal/index.js +9 -0
- package/dist/components/Portal/index.js.map +1 -0
- package/dist/components/Select/Select.stories.d.ts +6 -2
- package/dist/components/Text/Text.js +1 -1
- package/dist/components/Text/Text.js.map +1 -1
- package/dist/components/Transition/Transition.d.ts +3 -2
- package/dist/components/Transition/Transition.js +19 -3
- package/dist/components/Transition/Transition.js.map +1 -1
- package/dist/components/Transition/Transition.module.scss +58 -5
- package/dist/components/UncontrolledTransition/UncontrolledTransition.stories.d.ts +1 -0
- package/dist/components/UncontrolledTransition/UncontrolledTransition.stories.js +42 -1
- package/dist/components/UncontrolledTransition/UncontrolledTransition.stories.js.map +1 -1
- package/dist/components/UncontrolledTransition/UncontrolledTransition.stories.module.scss +4 -0
- package/dist/context/OneUIProvider.d.ts +5 -3
- package/dist/context/OneUIProvider.js +35 -46
- package/dist/context/OneUIProvider.js.map +1 -1
- package/dist/hooks/shims/ObjectWatchShim.js +9 -12
- package/dist/hooks/shims/ObjectWatchShim.js.map +1 -1
- package/dist/hooks/useAsyncControl.js +2 -2
- package/dist/hooks/useAsyncControl.js.map +1 -1
- package/dist/hooks/useForm.d.ts +16 -0
- package/dist/hooks/useForm.js +24 -0
- package/dist/hooks/useForm.js.map +1 -0
- package/dist/hooks/useObserve.d.ts +1 -1
- package/dist/hooks/useObserve.js +9 -5
- package/dist/hooks/useObserve.js.map +1 -1
- package/dist/hooks/useRebound.d.ts +9 -0
- package/dist/hooks/useRebound.js +24 -0
- package/dist/hooks/useRebound.js.map +1 -0
- package/dist/hooks/useShortIntl.d.ts +1 -0
- package/dist/hooks/useShortIntl.js +5 -2
- package/dist/hooks/useShortIntl.js.map +1 -1
- package/package.json +25 -6
- package/scripts/start-emulator.js +48 -0
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
import { Get } from "type-fest";
|
|
1
2
|
import React from "react";
|
|
2
3
|
import { PropsWithChildren } from "react";
|
|
4
|
+
import { FieldPath } from "../utils";
|
|
3
5
|
declare type DeepPartial<T> = {
|
|
4
6
|
[P in keyof T]?: T[P] extends Function ? T[P] : DeepPartial<T[P]>;
|
|
5
7
|
};
|
|
6
8
|
declare type ContextSpecs = {
|
|
7
9
|
component: {
|
|
8
|
-
text
|
|
9
|
-
className
|
|
10
|
+
text?: {
|
|
11
|
+
className?: {
|
|
10
12
|
[k in React.ComponentProps<typeof import("../components/Text")["default"]>["type"]]?: string;
|
|
11
13
|
};
|
|
12
14
|
};
|
|
@@ -62,6 +64,6 @@ declare type ContextConfigSpecs = DeepPartial<ContextSpecs>;
|
|
|
62
64
|
export default function OneUIProvider({ children, config, }: PropsWithChildren<{
|
|
63
65
|
config: ContextConfigSpecs;
|
|
64
66
|
}>): JSX.Element;
|
|
65
|
-
export declare function ProtectVariableAccess(obj?: any, basePath?: string[]): any;
|
|
66
67
|
export declare function useOneUIContext(): ContextSpecs;
|
|
68
|
+
export declare function useOneUIConfig<P extends FieldPath<ContextSpecs>, T extends Get<ContextSpecs, P>>(prop: P, defaultValue?: T): NonNullable<Get<ContextSpecs, P>>;
|
|
67
69
|
export {};
|
|
@@ -3,8 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
const
|
|
6
|
+
exports.useOneUIConfig = exports.useOneUIContext = void 0;
|
|
7
|
+
const get_1 = __importDefault(require("lodash/get"));
|
|
8
8
|
const react_1 = __importDefault(require("react"));
|
|
9
9
|
const react_2 = require("react");
|
|
10
10
|
const Context = (0, react_2.createContext)(null);
|
|
@@ -12,60 +12,49 @@ function OneUIProvider({ children, config, }) {
|
|
|
12
12
|
return react_1.default.createElement(Context.Provider, { value: config }, children);
|
|
13
13
|
}
|
|
14
14
|
exports.default = OneUIProvider;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
case "component.input":
|
|
38
|
-
return {};
|
|
39
|
-
}
|
|
40
|
-
if (!IGNORED_KEYS.includes(path[path.length - 1]))
|
|
41
|
-
debouncedError(`A component is using the UI config ${path.join(".")}.
|
|
42
|
-
|
|
15
|
+
function ErrorWrapper(originalObject, path = "config") {
|
|
16
|
+
return new Proxy(originalObject || {}, {
|
|
17
|
+
get(_target, key) {
|
|
18
|
+
if (key === Symbol.toPrimitive) {
|
|
19
|
+
return () => _target[key];
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
const value = originalObject[key];
|
|
23
|
+
if (typeof value === "undefined" || typeof value === "object")
|
|
24
|
+
return ErrorWrapper(value, [path, key].filter(Boolean).join("."));
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
catch (e) {
|
|
28
|
+
const pathJson = path
|
|
29
|
+
.split(".")
|
|
30
|
+
.concat(key)
|
|
31
|
+
.reduce((result, key, idx, arr) => {
|
|
32
|
+
arr.slice(0, idx).reduce((r, k) => r[k], result)[key] = idx === arr.length - 1 ? `THE_MISSING_CONFIG` : {};
|
|
33
|
+
return result;
|
|
34
|
+
}, {});
|
|
35
|
+
throw new Error(`A component is using the UI config ${[path, key].join(".")}.
|
|
36
|
+
|
|
43
37
|
Please define it using:
|
|
44
38
|
import OneUIProvider from "@onepercent/one-ui/dist/context/OneUIProvider";
|
|
39
|
+
|
|
40
|
+
...
|
|
41
|
+
${`<OneUIProvider config={${JSON.stringify(pathJson, null, 4)}}>
|
|
45
42
|
...
|
|
46
|
-
|
|
47
|
-
...
|
|
48
|
-
</OneUIProvider>`);
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
debouncedError.cancel();
|
|
52
|
-
}
|
|
43
|
+
</OneUIProvider>`.replace(/[ ]/g, "-")}`);
|
|
53
44
|
}
|
|
54
|
-
if ((typeof value === "object" && !Array.isArray(value)) ||
|
|
55
|
-
(value === undefined && /[^A-Z]/.test(String(variable).charAt(0))))
|
|
56
|
-
return ProtectVariableAccess(value, [...basePath, variable.toString()]);
|
|
57
|
-
return value;
|
|
58
45
|
},
|
|
59
46
|
});
|
|
60
|
-
return proxyInstance;
|
|
61
47
|
}
|
|
62
|
-
exports.ProtectVariableAccess = ProtectVariableAccess;
|
|
63
48
|
function useOneUIContext() {
|
|
64
49
|
const context = (0, react_2.useContext)(Context);
|
|
65
|
-
if (process.env.NODE_ENV === "development")
|
|
66
|
-
return
|
|
67
|
-
}
|
|
50
|
+
if (process.env.NODE_ENV === "development")
|
|
51
|
+
return ErrorWrapper(context);
|
|
68
52
|
return context;
|
|
69
53
|
}
|
|
70
54
|
exports.useOneUIContext = useOneUIContext;
|
|
55
|
+
function useOneUIConfig(prop, defaultValue) {
|
|
56
|
+
const context = (0, react_2.useContext)(Context);
|
|
57
|
+
return ErrorWrapper((0, get_1.default)(context, prop) || defaultValue);
|
|
58
|
+
}
|
|
59
|
+
exports.useOneUIConfig = useOneUIConfig;
|
|
71
60
|
//# sourceMappingURL=OneUIProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OneUIProvider.js","sourceRoot":"","sources":["../../src/context/OneUIProvider.tsx"],"names":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"OneUIProvider.js","sourceRoot":"","sources":["../../src/context/OneUIProvider.tsx"],"names":[],"mappings":";;;;;;A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AAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,EAAE,CAAC;oBACvD,OAAO,MAAM,CAAC;gBAChB,CAAC,EAAE,EAAE,CAAC,CAAC;gBACT,MAAM,IAAI,KAAK,CACb,sCAAsC,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;;;;;;EAMnE,0BAA0B,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;;iBAE5C,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAC/B,CAAC;aACH;QACH,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAED,SAAgB,eAAe;IAC7B,MAAM,OAAO,GAAG,IAAA,kBAAU,EAAC,OAAO,CAAC,CAAC;IAEpC,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa;QACxC,OAAO,YAAY,CAAC,OAAO,CAA4B,CAAC;IAE1D,OAAO,OAAuB,CAAC;AACjC,CAAC;AAPD,0CAOC;AAED,SAAgB,cAAc,CAG5B,IAAO,EAAE,YAAgB;IACzB,MAAM,OAAO,GAAG,IAAA,kBAAU,EAAC,OAAO,CAAC,CAAC;IACpC,OAAO,YAAY,CAAC,IAAA,aAAG,EAAC,OAAO,EAAE,IAAI,CAAC,IAAI,YAAY,CAAmB,CAAC;AAC5E,CAAC;AAND,wCAMC"}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// object.watch
|
|
4
4
|
if (!Object.prototype.watch)
|
|
5
5
|
Object.prototype.watch = function (propsToWatchFor, handler) {
|
|
6
|
+
(this._handlers || (this._handlers = [])).push(handler);
|
|
6
7
|
propsToWatchFor.forEach((prop) => {
|
|
7
8
|
var oldval = this[prop], newval = oldval, getter = function () {
|
|
8
9
|
return newval;
|
|
@@ -10,7 +11,8 @@ if (!Object.prototype.watch)
|
|
|
10
11
|
if (this._watchTimer)
|
|
11
12
|
clearTimeout(this._watchTimer);
|
|
12
13
|
this._watchTimer = setTimeout(() => {
|
|
13
|
-
handler.
|
|
14
|
+
for (let handler of this._handlers)
|
|
15
|
+
handler.call();
|
|
14
16
|
clearTimeout(this._watchTimer);
|
|
15
17
|
delete this._watchTimer;
|
|
16
18
|
}, 0);
|
|
@@ -20,12 +22,13 @@ if (!Object.prototype.watch)
|
|
|
20
22
|
};
|
|
21
23
|
if (delete this[prop]) {
|
|
22
24
|
// can't watch constants
|
|
23
|
-
if (Object.defineProperty)
|
|
24
|
-
// ECMAScript 5
|
|
25
|
+
if (Object.defineProperty) {
|
|
26
|
+
// ECMAScript 5
|
|
25
27
|
Object.defineProperty(this, prop, {
|
|
26
28
|
get: getter,
|
|
27
29
|
set: setter,
|
|
28
30
|
});
|
|
31
|
+
}
|
|
29
32
|
else if (Object.prototype.__defineGetter__ &&
|
|
30
33
|
Object.prototype.__defineSetter__) {
|
|
31
34
|
// legacy
|
|
@@ -34,15 +37,9 @@ if (!Object.prototype.watch)
|
|
|
34
37
|
}
|
|
35
38
|
}
|
|
36
39
|
});
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
delete this[prop]; // remove accessors
|
|
40
|
-
this[prop] = val;
|
|
41
|
-
}
|
|
42
|
-
this.unwatch = function () {
|
|
43
|
-
propsToWatchFor.forEach((prop) => {
|
|
44
|
-
_unwatch(prop);
|
|
45
|
-
});
|
|
40
|
+
this.unwatch = () => {
|
|
41
|
+
this._handlers.splice(this._handlers.indexOf(handler), 1);
|
|
46
42
|
};
|
|
43
|
+
return this.unwatch;
|
|
47
44
|
};
|
|
48
45
|
//# sourceMappingURL=ObjectWatchShim.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ObjectWatchShim.js","sourceRoot":"","sources":["../../../src/hooks/shims/ObjectWatchShim.ts"],"names":[],"mappings":";AAAA,cAAc;AACd,eAAe;AACf,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK;IACzB,MAAM,CA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AY,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;oBAC/B,OAAO,IAAI,CAAC,WAAW,CAAC;gBAC1B,CAAC,EAAE,CAAC,CAAC,CAAC;gBACN,MAAM,GAAG,MAAM,CAAC;gBAChB,MAAM,GAAG,GAAG,CAAC;gBACb,OAAO,IAAI,CAAC;YACd,CAAC,CAAC;YACJ,IAAI,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE;gBACrB,wBAAwB;gBACxB,IAAI,MAAM,CAAC,cAAc,EAAE;oBACzB,yBAAyB;oBACzB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,IAAI,EAAE;wBAChC,GAAG,EAAE,MAAM;wBACX,GAAG,EAAE,MAAM;qBACZ,CAAC,CAAC;iBACJ;qBACI,IACH,MAAM,CAAC,SAAS,CAAC,gBAAgB;oBACjC,MAAM,CAAC,SAAS,CAAC,gBAAgB,EACjC;oBACA,SAAS;oBACT,MAAM,CAAC,SAAS,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;oBAC3D,MAAM,CAAC,SAAS,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;iBAC5D;aACF;QACH,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,OAAO,GAAG,GAAG,EAAE;YAClB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;QAC5D,CAAC,CAAC;QAEF,OAAO,IAAI,CAAC,OAAO,CAAA;IACrB,CAAC,CAAC"}
|
|
@@ -13,7 +13,7 @@ const react_1 = require("react");
|
|
|
13
13
|
function useAsyncControl() {
|
|
14
14
|
const [error, setError] = (0, react_1.useState)();
|
|
15
15
|
const [loading, setLoading] = (0, react_1.useState)(false);
|
|
16
|
-
const _process = (asyncFn) => __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
const _process = (0, react_1.useCallback)((asyncFn) => __awaiter(this, void 0, void 0, function* () {
|
|
17
17
|
try {
|
|
18
18
|
setLoading(true);
|
|
19
19
|
setError(undefined);
|
|
@@ -27,7 +27,7 @@ function useAsyncControl() {
|
|
|
27
27
|
finally {
|
|
28
28
|
setLoading(false);
|
|
29
29
|
}
|
|
30
|
-
});
|
|
30
|
+
}), []);
|
|
31
31
|
return {
|
|
32
32
|
process: _process,
|
|
33
33
|
loading,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAsyncControl.js","sourceRoot":"","sources":["../../src/hooks/useAsyncControl.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"useAsyncControl.js","sourceRoot":"","sources":["../../src/hooks/useAsyncControl.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,iCAA8C;AAG9C,SAAwB,eAAe;IACrC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,IAAA,gBAAQ,GAAK,CAAC;IACxC,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,IAAA,gBAAQ,EAAU,KAAK,CAAC,CAAC;IAEvD,MAAM,QAAQ,GAAG,IAAA,mBAAW,EAAC,CAAO,OAA2B,EAAE,EAAE;QACjE,IAAI;YACF,UAAU,CAAC,IAAI,CAAC,CAAC;YACjB,QAAQ,CAAC,SAAS,CAAC,CAAC;YACpB,MAAM,OAAO,EAAE,CAAC;SACjB;QAAC,OAAO,CAAC,EAAE;YACV,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa;gBAAE,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAC7D,QAAQ,CAAC,kBAAuB,CAAC,CAAC;SACnC;gBAAS;YACR,UAAU,CAAC,KAAK,CAAC,CAAC;SACnB;IACH,CAAC,CAAA,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO;QACL,OAAO,EAAE,QAAQ;QACjB,OAAO;QACP,KAAK;QACL,QAAQ;QACR,UAAU;KACX,CAAC;AACJ,CAAC;AAxBD,kCAwBC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BaseForm, FieldDefinition, FieldTypes } from "../components/Form/Form";
|
|
2
|
+
declare type Intermediary<F extends BaseForm> = {
|
|
3
|
+
form: F;
|
|
4
|
+
formValidation: {
|
|
5
|
+
[k in keyof F]: string;
|
|
6
|
+
} & {
|
|
7
|
+
isValid: string | true;
|
|
8
|
+
};
|
|
9
|
+
set: <K extends keyof F>(k: K, value: F[K]) => void;
|
|
10
|
+
};
|
|
11
|
+
export declare type FormControls<C extends FormConfig<any>> = Intermediary<C extends FormConfig<infer F> ? F : never>;
|
|
12
|
+
export declare type FormConfig<T extends BaseForm> = {
|
|
13
|
+
[k in keyof T]: FieldDefinition<T, k, FieldTypes>;
|
|
14
|
+
};
|
|
15
|
+
export default function useContextForm<T extends BaseForm>(config: FormConfig<T>, initialState: T): FormControls<FormConfig<T>>;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const react_1 = require("react");
|
|
4
|
+
function useContextForm(config, initialState) {
|
|
5
|
+
const [form, setForm] = (0, react_1.useState)(initialState);
|
|
6
|
+
const isValid = (0, react_1.useMemo)(() => !Object.keys(config).some((a) => typeof config[a].validator(form[a], form) === "string"), [form]);
|
|
7
|
+
const _setFormField = (key, value) => {
|
|
8
|
+
setForm(prev => (Object.assign(Object.assign({}, prev), { [key]: value })));
|
|
9
|
+
};
|
|
10
|
+
const validFormFields = (0, react_1.useMemo)(() => {
|
|
11
|
+
return Object.keys(config).reduce((result, field) => {
|
|
12
|
+
const fieldConfig = config[field];
|
|
13
|
+
const invalidMessage = fieldConfig.validator(form[field], form);
|
|
14
|
+
return Object.assign(Object.assign({}, result), { [field]: invalidMessage });
|
|
15
|
+
}, { isValid });
|
|
16
|
+
}, [form, isValid]);
|
|
17
|
+
return {
|
|
18
|
+
form: form,
|
|
19
|
+
formValidation: validFormFields,
|
|
20
|
+
set: _setFormField
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
exports.default = useContextForm;
|
|
24
|
+
//# sourceMappingURL=useForm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useForm.js","sourceRoot":"","sources":["../../src/hooks/useForm.ts"],"names":[],"mappings":";;AAAA,iCAAkD;AAYlD,SAAwB,cAAc,CAClC,MAAqB,EACrB,YAAe;IAEf,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,IAAA,gBAAQ,EAAa,YAAY,CAAC,CAAC;IAC3D,MAAM,OAAO,GAAG,IAAA,eAAO,EACnB,GAAG,EAAE,CACD,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CACrB,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,QAAQ,CAChE,EACL,CAAC,IAAI,CAAC,CACT,CAAC;IAEF,MAAM,aAAa,GAAmD,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;QACjF,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,iCACT,IAAI,KACP,CAAC,GAAG,CAAC,EAAE,KAAK,IACd,CAAC,CAAA;IACP,CAAC,CAAA;IAED,MAAM,eAAe,GAAG,IAAA,eAAO,EAAC,GAAG,EAAE;QACjC,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,KAAc,EAAE,EAAE;YACzD,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;YAClC,MAAM,cAAc,GAAG,WAAW,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,CAAC;YAChE,uCACO,MAAM,KACT,CAAC,KAAK,CAAC,EAAE,cAAc,IAC1B;QACL,CAAC,EAAE,EAAE,OAAO,EAA8D,CAAC,CAAA;IAC/E,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;IAEpB,OAAO;QACH,IAAI,EAAE,IAAI;QACV,cAAc,EAAE,eAAe;QAC/B,GAAG,EAAE,aAAa;KACd,CAAA;AACZ,CAAC;AApCD,iCAoCC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import "./shims/ObjectWatchShim.js";
|
|
2
|
-
export default function useObserve<T extends any>(
|
|
2
|
+
export default function useObserve<T extends any>(toObserve: T | T[], keysToObserve: (keyof T)[]): void;
|
package/dist/hooks/useObserve.js
CHANGED
|
@@ -2,13 +2,17 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const react_1 = require("react");
|
|
4
4
|
require("./shims/ObjectWatchShim.js");
|
|
5
|
-
function useObserve(
|
|
5
|
+
function useObserve(toObserve, keysToObserve) {
|
|
6
6
|
const [_, ss] = (0, react_1.useState)(0);
|
|
7
7
|
(0, react_1.useLayoutEffect)(() => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
const arr = Array.isArray(toObserve) ? toObserve : [toObserve];
|
|
9
|
+
for (let object of arr)
|
|
10
|
+
return object.watch(keysToObserve, () => {
|
|
11
|
+
ss((p) => {
|
|
12
|
+
return p + 1;
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
}, [toObserve]);
|
|
12
16
|
}
|
|
13
17
|
exports.default = useObserve;
|
|
14
18
|
//# sourceMappingURL=useObserve.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useObserve.js","sourceRoot":"","sources":["../../src/hooks/useObserve.ts"],"names":[],"mappings":";;AAAA,iCAA6D;AAC7D,sCAAoC;AAOpC,SAAwB,UAAU,CAChC,
|
|
1
|
+
{"version":3,"file":"useObserve.js","sourceRoot":"","sources":["../../src/hooks/useObserve.ts"],"names":[],"mappings":";;AAAA,iCAA6D;AAC7D,sCAAoC;AAOpC,SAAwB,UAAU,CAChC,SAAkB,EAClB,aAA0B;IAE1B,MAAM,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,IAAA,gBAAQ,EAAC,CAAC,CAAC,CAAC;IAC5B,IAAA,uBAAe,EAAC,GAAG,EAAE;QACnB,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;QAC9D,KAAK,IAAI,MAAM,IAAI,GAAG;YACpB,OAAQ,MAAiB,CAAC,KAAK,CAAC,aAAoB,EAAE,GAAG,EAAE;gBACzD,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE;oBACP,OAAO,CAAC,GAAG,CAAC,CAAA;gBACd,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;IACP,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;AAClB,CAAC;AAdD,6BAcC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
/**
|
|
3
|
+
* This hook adds a prop that you can toggle and returns to initial
|
|
4
|
+
* state after a defined time (usefull for notification)
|
|
5
|
+
*/
|
|
6
|
+
export default function useRebound<T extends any>(initialValue: T, timeoutSec?: number): {
|
|
7
|
+
current: T;
|
|
8
|
+
setState: import("react").Dispatch<import("react").SetStateAction<T>>;
|
|
9
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const react_1 = require("react");
|
|
4
|
+
/**
|
|
5
|
+
* This hook adds a prop that you can toggle and returns to initial
|
|
6
|
+
* state after a defined time (usefull for notification)
|
|
7
|
+
*/
|
|
8
|
+
function useRebound(initialValue, timeoutSec = 1) {
|
|
9
|
+
const [state, setState] = (0, react_1.useState)(initialValue);
|
|
10
|
+
(0, react_1.useEffect)(() => {
|
|
11
|
+
if (state !== initialValue) {
|
|
12
|
+
const timeout = setTimeout(() => {
|
|
13
|
+
setState(initialValue);
|
|
14
|
+
}, timeoutSec * 1000);
|
|
15
|
+
return () => clearTimeout(timeout);
|
|
16
|
+
}
|
|
17
|
+
}, [state]);
|
|
18
|
+
return {
|
|
19
|
+
current: state,
|
|
20
|
+
setState
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
exports.default = useRebound;
|
|
24
|
+
//# sourceMappingURL=useRebound.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRebound.js","sourceRoot":"","sources":["../../src/hooks/useRebound.ts"],"names":[],"mappings":";;AAAA,iCAA2C;AAE3C;;;GAGG;AACH,SAAwB,UAAU,CAAgB,YAAe,EAAE,aAAqB,CAAC;IACrF,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,IAAA,gBAAQ,EAAI,YAAY,CAAC,CAAA;IAEnD,IAAA,iBAAS,EAAC,GAAG,EAAE;QACX,IAAI,KAAK,KAAK,YAAY,EAAE;YACxB,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE;gBAC5B,QAAQ,CAAC,YAAY,CAAC,CAAA;YAC1B,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC,CAAC;YAEtB,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;SACtC;IACL,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IACZ,OAAO;QACH,OAAO,EAAE,KAAK;QACd,QAAQ;KACX,CAAA;AACL,CAAC;AAhBD,6BAgBC"}
|
|
@@ -2,6 +2,7 @@ import { IntlFormatters, IntlShape } from "react-intl";
|
|
|
2
2
|
import { BigNumber } from "bignumber.js";
|
|
3
3
|
export default function useShortIntl(): IntlShape & {
|
|
4
4
|
txt: (id: OnepercentUtility.IntlIds, params?: Parameters<IntlFormatters["formatMessage"]>[1]) => ReturnType<IntlFormatters["formatMessage"]>;
|
|
5
|
+
formatToDoubleDecimal(number: number, options?: Parameters<IntlFormatters["formatNumber"]>[1]): string;
|
|
5
6
|
formatBigNumber(number: BigNumber, options?: Parameters<IntlFormatters["formatNumber"]>[1]): string;
|
|
6
7
|
};
|
|
7
8
|
declare type StrMap = {
|
|
@@ -4,10 +4,13 @@ exports.isolateMessages = void 0;
|
|
|
4
4
|
const react_intl_1 = require("react-intl");
|
|
5
5
|
function useShortIntl() {
|
|
6
6
|
const intl = (0, react_intl_1.useIntl)();
|
|
7
|
-
const { formatMessage } = intl;
|
|
7
|
+
const { formatMessage, formatNumber } = intl;
|
|
8
8
|
return Object.assign(Object.assign({}, intl), { txt: (id, params) => {
|
|
9
9
|
return formatMessage({ id }, params);
|
|
10
|
-
},
|
|
10
|
+
}, formatToDoubleDecimal(val, options = {}) {
|
|
11
|
+
return formatNumber(val, Object.assign({ minimumFractionDigits: 2, maximumFractionDigits: 2 }, options));
|
|
12
|
+
},
|
|
13
|
+
formatBigNumber(bigNumber, options) {
|
|
11
14
|
const { decimalSeparator } = intl
|
|
12
15
|
.formatNumberToParts(1000.1)
|
|
13
16
|
.reduce((r, a) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useShortIntl.js","sourceRoot":"","sources":["../../src/hooks/useShortIntl.ts"],"names":[],"mappings":";;;AAAA,2CAAgE;AAGhE,SAAwB,YAAY;
|
|
1
|
+
{"version":3,"file":"useShortIntl.js","sourceRoot":"","sources":["../../src/hooks/useShortIntl.ts"],"names":[],"mappings":";;;AAAA,2CAAgE;AAGhE,SAAwB,YAAY;IAWlC,MAAM,IAAI,GAAG,IAAA,oBAAO,GAAE,CAAC;IACvB,MAAM,EAAE,aAAa,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC;IAC7C,uCACK,IAAI,KACP,GAAG,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE;YAClB,OAA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CAAC;QACP,CAAC,IACD;AACJ,CAAC;AAhDD,+BAgDC;AAUD,SAAgB,eAAe,CAC7B,OAAU,EACV,OAAU;IAEV,OAAO,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,CACnC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,iCACV,CAAC,KACJ,CAAC,GAAG,OAAO,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,IACtB,EACF,EAA4C,CAC7C,CAAC;AACJ,CAAC;AAXD,0CAWC"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onepercentio/one-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "A set of reusable components created through the development of Onepercent projects",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
7
7
|
"WebpackConfigs",
|
|
8
8
|
"cypress/support"
|
|
9
9
|
],
|
|
10
|
+
"bin": {
|
|
11
|
+
"start-emulator": "scripts/start-emulator.js"
|
|
12
|
+
},
|
|
10
13
|
"repository": "git@github.com:onepercentio/one-ui.git",
|
|
11
14
|
"author": "Murilo Oliveira de Araujo <muritavo@outlook.com>",
|
|
12
15
|
"license": "MIT",
|
|
@@ -15,6 +18,7 @@
|
|
|
15
18
|
"@babel/core": "^7.16.0",
|
|
16
19
|
"@cypress/react": "^5.12.5",
|
|
17
20
|
"@firebase/rules-unit-testing": "^2.0.2",
|
|
21
|
+
"@muritavo/cypress-toolkit": "^0.0.3",
|
|
18
22
|
"@muritavo/webpack-microfrontend-scripts": "^0.0.16",
|
|
19
23
|
"@storybook/addon-actions": "^6.4.18",
|
|
20
24
|
"@storybook/addon-essentials": "^6.4.18",
|
|
@@ -36,12 +40,13 @@
|
|
|
36
40
|
"cpy-cli": "^3.1.1",
|
|
37
41
|
"crypto-browserify": "^3.12.0",
|
|
38
42
|
"css-loader": "^5",
|
|
39
|
-
"cypress": "^
|
|
43
|
+
"cypress": "^10.2.0",
|
|
40
44
|
"firebase": "^9.8.1",
|
|
41
45
|
"firebase-admin": "^10.2.0",
|
|
42
46
|
"https-browserify": "^1.0.0",
|
|
43
47
|
"inquirer": "^8.2.4",
|
|
44
48
|
"jest": "^27.3.1",
|
|
49
|
+
"node-fetch": "^2",
|
|
45
50
|
"node-sass": "^6.0.1",
|
|
46
51
|
"os-browserify": "^0.3.0",
|
|
47
52
|
"react": "^18.0.0",
|
|
@@ -54,9 +59,10 @@
|
|
|
54
59
|
"stream-http": "^3.2.0",
|
|
55
60
|
"style-loader": "^2",
|
|
56
61
|
"ts-jest": "^27.0.7",
|
|
62
|
+
"type-fest": "^2.13.1",
|
|
57
63
|
"typescript": "^4.5.2",
|
|
58
|
-
"
|
|
59
|
-
"
|
|
64
|
+
"url": "^0.11.0",
|
|
65
|
+
"use-wallet": "0.13.5"
|
|
60
66
|
},
|
|
61
67
|
"dependencies": {
|
|
62
68
|
"@types/chroma-js": "^2.1.3",
|
|
@@ -83,11 +89,24 @@
|
|
|
83
89
|
"postbuild": "cd ..",
|
|
84
90
|
"dev": "tsc --watch",
|
|
85
91
|
"test:watch": "jest --watchAll --coverage",
|
|
86
|
-
"deploy:storybook": "yarn build-storybook
|
|
92
|
+
"deploy:storybook": "yarn build-storybook && firebase deploy --only hosting",
|
|
93
|
+
"test:e2e:watch": "cypress open --component",
|
|
87
94
|
"prepublish": "yarn build"
|
|
88
95
|
},
|
|
96
|
+
"browserslist": {
|
|
97
|
+
"production": [
|
|
98
|
+
">0.2%",
|
|
99
|
+
"not dead",
|
|
100
|
+
"not op_mini all"
|
|
101
|
+
],
|
|
102
|
+
"development": [
|
|
103
|
+
"last 1 chrome version",
|
|
104
|
+
"last 1 firefox version",
|
|
105
|
+
"last 1 safari version"
|
|
106
|
+
]
|
|
107
|
+
},
|
|
89
108
|
"peerDependencies": {
|
|
90
109
|
"chroma-js": "^2.4.2",
|
|
91
110
|
"use-wallet": "0.13.5"
|
|
92
111
|
}
|
|
93
|
-
}
|
|
112
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fetch = require("node-fetch");
|
|
4
|
+
const { spawn } = require("child_process");
|
|
5
|
+
function WaitTimeout(ml = 200) {
|
|
6
|
+
return new Promise((r) => {
|
|
7
|
+
setTimeout(() => {
|
|
8
|
+
r();
|
|
9
|
+
}, ml);
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
const [, , projectId, databaseToImport] = process.argv;
|
|
13
|
+
|
|
14
|
+
if (!projectId) {
|
|
15
|
+
console.error("You need to provide a project id");
|
|
16
|
+
process.exit(1);
|
|
17
|
+
}
|
|
18
|
+
spawn(
|
|
19
|
+
`firebase emulators:start -P ${projectId} ${
|
|
20
|
+
databaseToImport ? `--import ${databaseToImport}` : ""
|
|
21
|
+
}`,
|
|
22
|
+
{
|
|
23
|
+
cwd: undefined,
|
|
24
|
+
env: process.env,
|
|
25
|
+
shell: true,
|
|
26
|
+
detached: true,
|
|
27
|
+
}
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
(async function () {
|
|
31
|
+
let breakLoop = false;
|
|
32
|
+
const timeout = setTimeout(() => {
|
|
33
|
+
breakLoop = true;
|
|
34
|
+
console.error("Could not receive ok from firebase emulator");
|
|
35
|
+
clearTimeout(timeout);
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}, 60000);
|
|
38
|
+
while (!breakLoop) {
|
|
39
|
+
try {
|
|
40
|
+
await fetch(`http://localhost:4000`);
|
|
41
|
+
console.log("Emulator restarted");
|
|
42
|
+
clearTimeout(timeout);
|
|
43
|
+
process.exit(0);
|
|
44
|
+
} catch (e) {}
|
|
45
|
+
await WaitTimeout(1000);
|
|
46
|
+
}
|
|
47
|
+
await new Promise((r) => {});
|
|
48
|
+
})();
|