|
14 | 14 | * limitations under the License.
|
15 | 15 | */
|
16 | 16 |
|
| 17 | +import { useState } from 'react' |
17 | 18 | import Tippy from '@tippyjs/react'
|
18 |
| -import { noop } from '@Common/Helper' |
19 | 19 | import { ReactComponent as DockerIcon } from '../../../Assets/Icon/ic-docker.svg'
|
20 | 20 | import { ImageChipCellProps } from './types'
|
21 | 21 | import './imageChipCell.scss'
|
22 | 22 |
|
23 | 23 | const ImageChipCell = ({
|
24 | 24 | imagePath,
|
25 | 25 | registryType,
|
26 |
| - handleClick = noop, |
27 |
| - isExpanded = false, |
| 26 | + handleClick, |
| 27 | + isExpanded: isExpandedProp, |
28 | 28 | placement = 'auto',
|
29 |
| -}: ImageChipCellProps) => ( |
30 |
| - <div className="cn-7 fs-14 lh-20 flexbox"> |
31 |
| - <Tippy content={imagePath} className="default-tt" placement={placement} arrow={false}> |
32 |
| - <button |
33 |
| - type="button" |
34 |
| - className={`display-grid dc__align-items-center image-chip-cell__container ${isExpanded ? 'image-chip-cell__container--expanded' : ''} bcn-1 br-6 dc__transparent py-0 px-6 cursor max-w-100`} |
35 |
| - onClick={handleClick} |
36 |
| - > |
37 |
| - {registryType ? ( |
38 |
| - <div className={`h-14 w-14 dc__registry-icon ${registryType} br-8 dc__no-shrink`} /> |
39 |
| - ) : ( |
40 |
| - <DockerIcon className="icon-dim-14 mw-14" /> |
41 |
| - )} |
42 |
| - {isExpanded ? ( |
43 |
| - <div className="mono dc__ellipsis-left direction-left">{imagePath}</div> |
44 |
| - ) : ( |
45 |
| - <> |
46 |
| - <div>…</div> |
47 |
| - <div className="mono dc__ellipsis-left direction-left text-overflow-clip"> |
48 |
| - {imagePath.split(':').slice(-1)[0] ?? ''} |
49 |
| - </div> |
50 |
| - </> |
51 |
| - )} |
52 |
| - </button> |
53 |
| - </Tippy> |
54 |
| - </div> |
55 |
| -) |
| 29 | +}: ImageChipCellProps) => { |
| 30 | + const [isExpandedState, setIsExpandedState] = useState<boolean>(false) |
| 31 | + |
| 32 | + const handleToggleExpand = () => { |
| 33 | + setIsExpandedState((prev) => !prev) |
| 34 | + } |
| 35 | + |
| 36 | + const isExpanded = isExpandedProp ?? isExpandedState |
| 37 | + |
| 38 | + return ( |
| 39 | + <div className="cn-7 fs-14 lh-20 flexbox"> |
| 40 | + <Tippy content={imagePath} className="default-tt" placement={placement} arrow={false}> |
| 41 | + <button |
| 42 | + type="button" |
| 43 | + className={`display-grid dc__align-items-center dc__select-text image-chip-cell__container ${isExpanded ? 'image-chip-cell__container--expanded' : ''} bcn-1 br-6 dc__transparent py-0 px-6 cursor max-w-100`} |
| 44 | + onClick={handleClick || handleToggleExpand} |
| 45 | + > |
| 46 | + {registryType ? ( |
| 47 | + <div className={`h-14 w-14 dc__registry-icon ${registryType} br-8 dc__no-shrink`} /> |
| 48 | + ) : ( |
| 49 | + <DockerIcon className="icon-dim-14 mw-14" /> |
| 50 | + )} |
| 51 | + {isExpanded ? ( |
| 52 | + <div className="mono dc__ellipsis-left direction-left">{imagePath}</div> |
| 53 | + ) : ( |
| 54 | + <> |
| 55 | + <div>…</div> |
| 56 | + <div className="mono dc__ellipsis-left direction-left text-overflow-clip"> |
| 57 | + {imagePath.split(':').slice(-1)[0] ?? ''} |
| 58 | + </div> |
| 59 | + </> |
| 60 | + )} |
| 61 | + </button> |
| 62 | + </Tippy> |
| 63 | + </div> |
| 64 | + ) |
| 65 | +} |
56 | 66 |
|
57 | 67 | export default ImageChipCell
|
0 commit comments