PluginProbe
AI Builder – Generate pages, blocks, images & translate with AI / 2.1.3
AI Builder – Generate pages, blocks, images & translate with AI v2.1.3
2.8.0 2.7.10 2.7.9 2.7.8 2.0.8 2.0.9 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.3.0 All 123 releases
ai-builder / assets / js / src / editor-blocks / stat-bar / index.js

index.js in AI Builder – Generate pages, blocks, images & translate with AI 2.1.3, at assets/js/src/editor-blocks/stat-bar/index.js

86 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { __ } from "@wordpress/i18n";
2 import { registerBlockType } from "@wordpress/blocks";
3 import { InspectorControls, PanelColorSettings } from "@wordpress/block-editor";
4 import { PanelBody, RangeControl, TextControl } from "@wordpress/components";
5 import "./stat-bar.css";
6
7 registerBlockType("ai-builder/stat-bar", {
8 title: __("Stat Bar", "ai-builder"),
9 icon: "chart-bar",
10 category: "widgets",
11 attributes: {
12 value: {
13 type: "number",
14 default: 75,
15 },
16 color: {
17 type: "string",
18 default: "#2563eb",
19 },
20 label: {
21 type: "string",
22 default: "75%",
23 },
24 },
25 edit: ({ attributes, setAttributes }) => {
26 const { value, color, label } = attributes;
27 return (
28 <div className="ai-stat-bar-editor">
29 <InspectorControls>
30 <PanelBody title={__("Stat Bar Settings", "ai-builder")}>
31 <RangeControl
32 label={__("Value (%)", "ai-builder")}
33 value={value}
34 onChange={(val) => {
35 setAttributes({ value: val, label: `${val}%` });
36 }}
37 min={0}
38 max={100}
39 />
40 <TextControl
41 label={__("Label", "ai-builder")}
42 value={label}
43 onChange={(val) => setAttributes({ label: val })}
44 />
45 </PanelBody>
46 <PanelColorSettings
47 title={__("Bar Color", "ai-builder")}
48 colorSettings={[
49 {
50 value: color,
51 onChange: (val) => setAttributes({ color: val }),
52 label: __("Bar Color", "ai-builder"),
53 },
54 ]}
55 />
56 </InspectorControls>
57 <div className="ai-stat-bar-preview">
58 <div className="ai-stat-bar-track" style={{ background: "#e5e7eb" }}>
59 <div
60 className="ai-stat-bar-fill"
61 style={{ width: `${value}%`, background: color }}
62 >
63 <span className="ai-stat-bar-label">{label}</span>
64 </div>
65 </div>
66 </div>
67 </div>
68 );
69 },
70 save: ({ attributes }) => {
71 const { value, color, label } = attributes;
72 return (
73 <div className="ai-stat-bar-frontend">
74 <div className="ai-stat-bar-track" style={{ background: "#e5e7eb" }}>
75 <div
76 className="ai-stat-bar-fill"
77 style={{ width: `${value}%`, background: color }}
78 >
79 <span className="ai-stat-bar-label">{label}</span>
80 </div>
81 </div>
82 </div>
83 );
84 },
85 });
86