11import React from 'react' ;
22import PropTypes from 'prop-types' ;
33// import { Scale32 } from '@carbon/icons-react';
4+ import { Close16 } from '@carbon/icons-react' ;
5+ import { Button } from 'carbon-components-react' ;
6+ import omit from 'lodash/omit' ;
47
5- // import Button from '../../../../Button';
68import { settings } from '../../../../../constants/Settings' ;
79
810const { iotPrefix, prefix } = settings ;
@@ -22,7 +24,7 @@ const propTypes = {
2224 interval : PropTypes . string ,
2325 } ) ,
2426 /* callback when image input value changes (File object) */
25- // onChange: PropTypes.func.isRequired,
27+ onChange : PropTypes . func . isRequired ,
2628 i18n : PropTypes . shape ( { } ) ,
2729} ;
2830
@@ -32,10 +34,11 @@ const defaultProps = {
3234 imageFile : 'Image file' ,
3335 editImage : 'Edit image' ,
3436 image : 'Image' ,
37+ close : 'Close' ,
3538 } ,
3639} ;
3740
38- const ImageCardFormItems = ( { cardConfig, i18n } ) => {
41+ const ImageCardFormItems = ( { cardConfig, i18n, onChange } ) => {
3942 const mergedI18n = { ...defaultProps . i18n , ...i18n } ;
4043 const baseClassName = `${ iotPrefix } --card-edit-form` ;
4144 return (
@@ -44,7 +47,7 @@ const ImageCardFormItems = ({ cardConfig, i18n }) => {
4447 className = { `${ baseClassName } --form-section ${ baseClassName } --form-section-image` } >
4548 { mergedI18n . image }
4649 </ div >
47- < div className = { `${ baseClassName } --input` } >
50+ < div className = { `${ baseClassName } --form-section-image-- input` } >
4851 < label
4952 id = { `${ mergedI18n . imageFile } -label` }
5053 className = { `${ prefix } --label` }
@@ -56,6 +59,27 @@ const ImageCardFormItems = ({ cardConfig, i18n }) => {
5659 readOnly
5760 value = { cardConfig . content ?. id || '' }
5861 />
62+ { cardConfig . content ?. id ? (
63+ < Button
64+ kind = "ghost"
65+ renderIcon = { Close16 }
66+ size = "field"
67+ iconDescription = { mergedI18n . close }
68+ className = { `${ baseClassName } --form-section ${ baseClassName } --form-section-image-clear-button` }
69+ onClick = { ( ) =>
70+ // close means clear the image info out of the JSON
71+ onChange (
72+ omit (
73+ cardConfig ,
74+ 'content.id' ,
75+ 'content.src' ,
76+ 'content.alt' ,
77+ 'content.imgState'
78+ )
79+ )
80+ }
81+ />
82+ ) : null }
5983 </ label >
6084 { /* TODO enable once hotspot editing is live <Button
6185 className={`${baseClassName}--form-section-image-btn`}
0 commit comments