承接 agencenous/blocss 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

agencenous/blocss

最新稳定版本:0.3.4

Composer 安装命令:

composer require agencenous/blocss

包简介

CSS editor for elements in Wordpress blocks

README 文档

README

Two in one CSS editor for elements in Wordpress blocks.

  • The @agencenous/blocss NPM library to use in block editor
  • The agencenous/blocss Composer library to use in the PHP callback function

Frontend

You can add style attributes to your blocks. It will allow editors to apply style in the editor UI.

Add the depency:

npm install @agencenous/blocss

Just add attributes in the block.json file. If you need to manage many styles, no pronlem, you can add as many attributes as you need.

{
    "attributes": {
        "boxStyle":  {
            "type": "object",
            "default": {
                "fontSize": "1em",
                "backgroudColor": "#ff0000"
            }
        },
        "itemStyle":  {
            "type": "object",
            "default": {
                "fontSize": "1em",
                "color": "#ffffff"
            }
        }
    }
}

In the editor, use the npm library

const { InspectorControls, useBlockProps } = wp.blockEditor;
import { PanelBody } from '@wordpress/components';
import { StyleControl } from '@agencenous/blocss';

const blockProps = useBlockProps();
const { 
    boxStyle,
    itemStyle,
    } = attributes;

const edit = ({ setAttributes, attributes }) => {
    return (
        <div className={className} {...blockProps}>
            <InspectorControls>
                <PanelBody title={__("Box")} initialOpen={true}>
                    <StyleControl
                        value={boxStyle}
                        font={{
                            size: true,
                        }}
                        color={{
                            background: true
                        }}
                        onChange={(value) => setAttributes({ boxStyle: value })}
                    />
                </PanelBody>
                <PanelBody title={__("Items")} initialOpen={true}>
                    <StyleControl
                        value={itemStyle}
                        border={{
                            radius: true,
                            width: true,
                            color: true,
                            style: true,
                        }}
                        box={{
                            padding: true,
                            margin: true,
                        }}
                        onChange={(value) => setAttributes({ itemStyle: value })}
                    />
                </PanelBody>
            </InspectorControls>
        </div>
)};

Backend

In the callback, use the composer library

composer install agencenous/blocss
function myblock_render_callback($attributes) {
    $block_id = 'my-block-' . uniqid();
    $css_rules = [
        '.my-block' => $attributes['boxStyle'],
        '.my-block .block-item' => $attributes['itemStyle'],
    ];
    return '<div id="'.esc_attr($block_id).'" class="my-block">
        <h3>My block</h3>
        <div class="block-item">Item 1</div>
        <div class="block-item">Item 2</div>
    </div>'.Blocss\inline_styles($css_rules, '#' . $block_id);
}

统计信息

  • 总下载量: 159
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 5
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: JavaScript

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2025-11-27

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固