function pokemonTable(
list,
{
columns = ["baseStats", "total", "hp", "atk", "def", "spa", "spd", "spe"],
rows = 30
} = {}
) {
return Inputs.table(list.map(normalizeData), {
rows,
columns: ["gen", "num", "sprite", "nameAndForme", "types", ...columns],
header: {
genderCode: "genderRatio",
nameAndForme: "pokemon"
},
format: {
gen: (gen) => formatGen(gen),
nameAndForme: ({ name, forme }) => {
return html`
<div>
<div style="font-weight: bold;">${name}</div>
<div>${forme ?? ""}</div>
</div>
`;
},
types: (ts) =>
html`<div style="display: flex; width: 4rem; flex-direction: column; gap: 0.125rem;">${ts.map(
renderType
)}</div>`,
sprite: (spriteUrl) =>
html`<img src="${spriteUrl}" style="max-height:3rem;" />`,
heightm: (h) => h.toFixed(1),
weightkg: (w) => w.toFixed(1),
baseStats: renderBaseStats,
abilities: (abilities) =>
html`<div style="display:flex;flex-direction:column">${abilities.map(
(ability) => `<div>${ability}</div>`
)}</div>`,
evYield: (evYield) => {
return html`<div>
${Object.entries(evYield).map(
([stat, value]) => `<div>${value} ${statDisplayMap[stat]}</div>`
)}
</div>`;
},
eggGroups: (eggGroups) =>
html`<div style="display:flex;flex-direction:column">${eggGroups.map(
(eggGroup) => `<div>${eggGroup}</div>`
)}</div>`,
genderCode: (code) => {
const text = displayGenderRatio(code);
const mPercent = code === -1 ? 0 : (code / 8) * 100;
const fPercent = code === -1 ? 0 : ((8 - code) / 8) * 100;
const nPercent = code === -1 ? 100 : 0;
return html`
<div style="display:flex;flex-direction:column;align-items:center;">
<div style="width:100%; height:1rem; display:flex; border-radius: 8px; overflow:hidden">
<div style="height:100%; background-color:lightskyblue; width: ${mPercent}%"></div>
<div style="height:100%; background-color:pink; width: ${fPercent}%"></div>
<div style="height:100%; background-color:grey; width: ${nPercent}%"></div>
</div>
<div>${text}</div>
</div>
`;
}
}
});
}