import { css } from '@emotion/css'; import React, { FC } from 'react'; import { GrafanaTheme2 } from '@grafana/data'; import { useStyles2 } from '@grafana/ui'; import { DimensionContext, ScalarDimensionConfig } from 'app/features/dimensions'; import { ScalarDimensionEditor } from 'app/features/dimensions/editors'; import { CanvasElementItem, CanvasElementProps } from '../element'; interface DroneFrontData { rollAngle?: number; } interface DroneFrontConfig { rollAngle?: ScalarDimensionConfig; } const DroneFrontDisplay: FC> = (props) => { const styles = useStyles2(getStyles); const { data } = props; const droneFrontTransformStyle = `rotate(${data?.rollAngle ? data.rollAngle : 0}deg)`; return ( ); }; export const droneFrontItem: CanvasElementItem = { id: 'droneFront', name: 'Drone Front', description: 'Drone front', display: DroneFrontDisplay, defaultSize: { width: 100, height: 100, }, getNewOptions: (options) => ({ ...options, }), // Called when data changes prepareData: (ctx: DimensionContext, cfg: DroneFrontConfig) => { const data: DroneFrontData = { rollAngle: cfg?.rollAngle ? ctx.getScalar(cfg.rollAngle).value() : 0, }; return data; }, registerOptionsUI: (builder) => { const category = ['Drone Front']; builder.addCustomEditor({ category, id: 'rollAngle', path: 'config.rollAngle', name: 'Roll Angle', editor: ScalarDimensionEditor, }); }, }; const getStyles = (theme: GrafanaTheme2) => ({ droneFront: css` transition: transform 0.4s; `, });