2022-02-07 22:34:53 +08:00
|
|
|
<script lang="ts">
|
2023-07-05 00:21:23 +08:00
|
|
|
import { onMount } from "svelte";
|
2023-01-18 04:47:40 +08:00
|
|
|
|
|
|
|
export let value: string;
|
|
|
|
export let type: "gallery" | "table";
|
2023-07-05 00:21:23 +08:00
|
|
|
export let selected = false;
|
|
|
|
|
|
|
|
let size: number;
|
|
|
|
let el: HTMLDivElement;
|
|
|
|
|
|
|
|
function set_styles(element: HTMLElement, el_width: number): void {
|
|
|
|
if (!element || !el_width) return;
|
|
|
|
el.style.setProperty(
|
|
|
|
"--local-text-width",
|
|
|
|
`${el_width < 150 ? el_width : 200}px`
|
|
|
|
);
|
|
|
|
el.style.whiteSpace = "unset";
|
|
|
|
}
|
|
|
|
|
|
|
|
onMount(() => {
|
|
|
|
set_styles(el, size);
|
|
|
|
});
|
2022-02-01 21:45:55 +08:00
|
|
|
</script>
|
2022-02-01 23:46:50 +08:00
|
|
|
|
2023-01-18 04:47:40 +08:00
|
|
|
<div
|
2023-07-05 00:21:23 +08:00
|
|
|
bind:clientWidth={size}
|
|
|
|
bind:this={el}
|
2023-01-18 04:47:40 +08:00
|
|
|
class:table={type === "table"}
|
|
|
|
class:gallery={type === "gallery"}
|
|
|
|
class:selected
|
|
|
|
>
|
|
|
|
{value}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.gallery {
|
|
|
|
padding: var(--size-1) var(--size-2);
|
|
|
|
}
|
2023-07-05 00:21:23 +08:00
|
|
|
|
|
|
|
div {
|
|
|
|
overflow: hidden;
|
|
|
|
min-width: var(--local-text-width);
|
|
|
|
|
|
|
|
white-space: nowrap;
|
|
|
|
}
|
2023-01-18 04:47:40 +08:00
|
|
|
</style>
|