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

Add Import/Export theme settings on switcher #30

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Next Next commit
Add Import/Export on theme editor popover
  • Loading branch information
phpbits committed Jun 9, 2020
commit 96a36f272c46e28e66d3af8ab0bee2f4fce97b4e
54 changes: 54 additions & 0 deletions src/components/theme-import-export/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { Fragment, Component } from '@wordpress/element';
import { withDispatch } from '@wordpress/data';
import { compose, withInstanceId } from '@wordpress/compose';
import {
MenuGroup,
MenuItem,
BaseControl,
RangeControl,
SelectControl,
withSpokenMessages,
} from '@wordpress/components';

class ThemeImportExport extends Component {
constructor() {
super( ...arguments );

this.state = {
updatedSettings: {},
};
}
componentDidMount() {
this.setState( { updatedSettings: this.props.themeSettings } );
}
render() {
const {
onToggle,
onClose,
themeSettings,
loadConfig,
isEditingTypography,
updateState,
} = this.props;

return <Fragment>asdfasdf</Fragment>;
}
}

export default compose( [
withInstanceId,
withDispatch( ( dispatch ) => {
const { setThemeSettings } = dispatch( 'iceberg-settings' );

return {
updateThemeSettings( settings ) {
setThemeSettings( settings );
},
};
} ),
withSpokenMessages,
] )( ThemeImportExport );
46 changes: 43 additions & 3 deletions src/components/theme-switcher/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { map, merge, assign, get } from 'lodash';
import defaults from '../theme-editor/default';
import EditorThemes from '../theme-editor/editor-themes';
import ThemeEditor from '../theme-editor';
import ThemeImportExport from '../theme-import-export';
import icons from '../icons';
import { assignVariables } from './variables';
import difference from './utils/difference';
Expand Down Expand Up @@ -47,6 +48,7 @@ class ThemeSwitcher extends Component {
isEditorThemeLoaded: false,
isEditingTheme: false,
isEditingTypography: false,
isImportExport: false,
};
}

Expand Down Expand Up @@ -162,7 +164,10 @@ class ThemeSwitcher extends Component {
}
}

this.setState( { isEditingTypography: false } );
this.setState( {
isEditingTypography: false,
isImportExport: false,
} );
updateThemeSettings( this.state.themeSettings );
};

Expand Down Expand Up @@ -269,7 +274,8 @@ class ThemeSwitcher extends Component {
renderContent={ ( { onToggle } ) => (
<Fragment>
{ ! this.state.isEditingTheme &&
! this.state.isEditingTypography ? (
! this.state.isEditingTypography &&
! this.state.isImportExport ? (
<Fragment>
<MenuGroup>
{ map(
Expand Down Expand Up @@ -358,9 +364,30 @@ class ThemeSwitcher extends Component {
) }
{ icons.typography }
</MenuItem>
<MenuItem
className="components-iceberg-theme-switcher__export"
onClick={ () => {
this.setState( {
isEditingTheme: false,
isEditingTypography: false,
isImportExport: true,
} );
this.onEditTheme(
onToggle,
'isImportExport'
);
} }
>
{ __(
'Import / Export',
'iceberg'
) }
</MenuItem>
</MenuGroup>
</Fragment>
) : (
) : null }
{ ! this.state.isEditingTheme &&
! this.state.isEditingTypography ? null : (
<ThemeEditor
onToggle={ onToggle }
loadConfig={ this.loadConfig }
Expand All @@ -383,6 +410,19 @@ class ThemeSwitcher extends Component {
} }
/>
) }

{ this.state.isImportExport && (
<ThemeImportExport
onToggle={ onToggle }
onClose={ () => {
this.setState( {
isEditingTheme: false,
isEditingTypography: false,
} );
this.onExitEditTheme( onToggle );
} }
/>
) }
</Fragment>
) }
/>
Expand Down