diff --git a/addons/centered/package.json b/addons/centered/package.json index 14cc4e244499..da4f4b1e4a0a 100644 --- a/addons/centered/package.json +++ b/addons/centered/package.json @@ -18,7 +18,7 @@ "license": "MIT", "author": "Muhammed Thanish ", "main": "dist/index.js", - "jsnext:main": "src/index.js", + "types": "dist/index.d.ts", "scripts": { "prepare": "node ../../scripts/prepare.js" }, @@ -27,6 +27,14 @@ "global": "^4.3.2", "util-deprecate": "^1.0.2" }, + "devDependencies": { + "@types/mithril": "^1.1.16" + }, + "optionalDependencies": { + "react": "*", + "preact": "*", + "mithril": "*" + }, "publishConfig": { "access": "public" } diff --git a/addons/centered/src/angular.js b/addons/centered/src/angular.ts similarity index 86% rename from addons/centered/src/angular.js rename to addons/centered/src/angular.ts index fa03af8b9e49..da930cd17e22 100644 --- a/addons/centered/src/angular.js +++ b/addons/centered/src/angular.ts @@ -1,11 +1,11 @@ import styles from './styles'; -function getComponentSelector(component) { +function getComponentSelector(component: any) { // eslint-disable-next-line no-underscore-dangle return component.__annotations__[0].selector; } -function getTemplate(metadata) { +function getTemplate(metadata: any) { let tpl = ''; if (metadata.component) { const selector = getComponentSelector(metadata.component); @@ -24,7 +24,7 @@ function getTemplate(metadata) { `; } -function getModuleMetadata(metadata) { +function getModuleMetadata(metadata: any) { const { moduleMetadata, component } = metadata; if (component && !moduleMetadata) { @@ -43,7 +43,7 @@ function getModuleMetadata(metadata) { return moduleMetadata; } -export default function(metadataFn) { +export default function(metadataFn: any) { const metadata = metadataFn(); return { diff --git a/addons/centered/src/ember.js b/addons/centered/src/ember.ts similarity index 82% rename from addons/centered/src/ember.js rename to addons/centered/src/ember.ts index 91a017a4b645..efb0cd21ff86 100644 --- a/addons/centered/src/ember.js +++ b/addons/centered/src/ember.ts @@ -1,7 +1,7 @@ import { document } from 'global'; import styles from './styles'; -export default function(storyFn) { +export default function(storyFn: () => { template: any; context: any }) { const { template, context } = storyFn(); const element = document.createElement('div'); @@ -13,7 +13,7 @@ export default function(storyFn) { element.appendChild(innerElement); // the inner element should append the parent - innerElement.appendTo = function appendTo(el) { + innerElement.appendTo = function appendTo(el: any) { el.appendChild(element); }; diff --git a/addons/centered/src/helpers/json2CSS.js b/addons/centered/src/helpers/json2CSS.ts similarity index 75% rename from addons/centered/src/helpers/json2CSS.js rename to addons/centered/src/helpers/json2CSS.ts index 0126a5e0c046..11e939b15962 100644 --- a/addons/centered/src/helpers/json2CSS.js +++ b/addons/centered/src/helpers/json2CSS.ts @@ -10,11 +10,11 @@ import { document } from 'global'; * @returns {string} * @see https://stackoverflow.com/questions/38533544/jsx-css-to-inline-styles */ -export default function jsonToCss(jsonStyles) { - const frag = document.createElement('div'); +export default function jsonToCss(jsonStyles: Partial) { + const frag = document.createElement('div') as HTMLDivElement; Object.keys(jsonStyles).forEach(key => { - frag.style[key] = jsonStyles[key]; + (frag.style as any)[key] = (jsonStyles as any)[key]; }); return frag.getAttribute('style'); diff --git a/addons/centered/src/html.js b/addons/centered/src/html.ts similarity index 82% rename from addons/centered/src/html.js rename to addons/centered/src/html.ts index 88e3e8ab4b70..1a22c7a1c64d 100644 --- a/addons/centered/src/html.js +++ b/addons/centered/src/html.ts @@ -4,14 +4,14 @@ import styles from './styles'; const INNER_ID = 'sb-addon-centered-inner'; const WRAPPER_ID = 'sb-addon-centered-wrapper'; -function getOrCreate(id, style) { +function getOrCreate(id: string, style: Partial): HTMLDivElement { const elementOnDom = document.getElementById(id); if (elementOnDom) { return elementOnDom; } - const element = document.createElement('div'); + const element = document.createElement('div') as HTMLDivElement; element.setAttribute('id', id); Object.assign(element.style, style); @@ -26,7 +26,7 @@ function getWrapperDiv() { return getOrCreate(WRAPPER_ID, styles.style); } -export default function(storyFn) { +export default function(storyFn: () => any) { const inner = getInnerDiv(); const wrapper = getWrapperDiv(); wrapper.appendChild(inner); diff --git a/addons/centered/src/index.js b/addons/centered/src/index.ts similarity index 100% rename from addons/centered/src/index.js rename to addons/centered/src/index.ts diff --git a/addons/centered/src/mithril.js b/addons/centered/src/mithril.tsx similarity index 68% rename from addons/centered/src/mithril.js rename to addons/centered/src/mithril.tsx index 12c10927204f..c60d1e991b64 100644 --- a/addons/centered/src/mithril.js +++ b/addons/centered/src/mithril.tsx @@ -1,10 +1,8 @@ /** @jsx m */ - -// eslint-disable-next-line import/no-extraneous-dependencies -import m from 'mithril'; +import m, { ComponentTypes } from 'mithril'; import styles from './styles'; -export default function(storyFn) { +export default function(storyFn: () => ComponentTypes) { return { view: () => (
diff --git a/addons/centered/src/preact.js b/addons/centered/src/preact.tsx similarity index 56% rename from addons/centered/src/preact.js rename to addons/centered/src/preact.tsx index 71e9573ddb1c..559424960977 100644 --- a/addons/centered/src/preact.js +++ b/addons/centered/src/preact.tsx @@ -1,9 +1,8 @@ /** @jsx h */ -// eslint-disable-next-line import/no-extraneous-dependencies -import { h } from 'preact'; +import { Component, h } from 'preact'; import styles from './styles'; -export default function(storyFn) { +export default function(storyFn: () => Component) { return (
{storyFn()}
diff --git a/addons/centered/src/react.js b/addons/centered/src/react.tsx similarity index 64% rename from addons/centered/src/react.js rename to addons/centered/src/react.tsx index 4f29808de058..fe54f4c9ccf5 100644 --- a/addons/centered/src/react.js +++ b/addons/centered/src/react.tsx @@ -1,8 +1,7 @@ -// eslint-disable-next-line import/no-extraneous-dependencies -import React from 'react'; +import React, { ReactNode } from 'react'; import styles from './styles'; -export default function(storyFn) { +export default function(storyFn: () => ReactNode) { return (
{storyFn()}
diff --git a/addons/centered/src/styles.js b/addons/centered/src/styles.ts similarity index 78% rename from addons/centered/src/styles.js rename to addons/centered/src/styles.ts index e0fbb3474fbd..d1a92167bfca 100644 --- a/addons/centered/src/styles.js +++ b/addons/centered/src/styles.ts @@ -1,10 +1,10 @@ const styles = { style: { position: 'fixed', - top: 0, - left: 0, - bottom: 0, - right: 0, + top: '0', + left: '0', + bottom: '0', + right: '0', display: 'flex', alignItems: 'center', overflow: 'auto', @@ -14,6 +14,6 @@ const styles = { maxHeight: '100%', // Hack for centering correctly in IE11 overflow: 'auto', }, -}; +} as const; export default styles; diff --git a/addons/centered/src/svelte.js b/addons/centered/src/svelte.ts similarity index 95% rename from addons/centered/src/svelte.js rename to addons/centered/src/svelte.ts index a95f3e32ca4a..796233c7dc57 100644 --- a/addons/centered/src/svelte.js +++ b/addons/centered/src/svelte.ts @@ -18,7 +18,7 @@ const centeredStyles = { * * @see https://svelte.technology/guide#svelte-component */ -export default function(storyFn) { +export default function(storyFn: () => any) { const { Component: OriginalComponent, props, on } = storyFn(); return { diff --git a/addons/centered/src/typings.d.ts b/addons/centered/src/typings.d.ts new file mode 100644 index 000000000000..ad116294c0f6 --- /dev/null +++ b/addons/centered/src/typings.d.ts @@ -0,0 +1,2 @@ +declare module 'global'; +declare module '*.svelte'; diff --git a/addons/centered/src/vue.js b/addons/centered/src/vue.ts similarity index 100% rename from addons/centered/src/vue.js rename to addons/centered/src/vue.ts diff --git a/addons/centered/tsconfig.json b/addons/centered/tsconfig.json new file mode 100644 index 000000000000..8876bb6737a1 --- /dev/null +++ b/addons/centered/tsconfig.json @@ -0,0 +1,13 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "rootDir": "./src", + "types": ["webpack-env"] + }, + "include": [ + "src/**/*" + ], + "exclude": [ + "src/__tests__/**/*" + ] +} diff --git a/examples/preact-kitchen-sink/src/stories/__snapshots__/addon-centered.stories.storyshot b/examples/preact-kitchen-sink/src/stories/__snapshots__/addon-centered.stories.storyshot index 2d8c520d1008..43083a564c53 100644 --- a/examples/preact-kitchen-sink/src/stories/__snapshots__/addon-centered.stories.storyshot +++ b/examples/preact-kitchen-sink/src/stories/__snapshots__/addon-centered.stories.storyshot @@ -5,13 +5,13 @@ exports[`Storyshots Addons|Centered Button 1`] = ` style={ Object { "alignItems": "center", - "bottom": 0, + "bottom": "0", "display": "flex", - "left": 0, + "left": "0", "overflow": "auto", "position": "fixed", - "right": 0, - "top": 0, + "right": "0", + "top": "0", } } > diff --git a/yarn.lock b/yarn.lock index 5a558b392aeb..168a4bb4a911 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3455,6 +3455,11 @@ resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d" integrity sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA== +"@types/mithril@^1.1.16": + version "1.1.16" + resolved "https://registry.yarnpkg.com/@types/mithril/-/mithril-1.1.16.tgz#97647157a4d6dacee8fc86414578c56723dfd715" + integrity sha512-+HlRvSpKwXP8RXh1hrIcgSHQ/Fh+5O9nYfG7fgNN7PGr2K03G+hLoiA+HXzmUJCsQfPEuNiBQ+TwRl6n7kerSw== + "@types/node@*", "@types/node@~12.0.0": version "12.0.1" resolved "https://registry.yarnpkg.com/@types/node/-/node-12.0.1.tgz#3dde31f8da274dfeb90e96abf55038fef46285f0" @@ -19981,7 +19986,7 @@ mississippi@^3.0.0: stream-each "^1.1.0" through2 "^2.0.0" -mithril@^1.1.6: +mithril@*, mithril@^1.1.6: version "1.1.6" resolved "https://registry.yarnpkg.com/mithril/-/mithril-1.1.6.tgz#bd2cc0de3d3c86076a6a7a30367a601a1bd108f3" integrity sha512-fWcUrQTCqu8M916rj1MFGlHaPh65rznPu6U/N2U9g81H89klDCIptSK5bnkNkC+jyi3sJIXjyGhSQjUnR8jzZA==