-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial experimental custom components support
Signed-off-by: Zvonimir Fras <[email protected]>
- Loading branch information
1 parent
ff5527c
commit a34899f
Showing
10 changed files
with
322 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import React, { useContext, useState } from 'react'; | ||
import { Modal } from '@carbon/react'; | ||
import Editor from '@monaco-editor/react'; | ||
import { GlobalStateContext, ModalContext } from '../context'; | ||
|
||
export const CustomComponentsModal = () => { | ||
const { customComponentsModal, hideCustomComponentsModal } = useContext(ModalContext); | ||
const { customComponentsCollections, setCustomComponentsCollections } = useContext(GlobalStateContext); | ||
const [jsonParseError, setJsonParseError] = useState(''); | ||
const [model, _setModel] = useState(JSON.stringify(customComponentsCollections ? customComponentsCollections[0] : {}, null, '\t')); | ||
|
||
const setModel = (modelString: string) => { | ||
_setModel(modelString); | ||
try { | ||
if (modelString) { | ||
// TODO set exact modelCollection based on name instead | ||
setCustomComponentsCollections([JSON.parse(modelString)]); | ||
} | ||
|
||
setJsonParseError(''); | ||
} catch (e) { | ||
setJsonParseError((e as any).toString()); | ||
} | ||
}; | ||
|
||
const handleEditorChange = (value: any, _event: any) => { | ||
setModel(value); | ||
}; | ||
|
||
return <Modal | ||
size='lg' | ||
open={customComponentsModal.isVisible} | ||
onRequestClose={hideCustomComponentsModal} | ||
modalHeading='Custom components (Experimental)' | ||
primaryButtonText='Done' | ||
onRequestSubmit={() => { | ||
hideCustomComponentsModal(); | ||
}}> | ||
{ | ||
jsonParseError | ||
&& <> | ||
Not saved until the error is corrected: | ||
<code style={{ color: '#a00', marginBottom: '10pt', width: '100%' }}> | ||
<pre>{jsonParseError}</pre> | ||
</code> | ||
</> | ||
} | ||
<Editor | ||
height='calc(100vh - 32px)' | ||
language='json' | ||
value={model} | ||
onChange={handleEditorChange} | ||
/> | ||
</Modal>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.