Search by

tmonier / sylius-industry-trade-theme

thibmonier

Thème Industrie & Négoce pour Sylius — haute densité d'information, mode sombre AAA, saisie rapide

Package info

github.com/thibmonier/sylius-industry-trade-theme

Type:sylius-theme

pkg:composer/tmonier/sylius-industry-trade-theme

Statistics

Installs: 238

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.3.1 2026-11-12 12:34 UTC

README

Français : README.fr.md

B2B theme for Sylius 2 optimized for industry and trade: high information density, AAA contrasts.

Features

  • Design tokens: color palette with WCAG AAA contrasts (≥ 7:1), overridable via CSS custom properties
  • Optional dark mode: dark token set, every text/background pair at 7:1 (AAA, checked in CI), light/dark toggle remembered between visits
  • Common components: header, footer, buttons, tables, forms, messages
  • Cart, account and content pages: dense cart (reference, editable quantity, prices excl. tax), themed account navigation (plugin entries included only when the plugin is installed), content page layout @TmonierSyliusIndustryTradeTheme/content/page.html.twig
  • Compatibility: Sylius 2.2 and 2.3, PHP 8.3+
  • Assets: Webpack Encore

Prerequisites

  • PHP 8.3 or higher
  • Sylius 2.2.9 or 2.3+
  • Sylius Theme Bundle ^2.4

Installation

composer require tmonier/sylius-industry-trade-theme

Copy the configuration to your application:

cp vendor/tmonier/sylius-industry-trade-theme/config/packages/tmonier_sylius_industry_trade_theme.yaml config/packages/
cp -r vendor/tmonier/sylius-industry-trade-theme/config/twig_hooks config/

What the configuration does, and what it never does:

  • It registers the Twig namespace @TmonierSyliusIndustryTradeTheme (twig.paths), resolved on every channel, for the templates the theme adds: the cart "Reference" column, the account navigation items and the content page layout.
  • It adds two hookables, industry_reference, to the cart head and body (priority 350). They render nothing unless the theme is active on the current channel.
  • It does not replace any hookable of Sylius or of your application. The themed pages (header, footer, flash messages, cart, account, product list, search field) are template overrides under templates/bundles/SyliusShopBundle/, which Sylius applies only to channels using the theme. The hookables you added to sylius_shop.base.header.content, sylius_shop.base.footer.content or the product list keep rendering, and your own settings on the cart hookables items, coupon, summary, form and account (template, props, priority) stay yours, on themed and non-themed channels alike.
  • It adds one more hookable, industry_color_mode (config/twig_hooks/color_mode.yaml), to the shop top bar (sylius_shop.base.header.top_bar, priority -100): the light/dark toggle. It renders nothing unless the theme is active on the current channel. Do not copy that file if you do not want the toggle: the theme then only follows the system setting.
  • The quick order link of an empty cart appears only when the quick-order plugin is installed.

Install the styles and assets

The package ships SCSS sources, not compiled assets. Import them in the Encore entry of your application, after the Sylius shop styles (Sass loader enabled, as in a standard Sylius application):

// assets/shop/entrypoint.scss (or the stylesheet imported by your shop entry)
@use '../../vendor/tmonier/sylius-industry-trade-theme/assets/styles/theme';

If your shop entry does not import a stylesheet yet (a fresh Sylius-Standard project), import this file from it:

import './entrypoint.scss';

then build as usual:

npm run build

All the rules of the theme are scoped to [data-theme="industry-trade"], an attribute the theme layout sets on <body>: on a channel without the theme, or elsewhere in your application, no token and no component changes.

Theme activation

Sylius must find the theme: its filesystem source scans the directories of sylius_theme.sources.filesystem.directories (composer.json files, scan_depth levels deep), for example

sylius_theme:
    sources:
        filesystem:
            scan_depth: 1
            directories:
                - '%kernel.project_dir%/themes'
                - '%kernel.project_dir%/vendor/tmonier'

Then set the theme_name of a Sylius channel to tmonier/sylius-industry-trade-theme.

The CI runs this procedure, as written, in a fresh Sylius-Standard project (Sylius 2.2 and 2.3): the code blocks marked blank-project above are executed by bin/blank-project-steps, then the job checks a channel with the theme and a channel without it. Change a command here and the job runs the new one.

Usage

Customize design tokens

The theme defines its CSS custom properties on [data-theme="industry-trade"] (colors, spacing, fonts), not on :root, so they cannot collide with the variables of your application. To override them, use the same selector, loaded after the theme stylesheet:

