Skip to content

Commit

Permalink
adds flow type
Browse files Browse the repository at this point in the history
  • Loading branch information
brigand committed Oct 21, 2017
1 parent 9a45fff commit f77f5a4
Show file tree
Hide file tree
Showing 10 changed files with 1,605 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .flowconfig
@@ -0,0 +1,9 @@
[ignore]

[include]

[libs]

[lints]

[options]
11 changes: 11 additions & 0 deletions README.md
Expand Up @@ -14,6 +14,17 @@ var Comp = React.createClass({

You can use stylePropType.isRequired similar to the built in proptypes.

## Flow

We also expose a flow type definition. It doesn't use an 'exact' type definition due to a bug in flow, so it'll allow invalid properties. The main purpose of this type is to improve the editor experience for custom components that accept a style prop.

```jsx
import { type Style } from 'react-style-proptype/src/Style.flow.js';

type Props = {
style: Style,
};
```

## Arrays

Expand Down
317 changes: 317 additions & 0 deletions data/allCamel.json
@@ -0,0 +1,317 @@
[
"alignContent",
"alignItems",
"alignSelf",
"all",
"animation",
"animationDelay",
"animationDirection",
"animationDuration",
"animationFillMode",
"animationIterationCount",
"animationName",
"animationPlayState",
"animationTimingFunction",
"backfaceVisibility",
"background",
"backgroundAttachment",
"backgroundBlendMode",
"backgroundClip",
"backgroundColor",
"backgroundImage",
"backgroundOrigin",
"backgroundPosition",
"backgroundRepeat",
"backgroundSize",
"blockSize",
"border",
"borderBlockEnd",
"borderBlockEndColor",
"borderBlockEndStyle",
"borderBlockEndWidth",
"borderBlockStart",
"borderBlockStartColor",
"borderBlockStartStyle",
"borderBlockStartWidth",
"borderBottom",
"borderBottomColor",
"borderBottomLeftRadius",
"borderBottomRightRadius",
"borderBottomStyle",
"borderBottomWidth",
"borderCollapse",
"borderColor",
"borderImage",
"borderImageOutset",
"borderImageRepeat",
"borderImageSlice",
"borderImageSource",
"borderImageWidth",
"borderInlineEnd",
"borderInlineEndColor",
"borderInlineEndStyle",
"borderInlineEndWidth",
"borderInlineStart",
"borderInlineStartColor",
"borderInlineStartStyle",
"borderInlineStartWidth",
"borderLeft",
"borderLeftColor",
"borderLeftStyle",
"borderLeftWidth",
"borderRadius",
"borderRight",
"borderRightColor",
"borderRightStyle",
"borderRightWidth",
"borderSpacing",
"borderStyle",
"borderTop",
"borderTopColor",
"borderTopLeftRadius",
"borderTopRightRadius",
"borderTopStyle",
"borderTopWidth",
"borderWidth",
"bottom",
"boxDecorationBreak",
"boxShadow",
"boxSizing",
"breakAfter",
"breakBefore",
"breakInside",
"captionSide",
"caretColor",
"ch",
"clear",
"clip",
"clipPath",
"cm",
"color",
"columnCount",
"columnFill",
"columnGap",
"columnRule",
"columnRuleColor",
"columnRuleStyle",
"columnRuleWidth",
"columnSpan",
"columnWidth",
"columns",
"content",
"counterIncrement",
"counterReset",
"cursor",
"deg",
"direction",
"display",
"dpcm",
"dpi",
"dppx",
"em",
"emptyCells",
"ex",
"filter",
"flexBasis",
"flexDirection",
"flexFlow",
"flexGrow",
"flexShrink",
"flexWrap",
"float",
"font",
"fontFamily",
"fontFeatureSettings",
"fontKerning",
"fontLanguageOverride",
"fontSize",
"fontSizeAdjust",
"fontStretch",
"fontStyle",
"fontSynthesis",
"fontVariant",
"fontVariantAlternates",
"fontVariantCaps",
"fontVariantEastAsian",
"fontVariantLigatures",
"fontVariantNumeric",
"fontVariantPosition",
"fontWeight",
"fr",
"grad",
"grid",
"gridArea",
"gridAutoColumns",
"gridAutoFlow",
"gridAutoRows",
"gridColumn",
"gridColumnEnd",
"gridColumnGap",
"gridColumnStart",
"gridGap",
"gridRow",
"gridRowEnd",
"gridRowGap",
"gridRowStart",
"gridTemplate",
"gridTemplateAreas",
"gridTemplateColumns",
"gridTemplateRows",
"hangingPunctuation",
"height",
"hyphens",
"hz",
"imageOrientation",
"imageRendering",
"imageResolution",
"in",
"inherit",
"initial",
"inlineSize",
"isolation",
"justifyContent",
"khz",
"left",
"letterSpacing",
"lineBreak",
"lineHeight",
"listStyle",
"listStyleImage",
"listStylePosition",
"listStyleType",
"margin",
"marginBlockEnd",
"marginBlockStart",
"marginBottom",
"marginInlineEnd",
"marginInlineStart",
"marginLeft",
"marginRight",
"marginTop",
"mask",
"maskClip",
"maskComposite",
"maskImage",
"maskMode",
"maskOrigin",
"maskPosition",
"maskRepeat",
"maskSize",
"maskType",
"maxHeight",
"maxWidth",
"minBlockSize",
"minHeight",
"minInlineSize",
"minWidth",
"mixBlendMode",
"mm",
"ms",
"objectFit",
"objectPosition",
"offsetBlockEnd",
"offsetBlockStart",
"offsetInlineEnd",
"offsetInlineStart",
"opacity",
"order",
"orphans",
"outline",
"outlineColor",
"outlineOffset",
"outlineStyle",
"outlineWidth",
"overflow",
"overflowWrap",
"overflowX",
"overflowY",
"padding",
"paddingBlockEnd",
"paddingBlockStart",
"paddingBottom",
"paddingInlineEnd",
"paddingInlineStart",
"paddingLeft",
"paddingRight",
"paddingTop",
"pageBreakAfter",
"pageBreakBefore",
"pageBreakInside",
"pc",
"perspective",
"perspectiveOrigin",
"pointerEvents",
"position",
"pt",
"px",
"q",
"quotes",
"rad",
"rem",
"resize",
"revert",
"right",
"rubyAlign",
"rubyMerge",
"rubyPosition",
"s",
"scrollBehavior",
"scrollSnapCoordinate",
"scrollSnapDestination",
"scrollSnapType",
"shapeImageThreshold",
"shapeMargin",
"shapeOutside",
"tabSize",
"tableLayout",
"textAlign",
"textAlignLast",
"textCombineUpright",
"textDecoration",
"textDecorationColor",
"textDecorationLine",
"textDecorationStyle",
"textEmphasis",
"textEmphasisColor",
"textEmphasisPosition",
"textEmphasisStyle",
"textIndent",
"textJustify",
"textOrientation",
"textOverflow",
"textRendering",
"textShadow",
"textTransform",
"textUnderlinePosition",
"top",
"touchAction",
"transform",
"transformBox",
"transformOrigin",
"transformStyle",
"transition",
"transitionDelay",
"transitionDuration",
"transitionProperty",
"transitionTimingFunction",
"turn",
"unicodeBidi",
"unset",
"verticalAlign",
"vh",
"visibility",
"vmax",
"vmin",
"vw",
"whiteSpace",
"widows",
"width",
"willChange",
"wordBreak",
"wordSpacing",
"wordWrap",
"writingMode",
"zIndex",
"flex",
"overflowScrolling"
]
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -29,6 +29,7 @@
},
"devDependencies": {
"cheerio": "^0.20.0",
"flow-bin": "^0.57.3",
"superagent": "^1.8.3",
"tape": "^4.5.1"
}
Expand Down
23 changes: 23 additions & 0 deletions scripts/genFlow.js
@@ -0,0 +1,23 @@
const fs = require('fs');
let data;
try {
data = require('../data/allCamel.json');
} catch (e) {
console.error(`Must run scripts/scrape.js first`);
process.exit(7);
}

let out = ``;
out += `// @flow\n`;
out += `// generated by scripts/getFlow\n\n`;
out += `export type Style = {\n`;
data.forEach((prop) => {
out += ` ${prop}?: ?string | ?number,\n`;
});

out += `}\n`;

fs.writeFileSync('src/Style.flow.js', out);

console.log(out);

10 changes: 10 additions & 0 deletions scripts/scrape.js
@@ -1,3 +1,4 @@
var fs = require('fs');
var superagent = require('superagent');
var cheerio = require('cheerio');
var url = 'https://developer.mozilla.org/en-US/docs/Web/CSS/Reference';
Expand All @@ -11,6 +12,15 @@ superagent.get(url)
.filter((x) => /^[a-z-]+$/.test(x))
var camel = names.map((x) => x.split('-').map((a, i) => i === 0 ? a : a[0].toUpperCase() + a.slice(1)).join(''));
camel.push('fontSize', 'flex', 'fr', 'overflowScrolling');

var uniq = [];
camel.forEach((x) => {
if (uniq.indexOf(x) === -1) {
uniq.push(x);
}
});

fs.writeFileSync('data/allCamel.json', JSON.stringify(uniq, null, 2));
var prefixed = camel.map((name) => {
var upper = name[0].toUpperCase() + name.slice(1);
var items = [name, 'Moz' + upper, 'Webkit' + upper, 'MS' + upper, 'O' + upper];
Expand Down

0 comments on commit f77f5a4

Please sign in to comment.