Skip to content

Commit

Permalink
improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
baptadn committed Jan 30, 2020
1 parent 0dc0a5d commit eaa3c62
Show file tree
Hide file tree
Showing 23 changed files with 3,858 additions and 141 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"customize-cra": "^0.9.1",
"customize-cra-react-refresh": "^1.0.1",
"prettier": "^1.19.1",
"react-app-rewired": "^2.1.5"
"react-app-rewired": "^2.1.5",
"typedoc": "^0.16.9"
}
}
55 changes: 55 additions & 0 deletions scripts/format.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const types = require("./types.json");
const fs = require("fs");
const references = {};

const inferType = (type, children) => {
if (type.type === "union") {
if (
type.types.length === 3 &&
type.types[1].name === "false" &&
type.types[2].name === "true"
) {
return { type: "boolean" };
} else if (
type.types.length === 2 &&
type.types[0].name === "undefined" &&
type.types[1].name === "string"
) {
return { type: "string" };
} else if (
type.types.length === 2 &&
type.types[0].name === "undefined" &&
type.types[1].type === "reflection"
) {
return { type: "callback" };
} else if (
type.types.length > 0 &&
type.types[0].type === "stringLiteral"
) {
return {
type: "enum",
choices: type.types.map(item => item.value)
};
}
}

return { type: "string" };
};

types.children
.filter(child => !!child.children)
.filter(child => child.kindString === "Interface")
.map(child => {
references[child.sources[0].fileName.split("/")[0]] = child.children.map(
props => {
const { name, type, comment } = props;
return {
name,
type: inferType(type, types.children),
description: comment && comment.shortText
};
}
);
});

fs.writeFileSync("./ref.json", JSON.stringify(references));
40 changes: 40 additions & 0 deletions scripts/generate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const TypeDoc = require("typedoc");

const app = new TypeDoc.Application();

// If you want TypeDoc to load tsconfig.json / typedoc.json files
app.options.addReader(new TypeDoc.TSConfigReader());
app.options.addReader(new TypeDoc.TypeDocReader());

app.bootstrap({
mode: "file",
includeDeclarations: true,
excludeExternals: true
});

//node_modules/@chakra-ui/core/dist/theme/icons.d.ts
const COMPONENTS = [
"Badge",
"Checkbox",
"Button",
"Image",
"Badge",
"Icon",
"Text",
"Avatar",
"AvatarGroup",
"AvatarBadge",
"Tag"
];
const project = app.convert(
app.expandInputFiles(
COMPONENTS.map(
name => `../node_modules/@chakra-ui/core/dist/${name}/index.d.ts`
)
)
);

