Compare commits

...

2 commits

41 changed files with 363 additions and 23 deletions

View file

@ -7,7 +7,8 @@
}, },
"exports": { "exports": {
".": "./src/index.ts", ".": "./src/index.ts",
"./navbar/*": "./src/navbar/*" "./navbar/*": "./src/navbar/*",
"./accordion/*": "./src/accordion/*"
}, },
"devDependencies": { "devDependencies": {
"@types/bun": "latest", "@types/bun": "latest",

View file

@ -0,0 +1,41 @@
.msp-accordion {
// background-color: red;
&-item.msp-accordion-show {
.msp-accordion-header::after {
transform: rotate(180deg);
}
}
&-header {
cursor: pointer;
position: relative;
&::after {
display: inline-block;
position: absolute;
top: 50%;
right: 0;
transform: rotate(0deg);
translate: 110% -50%;
content: "";
width: 1em;
height: 1em;
// TODO: change SVG of the arrow
background: url('data:image/svg+xml;utf8,<svg fill="%23000000" viewBox="0 0 24 24" id="down-arrow-circle" data-name="Flat Line" xmlns="http://www.w3.org/2000/svg" class="icon flat-line"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"><path id="secondary" d="M12,3a9,9,0,1,0,9,9A9,9,0,0,0,12,3Zm2.83,10.5-2.14,3.12a.82.82,0,0,1-1.38,0L9.17,13.5A1,1,0,0,1,9.86,12h4.28A1,1,0,0,1,14.83,13.5Z" style="fill: %232ca9bc; stroke-width: 2;"></path><path id="primary" d="M12,7v5m.69,4.63,2.14-3.13a1,1,0,0,0-.69-1.5H9.86a1,1,0,0,0-.69,1.5l2.14,3.12A.82.82,0,0,0,12.69,16.63ZM12,3a9,9,0,1,0,9,9A9,9,0,0,0,12,3Z" style="fill: none; stroke: %23000000; stroke-linecap: round; stroke-linejoin: round; stroke-width: 2;"></path></g></svg>')
no-repeat center center;
background-size: contain;
transition: transform 0.5s ease;
}
}
&-collapse {
overflow: hidden;
height: 0;
display: none;
transition: height 0.5s ease;
}
}

View file

@ -0,0 +1,53 @@
import { qs, qsa } from "../utils";
enum AccordionState {
Open = 1,
Closed = 2,
}
function waitAndHideCollapse(e: TransitionEvent) {
if (!e.target) return;
const el = e.target as HTMLElement;
el.style.display = "none";
el.removeEventListener("transitionend", waitAndHideCollapse);
}
function toggleAccordion(item: HTMLElement, state: AccordionState) {
const collapse = qs(".msp-accordion-collapse", item);
if (!collapse) throw new Error("Collapse element not found");
if (state === AccordionState.Closed) {
collapse.style.height = "0px";
collapse
.closest(".msp-accordion-item")
?.classList.remove("msp-accordion-show");
collapse.addEventListener("transitionend", waitAndHideCollapse);
} else if (state === AccordionState.Open) {
collapse.style.display = "block";
const height = qs(".msp-accordion-content", collapse)?.offsetHeight;
if (height == null) throw new Error("Content element not found");
collapse.style.height = `${height}px`;
collapse
.closest(".msp-accordion-item")
?.classList.add("msp-accordion-show");
}
}
window.onload = () => {
qsa(".msp-accordion-item").forEach((item) => {
qs(".msp-accordion-header", item)?.addEventListener("click", (e) => {
e.preventDefault();
toggleAccordion(
item,
item.classList.contains("msp-accordion-show")
? AccordionState.Closed
: AccordionState.Open,
);
});
});
};

View file

@ -0,0 +1,13 @@
export const qs = (
query: string,
el: Element | Document = document,
): HTMLElement | null => {
return el.querySelector(query);
};
export const qsa = (
query: string,
el: Element | Document = document,
): NodeListOf<HTMLElement> => {
return el.querySelectorAll(query);
};

View file

@ -1,11 +1,35 @@
import type { BuildConfig, BunPlugin, PluginBuilder } from "bun"; import type { BuildConfig, BunPlugin, PluginBuilder } from "bun";
import { parseArgs } from "node:util";
import { readdir, rm } from "node:fs/promises"; import { readdir, rm } from "node:fs/promises";
import { join } from "node:path"; import { join } from "node:path";
import type { FileImporter } from "sass"; import type { FileImporter } from "sass";
import { HTMLComponents } from "@mini-strap/components"; import { HTMLComponents } from "@mini-strap/components";
const outdir = "./static"; const { values } = parseArgs({
args: Bun.argv,
options: {
production: {
type: "boolean",
short: "p",
default: false,
},
filter: {
type: "string",
short: "f",
default: "all",
},
output: {
type: "string",
short: "o",
default: "static",
},
},
strict: true,
allowPositionals: true,
});
const outdir = values.output ?? "./static";
const nodeModuleImporter: FileImporter<"async"> = { const nodeModuleImporter: FileImporter<"async"> = {
findFileUrl(url) { findFileUrl(url) {
@ -35,28 +59,36 @@ const sassPlugin: BunPlugin = {
}, },
}; };
const assets: BuildConfig[] = [ const assets: BuildConfig[] = [];
{
const filter = values.filter ?? "all";
if (["all", "sass"].includes(filter)) {
assets.push({
entrypoints: ["./sass/style.scss"], entrypoints: ["./sass/style.scss"],
outdir: `${outdir}/css`, outdir: `${outdir}/css`,
naming: "[name].css", naming: "[name].css",
plugins: [sassPlugin], plugins: [sassPlugin],
minify: true, minify: values.production,
// On by default in Bun v1.2+ // On by default in Bun v1.2+
html: true, html: true,
experimentalCss: true, experimentalCss: true,
}, });
}
{ if (["all", "js", "ts"].includes(filter)) {
assets.push({
entrypoints: ["./js/index.ts"], entrypoints: ["./js/index.ts"],
outdir: `${outdir}/js`, outdir: `${outdir}/js`,
target: "browser", target: "browser",
splitting: true, splitting: values.production,
minify: true, minify: values.production,
}, });
}
{ if (["all", "html"].includes(filter)) {
assets.push({
entrypoints: Object.values(HTMLComponents), entrypoints: Object.values(HTMLComponents),
outdir: "./templates/ext-components", outdir: "./templates/ext-components",
target: "browser", target: "browser",
@ -69,8 +101,8 @@ const assets: BuildConfig[] = [
// On by default in Bun v1.2+ // On by default in Bun v1.2+
html: true, html: true,
experimentalCss: true, experimentalCss: true,
}, });
]; }
const out = await Promise.all( const out = await Promise.all(
assets.map(async (item) => { assets.map(async (item) => {

View file

@ -9,6 +9,10 @@ compile_sass = false
# Whether to build a search index to be used later on by a JavaScript library # Whether to build a search index to be used later on by a JavaScript library
build_search_index = true build_search_index = true
taxonomies = [
{ name = "section", feed = true }
]
[markdown] [markdown]
# Whether to do syntax highlighting # Whether to do syntax highlighting
# Theme can be customised by setting the `highlight_theme` variable to a theme supported by Zola # Theme can be customised by setting the `highlight_theme` variable to a theme supported by Zola

View file

@ -1,4 +1,5 @@
+++ +++
+++ +++
# mini-strap Documentation # mini-strap Documentation

View file

@ -0,0 +1,6 @@
+++
+++
# Components
Complex elements that require custom javascript to run

View file

@ -0,0 +1,31 @@
+++
[taxonomies]
section = ["Components"]
+++
# accordion.md
Example:
```html
<ul class="msp-list-unstyle msp-accordion">
<li>
<a href="/">Overview</a>
</li>
{% for item in get_taxonomy(kind="section") | get(key="items") %}
<li class="msp-accordion-item">
<a class="msp-accordion-header" href="#">{{ item.name | title }}</a>
<div class="msp-accordion-collapse">
<ul class="msp-list-unstyle msp-accordion-content">
{% for page in item.pages %}
<li class="">
<a href="{{ page.permalink }}">{{ page.title | default(value=page.slug) | title }}</a>
</li>
{% endfor %}
</ul>
</div>
</li>
{% endfor %}
</ul>
```

View file

@ -0,0 +1,6 @@
+++
[taxonomies]
section = ["Components"]
+++
# dropdown.md

View file

@ -0,0 +1,6 @@
+++
[taxonomies]
section = ["Components"]
+++
# modal.md

View file

@ -0,0 +1,6 @@
+++
[taxonomies]
section = ["Components"]
+++
# offcanvas.md

View file

@ -0,0 +1,6 @@
+++
[taxonomies]
section = ["Components"]
+++
# tabs.md

View file

@ -0,0 +1,6 @@
+++
[taxonomies]
section = ["Components"]
+++
# tooltip.md

View file

@ -0,0 +1,4 @@
+++
+++
# Components

View file

@ -0,0 +1,6 @@
+++
[taxonomies]
section = ["Content"]
+++
# Buttons

View file

@ -0,0 +1,6 @@
+++
[taxonomies]
section = ["Content"]
+++
# Buttons

View file

@ -0,0 +1,6 @@
+++
[taxonomies]
section = ["Content"]
+++
# Buttons

View file

@ -0,0 +1,6 @@
+++
[taxonomies]
section = ["Content"]
+++
# Buttons

View file

@ -0,0 +1,4 @@
+++
+++
foo

View file

@ -0,0 +1,6 @@
+++
[taxonomies]
section = ["Elements"]
+++
# Buttons

View file

@ -0,0 +1,6 @@
+++
[taxonomies]
section = ["Elements"]
+++
# Buttons

View file

@ -0,0 +1,6 @@
+++
[taxonomies]
section = ["Elements"]
+++
# Buttons

View file

@ -0,0 +1,6 @@
+++
[taxonomies]
section = ["Elements"]
+++
# Buttons

View file

@ -0,0 +1,6 @@
+++
[taxonomies]
section = ["Elements"]
+++
# Buttons

View file

@ -0,0 +1,6 @@
+++
[taxonomies]
section = ["Elements"]
+++
# Buttons

View file

@ -0,0 +1,4 @@
+++
+++
# Components

View file

@ -0,0 +1,6 @@
+++
[taxonomies]
section = ["Layout"]
+++
# Buttons

View file

@ -0,0 +1,6 @@
+++
[taxonomies]
section = ["Layout"]
+++
# Buttons

View file

@ -0,0 +1,6 @@
+++
[taxonomies]
section = ["Layout"]
+++
# Buttons

View file

@ -0,0 +1,6 @@
+++
[taxonomies]
section = ["Layout"]
+++
# Buttons

View file

@ -0,0 +1,6 @@
+++
[taxonomies]
section = ["Layout"]
+++
# Buttons

View file

@ -0,0 +1,6 @@
+++
[taxonomies]
section = ["Layout"]
+++
# Buttons

View file

@ -1 +1,2 @@
import "@mini-strap/components/accordion/index.ts";
console.log("hello world!"); console.log("hello world!");

View file

@ -3,7 +3,9 @@
"type": "module", "type": "module",
"scripts": { "scripts": {
"link-dependencies": "bun run _scripts/link-dependencies.ts", "link-dependencies": "bun run _scripts/link-dependencies.ts",
"dev": "zola serve --port 3000 --fast" "prebuild": "bun run _scripts/build.ts",
"watch-deps": "bun run --watch _scripts/build.ts",
"dev": "zola serve --port 3000 --fast --open"
}, },
"dependencies": { "dependencies": {
"@mini-strap/core": "workspace:*", "@mini-strap/core": "workspace:*",

View file

@ -1,4 +1,6 @@
@use "@mini-strap/core"; @use "@mini-strap/core";
@use "@mini-strap/components/navbar/navbar.scss";
@use "@mini-strap/components/accordion/accordion.scss";
html { html {
// background-color: red; // background-color: red;

View file

@ -8,13 +8,14 @@
<title>alecodes.page</title> <title>alecodes.page</title>
<ViewTransitions /> <ViewTransitions />
<script src="/js/index.js"></script> {% block scripts %}<script src="/js/index.js"></script>{% endblock %}
<link rel="stylesheet" href="/css/style.css" /> <link rel="stylesheet" href="/css/style.css" />
</head> </head>
<body transition:animate="fade"> <body transition:animate="fade">
<header class="position-sticky py-1 py-lg-3"> <header class="msp-position-sticky msp-py-1 msp-py-lg-3">
{% include "partials/navbar.html" %} {% include "partials/header.html" %}
</header> </header>
<main> <main>
{% block content %}{% endblock %} {% block content %}{% endblock %}

View file

@ -0,0 +1,20 @@
<ul class="msp-list-unstyle msp-accordion">
<li>
<a href="/">Overview</a>
</li>
{% for item in get_taxonomy(kind="section") | get(key="items") %}
<li class="msp-accordion-item">
<a class="msp-accordion-header" href="{{ get_url(path="@/" ~ item.slug ~ "/_index.md") }}">{{ item.name | title }}</a>
<div class="msp-accordion-collapse">
<ul class="msp-list-unstyle msp-accordion-content">
{% for page in item.pages %}
<li class="">
<a href="{{ page.permalink }}">{{ page.title | default(value=page.slug) | title }}</a>
</li>
{% endfor %}
</ul>
</div>
</li>
{% endfor %}
</ul>

View file

@ -3,10 +3,4 @@
{% block content %} {% block content %}
{{section.content | safe}} {{section.content | safe}}
<ul>
{% for page in section.pages %}
<li><a href="{{page.permalink}}">{{page.path | safe}}</a></li>
{% endfor %}
</ul>
{% endblock content %} {% endblock content %}