feat(core): add styles for vanilla form elements

#1
This commit is contained in:
Alexander Navarro 2024-09-16 20:35:38 -03:00
parent 919afcbcfc
commit e754e40622
22 changed files with 1034 additions and 184 deletions

View file

@ -14,6 +14,7 @@
"vite": "^5.4.1"
},
"dependencies": {
"handlebars": "^4.7.8",
"mini-strap-core": "workspace:*"
}
}

View file

@ -1,9 +0,0 @@
export function setupCounter(element: HTMLButtonElement) {
let counter = 0
const setCounter = (count: number) => {
counter = count
element.innerHTML = `count is ${counter}`
}
element.addEventListener('click', () => setCounter(counter + 1))
setCounter(0)
}

View file

@ -1,24 +1,12 @@
import "mini-strap-core";
import typescriptLogo from "./typescript.svg";
import viteLogo from "/vite.svg";
import { setupCounter } from "./counter.ts";
import render from "./render";
import layout from "./templates/form.html";
document.querySelector<HTMLDivElement>("#app")!.innerHTML = `
<main class="msp-container">
<a href="https://vitejs.dev" target="_blank">
<img src="${viteLogo}" class="logo" alt="Vite logo" />
</a>
<a href="https://www.typescriptlang.org/" target="_blank">
<img src="${typescriptLogo}" class="logo vanilla" alt="TypeScript logo" />
</a>
<h1>Vite + TypeScript</h1>
<div class="card">
<button id="counter" type="button"></button>
</div>
<p class="read-the-docs">
Click on the Vite and TypeScript logos to learn more
</p>
<section>
${render(layout, { name: "ale" })}
</section>
</main>
`;
setupCounter(document.querySelector<HTMLButtonElement>("#counter")!);

View file

@ -0,0 +1,11 @@
import Handlebars from "handlebars";
export default function (template: string, data: Record<string, unknown>) {
const engine = Handlebars.compile(template);
return engine(data);
}
export function mapRender(items: string[]) {
return items.join("\n");
}

View file

@ -0,0 +1,127 @@
<form>
<fieldset>
<div class="msp-mb-3">
<label for="exampleInputEmail1" class="">Email address</label>
<input
type="email"
class=""
id="exampleInputEmail1"
aria-describedby="emailHelp"
placeholder="user@email.com"
/>
<div id="emailHelp" class="">
We'll never share your email with anyone else.
</div>
</div>
<div class="msp-mb-3">
<label for="exampleInputPassword1" class="">Password</label>
<input
type="password"
class=""
id="exampleInputPassword1"
placeholder="Secret..."
/>
</div>
<div class="msp-mb-3">
<input type="checkbox" class="" id="exampleCheck1" />
<label class="" for="exampleCheck1">Check me out</label>
</div>
<div class="msp-mb-3">
<input
class="form-check-input"
type="radio"
name="flexRadioDefault"
id="flexRadioDefault1"
/>
<label class="form-check-label" for="flexRadioDefault1">
Default radio
</label>
</div>
<div class="msp-mb-3">
<label class="form-check-label" for="flexRadioDefault1">
Default range
</label>
<input
class="form-check-input"
type="range"
name="flexRadioDefault"
id="flexRadioDefault1"
/>
</div>
<div class="msp-mb-3">
<label class="" for="example-select">Select</label>
<select
id="example-select"
class="form-select"
aria-label="Default select example"
>
<option selected disabled hidden>Open this select menu</option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
</div>
<div class="msp-mb-3">
<label for="formFile" class="form-label"
>Default file input example</label
>
<input class="form-control" type="file" id="formFile" />
</div>
<div class="msp-mb-3">
<label for="exampleColorInput" class="form-label">Color picker</label>
<input
type="color"
class="form-control form-control-color"
id="exampleColorInput"
value="#563d7c"
title="Choose your color"
/>
</div>
<button type="submit" class="">Submit</button>
</fieldset>
</form>
<br />
<form>
<fieldset disabled class="msp-fieldset-border">
<legend>Disabled fieldset example</legend>
<div class="msp-mb-3">
<label for="disabledTextInput" class="form-label">Disabled input</label>
<input
type="text"
id="disabledTextInput"
class="form-control"
placeholder="Disabled input"
/>
</div>
<div class="msp-mb-3">
<label for="disabledSelect" class="form-label"
>Disabled select menu</label
>
<select id="disabledSelect" class="form-select">
<option>Disabled select</option>
</select>
</div>
<div class="msp-mb-3">
<div class="form-check">
<input
class="form-check-input"
type="checkbox"
id="disabledFieldsetCheck"
disabled
/>
<label class="form-check-label" for="disabledFieldsetCheck">
Can't check this
</label>
</div>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</fieldset>
</form>

View file

@ -0,0 +1 @@
<section>{{name}}</section>

View file

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="32" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path fill="#007ACC" d="M0 128v128h256V0H0z"></path><path fill="#FFF" d="m56.612 128.85l-.081 10.483h33.32v94.68h23.568v-94.68h33.321v-10.28c0-5.69-.122-10.444-.284-10.566c-.122-.162-20.4-.244-44.983-.203l-44.74.122l-.121 10.443Zm149.955-10.742c6.501 1.625 11.459 4.51 16.01 9.224c2.357 2.52 5.851 7.111 6.136 8.208c.08.325-11.053 7.802-17.798 11.988c-.244.162-1.22-.894-2.317-2.52c-3.291-4.795-6.745-6.867-12.028-7.233c-7.76-.528-12.759 3.535-12.718 10.321c0 1.992.284 3.17 1.097 4.795c1.707 3.536 4.876 5.649 14.832 9.956c18.326 7.883 26.168 13.084 31.045 20.48c5.445 8.249 6.664 21.415 2.966 31.208c-4.063 10.646-14.14 17.879-28.323 20.276c-4.388.772-14.79.65-19.504-.203c-10.28-1.828-20.033-6.908-26.047-13.572c-2.357-2.6-6.949-9.387-6.664-9.874c.122-.163 1.178-.813 2.356-1.504c1.138-.65 5.446-3.129 9.509-5.485l7.355-4.267l1.544 2.276c2.154 3.29 6.867 7.801 9.712 9.305c8.167 4.307 19.383 3.698 24.909-1.26c2.357-2.153 3.332-4.388 3.332-7.68c0-2.966-.366-4.266-1.91-6.501c-1.99-2.845-6.054-5.242-17.595-10.24c-13.206-5.69-18.895-9.224-24.096-14.832c-3.007-3.25-5.852-8.452-7.03-12.8c-.975-3.617-1.22-12.678-.447-16.335c2.723-12.76 12.353-21.659 26.25-24.3c4.51-.853 14.994-.528 19.424.569Z"></path></svg>

Before

Width:  |  Height:  |  Size: 1.4 KiB

View file

@ -1 +1,4 @@
/// <reference types="vite/client" />
declare module "*.html";
declare module "*.md";

View file

@ -0,0 +1,26 @@
import { defineConfig } from "vite";
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
// Custom plugin to load markdown files
{
name: "markdown-loader",
transform(code, id) {
if (id.slice(-3) === ".md") {
// For .md files, get the raw content
return `export default ${JSON.stringify(code)};`;
}
},
},
{
name: "html-loader",
transform(code, id) {
if (id.slice(-5) === ".html") {
// For .md files, get the raw content
return `export default ${JSON.stringify(code)};`;
}
},
},
],
});