react-admin-base-bootstrap 0.8.4 → 0.8.5
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/lib/esm/Components/BootstrapModal.d.ts +2 -0
- package/lib/esm/Components/BootstrapModal.js +7 -0
- package/lib/esm/Components/BootstrapOptions.d.ts +11 -0
- package/lib/esm/Components/BootstrapOptions.js +11 -0
- package/lib/esm/Components/CRUD.js +4 -3
- package/lib/esm/Components/FilePickerCore.js +3 -2
- package/lib/esm/Components/GoToTop.js +1 -1
- package/lib/esm/index.d.ts +3 -1
- package/lib/esm/index.js +3 -1
- package/package.json +1 -1
- package/src/Components/BootstrapModal.tsx +9 -0
- package/src/Components/BootstrapOptions.tsx +25 -0
- package/src/Components/CRUD.tsx +7 -3
- package/src/Components/EntityEditor.tsx +0 -1
- package/src/Components/FilePickerCore.tsx +3 -2
- package/src/Components/GoToTop.tsx +1 -2
- package/src/Components/ThemeProvider.tsx +1 -1
- package/src/index.ts +6 -1
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Modal } from "reactstrap";
|
|
3
|
+
import { useBootstrapOptions } from "./BootstrapOptions";
|
|
4
|
+
export default function BootstrapModal(props) {
|
|
5
|
+
const bsOptions = useBootstrapOptions();
|
|
6
|
+
return React.createElement(Modal, Object.assign({}, props, { toggle: bsOptions.noCloseModal ? undefined : props.toggle }));
|
|
7
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
import BootstrapOptions from "./BootstrapOptions";
|
|
3
|
+
interface BootstrapOptions {
|
|
4
|
+
noCloseModal: boolean;
|
|
5
|
+
}
|
|
6
|
+
interface BootstrapOptionsProviderProps extends BootstrapOptions {
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
}
|
|
9
|
+
export declare function useBootstrapOptions(): BootstrapOptions;
|
|
10
|
+
export default function BootstrapOptionsProvider({ children, noCloseModal }: BootstrapOptionsProviderProps): JSX.Element;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React, { createContext, useContext, useMemo } from "react";
|
|
2
|
+
const BootstrapOptionsContext = createContext({
|
|
3
|
+
noCloseModal: false
|
|
4
|
+
});
|
|
5
|
+
export function useBootstrapOptions() {
|
|
6
|
+
return useContext(BootstrapOptionsContext);
|
|
7
|
+
}
|
|
8
|
+
export default function BootstrapOptionsProvider({ children, noCloseModal }) {
|
|
9
|
+
const options = useMemo(() => ({ noCloseModal }), [noCloseModal]);
|
|
10
|
+
return React.createElement(BootstrapOptionsContext.Provider, { value: options }, children);
|
|
11
|
+
}
|
|
@@ -22,9 +22,10 @@ import React, { useCallback, useContext, useRef, useState } from 'react';
|
|
|
22
22
|
import { ValidatorProvider } from "react-admin-base";
|
|
23
23
|
import { FormattedMessage } from 'react-intl';
|
|
24
24
|
import { Navigate, Routes, useParams, Route } from 'react-router-dom';
|
|
25
|
-
import { Alert, Button, Col, Form,
|
|
25
|
+
import { Alert, Button, Col, Form, ModalFooter, ModalHeader, Row } from "reactstrap";
|
|
26
26
|
import LoadingButton from '../Components/LoadingButton';
|
|
27
27
|
import BootstrapDataTable, { Actions } from './BootstrapDataTable';
|
|
28
|
+
import BootstrapModal from './BootstrapModal';
|
|
28
29
|
export function ModalEntityEditor({ entity, title, size, url, onReload, disabled, children }) {
|
|
29
30
|
const [, , save, loading] = entity;
|
|
30
31
|
const [open, setOpen] = useState(true);
|
|
@@ -59,7 +60,7 @@ export function ModalEntityEditor({ entity, title, size, url, onReload, disabled
|
|
|
59
60
|
}, [save, saved, error, onReload, url]);
|
|
60
61
|
return React.createElement(React.Fragment, null,
|
|
61
62
|
(saved || !open) && url && React.createElement(Navigate, { to: url, replace: true }),
|
|
62
|
-
React.createElement(
|
|
63
|
+
React.createElement(BootstrapModal, { isOpen: true, size: size, toggle: () => url ? setOpen(false) : onReload(null), fade: false },
|
|
63
64
|
title && React.createElement(ModalHeader, { toggle: () => url ? setOpen(false) : onReload(null) },
|
|
64
65
|
React.createElement("b", null, title)),
|
|
65
66
|
React.createElement(ValidatorProvider, null,
|
|
@@ -103,5 +104,5 @@ export default function CRUD(props) {
|
|
|
103
104
|
React.createElement(Routes, null,
|
|
104
105
|
!noAdd && React.createElement(Route, { path: "create", element: React.createElement(ComponentWrapper, Object.assign({ Component: Component, url: url, onReload: reload }, (defaultParams || {}))) }),
|
|
105
106
|
React.createElement(Route, { path: ":id/edit", element: React.createElement(ComponentWrapper, Object.assign({ Component: Component, url: url, onReload: reload }, (defaultParams || {}))) })),
|
|
106
|
-
React.createElement(BootstrapDataTable, Object.assign({ innerRef: ref, add: (!noAdd && "create") || undefined }, props, { url: apiUrl || url })));
|
|
107
|
+
React.createElement(BootstrapDataTable, Object.assign({ innerRef: ref, add: (!noAdd && "create") || undefined }, props, { url: apiUrl || url }), props.children));
|
|
107
108
|
}
|
|
@@ -6,7 +6,8 @@ import { FormattedMessage } from "react-intl";
|
|
|
6
6
|
import DragAndDropArrow from './DragAndDropArrow';
|
|
7
7
|
const photo_ext = ["png", "jpg", "jpeg", "svg"];
|
|
8
8
|
function is_photo(name) {
|
|
9
|
-
|
|
9
|
+
const sp = (name || '').split('.');
|
|
10
|
+
return photo_ext.indexOf((sp[sp.length - 1] || '').toLowerCase()) !== -1;
|
|
10
11
|
}
|
|
11
12
|
function is_absolute(url) {
|
|
12
13
|
if (url.indexOf("blob:") === 0)
|
|
@@ -25,7 +26,7 @@ export function Relative({ children }) {
|
|
|
25
26
|
});
|
|
26
27
|
}
|
|
27
28
|
export function Preview({ value }) {
|
|
28
|
-
const name = value.$name;
|
|
29
|
+
const name = value.$name || value.name;
|
|
29
30
|
const src = value.$blob_url || value.$src;
|
|
30
31
|
if (is_photo(name)) {
|
|
31
32
|
return React.createElement("div", { className: "mt-2" },
|
|
@@ -10,7 +10,7 @@ export default class GoToTop extends React.Component {
|
|
|
10
10
|
window.scrollTo(0, 0);
|
|
11
11
|
}
|
|
12
12
|
handleScroll(e) {
|
|
13
|
-
|
|
13
|
+
const newShow = window.scrollY > 100;
|
|
14
14
|
if (newShow !== this.state.show) {
|
|
15
15
|
this.setState({ show: newShow });
|
|
16
16
|
}
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -21,4 +21,6 @@ import StepList, { StepItem } from './Components/StepList';
|
|
|
21
21
|
import PasswordInput from './Components/PasswordInput';
|
|
22
22
|
import DefaultValidatorOptions from './Components/DefaultValidatorOptions';
|
|
23
23
|
import DragAndDropArrow from './Components/DragAndDropArrow';
|
|
24
|
-
|
|
24
|
+
import BootstrapOptionsProvider, { useBootstrapOptions } from './Components/BootstrapOptions';
|
|
25
|
+
import BootstrapModal from './Components/BootstrapModal';
|
|
26
|
+
export { ThemeProvider, useTheme, useAllThemes, useIsMobile, useMenuState, DefaultValidatorOptions, PasswordInput, StepList, StepItem, TopProgressBar, CRUD, ModalEntityEditor, CRUDActions, Relative, ApiSelect, Preview, ExcelExportButton, ExternalLoginButton, SingleFilePicker, MultiFilePicker, ImagePicker, BootstrapTable, EntityEditor, GoToTop, Validator, ValueValidator, ValidationErrors, LoadingButton, BootstrapDataTable, IdColumn, Column, ActionsColumn, Actions, useDataTableContext, RowRenderer, LanguageProvider, useLanguage, LanguageSwitcher, ErrorBoundary, CheckBox, DragAndDropArrow, useBootstrapOptions, BootstrapOptionsProvider, BootstrapModal };
|
package/lib/esm/index.js
CHANGED
|
@@ -21,4 +21,6 @@ import StepList, { StepItem } from './Components/StepList';
|
|
|
21
21
|
import PasswordInput from './Components/PasswordInput';
|
|
22
22
|
import DefaultValidatorOptions from './Components/DefaultValidatorOptions';
|
|
23
23
|
import DragAndDropArrow from './Components/DragAndDropArrow';
|
|
24
|
-
|
|
24
|
+
import BootstrapOptionsProvider, { useBootstrapOptions } from './Components/BootstrapOptions';
|
|
25
|
+
import BootstrapModal from './Components/BootstrapModal';
|
|
26
|
+
export { ThemeProvider, useTheme, useAllThemes, useIsMobile, useMenuState, DefaultValidatorOptions, PasswordInput, StepList, StepItem, TopProgressBar, CRUD, ModalEntityEditor, CRUDActions, Relative, ApiSelect, Preview, ExcelExportButton, ExternalLoginButton, SingleFilePicker, MultiFilePicker, ImagePicker, BootstrapTable, EntityEditor, GoToTop, Validator, ValueValidator, ValidationErrors, LoadingButton, BootstrapDataTable, IdColumn, Column, ActionsColumn, Actions, useDataTableContext, RowRenderer, LanguageProvider, useLanguage, LanguageSwitcher, ErrorBoundary, CheckBox, DragAndDropArrow, useBootstrapOptions, BootstrapOptionsProvider, BootstrapModal };
|
package/package.json
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {Modal, ModalProps} from "reactstrap";
|
|
3
|
+
import { useBootstrapOptions } from "./BootstrapOptions";
|
|
4
|
+
|
|
5
|
+
export default function BootstrapModal(props: ModalProps) {
|
|
6
|
+
const bsOptions = useBootstrapOptions();
|
|
7
|
+
|
|
8
|
+
return <Modal {...props} toggle={bsOptions.noCloseModal ? undefined : props.toggle} />;
|
|
9
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React, {createContext, ReactNode, useContext, useMemo} from "react";
|
|
2
|
+
import BootstrapOptions from "./BootstrapOptions";
|
|
3
|
+
|
|
4
|
+
interface BootstrapOptions {
|
|
5
|
+
noCloseModal: boolean;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
interface BootstrapOptionsProviderProps extends BootstrapOptions {
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const BootstrapOptionsContext = createContext<BootstrapOptions>({
|
|
13
|
+
noCloseModal: false
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export function useBootstrapOptions() {
|
|
17
|
+
return useContext(BootstrapOptionsContext);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default function BootstrapOptionsProvider({children,noCloseModal}: BootstrapOptionsProviderProps) {
|
|
21
|
+
const options = useMemo(() => ({noCloseModal}), [noCloseModal]);
|
|
22
|
+
return <BootstrapOptionsContext.Provider value={options}>
|
|
23
|
+
{ children }
|
|
24
|
+
</BootstrapOptionsContext.Provider>;
|
|
25
|
+
}
|
package/src/Components/CRUD.tsx
CHANGED
|
@@ -5,6 +5,8 @@ import { Navigate, Routes, useParams, Route } from 'react-router-dom';
|
|
|
5
5
|
import { Alert, Button, Col, Form, Modal, ModalFooter, ModalHeader, Row } from "reactstrap";
|
|
6
6
|
import LoadingButton from '../Components/LoadingButton';
|
|
7
7
|
import BootstrapDataTable, { Actions, BootstrapTableProps } from './BootstrapDataTable';
|
|
8
|
+
import BootstrapModal from './BootstrapModal';
|
|
9
|
+
import {useBootstrapOptions} from "./BootstrapOptions";
|
|
8
10
|
|
|
9
11
|
type ModalEntityEditorParams = {
|
|
10
12
|
entity: any;
|
|
@@ -57,7 +59,7 @@ export function ModalEntityEditor({ entity, title, size, url, onReload, disabled
|
|
|
57
59
|
|
|
58
60
|
return <>
|
|
59
61
|
{ (saved || !open) && url && <Navigate to={url} replace />}
|
|
60
|
-
<
|
|
62
|
+
<BootstrapModal isOpen size={size} toggle={() => url ? setOpen(false) : onReload(null)} fade={false}>
|
|
61
63
|
{ title && <ModalHeader toggle={() => url ? setOpen(false) : onReload(null)}>
|
|
62
64
|
<b>{ title }</b>
|
|
63
65
|
</ModalHeader> }
|
|
@@ -83,7 +85,7 @@ export function ModalEntityEditor({ entity, title, size, url, onReload, disabled
|
|
|
83
85
|
</ModalFooter>
|
|
84
86
|
</Form>
|
|
85
87
|
</ValidatorProvider>
|
|
86
|
-
</
|
|
88
|
+
</BootstrapModal>
|
|
87
89
|
</>;
|
|
88
90
|
}
|
|
89
91
|
|
|
@@ -130,6 +132,8 @@ export default function CRUD(props: CRUDProps) {
|
|
|
130
132
|
{ !noAdd && <Route path="create" element={<ComponentWrapper Component={Component} url={url} onReload={reload} {...(defaultParams || {})} />} /> }
|
|
131
133
|
<Route path=":id/edit" element={<ComponentWrapper Component={Component} url={url} onReload={reload} {...(defaultParams || {})} />} />
|
|
132
134
|
</Routes>
|
|
133
|
-
<BootstrapDataTable innerRef={ref} add={(!noAdd && "create") || undefined} {...props} url={apiUrl || url}
|
|
135
|
+
<BootstrapDataTable innerRef={ref} add={(!noAdd && "create") || undefined} {...props} url={apiUrl || url}>
|
|
136
|
+
{props.children}
|
|
137
|
+
</BootstrapDataTable>
|
|
134
138
|
</UrlContext.Provider>;
|
|
135
139
|
}
|
|
@@ -4,7 +4,6 @@ import { FormattedMessage } from "react-intl";
|
|
|
4
4
|
import { Alert, Form } from 'reactstrap';
|
|
5
5
|
import LoadingButton from "../Components/LoadingButton";
|
|
6
6
|
import { ValidationErrors } from './Validator';
|
|
7
|
-
import { Navigate } from 'react-router-dom';
|
|
8
7
|
|
|
9
8
|
type EntityEditorParams = {
|
|
10
9
|
entity: any;
|
|
@@ -9,7 +9,8 @@ import DragAndDropArrow from './DragAndDropArrow';
|
|
|
9
9
|
const photo_ext = ["png", "jpg", "jpeg", "svg"];
|
|
10
10
|
|
|
11
11
|
function is_photo(name) {
|
|
12
|
-
|
|
12
|
+
const sp = (name || '').split('.');
|
|
13
|
+
return photo_ext.indexOf((sp[sp.length - 1] || '').toLowerCase()) !== -1;
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
function is_absolute(url) {
|
|
@@ -39,7 +40,7 @@ export function Relative({ children }: RelativeProps) {
|
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
export function Preview({ value }) {
|
|
42
|
-
const name = value.$name;
|
|
43
|
+
const name = value.$name || value.name;
|
|
43
44
|
const src = value.$blob_url || value.$src;
|
|
44
45
|
|
|
45
46
|
if (is_photo(name)) {
|
|
@@ -2,7 +2,6 @@ import React from 'react';
|
|
|
2
2
|
import {FormattedMessage} from "react-intl";
|
|
3
3
|
|
|
4
4
|
export default class GoToTop extends React.Component {
|
|
5
|
-
|
|
6
5
|
state = {show: false};
|
|
7
6
|
|
|
8
7
|
scrollTop(e) {
|
|
@@ -12,7 +11,7 @@ export default class GoToTop extends React.Component {
|
|
|
12
11
|
}
|
|
13
12
|
|
|
14
13
|
handleScroll(e) {
|
|
15
|
-
|
|
14
|
+
const newShow = window.scrollY > 100;
|
|
16
15
|
if (newShow !== this.state.show) {
|
|
17
16
|
this.setState({show: newShow});
|
|
18
17
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { createContext, Dispatch, useContext, useEffect, useMemo, useReducer, useRef } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { useLocalStorage } from "react-admin-base";
|
|
3
3
|
|
|
4
4
|
const ThemeContext = createContext(null as any);
|
|
5
5
|
const AllThemesContext = createContext(null as any);
|
package/src/index.ts
CHANGED
|
@@ -22,6 +22,8 @@ import StepList, { StepItem } from './Components/StepList';
|
|
|
22
22
|
import PasswordInput from './Components/PasswordInput';
|
|
23
23
|
import DefaultValidatorOptions from './Components/DefaultValidatorOptions';
|
|
24
24
|
import DragAndDropArrow from './Components/DragAndDropArrow';
|
|
25
|
+
import BootstrapOptionsProvider, { useBootstrapOptions } from './Components/BootstrapOptions';
|
|
26
|
+
import BootstrapModal from './Components/BootstrapModal';
|
|
25
27
|
|
|
26
28
|
export {
|
|
27
29
|
ThemeProvider, useTheme, useAllThemes,
|
|
@@ -49,5 +51,8 @@ export {
|
|
|
49
51
|
LanguageProvider, useLanguage, LanguageSwitcher,
|
|
50
52
|
ErrorBoundary,
|
|
51
53
|
CheckBox,
|
|
52
|
-
DragAndDropArrow
|
|
54
|
+
DragAndDropArrow,
|
|
55
|
+
useBootstrapOptions,
|
|
56
|
+
BootstrapOptionsProvider,
|
|
57
|
+
BootstrapModal
|
|
53
58
|
};
|