Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable adjustment of 'settings' values #120

Open
wants to merge 45 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
2a5bd33
feat: init
chrishall0 Dec 2, 2024
f5137a7
feat: render appearance tools
chrishall0 Dec 6, 2024
d082d47
feat: border settings
chrishall0 Dec 6, 2024
35a844e
feat: color settings
chrishall0 Dec 6, 2024
c35485d
feat: duotone component
chrishall0 Dec 6, 2024
7d6c0be
feat: gradient settings
chrishall0 Dec 6, 2024
0c5aa78
feat: color palette setting
chrishall0 Dec 6, 2024
045a3da
feat: refactor gradient setting tool
chrishall0 Dec 6, 2024
fbb10ed
feat: duotone setting component
chrishall0 Dec 9, 2024
992e018
feat: style duotone buttons
chrishall0 Dec 9, 2024
0035140
feat: use buttons over palette components for consistency
chrishall0 Dec 9, 2024
63d0b9c
feat: remove unnecessary useeffect
chrishall0 Dec 9, 2024
424fc09
feat: layout component, linting
chrishall0 Dec 9, 2024
75d2ac8
fix: remove console logs
chrishall0 Dec 9, 2024
0ad019d
feat: typography first pass, dimensions settings
chrishall0 Dec 10, 2024
7b02e45
feat: shadow component
chrishall0 Dec 10, 2024
0138cf5
feat: typography setting feat
chrishall0 Dec 10, 2024
b8dc7fd
feat: adds in font face src picker
chrishall0 Dec 10, 2024
00ea057
feat: escape title
chrishall0 Dec 10, 2024
59d7c67
feat: font sizes, typography updates
chrishall0 Dec 16, 2024
266c7ac
feat: remainder of typography settings
chrishall0 Dec 16, 2024
8dfdce4
feat: removing unused components, various linting
chrishall0 Dec 17, 2024
e683ff6
style: linting
chrishall0 Dec 17, 2024
7a7e61f
style: various linting fixes
chrishall0 Dec 17, 2024
e00beb5
style: linting fix
chrishall0 Dec 17, 2024
107862f
feat: custom settings
chrishall0 Dec 18, 2024
632a4c0
feat: adds definitions from schema to settings
chrishall0 Dec 18, 2024
7b74678
feat: styling tweaks
chrishall0 Dec 18, 2024
3cc825f
feat: custom css setting help
chrishall0 Dec 18, 2024
f87ea29
feat: remove block settings, corrected references to 'styles' to 'set…
chrishall0 Jan 2, 2025
93055bd
docs: updated JSdoc comments
chrishall0 Jan 2, 2025
78fa751
feat: edit theme color palette rather than custom
chrishall0 Jan 2, 2025
2273617
feat: add code view for settings
chrishall0 Jan 2, 2025
04b4842
feat: rename custom settings to custom css
chrishall0 Jan 2, 2025
fb69cfc
feat: use theme settings rather than custom settings
chrishall0 Jan 2, 2025
cd82f96
feat: changes to spacing settings, preset units
chrishall0 Jan 9, 2025
9025ff8
feat: added missing 'button' value in color settings
chrishall0 Jan 9, 2025
d2f06b1
feat: added in basic missing settings
chrishall0 Jan 9, 2025
78b1a40
fix: styling fix for overflowing components with code view active
chrishall0 Jan 9, 2025
f236242
feat: make settings button deselectable and route to prev path on des…
chrishall0 Jan 9, 2025
89dc65a
feat: remove padding from accordions
chrishall0 Jan 9, 2025
4a55d69
feat: remove duplicate headings
chrishall0 Jan 9, 2025
e158ec6
feat: shared component for add/edit color palette
chrishall0 Jan 10, 2025
554095a
feat: share component for add/edit duotone
chrishall0 Jan 10, 2025
729f481
feat: share component for add/edit gradient
chrishall0 Jan 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/editor/components/CodeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ const CodeView = ( { themeConfig } ) => {
return rest;
}

