@autobusal/common 1.0.6 → 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/Notifications/Icon.tsx +37 -0
- package/Notifications/utilities.ts +16 -0
- package/Viewer/Data.tsx +1 -1
- package/Viewer/Items/TextareaHtml.tsx +1 -0
- package/Viewer/Loading.tsx +14 -0
- package/Viewer/Viewer.tsx +7 -1
- package/index.ts +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { IoAlertSharp, IoBusSharp, IoChatboxOutline, IoCheckmarkOutline, IoCloseSharp, IoWarningOutline } from 'react-icons/io5';
|
|
2
|
+
import { ICONS } from './utilities';
|
|
3
|
+
|
|
4
|
+
interface Props {
|
|
5
|
+
type: string
|
|
6
|
+
size?: number
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const Icon = ({ type, size }: Props): (JSX.Element | undefined) => {
|
|
10
|
+
if (!ICONS.includes(type)) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
switch (type) {
|
|
15
|
+
case 'warning':
|
|
16
|
+
return <IoWarningOutline size={ size } />;
|
|
17
|
+
|
|
18
|
+
case 'error':
|
|
19
|
+
return <IoCloseSharp size={ size } />;
|
|
20
|
+
|
|
21
|
+
case 'success':
|
|
22
|
+
return <IoCheckmarkOutline size={ size } />;
|
|
23
|
+
|
|
24
|
+
case 'alert':
|
|
25
|
+
return <IoAlertSharp size={ size } />;
|
|
26
|
+
|
|
27
|
+
case 'bus':
|
|
28
|
+
return <IoBusSharp size={ size } />;
|
|
29
|
+
|
|
30
|
+
case 'message':
|
|
31
|
+
return <IoChatboxOutline size={ size } />;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return <></>;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export default Icon;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export const ICONS = [
|
|
2
|
+
'warning', 'error', 'success', 'alert', 'bus', 'message'
|
|
3
|
+
];
|
|
4
|
+
|
|
5
|
+
export const getBackgroundColor = (type?: string): (string | undefined) => {
|
|
6
|
+
switch (type) {
|
|
7
|
+
case 'warning':
|
|
8
|
+
return '#FF9C5A';
|
|
9
|
+
|
|
10
|
+
case 'error':
|
|
11
|
+
return '#FF6B5A';
|
|
12
|
+
|
|
13
|
+
case 'success':
|
|
14
|
+
return '#6CF96B';
|
|
15
|
+
}
|
|
16
|
+
};
|
package/Viewer/Data.tsx
CHANGED
|
@@ -32,7 +32,7 @@ const Data = ({ id, item, refs, t, onUpdate }: Props): (JSX.Element | null) => {
|
|
|
32
32
|
|
|
33
33
|
switch (item.type) {
|
|
34
34
|
case 'checkbox':
|
|
35
|
-
return <input type="checkbox" value={ 1 } defaultChecked={ Number(item.value)
|
|
35
|
+
return <input type="checkbox" value={ 1 } defaultChecked={ Number(item.value) === 1 } { ...refs(item.name, Validate(String(item.rules), t)) } />;
|
|
36
36
|
|
|
37
37
|
case 'checkbox-list':
|
|
38
38
|
case 'checkbox-list-all':
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { TFunction } from 'i18next';
|
|
2
|
+
import { Inline } from '../Loading/Loading';
|
|
3
|
+
|
|
4
|
+
interface Props {
|
|
5
|
+
t: TFunction<'common'>
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const Loading = ({ t }: Props): JSX.Element => (
|
|
9
|
+
<div className="box">
|
|
10
|
+
<Inline text={ t('table.loading_data', { ns: 'common' }) } />
|
|
11
|
+
</div>
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
export default Loading;
|
package/Viewer/Viewer.tsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useForm } from 'react-hook-form';
|
|
2
2
|
import { TFunction } from 'i18next';
|
|
3
|
+
import Loading from './Loading';
|
|
3
4
|
import Item from './Item';
|
|
4
5
|
import Actions from './Actions';
|
|
5
6
|
import { Container } from './styles';
|
|
@@ -9,6 +10,7 @@ interface Props {
|
|
|
9
10
|
id: number
|
|
10
11
|
type?: 'simple'
|
|
11
12
|
data: ViewData[]
|
|
13
|
+
fetching?: boolean
|
|
12
14
|
pending?: boolean
|
|
13
15
|
actions?: string[]
|
|
14
16
|
t: TFunction<'common'>
|
|
@@ -16,8 +18,12 @@ interface Props {
|
|
|
16
18
|
onDelete?: (data?: any) => void
|
|
17
19
|
}
|
|
18
20
|
|
|
19
|
-
const Viewer = ({ id, type, data, pending, actions, t, onSave, onDelete }: Props): JSX.Element => {
|
|
21
|
+
const Viewer = ({ id, type, data, fetching, pending, actions, t, onSave, onDelete }: Props): JSX.Element => {
|
|
20
22
|
const { register, handleSubmit, formState: { errors }, setValue } = useForm<any>();
|
|
23
|
+
|
|
24
|
+
if (fetching) {
|
|
25
|
+
return <Loading t={ t } />;
|
|
26
|
+
}
|
|
21
27
|
|
|
22
28
|
const items = data.map((item, index) => (
|
|
23
29
|
<Item
|
package/index.ts
CHANGED
|
@@ -17,6 +17,7 @@ import { General, Inline, Box, BoxMiddle, GeneralFull } from './Loading/Loading'
|
|
|
17
17
|
import IpLogs from './IpLogs/IpLogs';
|
|
18
18
|
import Meta from './Meta';
|
|
19
19
|
import Modal from './Modal/Modal';
|
|
20
|
+
import NotificationIcon from './Notifications/Icon';
|
|
20
21
|
import Pagination from './Pagination/Pagination';
|
|
21
22
|
import Paragraph from './Loading/Paragraph';
|
|
22
23
|
import Passengers from './Passengers/Passengers';
|
|
@@ -53,6 +54,7 @@ export {
|
|
|
53
54
|
IpLogs,
|
|
54
55
|
Meta,
|
|
55
56
|
Modal,
|
|
57
|
+
NotificationIcon,
|
|
56
58
|
Pagination,
|
|
57
59
|
Paragraph,
|
|
58
60
|
Passengers,
|