use Checkbox component in database edit pages with element theming
This commit is contained in:
parent
b8ad70229d
commit
d5a22baa0a
3 changed files with 47 additions and 24 deletions
|
|
@ -4,6 +4,7 @@
|
||||||
import type { Snippet } from 'svelte'
|
import type { Snippet } from 'svelte'
|
||||||
import Input from './Input.svelte'
|
import Input from './Input.svelte'
|
||||||
import Select from './Select.svelte'
|
import Select from './Select.svelte'
|
||||||
|
import Checkbox from './checkbox/Checkbox.svelte'
|
||||||
|
|
||||||
interface SelectOption {
|
interface SelectOption {
|
||||||
value: string | number
|
value: string | number
|
||||||
|
|
@ -18,7 +19,8 @@
|
||||||
editable = false,
|
editable = false,
|
||||||
type = 'text',
|
type = 'text',
|
||||||
options,
|
options,
|
||||||
placeholder
|
placeholder,
|
||||||
|
element
|
||||||
}: {
|
}: {
|
||||||
label: string
|
label: string
|
||||||
value?: string | number | boolean | null | undefined
|
value?: string | number | boolean | null | undefined
|
||||||
|
|
@ -27,6 +29,7 @@
|
||||||
type?: 'text' | 'number' | 'select' | 'checkbox'
|
type?: 'text' | 'number' | 'select' | 'checkbox'
|
||||||
options?: SelectOption[]
|
options?: SelectOption[]
|
||||||
placeholder?: string
|
placeholder?: string
|
||||||
|
element?: 'wind' | 'fire' | 'water' | 'earth' | 'dark' | 'light'
|
||||||
} = $props()
|
} = $props()
|
||||||
|
|
||||||
// For checkbox type, convert value to boolean
|
// For checkbox type, convert value to boolean
|
||||||
|
|
@ -46,10 +49,7 @@
|
||||||
{#if type === 'select' && options}
|
{#if type === 'select' && options}
|
||||||
<Select bind:value={value as string | number | undefined} {options} {placeholder} size="medium" contained />
|
<Select bind:value={value as string | number | undefined} {options} {placeholder} size="medium" contained />
|
||||||
{:else if type === 'checkbox'}
|
{:else if type === 'checkbox'}
|
||||||
<label class="checkbox-wrapper">
|
<Checkbox bind:checked={checkboxValue} contained {element} />
|
||||||
<input type="checkbox" bind:checked={checkboxValue} class="checkbox" />
|
|
||||||
<span class="checkbox-label">{checkboxValue ? 'Yes' : 'No'}</span>
|
|
||||||
</label>
|
|
||||||
{:else if type === 'number'}
|
{:else if type === 'number'}
|
||||||
<Input
|
<Input
|
||||||
bind:value
|
bind:value
|
||||||
|
|
@ -131,22 +131,5 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.checkbox-wrapper {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: spacing.$unit;
|
|
||||||
cursor: pointer;
|
|
||||||
|
|
||||||
.checkbox {
|
|
||||||
width: spacing.$unit-2x;
|
|
||||||
height: spacing.$unit-2x;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
.checkbox-label {
|
|
||||||
color: var(--text-primary);
|
|
||||||
user-select: none;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
||||||
|
|
@ -164,6 +164,37 @@
|
||||||
--cb-checked-fg: white;
|
--cb-checked-fg: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Element colors when bound (higher specificity to override .checkbox.bound)
|
||||||
|
:global(.checkbox.bound.wind[data-state='checked']),
|
||||||
|
:global(.checkbox.bound.wind[data-state='indeterminate']),
|
||||||
|
:global(.checkbox.bound.fire[data-state='checked']),
|
||||||
|
:global(.checkbox.bound.fire[data-state='indeterminate']),
|
||||||
|
:global(.checkbox.bound.water[data-state='checked']),
|
||||||
|
:global(.checkbox.bound.water[data-state='indeterminate']),
|
||||||
|
:global(.checkbox.bound.earth[data-state='checked']),
|
||||||
|
:global(.checkbox.bound.earth[data-state='indeterminate']),
|
||||||
|
:global(.checkbox.bound.dark[data-state='checked']),
|
||||||
|
:global(.checkbox.bound.dark[data-state='indeterminate']),
|
||||||
|
:global(.checkbox.bound.light[data-state='checked']),
|
||||||
|
:global(.checkbox.bound.light[data-state='indeterminate']) {
|
||||||
|
background-color: var(--cb-checked-bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
:global(.checkbox.bound.wind[data-state='checked']:hover:not(:disabled)),
|
||||||
|
:global(.checkbox.bound.wind[data-state='indeterminate']:hover:not(:disabled)),
|
||||||
|
:global(.checkbox.bound.fire[data-state='checked']:hover:not(:disabled)),
|
||||||
|
:global(.checkbox.bound.fire[data-state='indeterminate']:hover:not(:disabled)),
|
||||||
|
:global(.checkbox.bound.water[data-state='checked']:hover:not(:disabled)),
|
||||||
|
:global(.checkbox.bound.water[data-state='indeterminate']:hover:not(:disabled)),
|
||||||
|
:global(.checkbox.bound.earth[data-state='checked']:hover:not(:disabled)),
|
||||||
|
:global(.checkbox.bound.earth[data-state='indeterminate']:hover:not(:disabled)),
|
||||||
|
:global(.checkbox.bound.dark[data-state='checked']:hover:not(:disabled)),
|
||||||
|
:global(.checkbox.bound.dark[data-state='indeterminate']:hover:not(:disabled)),
|
||||||
|
:global(.checkbox.bound.light[data-state='checked']:hover:not(:disabled)),
|
||||||
|
:global(.checkbox.bound.light[data-state='indeterminate']:hover:not(:disabled)) {
|
||||||
|
background-color: var(--cb-checked-bg-hover);
|
||||||
|
}
|
||||||
|
|
||||||
// Size variations
|
// Size variations
|
||||||
:global(.checkbox.small) {
|
:global(.checkbox.small) {
|
||||||
--cb-icon-size: #{calc($unit * 1.5)};
|
--cb-icon-size: #{calc($unit * 1.5)};
|
||||||
|
|
|
||||||
|
|
@ -212,6 +212,13 @@
|
||||||
|
|
||||||
const uncapLevel = $derived(getCharacterMaxUncapLevel({ special, uncap: { flb, ulb, transcendence } }))
|
const uncapLevel = $derived(getCharacterMaxUncapLevel({ special, uncap: { flb, ulb, transcendence } }))
|
||||||
const transcendenceStage = $derived(transcendence ? 5 : 0)
|
const transcendenceStage = $derived(transcendence ? 5 : 0)
|
||||||
|
|
||||||
|
// Get element name for checkbox theming
|
||||||
|
const elementName = $derived.by(() => {
|
||||||
|
const el = editMode ? editData.element : character?.element
|
||||||
|
const label = getElementLabel(el)
|
||||||
|
return label !== '—' && label !== 'Null' ? label.toLowerCase() as 'wind' | 'fire' | 'water' | 'earth' | 'dark' | 'light' : undefined
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
|
|
@ -278,19 +285,21 @@
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if editMode}
|
{#if editMode}
|
||||||
<DetailItem label="FLB" bind:value={editData.flb} editable={true} type="checkbox" />
|
<DetailItem label="FLB" bind:value={editData.flb} editable={true} type="checkbox" element={elementName} />
|
||||||
<DetailItem label="ULB" bind:value={editData.ulb} editable={true} type="checkbox" />
|
<DetailItem label="ULB" bind:value={editData.ulb} editable={true} type="checkbox" element={elementName} />
|
||||||
<DetailItem
|
<DetailItem
|
||||||
label="Transcendence"
|
label="Transcendence"
|
||||||
bind:value={editData.transcendence}
|
bind:value={editData.transcendence}
|
||||||
editable={true}
|
editable={true}
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
|
element={elementName}
|
||||||
/>
|
/>
|
||||||
<DetailItem
|
<DetailItem
|
||||||
label="Special"
|
label="Special"
|
||||||
bind:value={editData.special}
|
bind:value={editData.special}
|
||||||
editable={true}
|
editable={true}
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
|
element={elementName}
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue