-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Global Styles JSON data inspector (#697)
* Add global styles inspector * rename option * rename option Co-authored-by: Jeff Ong <[email protected]> * rename option --------- Co-authored-by: Jeff Ong <[email protected]>
- Loading branch information
1 parent
a8b2e52
commit 36310c3
Showing
2 changed files
with
94 additions
and
0 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,72 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import CodeMirror from '@uiw/react-codemirror'; | ||
import { json } from '@codemirror/lang-json'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __, sprintf } from '@wordpress/i18n'; | ||
import { Modal } from '@wordpress/components'; | ||
import { useSelect } from '@wordpress/data'; | ||
import { store as coreStore } from '@wordpress/core-data'; | ||
|
||
const GlobalStylesJsonEditorModal = ( { onRequestClose } ) => { | ||
const themeName = useSelect( ( select ) => | ||
select( 'core' ).getCurrentTheme() | ||
)?.name?.raw; | ||
|
||
const { record: globalStylesRecord } = useSelect( ( select ) => { | ||
const { | ||
__experimentalGetCurrentGlobalStylesId, | ||
getEditedEntityRecord, | ||
} = select( coreStore ); | ||
const globalStylesId = __experimentalGetCurrentGlobalStylesId(); | ||
const record = getEditedEntityRecord( | ||
'root', | ||
'globalStyles', | ||
globalStylesId | ||
); | ||
return { | ||
record, | ||
}; | ||
} ); | ||
|
||
const globalStyles = { | ||
...( globalStylesRecord?.styles && { | ||
styles: globalStylesRecord.styles, | ||
} ), | ||
...( globalStylesRecord?.settings && { | ||
settings: globalStylesRecord.settings, | ||
} ), | ||
}; | ||
|
||
const globalStylesAsString = globalStyles | ||
? JSON.stringify( globalStyles, null, 4 ) | ||
: ''; | ||
|
||
const handleSave = () => {}; | ||
|
||
return ( | ||
<Modal | ||
size="large" | ||
title={ sprintf( | ||
// translators: %s: theme name. | ||
__( 'Custom Styles for %s', 'create-block-theme' ), | ||
themeName | ||
) } | ||
onRequestClose={ onRequestClose } | ||
className="create-block-theme__theme-json-modal" | ||
> | ||
<CodeMirror | ||
extensions={ [ json() ] } | ||
value={ globalStylesAsString } | ||
onChange={ handleSave } | ||
readOnly | ||
/> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default GlobalStylesJsonEditorModal; |
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