@sishuguojixuefu/react-native-form
Version:
52 lines • 2.7 kB
JavaScript
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = __importStar(require("react"));
const react_native_1 = require("react-native");
const react_native_ratings_1 = require("react-native-ratings");
const ErrorTip_1 = __importDefault(require("./helper/ErrorTip"));
const getFieldDecorator_1 = __importDefault(require("../utils/getFieldDecorator"));
const Label_1 = __importDefault(require("./helper/Label"));
class SsRatingView extends react_1.Component {
constructor() {
super(...arguments);
this.ratingCompleted = (nValue) => {
const { onChange } = this.props;
onChange && onChange(nValue);
};
}
render() {
const { label, required, initialValue, allowHalf } = this.props;
return (react_1.default.createElement(react_native_1.View, { style: { flexDirection: 'row', justifyContent: 'space-between', paddingRight: 10, paddingVertical: 8 } },
react_1.default.createElement(Label_1.default, { required: required, label: label }),
allowHalf ? (react_1.default.createElement(react_native_ratings_1.Rating, { showRating: false, startingValue: initialValue, ratingCount: 5, onFinishRating: this.ratingCompleted })) : (react_1.default.createElement(react_native_ratings_1.AirbnbRating, { reviews: [], showRating: false, defaultRating: initialValue, count: 5, onFinishRating: this.ratingCompleted }))));
}
}
exports.SsRatingView = SsRatingView;
SsRatingView.defaultProps = {
required: false,
};
class SsRating extends react_1.Component {
componentWillMount() {
const { form, id, initialValue, rules } = this.props;
this.fieldDecorator = getFieldDecorator_1.default(form, id, initialValue, rules);
}
render() {
const { label, required, form, id, onChange, initialValue, allowHalf } = this.props;
return (react_1.default.createElement(ErrorTip_1.default, { error: form.getFieldError(id) }, this.fieldDecorator(react_1.default.createElement(SsRatingView, { label: label, required: required, onChange: onChange, initialValue: Number(initialValue), allowHalf: allowHalf }))));
}
}
exports.default = SsRating;
SsRating.defaultProps = {
required: false,
};
//# sourceMappingURL=SsRating.js.map