]> git.ipfire.org Git - thirdparty/bulma.git/commitdiff
Add Control vars
authorJeremy Thomas <bbxdesign@gmail.com>
Wed, 26 Jun 2024 15:06:52 +0000 (16:06 +0100)
committerJeremy Thomas <bbxdesign@gmail.com>
Wed, 26 Jun 2024 15:06:52 +0000 (16:06 +0100)
14 files changed:
.gitignore
docs/_react/bulma-customizer/index.html
docs/_react/bulma-customizer/src/App.jsx
docs/_react/bulma-customizer/src/components/Slider.module.css
docs/_react/bulma-customizer/src/constants.js
docs/_react/bulma-customizer/src/pages/form/Control.jsx [new file with mode: 0644]
docs/_react/bulma-customizer/src/pages/form/File.jsx [new file with mode: 0644]
docs/_react/bulma-customizer/src/pages/form/Input.jsx [new file with mode: 0644]
docs/_react/bulma-customizer/src/pages/grid/Columns.jsx [new file with mode: 0644]
docs/_react/bulma-customizer/src/pages/grid/Grid.jsx [new file with mode: 0644]
docs/_react/bulma-customizer/src/pages/layout/Footer.jsx [new file with mode: 0644]
docs/_react/bulma-customizer/src/pages/layout/Hero.jsx [new file with mode: 0644]
docs/_react/bulma-customizer/src/pages/layout/Media.jsx [new file with mode: 0644]
docs/_react/bulma-customizer/src/pages/layout/Section.jsx [new file with mode: 0644]

index c3ece8e0df59149f03b4219de91bd77205a5752d..7c5483b279e846ae4246279dcd5d8ebb3bc7d95b 100644 (file)
@@ -17,5 +17,6 @@ test.css.map
 _gh_pages
 _site
 dev
+dist
 node_modules
 test/output/
index 2fca3e3becda16d32e8b149b8bd9ea235f684c60..9344bc96ee85ba46842fc9b0c51f38430371da13 100644 (file)
@@ -8,7 +8,7 @@
   </head>
   <body>
     <div id="root"></div>
-    <div class="is-hidden">
+    <div id="scope" class="is-hidden">
       <div class="box"></div>
       <div class="content"></div>
       <div class="delete"></div>
       <div class="table"></div>
       <div class="tag"></div>
       <div class="title"></div>
+      <input class="input">
+      <div class="file"></div>
+      <div class="columns"></div>
+      <div class="grid"></div>
+      <div class="footer"></div>
+      <div class="hero"></div>
+      <div class="media"></div>
+      <div class="section"></div>
     </div>
     <script type="module" src="/src/main.jsx"></script>
   </body>
index 31859dcc0380f3230d30893836b54f6974e985c9..8d20f0d5692b4767b4ed5c4e8c4fae28b943af7e 100644 (file)
@@ -1,4 +1,4 @@
-import { createContext, useEffect, useState } from "react";
+import { createContext, useEffect, useRef, useState } from "react";
 import classNames from "classnames";
 import "../../../../css/bulma.css";
 
@@ -21,6 +21,15 @@ import Progress from "./pages/elements/Progress";
 import Table from "./pages/elements/Table";
 import Tag from "./pages/elements/Tag";
 import Title from "./pages/elements/Title";
