upend/ui/src/components/utils/Ellipsis.svelte

48 lines
1 KiB
Svelte
Raw Normal View History

<script lang="ts">
export let value: string;
2021-12-21 22:48:30 +01:00
let root: HTMLDivElement;
$: valueStart = value.substring(0, value.length - 7);
$: valueEnd = value.substring(value.length - 7, value.length);
2021-12-21 22:48:30 +01:00
// If the break happens to be on a space, it gets collapsed; `white-space` CSS
// property doesn't help, and replacing the spaces in the strings gets escaped
// by Svelte; hence, direct manipulation of the DOM.
$: {
value;
Array.from(root?.children || []).forEach(
(el) => (el.innerHTML = el.innerHTML.replace(" ", "&nbsp;"))
);
}
</script>
2021-12-21 22:48:30 +01:00
<div class="ellipsis" bind:this={root}>
<div class="start">{valueStart}</div>
<div class="end">{valueEnd}</div>
</div>
<style lang="scss">
.ellipsis {
2021-12-11 21:34:00 +01:00
display: flex;
flex-wrap: nowrap;
max-width: 100%;
* {
display: inline-block;
overflow: hidden;
white-space: nowrap;
min-width: 0;
}
.start {
flex: 0 1 auto;
text-overflow: ellipsis;
}
.end {
flex: 1 0 auto;
white-space: nowrap;
}
}
</style>