import { css } from '@emotion/css'; import React from 'react'; import { GrafanaTheme2 } from '@grafana/data'; import { useStyles2 } from '@grafana/ui'; import { Constraint, HorizontalConstraint, VerticalConstraint } from 'app/features/canvas'; interface Props { onVerticalConstraintChange: (v: VerticalConstraint) => void; onHorizontalConstraintChange: (h: HorizontalConstraint) => void; currentConstraints: Constraint; } export const ConstraintSelectionBox = ({ onVerticalConstraintChange, onHorizontalConstraintChange, currentConstraints, }: Props) => { const styles = useStyles2(getStyles(currentConstraints)); const onClickTopConstraint = () => { onVerticalConstraintChange(VerticalConstraint.Top); }; const onClickBottomConstraint = () => { onVerticalConstraintChange(VerticalConstraint.Bottom); }; const onClickVerticalCenterConstraint = () => { onVerticalConstraintChange(VerticalConstraint.Center); }; const onClickLeftConstraint = () => { onHorizontalConstraintChange(HorizontalConstraint.Left); }; const onClickRightConstraint = () => { onHorizontalConstraintChange(HorizontalConstraint.Right); }; const onClickHorizontalCenterConstraint = () => { onHorizontalConstraintChange(HorizontalConstraint.Center); }; return ( ); }; const getStyles = (currentConstraints: Constraint) => (theme: GrafanaTheme2) => { const HOVER_COLOR = '#daebf7'; const HOVER_OPACITY = '0.6'; const SELECTED_COLOR = '#0d99ff'; const selectionBoxColor = theme.isDark ? '#ffffff' : '#000000'; return { constraintHover: css` &:hover { fill: ${HOVER_COLOR}; fill-opacity: ${HOVER_OPACITY}; } `, topConstraint: css` ${currentConstraints.vertical === VerticalConstraint.Top || currentConstraints.vertical === VerticalConstraint.TopBottom ? `width: 92pt; x: 1085; fill: ${SELECTED_COLOR};` : `fill: ${selectionBoxColor};`} `, bottomConstraint: css` ${currentConstraints.vertical === VerticalConstraint.Bottom || currentConstraints.vertical === VerticalConstraint.TopBottom ? `width: 92pt; x: 1085; fill: ${SELECTED_COLOR};` : `fill: ${selectionBoxColor};`} `, leftConstraint: css` ${currentConstraints.horizontal === HorizontalConstraint.Left || currentConstraints.horizontal === HorizontalConstraint.LeftRight ? `height: 92pt; y: 1014; fill: ${SELECTED_COLOR};` : `fill: ${selectionBoxColor};`} `, rightConstraint: css` ${currentConstraints.horizontal === HorizontalConstraint.Right || currentConstraints.horizontal === HorizontalConstraint.LeftRight ? `height: 92pt; y: 1014; fill: ${SELECTED_COLOR};` : `fill: ${selectionBoxColor};`} `, horizontalCenterConstraint: css` ${currentConstraints.horizontal === HorizontalConstraint.Center ? `height: 92pt; y: 1014; fill: ${SELECTED_COLOR};` : `fill: ${selectionBoxColor};`} `, verticalCenterConstraint: css` ${currentConstraints.vertical === VerticalConstraint.Center ? `width: 92pt; x: 1085; fill: ${SELECTED_COLOR};` : `fill: ${selectionBoxColor};`} `, box: css` fill: ${selectionBoxColor}; `, }; };