Skip to content

Extension & Customization

TechUI allows developers to perform deep customization of the control panel, including excluding unwanted default options or injecting business-specific configuration switches.

All customization operations are implemented by modifying the global state $tState.controlPanel.

Excluding Default Items

If you do not want users to see certain system settings (e.g., you don't want users to turn off sound), you can add the corresponding label to the exclusion array.

javascript
import { inject, onMounted } from 'vue';

const { $tState } = inject('$global');

onMounted(() => {
  // Hide "Sound" and "Menu Trigger" settings
  $tState.controlPanel.exclusion = ['sound', 'menuTrigger'];
});

List of Excludable Labels:theme, t3D, maskBlur, transition, sound, adaptive, floaterTo, resizeBy, background, menuTrigger.

Injecting Custom Items

You can add custom switches or options to the panel to control business logic.

Data Structure

Push objects that meet the specifications into the extension array. The object must contain the following fields:

FieldTypeDescription
labelStringUnique identifier, corresponds to the Key in $globalConfig.
typeStringControl type: 'switch' (Switch) or 'radio' (Radio Group).
valueAnyDefault value.
titleStringTitle text displayed on the panel.
tipContentString(Optional) Tooltip content displayed when hovering over the info icon.
childrenArray(Radio type only) List of options, structure is { label, value }.

Full Development Example

The following example demonstrates how to add a Switch and a Radio Group simultaneously.

javascript
import { inject, onMounted, watch } from 'vue';

const { $tState, $globalConfig } = inject('$global');

// Define extension configuration array
const myExtensions = [
  // Case 1: Append a global switch
  {
    label: "extendItem",
    type: "switch",
    title: "Appended Toggle",
    value: true,
    tipContent: "Append a global Toggle to the control panel via Extension"
  },
  
  // Case 2: Append a global radio group
  {
    label: "extendArray",
    type: "radio",
    title: "Appended Radio",
    value: "item3",
    tipContent: "Append a global Radio to the control panel via Extension",
    children: [
      { label: "Option 1", value: "item1" },
      { label: "Option 2", value: "item2" },
      { label: "Option 3", value: "item3" },
    ]
  },
];

onMounted(() => {
  // 1. Inject extension items
  $tState.controlPanel.extension = myExtensions;
  
  // 2. (Optional) Configure other panel properties simultaneously
  // $tState.controlPanel.exclusion = ["t3D"]; // Exclude 3D panel options
  // $tState.controlPanel.width = 300;        // Modify panel width
});

// 3. Watch for configuration changes (Business Logic)
watch(() => $globalConfig.value.extendItem, (val) => {
  console.log("Appended Toggle state changed to:", val);
});

watch(() => $globalConfig.value.extendArray, (val) => {
  console.log("Appended Radio value is:", val);
});

Working Principle

After you inject the above configuration into extension:

  1. Auto Rendering: The control panel automatically renders the corresponding UI component based on type.
  2. State Binding: The system automatically registers the extendItem and extendArray fields in $globalConfig.
  3. Instant Response: When users operate the panel, the corresponding values in $globalConfig update in real-time. You only need to watch these values in your business code to implement functionality.

Appearance Configuration

You can also directly control the properties of the panel container.

javascript
// Set panel width to 400px
$tState.controlPanel.width = 400;

// Disable modal background (clicking mask does not close, and background does not darken)
$tState.controlPanel.modal = false;

Toggle Component

The trigger component used to call out the control panel.

Property NameTypeDefaultDescription
modelValueBooleanfalse(v-model) Controls the active state of the trigger, usually no manual binding needed.
appearanceString'iconPlain'Appearance style. Options: 'iconPlain' (Plain Icon), 'iconButton' (Button), 'toggleRound' (Round Switch), 'toggleRect' (Square Switch).
sizeString'default'Size. Options: 'small', 'default', 'large'.
iconString/Array'tui-icon ti-cog'Icon class name.
directionString'h'Alignment direction. Options: 'h' (Horizontal), 'v' (Vertical).
showLabelBooleanfalseWhether to show text label.
labelStringnullContent of the text label.

Control Panel Component

Customize by modifying the parameters of $tState.controlPanel.

The core state object of the control panel.

Property NameTypeDescription
visibleBooleanControls the display and hiding of the control panel.
widthNumberThe width of the panel drawer (px).
modalBooleanWhether to enable the modal background mask for the drawer.
exclusionArrayString array used to store the Labels of default configuration items to be hidden.
extensionArrayObject array used to store custom extension configuration items.

Released under the MIT License.