Changeset 34076d7 in Klonkt


Ignore:
Timestamp:
06/24/2026 05:17:00 PM (3 months ago)
Author:
Robin Genis <roboburr@…>
Branches:
main
Children:
dd856db
Parents:
c9c70cc
Message:

feat(appearance): live theme preview in site settings

Selecting an accent, theme or palette now re-themes the settings page instantly
(updates data-palette/data-theme + the --accent style block, mirroring the shell)
so you see it before saving; reverts on reload, persists on save. Also fixes a
stale 'sage' default in the palette picker -> klonkt.

Co-Authored-By: Claude <noreply@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/views/pages/admin-site-edit.ejs

    rc9c70cc r34076d7  
    121121        <% palettes.forEach(function(p) { %>
    122122          <label class="palette-swatch">
    123             <input type="radio" name="palette" value="<%= p.key %>" <%= (site.palette || 'sage') === p.key ? 'checked' : '' %>>
     123            <input type="radio" name="palette" value="<%= p.key %>" <%= (site.palette || 'klonkt') === p.key ? 'checked' : '' %>>
    124124            <span class="palette-preview" aria-hidden="true">
    125125              <span class="pp-half pp-light" style="background: <%= p.light.paper %>; color: <%= p.light.ink %>;">
     
    137137      </fieldset>
    138138    </fieldset>
     139
     140    <%# Live preview: selecting an accent / theme / palette re-themes this page
     141        instantly (reverts on reload; persists on save). %>
     142    <script>
     143    (function(){
     144      if (window.__themePreviewWired) return; window.__themePreviewWired = true;
     145      var html = document.documentElement;
     146      function applyAccent(hex){
     147        if(!/^#[0-9a-fA-F]{6}$/.test(hex)) return;
     148        var sa = document.getElementById('pcms-site-accent');
     149        if(!sa){ sa = document.createElement('style'); sa.id = 'pcms-site-accent'; document.head.appendChild(sa); }
     150        sa.textContent = ':root,[data-palette]{--accent:'+hex+';--accent-soft:color-mix(in srgb,'+hex+' 80%,white);--accent-tint:color-mix(in srgb,'+hex+' 12%,transparent);}';
     151      }
     152      document.addEventListener('change', function(e){
     153        var t = e.target; if(!t || !t.name) return;
     154        if(t.name === 'palette'){ html.setAttribute('data-palette', t.value); }
     155        else if(t.name === 'accent'){ applyAccent(t.value); }
     156        else if(t.name === 'theme_override'){
     157          if(t.value === 'light' || t.value === 'dark'){ html.setAttribute('data-theme', t.value); }
     158          else { var dk = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches; html.setAttribute('data-theme', dk ? 'dark' : 'light'); }
     159        }
     160      });
     161    })();
     162    </script>
    139163
    140164    <fieldset>
Note: See TracChangeset for help on using the changeset viewer.