Frontend Features
Banner

Frontend Features

Pipelines

WP BOX WordPress theme includes pipelines for compilation and dependency enqueuing preconfigured to work on specific directories in the project.

List of pipelines:

  • Gutenberg blocks React code compilation, used in admin-side rendering of custom blocks.
  • Minification of block-scoped and global theme assets – scripts and images.
  • Dynamic registering and enqueuing of assets and asset dependencies based on dependencies.json that can be added into block directory. (Load a library only when its used by the block).
  • Parsing and compilation of Tailwind classes, that are used in theme files.
  • Watch for changes and automatic recompilations
	"scripts": {
		"start-tailwind": "npx tailwindcss -i ./styles/src/tailwind.css -o ./styles/dist/tailwind.css --watch=always",
		"lint-js": "npx eslint .",
		"format-js": "npx eslint --fix .",
		"gulp": "gulp",
		"start-components": "webpack --watch --config ./webpack/webpack.components.js",
		"start-gutenberg-variations": "webpack --watch --config ./webpack/webpack.gutenberg-variations.js",
		"start-gutenberg-hooks": "webpack --watch --config ./webpack/webpack.gutenberg-hooks.js",
		"start-gutenberg-scripts": "webpack --watch --config ./webpack/webpack.gutenberg-scripts.js",
		"start-gutenberg": "wp-scripts start --config ./webpack/webpack.gutenberg.js",
		"start-svg": "wp-scripts start --config ./webpack/webpack.global-svg.js",
		"start-imgs": "wp-scripts start --config ./webpack/webpack.global-images.js",
		"start": "npm-run-all --parallel start-tailwind start-gutenberg start-components start-gutenberg-scripts start-gutenberg-hooks start-gutenberg-variations gulp"
	},
In this section:

Tailwind Support

WP BOX comes with Tailwind CSS integrated into frontend development flow.

