1e1b82ad63
* Using nested selector to style Product elements in Products Block This commit simplifies the INNER_BLOCKS_TEMPLATE array in the product-query constants.ts file by removing the style properties from the individual elements. Instead, the default styles are now managed in the style.scss file, providing a more consistent and centralized approach to styling. In the style.scss file, a new section for default styling has been added to handle product elements inside the Products Block, adhering to the Gutenberg styling hierarchy. This ensures the lowest precedence in the hierarchy, allowing for easier overrides when needed. * Decrease specificity of styles for product elements in Products Block The commit changes the default styles for product elements inside the 'Products Block'. It changes the way the margin-bottom and margin-top properties are set by using the :where() selector instead of using the .products-block-post-template class selector. This is done to decrease the specificity of the CSS selector, ensuring that the styles have the lowest precedence in the hierarchy. It also removes the display: inline-block property from the a selector, and moves the styles to the .editor-styles-wrapper class selector. * Decrease specificity of CSS selectors In these changes, the product elements inside the Products Block have been restyled. The specificity of the CSS selector has been decreased using the :where() selector, to ensure that these styles have the lowest precedence in the hierarchy. In constants.ts, a new class name, products-block-post-template, has been added to the inner block template for the post. This class is used to add default styles for inner blocks. In style.scss, the CSS selector for the inner blocks has been updated to include the new class name. The :where() selector has also been used to ensure that these styles have the lowest precedence in the hierarchy. * Update default margins and remove redundant entries This commit updates the default margin values for the Product Title in the Products block, moving them from the style.scss file to the constants.ts file. It also removes unnecessary empty arrays in the INNER_BLOCKS_TEMPLATE and background-color property from the style.scss file. |
||
---|---|---|
.. | ||
active-filters | ||
attribute-filter | ||
breadcrumbs | ||
cart | ||
cart-checkout-shared | ||
catalog-sorting | ||
checkout | ||
classic-template | ||
customer-account | ||
featured-items | ||
filter-wrapper | ||
handpicked-products | ||
mini-cart | ||
price-filter | ||
product-best-sellers | ||
product-categories | ||
product-category | ||
product-new | ||
product-on-sale | ||
product-query | ||
product-results-count | ||
product-search | ||
product-tag | ||
product-top-rated | ||
products | ||
products-by-attribute | ||
rating-filter | ||
reviews | ||
shared/styles | ||
single-product | ||
stock-filter | ||
store-notices | ||
README.md |
README.md
Blocks
Our blocks are generally made up of up to 4 files:
|- block.js
|- editor.scss
|- index.js
|- style.scss
The only required file is index.js
, this sets up the block using registerBlockType
. Each block has edit and save functions.
The scss files are split so that things in style
are added to the editor and frontend, while styles in editor
are only added to the editor. Most of our blocks should use core components that won't need CSS though.
Editing
A simple edit function can live in index.js
, but most blocks are a little more complicated, so the edit function instead returns a Block component, which lives in block.js
. By using a component, we can use React lifecycle methods to fetch data or save state.
The Newest Products block is a good example to read over, this is a simple block that fetches the products and renders them using the ProductPreview component.
We include settings in the sidebar, called the Inspector in gutenberg. See an example of this.
Other blocks have the concept of an "edit state", like when you need to pick a product in the Featured Product block, or pick a category in the Products by Category block.