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

Implement Accordion Block Plugin #16

Open
wants to merge 77 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
8897a61
Initial commit.
jffng Jun 12, 2024
bb67231
Use interactivity API.
jffng Jun 12, 2024
e7bf6d4
Incorporate heading level.
jffng Jun 14, 2024
541f88a
Add text align.
jffng Jun 14, 2024
dbb822d
Scaffold an icon for the accordion title.
jffng Jun 18, 2024
7a5c73c
Convert to HTML tag processor.
jffng Jun 18, 2024
8c55763
Make classnames consistent.
jffng Jun 18, 2024
1299625
Fix accordion within accordion bug.
jffng Jun 20, 2024
71c3a4f
Add toggle and format.
jffng Jun 20, 2024
6f30b69
allow text align to work.
jffng Jun 20, 2024
dfc4070
Add layout support
jffng Jun 20, 2024
bce6ec9
Downgrade wp-scripts for now.
jffng Jun 20, 2024
b38778a
Add icon styles.
jffng Jun 21, 2024
ecf287c
Use background as mask instead.
jffng Jun 21, 2024
c206519
Rename to accordion-item.
jffng Jun 21, 2024
12ee418
Format.
jffng Jun 21, 2024
7db5ca6
Format.
jffng Jun 21, 2024
129713c
Update colors.
jffng Jun 21, 2024
b6ff4be
Add setting for icon position.
jffng Jun 24, 2024
11d2c9a
Allow no icon option.
jffng Jun 25, 2024
b03af8d
Replace with custom icon.
jffng Jun 25, 2024
8126131
Convert to two blocks.
jffng Jul 1, 2024
c27583c
Refactor iAPI.
jffng Jul 1, 2024
e6939c5
Fix icon display.
jffng Jul 1, 2024
1a2728c
Remove unused CSS for now.
jffng Jul 1, 2024
180c4db
Make id more specific.
jffng Jul 2, 2024
ec1b458
Remove zip.
jffng Jul 2, 2024
4ebfc34
Remove comments.
jffng Jul 2, 2024
1db0e5f
Allow multiple accordion items.
jffng Jul 2, 2024
d186c0a
WIP.
jffng Jul 2, 2024
c4f5737
Fix array filtering bug.
jffng Jul 9, 2024
c098b30
Cleanup unused classes.
jffng Jul 9, 2024
cbd7dee
Refactor so styles live at top level block and no need for textAlign.
jffng Jul 9, 2024
185a97f
Update server side register with correct block names.
jffng Jul 9, 2024
610031a
Simplify to accordion item.
jffng Jul 11, 2024
8cb37fe
Fix classes and format.
jffng Jul 11, 2024
ce78480
Add support for border and typography.
jffng Jul 12, 2024
9bd3ab0
Enable more typography and border support.
jffng Jul 12, 2024
c78d40f
Remove build files.
jffng Jul 16, 2024
cb175fe
Ignore package-lock
jffng Jul 16, 2024
9880187
Remove editorconfig.
jffng Jul 16, 2024
91889f5
Adds css grid based animation.
jffng Jul 16, 2024
1e1d4f0
Format.
jffng Jul 16, 2024
49ed8a7
Bump wordpress/scripts to highest 27.
jffng Jul 18, 2024
f5f7227
Add color support.
jffng Jul 18, 2024
0f06e5a
Enable multiple items to be open at once.
jffng Jul 18, 2024
119f118
Separate trigger and content blocks.
jffng Jul 18, 2024
fd12f83
Enable template locking.
jffng Jul 19, 2024
f491539
Enable open by default.
jffng Jul 19, 2024
5936210
Clean up.
jffng Jul 19, 2024
ecb268c
Replace icons with confusing ones.
jffng Jul 19, 2024
782b12b
Enable better icon positioning and sizing.
jffng Jul 19, 2024
e63b67f
Support anchors.
jffng Jul 19, 2024
7abda6a
Fix aria implementation.
jffng Jul 19, 2024
0988f95
Bump version.
jffng Jul 19, 2024
ab0a2a0
Fix how styles are applied.
jffng Jul 19, 2024
2b05962
Replace icons and simplify names.
jffng Jul 22, 2024
86fb66f
Remove padding controls because it messes up the show/hide behavior.
jffng Jul 22, 2024
d3b1079
Change the icon open/close states.
jffng Jul 22, 2024
80a866b
Fix icon color inheritance.
jffng Jul 22, 2024
9c40635
Add transition for only users who have no preference set.
jffng Jul 22, 2024
245a2bf
Fix clip and fillRule.
jffng Jul 24, 2024
8d2821a
Use wrapping div so padding can be applied as expected.
jffng Jul 24, 2024
7d8373b
Change setting name to autoclose and make false by default.
jffng Jul 24, 2024
75d516e
Fix icon.
jffng Jul 24, 2024
5169077
Move icons to settings of trigger.
jffng Jul 24, 2024
8929342
Rename.
jffng Jul 25, 2024
c5b4a3c
Reorder and label the icon options.
jffng Jul 25, 2024
a289d2e
Allow background image and only vertical margin.
jffng Jul 25, 2024
90344a3
Improve insertion UX.
jffng Jul 25, 2024
fac32de
Add back hidden html attribute.
jffng Jul 25, 2024
6a62f44
WIP determine if block is selected.
jffng Jul 25, 2024
81add00
Auto expand and close based on selection.
jffng Jul 26, 2024
9e604cf
More sensible placeholders.
jffng Jul 26, 2024
1da0a51
Fix ariaHidden -> aria-hidden.
jffng Jul 26, 2024
20ad058
Bump minor version.
jffng Jul 26, 2024
7338b2d
Force margin on wrapper div.
jffng Jul 30, 2024
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
35 changes: 35 additions & 0 deletions accordion/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Coverage directory used by tools like istanbul
coverage

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Output of `npm pack`
*.tgz

