ldx-widgets
Version:
widgets
102 lines (94 loc) • 3.07 kB
JavaScript
(function() {
var React, SelectPvrOption, div;
React = require('react');
div = React.DOM.div;
/*
Select Popover Option, see select_pvr.coffee for docs
*/
SelectPvrOption = React.createClass({
displayName: 'SelectPvrOption',
getDefaultProps: function() {
return {
optionHeight: 0,
hasSubLabel: false,
isSelected: false,
noWrapOptions: false,
option: {
isSubHeader: false,
isIndented: false,
disabled: false
}
};
},
render: function() {
var className, customClass, disabled, hasSubLabel, id, info, isIndented, isSelected, isSubHeader, label, labelClass, lh, noWrapOptions, option, optionHeight, optionKey, ref, subLabel, value;
ref = this.props, option = ref.option, isSelected = ref.isSelected, optionHeight = ref.optionHeight, hasSubLabel = ref.hasSubLabel, noWrapOptions = ref.noWrapOptions;
isSubHeader = option.isSubHeader, isIndented = option.isIndented, info = option.info, id = option.id, value = option.value, subLabel = option.subLabel, label = option.label, customClass = option.customClass, disabled = option.disabled;
className = 'select-pvr-option';
if (isSelected) {
className += ' is-selected';
}
if (noWrapOptions) {
className += ' no-wrap';
}
if (disabled) {
className += ' is-disabled';
}
if (isSubHeader) {
className += ' is-sub-header';
}
if (isIndented) {
className += ' is-indented';
}
if (customClass != null) {
className += " " + customClass;
}
if (hasSubLabel) {
className += ' has-sublabel';
lh = optionHeight / 2;
} else {
lh = optionHeight;
}
labelClass = 'label';
if (info != null) {
labelClass += ' has-info';
}
optionKey = id || value;
return div({
key: optionKey,
className: className,
onClick: !isSubHeader ? this.handleClick : void 0,
style: {
height: optionHeight,
lineHeight: lh + "px"
}
}, [
div({
key: 'label',
className: 'main-label'
}, [
info != null ? div({
key: 'info',
className: 'info'
}, info) : void 0, label != null ? div({
key: 'label',
className: labelClass
}, label) : void 0, subLabel != null ? div({
key: 'sub-label',
className: 'sub-label'
}, subLabel) : void 0
])
]);
},
handleClick: function(e) {
var canDeselect, disabled, handleClick, isSelected, option, ref;
e.stopPropagation();
ref = this.props, handleClick = ref.handleClick, option = ref.option, isSelected = ref.isSelected, canDeselect = ref.canDeselect;
disabled = option.disabled;
if (!((isSelected && !canDeselect) || disabled)) {
return handleClick(option);
}
}
});
module.exports = SelectPvrOption;
}).call(this);