if (project) {
// Project may not have converted correctly
app.generateJson(project, "types.json");
}
273 changes: 273 additions & 0 deletions scripts/ref.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,273 @@
{
"Avatar": [
{
"name": "children",
"type": { "type": "string" },
"description": "The badge at the bottom right corner of the avatar."
},
{
"name": "name",
"type": { "type": "string" },
"description": "The name of the person in the avatar."
},
{
"name": "showBorder",
"type": { "type": "boolean" },
"description": "If `true`, the `Avatar` will show a border around it."
},
{
"name": "size",
"type": { "type": "string" },
"description": "The size of the avatar."
},
{
"name": "src",
"type": { "type": "string" },
"description": "The image url of the `Avatar`"
}
],
"AvatarGroup": [
{ "name": "label", "type": { "type": "string" } },
{ "name": "size", "type": { "type": "string" } }
],
"Badge": [
{
"name": "variant",
"type": { "type": "enum", "choices": ["solid", "subtle", "outline"] },
"description": "The variant of the badge"
},
{
"name": "variantColor",
"type": { "type": "string" },
"description": "The color scheme of the badge"
}
],
"Button": [
{
"name": "children",
"type": { "type": "string" },
"description": "The content of the button."
},
{
"name": "iconSpacing",
"type": { "type": "string" },
"description": "The space between the button icon and label.\nUse the styled-system tokens or add custom values as a string"
},
{
"name": "isActive",
"type": { "type": "boolean" },
"description": "If `true`, the button will be styled in it's active state."
},
{
"name": "isDisabled",
"type": { "type": "boolean" },
"description": "If `true`, the button will be disabled."
},
{
"name": "isFullWidth",
"type": { "type": "boolean" },
"description": "If `true`, the button will take up the full width of its container."
},
{
"name": "isLoading",
"type": { "type": "boolean" },
"description": "If `true`, the button will show a spinner."
},
{
"name": "leftIcon",
"type": { "type": "string" },
"description": "If added, the button will show an icon before the button's label.\nUse the icon key in `theme.iconPath`"
},
{
"name": "loadingText",
"type": { "type": "string" },
"description": "The label to show in the button when `isLoading` is true\nIf no text is passed, it only shows the spinner"
},
{
"name": "rightIcon",
"type": { "type": "string" },
"description": "If added, the button will show an icon after the button's label.\nUse the icon key in `theme.iconPath`"
},
{
"name": "size",
"type": { "type": "enum", "choices": ["xs", "sm", "md", "lg"] },
"description": "The size of the button"
},
{
"name": "type",
"type": { "type": "enum", "choices": ["button", "reset", "submit"] },
"description": "The html button type to use."
},
{
"name": "variant",
"type": {
"type": "enum",
"choices": ["outline", "ghost", "unstyled", "link", "solid"]
},
"description": "The variant of the button style to use."
},
{
"name": "variantColor",
"type": { "type": "string" },
"description": "The color scheme of the button."
}
],
"Checkbox": [
{
"name": "children",
"type": { "type": "string" },
"description": "The children is the label to be displayed to the right of the checkbox."
},
{
"name": "defaultIsChecked",
"type": { "type": "boolean" },
"description": "If `true`, the checkbox will be initially checked."
},
{
"name": "id",
"type": { "type": "string" },
"description": "id assigned to input"
},
{
"name": "isChecked",
"type": { "type": "boolean" },
"description": "If `true`, the checkbox will be checked.\nYou'll need to pass `onChange` to update it's value (since it's now controlled)"
},
{
"name": "isDisabled",
"type": { "type": "boolean" },
"description": "If `true`, the checkbox will be disabled"
},
{
"name": "isFullWidth",
"type": { "type": "boolean" },
"description": "If `true`, the checkbox should take up the full width of the parent."
},
{
"name": "isIndeterminate",
"type": { "type": "boolean" },
"description": "If `true`, the checkbox will be indeterminate.\nThis only affects the icon shown inside checkbox\nand does not modify the isChecked property."
},
{
"name": "isInvalid",
"type": { "type": "boolean" },
"description": "If `true`, the checkbox is marked as invalid.\nChanges style of unchecked state."
},
{
"name": "isReadOnly",
"type": { "type": "boolean" },
"description": "If `true`, the checkbox will be readonly"
},
{
"name": "name",
"type": { "type": "string" },
"description": "The name of the input field in a checkbox\n(Useful for form submission)."
},
{
"name": "onChange",
"type": { "type": "string" },
"description": "The callback invoked when the checked state of the `Checkbox` changes.."
},
{
"name": "size",
"type": { "type": "enum", "choices": ["sm", "md", "lg"] },
"description": "The size (width and height) of the checkbox"
},
{
"name": "value",
"type": { "type": "string" },
"description": "The value to be used in the checkbox input.\nThis is the value that will be returned on form submission."
},
{
"name": "variantColor",
"type": { "type": "string" },
"description": "The color scheme of the checkbox."
}
],
"Icon": [
{
"name": "color",
"type": { "type": "string" },
"description": "The color of the icon."
},
{
"name": "focusable",
"type": { "type": "boolean" },
"description": "If `false`, it means the icon is used within interactive\nelement and won't be focuable."
},
{
"name": "name",
"type": { "type": "string" },
"description": "The name of the icon."
},
{
"name": "role",
"type": { "type": "enum", "choices": ["presentation", "img"] },
"description": "The role of the icon. `presentation` or `img`"
},
{
"name": "size",
"type": { "type": "string" },
"description": "The size of the icon."
}
],
"Image": [
{
"name": "alt",
"type": { "type": "string" },
"description": "The alt text that describes the image"
},
{
"name": "fallbackSrc",
"type": { "type": "string" },
"description": "In event there was an error loading the `src`, specify a fallback\nIn most cases, this can be an avatar or image placeholder"
},
{
"name": "htmlHeight",
"type": { "type": "string" },
"description": "The native HTML `height` attribute to the passed to the `img`"
},
{
"name": "htmlWidth",
"type": { "type": "string" },
"description": "The native HTML `width` attribute to the passed to the `img`"
},
{
"name": "ignoreFallback",
"type": { "type": "boolean" },
"description": "Opt out of the `fallbackSrc` logic and use the `Image` directly"
},
{
"name": "onError",
"type": { "type": "callback" },
"description": "A callback for when there was an error loading the image `src`"
},
{
"name": "onLoad",
"type": { "type": "callback" },
"description": "A callback for when the image `src` has been loaded"
},
{
"name": "src",
"type": { "type": "string" },
"description": "The path to the image source"
}
],
"Tag": [
{
"name": "size",
"type": { "type": "enum", "choices": ["sm", "md", "lg"] },
"description": "The size of the tag."
},
{
"name": "variant",
"type": { "type": "string" },
"description": "The variant of the tag."
},
{
"name": "variantColor",
"type": { "type": "string" },
"description": "The color scheme of the tag."
}
]
}
Loading

0 comments on commit eaa3c62

Please sign in to comment.