Skip to content

Commit

Permalink
Use existing copyright component in footer (#827)
Browse files Browse the repository at this point in the history
* use existing copyright component in footer

* removed typography component from copyright

* return getManifestByDir
  • Loading branch information
kancijan authored May 15, 2024
1 parent 341c42b commit b7f2e79
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { selector, checkAttr, classnames } from '@eightshift/frontend-libs/scripts';
import { RichText } from '@wordpress/block-editor';
import { selector, checkAttr, classnames, getAttrKey } from '@eightshift/frontend-libs/scripts';
import manifest from './../manifest.json';

export const CopyrightEditor = (attributes) => {
Expand All @@ -11,12 +12,12 @@ export const CopyrightEditor = (attributes) => {
selectorClass = componentClass,
blockClass,
additionalClass,
setAttributes
} = attributes;

const copyrightUse = checkAttr('copyrightUse', attributes, manifest);
const copyrightBy = checkAttr('copyrightBy', attributes, manifest);
const copyrightYear = checkAttr('copyrightYear', attributes, manifest) ?? new Date().getFullYear();
const copyrightContent = checkAttr('copyrightContent', attributes, manifest);
const copyrightYear = new Date().getFullYear();

const copyrightClass = classnames(
selector(componentClass, componentClass),
Expand All @@ -30,7 +31,12 @@ export const CopyrightEditor = (attributes) => {

return (
<div className={copyrightClass}>
&copy; {copyrightBy} {copyrightYear} - {copyrightContent}
&copy;{copyrightYear} | <RichText
value={copyrightContent}
onChange={(value) => setAttributes({ [getAttrKey('copyrightContent', attributes, manifest)]: value })}
keepPlaceholderOnFocus
allowedFormats={[]}
/>
</div>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react';
import { __ } from '@wordpress/i18n';
import { Toggle, checkAttr, getAttrKey } from '@eightshift/frontend-libs/scripts';
import manifest from '../manifest.json';

export const CopyrightOptions = (attributes) => {
const {
setAttributes
} = attributes;

const copyrightUse = checkAttr('copyrightUse', attributes, manifest);

return (
<Toggle
label={__('Copyright', 'eightshift-frontend-libs')}
checked={copyrightUse}
onChange={(value) => setAttributes({ [getAttrKey('copyrightUse', attributes, manifest)]: value })}
reducedBottomSpacing
/>
);
};
5 changes: 2 additions & 3 deletions blocks/init/src/Blocks/components/copyright/copyright.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
$blockClass = $attributes['blockClass'] ?? '';
$selectorClass = $attributes['selectorClass'] ?? $componentClass;

$copyrightBy = Components::checkAttr('copyrightBy', $attributes, $manifest);
$copyrightYear = Components::checkAttr('copyrightYear', $attributes, $manifest);
$copyrightYear = date('Y');
$copyrightContent = Components::checkAttr('copyrightContent', $attributes, $manifest);

$copyrightClass = Components::classnames([
Expand All @@ -32,5 +31,5 @@

?>
<div class="<?php echo esc_attr($copyrightClass); ?>">
<?php echo esc_html("&copy; {$copyrightBy} {$copyrightYear} - {$copyrightContent}"); ?>
<?php echo esc_html("&copy;{$copyrightYear} | {$copyrightContent}"); ?>
</div>
20 changes: 4 additions & 16 deletions blocks/init/src/Blocks/components/copyright/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,14 @@
"componentName": "copyright",
"title": "Copyright",
"componentClass": "copyright",
"example": {
"attributes": {
"copyrightBy": "Eightshift",
"copyrightContent": "Made with ❤️ by Team Eightshift",
"copyrightUse": true
}
},
"attributes": {
"copyrightBy": {
"type": "string"
},
"copyrightYear": {
"type": "string"
},
"copyrightContent": {
"type": "string"
},
"copyrightUse": {
"type": "boolean",
"default": true
},
"copyrightContent": {
"type": "string",
"default": "Made with ❤️ by Team Eightshift"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const SiteFooterEditor = ({ attributes, setAttributes }) => {
})}
/>

<ParagraphEditor
<CopyrightEditor
{...props('copyright', attributes, {
blockClass: blockClass,
selectorClass: 'copyright',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { PanelBody } from '@wordpress/components';
import { props } from '@eightshift/frontend-libs/scripts';
import { ImageOptions } from '../../../components/image/components/image-options';
import { SocialNetworksOptions } from '../../../components/social-networks/components/social-networks-options';
import { CopyrightOptions } from '../../../components/copyright/components/copyright-options';

export const SiteFooterOptions = ({ attributes, setAttributes }) => {
return (
Expand All @@ -16,6 +17,12 @@ export const SiteFooterOptions = ({ attributes, setAttributes }) => {
reducedBottomSpacing
/>

<CopyrightOptions
{...props('copyright', attributes, { setAttributes })}
label={__('Copyright', 'eightshift-frontend-libs')}
reducedBottomSpacing
/>

<SocialNetworksOptions
{...props('socialNetworks', attributes, { setAttributes })}
hideModeSelector
Expand Down
2 changes: 1 addition & 1 deletion blocks/init/src/Blocks/custom/site-footer/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"components": {
"logo": "image",
"copyright": "paragraph",
"copyright": "copyright",
"socialNetworks": "social-networks"
}
}
2 changes: 1 addition & 1 deletion blocks/init/src/Blocks/custom/site-footer/site-footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class="<?php echo esc_attr($linkClass); ?>"
echo Components::render('social-networks', Components::props('socialNetworks', $attributes, [
'blockClass' => $blockClass,
])),
Components::render('paragraph', Components::props('copyright', $attributes, [
Components::render('copyright', Components::props('copyright', $attributes, [
'blockClass' => $blockClass,
'selectorClass' => 'copyright',
]));
Expand Down

0 comments on commit b7f2e79

Please sign in to comment.