added button groups

This commit is contained in:
Ulysia 2024-10-14 12:32:16 +02:00
parent ce307575ab
commit 99fc023e6b
3 changed files with 74 additions and 21 deletions

View file

@ -1,6 +1,5 @@
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types" import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
import style from "./styles/buttons8831.scss" import style from "./styles/buttons8831.scss"
import { useEffect, useState } from "preact/hooks"
// Import the JSON data // Import the JSON data
import buttonsData from "./buttons.json" import buttonsData from "./buttons.json"
@ -8,28 +7,66 @@ import buttonsData from "./buttons.json"
export default (() => { export default (() => {
// Define the component // Define the component
const Btn8831: QuartzComponent = ({ displayClass, cfg }: QuartzComponentProps) => { const Btn8831: QuartzComponent = ({ displayClass, cfg }: QuartzComponentProps) => {
// Since the data is static, you can directly use buttonsData // Group buttons by type
const [buttons, setButtons] = useState(buttonsData) const groupedButtons = groupButtonsByType(buttonsData)
// Optional: If you need to perform any data manipulation or sorting, you can do it here // Define the order of types
// For example, if buttonsData isn't sorted, but you need to sort it: const typeOrder = ["misc", "friend", "standard"]
// useEffect(() => {
// const sortedButtons = [...buttonsData].sort(/* your sorting function */);
// setButtons(sortedButtons);
// }, []);
return ( return (
<div class={`btn8831-container ${displayClass ?? ""}`}> <div class={`btn8831-container ${displayClass ?? ""}`}>
{buttons.map((button, index) => ( {typeOrder.map((type, index) => {
<a href={button.url} key={index}> const buttons = groupedButtons[type]
<img src={button.image} alt={button.alt} title={button.title} /> if (buttons && buttons.length > 0) {
</a> return (
))} <div key={type}>
{/* Render buttons of the current type */}
<div class="button-group">
{buttons.map((button, idx) => (
<a href={button.url} key={idx}>
<img src={button.image} alt={button.alt} title={button.title} />
</a>
))}
</div>
{/* Add a horizontal line after the group except for the last one */}
{index < typeOrder.length - 1 && <hr />}
</div>
)
}
return null
})}
{/* Include the iframe if needed */}
<iframe
src="//incr.easrng.net/badge?key=changeme"
style="background: url(//incr.easrng.net/bg.gif)"
title="increment badge"
width="88"
height="31"
frameborder="0"
></iframe>
</div> </div>
) )
} }
// Combine base styles with custom styles // Function to group buttons by type
function groupButtonsByType(buttons) {
const groups = {
misc: [],
friend: [],
standard: [],
}
buttons.forEach((button) => {
let type = button.type?.toLowerCase() || "standard"
if (type === "fren") type = "friend"
if (!groups[type]) type = "standard" // Default to 'standard' if type is unrecognized
groups[type].push(button)
})
return groups
}
// Use the existing style and add any additional styles if necessary
Btn8831.css = style Btn8831.css = style
return Btn8831 return Btn8831

View file

@ -3,12 +3,14 @@
"image": "https://assets.derg.cz/buttons/theysosmall_by_liah.png", "image": "https://assets.derg.cz/buttons/theysosmall_by_liah.png",
"url": "https://smolderg.xyz", "url": "https://smolderg.xyz",
"alt": "\"They so small!\" in large letters accompanied by an arrow pointing at a tiny dragon in the corner of the image, surrounded by the smaller bits of text \"Wow!\" \"Look!\" and \"Pet them!\"", "alt": "\"They so small!\" in large letters accompanied by an arrow pointing at a tiny dragon in the corner of the image, surrounded by the smaller bits of text \"Wow!\" \"Look!\" and \"Pet them!\"",
"title": "\"They so small!\" in large letters accompanied by an arrow pointing at a tiny dragon in the corner of the image, surrounded by the smaller bits of text \"Wow!\" \"Look!\" and \"Pet them!\"" "title": "\"They so small!\" in large letters accompanied by an arrow pointing at a tiny dragon in the corner of the image, surrounded by the smaller bits of text \"Wow!\" \"Look!\" and \"Pet them!\"",
"fren": true
}, },
{ {
"image": "https://assets.derg.cz/buttons/sirlan.png", "image": "https://assets.derg.cz/buttons/sirlan.png",
"url": "https://dragon-vi.be", "url": "https://dragon-vi.be",
"alt": "Button with the text Sirlan which points to dragon-vi.be", "alt": "Button with the text Sirlan which points to dragon-vi.be",
"title": "Sirlan, the adorable eastern derg" "title": "Sirlan, the adorable eastern derg",
"fren": true
} }
] ]

View file

@ -1,17 +1,31 @@
.btn8831-container { .btn8831-container {
display: flex; display: flex;
flex-wrap: wrap; flex-wrap: column;
justify-content: center; justify-content: center;
max-width: 60%; max-width: 60%;
margin: 0 auto; margin: 0 auto;
opacity: 1.0; opacity: 1.0;
} }
.btn8831-container a { .button-group a {
margin: 5px; margin: 5px;
opacity: 1; opacity: 1;
} }
.btn8831-container img { .button-group img {
width: 88px; width: 88px;
height: 31px; height: 31px;
opacity: 1; opacity: 1;
} }
.button-group {
display: flex;
flex-wrap: wrap;
justify-content: center;
margin-bottom: 10px; /* Space between groups */
}
.btn8831-container hr {
width: 100%;
border: 0;
border-top: 1px solid #ccc;
margin: 10px 0;
}