options.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import { PanelOptionsSupplier } from '@grafana/data/src/panel/PanelPlugin';
  2. import { BackgroundImageSize, CanvasElementOptions } from 'app/features/canvas';
  3. import { ColorDimensionEditor, ResourceDimensionEditor } from 'app/features/dimensions/editors';
  4. interface OptionSuppliers {
  5. addBackground: PanelOptionsSupplier<CanvasElementOptions>;
  6. addBorder: PanelOptionsSupplier<CanvasElementOptions>;
  7. }
  8. export const optionBuilder: OptionSuppliers = {
  9. addBackground: (builder, context) => {
  10. const category = ['Background'];
  11. builder
  12. .addCustomEditor({
  13. category,
  14. id: 'background.color',
  15. path: 'background.color',
  16. name: 'Color',
  17. editor: ColorDimensionEditor,
  18. settings: {},
  19. defaultValue: {
  20. // Configured values
  21. fixed: '',
  22. },
  23. })
  24. .addCustomEditor({
  25. category,
  26. id: 'background.image',
  27. path: 'background.image',
  28. name: 'Image',
  29. editor: ResourceDimensionEditor,
  30. settings: {
  31. resourceType: 'image',
  32. },
  33. })
  34. .addRadio({
  35. category,
  36. path: 'background.size',
  37. name: 'Image size',
  38. settings: {
  39. options: [
  40. { value: BackgroundImageSize.Original, label: 'Original' },
  41. { value: BackgroundImageSize.Contain, label: 'Contain' },
  42. { value: BackgroundImageSize.Cover, label: 'Cover' },
  43. { value: BackgroundImageSize.Fill, label: 'Fill' },
  44. { value: BackgroundImageSize.Tile, label: 'Tile' },
  45. ],
  46. },
  47. defaultValue: BackgroundImageSize.Cover,
  48. });
  49. },
  50. addBorder: (builder, context) => {
  51. const category = ['Border'];
  52. builder.addSliderInput({
  53. category,
  54. path: 'border.width',
  55. name: 'Width',
  56. defaultValue: 2,
  57. settings: {
  58. min: 0,
  59. max: 20,
  60. },
  61. });
  62. if (context.options?.border?.width) {
  63. builder.addCustomEditor({
  64. category,
  65. id: 'border.color',
  66. path: 'border.color',
  67. name: 'Color',
  68. editor: ColorDimensionEditor,
  69. settings: {},
  70. defaultValue: {
  71. // Configured values
  72. fixed: '',
  73. },
  74. });
  75. }
  76. },
  77. };