ElementTile.svelte
automatically changes text color to ensure high contrast with its background. If its background is transparent, it traverses up the DOM tree to find the first element with non-transparent background color. This an, of course, go wrong e.g. if the tile is absolutely positioned outside its parent element. In that case, pass an explicit text_color
prop and text_color_threshold={null}
to ElementTile
to override the automatic color selection.
<script>
import { ElementTile, element_data } from '$lib'
const rand_color = () => `hsl(${Math.random() * 360}, ${Math.random() * 50 + 50}%, ${Math.random() * 50 + 50}%)`
</script>
<ol>
{#each Array(27).fill(0).map(rand_color) as bg_color, idx}
<ElementTile {bg_color} element={element_data[idx]} style="width: 4em; margin: 0;" />
{/each}
</ol>
2 He Helium
10 Ne Neon
18 Ar Argon
Displaying values instead of element names by passing the value
prop.
<script>
import { ElementTile, element_data } from '$lib'
</script>
<ol>
{#each ['red', 'green', 'blue', 'yellow', 'cyan', 'magenta', 'black', 'white'] as bg_color, idx}
<ElementTile {bg_color} element={element_data[idx]} value={Math.random()} style="width: 4em; margin: 0;" active />
{/each}
</ol>
2 He 0.129