Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F10360978
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/back/routes/common/show-first-row/show-first-row.tsx b/src/back/routes/common/show-first-row/show-first-row.tsx
index 253f0a7..b3b4d1b 100644
--- a/src/back/routes/common/show-first-row/show-first-row.tsx
+++ b/src/back/routes/common/show-first-row/show-first-row.tsx
@@ -1,134 +1,135 @@
import { TempstreamJSX } from "tempstream";
import type { FlatTemplatable } from "tempstream";
const showFirstRowIds = (function* () {
let i = 0;
while (true) {
yield i++;
if (i == 999999999) {
i = 0;
}
}
})();
function min_container_width(columns: number, column_width: number, gap: number) {
return columns * column_width + (columns - 1) * gap;
}
export async function showFirstRow({
items,
min_column_width_px = 250,
column_gap_px = 10,
row_gap_px = column_gap_px,
make_show_more_button = () => (
<span class="show-first-row__default-button">Show more</span>
),
make_show_less_button = () => (
<span class="show-first-row__default-button">Show less</span>
),
add_button_to_content = (content, show_more_button, show_less_button) => (
<>
{content}
{show_more_button}
{show_less_button}
</>
),
classes = [],
how_many_rows = () => 1,
}: {
items: FlatTemplatable[];
min_column_width_px?: number;
make_show_more_button?: () => JSX.Element;
make_show_less_button?: () => JSX.Element;
column_gap_px?: number;
row_gap_px?: number;
add_button_to_content?: (
content: JSX.Element,
show_more_button: JSX.Element,
show_less_button: JSX.Element
) => JSX.Element;
classes?: classNames.ArgumentArray;
how_many_rows?: (columns_count: number) => number;
}): Promise<string> {
const id = showFirstRowIds.next().value;
const checkbox_id = "show-first-row__checkbox--" + id;
return (
<div
class={[
"show-first-row",
`show-first-row--id-${id}`,
`show-first-row--items-count-${items.length}`,
...classes,
]}
style={`--min-column-width: ${min_column_width_px}px; --items-count: ${items.length}; --column-gap: ${column_gap_px}px`}
>
{[1, 2, 3, 4, 5, 6, 7, 8, 9]
.reverse()
.map((columns) => {
const rows = how_many_rows(columns);
return /* HTML */ `<style>
@container (min-width: ${min_container_width(
columns,
min_column_width_px,
column_gap_px
) + 1}px) and (max-width: ${min_container_width(
columns + 1,
min_column_width_px,
column_gap_px
)}px) {
.show-first-row--id-${id} {
&:not(
:has(
.show-first-row__items
> *:nth-child(${columns * rows + 1})
)
) {
.show-first-row__button {
display: none;
}
}
.show-first-row__checkbox:not(:checked)
+ .show-first-row__items {
grid-template-rows: ${"auto ".repeat(rows)} repeat(
calc(var(--items-count) - ${rows}),
0px
);
& > * {
margin-bottom: ${row_gap_px}px !important;
&:nth-child(n + ${columns * rows + 1}) {
opacity: 0;
pointer-events: none;
}
}
}
}
}
</style>`;
})
.join("\n")}
<input
class="show-first-row__checkbox"
+ autocomplete="off"
type="checkbox"
id={checkbox_id}
style="display: none"
/>
{add_button_to_content(
<div class={["show-first-row__items"]}>{items}</div>,
<label
for={checkbox_id}
class={["show-first-row__button", "show-first-row__show-more-button"]}
>
{make_show_more_button()}
</label>,
<label
for={checkbox_id}
class={["show-first-row__button", "show-first-row__show-less-button"]}
>
{make_show_less_button()}
</label>
)}
</div>
);
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sat, Nov 8, 10:19 (1 d, 5 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1032480
Default Alt Text
(3 KB)
Attached To
Mode
rREWRITE Configurable rewriter
Attached
Detach File
Event Timeline
Log In to Comment