-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
192 additions
and
1 deletion.
There are no files selected for viewing
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,70 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/block.json", | ||
"apiVersion": 2, | ||
"name": "givewp/campaign-list-block", | ||
"version": "1.0.0", | ||
"title": "Campaign List Block", | ||
"category": "give", | ||
"description": "Insert an existing campaign into the page.", | ||
"supports": { | ||
"align": [ | ||
"wide", | ||
"full", | ||
"left", | ||
"center", | ||
"right" | ||
] | ||
}, | ||
"attributes": { | ||
"layout": { | ||
"type": "string", | ||
"default": "full", | ||
"enum": [ | ||
"full", | ||
"full" | ||
] | ||
}, | ||
"showImage": { | ||
"type": "boolean", | ||
"default": true | ||
}, | ||
"showDescription": { | ||
"type": "boolean", | ||
"default": true | ||
}, | ||
"showGoal": { | ||
"type": "boolean", | ||
"default": true | ||
}, | ||
"sortBy": { | ||
"type": "string", | ||
"default": "date", | ||
"enum": [ | ||
"date" | ||
] | ||
}, | ||
"orderBy": { | ||
"type": "string", | ||
"default": "desc", | ||
"enum": [ | ||
"asc", | ||
"desc" | ||
] | ||
}, | ||
"filterBy": { | ||
"type": "array", | ||
"default": [] | ||
}, | ||
"perPage": { | ||
"type": "number", | ||
"default": "6" | ||
}, | ||
"showPagination": { | ||
"type": "boolean", | ||
"default": true | ||
} | ||
}, | ||
"textdomain": "give", | ||
"editorScript": "file:../../../../build/campaignListBlock.js", | ||
"render": "file:./render.php" | ||
} |
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,98 @@ | ||
import {__} from '@wordpress/i18n'; | ||
import {InspectorControls, useBlockProps} from '@wordpress/block-editor'; | ||
import {BlockEditProps} from '@wordpress/blocks'; | ||
import {FormTokenField, PanelBody, SelectControl, ToggleControl} from '@wordpress/components'; | ||
import {TokenItem} from "@wordpress/components/build-types/form-token-field/types" | ||
import useCampaigns from "../shared/hooks/useCampaigns"; | ||
|
||
export default function Edit({attributes, setAttributes}: BlockEditProps<{ | ||
layout: string; | ||
showImage: boolean; | ||
showDescription: boolean; | ||
showGoal: boolean; | ||
showPagination: boolean; | ||
sortBy: string; | ||
orderBy: string; | ||
filterBy: (string | TokenItem)[]; | ||
perPage: number; | ||
}>) { | ||
const blockProps = useBlockProps(); | ||
const {campaigns, hasResolved} = useCampaigns(); | ||
|
||
return ( | ||
<div {...blockProps}> | ||
{hasResolved && ( | ||
<InspectorControls> | ||
<PanelBody title={__('Layout', 'give')} initialOpen={true}> | ||
<SelectControl | ||
label={__('Grid', 'give')} | ||
onChange={(layout: string) => setAttributes({layout})} | ||
options={[ | ||
{ | ||
value: 'full', | ||
label: __('Full', 'give'), | ||
} | ||
]} | ||
/> | ||
</PanelBody> | ||
|
||
<PanelBody title={__('Display Elements', 'give')} initialOpen={true}> | ||
<ToggleControl | ||
label={__('Show campaign image', 'give')} | ||
checked={attributes.showImage} | ||
onChange={(showImage) => setAttributes({showImage})} | ||
/> | ||
<ToggleControl | ||
label={__('Show description', 'give')} | ||
checked={attributes.showDescription} | ||
onChange={(showDescription) => setAttributes({showDescription})} | ||
/> | ||
<ToggleControl | ||
label={__('Show goal', 'give')} | ||
checked={attributes.showGoal} | ||
onChange={(showGoal) => setAttributes({showGoal})} | ||
/> | ||
</PanelBody> | ||
|
||
<PanelBody title={__('Grid Settings', 'give')} initialOpen={true}> | ||
<SelectControl | ||
label={__('Order By', 'give')} | ||
onChange={(sortBy: string) => setAttributes({sortBy})} | ||
help={__('The order campaigns are displayed in.', 'give')} | ||
options={[ | ||
{ | ||
value: 'date', | ||
label: __('Date Created', 'give'), | ||
} | ||
]} | ||
/> | ||
<SelectControl | ||
label={__('Order', 'give')} | ||
onChange={(orderBy: string) => setAttributes({orderBy})} | ||
help={__('Choose whether the campaign order ascends or descends.', 'give')} | ||
options={[ | ||
{ | ||
value: 'desc', | ||
label: __('Descending', 'give'), | ||
}, | ||
{ | ||
value: 'asc', | ||
label: __('Ascending', 'give'), | ||
} | ||
]} | ||
/> | ||
<FormTokenField | ||
value={attributes.filterBy} | ||
label={__('Filter by Campaign', 'give')} | ||
onChange={(filterBy) => setAttributes({filterBy})} | ||
suggestions={campaigns?.map((campaign) => ({ | ||
value: String(campaign.id), | ||
title: campaign.title | ||
}))} | ||
/> | ||
</PanelBody> | ||
</InspectorControls> | ||
)} | ||
</div> | ||
) | ||
} |
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,14 @@ | ||
import metadata from './block.json'; | ||
import Edit from './edit'; | ||
import initBlock from '../shared/utils/init-block'; | ||
import GiveIcon from '@givewp/components/GiveIcon'; | ||
|
||
const {name} = metadata; | ||
|
||
export {metadata, name}; | ||
export const settings = { | ||
edit: Edit, | ||
icon: <GiveIcon color="gray"/>, | ||
}; | ||
|
||
export const init = () => initBlock({name, metadata, settings}); |
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,7 @@ | ||
<?php | ||
|
||
/** | ||
* @var array $attributes | ||
*/ | ||
print_r($attributes); | ||
|
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