Changes to directory structure

This commit is contained in:
Jeremy Rangel
2024-12-18 02:27:09 -08:00
parent d5a5f4e87b
commit 94d2c7c8a2
135 changed files with 335 additions and 5435 deletions

View File

@ -0,0 +1,41 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"name": "lcp/key-points",
"version": "0.1.0",
"title": "Key Points",
"category": "widgets",
"icon": "smiley",
"description": "Key points meta field for single posts",
"example": {},
"supports": {
"html": false
},
"attributes": {
"heading": {
"type": "string",
"default": "Key Points"
},
"headingTag": {
"type": "string",
"default": "h3"
},
"headingFontSizeLarge": {
"type": "string",
"default": "24px"
},
"pointsFontSizeLarge": {
"type": "string",
"default": "16px"
},
"listStyleType": {
"type": "string",
"default": "disc"
}
},
"textdomain": "key-points",
"editorScript": "file:./index.js",
"editorStyle": "file:./index.css",
"style": "file:./style-index.css",
"viewScript": "file:./view.js"
}

View File

@ -0,0 +1,118 @@
import { __ } from '@wordpress/i18n';
import { useBlockProps, InspectorControls } from '@wordpress/block-editor';
import { SelectControl, FontSizePicker, TextControl } from '@wordpress/components';
import { useState, useEffect } from 'react';
import './editor.scss';
export default function Edit( { attributes, setAttributes } ) {
const { heading, pointsFontSizeLarge, headingFontSizeLarge, listStyleType } = attributes;
const fontSizes = [
{
name: __( 'Small', 'key-points' ),
slug: 'small',
size: '12px',
},
{
name: __( 'Medium', 'key-points' ),
slug: 'medium',
size: '16px',
},
{
name: __( 'Large', 'key-points' ),
slug: 'large',
size: '24px',
},
{
name: __( 'Extra Large', 'key-points' ),
slug: 'x-large',
size: '36px',
},
];
const listStyleTypeOptions = [
{ label: __( 'Disc', 'lcp' ), value: 'disc' },
{ label: __( 'Circle', 'lcp' ), value: 'circle' },
{ label: __( 'Square', 'lcp' ), value: 'square' },
{ label: __( 'None', 'lcp' ), value: 'none' },
];
// Static Lorem Ipsum key points (5 unique points)
const loremIpsumPoints = [
"Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
"Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
"Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.",
"Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.",
"Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
];
const [keyPoints, setKeyPoints] = useState(loremIpsumPoints); // Set initial key points to the Lorem Ipsum array
return (
<>
{/* Inspector Controls */}
<InspectorControls>
{/* List Style Dropdown */}
<SelectControl
label={ __( 'List Style', 'lcp' ) }
value={ listStyleType }
options={ listStyleTypeOptions }
onChange={ ( newValue ) => {
setAttributes( { listStyleType: newValue } );
} }
/>
{/* Heading Input */}
<TextControl
label={ __( 'Heading', 'lcp' ) }
value={ heading || '' }
onChange={ ( newHeading ) => setAttributes( { heading: newHeading } ) }
/>
{/* Font Size Picker for Points */}
<FontSizePicker
fontSizes={ fontSizes }
units={ ['px', 'em', 'rem', 'vw', 'vh'] }
value={ pointsFontSizeLarge }
onChange={ ( newFontSize ) => {
if ( typeof newFontSize === 'string' ) {
setAttributes( { pointsFontSizeLarge: newFontSize } );
}
} }
fallbackFontSize={ '16px' }
/>
{/* Font Size Picker for Heading */}
<FontSizePicker
fontSizes={ fontSizes }
units={ ['px', 'em', 'rem', 'vw', 'vh'] }
value={ headingFontSizeLarge }
onChange={ ( newFontSize ) => {
if ( typeof newFontSize === 'string' ) {
setAttributes( { headingFontSizeLarge: newFontSize } );
}
} }
fallbackFontSize={ '24px' }
/>
</InspectorControls>
{/* Block Content */}
<p { ...useBlockProps() }>
{ __( 'Key Points hello from the editor!', 'lcp' ) }
</p>
{ heading && <h2>{ heading }</h2> }
{/* Display key points */}
{ keyPoints && keyPoints.length > 0 && (
<ul style={{ listStyleType: listStyleType }}>
{keyPoints.map((point, index) => (
<li key={index} style={{ fontSize: pointsFontSizeLarge }}>
{point}
</li>
))}
</ul>
)}
</>
);
}

View File

@ -0,0 +1,9 @@
/**
* The following styles get applied inside the editor only.
*
* Replace them with your own styles or remove the file completely.
*/
.wp-block-create-block-key-points {
border: 1px dotted #f00;
}

View File

@ -0,0 +1,39 @@
/**
* Registers a new block provided a unique name and an object defining its behavior.
*
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/
*/
import { registerBlockType } from '@wordpress/blocks';
/**
* Lets webpack process CSS, SASS or SCSS files referenced in JavaScript files.
* All files containing `style` keyword are bundled together. The code used
* gets applied both to the front of your site and to the editor.
*
* @see https://www.npmjs.com/package/@wordpress/scripts#using-css
*/
import './style.scss';
/**
* Internal dependencies
*/
import Edit from './edit';
import save from './save';
import metadata from './block.json';
/**
* Every block starts by registering a new block type definition.
*
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/
*/
registerBlockType( metadata.name, {
/**
* @see ./edit.js
*/
edit: Edit,
/**
* @see ./save.js
*/
save,
} );

View File

@ -0,0 +1,22 @@
/**
* React hook that is used to mark the block wrapper element.
* It provides all the necessary props like the class name.
*
* @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/#useblockprops
*/
import { useBlockProps } from '@wordpress/block-editor';
/**
* The save function defines the way in which the different attributes should
* be combined into the final markup, which is then serialized by the block
* editor into `post_content`.
*
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-edit-save/#save
*
* @return {Element} Element to render.
*/
export default function save() {
return (
null
);
}

View File

@ -0,0 +1,12 @@
/**
* The following styles get applied both on the front of your site
* and in the editor.
*
* Replace them with your own styles or remove the file completely.
*/
.wp-block-create-block-key-points {
background-color: #21759b;
color: #fff;
padding: 2px;
}

View File

@ -0,0 +1,25 @@
/**
* Use this file for JavaScript code that you want to run in the front-end
* on posts/pages that contain this block.
*
* When this file is defined as the value of the `viewScript` property
* in `block.json` it will be enqueued on the front end of the site.
*
* Example:
*
* ```js
* {
* "viewScript": "file:./view.js"
* }
* ```
*
* If you're not making any changes to this file because your project doesn't need any
* JavaScript running in the front-end, then you should delete this file and remove
* the `viewScript` property from `block.json`.
*
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-metadata/#view-script
*/
/* eslint-disable no-console */
console.log( 'Hello World! (from create-block-key-points block)' );
/* eslint-enable no-console */