| 1 |
import React from 'react'; |
| 2 |
|
| 3 |
import '../../../css/admin/template/property.scss'; |
| 4 |
|
| 5 |
import Icon from 'Shared/Icon'; |
| 6 |
import Helpers from '../general/Helpers'; |
| 7 |
|
| 8 |
import PropertyColor from './properties/Color'; |
| 9 |
import PropertyDropdown from './properties/Dropdown'; |
| 10 |
import PropertyFont from './properties/Font'; |
| 11 |
import PropertyIcon from './properties/Icon'; |
| 12 |
import PropertyImage from './properties/Image'; |
| 13 |
import PropertyImageSize from './properties/ImageSize'; |
| 14 |
import PropertyNumber from './properties/Number'; |
| 15 |
import PropertySize from './properties/Size'; |
| 16 |
import PropertyText from './properties/Text'; |
| 17 |
import PropertyToggle from './properties/Toggle'; |
| 18 |
|
| 19 |
const propertyTypes = { |
| 20 |
color: PropertyColor, |
| 21 |
align: PropertyDropdown, |
| 22 |
border: PropertyDropdown, |
| 23 |
dropdown: PropertyDropdown, |
| 24 |
float: PropertyDropdown, |
| 25 |
font: PropertyFont, |
| 26 |
font_size: PropertySize, |
| 27 |
icon: PropertyIcon, |
| 28 |
image: PropertyImage, |
| 29 |
image_size: PropertyImageSize, |
| 30 |
percentage: PropertyNumber, |
| 31 |
number: PropertyNumber, |
| 32 |
size: PropertySize, |
| 33 |
text: PropertyText, |
| 34 |
toggle: PropertyToggle, |
| 35 |
} |
| 36 |
|
| 37 |
const Property = (props) => { |
| 38 |
const PropertyComponent = propertyTypes.hasOwnProperty(props.property.type) ? propertyTypes[props.property.type] : false; |
| 39 |
|
| 40 |
if ( ! PropertyComponent ) { |
| 41 |
return null; |
| 42 |
} |
| 43 |
|
| 44 |
if ( ! Helpers.dependencyMet(props.property, props.properties) ) { |
| 45 |
return null; |
| 46 |
} |
| 47 |
|
| 48 |
let helpIcon = null; |
| 49 |
if ( props.property.hasOwnProperty( 'help' ) ) { |
| 50 |
helpIcon = ( |
| 51 |
<Icon |
| 52 |
type="question" |
| 53 |
title={ props.property.help } |
| 54 |
className="wpupg-admin-icon-help" |
| 55 |
/> |
| 56 |
); |
| 57 |
} |
| 58 |
|
| 59 |
return ( |
| 60 |
<div className="wpupg-template-property"> |
| 61 |
<div className="wpupg-template-property-label"> |
| 62 |
{ props.property.name } { helpIcon } |
| 63 |
</div> |
| 64 |
<div className={ `wpupg-template-property-value wpupg-template-property-value-${props.property.type}` }> |
| 65 |
<PropertyComponent |
| 66 |
property={props.property} |
| 67 |
value={props.property.value} |
| 68 |
onValueChange={(value) => { props.onPropertyChange(props.property.id, value); } } |
| 69 |
/> |
| 70 |
</div> |
| 71 |
</div> |
| 72 |
); |
| 73 |
} |
| 74 |
|
| 75 |
export default Property; |