How to use the @bentley/ui-abstract.ConditionalDisplayType.Visibility function in @bentley/ui-abstract

To help you get started, we’ve selected a few @bentley/ui-abstract examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github imodeljs / imodeljs / test-apps / ui-test-app / src / frontend / tools / UiProviderTool.ts View on Github external
const simpleActionSpec: ActionItemInsertSpec = {
        itemType: ToolbarItemType.ActionButton,
        itemId: "simple-test-action-tool",
        execute: (): void => {
          // tslint:disable-next-line: no-console
          console.log("Got Here!");
        },
        icon: "icon-developer",
        label: "simple-test-action-tool",
      };

      const childActionSpec: ActionItemInsertSpec = {
        itemType: ToolbarItemType.ActionButton,
        itemId: "child-test-action-tool",
        condition: {
          type: ConditionalDisplayType.Visibility,
          testFunc: (): boolean => SampleAppIModelApp.getTestProperty() !== "HIDE",
          syncEventIds: [SampleAppUiActionId.setTestProperty],
        },
        execute: (): void => {
          // tslint:disable-next-line: no-console
          console.log("Got Here!");
        },
        icon: "icon-developer",
        label: "child-test-action-tool",
      };

      const nestedActionSpec: ActionItemInsertSpec = {
        itemType: ToolbarItemType.ActionButton,
        parentToolGroupId: "tool-formatting-setting",
        itemId: "nested-test-action-tool",
        execute: (): void => {
github imodeljs / imodeljs / ui / framework / src / ui-framework / widgets / ToolbarWidgetBase.tsx View on Github external
});
      itemDef = new GroupItemDef({
        groupId: groupSpec.itemId,
        iconSpec: groupSpec.icon,
        label: groupSpec.label,
        badgeType: groupSpec.badge,
        items: childItems,
      });
    }

    // If conditional display options are defined set up item def with necessary stateFunc and stateSyncIds
    // istanbul ignore else
    if (itemDef) {
      // istanbul ignore else
      if (spec.condition && spec.condition.testFunc && spec.condition.syncEventIds.length > 0) {
        if (spec.condition.type === ConditionalDisplayType.Visibility) {
          itemDef.stateFunc = (state: Readonly): BaseItemState => {
            return spec.condition!.testFunc() ? { ...state, isVisible: true } : { ...state, isVisible: false };
          };
        } else {
          itemDef.stateFunc = (state: Readonly): BaseItemState => {
            return spec.condition!.testFunc() ? { ...state, isEnabled: true } : { ...state, isEnabled: false };
          };
        }
        itemDef.stateSyncIds = spec.condition.syncEventIds;
      }
    }

    return itemDef;
  }