/**
* If the current location is the site settings path, return the entire
* settings object.
*/
if ( location.path === '/settings' ) {
const { blocks, elements, ...rest } = themeConfig.settings;
return rest;
}
/**
* Remove the leading slash from the path so we don't end up with
* an empty string as the first part of the pathParts array.
Expand Down
177 changes: 177 additions & 0 deletions src/editor/components/ComponentSettings/Settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
import { Panel, PanelBody } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useContext } from '@wordpress/element';

import EditorContext from '../../context/EditorContext';

import SettingsAppearanceTools from './SettingsAppearanceTools';
import SettingsBorder from './SettingsBorder';
import SettingsColor from './SettingsColor';
import SettingsCustomCSS from './SettingsCustomCSS';
import SettingsLayout from './SettingsLayout';
import SettingsSpacing from './SettingsSpacing';
import TypographySettings from './TypographySettings';
import SettingsDimensions from './SettingsDimensions';
import SettingsShadow from './SettingsShadow';
import SettingsPosition from './SettingsPosition';
import SettingsBackground from './SettingsBackground';

/**
* Settings component
*
* This component will render the settings components for the given selector.
*
*
* @param {Object} props Component props
* @param {string} props.selector Selector for settings object within theme config
*/
const Settings = ( { selector } ) => {
const { schema } = useContext( EditorContext );

if ( ! selector ) {
return;
}

const definitions = schema?.definitions;

return (
<div className="themer--settings">
<Panel header={ __( 'Site Settings', 'themer' ) }>
<PanelBody
title={ __( 'Appearance Tools', 'themer' ) }
initialOpen={ false }
>
<SettingsAppearanceTools
selector={ `${ selector }` }
description={
definitions?.settingsAppearanceToolsProperties
?.properties?.appearanceTools?.description
}
/>
</PanelBody>
<PanelBody
title={ __( 'Border Settings', 'themer' ) }
initialOpen={ false }
>
<SettingsBorder
selector={ `${ selector }.border` }
description={
definitions?.settingsBorderProperties?.properties
?.border?.description
}
/>
</PanelBody>
<PanelBody
title={ __( 'Color Settings', 'themer' ) }
initialOpen={ false }
>
<SettingsColor
selector={ `${ selector }.color` }
description={
definitions?.settingsColorProperties?.properties
?.color?.description
}
/>
</PanelBody>
<PanelBody
title={ __( 'Custom CSS', 'themer' ) }
initialOpen={ false }
>
<SettingsCustomCSS
selector={ `${ selector }.custom` }
description={
definitions?.settingsCustomAdditionalProperties
?.description
}
/>
</PanelBody>
<PanelBody
title={ __( 'Layout Settings', 'themer' ) }
initialOpen={ false }
>
<SettingsLayout
selector={ `${ selector }.layout` }
description={
definitions?.settingsLayoutProperties?.properties
?.layout?.description
}
/>
</PanelBody>
<PanelBody
title={ __( 'Spacing Settings', 'themer' ) }
initialOpen={ false }
>
<SettingsSpacing
selector={ `${ selector }.spacing` }
description={
definitions?.settingsSpacingProperties?.properties
?.spacing?.description
}
/>
</PanelBody>
<PanelBody
title={ __( 'Typography Settings', 'themer' ) }
initialOpen={ false }
>
<TypographySettings
selector={ `${ selector }.typography` }
description={
definitions?.settingsTypographyProperties
?.properties?.typography?.description
}
/>
</PanelBody>
<PanelBody
title={ __( 'Dimensions Settings', 'themer' ) }
initialOpen={ false }
>
<SettingsDimensions
selector={ `${ selector }.dimensions` }
description={
definitions?.settingsDimensionsProperties
?.properties?.dimensions?.description
}
/>
</PanelBody>
<PanelBody
title={ __( 'Shadow Settings', 'themer' ) }
initialOpen={ false }
>
<SettingsShadow
selector={ `${ selector }.shadow` }
description={
definitions?.settingsShadowProperties?.properties
?.shadow?.description
}
/>
</PanelBody>
<PanelBody
title={ __( 'Position Settings', 'themer' ) }
initialOpen={ false }
>
<SettingsPosition
selector={ `${ selector }.position` }
description={
definitions?.settingsPositionProperties?.properties
?.position?.description
}
/>
</PanelBody>
<PanelBody
title={ __( 'Background Settings', 'themer' ) }
initialOpen={ false }
>
<SettingsBackground
selector={ `${ selector }.background` }
description={
definitions?.settingsBackgroundProperties
?.properties?.background?.description
}
/>
</PanelBody>
</Panel>
</div>
);
};

export default Settings;
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { set } from 'lodash';
import { __ } from '@wordpress/i18n';
import { useContext } from '@wordpress/element';
import { ToggleControl } from '@wordpress/components';

import getThemeOption from '../../../utils/get-theme-option';
import EditorContext from '../../context/EditorContext';
import StylesContext from '../../context/StylesContext';

