index.js
110 lines
| 1 | import { InspectorControls } from '@wordpress/block-editor'; |
| 2 | import { useContext } from '@wordpress/element'; |
| 3 | import ControlsContext from '../../block-context'; |
| 4 | import ResponsiveTabs from './controls/responsive-tabs'; |
| 5 | import TypographyControls from './controls/typography'; |
| 6 | import SpacingControls from './controls/spacing'; |
| 7 | import BorderControls from './controls/borders'; |
| 8 | import ColorsControls from './controls/colors'; |
| 9 | import IconControls from './controls/icon'; |
| 10 | import SettingsPanel from './controls/settings-panel'; |
| 11 | import BackgroundPanel from './controls/background-panel'; |
| 12 | import ShapesPanel from './controls/shapes-panel'; |
| 13 | import LayoutControls from './controls/layout'; |
| 14 | import SizingControls from './controls/sizing'; |
| 15 | import getDeviceType from '../../utils/get-device-type'; |
| 16 | |
| 17 | export default function GenerateBlocksInspectorControls( { attributes, setAttributes, computedStyles = {}, children } ) { |
| 18 | const device = getDeviceType(); |
| 19 | const { |
| 20 | supports: { |
| 21 | responsiveTabs, |
| 22 | settingsPanel, |
| 23 | layout, |
| 24 | typography, |
| 25 | spacing, |
| 26 | borders, |
| 27 | colors, |
| 28 | backgroundPanel, |
| 29 | shapesPanel, |
| 30 | icon, |
| 31 | sizingPanel, |
| 32 | }, |
| 33 | } = useContext( ControlsContext ); |
| 34 | |
| 35 | return ( |
| 36 | <InspectorControls> |
| 37 | { responsiveTabs && <ResponsiveTabs /> } |
| 38 | |
| 39 | { settingsPanel.enabled && !! children && |
| 40 | <SettingsPanel>{ children }</SettingsPanel> |
| 41 | } |
| 42 | |
| 43 | { layout.enabled && |
| 44 | <LayoutControls |
| 45 | attributes={ attributes } |
| 46 | setAttributes={ setAttributes } |
| 47 | /> |
| 48 | } |
| 49 | |
| 50 | { sizingPanel.enabled && |
| 51 | <SizingControls |
| 52 | attributes={ attributes } |
| 53 | setAttributes={ setAttributes } |
| 54 | /> |
| 55 | } |
| 56 | |
| 57 | { spacing.enabled && |
| 58 | <SpacingControls |
| 59 | attributes={ attributes } |
| 60 | setAttributes={ setAttributes } |
| 61 | computedStyles={ computedStyles } |
| 62 | /> |
| 63 | } |
| 64 | |
| 65 | { borders.enabled && |
| 66 | <BorderControls |
| 67 | attributes={ attributes } |
| 68 | setAttributes={ setAttributes } |
| 69 | /> |
| 70 | } |
| 71 | |
| 72 | { typography.enabled && ! attributes.removeText && |
| 73 | <TypographyControls |
| 74 | attributes={ attributes } |
| 75 | setAttributes={ setAttributes } |
| 76 | computedStyles={ computedStyles } |
| 77 | /> |
| 78 | } |
| 79 | |
| 80 | { colors.enabled && 'Desktop' === device && |
| 81 | <ColorsControls |
| 82 | attributes={ attributes } |
| 83 | setAttributes={ setAttributes } |
| 84 | /> |
| 85 | } |
| 86 | |
| 87 | { backgroundPanel.enabled && 'Desktop' === device && |
| 88 | <BackgroundPanel |
| 89 | attributes={ attributes } |
| 90 | setAttributes={ setAttributes } |
| 91 | /> |
| 92 | } |
| 93 | |
| 94 | { shapesPanel.enabled && ( 'Desktop' === device || attributes?.shapeDividers.length > 0 ) && |
| 95 | <ShapesPanel |
| 96 | attributes={ attributes } |
| 97 | setAttributes={ setAttributes } |
| 98 | /> |
| 99 | } |
| 100 | |
| 101 | { icon.enabled && ( 'Desktop' === device || !! attributes.icon ) && |
| 102 | <IconControls |
| 103 | attributes={ attributes } |
| 104 | setAttributes={ setAttributes } |
| 105 | /> |
| 106 | } |
| 107 | </InspectorControls> |
| 108 | ); |
| 109 | } |
| 110 |