|
| 1 | +// Copyright 2022 The Parca Authors |
| 2 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | +// you may not use this file except in compliance with the License. |
| 4 | +// You may obtain a copy of the License at |
| 5 | +// |
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +// |
| 8 | +// Unless required by applicable law or agreed to in writing, software |
| 9 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | +// See the License for the specific language governing permissions and |
| 12 | +// limitations under the License. |
| 13 | + |
| 14 | +import {Icon} from '@iconify/react'; |
| 15 | +import cx from 'classnames'; |
| 16 | + |
| 17 | +interface RefreshButtonProps { |
| 18 | + onClick: () => void; |
| 19 | + disabled: boolean; |
| 20 | + title: string; |
| 21 | + testId: string; |
| 22 | + loading?: boolean; |
| 23 | + sticky?: boolean; |
| 24 | +} |
| 25 | + |
| 26 | +const RefreshButton = ({ |
| 27 | + onClick, |
| 28 | + disabled, |
| 29 | + title, |
| 30 | + testId, |
| 31 | + sticky = false, |
| 32 | +}: RefreshButtonProps): JSX.Element => { |
| 33 | + return ( |
| 34 | + <div |
| 35 | + className={cx( |
| 36 | + 'w-full flex items-center justify-center px-3 py-2 bg-gray-50 dark:bg-gray-900 border-t border-gray-200 dark:border-gray-700', |
| 37 | + sticky && 'sticky bottom-0 z-20 mt-auto' |
| 38 | + )} |
| 39 | + > |
| 40 | + <button |
| 41 | + onClick={e => { |
| 42 | + e.preventDefault(); |
| 43 | + e.stopPropagation(); |
| 44 | + onClick(); |
| 45 | + }} |
| 46 | + disabled={disabled} |
| 47 | + className={cx( |
| 48 | + 'py-1 px-2 flex items-center gap-1 rounded-full transition-all duration-200 w-auto justify-center', |
| 49 | + disabled |
| 50 | + ? 'cursor-wait opacity-50' |
| 51 | + : 'hover:bg-gray-200 dark:hover:bg-gray-700 cursor-pointer' |
| 52 | + )} |
| 53 | + title={title} |
| 54 | + type="button" |
| 55 | + data-testid={testId} |
| 56 | + > |
| 57 | + <Icon |
| 58 | + icon="system-uicons:reset" |
| 59 | + className={cx('w-3 h-3 text-gray-500 dark:text-gray-400', disabled && 'animate-spin')} |
| 60 | + /> |
| 61 | + <span className="text-xs text-gray-500 dark:text-gray-400">Refresh results</span> |
| 62 | + </button> |
| 63 | + </div> |
| 64 | + ); |
| 65 | +}; |
| 66 | + |
| 67 | +export default RefreshButton; |
0 commit comments