|
| 1 | +/*! |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | +import { type ButtonProps, IconButton } from "@chakra-ui/react"; |
| 20 | +import type { FC, ReactElement } from "react"; |
| 21 | + |
| 22 | +import { Button, Tooltip } from "src/components/ui"; |
| 23 | + |
| 24 | +type Props = { |
| 25 | + readonly actionName: string; |
| 26 | + readonly colorPalette?: string; |
| 27 | + readonly icon: ReactElement; |
| 28 | + readonly onClick: () => void; |
| 29 | + readonly text: string; |
| 30 | + readonly variant?: string; |
| 31 | + readonly withText?: boolean; |
| 32 | +} & ButtonProps; |
| 33 | + |
| 34 | +const ActionButton = ({ |
| 35 | + actionName, |
| 36 | + colorPalette, |
| 37 | + icon, |
| 38 | + onClick, |
| 39 | + text, |
| 40 | + variant = "outline", |
| 41 | + withText = true, |
| 42 | +}: Props) => { |
| 43 | + const ButtonComponent: FC<ButtonProps> = withText ? Button : IconButton; |
| 44 | + |
| 45 | + return ( |
| 46 | + <Tooltip content={actionName} disabled={Boolean(withText)}> |
| 47 | + <ButtonComponent |
| 48 | + aria-label={actionName} |
| 49 | + colorPalette={withText ? colorPalette : "blue"} |
| 50 | + onClick={onClick} |
| 51 | + size={withText ? "md" : "sm"} |
| 52 | + variant={withText ? variant : "ghost"} |
| 53 | + > |
| 54 | + {icon} |
| 55 | + {withText ? text : ""} |
| 56 | + </ButtonComponent> |
| 57 | + </Tooltip> |
| 58 | + ); |
| 59 | +}; |
| 60 | + |
| 61 | +export default ActionButton; |
0 commit comments