@dilicorp/ui 0.2.52 → 1.1.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/dist/components/form-builder/components/input-percentage.d.ts +13 -0
- package/dist/components/form-builder/components/input-percentage.js +22 -0
- package/dist/components/form-builder/components/input.d.ts +2 -1
- package/dist/components/form-builder/components/input.js +6 -2
- package/dist/molecules/alert.d.ts +2 -0
- package/dist/molecules/alert.js +5 -2
- package/dist/molecules/modal/modal.js +1 -1
- package/dist/utils/number-helper.d.ts +1 -0
- package/dist/utils/number-helper.js +11 -0
- package/package.json +1 -1
- package/dist/atoms/panel/panel-container.d.ts +0 -10
- package/dist/atoms/panel/panel-container.js +0 -6
- package/dist/atoms/panel/panel-field.d.ts +0 -12
- package/dist/atoms/panel/panel-field.js +0 -10
- package/dist/atoms/panel/panel-group.d.ts +0 -14
- package/dist/atoms/panel/panel-group.js +0 -9
- package/dist/atoms/panel/panel.d.ts +0 -29
- package/dist/atoms/panel/panel.js +0 -8
- package/dist/components/modal/modal.d.ts +0 -11
- package/dist/components/modal/modal.js +0 -15
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
declare type Props = {
|
|
3
|
+
name: string;
|
|
4
|
+
attrs: {
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
};
|
|
7
|
+
handleChange: (params: any) => void;
|
|
8
|
+
max?: number | string;
|
|
9
|
+
decimals?: number;
|
|
10
|
+
};
|
|
11
|
+
export declare const InputPercentage: ({ attrs, handleChange, max, decimals, name }: Props) => JSX.Element;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=input-percentage.d.ts.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { FastField, Field } from 'formik';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import numberHelper from '../../../utils/number-helper';
|
|
4
|
+
export const InputPercentage = ({ attrs, handleChange, max = 100, decimals = 2, name }) => {
|
|
5
|
+
const { maxLength = 8 } = attrs;
|
|
6
|
+
const handleChangePercentage = (event) => {
|
|
7
|
+
const { value } = event.currentTarget;
|
|
8
|
+
const percentage = numberHelper.percentageSanitize(value, decimals);
|
|
9
|
+
if (typeof max === 'number' && max < Number(percentage)) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
handleChange({
|
|
13
|
+
currentTarget: {
|
|
14
|
+
name,
|
|
15
|
+
value: percentage ? `${percentage}%` : ''
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
const { fastField = true, ...restAttrs } = attrs;
|
|
20
|
+
const Tag = fastField ? FastField : Field;
|
|
21
|
+
return (React.createElement(Tag, { name: name }, ({ field }) => (React.createElement("input", { ...field, max: max, ...restAttrs, onChange: handleChangePercentage, min: "0", maxLength: maxLength }))));
|
|
22
|
+
};
|
|
@@ -3,7 +3,7 @@ import { FormikProps } from 'formik';
|
|
|
3
3
|
import { FormBuilderBasicsItem } from '../form-builder.types';
|
|
4
4
|
export interface FormBuildItemInput extends Omit<FormBuilderBasicsItem, 'prefix'> {
|
|
5
5
|
component?: 'input';
|
|
6
|
-
type?: 'text' | 'button' | 'checkbox' | 'email' | 'file' | 'hidden' | 'number' | 'submit' | 'reset' | 'color';
|
|
6
|
+
type?: 'text' | 'button' | 'checkbox' | 'email' | 'file' | 'hidden' | 'number' | 'submit' | 'reset' | 'color' | 'percentage';
|
|
7
7
|
mask?: string | Array<string | RegExp>;
|
|
8
8
|
multiple?: boolean;
|
|
9
9
|
currency?: {
|
|
@@ -13,6 +13,7 @@ export interface FormBuildItemInput extends Omit<FormBuilderBasicsItem, 'prefix'
|
|
|
13
13
|
suffix?: string | React.ReactNode;
|
|
14
14
|
prefix?: string | React.ReactNode;
|
|
15
15
|
fastField?: boolean;
|
|
16
|
+
decimals?: number;
|
|
16
17
|
}
|
|
17
18
|
declare type Props = Omit<FormBuildItemInput, 'component'> & {
|
|
18
19
|
actions: FormikProps<any>;
|
|
@@ -4,8 +4,9 @@ import classNames from 'classnames';
|
|
|
4
4
|
import { InputCurrency } from './input-currency';
|
|
5
5
|
import { InputMask } from './input-mask';
|
|
6
6
|
import { InputPrefixSuffix } from './input-prefix-suffix';
|
|
7
|
+
import { InputPercentage } from './input-percentage';
|
|
7
8
|
export default function Input(props) {
|
|
8
|
-
const { name, id = name, type = 'text', tabIndex = 0, actions, mask, multiple = false, currency, className, prefix, suffix, fastField = true, ...elements } = props;
|
|
9
|
+
const { name, id = name, type = 'text', tabIndex = 0, actions, mask, multiple = false, currency, className, prefix, suffix, fastField = true, decimals = 2, ...elements } = props;
|
|
9
10
|
const validOptions = {
|
|
10
11
|
alt: elements.alt,
|
|
11
12
|
autoComplete: elements.autoComplete,
|
|
@@ -71,12 +72,15 @@ export default function Input(props) {
|
|
|
71
72
|
...attrsInput,
|
|
72
73
|
fastField
|
|
73
74
|
};
|
|
75
|
+
if (type === 'percentage') {
|
|
76
|
+
return React.createElement(InputPercentage, { ...{ name, attrs, currency, handleChange, decimals, max: elements.max } });
|
|
77
|
+
}
|
|
74
78
|
if (currency)
|
|
75
79
|
return React.createElement(InputCurrency, { ...{ name, attrs, currency, handleChange } });
|
|
76
80
|
if (mask)
|
|
77
81
|
return React.createElement(InputMask, { ...{ name, attrs, mask } });
|
|
78
82
|
if (prefix || suffix)
|
|
79
|
-
return React.createElement(InputPrefixSuffix, { ...{ attrs, suffix, prefix } });
|
|
83
|
+
return React.createElement(InputPrefixSuffix, { ...{ attrs, suffix, prefix, handleChange } });
|
|
80
84
|
const Tag = fastField ? FastField : Field;
|
|
81
85
|
return (React.createElement(Tag, { ...attrsInput, as: multiple ? 'textarea' : 'input', readOnly: true, onFocus: (event) => {
|
|
82
86
|
event.currentTarget.readOnly = false;
|
|
@@ -7,10 +7,12 @@ export declare type AlertProps = {
|
|
|
7
7
|
color?: 'default' | 'success' | 'info' | 'warning' | 'error';
|
|
8
8
|
showButton?: boolean;
|
|
9
9
|
buttonText?: string;
|
|
10
|
+
onClose?: () => void;
|
|
10
11
|
} & React.HTMLAttributes<HTMLDivElement>;
|
|
11
12
|
export declare const Alert: React.ForwardRefExoticComponent<{
|
|
12
13
|
color?: "success" | "info" | "warning" | "default" | "error" | undefined;
|
|
13
14
|
showButton?: boolean | undefined;
|
|
14
15
|
buttonText?: string | undefined;
|
|
16
|
+
onClose?: (() => void) | undefined;
|
|
15
17
|
} & React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<AlertRef>>;
|
|
16
18
|
//# sourceMappingURL=alert.d.ts.map
|
package/dist/molecules/alert.js
CHANGED
|
@@ -3,10 +3,13 @@ import ReactDOM from 'react-dom';
|
|
|
3
3
|
import classNames from 'classnames';
|
|
4
4
|
import { Button } from '../atoms/button';
|
|
5
5
|
export const Alert = forwardRef((props, ref) => {
|
|
6
|
-
const { children, className, showButton, buttonText = 'Ok', color } = props;
|
|
6
|
+
const { children, className, showButton, buttonText = 'Ok', color, onClose } = props;
|
|
7
7
|
const [display, setDisplay] = useState(false);
|
|
8
8
|
const open = () => setDisplay(true);
|
|
9
|
-
const close = () =>
|
|
9
|
+
const close = () => {
|
|
10
|
+
setDisplay(false);
|
|
11
|
+
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
12
|
+
};
|
|
10
13
|
useImperativeHandle(ref, () => ({
|
|
11
14
|
open: () => open(),
|
|
12
15
|
close: () => close()
|
|
@@ -5,7 +5,7 @@ import classNames from 'classnames';
|
|
|
5
5
|
export const Modal = forwardRef((props, ref) => {
|
|
6
6
|
const { children, title, closeFn, className, innerRef } = props;
|
|
7
7
|
const classes = classNames(className !== null && className !== void 0 ? className : 'alert-small');
|
|
8
|
-
return (React.createElement(Alert, { ref: ref !== null && ref !== void 0 ? ref : innerRef, className: classes },
|
|
8
|
+
return (React.createElement(Alert, { ref: ref !== null && ref !== void 0 ? ref : innerRef, className: classes, onClose: closeFn },
|
|
9
9
|
React.createElement("div", { className: "modal modal-sm" },
|
|
10
10
|
React.createElement("div", { className: "modal-header" },
|
|
11
11
|
React.createElement("div", { className: "title" }, title),
|
|
@@ -3,6 +3,7 @@ declare class NumberHelper {
|
|
|
3
3
|
sanitize(string: string): string;
|
|
4
4
|
currency(value?: number, locale?: string, format?: string): string;
|
|
5
5
|
currencySanitize(value: string): string | null;
|
|
6
|
+
percentageSanitize(value: string, decimals?: number): string | null;
|
|
6
7
|
}
|
|
7
8
|
declare const _default: NumberHelper;
|
|
8
9
|
export default _default;
|
|
@@ -21,5 +21,16 @@ class NumberHelper {
|
|
|
21
21
|
return `${integer}.0${decimal}`;
|
|
22
22
|
return `${integer}.${decimal}`;
|
|
23
23
|
}
|
|
24
|
+
percentageSanitize(value, decimals = 2) {
|
|
25
|
+
var _a;
|
|
26
|
+
const sanitize = (Number(this.sanitize(value))).toString();
|
|
27
|
+
const integer = (_a = sanitize.slice(0, -decimals)) !== null && _a !== void 0 ? _a : 0;
|
|
28
|
+
const decimal = sanitize.slice(-decimals);
|
|
29
|
+
if (value.replace(/\D/g, '') === '00' || sanitize === '')
|
|
30
|
+
return null;
|
|
31
|
+
if (decimal.length === 1)
|
|
32
|
+
return `${integer}.0${decimal}`;
|
|
33
|
+
return `${integer}.${decimal}`;
|
|
34
|
+
}
|
|
24
35
|
}
|
|
25
36
|
export default new NumberHelper();
|
package/package.json
CHANGED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
declare type PanelContainerProps = {
|
|
3
|
-
children: React.ReactNode;
|
|
4
|
-
};
|
|
5
|
-
export declare const PanelContainer: {
|
|
6
|
-
({ children }: PanelContainerProps): JSX.Element;
|
|
7
|
-
displayName: string;
|
|
8
|
-
};
|
|
9
|
-
export {};
|
|
10
|
-
//# sourceMappingURL=panel-container.d.ts.map
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
declare type PanelFieldProps = {
|
|
3
|
-
label: string;
|
|
4
|
-
value?: React.ReactNode;
|
|
5
|
-
forceShow?: boolean;
|
|
6
|
-
};
|
|
7
|
-
export declare const PanelField: {
|
|
8
|
-
({ label, value, forceShow }: PanelFieldProps): JSX.Element | null;
|
|
9
|
-
displayName: string;
|
|
10
|
-
};
|
|
11
|
-
export {};
|
|
12
|
-
//# sourceMappingURL=panel-field.d.ts.map
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
export const PanelField = ({ label, value, forceShow = true }) => {
|
|
3
|
-
if (!forceShow && !value)
|
|
4
|
-
return null;
|
|
5
|
-
return (React.createElement("div", { className: "panel-field" },
|
|
6
|
-
label,
|
|
7
|
-
": ",
|
|
8
|
-
React.createElement("strong", null, value)));
|
|
9
|
-
};
|
|
10
|
-
PanelField.displayName = 'PanelField';
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { ColProps } from '../col';
|
|
3
|
-
declare type Props = {
|
|
4
|
-
label?: string;
|
|
5
|
-
value?: React.ReactNode | string;
|
|
6
|
-
big?: boolean;
|
|
7
|
-
upper?: boolean;
|
|
8
|
-
} & ColProps;
|
|
9
|
-
export declare const PanelGroup: {
|
|
10
|
-
({ value, label, size, big, upper }: Props): JSX.Element;
|
|
11
|
-
displayName: string;
|
|
12
|
-
};
|
|
13
|
-
export {};
|
|
14
|
-
//# sourceMappingURL=panel-group.d.ts.map
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Col } from '../col';
|
|
3
|
-
export const PanelGroup = ({ value, label, size = [12, 6], big = false, upper = true }) => {
|
|
4
|
-
return (React.createElement(Col, { size: size },
|
|
5
|
-
React.createElement("div", { className: "panel-group" },
|
|
6
|
-
React.createElement("label", null, label),
|
|
7
|
-
React.createElement("div", { className: `${upper ? ' upper' : ''} text${big ? ' big' : ''}` }, value || '-'))));
|
|
8
|
-
};
|
|
9
|
-
PanelGroup.displayName = 'PanelGroup';
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
export declare const Panel: {
|
|
3
|
-
Container: {
|
|
4
|
-
({ children }: {
|
|
5
|
-
children: import("react").ReactNode;
|
|
6
|
-
}): JSX.Element;
|
|
7
|
-
displayName: string;
|
|
8
|
-
};
|
|
9
|
-
Group: {
|
|
10
|
-
({ value, label, size, big, upper }: {
|
|
11
|
-
label?: string | undefined;
|
|
12
|
-
value?: import("react").ReactNode;
|
|
13
|
-
big?: boolean | undefined;
|
|
14
|
-
upper?: boolean | undefined;
|
|
15
|
-
} & {
|
|
16
|
-
size?: boolean | ("none" | 1 | 2 | 3 | 4 | 5 | "auto" | 6 | 7 | 8 | 9 | 10 | 11 | 12) | ("none" | 1 | 2 | 3 | 4 | 5 | "auto" | 6 | 7 | 8 | 9 | 10 | 11 | 12)[] | undefined;
|
|
17
|
-
} & import("react").HTMLAttributes<HTMLDivElement>): JSX.Element;
|
|
18
|
-
displayName: string;
|
|
19
|
-
};
|
|
20
|
-
Field: {
|
|
21
|
-
({ label, value, forceShow }: {
|
|
22
|
-
label: string;
|
|
23
|
-
value?: import("react").ReactNode;
|
|
24
|
-
forceShow?: boolean | undefined;
|
|
25
|
-
}): JSX.Element | null;
|
|
26
|
-
displayName: string;
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
//# sourceMappingURL=panel.d.ts.map
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { AlertRef } from '../../molecules/alert';
|
|
3
|
-
export declare type ModalProps = {
|
|
4
|
-
children: React.ReactNode;
|
|
5
|
-
title?: string;
|
|
6
|
-
closeFn?: () => void;
|
|
7
|
-
className?: string;
|
|
8
|
-
innerRef?: React.ForwardedRef<AlertRef>;
|
|
9
|
-
};
|
|
10
|
-
export declare const Modal: React.ForwardRefExoticComponent<ModalProps & React.RefAttributes<AlertRef>>;
|
|
11
|
-
//# sourceMappingURL=modal.d.ts.map
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import React, { forwardRef } from 'react';
|
|
2
|
-
import { Button } from '../../atoms/button';
|
|
3
|
-
import { Alert } from '../../molecules/alert';
|
|
4
|
-
import classNames from 'classnames';
|
|
5
|
-
export const Modal = forwardRef((props, ref) => {
|
|
6
|
-
const { children, title, closeFn, className, innerRef } = props;
|
|
7
|
-
const classes = classNames(className !== null && className !== void 0 ? className : 'alert-small');
|
|
8
|
-
return (React.createElement(Alert, { ref: ref !== null && ref !== void 0 ? ref : innerRef, className: classes },
|
|
9
|
-
React.createElement("div", { className: "modal modal-sm" },
|
|
10
|
-
React.createElement("div", { className: "modal-header" },
|
|
11
|
-
React.createElement("div", { className: "title" }, title),
|
|
12
|
-
React.createElement(Button, { small: true, onClick: closeFn }, "\u00D7")),
|
|
13
|
-
React.createElement("div", { className: "modal-body" }, children))));
|
|
14
|
-
});
|
|
15
|
-
Modal.displayName = 'Modal';
|