/**
* Component for site appearance settings
*
* @param {Object} props Component props
* @param {string} props.selector Property target selector
* @param {string} props.description Property description
*/
const SettingsAppearanceTools = ( { selector, description } ) => {
const { userConfig, themeConfig } = useContext( EditorContext );
const { setUserConfig } = useContext( StylesContext );
const value = getThemeOption( selector, themeConfig ) || {};

const handleNewValue = ( newValue, key ) => {
let config = structuredClone( userConfig );
config = set( config, [ selector, key ].join( '.' ), newValue );
setUserConfig( config );
};

return (
<>
<span className="themer--settings__item__title">
{ __( 'Appearance Tools', 'themer' ) }
</span>
{ description && (
<p className="themer--settings__item__description">
{ description }
</p>
) }
<ToggleControl
label={ __( 'Appearance Tools', 'themer' ) }
checked={ value?.appearanceTools }
onChange={ ( newValue ) =>
handleNewValue( newValue, 'appearanceTools' )
}
/>
<ToggleControl
label={ __( 'Use Root Padding Aware Alignments', 'themer' ) }
checked={ value?.useRootPaddingAwareAlignments }
onChange={ ( newValue ) =>
handleNewValue( newValue, 'useRootPaddingAwareAlignments' )
}
/>
</>
);
};

export default SettingsAppearanceTools;
56 changes: 56 additions & 0 deletions src/editor/components/ComponentSettings/SettingsBackground.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { set } from 'lodash';
import { __ } from '@wordpress/i18n';
import { useContext } from '@wordpress/element';
import { ToggleControl } from '@wordpress/components';

import getThemeOption from '../../../utils/get-theme-option';
import EditorContext from '../../context/EditorContext';
import StylesContext from '../../context/StylesContext';

/**
* Component for background settings
*
* @param {Object} props Component props
* @param {string} props.selector Property target selector
* @param {string} props.description Property description
*/
const BackgroundSettings = ( { selector, description } ) => {
const { userConfig, themeConfig } = useContext( EditorContext );
const { setUserConfig } = useContext( StylesContext );
const value = getThemeOption( selector, themeConfig ) || {};

const handleNewValue = ( newValue, key ) => {
let config = structuredClone( userConfig );
config = set( config, [ selector, key ].join( '.' ), newValue );
setUserConfig( config );
};

return (
<>
<span className="themer--settings__item__title">
{ __( 'Background', 'themer' ) }
</span>
{ description && (
<p className="themer--settings__item__description">
{ description }
</p>
) }
<ToggleControl
label={ __( 'Background Image', 'themer' ) }
checked={ value?.backgroundImage }
onChange={ ( newValue ) =>
handleNewValue( newValue, 'backgroundImage' )
}
/>
<ToggleControl
label={ __( 'Background Size', 'themer' ) }
checked={ value?.backgroundSize }
onChange={ ( newValue ) =>
handleNewValue( newValue, 'backgroundSize' )
}
/>
</>
);
};

export default BackgroundSettings;
64 changes: 64 additions & 0 deletions src/editor/components/ComponentSettings/SettingsBorder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { set } from 'lodash';
import { __ } from '@wordpress/i18n';
import { useContext } from '@wordpress/element';
import { ToggleControl } from '@wordpress/components';

import getThemeOption from '../../../utils/get-theme-option';
import EditorContext from '../../context/EditorContext';
import StylesContext from '../../context/StylesContext';

/**
* Component for border settings
*
* @param {Object} props Component props
* @param {string} props.selector Property target selector
* @param {string} props.description Property description
*/
const SettingsBorder = ( { selector, description } ) => {
const { userConfig, themeConfig } = useContext( EditorContext );
const { setUserConfig } = useContext( StylesContext );
const value = getThemeOption( selector, themeConfig ) || {};

const handleNewValue = ( newValue, key ) => {
let config = structuredClone( userConfig );
config = set( config, [ selector, key ].join( '.' ), newValue );
setUserConfig( config );
};

return (
<>
<span className="themer--settings__item__title">
{ __( 'Border Settings', 'themer' ) }
</span>
{ description && (
<p className="themer--settings__item__description">
{ description }
</p>
) }
<ToggleControl
label={ __( 'Color', 'themer' ) }
checked={ value?.color }
onChange={ ( newValue ) => handleNewValue( newValue, 'color' ) }
/>
<ToggleControl
label={ __( 'Radius', 'themer' ) }
checked={ value?.radius }
onChange={ ( newValue ) =>
handleNewValue( newValue, 'radius' )
}
/>
<ToggleControl
label={ __( 'Style', 'themer' ) }
checked={ value?.style }
onChange={ ( newValue ) => handleNewValue( newValue, 'style' ) }
/>
<ToggleControl
label={ __( 'Width', 'themer' ) }
checked={ value?.width }
onChange={ ( newValue ) => handleNewValue( newValue, 'width' ) }
/>
</>
);
};

export default SettingsBorder;
Loading