const tailwindConfig = {
	theme: {
		extend: {
			screens: {
				sm: '480px',
				md: '800px',
				lg: '1024px',
				xl: '1600px',
			},
			textColor: {
				theme: {
					base: 'var(--color-text-base)',
					link: 'var(--color-text-link)',
					hover: 'var(--color-text-hover)',
				},
			},
			backgroundColor: {
				theme: {
					'light-gray': 'var(--color-bg-light-gray)',
					'light-blue': 'var(--color-bg-light-blue)',
					white: 'var(--color-bg-white)',
					modal: 'var(--color-bg-modal)',
					'bg-hover': 'var(--color-bg-hover)',
				},
			},

Tailwind Config

Variables defined in tailwind.config.js are compiled into CSS classes together with default Tailwind utility classes, that are used in projects.

By default WP BOX withdraws post authors access to styling settings, to have a persistent style across website. Also this allows developers to build new components faster, reusing existing defines.

Theme.json Configurator

WP BOX provides a class, that merges Tailwind Config settings into theme.json, default site does not use it, because editors access to theme styles is disabled, but in case you need it – you can pass the desired Tailwind settings into WordPress settings with a setSettings() method of a WPThemeConfigurator class, which are then saved into a file.

Right now we just build a minimal empty theme.json file, that is required to enable Full Site Editing feature of WordPress.

class WPThemeConfigurator {
	constructor() {
		this.$schema = 'https://schemas.wp.org/trunk/theme.json';
		this.version = 3;
		this.settings = {};
	}

	setSettings( config ) {
		this.settings = { ...this.settings, ...config };
		return this;
	}

	// Method to save configuration to theme.json file.
	saveToThemeJSON( filePath = 'theme.json' ) {
		const jsonString = JSON.stringify( this, null, 2 );

		fs.writeFileSync( filePath, jsonString );
		// eslint-disable-next-line no-console
		console.log( `Configuration saved to ${ filePath }` );
	}
}
Снимок экрана 2024-08-18 160304

Intellisense for IDE

If you ever wondered, how could one remember all those utility classes – the answer is you shouldn’t remember them.

Modern IDEs have extensions, that suggest autocompletion and provide explanation on Tailwind utility classes. Also these classes are well documented on the official website.

Utilizing Layers

To have an even more reusable component system, WP BOX is utilizing Tailwind layers to create custom components. When is this needed?

Imagine that you want to have visually similar buttons across all website, but under the hood, they have different functionality. E.g. a button which is a link, a button which triggers ajax request and a button that runs some other frontend script. In this case, you would probably have 3 different Gutenberg blocks – button-link, button-pay and button-script.

To avoid copy-pasting of utility classes in every block, you can define them once in a components layer, and reuse in all your components.

@layer components {

	.wpbox-input {
		@apply relative;

	  input {
		@apply bg-theme-white text-theme-base w-full pt-6 px-4 pb-2 rounded outline-none;
	  }
	  label {
		@apply absolute transition-all start-4 top-4 opacity-60 text-base-paragraph md:text-base-paragraph-desktop pointer-events-none;
	  }
	}

	.wpbox-button {
		@apply block whitespace-nowrap max-w-fit cursor-pointer text-theme-link hover:text-theme-hover border-2 rounded-md border-theme-link px-4 py-3.5 no-underline hover:bg-theme-bg-hover;
	}
}
In this section:

Gutenberg Blocks

public static function theme_gutenberg_blocks()
	{
		$blocks_parent_directory = get_template_directory() . '/blocks/';

		// Scan and register blocks from the parent theme directory
		self::register_blocks($blocks_parent_directory, false);

		if (is_child_theme()) {
			$blocks_child_directory = get_stylesheet_directory() . '/blocks/';
			// Scan and register blocks from the child theme directory
			self::register_blocks($blocks_child_directory, true);
		}
	}

Registering Blocks

The blocks directory in the theme folder contains all resources related to blocks, and the ThemeBlocks class is responsible for registering blocks and loading their assets.

To add new blocks, you need to follow the naming and file structuring rules. Files such as block.json, render.phpand block.index.js placed in the block’s directory, as well as resources in the ./assets/ folder, will be registered, loaded, and available for use.

Block Overrides, Variations and Patterns

Theme features another solution for simple and unified implementation of overrides, variations and patterns. Backend classes ThemeBlocksOverrides, ThemeBlocksVariations and ThemeBlocksPatterns are responsible for scanning respective directories and implementing hooks.js and filters.php defined in the folder during the initialization.

Note the screenshot with the example on how the core/code block is overriden, which you saw on this page.

Block Overrides

Examples of blocks included in the project

The project includes several dozen ready-made blocks and overrides of core blocks that you can learn from to create your custom blocks, use them as is, or modify to your needs:

  • Section: Container block which allows you to add a limited set of nested child blocks. Set the section’s background color and fill it with other blocks. All sections have unified padding styles, so they look good and visually separate information. This page has some sections.
  • Paragraph: This is a standard core block, but modified to support the sizes and fonts specified in the Tailwind configuration. Unnecessary settings are disabled. Now, the author of the article won’t make a mistake when choosing the color, font, and size, and all paragraphs on the site will look in consistent style.
  • Queried Object Template: This block can be used to display the latest news or other items but within a custom template and settings. Wrapper settings support flexbox and you can justify and align content as you like.
  • Section Menu: This block automatically creates a dynamic menu from the section headers, which remains on the screen while the user is viewing the section. Clicking on the links in the menu smoothly scrolls the screen to the corresponding header in the section. This section has that block, check it out!
  • Payment Button: A block where you specify the product, currency, and additional text. Clicking on the button triggers a series of scripts that interact with the backend. Wherever you place the button, it will trigger a popup for the client’s details submission, validate them, and finally redirect them to the payment system.

Code Style Linter

As you probably already noticed above in the pipelines section, WP BOX includes code style assisting implemented with ESLint packages and WordPress code style configuration with few changes. Also you will need to setup your IDE to to use project config.

ESLint Support

Linting features

  • Real-time linting of code as you type
  • CLI command for linting all files at once locally or inside a CI/CD pipeline
  • CLI command for automatic fixing of simple issues across all files

Build technically perfect websites today

Save time, money and nerves by investing in awesome code base early and be prepared when your project needs it.

50% discount applies on purchases in December 2024/January 2025. Happy New Year!

Visit pricing details page