22import React from 'react' ;
33import PropTypes from 'prop-types' ;
44import clsx from 'clsx' ;
5+ import { faRotateLeft } from '@fortawesome/free-solid-svg-icons' ;
56
7+ import { AwesomeIcon } from '../AwesomeIcon' ;
68import BooleanWidget from '../widgets/BooleanWidget' ;
79import ColorWidget from '../widgets/ColorWidget' ;
810import InputWidget from '../widgets/InputWidget' ;
@@ -36,7 +38,7 @@ export default class PropertyRow extends React.Component {
3638 this . id = props . componentname + ':' + props . name ;
3739 }
3840
39- getWidget ( ) {
41+ getType ( ) {
4042 const props = this . props ;
4143 let type = props . schema . type ;
4244
@@ -57,6 +59,13 @@ export default class PropertyRow extends React.Component {
5759 type = 'boolean' ;
5860 }
5961
62+ return type ;
63+ }
64+
65+ getWidget ( ) {
66+ const props = this . props ;
67+ const type = this . getType ( ) ;
68+
6069 let value =
6170 type === 'selector'
6271 ? props . entity . getDOMAttribute ( props . componentname ) ?. [ props . name ]
@@ -152,18 +161,49 @@ export default class PropertyRow extends React.Component {
152161 }
153162 }
154163
164+ isPropertyExplicitlySet ( ) {
165+ const props = this . props ;
166+ if ( props . isSingle ) {
167+ return props . entity . getDOMAttribute ( props . componentname ) !== null ;
168+ } else {
169+ return (
170+ ( props . entity . getDOMAttribute ( props . componentname ) || { } ) [
171+ props . name
172+ ] !== undefined
173+ ) ;
174+ }
175+ }
176+
155177 render ( ) {
156178 const props = this . props ;
157- const value =
158- props . schema . type === 'selector'
159- ? props . entity . getDOMAttribute ( props . componentname ) ?. [ props . name ]
160- : JSON . stringify ( props . data ) ;
161- const title =
162- props . name + '\n - type: ' + props . schema . type + '\n - value: ' + value ;
179+ const type = this . getType ( ) ;
180+ const isPropertyDefined = this . isPropertyDefined ( ) ;
181+ const isPropertyExplicitlySet = this . isPropertyExplicitlySet ( ) ;
163182
183+ let title = props . name + '\n - type: ' + type ;
184+ if ( type === 'number' || type === 'int' ) {
185+ const schema = props . schema ;
186+ if ( schema . hasOwnProperty ( 'min' ) && schema . min !== - Infinity ) {
187+ title += '\n - min: ' + schema . min ;
188+ }
189+ if ( schema . hasOwnProperty ( 'max' ) && schema . max !== Infinity ) {
190+ title += '\n - max: ' + schema . max ;
191+ }
192+ }
193+ if ( ! isPropertyDefined ) {
194+ if ( isPropertyExplicitlySet ) {
195+ title += '\n\nexplicitly set to default value' ;
196+ } else {
197+ title += '\n\ndefault value' ;
198+ }
199+ } else {
200+ title += '\n\nmodified value' ;
201+ }
164202 const className = clsx ( {
165203 propertyRow : true ,
166- propertyRowDefined : this . isPropertyDefined ( )
204+ propertyRowDefined : isPropertyDefined ,
205+ propertyRowExplicitlySetToDefault :
206+ ! isPropertyDefined && isPropertyExplicitlySet
167207 } ) ;
168208
169209 return (
@@ -172,6 +212,22 @@ export default class PropertyRow extends React.Component {
172212 { props . name }
173213 </ label >
174214 { this . getWidget ( ) }
215+ { isPropertyExplicitlySet && type !== 'map' && (
216+ < button
217+ className = "reset-button"
218+ title = "Reset"
219+ onClick = { ( ) => {
220+ updateEntity (
221+ props . entity ,
222+ props . componentname ,
223+ ! props . isSingle ? props . name : '' ,
224+ null
225+ ) ;
226+ } }
227+ >
228+ < AwesomeIcon icon = { faRotateLeft } />
229+ </ button >
230+ ) }
175231 </ div >
176232 ) ;
177233 }
0 commit comments