Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add TypeScript #992

Merged
merged 17 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": "^18.0.11",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are react libraries not version-matched? ie. react-dom would also be 16.x

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not entirely sure. I followed what we were already using on RS, but maybe @kyleshike would know?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yikes yea these should be version matched. I guess it hasn't come up because all the react-dom stuff is happening under the hood with react-rails over in rails-server

"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';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice that TS builds in enums like this

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea this is part of what is going to make TS in the DS incredibly useful over in rails server.

FYI this is actually a union of literals, and an enum exactly:

https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#union-types
https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types

But TS does have some awesome enums as well:
https://www.typescriptlang.org/docs/handbook/enums.html

primaryAction?: ReactNode;
subtitle?: string | ReactNode;
title?: ReactNode;
}

const EmptyState = ({
className,
fullWidth = false,
marginTop = 'sm',
Comment on lines +21 to +22
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put default props here that used to be on propTypes

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