| 1 |
import React, { Fragment} from 'react'; |
| 2 |
|
| 3 |
import Property from './Property'; |
| 4 |
|
| 5 |
const TemplateProperties = (props) => { |
| 6 |
let propertiesColor = []; |
| 7 |
let propertiesText = []; |
| 8 |
let propertiesOther = []; |
| 9 |
|
| 10 |
for ( let property of Object.values(props.template.style.properties) ) { |
| 11 |
switch(property.type) { |
| 12 |
case 'color': |
| 13 |
propertiesColor.push(property); |
| 14 |
break; |
| 15 |
case 'align': |
| 16 |
property.options = { |
| 17 |
left: 'Left', |
| 18 |
center: 'Center', |
| 19 |
right: 'Right', |
| 20 |
}; |
| 21 |
case 'font': |
| 22 |
case 'font_size': |
| 23 |
propertiesText.push(property); |
| 24 |
break; |
| 25 |
case 'float': |
| 26 |
property.options = { |
| 27 |
left: 'Left', |
| 28 |
none: 'None', |
| 29 |
right: 'Right', |
| 30 |
}; |
| 31 |
propertiesOther.push(property); |
| 32 |
break; |
| 33 |
case 'border': |
| 34 |
property.options = { |
| 35 |
solid: 'Solid', |
| 36 |
dashed: 'Dashed', |
| 37 |
dotted: 'Dotted', |
| 38 |
double: 'Double', |
| 39 |
groove: 'Groove', |
| 40 |
ridge: 'Ridge', |
| 41 |
inset: 'Inset', |
| 42 |
outset: 'Outset', |
| 43 |
}; |
| 44 |
propertiesOther.push(property); |
| 45 |
break; |
| 46 |
case 'percentage': |
| 47 |
property.suffix = '%'; |
| 48 |
propertiesOther.push(property); |
| 49 |
break; |
| 50 |
default: |
| 51 |
propertiesOther.push(property); |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
const groups = [ |
| 56 |
{ |
| 57 |
header: 'Colors', |
| 58 |
properties: propertiesColor |
| 59 |
}, |
| 60 |
{ |
| 61 |
header: 'Text', |
| 62 |
properties: propertiesText |
| 63 |
}, |
| 64 |
{ |
| 65 |
header: 'Other', |
| 66 |
properties: propertiesOther |
| 67 |
}, |
| 68 |
]; |
| 69 |
|
| 70 |
return ( |
| 71 |
<div id="wpupg-template-properties" className="wpupg-template-properties"> |
| 72 |
{ |
| 73 |
Object.values(props.template.style.properties).length > 0 |
| 74 |
? |
| 75 |
<Fragment> |
| 76 |
{ |
| 77 |
groups.map((group, i) => { |
| 78 |
if ( group.properties.length > 0 ) { |
| 79 |
return ( |
| 80 |
<Fragment key={i}> |
| 81 |
<div className="wpupg-template-properties-header">{group.header}</div> |
| 82 |
{ |
| 83 |
group.properties.map((property, j) => { |
| 84 |
return <Property |
| 85 |
property={property} |
| 86 |
onPropertyChange={props.onChangeTemplateProperty} |
| 87 |
key={j} |
| 88 |
/>; |
| 89 |
}) |
| 90 |
} |
| 91 |
</Fragment> |
| 92 |
) |
| 93 |
} |
| 94 |
}) |
| 95 |
} |
| 96 |
</Fragment> |
| 97 |
: |
| 98 |
<p>This template does not have any adjustable properties.</p> |
| 99 |
} |
| 100 |
</div> |
| 101 |
); |
| 102 |
} |
| 103 |
|
| 104 |
export default TemplateProperties; |