Tôi thực sự thích cách React thanh lọc các sự kiện cho bạn vì vậy tôi đã rất ngạc nhiên khi thấy rằng họ không tiền tố kiểu CSS của bạn cho bạn!Phong cách flexbox tiền tố cho React
Anyways, tôi bắt đầu thực hiện prefixer cơ bản của riêng tôi như thế này:
var prefixes = ["ms", "Moz", "Webkit", "O"];
var properties = [
'userSelect',
'transform',
'transition',
'transformOrigin',
'transformStyle',
'transitionProperty',
'transitionDuration',
'transitionTimingFunction',
'transitionDelay',
'borderImage',
'borderImageSlice',
'boxShadow',
'backgroundClip',
'backfaceVisibility',
'perspective',
'perspectiveOrigin',
'animation',
'animationDuration',
'animationName',
'animationDelay',
'animationDirection',
'animationIterationCount',
'animationTimingFunction',
'animationPlayState',
'animationFillMode',
'appearance',
'flexGrow',
];
function vendorPrefix(property, value) {
var result = {}
result[property] = value
if(properties.indexOf(property) == -1){
return result;
}
property = property[0].toUpperCase() + property.slice(1);
for (var i = 0; i < prefixes.length; i++) {
result[prefixes[i] + property] = value;
};
return result;
}
React.prefix = function(obj) {
var result = {};
for(var key in obj){
var prefixed = vendorPrefix(key, obj[key])
for(var pre in prefixed){
result[pre] = prefixed[pre]
}
}
return result;
};
Nhưng sau đó tôi realized a big problem, Phản ứng sử dụng một đối tượng cho phong cách và phù hợp tiền tố flexbox, bạn cần phải thêm tiền tố giá trị, không phải là tính chất. Do đó, tôi không thể bao gồm tất cả các kiểu sau cùng một lúc:
.page-wrap {
display: -webkit-box; /* OLD - iOS 6-, Safari 3.1-6 */
display: -moz-box; /* OLD - Firefox 19- (buggy but mostly works) */
display: -ms-flexbox; /* TWEENER - IE 10 */
display: -webkit-flex; /* NEW - Chrome */
display: flex; /* NEW, Spec - Opera 12.1, Firefox 20+ */
}
Bất kỳ ý tưởng nào để giải quyết vấn đề này?
Chức năng kiểu nội tuyến bị giới hạn ngày hôm nay. Tôi muốn đề nghị chỉ sử dụng một lớp truyền thống/'className' trong những trường hợp này. – WiredPrairie
Hoặc bạn có thể phát hiện các phiên bản trình duyệt, nhưng các lớp học có lẽ là cách để đi. – FakeRainBrigand
à, tôi hiểu rồi. Tôi đã hy vọng cuối cùng sẽ loại bỏ các bộ tiền xử lý CSS và CSS – Chet