I have just started learning Svelte
. I want to display as much as email fit in one line and show the remaining emails with a number like this: https://imgur.com/ro8eTPM
I want achieve this without modifying the code in the parent component. I just want to change the DisplayEmail component
.
So far I have done this: https://imgur.com/qEeY1q7
<!-- Parent component -->
<script lang="ts">
import DisplayEmail from components/DisplayEmail.svelte
const emailList = [
[ abc@yahoo.com , abc@hotmail.com , abc@hotmail.com , abc@gmail.com ],
]
</script>
<style lang="scss">
$border-style: solid 1px #777;
table {
table-layout: fixed;
border: $border-style;
width: 100%;
text-align: left;
}
th,
td {
border: $border-style;
padding: 5px 10px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
height: 34px;
box-sizing: border-box;
}
th {
&:nth-child(1) {
width: 20%;
}
&:nth-child(2) {
width: 30%;
}
&:nth-child(3) {
width: 50%;
}
&:nth-child(4) {
width: 90px;
}
&:nth-child(5) {
width: 70px;
}
}
tbody:nth-child(even) {
background-color: #ddd;
}
.align-right {
text-align: right;
}
</style>
<table cellspacing="0">
<thead>
<tr>
<th>Sender</th>
<th>Recipients</th>
<th>Subject</th>
<th class="align-right">Date</th>
<th class="align-right">Time</th>
</tr>
</thead>
<tbody>
{#each emailList as emails}
<tr>
<td>demo@gmail.com</td>
<td>
<DisplayEmail {emails} />
</td>
<td>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Enim, odio.
</td>
<td class="align-right">n/a</td>
<td class="align-right">n/a</td>
</tr>
{/each}
</tbody>
</table>
<!--DisplayEmail Component -->
<script lang="ts">
export let emails
let showEmail = emails.map((email: string) => email)
let spanWidth
</script>
<span bind:offsetWidth={spanWidth}>{showEmail}</span>