| 1 |
import React, { Fragment } from 'react'; |
| 2 |
import Select from 'react-select'; |
| 3 |
|
| 4 |
|
| 5 |
const PropertyFont = (props) => { |
| 6 |
const groupedOptions = [{ |
| 7 |
label: 'General', |
| 8 |
options: [ |
| 9 |
{ |
| 10 |
value: 'custom', |
| 11 |
label: 'Set custom font', |
| 12 |
},{ |
| 13 |
value: 'inherit', |
| 14 |
label: 'Inherit from parent', |
| 15 |
}, |
| 16 |
], |
| 17 |
},{ |
| 18 |
label: 'Default Serif Fonts', |
| 19 |
options: [ |
| 20 |
{ |
| 21 |
value: 'Georgia, serif', |
| 22 |
label: 'Georgia', |
| 23 |
},{ |
| 24 |
value: '"Palatino Linotype", "Book Antiqua", Palatino, serif', |
| 25 |
label: 'Palatino', |
| 26 |
},{ |
| 27 |
value: '"Times New Roman", Times, serif', |
| 28 |
label: 'Times New Roman', |
| 29 |
}, |
| 30 |
], |
| 31 |
},{ |
| 32 |
label: 'Default Sans-Serif Fonts', |
| 33 |
options: [ |
| 34 |
{ |
| 35 |
value: 'Arial, Helvetica, sans-serif', |
| 36 |
label: 'Arial', |
| 37 |
},{ |
| 38 |
value: '"Arial Black", Gadget, sans-serif', |
| 39 |
label: 'Arial Black', |
| 40 |
},{ |
| 41 |
value: '"Comic Sans MS", cursive, sans-serif', |
| 42 |
label: 'Comic Sans MS', |
| 43 |
|
| 44 |
},{ |
| 45 |
value: 'Helvetica, sans-serif', |
| 46 |
label: 'Helvetica', |
| 47 |
},{ |
| 48 |
value: 'Impact, Charcoal, sans-serif', |
| 49 |
label: 'Impact', |
| 50 |
},{ |
| 51 |
value: '"Lucida Sans Unicode", "Lucida Grande", sans-serif', |
| 52 |
label: 'Lucida', |
| 53 |
},{ |
| 54 |
value: 'Tahoma, Geneva, sans-serif', |
| 55 |
label: 'Tahoma', |
| 56 |
},{ |
| 57 |
value: '"Trebuchet MS", Helvetica, sans-serif', |
| 58 |
label: 'Trebuchet MS', |
| 59 |
},{ |
| 60 |
value: 'Verdana, Geneva, sans-serif', |
| 61 |
label: 'Verdana', |
| 62 |
}, |
| 63 |
], |
| 64 |
},{ |
| 65 |
label: 'Default Monospace Fonts', |
| 66 |
options: [ |
| 67 |
{ |
| 68 |
value: '"Courier New", Courier, monospace', |
| 69 |
label: 'Courier New', |
| 70 |
},{ |
| 71 |
value: '"Lucida Console", Monaco, monospace', |
| 72 |
label: 'Lucida Console', |
| 73 |
}, |
| 74 |
], |
| 75 |
}]; |
| 76 |
|
| 77 |
const selectOptions = groupedOptions.reduce((groups, group) => groups.concat(group.options), []); |
| 78 |
const selectValues = selectOptions.map(option => option.value); |
| 79 |
const custom = ! props.value || ! selectValues.includes(props.value); |
| 80 |
const selectValue = custom ? 'custom' : props.value; |
| 81 |
|
| 82 |
const selectStyles = { |
| 83 |
option: (styles, { data, isDisabled, isFocused, isSelected }) => { |
| 84 |
const fontFamily = 'custom' === data.value ? 'inherit' : data.value; |
| 85 |
|
| 86 |
return { |
| 87 |
...styles, |
| 88 |
fontFamily, |
| 89 |
}; |
| 90 |
}, |
| 91 |
}; |
| 92 |
|
| 93 |
return ( |
| 94 |
<Fragment> |
| 95 |
<Select |
| 96 |
className="wpupg-template-property-input" |
| 97 |
menuPlacement="top" |
| 98 |
value={selectOptions.filter(({value}) => value === selectValue)} |
| 99 |
onChange={(option) => { |
| 100 |
const value = 'custom' === option.value ? '' : option.value; |
| 101 |
return props.onValueChange(value); |
| 102 |
}} |
| 103 |
options={groupedOptions} |
| 104 |
styles={selectStyles} |
| 105 |
clearable={false} |
| 106 |
/> |
| 107 |
{ |
| 108 |
custom |
| 109 |
&& |
| 110 |
<input |
| 111 |
className="wpupg-template-property-input" |
| 112 |
type="text" |
| 113 |
value={props.value} |
| 114 |
onChange={(e) => props.onValueChange(e.target.value)} |
| 115 |
/> |
| 116 |
} |
| 117 |
</Fragment> |
| 118 |
); |
| 119 |
} |
| 120 |
|
| 121 |
export default PropertyFont; |