Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 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
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
31 changes: 31 additions & 0 deletions accordion/accordion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* Plugin Name: Accordion
* Description: Container block for accordion items.
* Requires at least: 6.1
* Requires PHP: 7.0
* Version: 0.1.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 wpsp_accordion_block_init() {
register_block_type( __DIR__ . '/build/accordion' );
register_block_type( __DIR__ . '/build/accordion-item' );
}
add_action( 'init', 'wpsp_accordion_block_init' );
27 changes: 27 additions & 0 deletions accordion/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "accordion",
"version": "0.1.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/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.1.0
License: GPL-2.0-or-later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Container block for accordion items.

== 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-item/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": "wpsp/accordion-item",
"version": "0.1.0",
"title": "Accordion Item",
"category": "design",
"icon": "button",
"description": "Accordion item block for displaying hidden content via a toggle.",
"example": {},
"parent": [ "wpsp/accordion" ],
"supports": {
"color": {
"background": true,
"gradient": true
},
"align": 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": {
"openByDefault": {
"type": "boolean",
"default": false
},
"title": {
"type": "rich-text",
"source": "rich-text",
"selector": "span"
},
"level": {
"type": "number",
"default": 3
}
},
"textdomain": "accordion",
"editorScript": "file:./index.js",
"render": "file:./render.php"
}
80 changes: 80 additions & 0 deletions accordion/src/accordion-item/edit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import clsx from 'clsx';
import { __ } from '@wordpress/i18n';
import {
useBlockProps,
useInnerBlocksProps,
InspectorControls,
BlockControls,
HeadingLevelDropdown,
RichText,
} from '@wordpress/block-editor';
import {
PanelBody,
PanelRow,
ToggleControl,
ToolbarGroup,
} from '@wordpress/components';

export default function Edit( { attributes, setAttributes } ) {
const { openByDefault, level, title, iconPosition } = attributes;
const TagName = 'h' + level;

const headingClassName = clsx( {
'wpsp-accordion-item__heading': true,
'icon-position-left': iconPosition === 'left',
} );

const innerBlocksProps = useInnerBlocksProps( {
className: 'wpsp-accordion-item__content',
} );

return (
<>
<BlockControls>
<ToolbarGroup>
<HeadingLevelDropdown
value={ level }
onChange={ ( newLevel ) =>
setAttributes( { level: newLevel } )
}
/>
</ToolbarGroup>
</BlockControls>
<InspectorControls key="setting">
<PanelBody title={ __( 'Display' ) }>
<PanelRow>
<ToggleControl
label={ __( 'Open by default' ) }
onChange={ ( value ) => {
setAttributes( {
openByDefault: value,
} );
} }
checked={ openByDefault }
/>
</PanelRow>
</PanelBody>
</InspectorControls>
<div
{ ...useBlockProps( {
className: 'is-open', // Force the editing interface to be open for now.
} ) }
>
<TagName className={ headingClassName }>
<button className="wpsp-accordion-item__toggle">
<RichText
disableLineBreaks
tagName="span"
value={ title }
onChange={ ( newTitle ) =>
setAttributes( { title: newTitle } )
}
placeholder={ __( 'Add text...' ) }
/>
</button>
</TagName>
<div { ...innerBlocksProps } />
</div>
</>
);
}
9 changes: 9 additions & 0 deletions accordion/src/accordion-item/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { registerBlockType } from '@wordpress/blocks';
import Edit from './edit';
import save from './save';
import metadata from './block.json';

registerBlockType( metadata.name, {
edit: Edit,
save,
} );
33 changes: 33 additions & 0 deletions accordion/src/accordion-item/render.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
$p = new WP_HTML_Tag_Processor( $content );
$unique_id = wp_unique_id( 'wpsp-accordion-item-' );

while ( $p->next_tag() ){
if ( $p->has_class( 'wp-block-wpsp-accordion-item') ) {
$p->set_attribute( 'data-id', $unique_id );
$p->set_attribute( 'data-wp-class--is-open', 'state.isOpen' );
}
}

$content = $p->get_updated_html();
$p = new WP_HTML_Tag_Processor( $content );

while ( $p->next_tag() ){
if ( $p->has_class( 'wpsp-accordion-item__toggle' ) ) {
$p->set_attribute( 'data-wp-on--click', 'actions.toggle' );
$p->set_attribute( 'aria-controls', $unique_id );
}
}

$content = $p->get_updated_html();
$p = new WP_HTML_Tag_Processor( $content );

while ( $p->next_tag() ){
if ( $p->has_class( 'wpsp-accordion-item__content' ) ) {
$p->set_attribute( 'id', $unique_id );
$p->set_attribute( 'data-wp-bind--aria-expanded', 'state.isOpen' );
$p->set_attribute( 'data-wp-bind--aria-hidden', '!state.isOpen' );
}
}

echo $p->get_updated_html();
32 changes: 32 additions & 0 deletions accordion/src/accordion-item/save.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import clsx from 'clsx';
import { __ } from '@wordpress/i18n';
import {
useBlockProps,
useInnerBlocksProps,
RichText,
} from '@wordpress/block-editor';

export default function save( { attributes } ) {
const { level, title, iconPosition } = attributes;
const TagName = 'h' + level;

const headingClassName = clsx( {
'wpsp-accordion-item__heading': true,
'icon-position-left': iconPosition === 'left',
} );

return (
<div { ...useBlockProps.save() }>
<TagName className={ headingClassName }>
<button className="wpsp-accordion-item__toggle">
<RichText.Content tagName="span" value={ title } />
</button>
</TagName>
<div
{ ...useInnerBlocksProps.save( {
className: 'wpsp-accordion-item__content',
} ) }
/>
</div>
);
}
Loading