mirror of
https://github.com/ragestudio/relic.git
synced 2025-06-09 10:34:18 +00:00
support local value changes
This commit is contained in:
parent
fd64d24470
commit
bdc0f6fbbd
@ -32,9 +32,21 @@ const PKGConfigs = (props) => {
|
|||||||
const config = defaultConfigs[key]
|
const config = defaultConfigs[key]
|
||||||
const storagedValue = configs[key]
|
const storagedValue = configs[key]
|
||||||
|
|
||||||
|
const [localValue, setLocalValue] = React.useState(storagedValue ?? config.default)
|
||||||
|
|
||||||
const ComponentType = config.ui_component ?? PKGConfigsComponentByTypes[config.type] ?? "input"
|
const ComponentType = config.ui_component ?? PKGConfigsComponentByTypes[config.type] ?? "input"
|
||||||
const ConfigComponent = PKGConfigsComponents[ComponentType]
|
const ConfigComponent = PKGConfigsComponents[ComponentType]
|
||||||
|
|
||||||
|
function handleOnChange(value) {
|
||||||
|
if (typeof value === "string" && config.string_trim === true) {
|
||||||
|
value = value.trim()
|
||||||
|
}
|
||||||
|
|
||||||
|
setLocalValue(value)
|
||||||
|
|
||||||
|
return props.onChange(key, value)
|
||||||
|
}
|
||||||
|
|
||||||
if (ConfigComponent == null) {
|
if (ConfigComponent == null) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
@ -42,33 +54,34 @@ const PKGConfigs = (props) => {
|
|||||||
const ComponentsProps = {
|
const ComponentsProps = {
|
||||||
...config.ui_component_props,
|
...config.ui_component_props,
|
||||||
defaultValue: storagedValue ?? config.default,
|
defaultValue: storagedValue ?? config.default,
|
||||||
|
value: localValue
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (ComponentType) {
|
switch (ComponentType) {
|
||||||
case "input": {
|
case "input": {
|
||||||
ComponentsProps.onChange = (e) => {
|
ComponentsProps.onChange = (e) => {
|
||||||
props.onChange(key, e.target.value)
|
handleOnChange(e.target.value)
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
case "slider": {
|
case "slider": {
|
||||||
ComponentsProps.onChange = (value) => {
|
ComponentsProps.onChange = (value) => {
|
||||||
props.onChange(key, value)
|
handleOnChange(value)
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
case "switch": {
|
case "switch": {
|
||||||
ComponentsProps.onChange = (checked) => {
|
ComponentsProps.onChange = (checked) => {
|
||||||
props.onChange(key, checked)
|
handleOnChange(checked)
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
default: {
|
default: {
|
||||||
ComponentsProps.onChange = (value) => {
|
ComponentsProps.onChange = (value) => {
|
||||||
props.onChange(key, value)
|
handleOnChange(value)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user