diff --git a/addons/backgrounds/package.json b/addons/backgrounds/package.json index 9a7e071942e..3197bee5c59 100644 --- a/addons/backgrounds/package.json +++ b/addons/backgrounds/package.json @@ -19,7 +19,7 @@ "license": "MIT", "author": "jbaxleyiii", "main": "dist/index.js", - "jsnext:main": "src/index.js", + "types": "dist/index.d.ts", "scripts": { "prepare": "node ../../scripts/prepare.js" }, @@ -37,6 +37,9 @@ "react": "^16.8.1", "util-deprecate": "^1.0.2" }, + "devDependencies": { + "@types/util-deprecate": "^1.0.0" + }, "publishConfig": { "access": "public" } diff --git a/addons/backgrounds/src/Tool.js b/addons/backgrounds/src/Tool.tsx similarity index 85% rename from addons/backgrounds/src/Tool.js rename to addons/backgrounds/src/Tool.tsx index d05a7658936..fac90416e4a 100644 --- a/addons/backgrounds/src/Tool.js +++ b/addons/backgrounds/src/Tool.tsx @@ -10,7 +10,7 @@ import { Icons, IconButton, WithTooltip, TooltipLinkList } from '@storybook/comp import { PARAM_KEY } from './constants'; -export const ColorIcon = styled.span(({ background }) => ({ +export const ColorIcon = styled.span(({ background }: any) => ({ borderRadius: '1rem', display: 'block', height: '1rem', @@ -41,7 +41,7 @@ const createItem = memoize(1000)((id, name, value, hasSwatch, change) => } ); -const getSelected = (list, state) => { +const getSelected = (list: any[], state: any) => { if (!list.length) { return 'transparent'; } @@ -73,7 +73,9 @@ const getState = memoize(10)((props, state, change) => { : []; const items = list.length - ? initial.concat(list.map(({ id, name, value }) => createItem(id, name, value, true, change))) + ? initial.concat( + list.map(({ id, name, value }: any) => createItem(id, name, value, true, change)) + ) : list; return { @@ -82,7 +84,7 @@ const getState = memoize(10)((props, state, change) => { }; }); -export default class BackgroundTool extends Component { +export default class BackgroundTool extends Component { static propTypes = { api: PropTypes.shape({ getQueryParam: PropTypes.func, @@ -90,7 +92,9 @@ export default class BackgroundTool extends Component { }).isRequired, }; - constructor(props) { + listener: () => void; + + constructor(props: any) { super(props); this.state = { @@ -114,7 +118,8 @@ export default class BackgroundTool extends Component { api.off(SET_STORIES, this.listener); } - change = (...args) => this.setState(...args); + // @ts-ignore + change = (...args: any[]) => this.setState(...args); render() { const { expanded } = this.state; @@ -135,7 +140,7 @@ export default class BackgroundTool extends Component { placement="top" trigger="click" tooltipShown={expanded} - onVisibilityChange={s => this.setState({ expanded: s })} + onVisibilityChange={(s: boolean) => this.setState({ expanded: s })} tooltip={} closeOnClick > diff --git a/addons/backgrounds/src/components.js b/addons/backgrounds/src/components.ts similarity index 50% rename from addons/backgrounds/src/components.js rename to addons/backgrounds/src/components.ts index 9bc6443aaf8..0a79450d973 100644 --- a/addons/backgrounds/src/components.js +++ b/addons/backgrounds/src/components.ts @@ -1,5 +1,5 @@ import { styled } from '@storybook/theming'; -export const ColorIcon = styled.span(({ background }) => ({ +export const ColorIcon = styled.span(({ background }: any) => ({ background, })); diff --git a/addons/backgrounds/src/constants.js b/addons/backgrounds/src/constants.ts similarity index 100% rename from addons/backgrounds/src/constants.js rename to addons/backgrounds/src/constants.ts diff --git a/addons/backgrounds/src/deprecated.js b/addons/backgrounds/src/deprecated.ts similarity index 100% rename from addons/backgrounds/src/deprecated.js rename to addons/backgrounds/src/deprecated.ts diff --git a/addons/backgrounds/src/index.js b/addons/backgrounds/src/index.ts similarity index 91% rename from addons/backgrounds/src/index.js rename to addons/backgrounds/src/index.ts index 460a270e44b..a19adac8357 100644 --- a/addons/backgrounds/src/index.js +++ b/addons/backgrounds/src/index.ts @@ -4,7 +4,7 @@ import deprecate from 'util-deprecate'; import Events from './constants'; -let prevBackgrounds; +let prevBackgrounds: any[]; const subscription = () => () => { prevBackgrounds = null; @@ -16,7 +16,7 @@ export const withBackgrounds = makeDecorator({ parameterName: 'backgrounds', skipIfNoParametersOrOptions: true, allowDeprecatedUsage: true, - wrapper: (getStory, context, { options, parameters }) => { + wrapper: (getStory: any, context: any, { options, parameters }: any) => { const data = parameters || options || []; const backgrounds = Array.isArray(data) ? data : Object.values(data); diff --git a/addons/backgrounds/src/register.js b/addons/backgrounds/src/register.tsx similarity index 92% rename from addons/backgrounds/src/register.js rename to addons/backgrounds/src/register.tsx index 7f398493438..0120755d589 100644 --- a/addons/backgrounds/src/register.js +++ b/addons/backgrounds/src/register.tsx @@ -6,6 +6,7 @@ import Tool from './Tool'; addons.register(ADDON_ID, api => { addons.add(ADDON_ID, { + title: 'Backgrounds', type: types.TOOL, match: ({ viewMode }) => viewMode === 'story', render: () => , diff --git a/addons/backgrounds/src/typings.d.ts b/addons/backgrounds/src/typings.d.ts new file mode 100644 index 00000000000..4f6eeff67b3 --- /dev/null +++ b/addons/backgrounds/src/typings.d.ts @@ -0,0 +1,3 @@ +// TODO: following packages need definition files or a TS migration +declare module '@storybook/theming'; +declare module '@storybook/components';