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

feat: Add initial TypeScript autocomplete support #35

Merged
merged 5 commits into from Dec 18, 2018
Merged
Changes from 3 commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -1,7 +1,8 @@
{
"extends": "seek",
"globals": {
"__PLAYROOM_GLOBAL__CONFIG__": true
"__PLAYROOM_GLOBAL__CONFIG__": true,
"__PLAYROOM_GLOBAL__STATIC_TYPES__": true
},
"rules": {
"no-console": 0,
@@ -1,4 +1,8 @@
import { typeCode, assertFrameContains } from '../support/utils';
import {
typeCode,
assertFrameContains,
assertTextareaContains
} from '../support/utils';

describe('Smoke test', () => {
it('works', () => {
@@ -8,4 +12,10 @@ describe('Smoke test', () => {
typeCode('<Bar />');
assertFrameContains('Bar');
});

it('autocompletes', () => {
typeCode('<F{enter} c{enter}={downarrow}{enter} />');
assertFrameContains('Foo');
assertTextareaContains('<Foo color="blue" />');
});
});
@@ -1,4 +1,18 @@
import React from 'react';
import PropTypes from 'prop-types';

export const Foo = () => <div>Foo</div>;
export const Bar = () => <div>Bar</div>;
const withPropTypes = component => {
component.propTypes = {
color: PropTypes.oneOf(['red', 'blue'])
};

return component;
};

export const Foo = withPropTypes(({ color }) => (
<div style={{ color }}>Foo</div>
));

export const Bar = withPropTypes(({ color }) => (
<div style={{ color }}>Bar</div>
));
@@ -4,7 +4,7 @@ export const typeCode = code =>
.click()
.focused()
.clear({ force: true })
.type(code, { force: true });
.type(code, { force: true, delay: 100 });

export const assertFrameContains = async text => {
const iframe = await cy.get('iframe').first();
@@ -14,3 +14,10 @@ export const assertFrameContains = async text => {
.find('body')
.contains(text);
};

export const assertTextareaContains = async text => {
return cy
.get('textarea')
.first()
.contains(text);
};
@@ -0,0 +1,13 @@
import React, { Component } from 'react';

interface Props {
color: 'red' | 'blue';
}

export default class Bar extends Component<Props> {
render() {
const { color } = this.props;

return <div style={{ color }}>Bar</div>;
}
}
@@ -0,0 +1,13 @@
import React, { Component } from 'react';

interface Props {
color: 'red' | 'blue';
}

export default class Foo extends Component<Props> {
render() {
const { color } = this.props;

return <div style={{ color }}>Foo</div>;
}
}
@@ -0,0 +1,2 @@
export { default as Foo } from './Foo/Foo';
export { default as Bar } from './Bar/Bar';
@@ -0,0 +1,22 @@
{
"name": "typescript-playroom-example",
"private": true,
"version": "0.0.0",
"description": "TypeScript example for Braid Design System",
"scripts": {
"build": "node ./../../bin/cli build",
"start": "node ./../../bin/cli start"
},
"license": "MIT",
"devDependencies": {
"@babel/core": "^7.2.0",
"@babel/preset-env": "^7.2.0",
"@babel/preset-react": "^7.0.0",
"@babel/preset-typescript": "^7.1.0",
"@types/react": "^16.7.13",
"babel-loader": "^8.0.4"
},
"dependencies": {
"react": "^16.6.3"
}
}
@@ -0,0 +1,27 @@
module.exports = {
components: './components/index.ts',
outputPath: './dist',
webpackConfig: () => ({
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: [
'@babel/preset-env',
'@babel/preset-typescript',
'@babel/preset-react'
]
}
}
}
]
},
resolve: {
extensions: ['.js', '.ts', '.tsx']
}
})
};
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"jsx": "preserve"
},
"include": [
"components/**/*"
],
"exclude": [
"node_modules"
]
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.