const Entry = ({ children, index }) => (
<div className="entry">
<div className="entry__inner">
<span className="entry__text">{children}</span>
<span className="entry__index">({index})</span>
</div>
</div>
);
const Demo = ({ entries }) => (
<table>
<thead>
<th>Name</th>
</thead>
<tbody>
{entries.map((text, index) => (
<tr key={index}>
<td>
<Entry index={index}>{text}</Entry>
</td>
</tr>
))}
</tbody>
</table>
);
const entries = ['entry', 'long entry', 'long long entry'];
ReactDOM.render(
<Demo entries={entries} />,
demo
);
td {
width: 5.5em;
}
.entry {
position: relative;
height: 1em;
}
.entry__inner {
position: absolute;
display: flex;
left: 0;
right: 0;
}
.entry__text {
flex: 1;
margin-right: 0.5em;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.entry__index {
text-align: right();
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
<div id="demo"></div>