wip on switching from docz to docusaurus
This commit is contained in:
1 parent
69e36106e3
commit
09469e6ac5
97 files changed
+1505
-7132
No files matched your search
@@ -1,119 +0,0 @@
|
||||
---
|
||||
name: ModalProvider
|
||||
route: customHooks/modalProvider
|
||||
---
|
||||
|
||||
import { Props } from 'docz';
|
||||
import { ModalProvider } from '../contextProviders';
|
||||
import ModalComponent from './ModalComponent.jsx';
|
||||
|
||||
# Modal Context Provider
|
||||
|
||||
This is a context provider that allow the application to share the modal
|
||||
component across all application.
|
||||
|
||||
## ModalProvider
|
||||
|
||||
Properties:
|
||||
|
||||
<Props of={ModalProvider} />
|
||||
|
||||
Usage example:
|
||||
|
||||
```javascript
|
||||
import { ModalProvider } from '@ohif/ui';
|
||||
import YourModalComponent from 'your-modal-component';
|
||||
|
||||
const App = () => {
|
||||
return (
|
||||
<ModalProvider modal={YourModalComponent}>
|
||||
/** You app content */
|
||||
</ModalComponent>;
|
||||
)
|
||||
};
|
||||
|
||||
export default App;
|
||||
```
|
||||
|
||||
## useModal
|
||||
|
||||
Used for React Functional Components. Should be used in the body of the
|
||||
functional component to get access to the context together with the `show/hide`
|
||||
functions.
|
||||
|
||||
Usage example:
|
||||
|
||||
```javascript
|
||||
import { withModal } from '@ohif/ui';
|
||||
|
||||
const SampleComponent = () => {
|
||||
const { show, hide } = useModal();
|
||||
|
||||
const openModal = () => {
|
||||
show({
|
||||
content: <div> Modal Content </div>,
|
||||
title: 'Modal title',
|
||||
});
|
||||
}
|
||||
|
||||
const closeModal = () => {
|
||||
hide();
|
||||
}
|
||||
|
||||
return (
|
||||
<button onClick={openModal}>
|
||||
Open modal
|
||||
</button>
|
||||
<button onClick={closeModal}>
|
||||
Close modal
|
||||
</button>
|
||||
);
|
||||
};
|
||||
|
||||
export default SampleComponent;
|
||||
```
|
||||
|
||||
## withModal
|
||||
|
||||
Used for React Class Components. This function show receive a Component as a
|
||||
property and this component will have access to the context through its own
|
||||
properties.
|
||||
|
||||
Usage example:
|
||||
|
||||
```javascript
|
||||
import { withModal } from '@ohif/ui';
|
||||
import React from 'react';
|
||||
|
||||
class SampleComponent extends React.Component {
|
||||
openModal() {
|
||||
this.props.modal.show({
|
||||
content: <div> Modal Content </div>,
|
||||
title: 'Modal title',
|
||||
});
|
||||
}
|
||||
|
||||
closeModal() = {
|
||||
this.props.modal.hide();
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<button onClick={this.openModal}>
|
||||
Open modal
|
||||
</button>
|
||||
<button onClick={this.closeModal}>
|
||||
Close modal
|
||||
</button>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default withModal(SampleComponent);
|
||||
```
|
||||
|
||||
## Modal Properties
|
||||
|
||||
The Modal Properties that can be override are:
|
||||
|
||||
<Props of={ModalComponent} />
|
||||
@@ -7,8 +7,8 @@ import React, {
|
||||
} from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
import SnackbarContainer from '../components/Snackbar/SnackbarContainer';
|
||||
import SnackbarTypes from '../components/Snackbar/SnackbarTypes';
|
||||
import SnackbarContainer from '../components/Snackbar/SnackbarContainer';
|
||||
|
||||
const SnackbarContext = createContext(null);
|
||||
|
||||
|
||||
@@ -1,179 +0,0 @@
|
||||
---
|
||||
name: ViewportDialogProvider
|
||||
route: customHooks/viewportDialogProvider
|
||||
---
|
||||
|
||||
import { Playground, Props } from 'docz';
|
||||
|
||||
<!-- This is a workaround to import things from ohif/core as docz does not allow us to access window element and @ohif/core does use it once we import to instanciate cornerstone -->
|
||||
import UIViewportDialogService from './../../../core/src/services/UIViewportDialogService';
|
||||
import ServicesManager from './../../../core/src/services/ServicesManager';
|
||||
|
||||
import { Dialog, Button, Notification } from '../components';
|
||||
import { ViewportDialogProvider, useViewportDialog } from '../contextProviders';
|
||||
|
||||
# Viewport Dialog Provider
|
||||
|
||||
This is a context provider that allow the application to share the modal
|
||||
component across all application.
|
||||
|
||||
## Sample
|
||||
|
||||
<Playground>
|
||||
{() => {
|
||||
const ViewportNotification = ({ hide }) => {
|
||||
return (
|
||||
<Notification
|
||||
message="Track all measurement for this series?"
|
||||
type="info"
|
||||
actions={[
|
||||
{
|
||||
type: 'cancel',
|
||||
text: 'No',
|
||||
value: 0,
|
||||
},
|
||||
{
|
||||
type: 'secondary',
|
||||
text: 'No, do not ask again',
|
||||
value: -1,
|
||||
},
|
||||
{
|
||||
type: 'primary',
|
||||
text: 'Yes',
|
||||
value: 1,
|
||||
},
|
||||
]}
|
||||
onSubmit={value => {
|
||||
if (typeof window !== 'undefined') {
|
||||
window.alert(value);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
);
|
||||
};
|
||||
const ViewportActionButtons = () => {
|
||||
const [dialogState, dialogApi] = useViewportDialog();
|
||||
return (
|
||||
<Button onClick={() => dialogApi.show({ content: ViewportNotification })}>
|
||||
Open Dialog
|
||||
</Button>
|
||||
);
|
||||
};
|
||||
return (
|
||||
<div className="w-full flex flex-row p-4" style={{height: '400px'}}>
|
||||
<div className="flex flex-1 items-center justify-center h-full w-full bg-black text-white border border-primary-main">
|
||||
<ViewportDialogProvider dialog={Dialog}>
|
||||
<div className="flex flex-1 flex-col items-center justify-center h-full">
|
||||
<ViewportActionButtons />
|
||||
<span>CONTENT 1</span>
|
||||
</div>
|
||||
</ViewportDialogProvider>
|
||||
</div>
|
||||
<div className="flex flex-1 items-center justify-center h-full w-full bg-black text-white border border-primary-main">
|
||||
<ViewportDialogProvider dialog={Dialog}>
|
||||
<div className="flex flex-1 flex-col items-center justify-center h-full">
|
||||
<ViewportActionButtons />
|
||||
<span>CONTENT 1</span>
|
||||
</div>
|
||||
</ViewportDialogProvider>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}}
|
||||
</Playground>
|
||||
|
||||
## Example using UIViewportDialogService
|
||||
|
||||
<Playground>
|
||||
{() => {
|
||||
const ViewportNotification = ({ hide }) => {
|
||||
return (
|
||||
<Notification
|
||||
message="Track all measurement for this series?"
|
||||
type="info"
|
||||
actions={[
|
||||
{
|
||||
type: 'cancel',
|
||||
text: 'No',
|
||||
value: 0,
|
||||
},
|
||||
{
|
||||
type: 'secondary',
|
||||
text: 'No, do not ask again',
|
||||
value: -1,
|
||||
},
|
||||
{
|
||||
type: 'primary',
|
||||
text: 'Yes',
|
||||
value: 1,
|
||||
},
|
||||
]}
|
||||
onSubmit={value => {
|
||||
if (typeof window !== 'undefined') {
|
||||
window.alert(value);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
);
|
||||
};
|
||||
// Creating servicesManager and register services should be in the root of your app
|
||||
const servicesManager = new ServicesManager();
|
||||
servicesManager.registerServices([UIViewportDialogService]);
|
||||
// Get service instance
|
||||
const _UIViewportDialogService =
|
||||
servicesManager.services.UIViewportDialogService;
|
||||
console.log(_UIViewportDialogService);
|
||||
return (
|
||||
<div className="w-full flex flex-col p-4" style={{height: '400px'}}>
|
||||
<div className="flex flex-2">
|
||||
<Button
|
||||
className="mr-4 mb-4"
|
||||
onClick={() =>
|
||||
_UIViewportDialogService.show({
|
||||
content: ViewportNotification,
|
||||
viewportIndex: 0,
|
||||
})
|
||||
}
|
||||
>
|
||||
Open dialog on 0
|
||||
</Button>
|
||||
<Button
|
||||
className="mr-4 mb-4"
|
||||
onClick={() =>
|
||||
_UIViewportDialogService.show({
|
||||
content: ViewportNotification,
|
||||
viewportIndex: 1,
|
||||
})
|
||||
}
|
||||
>
|
||||
Open dialog on 1
|
||||
</Button>
|
||||
</div>
|
||||
<div className="flex flex-1 w-full flex-row">
|
||||
<ViewportDialogProvider
|
||||
dialog={Dialog}
|
||||
service={_UIViewportDialogService}
|
||||
viewportIndex={0}
|
||||
>
|
||||
<div className="flex flex-1 items-center justify-center h-full bg-black text-white border border-primary-main">
|
||||
CONTENT 0
|
||||
</div>
|
||||
</ViewportDialogProvider>
|
||||
<ViewportDialogProvider
|
||||
dialog={Dialog}
|
||||
service={_UIViewportDialogService}
|
||||
viewportIndex={1}
|
||||
>
|
||||
<div className="flex flex-1 items-center justify-center h-full bg-black text-white border border-primary-main">
|
||||
CONTENT 1
|
||||
</div>
|
||||
</ViewportDialogProvider>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}}
|
||||
</Playground>
|
||||
|
||||
## Properties:
|
||||
|
||||
<Props of={ViewportDialogProvider} />
|
||||
Reference in new issue
Block a user