[data-theme="industry-trade"] {
    --bs-primary: #your-navy;
    --industry-accent: #your-accent;
    --bs-link-color: #your-link-color;
    --bs-link-hover-color: #your-hover-color;
}

See assets/styles/theme.scss for the complete list of available custom properties.

Dark mode (optional)

The theme ships a dark token set under [data-theme="industry-trade"]. There is no dark mode by default:

  • System setting: while the visitor has not chosen, prefers-color-scheme: dark applies the dark tokens; a light system stays light.
  • Switch: three buttons in the top bar ("Automatic", "Light", "Dark"; each is named, aria-pressed announces the active one, a check mark shows it without relying on color, keyboard reachable, 44 px targets). "Light" or "Dark" sets data-industry-mode on <html> and remembers the choice in localStorage (key industry-trade:color-mode); a choice overrides the system setting. "Automatic" removes that key and the attribute: the page follows prefers-color-scheme again, including when the system switches during the visit. The script dispatches a industry-trade:color-mode-change event on document (detail.choice, detail.mode) if your own code (charts, maps) must follow.
  • No flash: a small inline script in the <head>, run before the stylesheets, applies the remembered choice before the first paint. The switch stays hidden until that script has run (without JavaScript it would do nothing).
  • Storage unavailable (blocked or private browsing): the mode applies to the current page, nothing is remembered, no JavaScript error.
  • CSP (strict script-src without 'unsafe-inline'): the script is inline (<script data-industry-color-mode>). Two ways to allow it. (1) Nonce: if your application exposes a Twig variable industry_trade_script_nonce (for example a Twig global or a GlobalsInterface extension returning your nonce generator's script nonce, such as the one of NelmioSecurityBundle), the script carries nonce="..."; the theme does not depend on any bundle. (2) Hash: add 'sha256-Ter0gpyamaHCdpF/mPdb6ndLUHpL2AijAKVWPWZGOBg=' to script-src. That hash is the SHA-256 of the exact script content; ColorModeScriptCspTest fails in CI when the script changes without this value (and the one in README.fr.md) being updated. If the script is blocked, the switch stays hidden (it is hidden until the script runs) and the page follows the system setting.
  • Contrast: the dark pairs are the $industry-dark-* tokens of assets/styles/_variables.scss; tests/Unit/Theme/ColorContrastTest.php reads them and fails in CI, naming the pair, when one falls under 7:1 (3:1 for control borders).
  • Overrides: your own [data-theme="industry-trade"] overrides apply in light mode; to change a color in dark mode, use [data-industry-mode="dark"] [data-theme="industry-trade"] { ... } (and the same inside @media (prefers-color-scheme: dark) on html:not([data-industry-mode]) if you want it to follow the system too).
  • Logo: in dark mode the theme puts a light rounded backdrop behind the header logo (header a[aria-label*='logo' i]), so a logo with dark text, like the default Sylius one, stays readable; your logo is not modified. If you ship a dark-ready logo, reset it with [data-industry-mode="dark"] [data-theme="industry-trade"] header a[aria-label*='logo' i] { background: none; padding: 0; }.
Light Dark
Light mode Dark mode

Keyboard entry on the product list

On the dense product list (taxon and search result pages), a "Go to a reference or a designation" field lets a buyer jump to a line without the mouse:

  • Field: an ARIA combobox (role="combobox", aria-controls, aria-activedescendant). Typing filters the references and designations of the lines on the page (no network request: the core has no endpoint searching by reference, its list search covers the name only). The first match is highlighted, ↓/↑ move through the matches, Enter moves the focus to the line, Esc closes the list, then clears the field.
  • Announcements: a live region (role="status") says "N references found" or "No reference found".
  • Grid: ←/→ move between the focusable cells of a row (link, buttons), ↑/↓ to the same cell of the next row, Esc back to the field; the focus ring is 3 px. Quantity inputs keep their own arrow keys.
  • Without JavaScript the field stays hidden (hidden) and the list reads as before. CSP: the script is inline (<script data-industry-quick-find-script>); it carries the application nonce when the Twig variable industry_trade_script_nonce is defined (like the color mode script); otherwise add 'sha256-UtJO2cK4ZiY0HTR39tItR/U8YODUkpxMoJ08YnSUzbQ=' to script-src (SHA-256 of the exact script content; QuickFindScriptCspTest fails in CI when the script changes without this value, and the one in README.fr.md, being updated). Under a CSP that blocks it, the field stays hidden.
  • The quick-order plugin keeps its own page and fields; the theme does not touch them.

Quick find: "star" typed, matching reference highlighted above the dense list

The keyboard behaviour is covered by tests/Unit/Theme/QuickFindScriptTest.php (script run under Node) and tests/Functional/QuickFindTest.php.

Override components

On a channel that uses the theme, a template of the theme wins over the same template in templates/bundles/ of your application. The lookup order, for a themed channel, is:

  1. the active theme, then its parent themes (parents in the theme configuration): vendor/tmonier/sylius-industry-trade-theme/templates/bundles/<Bundle>/...;
  2. your application: templates/bundles/<Bundle>/...;
  3. the Sylius bundle: vendor/sylius/sylius/src/Sylius/Bundle/ShopBundle/templates/....

(This is how sylius/theme-bundle resolves a template: NamespacedTemplateLocator looks in the theme first, ThemeHierarchyProvider adds the parents.) A channel without the theme only sees levels 2 and 3.

To change a template the theme overrides, do not copy it into templates/bundles/: it would be ignored on themed channels. Create a theme of your own that declares this one as its parent, put your template in it, and set the channel to your theme:

{
    "name": "acme/shop-theme",
    "extra": {
        "sylius-theme": {
            "title": "Acme",
            "parents": ["tmonier/sylius-industry-trade-theme"]
        }
    }
}

with templates/bundles/SyliusShopBundle/... next to that composer.json (in the themes/ directory of your application by default). The two hookables of the "Reference" column compare the channel theme with industry_theme_name: if you use a child theme, redefine that Twig global to the name of your theme (twig.globals.industry_theme_name).

Hookables and their props stay the way to change what the theme does not override: add or configure them in your own sylius_twig_hooks file.

Reviewing template drift

Every template the theme overrides under templates/bundles/<Bundle>/** is copied from a Sylius template. The unit test tests/Unit/TemplateDrift/ThemeTemplateDriftTest.php compares the fingerprint of each original (normalized sha256, per Sylius minor version) with tests/TemplateDrift/fingerprints.json, recorded at the last review. It runs in the unit testsuite and in a weekly scheduled run (Monday). Overrides are discovered automatically.

When it fails, the message names the template:

  • original template modified: read the upstream diff between the previously reviewed Sylius version and the new one, adapt the override, then run php bin/template-fingerprints --update;
  • template removed upstream: adapt or remove the override (the script refuses to write while an original is missing);
  • override not registered: run php bin/template-fingerprints --update after review.

The script rewrites the fingerprints of the Sylius minor version installed in vendor/. To record the other minor version too, install it (composer require sylius/sylius:~2.2.0 --no-update && composer update), run the script again, then restore your constraint. php bin/template-fingerprints --check only reports the drift.

Screenshots

Catalogue pages (rendered with Bootstrap and the theme stylesheet; the shop header and footer are shown without the full Sylius stylesheet).

Page Capture
Home (hero, aisles of the channel menu taxon) Home
Dense product list (reference, designation, stock, price excl. VAT) Product list
Product list below 768 px (cards, no horizontal scroll) Product list at 375 px
Product page (references, technical sheet, documents, availability) Product page

Catalogue pages

  • Home: title, lead text and one link per child of the channel's menu taxon (hidden when the channel has none).
  • Product list: one row per product with reference, designation, stock, price excl. VAT and an actions cell. The price cell renders the core card hook sylius_shop.shared.product.card.prices and the actions cell the hookables of sylius_shop.shared.product.card (favourites, add to cart, quote... added by your application or plugins), so a price hidden by your application stays hidden. The exact stock is always shown; below 768 px each row becomes a card. A product without image shows a placeholder.
  • Product page: product and variant references, availability, technical sheet (product attributes) and a Documents list for attributes whose text value is a link to a pdf, dwg, step, zip, doc or xls file. Blocks from plugins (for example tier pricing) are left to the plugins and simply absent when the plugin is not installed.
  • Texts are in the industry_trade translation domain (translations/, English and French).
  • Implemented as theme template overrides (templates/bundles/SyliusShopBundle/), which only apply to channels using the theme and leave the hook configuration of your application alone. The only global additions are the two "Reference" hookables, guarded in their templates.
Cart (12 lines) Empty cart
Dense cart Empty cart
Account navigation Content page
Account Content page

B2B demo

This plugin is used in the Sylius B2B demo: a Sylius 2.3 shop with fictitious sample data where the B2B plugins work together. The source code, setup and fixtures of the demo are in that repository.

The demo is an example, not a production setup.

License

MIT