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

New Block: Implement progress bar block #68652

Open
wants to merge 15 commits into
base: trunk
Choose a base branch
from

Conversation

Infinite-Null
Copy link
Contributor

@Infinite-Null Infinite-Null commented Jan 14, 2025

Closes: #34219

What?

Added a new Progress Bar block to WordPress block editor that allows users to display customizable progress indicators.

Why?

Progress bars are essential UI elements for showing completion status or data visualization. Adding this as a block gives WordPress users a native way to display progress metrics without relying on external plugins or custom code.

How?

Implemented a new block type with the following:

  • Customizable progress value through a range control
  • Option to use as read progress
  • Adjustable bar height (1-30px)
  • Option to show/hide the progress value
  • Support for custom color settings

Testing Instructions

  1. Open the block editor
  2. Click the "+" icon to add a new block
  3. Search for and insert the "Progress Bar" block

Test the following features:

  • Adjust the progress value using the sidebar controls
  • Adjust option of use as read progress
  • Change the bar height using the range slider (1-30px)
  • Toggle the progress value display
  • Customize colors using the color picker
  • Verify the block renders correctly in both the editor and frontend

Screencast

Progress Bar:

Screen.Recording.2025-01-27.at.11.03.49.AM.mov

Use as read progress:

Screen.Recording.2025-01-27.at.11.06.47.AM.mov

@Infinite-Null Infinite-Null changed the title Implement meter progress block with basic controls New Block: Implement progress block Jan 14, 2025
@Infinite-Null Infinite-Null changed the title New Block: Implement progress block New Block: Implement progress bar block Jan 14, 2025
@Mamaduka Mamaduka added [Type] Enhancement A suggestion for improvement. New Block Suggestion for a new block labels Jan 14, 2025
- Introduced default attributes for `backgroundColor`, `progressColor`, `height`, and `showValue`.
- Added a `height` attribute to control the height of the progress bar dynamically.
- Added a `showValue` toggle to display the progress percentage.
- Replaced `TextControl` with `RichText` for the `label` attribute, enabling inline editing.
- Adjusted styles for better flexibility and customization.
- Updated `edit.js` and `save.js` to handle new attributes and functionality.
- Refactored progress bar rendering logic for cleaner output.
- Replaced `PanelBody` with `ToolsPanel` and `ToolsPanelItem` for settings organization.
- Added `resetAll` functionality to `ToolsPanel` for resetting all attributes to default values.
- Integrated `useToolsPanelDropdownMenuProps` for dropdown menu support.
- Refactored individual settings (`value`, `max`, `height`, `showValue`) into `ToolsPanelItem` components with better attribute handling.
- Improved UI and UX for configuring the Progress Bar block in the editor.
- Updated the Progress Bar block to use a custom `progressBar` icon from the WordPress icons library instead of the `home` icon.
- Added the `progressBar` icon to the icons library for consistent usage.
- Adjusted the block metadata to reference the new icon, enhancing visual representation in the editor.
- Simplified inline styles for the Progress Bar block to improve maintainability:
  - Removed unnecessary `overflow`, `position`, and `transition` properties from `progressBarStyle` and `progressStyle`.
  - Updated structural styles for better compatibility and readability.
- Removed redundant inline `div` styles in the block's markup for a cleaner layout.
- Integrated a dedicated SCSS file (`progress-bar/style.scss`) for the Progress Bar block:
  - Ensures consistent styling across the block.
  - Facilitates easier future modifications by consolidating styles into a central location.
- Updated `style.scss` to include the newly created `progress-bar/style.scss` file.
- Registered the `Progress Bar` block in `lib/blocks.php` to ensure proper loading and functionality within the block editor.
- Refactored the save logic for the Progress Bar block:
  - Simplified `progressBarStyle` and `progressStyle` by removing redundant CSS properties (`overflow`, `position`, `height`, and `transition`).
  - Updated the block's markup to streamline structure and remove unnecessary `div` styles for better performance and maintainability.
- Ensured the output HTML remains lightweight and optimized for frontend rendering.
Added a new "read progress" mode to the Progress Bar block that allows
it to function as a reading progress indicator. Key changes included:

* Added isReadProgress attribute with default false
* Added toggle control in the editor UI
* Updated block rendering for read progress mode
* Added fixed positioning and scroll animation styles
* Updated save component to handle read progress mode
* Added grow-progress animation keyframes
- Introduced new attributes `symbol` and `symbolPosition` in the block's `block.json`.
- Updated the block's edit component to include controls for customizing the value symbol and its position (prefix or suffix).
- Updated the block's save logic to render the symbol based on the selected position.
- Ensured backward compatibility by setting default values for `symbol` as `%` and `symbolPosition` as `suffix`.
Updates the maximum value field in the Progress Bar block from a RangeControl to NumberControl, allowing for more flexible value input. Also adjusts the minimum height constraint from 6px to 1px for finer control over bar appearance. Adds shift+arrow key support for increments of 10.
- Added option to show maximum value alongside current value
- Added custom separator control with "/" as default
- Made total value display respect symbol position setting
- Conditionally rendered total value controls only when "Show value" is enabled
- Added new block attributes: showTotal (boolean) and separator (string)
- Refactored value formatting logic into a reusable function
- Moved read progress toggle to top level for better visibility
- Grouped all value-related controls under a conditional block
- Reorganized controls to show/hide based on read progress state
- Moved bar height control outside the conditional block to make it available for all progress bar types
- Simplified "Progress bar height" label to "Bar height"
@Infinite-Null Infinite-Null marked this pull request as ready for review January 27, 2025 05:57
Copy link

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @mgozdis.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Unlinked contributors: mgozdis.

Co-authored-by: Infinite-Null <[email protected]>
Co-authored-by: ramonjd <[email protected]>
Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: andrewserong <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
New Block Suggestion for a new block [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New Progress Bar block (or a core-blocks approach to building a progress-style block pattern)
2 participants