Compare commits
2 Commits
af4cb15d2c
...
2794b21a41
| Author | SHA1 | Date |
|---|---|---|
|
|
2794b21a41 | |
|
|
d171e7b094 |
|
|
@ -22,6 +22,8 @@
|
|||
|
||||
:md-table[./sparks.csv]{roll remix}
|
||||
|
||||
:md-table[./npcs.csv]{roll}
|
||||
|
||||
### 链接
|
||||
|
||||
文本里面可以有:md-link[./stuff.md#啊什么]的啦
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
label,body
|
||||
"Hello world","**Hello**, world"
|
||||
"Hello foo","**Hello**, foo"
|
||||
"Hello bar","**Hello**, bar"
|
||||
"Hello stuff","**Hello**, stuff"
|
||||
"Hello again","**Hello**, again"
|
||||
|
|
|
@ -20,6 +20,7 @@ customElement('md-table', { roll: false, remix: false }, (props, { element }) =>
|
|||
const [activeTab, setActiveTab] = createSignal(0);
|
||||
const [activeGroup, setActiveGroup] = createSignal<string | null>(null);
|
||||
const [bodyHtml, setBodyHtml] = createSignal('');
|
||||
let tabsContainer: HTMLDivElement | undefined;
|
||||
|
||||
// 从 element 的 textContent 获取 CSV 路径
|
||||
const src = element?.textContent?.trim() || '';
|
||||
|
|
@ -140,12 +141,17 @@ customElement('md-table', { roll: false, remix: false }, (props, { element }) =>
|
|||
const handleRoll = () => {
|
||||
const randomIndex = Math.floor(Math.random() * filteredRows().length);
|
||||
setActiveTab(randomIndex);
|
||||
// 滚动到可视区域
|
||||
setTimeout(() => {
|
||||
const activeButton = tabsContainer?.querySelector('.border-blue-600');
|
||||
activeButton?.scrollIntoView({ behavior: 'smooth', block: 'nearest', inline: 'nearest' });
|
||||
}, 50);
|
||||
};
|
||||
|
||||
return (
|
||||
<div class="ttrpg-table">
|
||||
<div class="flex items-center gap-2 border-b border-gray-200">
|
||||
<div class="flex flex-col w-full">
|
||||
<div class="flex flex-col overflow-x-auto">
|
||||
{/* 分组 tabs */}
|
||||
<Show when={hasGroup()}>
|
||||
<div class="flex gap-2 border-b border-gray-100 pb-2">
|
||||
|
|
@ -176,21 +182,22 @@ customElement('md-table', { roll: false, remix: false }, (props, { element }) =>
|
|||
</div>
|
||||
</Show>
|
||||
{/* 内容 tabs */}
|
||||
<div class="flex gap-2">
|
||||
<div class="flex items-center gap-2">
|
||||
<Show when={props.roll}>
|
||||
<button
|
||||
onClick={handleRoll}
|
||||
class="text-gray-500 hover:text-gray-700"
|
||||
class="text-gray-500 hover:text-gray-700 flex-shrink-0"
|
||||
title="随机切换"
|
||||
>
|
||||
🎲
|
||||
</button>
|
||||
</Show>
|
||||
<div ref={tabsContainer} class="flex gap-2 overflow-x-auto flex-1 min-w-0">
|
||||
<For each={filteredRows()}>
|
||||
{(row, index) => (
|
||||
<button
|
||||
onClick={() => setActiveTab(index())}
|
||||
class={`font-medium transition-colors ${
|
||||
class={`font-medium transition-colors flex-shrink-0 ${
|
||||
activeTab() === index()
|
||||
? 'text-blue-600 border-b-2 border-blue-600'
|
||||
: 'text-gray-500 hover:text-gray-700'
|
||||
|
|
@ -203,6 +210,7 @@ customElement('md-table', { roll: false, remix: false }, (props, { element }) =>
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="p-1 prose max-w-none">
|
||||
<Show when={!csvData.loading && filteredRows().length > 0}>
|
||||
<div innerHTML={bodyHtml()} />
|
||||
|
|
|
|||
Loading…
Reference in New Issue