Create element and proficiency label components
This commit is contained in:
parent
2cf3c2067e
commit
d262eba8b2
2 changed files with 120 additions and 0 deletions
56
src/lib/components/labels/ElementLabel.svelte
Normal file
56
src/lib/components/labels/ElementLabel.svelte
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
<svelte:options runes={true} />
|
||||||
|
|
||||||
|
<script lang="ts">
|
||||||
|
import { getElementLabel, getElementIcon } from '$lib/utils/element'
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
element?: number
|
||||||
|
size?: 'small' | 'medium' | 'large' | 'xlarge' | 'natural'
|
||||||
|
}
|
||||||
|
|
||||||
|
let { element, size = 'natural' }: Props = $props()
|
||||||
|
|
||||||
|
const label = $derived(getElementLabel(element))
|
||||||
|
const imagePath = $derived(getElementIcon(element))
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if imagePath}
|
||||||
|
<img src={imagePath} alt={label} aria-label={`${label} element`} class="element-label {size}" />
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
@use '$src/themes/spacing' as spacing;
|
||||||
|
|
||||||
|
.element-label {
|
||||||
|
display: inline-block;
|
||||||
|
vertical-align: middle;
|
||||||
|
object-fit: contain;
|
||||||
|
|
||||||
|
&.natural {
|
||||||
|
// Display at natural size (34px height)
|
||||||
|
height: 34px;
|
||||||
|
width: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.small {
|
||||||
|
height: 20px;
|
||||||
|
width: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.medium {
|
||||||
|
height: 25px;
|
||||||
|
width: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.large {
|
||||||
|
// Natural size
|
||||||
|
height: 34px;
|
||||||
|
width: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.xlarge {
|
||||||
|
height: 51px;
|
||||||
|
width: auto;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
64
src/lib/components/labels/ProficiencyLabel.svelte
Normal file
64
src/lib/components/labels/ProficiencyLabel.svelte
Normal file
|
|
@ -0,0 +1,64 @@
|
||||||
|
<svelte:options runes={true} />
|
||||||
|
|
||||||
|
<script lang="ts">
|
||||||
|
import { getProficiencyLabel, getProficiencyIcon } from '$lib/utils/proficiency'
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
proficiency?: number
|
||||||
|
size?: 'small' | 'medium' | 'large' | 'xlarge' | 'natural'
|
||||||
|
}
|
||||||
|
|
||||||
|
let { proficiency, size = 'natural' }: Props = $props()
|
||||||
|
|
||||||
|
const label = $derived(getProficiencyLabel(proficiency ?? 0))
|
||||||
|
const imagePath = $derived(getProficiencyIcon(proficiency ?? 0))
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if imagePath}
|
||||||
|
<img
|
||||||
|
src={imagePath}
|
||||||
|
alt={label}
|
||||||
|
aria-label={`${label} proficiency`}
|
||||||
|
class="proficiency-label {size}"
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
@use '$src/themes/spacing' as spacing;
|
||||||
|
|
||||||
|
.proficiency-label {
|
||||||
|
display: inline-block;
|
||||||
|
vertical-align: middle;
|
||||||
|
object-fit: contain;
|
||||||
|
|
||||||
|
&.natural {
|
||||||
|
// Display at natural size (34px height)
|
||||||
|
height: 34px;
|
||||||
|
width: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.small {
|
||||||
|
// Half of natural size
|
||||||
|
height: 17px;
|
||||||
|
width: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.medium {
|
||||||
|
// ~75% of natural size
|
||||||
|
height: 25px;
|
||||||
|
width: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.large {
|
||||||
|
// Natural size
|
||||||
|
height: 34px;
|
||||||
|
width: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.xlarge {
|
||||||
|
// 1.5x natural size
|
||||||
|
height: 51px;
|
||||||
|
width: auto;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
Loading…
Reference in a new issue