+import Control from "./pages/form/Control";
+import Input from "./pages/form/Input";
+import File from "./pages/form/File";
+import Columns from "./pages/grid/Columns";
+import Grid from "./pages/grid/Grid";
+import Footer from "./pages/layout/Footer";
+import Hero from "./pages/layout/Hero";
+import Media from "./pages/layout/Media";
+import Section from "./pages/layout/Section";
 
 const SUFFIX_TO_KIND = {
   "-h": "hue",
@@ -37,6 +46,7 @@ const PAGE_TO_COMPONENT = {
   other: <Other />,
   generic: <Generic />,
   skeleton: <Skeleton />,
+  // Elements
   box: <Box />,
   content: <Content />,
   delete: <Delete />,
@@ -46,6 +56,18 @@ const PAGE_TO_COMPONENT = {
   table: <Table />,
   tag: <Tag />,
   title: <Title />,
+  // Form
+  control: <Control />,
+  input: <Input />,
+  file: <File />,
+  // Grid
+  columns: <Columns />,
+  grid: <Grid />,
+  // Layout
+  footer: <Footer />,
+  hero: <Hero />,
+  media: <Media />,
+  section: <Section />,
 };
 const PAGE_IDS = [
   "colors",
@@ -63,6 +85,15 @@ const PAGE_IDS = [
   "table",
   "tag",
   "title",
+  "control",
+  "input",
+  "file",
+  "columns",
+  "grid",
+  "footer",
+  "hero",
+  "media",
+  "section",
 ];
 
 export const CustomizerContext = createContext({
@@ -74,6 +105,7 @@ export const CustomizerContext = createContext({
 });
 
 function App() {
+  const styleRef = useRef();
   const initialContext = {
     cssvars: {},
     currentPage: "delete",
@@ -90,15 +122,15 @@ function App() {
     },
     updateVar: (id, newValue) => {
       setContext((context) => {
-        const { start, unit, scope } = context.cssvars[id];
-        const computedValue = `${newValue}${unit}`;
-        const el = document.querySelector(scope);
+        // const { start, unit, scope } = context.cssvars[id];
+        // const computedValue = `${newValue}${unit}`;
+        // const el = document.querySelector(`#scope ${scope}`);
 
-        if (start === newValue) {
-          el.style.removeProperty(`--bulma-${id}`);
-        } else {
-          el.style.setProperty(`--bulma-${id}`, computedValue);
-        }
+        // if (start === newValue) {
+        //   el.style.removeProperty(`--bulma-${id}`);
+        // } else {
+        //   el.style.setProperty(`--bulma-${id}`, computedValue);
+        // }
 
         return {
           ...context,
@@ -134,6 +166,14 @@ function App() {
       table: window.getComputedStyle(document.querySelector(".table")),
       tag: window.getComputedStyle(document.querySelector(".tag")),
       title: window.getComputedStyle(document.querySelector(".title")),
+      file: window.getComputedStyle(document.querySelector(".file")),
+      input: window.getComputedStyle(document.querySelector(".input")),
+      columns: window.getComputedStyle(document.querySelector(".columns")),
+      grid: window.getComputedStyle(document.querySelector(".grid")),
+      footer: window.getComputedStyle(document.querySelector(".footer")),
+      hero: window.getComputedStyle(document.querySelector(".hero")),
+      media: window.getComputedStyle(document.querySelector(".media")),
+      section: window.getComputedStyle(document.querySelector(".section")),
     };
 
     const cssvars = {};
@@ -171,6 +211,30 @@ function App() {
       } else if (key.startsWith("title")) {
         scope = ".title";
         original = styles.title.getPropertyValue(`--bulma-${key}`);
+      } else if (key.startsWith("file")) {
+        scope = ".file";
+        original = styles.file.getPropertyValue(`--bulma-${key}`);
+      } else if (key.startsWith("input")) {
+        scope = ".input";
+        original = styles.input.getPropertyValue(`--bulma-${key}`);
+      } else if (key.startsWith("columns")) {
+        scope = ".columns";
+        original = styles.columns.getPropertyValue(`--bulma-${key}`);
+      } else if (key.startsWith("grid")) {
+        scope = ".grid";
+        original = styles.grid.getPropertyValue(`--bulma-${key}`);
+      } else if (key.startsWith("footer")) {
+        scope = ".footer";
+        original = styles.footer.getPropertyValue(`--bulma-${key}`);
+      } else if (key.startsWith("hero")) {
+        scope = ".hero";
+        original = styles.hero.getPropertyValue(`--bulma-${key}`);
+      } else if (key.startsWith("media")) {
+        scope = ".media";
+        original = styles.media.getPropertyValue(`--bulma-${key}`);
+      } else if (key.startsWith("section")) {
+        scope = ".section";
+        original = styles.section.getPropertyValue(`--bulma-${key}`);
       } else {
         original = styles.root.getPropertyValue(`--bulma-${key}`);
       }
@@ -203,8 +267,42 @@ function App() {
     });
   }, []);
 
+  useEffect(() => {
+    const rules = {};
+
+    Object.values(context.cssvars).forEach((cssvar) => {
+      const { id, current, start, scope, unit } = cssvar;
+
+      if (current == start) {
+        return;
+      }
+
+      const computedValue = `${current}${unit}`;
+      const declaration = `--bulma-${id}: ${computedValue};`;
+
+      if (scope in rules) {
+        rules[scope].push(declaration);
+      } else {
+        rules[scope] = [declaration];
+      }
+    });
+
+    let content = "";
+
+    for (const [key, arr] of Object.entries(rules)) {
+      content += `${key} {`;
+      arr.forEach((item) => (content += item));
+      content += `}`;
+    }
+
+    if (styleRef) {
+      styleRef.current.innerHTML = content;
+    }
+  }, [context.cssvars]);
+
   return (
     <CustomizerContext.Provider value={context}>
+      <style ref={styleRef} />
       <section className="section">
         <div className="buttons">
           {PAGE_IDS.map((pageId) => {
index 828d1cfda220c3fb16a339a36425b35ab78d6193..84f9414b5e1f11d851a4a1a7fcec07855e45827e 100644 (file)
@@ -32,7 +32,7 @@
 
 .background {
   border-radius: 0.25rem;
-  background-color: var(--bulma-background);
+  background-color: var(--bulma-border);
   height: 0.5rem;
 }
 
index 92a67424acc5cfd167cef10fa1da19c773916171..5917c16fa31fa16039d95312c1f0c332f96d8bad 100644 (file)
@@ -522,6 +522,35 @@ export const CSSVAR_KEYS = {
       description: "The subtitle strong elements font weight",
     },
   ],
+  control: [
+    { id: "control-radius", description: "The control elements border radius" },
+    {
+      id: "control-radius-small",
+      description: "The control elements small border radius",
+    },
+    {
+      id: "control-border-width",
+      description: "The control elements border width",
+    },
+    { id: "control-height", description: "The control elements height" },
+    {
+      id: "control-line-height",
+      description: "The control elements line height",
+    },
+    {
+      id: "control-padding-vertical",
+      description: "The control elements vertical padding",
+    },
+    {
+      id: "control-padding-horizontal",
+      description: "The control elements horizontal padding",
+    },
+    { id: "control-size", description: "The control elements font size" },
+    {
+      id: "control-focus-shadow-l",
+      description: "The control elements shadow Lightness when focused",
+    },
+  ],
   file: [
     { id: "file-radius", description: "The file element border radius" },
     {
@@ -594,10 +623,6 @@ export const CSSVAR_KEYS = {
       id: "input-border-style",
       description: "The input element main border style",
     },
-    {
-      id: "input-border-width",
-      description: "The input element main border width",
-    },
     {
       id: "input-border-l",
       description: "The input element main border Lightness",
diff --git a/docs/_react/bulma-customizer/src/pages/form/Control.jsx b/docs/_react/bulma-customizer/src/pages/form/Control.jsx
new file mode 100644 (file)
index 0000000..ab2f163
--- /dev/null
@@ -0,0 +1,16 @@
+import VarItem from "components/VarItem";
+import { CSSVAR_KEYS } from "root/constants";
+
+function Control() {
+  const ids = CSSVAR_KEYS.control.map((i) => i.id);
+
+  return (
+    <div>
+      {ids.map((id) => {
+        return <VarItem key={id} id={id} />;
+      })}
+    </div>
+  );
+}
+
+export default Control;
diff --git a/docs/_react/bulma-customizer/src/pages/form/File.jsx b/docs/_react/bulma-customizer/src/pages/form/File.jsx
new file mode 100644 (file)
index 0000000..98fc660
--- /dev/null
@@ -0,0 +1,16 @@
+import VarItem from "components/VarItem";
+import { CSSVAR_KEYS } from "root/constants";
+
+function File() {
+  const ids = CSSVAR_KEYS.file.map((i) => i.id);
+
+  return (
+    <div>
+      {ids.map((id) => {
+        return <VarItem key={id} id={id} />;
+      })}
+    </div>
+  );
+}
+
+export default File;
diff --git a/docs/_react/bulma-customizer/src/pages/form/Input.jsx b/docs/_react/bulma-customizer/src/pages/form/Input.jsx
new file mode 100644 (file)
index 0000000..d34b0a9
--- /dev/null
@@ -0,0 +1,16 @@
+import VarItem from "components/VarItem";
+import { CSSVAR_KEYS } from "root/constants";
+
+function Input() {
+  const ids = CSSVAR_KEYS.input.map((i) => i.id);
+
+  return (
+    <div>
+      {ids.map((id) => {
+        return <VarItem key={id} id={id} />;
+      })}
+    </div>
+  );
+}
+
+export default Input;
diff --git a/docs/_react/bulma-customizer/src/pages/grid/Columns.jsx b/docs/_react/bulma-customizer/src/pages/grid/Columns.jsx
new file mode 100644 (file)
index 0000000..d913fc0
--- /dev/null
@@ -0,0 +1,16 @@
+import VarItem from "components/VarItem";
+import { CSSVAR_KEYS } from "root/constants";
+
+function Columns() {
+  const ids = CSSVAR_KEYS.columns.map((i) => i.id);
+
+  return (
+    <div>
+      {ids.map((id) => {
+        return <VarItem key={id} id={id} />;
+      })}
+    </div>
+  );
+}
+
+export default Columns;
diff --git a/docs/_react/bulma-customizer/src/pages/grid/Grid.jsx b/docs/_react/bulma-customizer/src/pages/grid/Grid.jsx
new file mode 100644 (file)
index 0000000..9e466a9
--- /dev/null
@@ -0,0 +1,16 @@
+import VarItem from "components/VarItem";
+import { CSSVAR_KEYS } from "root/constants";
+
+function Grid() {
+  const ids = CSSVAR_KEYS.grid.map((i) => i.id);
+
+  return (
+    <div>
+      {ids.map((id) => {
+        return <VarItem key={id} id={id} />;
+      })}
+    </div>
+  );
+}
+
+export default Grid;
diff --git a/docs/_react/bulma-customizer/src/pages/layout/Footer.jsx b/docs/_react/bulma-customizer/src/pages/layout/Footer.jsx
new file mode 100644 (file)
index 0000000..c95afe2
--- /dev/null
@@ -0,0 +1,16 @@
+import VarItem from "components/VarItem";
+import { CSSVAR_KEYS } from "root/constants";
+
+function Footer() {
+  const ids = CSSVAR_KEYS.footer.map((i) => i.id);
+
+  return (
+    <div>
+      {ids.map((id) => {
+        return <VarItem key={id} id={id} />;
+      })}
+    </div>
+  );
+}
+
+export default Footer;
diff --git a/docs/_react/bulma-customizer/src/pages/layout/Hero.jsx b/docs/_react/bulma-customizer/src/pages/layout/Hero.jsx
new file mode 100644 (file)
index 0000000..76324fb
--- /dev/null
@@ -0,0 +1,16 @@
+import VarItem from "components/VarItem";
+import { CSSVAR_KEYS } from "root/constants";
+
+function Hero() {
+  const ids = CSSVAR_KEYS.hero.map((i) => i.id);
+
+  return (
+    <div>
+      {ids.map((id) => {
+        return <VarItem key={id} id={id} />;
+      })}
+    </div>
+  );
+}
+
+export default Hero;
diff --git a/docs/_react/bulma-customizer/src/pages/layout/Media.jsx b/docs/_react/bulma-customizer/src/pages/layout/Media.jsx
new file mode 100644 (file)
index 0000000..bda13a8
--- /dev/null
@@ -0,0 +1,16 @@
+import VarItem from "components/VarItem";
+import { CSSVAR_KEYS } from "root/constants";
+
+function Media() {
+  const ids = CSSVAR_KEYS.media.map((i) => i.id);
+
+  return (
+    <div>
+      {ids.map((id) => {
+        return <VarItem key={id} id={id} />;
+      })}
+    </div>
+  );
+}
+
+export default Media;
diff --git a/docs/_react/bulma-customizer/src/pages/layout/Section.jsx b/docs/_react/bulma-customizer/src/pages/layout/Section.jsx
new file mode 100644 (file)
index 0000000..1797cc6
--- /dev/null
@@ -0,0 +1,16 @@
+import VarItem from "components/VarItem";
+import { CSSVAR_KEYS } from "root/constants";
+
+function Section() {
+  const ids = CSSVAR_KEYS.section.map((i) => i.id);
+
+  return (
+    <div>
+      {ids.map((id) => {
+        return <VarItem key={id} id={id} />;
+      })}
+    </div>
+  );
+}
+
+export default Section;