grafana/public/app/plugins/datasource/elasticsearch/components/AddRemove.tsx
Josh Hunt 3c6e0e8ef8
Chore: ESlint import order (#44959)
* Add and configure eslint-plugin-import

* Fix the lint:ts npm command

* Autofix + prettier all the files

* Manually fix remaining files

* Move jquery code in jest-setup to external file to safely reorder imports

* Resolve issue caused by circular dependencies within Prometheus

* Update .betterer.results

* Fix missing // @ts-ignore

* ignore iconBundle.ts

* Fix missing // @ts-ignore
2022-04-22 14:33:13 +01:00

30 lines
821 B
TypeScript

import { css } from '@emotion/css';
import React from 'react';
import { IconButton } from './IconButton';
interface Props {
index: number;
elements: any[];
onAdd: () => void;
onRemove: () => void;
}
/**
* A component used to show add & remove buttons for mutable lists of values. Wether to show or not the add or the remove buttons
* depends on the `index` and `elements` props. This enforces a consistent experience whenever this pattern is used.
*/
export const AddRemove = ({ index, onAdd, onRemove, elements }: Props) => {
return (
<div
className={css`
display: flex;
`}
>
{index === 0 && <IconButton iconName="plus" onClick={onAdd} label="add" />}
{elements.length >= 2 && <IconButton iconName="minus" onClick={onRemove} label="remove" />}
</div>
);
};