From 8a4cc7870a42dff8b8185ce0435b848e50d12ee4 Mon Sep 17 00:00:00 2001 From: _Kerman Date: Sun, 12 Nov 2023 12:44:41 +0800 Subject: [PATCH] upd: hide primary input when disabled --- .../src/blocks/component/getContent.r.ts | 47 ++++++++++--------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/packages/northstar/src/blocks/component/getContent.r.ts b/packages/northstar/src/blocks/component/getContent.r.ts index 517ac55..1c78f09 100644 --- a/packages/northstar/src/blocks/component/getContent.r.ts +++ b/packages/northstar/src/blocks/component/getContent.r.ts @@ -1,7 +1,7 @@ -import { Context, ref } from "refina"; -import { ComponentBlock } from "./block"; import { FUnderlineTextInput } from "@refina/fluentui"; +import { Context, ref } from "refina"; import { currentGraph } from "../../store"; +import { ComponentBlock } from "./block"; export function getContent(block: ComponentBlock) { const { @@ -23,25 +23,28 @@ export function getContent(block: ComponentBlock) { _.$cls`text-gray-600`; title(_); - _._span( - { - onmousedown: ev => ev.stopPropagation(), - onmouseup: ev => ev.stopPropagation(), - onclick: ev => ev.stopPropagation(), - onkeydown: ev => ev.stopPropagation(), - }, - _ => { - const inputRef = ref(); - _.$css`font-family: Consolas; max-width: 108px; padding-left:4px`; - _.$ref(inputRef) && _.fUnderlineTextInput(block.primaryValue, block.getPrimaryDisabled(), info.name); - inputRef.current!.inputRef.current!.node.onchange = () => { - currentGraph.pushRecord(); - }; - inputRef.current!.inputRef.current!.node.onfocus = () => { - currentGraph.addSelectedBlock(block, false); - _.$update(); - }; - }, - ); + if (!block.getPrimaryDisabled()) { + const propagationStopper = (ev: Event) => ev.stopPropagation(); + _._span( + { + onmousedown: propagationStopper, + onmouseup: propagationStopper, + onclick: propagationStopper, + onkeydown: propagationStopper, + }, + _ => { + const inputRef = ref(); + _.$css`font-family: Consolas; max-width: 108px; padding-left:4px`; + _.$ref(inputRef) && _.fUnderlineTextInput(block.primaryValue, false, info.name); + inputRef.current!.inputRef.current!.node.onchange = () => { + currentGraph.pushRecord(); + }; + inputRef.current!.inputRef.current!.node.onfocus = () => { + currentGraph.addSelectedBlock(block, false); + _.$update(); + }; + }, + ); + } }; }