Skip to content

Commit

Permalink
checkbox-section WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
qiyundai committed Mar 30, 2024
1 parent 4b965f8 commit a31409a
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 4 deletions.
Empty file.
3 changes: 0 additions & 3 deletions blocks/checkbox-fieldset/checkbox-fieldset.js

This file was deleted.

3 changes: 3 additions & 0 deletions blocks/checkbox-section/checkbox-section.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.checkbox-section {
border-bottom: 2px solid var(--color-gray-300);
}
35 changes: 35 additions & 0 deletions blocks/checkbox-section/checkbox-section.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { getLibs } from '../../scripts/utils.js';

const { html, render, useState } = await import(`${getLibs()}/deps/htm-preact.js`);

const CheckboxSection = (props) => {
const [checked, setChecked] = useState(false);

return html`
<section>
<h2>${props.heading}</h2>
<div>tooltip placeholder</div>
${props.checkboxes.map((checkboxName) => html`
<input type="checkbox" id="scales" name="scales" checked=${checked} />
<label for="scales">${checkboxName}</label>
`)}
</section>
`;
};

export default function init(el) {
const incasingFormHandler = el.closest('.form-handler');
if (!incasingFormHandler) return;

const heading = el.querySelector('h2')?.textContent.trim();
const tooltip = el.querySelector('p > em')?.textContent.trim();
const checkboxes = Array.from(el.querySelectorAll('ul > li'))?.map((li) => li.textContent.trim());
const props = {
heading,
tooltip,
checkboxes,
};

el.innerHTML = '';
render(html`<${() => CheckboxSection(props)} />`, el);
}
3 changes: 3 additions & 0 deletions blocks/form-handler/form-handler.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.form-handler {
display: block;
}
2 changes: 1 addition & 1 deletion blocks/form-handler/form-handler.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default function init(el) {
console.log('handler loaded');
console.log(el, 'handler loaded');
}

0 comments on commit a31409a

Please sign in to comment.