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

Pladaria/ts #32

Merged
merged 98 commits into from
Jun 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
af8cca3
APPS-6692 WIP migrate to TS
pladaria Jun 5, 2020
2e9a3af
APPS-6692 WIP migrate to TS
pladaria Jun 5, 2020
4ce7e31
APPS-6692 WIP migrate to TS - cp theme-context.tsx
pladaria Jun 8, 2020
69d7071
APPS-6692 WIP migrate to TS - jss type tests
pladaria Jun 8, 2020
cfcc46c
APPS-6692 WIP migrate to TS - fix lint issues, create theme.tsx
pladaria Jun 8, 2020
08623ff
APPS-6692 WIP migrate to TS - add utils
pladaria Jun 8, 2020
60f4d06
Merge remote-tracking branch 'origin/master' into pladaria/ts
pladaria Jun 8, 2020
53e6562
APPS-6692 WIP migrate to TS - fix eslint issues
pladaria Jun 8, 2020
56f6a6f
APPS-6692 WIP migrate to TS - copy platform and region-code
pladaria Jun 8, 2020
50f996f
APPS-6692 WIP migrate to TS - copy media queries
pladaria Jun 8, 2020
9ec1442
APPS-6692 WIP migrate TS - cp colors
pladaria Jun 8, 2020
4e38a3f
APPS-6692 WIP migrate TS - colors
pladaria Jun 8, 2020
4f4faca
APPS-6692 WIP migrate TS - colors
pladaria Jun 8, 2020
4e84f9b
APPS-6692 WIP migrate TS - jss types
pladaria Jun 8, 2020
b9be62e
APPS-6692 WIP migrate TS - jss types
pladaria Jun 8, 2020
68a9e8b
APPS-6692 WIP migrate TS - jss types
pladaria Jun 9, 2020
febf5d4
APPS-6692 WIP migrate TS - cp stack
pladaria Jun 9, 2020
a519a3f
APPS-6692 WIP migrate TS - cp touchable
pladaria Jun 9, 2020
9dd7012
APPS-6692 WIP migrate TS - add keycodes
pladaria Jun 9, 2020
616162f
APPS-6692 WIP migrate TS - touchable
pladaria Jun 9, 2020
046e69f
APPS-6692 WIP migrate TS - update tsconfig
pladaria Jun 9, 2020
3b632da
APPS-6692 WIP migrate TS - screen reader only cp
pladaria Jun 9, 2020
ea77185
APPS-6692 WIP migrate TS - cp hooks
pladaria Jun 9, 2020
b96fa7f
APPS-6692 WIP migrate TS - screen size context
pladaria Jun 9, 2020
ef7aa03
APPS-6692 WIP migrate TS - screen size context
pladaria Jun 9, 2020
0d25d71
Merge remote-tracking branch 'origin/master' into pladaria/ts
pladaria Jun 9, 2020
22dde52
APPS-6692 WIP migrate TS - fix locale
pladaria Jun 9, 2020
db8871a
Merge remote-tracking branch 'origin/master' into pladaria/ts
pladaria Jun 9, 2020
fb7df78
APPS-6692 update hook
pladaria Jun 9, 2020
8428490
APPS-6692 rm sync-from-webapp.sh script
pladaria Jun 9, 2020
bae406d
APPS-6692 update index
pladaria Jun 9, 2020
9d7a81a
APPS-6692 revert change in eslint config
pladaria Jun 9, 2020
6f38a9e
APPS-6692 dts-to-flow
pladaria Jun 9, 2020
2439164
APPS-6692 flow types generation
pladaria Jun 10, 2020
aa27bd6
APPS-6692 flow types generation
pladaria Jun 10, 2020
1fe84ad
APPS-6692 flow types generation
pladaria Jun 10, 2020
e4c2c09
APPS-6692 flow types generation
pladaria Jun 10, 2020
e332fa8
APPS-6692 flow types generation
pladaria Jun 10, 2020
91e237f
APPS-6692 flow types generation
pladaria Jun 10, 2020
857e790
APPS-6692 improve jss types
pladaria Jun 11, 2020
993f740
APPS-6692 cp button
pladaria Jun 11, 2020
1ebb341
APPS-6692 cp spinner
pladaria Jun 11, 2020
6e3cb56
APPS-6692 cp spinner
pladaria Jun 11, 2020
1f48bd1
APPS-6692 cp spinner
pladaria Jun 11, 2020
efee42b
APPS-6692 cp spinner
pladaria Jun 11, 2020
6d099dc
APPS-6692 spinner tsx
pladaria Jun 11, 2020
8112a8c
APPS-6692 box tsx
pladaria Jun 11, 2020
90669bd
APPS-6692 cp color
pladaria Jun 11, 2020
b55c2a8
APPS-6692 color tsx
pladaria Jun 11, 2020
f9d4dfe
APPS-6692 cp form context
pladaria Jun 11, 2020
f4dc687
APPS-6692 cp theme variant context
pladaria Jun 11, 2020
107e90c
APPS-6692 migrate to tsx
pladaria Jun 11, 2020
4f32332
APPS-6692 update generator
pladaria Jun 11, 2020
b0c7276
APPS-6692 update generator
pladaria Jun 11, 2020
ec7a122
APPS-6692 some tooling
pladaria Jun 11, 2020
ee8f11d
APPS-6692 fix tabIndex type
pladaria Jun 11, 2020
553fc21
APPS-6692 improve flow definitions
pladaria Jun 12, 2020
ef84046
APPS-6692 cp to tsx
pladaria Jun 12, 2020
748223a
APPS-6692 compatible types
pladaria Jun 12, 2020
9ebd5b5
APPS-6692 fixes to adapt to webapp
pladaria Jun 15, 2020
1b32caf
Merge remote-tracking branch 'origin/master' into pladaria/ts
pladaria Jun 15, 2020
d1d0868
APPS-6692 expose textDanger
pladaria Jun 15, 2020
75aff08
APPS-6692 type overrides and type fixes
pladaria Jun 15, 2020
f4af579
APPS-6692 tweak types
pladaria Jun 15, 2020
d9afb57
APPS-6692 rename all js to tsx
pladaria Jun 15, 2020
a7bc2d7
APPS-6692 migrate all icons
pladaria Jun 15, 2020
73fcf22
APPS-6692 migrate utils
pladaria Jun 15, 2020
124f9d3
APPS-6692 migrate more components
pladaria Jun 15, 2020
1bc066f
APPS-6692 [WIP] migrate to TS
pladaria Jun 16, 2020
40d22a0
APPS-6692 [WIP] migrate to TS
pladaria Jun 16, 2020
5b12f24
APPS-6692 [WIP] migrate to TS
pladaria Jun 16, 2020
126a7f4
APPS-6692 [WIP] migrate to TS
pladaria Jun 17, 2020
2ee9547
APPS-6692 [WIP] migrate to TS
pladaria Jun 17, 2020
f1286d3
APPS-6692 [WIP] migrate to TS
pladaria Jun 18, 2020
f9545bd
APPS-6692 format d.ts
pladaria Jun 18, 2020
454aa11
Merge remote-tracking branch 'origin/master' into pladaria/ts
pladaria Jun 18, 2020
f56319a
APPS-6692 rm js files
pladaria Jun 18, 2020
b99925d
APPS-6692 update flow-defs
pladaria Jun 18, 2020
1b3cd95
APPS-6692 storybook config for TS
pladaria Jun 19, 2020
3014df0
APPS-6692 update build script
pladaria Jun 19, 2020
d6553d2
APPS-6692 improvements after CR
pladaria Jun 19, 2020
635f6c9
APPS-6692 remove comments
pladaria Jun 19, 2020
2c1bbe6
Merge remote-tracking branch 'origin/master' into pladaria/ts
pladaria Jun 23, 2020
d389d73
APPS-6692 update flow defs and use babel macro
pladaria Jun 23, 2020
9ae6331
APPS-6692 working acceptance tests
pladaria Jun 23, 2020
cac086c
APPS-6692 unit tests passing
pladaria Jun 23, 2020
5aad69b
APPS-6692 update config
pladaria Jun 23, 2020
1a4c7eb
APPS-6692 remove FlowFixMes
pladaria Jun 23, 2020
853a52d
APPS-6692 remove debug code
pladaria Jun 23, 2020
7bb0243
APPS-6692 remove screenshot
pladaria Jun 23, 2020
cb6966e
APPS-6692 remove old screenshots
pladaria Jun 23, 2020
a812b81
APPS-6692 configure playroom
pladaria Jun 23, 2020
18c96bb
APPS-6692 revert box changes
pladaria Jun 23, 2020
6e9db71
APPS-6692 fix empty ComponentType transform
pladaria Jun 24, 2020
d71fa52
APPS-6692 watch script
pladaria Jun 24, 2020
1ab757c
APPS-6692 watch script
pladaria Jun 24, 2020
470407f
APPS-6692 watch script
pladaria Jun 24, 2020
398ff8f
APPS-6692 watch script
pladaria Jun 24, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
13 changes: 11 additions & 2 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
{
"presets": [
"@babel/preset-react",
"@babel/preset-flow",
[
"@babel/preset-typescript",
{
"isTSX": true,
"allExtensions": true,
"allowNamespaces": false,
"allowDeclareFields": true
}
],
[
"@babel/preset-env",
{
Expand All @@ -15,7 +23,8 @@
"plugins": [
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-nullish-coalescing-operator",
"@babel/plugin-proposal-optional-chaining"
"@babel/plugin-proposal-optional-chaining",
"macros"
],
"env": {
"test": {
Expand Down
60 changes: 58 additions & 2 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
parser: babel-eslint
parser: babel-eslint # typescript parser is used as an override (see overrides section)
env:
es6: true
node: true
browser: true
jest/globals: true
parserOptions: # http://eslint.org/docs/user-guide/configuring.html#specifying-parser-options
Expand All @@ -21,12 +22,15 @@ plugins:
- testing-library
- flowtype
- import
- '@typescript-eslint'
extends:
- 'eslint:recommended'
rules:
# Basic rules
default-case: error
dot-notation: error
eqeqeq: error
filenames/match-regex: [error, '^[a-z0-9]+(-[a-z0-9]+)*$']
filenames/match-regex: [error, '^[a-z0-9]+(-[a-z0-9]+)*(\.(config))?$'] # matches: "foo-bar" or "foo-bar.config"
new-cap: [error, {newIsCap: true, capIsNew: false}]
no-cond-assign: error
no-debugger: error
Expand Down Expand Up @@ -154,3 +158,55 @@ rules:
import/no-named-default: error
import/no-useless-path-segments: error
import/no-self-import: error

overrides:
# overrides for TypeScript files
- files:
- '*.tsx'
parser: '@typescript-eslint/parser'
rules:
'flowtype/no-types-missing-file-annotation': off
no-unused-vars: off
'@typescript-eslint/no-unused-vars':
- error
- vars: all
args: after-used
ignoreRestSiblings: true
'@typescript-eslint/no-empty-function': off
'@typescript-eslint/no-explicit-any': off
'@typescript-eslint/ban-ts-comment':
- error
- ts-expect-error: allow-with-description
ts-ignore: true
ts-nocheck: true
ts-check: false
'@typescript-eslint/no-namespace':
- error
- allowDeclarations: false
allowDefinitionFiles: false
'no-restricted-syntax':
- error
- selector: TSEnumDeclaration
message: 'enums are not allowed'
'@typescript-eslint/prefer-as-const': off # TODO: review this rule and check how flowgen translates "as const" syntax
extends:
- 'eslint:recommended'
- 'plugin:@typescript-eslint/recommended'

# overrides for Type Tests
- files:
- '**/__type_tests__/*-type-test.tsx'
- '**/__type_tests__/*-type-test.js'
rules:
'no-unused-vars': off
'babel/no-unused-expressions': off
'@typescript-eslint/no-unused-vars': off

# overrides for flow definitions
- files:
- '*.js.flow'
rules:
filenames/match-regex: [error, '^[a-z0-9]+(-[a-z0-9]+)*\.js$'] # matches: "foo-bar.js"
no-use-before-define: off
import/no-duplicates: off
no-undef: off
5 changes: 4 additions & 1 deletion .flowconfig
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
[ignore]
.*/node_modules/.*
!.*/node_modules/@tef-novum/.*
<PROJECT_ROOT>/dist/.*
<PROJECT_ROOT>/playroom/.*
<PROJECT_ROOT>/.storybook/.*
<PROJECT_ROOT>/scripts/dts-to-flow/overrides


[include]

Expand Down
38 changes: 38 additions & 0 deletions .storybook/colors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Workaround until these issues get fixed and released
// https://github.com/storybookjs/storybook/pull/10980
// https://github.com/storybookjs/storybook/pull/10813
//
// At this moment we cannot write addon's register in TSX (extension must be .js)
// but then we cannot import stuff from ./src
// So this module replaces the required parts from ./src/colors.tsx

/**
* @param {'Movistar' | 'Vivo' | 'O2'} skin
*/
export const getColors = (skin) => {
switch (skin) {
case 'Movistar':
return {
PRIMARY: '#019DF4',
TEXT_PRIMARY: '#313235',
TEXT_PRIMARY_INVERSE: '#FFFFFF',
TEXT_SECONDARY: '#86888C',
};
case 'Vivo':
return {
PRIMARY: '#660099',
TEXT_PRIMARY: '#000000',
TEXT_PRIMARY_INVERSE: '#FFFFFF',
TEXT_SECONDARY: '#666666',
};
case 'O2':
return {
PRIMARY: '#032B5A',
TEXT_PRIMARY: '#000033',
TEXT_PRIMARY_INVERSE: '#FFFFFF',
TEXT_SECONDARY: '#757575',
};
default:
throw Error('Unexpected skin: ' + skin);
}
};
21 changes: 15 additions & 6 deletions .storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
// @flow
const path = require('path');

const config /*: any*/ = {
stories: ['./welcome-story.js', '../src/**/__stories__/*-story.js'],
module.exports = {
stories: ['./welcome-story.tsx', '../src/**/__stories__/*-story.tsx'],
addons: [
'@storybook/addon-links',
{
name: '@storybook/addon-storysource',
options: {
rule: {
test: [/\-story\.js/],
test: [/-story\.tsx/],
include: [path.resolve(__dirname, '..', 'src'), __dirname],
},
loaderOptions: {
Expand All @@ -19,6 +18,16 @@ const config /*: any*/ = {
},
'./.storybook/theme-selector-addon/register',
],
webpackFinal: async (config) => {
config.module.rules.push({
test: /\.tsx$/,
use: [
{
loader: require.resolve('ts-loader'),
},
],
});
config.resolve.extensions.push('.tsx');
return config;
},
};

module.exports = config;
1 change: 0 additions & 1 deletion .storybook/manager.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @flow
import '../css/roboto.css';
import '../css/reset.css';
import {addons} from '@storybook/addons';
Expand Down
31 changes: 8 additions & 23 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @flow
import '../css/roboto.css';
import '../css/reset.css';
import * as React from 'react';
Expand All @@ -7,11 +6,8 @@ import {ThemeContextProvider, Box, MOVISTAR_SKIN, VIVO_SKIN, O2_SKIN} from '../s
import addons from '@storybook/addons';
import getTheme from './theme-selector-addon/themes';

import type {Context} from '@storybook/react';
import type {Skin} from '../src';

const getUserAgent = (): string => self.navigator.userAgent || '';
const isRunningAcceptanceTest = (): boolean => getUserAgent().includes('acceptance-test');
const getUserAgent = () => self.navigator.userAgent || '';
const isRunningAcceptanceTest = () => getUserAgent().includes('acceptance-test');

const acceptanceStyles = `
*, *:after, *:before {
Expand All @@ -29,18 +25,7 @@ const acceptanceStyles = `
height: 0 !important;
}`;

type DecoratorProps = {
Story: React.ComponentType<any>,
context?: {
...Context,
parameters: {
fullScreen?: boolean,
},
...
},
};

const LayoutDecorator = ({Story, context}: DecoratorProps) => {
const LayoutDecorator = ({Story, context}) => {
const styles = isRunningAcceptanceTest() ? <style>{acceptanceStyles}</style> : null;

return (
Expand All @@ -53,19 +38,19 @@ const LayoutDecorator = ({Story, context}: DecoratorProps) => {
);
};

const getSkin = (searchParams): ?Skin => {
const getSkin = (searchParams) => {
const qsSkin = searchParams.get('skin');
return [MOVISTAR_SKIN, O2_SKIN, VIVO_SKIN].find((skin) => skin === qsSkin);
};

const getPlatform = (searchParams): ?'ios' | 'android' => {
const getPlatform = (searchParams) => {
const qsPlatform = searchParams.get('platform');
return ['ios', 'android'].find((platform) => platform === qsPlatform);
};

const ThemeDecorator = ({Story}: DecoratorProps) => {
const ThemeDecorator = ({Story}) => {
const searchParams = new URLSearchParams(location.search);
const [skin, setSkin] = React.useState<?Skin>(getSkin(searchParams));
const [skin, setSkin] = React.useState(getSkin(searchParams));

React.useEffect(() => {
const channel = addons.getChannel();
Expand All @@ -81,5 +66,5 @@ const ThemeDecorator = ({Story}: DecoratorProps) => {
);
};

addDecorator((Story, context: any) => <LayoutDecorator Story={Story} context={context} />);
addDecorator((Story, context) => <LayoutDecorator Story={Story} context={context} />);
addDecorator((Story) => <ThemeDecorator Story={Story} />);
11 changes: 6 additions & 5 deletions .storybook/storybook-manager-theme.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// @flow
import logo from '../img/mistica-logo.svg';
import {getColors} from '../src';
import {create} from '@storybook/theming/create';
import {getColors} from './colors';

import type {Skin} from '../src';
import {create} from '@storybook/theming/create';

const createTheme = (skin: Skin): any => {
/**
* @param {'Movistar' | 'Vivo' | 'O2'} skin
*/
const createTheme = (skin) => {
const colors = getColors(skin);
return create({
base: 'light',
Expand Down
5 changes: 2 additions & 3 deletions .storybook/theme-selector-addon/register.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// @flow
import * as React from 'react';
import addonApi, {types} from '@storybook/addons';
import {WithTooltip, IconButton, TooltipLinkList} from '@storybook/components';
import {getColors} from '../../src';
import {getColors} from '../colors';
import {AVAILABLE_THEMES} from './themes';
import createManagerTheme from '../storybook-manager-theme';

Expand All @@ -26,7 +25,7 @@ const ThemeSelectorAddon = ({api}) => {

api.setOptions({theme: createManagerTheme(currentSkin)});

// We need this timeout because there could be some race condition between addon mount and storibook manager initialization on page load.
// We need this timeout because there could be some race condition between addon mount and storybook manager initialization on page load
const tid = setTimeout(() => {
api.setOptions({theme: createManagerTheme(currentSkin)});
}, 100);
Expand Down
13 changes: 5 additions & 8 deletions .storybook/theme-selector-addon/themes.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
// @flow
import type {ThemeConfig, Skin} from '../../src';

export const Movistar: ThemeConfig = {
export const Movistar = {
i18n: {locale: 'es-ES', phoneNumberFormattingRegionCode: 'ES'},
skin: 'Movistar',
};

export const O2: ThemeConfig = {
export const O2 = {
i18n: {locale: 'en-US', phoneNumberFormattingRegionCode: 'GB'},
skin: 'O2',
};

export const Vivo: ThemeConfig = {
export const Vivo = {
i18n: {locale: 'pt-BR', phoneNumberFormattingRegionCode: 'BR'},
skin: 'Vivo',
};

export const AVAILABLE_THEMES = [Movistar, O2, Vivo];

export default (selectedSkin: ?Skin, selectedPlatform: ?'ios' | 'android'): ThemeConfig => {
const themeConfig: ThemeConfig = AVAILABLE_THEMES.find(({skin}) => skin === selectedSkin) || Movistar;
export default (selectedSkin, selectedPlatform) => {
const themeConfig = AVAILABLE_THEMES.find(({skin}) => skin === selectedSkin) || Movistar;
return selectedPlatform
? {
...themeConfig,
Expand Down
3 changes: 1 addition & 2 deletions .storybook/welcome-story.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @flow
import * as React from 'react';
import {Text, Stack, Box, ResponsiveLayout, useTheme, ButtonLink, TextLink} from '../src';
import logo from '../img/mistica-react-logo.svg';
Expand All @@ -16,7 +15,7 @@ const Paragraph = ({children}) => {
);
};

export const Mistica = (): React.Node => {
export const Mistica = () => {
return (
<ResponsiveLayout>
<Box paddingY={32}>
Expand Down
8 changes: 7 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
{
"javascript.validate.enable": false
"javascript.validate.enable": false,
"typescript.tsdk": "node_modules/typescript/lib",
"search.exclude": {
"**/node_modules": true,
"**/flow-defs": true,
"**/flow-typed": true
}
}
Loading