# Output of `wp-scripts plugin-zip`
*.zip

# dotenv environment variables file
.env

# Build files
build/

package-lock.json
33 changes: 33 additions & 0 deletions accordion/accordion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* Plugin Name: Accordion
* Description: Container block for accordion items.
* Requires at least: 6.1
* Requires PHP: 7.0
* Version: 0.3.0
* Author: Studio 51
* License: GPL-2.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: accordion
*
* @package Wpsp
*/

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}

/**
* Registers the block using the metadata loaded from the `block.json` file.
* Behind the scenes, it registers also all assets so they can be enqueued
* through the block editor in the corresponding context.
*
* @see https://developer.wordpress.org/reference/functions/register_block_type/
*/
function wpcomsp_accordion_block_init() {
register_block_type( __DIR__ . '/build/accordion-group' );
register_block_type( __DIR__ . '/build/accordion-item' );
register_block_type( __DIR__ . '/build/accordion-trigger' );
register_block_type( __DIR__ . '/build/accordion-content' );
}
add_action( 'init', 'wpcomsp_accordion_block_init' );
28 changes: 28 additions & 0 deletions accordion/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "accordion",
"version": "0.3.0",
"description": "Accordion block for displaying hidden content via a toggle.",
"author": "The WordPress Contributors",
"license": "GPL-2.0-or-later",
"main": "build/accordion-item/index.js",
"scripts": {
"build": "wp-scripts build --experimental-modules",
"format": "wp-scripts format",
"lint:css": "wp-scripts lint-style",
"lint:js": "wp-scripts lint-js",
"packages-update": "wp-scripts packages-update",
"plugin-zip": "wp-scripts plugin-zip",
"start": "wp-scripts start --experimental-modules"
},
"files": [
"[^.]*"
],
"dependencies": {
"@wordpress/interactivity": "^6.0.0",
"clsx": "^2.1.1"
},
"devDependencies": {
"@wordpress/icons": "^10.3.0",
"@wordpress/scripts": "^27.9.0"
}
}
55 changes: 55 additions & 0 deletions accordion/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
=== Accordion ===
Contributors: Studio 51
Tags: block
Tested up to: 6.1
Stable tag: 0.2.0
License: GPL-2.0-or-later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

