Skip to main content
Sign in
Snippets Groups Projects
Commit 504894a1 authored by Emmanuel Raviart's avatar Emmanuel Raviart
Browse files

Change style of edited parameter (in edit page).

parent 6617158b
No related branches found
No related tags found
No related merge requests found
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
import { auditEditedAttribute } from "$lib/errors" import { auditEditedAttribute } from "$lib/errors"
import { metadata } from "$lib/metadata" import { metadata } from "$lib/metadata"
import { labelFromUnit } from "$lib/parameters" import { labelFromUnit } from "$lib/parameters"
import type { MaybeBooleanValue } from "@openfisca/json-model/build/parameters"
let globalErrors: { [key: string]: unknown } let globalErrors: { [key: string]: unknown }
export { globalErrors as errors } export { globalErrors as errors }
...@@ -32,6 +33,7 @@ ...@@ -32,6 +33,7 @@
function asMaybeNumberValue( function asMaybeNumberValue(
value: value:
| MaybeBooleanValue
| MaybeNumberValue | MaybeNumberValue
| MaybeStringArrayValue | MaybeStringArrayValue
| MaybeStringByStringValue | MaybeStringByStringValue
...@@ -69,22 +71,48 @@ ...@@ -69,22 +71,48 @@
) )
dispatch("change", valueAtInstant) dispatch("change", valueAtInstant)
} }
function valueHasChanged(
parameter: ValueParameter,
oldValueAtInstant: ValueAtInstant,
valueAtInstant: ValueAtInstant,
): boolean {
switch (parameter.type) {
case ValueType.Number:
return (
(valueAtInstant === "expected"
? null
: asMaybeNumberValue(valueAtInstant).value ?? null) !==
(oldValueAtInstant === "expected"
? null
: asMaybeNumberValue(oldValueAtInstant).value ?? null)
)
default:
console.log(`TODO: Handle parameter of type ${parameter.type}.`)
}
}
</script> </script>
<!-- svelte-ignore a11y-label-has-associated-control --> <!-- svelte-ignore a11y-label-has-associated-control -->
<label class="text-sm mb-4 mt-1"> <label class="text-sm mb-4 mt-1">
{#if parameter.type === ValueType.Number} {#if parameter.type === ValueType.Number}
{#if (valueAtInstant === "expected" ? null : asMaybeNumberValue(valueAtInstant).value ?? null) !== (oldValueAtInstant === "expected" ? null : asMaybeNumberValue(oldValueAtInstant).value ?? null)} {#if valueHasChanged(parameter, oldValueAtInstant, valueAtInstant)}
{#if oldValueAtInstant === "expected"} {#if oldValueAtInstant === "expected"}
<s>absent</s> <s>absent</s>
{:else} {:else}
<s class="font-serif text-base text-black bg-le-gris-dispositif-light" <s class="font-serif text-base text-black"
>{asMaybeNumberValue(oldValueAtInstant).value ?? "absent"}</s >{asMaybeNumberValue(oldValueAtInstant).value ?? "absent"}</s
> >
{/if} {/if}
{/if} {/if}
<input <input
class=" text-black hover:bg-le-gris-dispositif-light font-serif text-lg border-b border-t-0 border-l-0 border-r-0 px-2 py-0 mt-1 w-24" class=" text-black font-serif text-lg border-b border-t-0 border-l-0 border-r-0 px-2 py-0 mt-1 w-24 {valueHasChanged(
parameter,
oldValueAtInstant,
valueAtInstant,
)
? 'bg-le-gris-dispositif-light hover:text-le-gris-dispositif-dark'
: 'hover:text-le-gris-dispositif-dark'}"
step="any" step="any"
type="number" type="number"
on:change={changeValue} on:change={changeValue}
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment