import React, { useMemo } from 'react'; import { FieldOverrideEditorProps, SelectableValue } from '@grafana/data'; import { HorizontalGroup, IconButton, LineStyle, RadioButtonGroup, Select } from '@grafana/ui'; type LineFill = 'solid' | 'dash' | 'dot'; const lineFillOptions: Array> = [ { label: 'Solid', value: 'solid', }, { label: 'Dash', value: 'dash', }, // { // label: 'Dots', // value: 'dot', // }, ]; const dashOptions: Array> = [ '10, 10', // default '10, 15', '10, 20', '10, 25', '10, 30', '10, 40', '15, 10', '20, 10', '25, 10', '30, 10', '40, 10', '50, 10', '5, 10', '30, 3, 3', ].map(txt => ({ label: txt, value: txt, })); const dotOptions: Array> = [ '0, 10', // default '0, 20', '0, 30', '0, 40', '0, 3, 3', ].map(txt => ({ label: txt, value: txt, })); export const LineStyleEditor: React.FC> = ({ value, onChange }) => { const options = useMemo(() => (value?.fill === 'dash' ? dashOptions : dotOptions), [value]); const current = useMemo(() => { if (!value?.dash?.length) { return options[0]; } const str = value.dash?.join(', '); const val = options.find(o => o.value === str); if (!val) { return { label: str, value: str, }; } return val; }, [value, options]); return ( { onChange({ ...value, fill: v!, }); }} /> {value?.fill && value?.fill !== 'solid' && ( <>