2015-01-29 17:10:49 -08:00
|
|
|
/**
|
2015-03-23 15:07:33 -07:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
*
|
2018-02-16 18:24:55 -08:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2015-01-29 17:10:49 -08:00
|
|
|
*
|
2018-05-10 19:06:46 -07:00
|
|
|
* @format
|
2018-08-09 08:32:04 -07:00
|
|
|
* @flow strict-local
|
2015-01-29 17:10:49 -08:00
|
|
|
*/
|
2018-05-10 19:06:46 -07:00
|
|
|
|
2015-01-29 17:10:49 -08:00
|
|
|
'use strict';
|
|
|
|
|
2018-05-10 15:44:52 -07:00
|
|
|
const createStrictShapeTypeChecker = require('createStrictShapeTypeChecker');
|
|
|
|
const flattenStyle = require('flattenStyle');
|
2015-01-29 17:10:49 -08:00
|
|
|
|
2018-05-10 19:06:46 -07:00
|
|
|
function StyleSheetPropType(shape: {
|
|
|
|
[key: string]: ReactPropsCheckType,
|
|
|
|
}): ReactPropsCheckType {
|
2018-05-10 15:44:52 -07:00
|
|
|
const shapePropType = createStrictShapeTypeChecker(shape);
|
2017-02-08 14:38:37 -08:00
|
|
|
return function(props, propName, componentName, location?, ...rest) {
|
2018-05-10 15:44:52 -07:00
|
|
|
let newProps = props;
|
2015-01-29 17:10:49 -08:00
|
|
|
if (props[propName]) {
|
|
|
|
// Just make a dummy prop object with only the flattened style
|
|
|
|
newProps = {};
|
|
|
|
newProps[propName] = flattenStyle(props[propName]);
|
|
|
|
}
|
2017-02-08 14:38:37 -08:00
|
|
|
return shapePropType(newProps, propName, componentName, location, ...rest);
|
2015-01-29 17:10:49 -08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = StyleSheetPropType;
|