An accordion block.

== Description ==

This is the long description. No limit, and you can use Markdown (as well as in the following sections).

For backwards compatibility, if this section is missing, the full length of the short description will be used, and
Markdown parsed.

== Installation ==

This section describes how to install the plugin and get it working.

e.g.

1. Upload the plugin files to the `/wp-content/plugins/accordion` directory, or install the plugin through the WordPress plugins screen directly.
1. Activate the plugin through the 'Plugins' screen in WordPress


== Frequently Asked Questions ==

= A question that someone might have =

An answer to that question.

= What about foo bar? =

Answer to foo bar dilemma.

== Screenshots ==

1. This screen shot description corresponds to screenshot-1.(png|jpg|jpeg|gif). Note that the screenshot is taken from
the /assets directory or the directory that contains the stable readme.txt (tags or trunk). Screenshots in the /assets
directory take precedence. For example, `/assets/screenshot-1.png` would win over `/tags/4.3/screenshot-1.png`
(or jpg, jpeg, gif).
2. This is the second screen shot

== Changelog ==

= 0.1.0 =
* Release

== Arbitrary section ==

You may provide arbitrary sections, in the same format as the ones above. This may be of use for extremely complicated
plugins where more information needs to be conveyed that doesn't fit into the categories of "description" or
"installation." Arbitrary sections will be shown below the built-in sections outlined above.
75 changes: 75 additions & 0 deletions accordion/src/accordion-content/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"name": "wpcomsp/accordion-content",
"version": "0.1.0",
"title": "Content",
"category": "design",
"description": "Accordion item content",
"example": {},
"parent": [ "wpcomsp/accordion-item" ],
"supports": {
"color": {
"background": true,
"gradient": true
},
"border": true,
"interactivity": true,
"spacing": {
"padding": true,
"margin": [ "top", "bottom" ],
"blockGap": true,
"__experimentalDefaultControls": {
"padding": true,
"blockGap": true
}
},
"__experimentalBorder": {
"color": true,
"radius": true,
"style": true,
"width": true,
"__experimentalDefaultControls": {
"color": true,
"radius": true,
"style": true,
"width": true
}
},
"typography": {
"fontSize": true,
"lineHeight": true,
"__experimentalFontFamily": true,
"__experimentalFontWeight": true,
"__experimentalFontStyle": true,
"__experimentalTextTransform": true,
"__experimentalTextDecoration": true,
"__experimentalLetterSpacing": true,
"__experimentalDefaultControls": {
"fontSize": true
}
},
"shadow": true,
"layout": true
},
"attributes": {
"allowedBlocks": {
"type": "array"
},
"templateLock": {
"type": [ "string", "boolean" ],
"enum": [ "all", "insert", "contentOnly", false ],
"default": false
},
"openByDefault": {
"type": "boolean",
"default": false
},
"isSelected": {
"type": "boolean",
"default": false
}
},
"textdomain": "accordion",
"editorScript": "file:./index.js"
}
56 changes: 56 additions & 0 deletions accordion/src/accordion-content/edit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { __ } from '@wordpress/i18n';
import {
useBlockProps,
useInnerBlocksProps,
__experimentalUseBorderProps as useBorderProps,
__experimentalUseColorProps as useColorProps,
__experimentalGetSpacingClassesAndStyles as useSpacingProps,
__experimentalGetShadowClassesAndStyles as useShadowProps,
} from '@wordpress/block-editor';
import clsx from 'clsx';

