status-bar@0.1.1
scrapboxのstatus barと大体同じPreact Component
status-bar@0.1.0からの変更点
react-wcではなくpreact-custom-elementで閉じ込める
code:script.js
import {html} from '../htm@3.0.4%2Fpreact/script.js';
import register from '../preact-custom-element@4.2.1/script.js';
const statusBar = () => {
return html`
<style>
:host {
display: inline-block;
position: absolute;
background-color: var(--page-bg, #fefefe);
cursor: default;
}
:host(orientation="top-left") {
top: 0;
left: 0;
}
:host(orientation="top-left") ::slotted(*) {
border-right: 1px solid var(--status-bar-border-color, #a9aaaf);
border-bottom: 1px solid var(--status-bar-border-color, #a9aaaf);
}
:host(orientation="top-left") ::slotted(*:last-of-type) {
border-bottom-right-radius: 3px;
}
:host(orientation="top-right") {
top: 0;
right: 0;
}
:host(orientation="top-right") ::slotted(*) {
border-left: 1px solid var(--status-bar-border-color, #a9aaaf);
border-bottom: 1px solid var(--status-bar-border-color, #a9aaaf);
}
:host(orientation="top-right") ::slotted(*:first-of-type) {
border-bottom-left-radius: 3px;
}
:host(orientation="bottom-right") {
bottom: 0;
right: 0;
}
:host(orientation="bottom-right") ::slotted(*) {
border-top: 1px solid var(--status-bar-border-color, #a9aaaf);
border-left: 1px solid var(--status-bar-border-color, #a9aaaf);
}
:host(orientation="bottom-right") ::slotted(*:first-of-type) {
border-top-left-radius: 3px;
}
:host(orientation="bottom-left") {
bottom: 0;
left: 0;
}
:host(orientation="bottom-left") ::slotted(*) {
border-right: 1px solid var(--status-bar-border-color, #a9aaaf);
border-top: 1px solid var(--status-bar-border-color, #a9aaaf);
}
:host(orientation="bottom-left") ::slotted(*:last-of-type) {
border-top-right-radius: 3px;
}
</style>
<slot />
`;
};
const tag = 'x-userscript-status-bar';
register(statusBar, tag, 'orientation', {shadow: true});
export const StatusBar = ({children, orientation}) =>
html<${tag} orientation="${orientation}">${children}</${tag}>;
test code
code:js
import('/api/code/programming-notes/status-bar@0.1.1/test.js');
code:test.js
import {html, render} from '../htm@3.0.4%2Fpreact/script.js';
import {StatusBar} from './script.js';
render(html<${StatusBar} orientation="top-left"><span>status</span><//>, document.getElementById('app-container').firstElementChild);