-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Starting to set up global styles and refactor existing background components Porting over existing hook code to shared, global styles component. Next step is to gut the existing hook and set up props using setAttribute etc
- Loading branch information
Showing
8 changed files
with
651 additions
and
7 deletions.
There are no files selected for viewing
542 changes: 542 additions & 0 deletions
542
packages/block-editor/src/components/global-styles/background-panel.js
Large diffs are not rendered by default.
Oops, something went wrong.
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
50 changes: 50 additions & 0 deletions
50
packages/edit-site/src/components/global-styles/background-panel.js
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,50 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor'; | ||
import { useMemo } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { unlock } from '../../lock-unlock'; | ||
|
||
const { | ||
useGlobalStyle, | ||
useGlobalSetting, | ||
useSettingsForBlockElement, | ||
BackgroundPanel: StylesBackgroundPanel, | ||
} = unlock( blockEditorPrivateApis ); | ||
|
||
const DEFAULT_CONTROLS = { | ||
contentSize: true, | ||
wideSize: true, | ||
padding: true, | ||
margin: true, | ||
blockGap: true, | ||
minHeight: true, | ||
childLayout: false, | ||
}; | ||
|
||
export default function BackgroundPanel() { | ||
const [ style ] = useGlobalStyle( '', undefined, 'user', { | ||
shouldDecodeEncode: false, | ||
} ); | ||
const [ inheritedStyle, setStyle ] = useGlobalStyle( '', undefined, 'all', { | ||
shouldDecodeEncode: false, | ||
} ); | ||
|
||
const [ rawSettings ] = useGlobalSetting( '' ); | ||
const settings = useSettingsForBlockElement( rawSettings ); | ||
|
||
return ( | ||
<StylesBackgroundPanel | ||
inheritedValue={ inheritedStyle } | ||
value={ style } | ||
onChange={ setStyle } | ||
settings={ settings } | ||
includeLayoutControls | ||
defaultControls={ DEFAULT_CONTROLS } | ||
/> | ||
); | ||
} |
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
29 changes: 29 additions & 0 deletions
29
packages/edit-site/src/components/global-styles/screen-background.js
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,29 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import BackgroundPanel from './background-panel'; | ||
import ScreenHeader from './header'; | ||
import { unlock } from '../../lock-unlock'; | ||
|
||
const { useHasBackgroundPanel, useGlobalSetting, useSettingsForBlockElement } = | ||
unlock( blockEditorPrivateApis ); | ||
|
||
function ScreenBackground() { | ||
const [ rawSettings ] = useGlobalSetting( '' ); | ||
const settings = useSettingsForBlockElement( rawSettings ); | ||
const hasBackgroundPanel = useHasBackgroundPanel( settings ); | ||
return ( | ||
<> | ||
<ScreenHeader title={ __( 'Background' ) } /> | ||
{ hasBackgroundPanel && <BackgroundPanel /> } | ||
</> | ||
); | ||
} | ||
|
||
export default ScreenBackground; |
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