|
| 1 | +/* |
| 2 | + * Copyright (c) 2024. Devtron Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +import Tippy from '@tippyjs/react' |
| 18 | +import { ConditionalWrap } from '@Common/Helper' |
| 19 | +import { SourceTypeCardProps } from './types' |
| 20 | + |
| 21 | +const SourceTypeCard = ({ |
| 22 | + title, |
| 23 | + subtitle, |
| 24 | + image, |
| 25 | + alt, |
| 26 | + dataTestId, |
| 27 | + type, |
| 28 | + handleCardAction, |
| 29 | + disableInfo, |
| 30 | + isDisabled = false, |
| 31 | +}: Readonly<SourceTypeCardProps>) => { |
| 32 | + const disableCard = !!disableInfo || isDisabled |
| 33 | + const renderTippy = (children) => ( |
| 34 | + <Tippy className="default-tt w-200" placement="top" content={disableInfo} arrow={false}> |
| 35 | + {/* Since in disabled state Tippy does'nt work */} |
| 36 | + <span>{children}</span> |
| 37 | + </Tippy> |
| 38 | + ) |
| 39 | + |
| 40 | + return ( |
| 41 | + <ConditionalWrap wrap={renderTippy} condition={!!disableInfo}> |
| 42 | + <div className={disableCard ? 'cursor-not-allowed dc__position-rel' : ''}> |
| 43 | + <div |
| 44 | + className={`flexbox p-12 dc__gap-12 dc__align-self-stretch br-4 dc__border-n1 bg__primary dc__hover-n50 ${ |
| 45 | + disableCard ? 'dc__disable-click dc__opacity-0_5' : '' |
| 46 | + }`} |
| 47 | + role="button" |
| 48 | + data-testid={dataTestId} |
| 49 | + data-pipeline-type={type} |
| 50 | + onClick={handleCardAction} |
| 51 | + onKeyDown={handleCardAction} |
| 52 | + tabIndex={disableCard ? -1 : 0} |
| 53 | + aria-disabled={disableCard} |
| 54 | + > |
| 55 | + <div> |
| 56 | + <img src={image} className="flex br-8" alt={alt} width={40} height={40} /> |
| 57 | + </div> |
| 58 | + |
| 59 | + <div className="flexbox-col pr-12"> |
| 60 | + {/* TITLE */} |
| 61 | + <p className="m-0 cn-9 fs-13 fw-6 lh-20">{title}</p> |
| 62 | + |
| 63 | + {/* SUBTITLE */} |
| 64 | + <p className="m-0 cn-7 fs-12 fw-4 lh-16">{subtitle}</p> |
| 65 | + </div> |
| 66 | + </div> |
| 67 | + </div> |
| 68 | + </ConditionalWrap> |
| 69 | + ) |
| 70 | +} |
| 71 | + |
| 72 | +export default SourceTypeCard |
0 commit comments