Skip to content

Brand palette generator in WordPress

A hexadecimal colour field that computes a palette live (primary, hover, background, text), shows the WCAG contrast ratios and gives the CSS variables to copy.

Here is an excerpt of this component's code in WordPress. The full code is free for members, ready to copy into your project.

This component also comes in

Open in a new tab

The code in WordPress

formulaire-generateur-palette-marque.php
<?php
/**
 * Plugin Name: Forge, Générateur de palette de marque
 * Description: Un champ de couleur hexadécimale qui calcule en direct une palette (primaire, survol, fond, texte), affiche les rapports de contraste WCAG et donne les variables CSS à copier. Ajoute la composition « Générateur de palette de marque » à l'éditeur de blocs.
 * Version: 1.0.0
 * Requires at least: 6.6
 * Requires PHP: 8.1
 * Author: Forge
 * License: GPL-2.0-or-later
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain: forge-formulaire-generateur-palette-marque
 *
pattern.html
<!-- wp:html -->
<form class="gpm" data-gpm novalidate aria-labelledby="gpm-titre">
        <div class="gpm-head">
          <p class="gpm-eyebrow">Charte graphique</p>
          <h2 class="gpm-title" id="gpm-titre">Générez la palette de votre marque</h2>
          <p class="gpm-lead">Entrez votre couleur principale : la palette, ses contrastes WCAG et les variables CSS suivent à chaque caractère.</p>
        </div>
        <div class="gpm-grid">
          <div class="gpm-col">
            <div class="gpm-field">
              <label class="gpm-label" for="gpm-couleur">Couleur principale (hexadécimal)</label>
              <div class="gpm-row">
script.js
(() => {
  if (!document.querySelector(".gpm")) return;
  document.querySelectorAll("[data-gpm]").forEach((root) => {
    const on = (el, type, fn) => el.addEventListener(type, fn);
    const offs = [];
    const $ = (selector) => root.querySelector(selector);
    const form = root;
    const hex = $("[data-gpm-hex]");
    const picker = $("[data-gpm-picker]");
    const error = $("[data-gpm-error]");
    const preview = $("[data-gpm-preview]");
    const advice = $("[data-gpm-advice]");
style.css
:root {
  --gpm-scheme: light;
  --gpm-card: #ffffff;
  --gpm-text: #1f1d2b;
  --gpm-muted: #55526a;
  --gpm-accent: #4338ca;
  --gpm-on-accent: #ffffff;
  --gpm-line: #8a879c;
  --gpm-soft: #f1f0f7;
  --gpm-error: #b42318;
  --gpm-ok-bg: #e3f4ea;
  --gpm-ok: #14532d;

Free component: copy it freely, including for commercial projects.

Forms and inputs components in WordPress
  • A quote request form for tradespeople: the customer describes the work, picks a start date range and attaches up to six site photos, each with a preview, its size and a button to remove it.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A quote request form whose labels, hints and error messages are full French sentences, still readable at 320 px: nothing overflows, nothing is cut off, and each error is tied to its field.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • Visitors pick a package and tick options: the pre-tax total, VAT and total including tax update live, and the summary is sent with the contact form.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A short NPS survey: a 0 to 10 score as radio buttons, then a follow-up question adapted to whether the customer is a detractor, passive or promoter.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • An honest unsubscribe page: address prefilled from the link, choice between stopping everything or receiving less, optional reason and an undo.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A callback request form: French phone number checked and formatted, topic, working day and time slot, with explicit consent to the call.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component