Bin
2025-12-16 9e0b2ba2c317b1a86212f24cbae3195ad1f3dbfa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { type Instance, type SnapshotIn, types } from "mobx-state-tree";
import { guidGenerator } from "../utils/unique";
 
export type CustomButtonType = Instance<typeof CustomButton>;
export type CustomButtonSnType = SnapshotIn<typeof CustomButton>;
/**
 * Custom buttons that can be injected from outside application.
 * The only required property is `name`. If the `name` is one of the predefined buttons, it will be rendered as such.
 * @see CustomControl in BottomBar/Controls
 */
export const CustomButton = types
  .model("CustomButton", {
    id: types.optional(types.identifier, guidGenerator),
    name: types.string,
    title: types.string,
    variant: types.maybe(
      types.enumeration(["primary", "neutral", "positive", "negative", "warning", "inverted"] as const),
    ),
    look: types.maybe(types.enumeration(["filled", "outlined", "string"])),
    size: types.maybe(types.enumeration(["medium", "small", "smaller"])),
    tooltip: types.maybe(types.string),
    ariaLabel: types.maybe(types.string),
    disabled: types.maybe(types.boolean),
    props: types.maybe(types.frozen()),
  })
  .actions((self) => ({
    updateState(newState: CustomButtonSnType) {
      for (const key in newState) {
        if (key in self) {
          self[key] = newState[key];
        }
      }
    },
  }));