Skip to content

Commit

Permalink
add TypeScript (#992)
Browse files Browse the repository at this point in the history
* add TypeScript packages

* add tsconfig.json

* update storybook/main.js

* add preset-typescript to babelrc

* add build-ts script

* update tsconfig.json

* add dummy TestPill component

* Fixes up TS config (#993)

* convert EmptyState to TS and remove demo TestPill

* update EmptyStateProps

* use relative import for Heading and Text in EmptyState

* add react/jsx-filename-extension to .eslintrc

* remove test copy

* trailing comma

* bring types/react-dom version down to ^16

---------

Co-authored-by: Kyle Shike <kyleshike@gmail.com>
  • Loading branch information
jasonbasuil and kyleshike authored Sep 15, 2023
1 parent 64633a7 commit 5ab953d
Show file tree
Hide file tree
Showing 18 changed files with 453 additions and 225 deletions.
3 changes: 2 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"presets": [
"@babel/preset-env",
"@babel/preset-react"
"@babel/preset-react",
"@babel/preset-typescript"
],
"plugins": [
"@babel/plugin-transform-runtime",
Expand Down
29 changes: 24 additions & 5 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"extends": "airbnb",
"extends": [
"airbnb",
"plugin:@typescript-eslint/recommended",
"plugin:import/typescript"
],
"parser": "@typescript-eslint/parser",
"overrides": [
{
"files": [
Expand All @@ -11,9 +16,9 @@
},
{
"files": [
"src/**/*.{js,jsx}",
"spec/**/*.{js,jsx}",
"stories/**/*.{js,jsx}"
"src/**/*.{js,jsx,ts,tsx}",
"spec/**/*.{js,jsx,ts,tsx}",
"stories/**/*.{js,jsx,ts,tsx}"
],
"env": {
"browser": true
Expand Down Expand Up @@ -117,6 +122,7 @@
}
},
"rules": {
"@typescript-eslint/explicit-function-return-type": "off",
"class-methods-use-this": 0,
"function-paren-newline": ["error", "consistent"],
"func-names": ["error", "never"],
Expand All @@ -141,9 +147,22 @@
"prefer-destructuring": "warn",
"quotes": ["error", "single", { "allowTemplateLiterals" : true }],
"radix": 0,
"react/jsx-filename-extension": ["error", {
"extensions": [".tsx", ".jsx"]
}],
"react/jsx-fragments": 0,
"symbol-description": 0,
"template-curly-spacing": "off",
"indent": "off"
"indent": "off",
"import/extensions": [
"error",
"ignorePackages",
{
"js": "never",
"jsx": "never",
"ts": "never",
"tsx": "never"
}
]
}
}
8 changes: 7 additions & 1 deletion .storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ const config = {
stories: [
'../stories/Intro.stories.mdx',
'../src/**/*.stories.@(js|mdx)',
'../src/**/*.stories.@(ts|mdx)',
'../src/**/*.stories.js[x]',
'../src/**/*.stories.ts[x]',
'../stories/**/*.stories.mdx',
'../stories/**/*.stories.js[x]'
'../stories/**/*.stories.js[x]',
'../stories/**/*.stories.ts[x]'
],
features: {
storyStoreV7: false,
Expand All @@ -36,6 +39,9 @@ const config = {
name: '@storybook/react-webpack5',
options: { fastRefresh: true },
},
typescript: {
check: true,
},
};

export default config;
2 changes: 1 addition & 1 deletion nodemon.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"exec": "bin/link-rs",
"ext": "js,json,jsx,scss",
"ext": "js,json,jsx,ts,tsx,scss",
"verbose": true,
"watch": [
"scss",
Expand Down
12 changes: 10 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
"@tiptap/extension-text": "^2.0.3",
"@tiptap/pm": "^2.0.3",
"@tiptap/react": "^2.0.3",
"@typescript-eslint/eslint-plugin": "^2",
"@typescript-eslint/parser": "^2",
"react-bootstrap": "^2.5.0",
"react-currency-input-field": "^3.6.10",
"react-loading-skeleton": "^3.1.0",
Expand All @@ -29,9 +31,10 @@
"uuid": "^7.0.2"
},
"scripts": {
"build": "NODE_ENV=production babel src --out-dir lib --copy-files",
"build": "NODE_ENV=production babel src --out-dir lib --copy-files --extensions '.js,.jsx,.ts,.tsx' && tsc",
"build-storybook": "storybook build -s public",
"build-storybook-docs": "storybook build -s public --docs",
"build-ts": "tsc",
"chromatic": "npx chromatic",
"lint": "eslint . --ext .js,.jsx",
"prepublishOnly": "yarn build",
Expand Down Expand Up @@ -81,6 +84,7 @@
"@babel/plugin-proposal-private-property-in-object": "^7.21.0",
"@babel/plugin-transform-runtime": "^7.12.1",
"@babel/preset-env": "^7.8.4",
"@babel/preset-typescript": "^7.22.5",
"@babel/runtime": "^7.12.5",
"@fortawesome/fontawesome-svg-core": "^1.2.28",
"@fortawesome/free-brands-svg-icons": "^5.15.3",
Expand All @@ -106,6 +110,8 @@
"@testing-library/react": "^12.1.2",
"@testing-library/react-hooks": "^3.2.1",
"@testing-library/user-event": "^13.5.0",
"@types/react": "16.14.0",
"@types/react-dom": "^16.0.0",
"babel-eslint": "^10.0.3",
"babel-jest": "^27.4.6",
"babel-loader": "^8.0.6",
Expand Down Expand Up @@ -144,6 +150,7 @@
"storybook-addon-designs": "6.3.1",
"style-loader": "^1.1.3",
"styled-components": "^5.3.3",
"typescript": "^4.9.5",
"webpack": "^5.80.0",
"yalc": "^1.0.0-pre.53"
},
Expand All @@ -160,7 +167,8 @@
"node": ">= 16 < 19",
"yarn": "^ 1.22"
},
"main": "lib/index.js",
"main": "lib/index",
"types": "lib/index",
"publishConfig": {
"registry": "https://npm.pkg.github.com/"
},
Expand Down
83 changes: 0 additions & 83 deletions src/EmptyState/EmptyState.jsx

This file was deleted.

50 changes: 0 additions & 50 deletions src/EmptyState/EmptyState.stories.jsx

This file was deleted.

48 changes: 48 additions & 0 deletions src/EmptyState/EmptyState.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React from 'react';
import type { Meta, StoryObj } from '@storybook/react';

import { faPlus } from '@fortawesome/pro-regular-svg-icons';

import Button from 'src/Button';

import EmptyState from './EmptyState';

const meta: Meta<typeof EmptyState> = {
component: EmptyState,
title: 'Components/EmptyState',
};

export default meta;
type Story = StoryObj<typeof EmptyState>;

export const Default: Story = {
args: {
subtitle: 'Launch your first project to start conducting research!',
title: 'You have no projects',
}
};

export const PrimaryAction: Story = {
args: {
primaryAction: <Button leadingIcon={faPlus} variant="primary">New project</Button>,
subtitle: 'Launch your first project to start conducting research! Source from a pool of 2.4 million participants to reach nearly any target audience.',
title: 'You have no projects',
}
};

export const FullWidth: Story = {
args: {
fullWidth: true,
primaryAction: <Button leadingIcon={faPlus} variant="primary">New project</Button>,
subtitle: 'Launch your first project to start conducting research! Source from a pool of 2.4 million participants to reach nearly any target audience.',
title: 'You have no projects',
}
};

export const MarginTop: Story = {
args: {
marginTop: 'sm',
subtitle: 'Add a new participant segment above',
title: 'No segments created',
}
};
57 changes: 57 additions & 0 deletions src/EmptyState/EmptyState.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React, { ReactNode } from 'react';

import classNames from 'classnames';

import { Heading } from '../Heading';
import { Text } from '../Text';

import './EmptyState.scss';

export interface EmptyStateProps {
className?: string;
fullWidth?: boolean;
marginTop?: 'sm' | 'md' | 'lg' | 'none';
primaryAction?: ReactNode;
subtitle?: string | ReactNode;
title?: ReactNode;
}

const EmptyState = ({
className,
fullWidth = false,
marginTop = 'sm',
primaryAction,
subtitle,
title,
}: EmptyStateProps) => (
<div className={classNames(
className,
'EmptyState',
marginTop && `EmptyState--margin-top--${marginTop}`,
)}
>
<div className={classNames(
'EmptyState__content',
fullWidth && 'EmptyState--full-width',
)}
>
{title && (
<Heading className="EmptyState__title" level={4} size="lg" textAlign="center">{title}</Heading>
)}

{subtitle && (
<Text className="EmptyState__subtitle" textAlign="center">{subtitle}</Text>
)}

{primaryAction && (
<div className="EmptyState__actions">
<div className="EmptyState__actions__primary-action">
{primaryAction}
</div>
</div>
)}
</div>
</div>
);

export default EmptyState;
File renamed without changes.
Loading

0 comments on commit 5ab953d

Please sign in to comment.