export default function Edit( { attributes } ) {
const { allowedBlocks, templateLock, openByDefault, isSelected } =
attributes;
const borderProps = useBorderProps( attributes );
const colorProps = useColorProps( attributes );
const spacingProps = useSpacingProps( attributes );
const shadowProps = useShadowProps( attributes );

const blockProps = useBlockProps();
const innerBlocksProps = useInnerBlocksProps(
{
className: 'wpcomsp-accordion-content__wrapper',
style: {
...spacingProps.style,
},
},
{
allowedBlocks,
template: [ [ 'core/paragraph', {} ] ],
templateLock,
}
);

return (
<div
{ ...blockProps }
className={ clsx(
blockProps.className,
colorProps.className,
borderProps.className,
{
[ `has-custom-font-size` ]: blockProps?.style?.fontSize,
}
) }
style={ {
...borderProps.style,
...colorProps.style,
...shadowProps.style,
} }
aria-hidden={ ! isSelected && ! openByDefault }
>
<div { ...innerBlocksProps } />
</div>
);
}
28 changes: 28 additions & 0 deletions accordion/src/accordion-content/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { registerBlockType } from '@wordpress/blocks';
import { SVG, Path } from '@wordpress/components';
import Edit from './edit';
import save from './save';
import metadata from './block.json';

const icon = (
<SVG
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<Path
fillRule="evenodd"
clipRule="evenodd"
d="M8.10417 6.00024H6.5C5.39543 6.00024 4.5 6.89567 4.5 8.00024V10.3336H6V8.00024C6 7.7241 6.22386 7.50024 6.5 7.50024H8.10417V6.00024ZM4.5 13.6669V16.0002C4.5 17.1048 5.39543 18.0002 6.5 18.0002H8.10417V16.5002H6.5C6.22386 16.5002 6 16.2764 6 16.0002V13.6669H4.5ZM10.3958 6.00024V7.50024H13.6042V6.00024H10.3958ZM15.8958 6.00024V7.50024H17.5C17.7761 7.50024 18 7.7241 18 8.00024V10.3336H19.5V8.00024C19.5 6.89567 18.6046 6.00024 17.5 6.00024H15.8958ZM19.5 13.6669H18V16.0002C18 16.2764 17.7761 16.5002 17.5 16.5002H15.8958V18.0002H17.5C18.6046 18.0002 19.5 17.1048 19.5 16.0002V13.6669ZM13.6042 18.0002V16.5002H10.3958V18.0002H13.6042Z"
fill="currentColor"
/>
</SVG>
);

registerBlockType( metadata.name, {
icon,
edit: Edit,
save,
} );
46 changes: 46 additions & 0 deletions accordion/src/accordion-content/save.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { __ } from '@wordpress/i18n';
import {
InnerBlocks,
useBlockProps,
__experimentalGetBorderClassesAndStyles as getBorderClassesAndStyles,
__experimentalGetColorClassesAndStyles as getColorClassesAndStyles,
__experimentalGetSpacingClassesAndStyles as getSpacingClassesAndStyles,
__experimentalGetShadowClassesAndStyles as getShadowClassesAndStyles,
} from '@wordpress/block-editor';
import clsx from 'clsx';

export default function save( { attributes } ) {
const blockProps = useBlockProps.save();
const borderProps = getBorderClassesAndStyles( attributes );
const colorProps = getColorClassesAndStyles( attributes );
const spacingProps = getSpacingClassesAndStyles( attributes );
const shadowProps = getShadowClassesAndStyles( attributes );

return (
<div
{ ...blockProps }
className={ clsx(
blockProps.className,
colorProps.className,
borderProps.className,
{
[ `has-custom-font-size` ]: blockProps?.style?.fontSize,
}
) }
style={ {
...borderProps.style,
...colorProps.style,
...shadowProps.style,
} }
>
<div
className="wpcomsp-accordion-content__wrapper"
style={ {
...spacingProps.style,
} }
>
<InnerBlocks.Content />
</div>
</div>
);
}
Loading