absolutely massive typescript porting time

This commit is contained in:
41666 2019-06-02 18:58:15 -05:00
parent 01f238f515
commit 30d08a630f
No known key found for this signature in database
GPG key ID: BC51D07640DC10AF
159 changed files with 2563 additions and 3861 deletions

View file

@ -1,11 +1,9 @@
{
"presets": [
"next/babel",
"@babel/preset-typescript",
"@zeit/next-typescript/babel"
],
"plugins": [
"@babel/plugin-syntax-dynamic-import",
"@babel/plugin-proposal-class-properties",
[
"@babel/plugin-transform-runtime",
{
@ -18,8 +16,6 @@
"ssr": true
}
],
"@babel/plugin-proposal-optional-chaining",
"macros"
],
"env": {
"test": {
@ -32,10 +28,6 @@
}
}
]
],
"plugins": [
"require-context-hook",
"macros"
]
}
}

View file

@ -4,8 +4,11 @@ linters:
- git add
lib/*.d.ts:
- tslint --fix
- git add
src/*.{ts,tsx}:
- tslint --fix
- stylelint --fix
- jest --bail --findRelatedTests
- git add
- git add

View file

@ -1,3 +1,3 @@
<script src="https://use.typekit.net/bck0pci.js"></script>
<script>try { Typekit.load(); } catch (e) { }</script>
<script src="https://use.typekit.net/bck0pci.js" async></script>
<script async>try { Typekit.load({ async: true }); } catch (e) { }</script>
<style>body{font-family: "source-han-sans-japanese", "Source Sans Pro", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol" !important;}</style>

View file

@ -11,6 +11,7 @@
"files": [
"lib"
],
"types": "./lib/index.d.ts",
"devDependencies": {
"@babel/core": "^7.4.4",
"@babel/preset-typescript": "^7.3.3",
@ -25,7 +26,7 @@
"@types/enzyme-adapter-react-16": "^1.0.5",
"@types/jest": "^24.0.13",
"@types/node": "^12.0.2",
"@types/react": "^16.8.17",
"@types/react": "^16.8.19",
"@types/react-dom": "^16.8.4",
"@types/react-test-renderer": "^16.8.1",
"@types/storybook__addon-actions": "^3.4.2",
@ -36,16 +37,14 @@
"@types/styled-components": "4.1.8",
"awesome-typescript-loader": "^5.2.1",
"babel-loader": "^8.0.6",
"babel-plugin-macros": "^2.5.1",
"babel-plugin-require-context-hook": "^1.0.0",
"lint-staged": "^8.1.7",
"react-docgen-typescript-loader": "^3.1.0",
"react-test-renderer": "^16.8.6",
"require-context.macro": "^1.0.4",
"sinon": "^7.3.2",
"stylelint": "^10.0.1",
"tslint": "^5.16.0",
"tslint": "^5.17.0",
"tslint-config-standard": "^8.0.1",
"typescript": "^3.4.5"
"typescript": "^3.5.1"
},
"scripts": {
"storybook": "start-storybook -p 6006",

View file

@ -45,25 +45,155 @@ exports[`Storyshots Button Disabled 1`] = `
`;
exports[`Storyshots Button Loading 1`] = `
<styled.button
<Button
disabled={false}
loadingPct={0}
onClick={[Function]}
primary={false}
secondary={false}
theme={
loading={false}
loadingPct={100}
onButtonPress={[Function]}
overrides={
Object {
"actions": Object {
"primary": "#46b646",
},
"button": Object {
"borderRadius": "2px",
"BaseButton": Object {
"component": Object {
"$$typeof": Symbol(react.forward_ref),
"attrs": Array [],
"componentStyle": ComponentStyle {
"componentId": "sc-bxivhb",
"isStatic": false,
"rules": Array [
"
/* reset some styles */
box-shadow: none;
appearance: none;
outline: none;
cursor: pointer;
background-color: rgba(0,0,0,0.1);
/* real styles */
position: relative;
transition: all 0.05s ease-in-out;
padding: 1em 1.4em;
font-weight: bold;
border: 1px solid rgba(0,0,0,0.1);
border-radius: ",
[Function],
";
&:disabled {
cursor: not-allowed;
}
&:not(:disabled) {
&::after {
content: \\"\\";
position: absolute;
top: 0;
right: 0;
left: 0;
bottom: 0;
/* transparent by default */
background-color: transparent;
transition: background-color 0.05s ease-in-out;
/* put the overlay behind the text */
z-index: -1;
}
/* on hover, raise, brighten and shadow */
&:hover {
transform: translateY(-1px);
box-shadow: 0 1px 2px rgba(0,0,0,0.05);
&::after {
background-color: rgba(255, 255, 255, 0.3);
}
}
/* on click, lower and darken */
&:active {
outline: none;
box-shadow: none;
border-color: rgba(0,0,0,0.2);
transform: translateY(0);
&::after {
background-color: rgba(0, 0, 0, 0.1);
}
}
}
",
"
--right: 0%;
&::after {
content: \\"\\";
/* z-index: ; */
top: 0;
bottom: 0;
left: 0;
right: var(--right);
border-radius: ",
[Function],
";
position: absolute;
opacity: 0.5;
/* background-color: red; */
background-image: linear-gradient(to right, 0px rgba(0,0,0,1), 100% red);
animation: ",
Keyframes {
"id": "sc-keyframes-cwUnhJ",
"inject": [Function],
"name": "cwUnhJ",
"rules": Array [
"@-webkit-keyframes cwUnhJ{0%{background-image:linear-gradient(to right,0px transparent,1px red);}100%{background-image:linear-gradient(to right,0px transparent,100% red);}}",
"@keyframes cwUnhJ{0%{background-image:linear-gradient(to right,0px transparent,1px red);}100%{background-image:linear-gradient(to right,0px transparent,100% red);}}",
],
"toString": [Function],
},
" forwards infinite 1s;
}
",
],
},
"defaultProps": Object {
"loadingPct": 100,
"theme": Object {
"actions": Object {
"primary": "#46b646",
},
"button": Object {
"borderRadius": "2px",
},
},
},
"displayName": "Styled(styled.button)",
"foldedComponentIds": Array [
"sc-bdVaJa",
],
"render": [Function],
"styledComponentId": "sc-bxivhb",
"target": "button",
"toString": [Function],
"warnTooManyClasses": [Function],
"withComponent": [Function],
},
"props": Object {
"disabled": true,
"style": Object {
"--right": "0%",
},
},
},
}
}
primary={false}
secondary={false}
>
Example
</styled.button>
</Button>
`;
exports[`Storyshots Button Primary 1`] = `

View file

@ -1,10 +1,16 @@
import * as React from 'react'
import { storiesOf } from '@storybook/react'
import { action } from '@storybook/addon-actions'
import { number, withKnobs } from '@storybook/addon-knobs'
import Button, { PrimaryButton, SecondaryButton } from './Button'
import Button, {
PrimaryButton,
SecondaryButton,
LoadingButton
} from './Button'
const s = storiesOf('Button', module)
s.addDecorator(withKnobs)
const pressed = action('button pressed!')
@ -12,4 +18,4 @@ s.add('Default', () => <Button onButtonPress={pressed}>Example</Button>)
s.add('Disabled', () => <Button disabled onButtonPress={pressed}>Example</Button>)
s.add('Primary', () => <PrimaryButton onButtonPress={pressed}>Example</PrimaryButton>)
s.add('Secondary', () => <SecondaryButton onButtonPress={pressed}>Example</SecondaryButton>)
s.add('Loading', () => <Button loading onButtonPress={pressed}>Example</Button>)
s.add('Loading', () => <LoadingButton onButtonPress={pressed} loadingPct={number('Loading percentage', 100, ({ max: 100, min: 0, step: 1 } as any))}>Example</LoadingButton>)

View file

@ -1,8 +1,11 @@
import * as React from 'react'
import { shallow } from 'enzyme'
import * as sinon from 'sinon'
import 'jest-styled-components'
import Button from './Button'
// import { StyledLoadingButton } from './styled'
// import { ButtonProps } from './types'
describe('<Button />', () => {
it('calls onButtonPress when not disabled', () => {
@ -21,3 +24,10 @@ describe('<Button />', () => {
expect(spy.notCalled).toBeTruthy()
})
})
describe('<StyledLoadingButton />', () => {
// it('clamps between 0-100%', () => {
// const button = shallow<ButtonProps>(<StyledLoadingButton loadingPct={-100} />)
// })
})

View file

@ -5,12 +5,15 @@ import {
import {
StyledButton,
StyledPrimaryButton,
StyledSecondaryButton
StyledSecondaryButton,
StyledLoadingButton
} from './styled'
import {
ButtonProps
} from './types'
const clampPct = (i: number): number => Math.max(0, Math.min(100, i))
export default class Button extends React.Component<ButtonProps> {
static defaultProps: ButtonProps = {
disabled: false,
@ -64,3 +67,15 @@ export const SecondaryButton = (props: ButtonProps) => <Button {...props} overri
component: StyledSecondaryButton
}
}} />
export const LoadingButton = (props: ButtonProps & { loadingPct?: number }) => <Button {...props} overrides={{
BaseButton: {
component: StyledLoadingButton,
props: {
disabled: true,
style: {
'--right': `${clampPct(100 - (props.loadingPct || 0))}%`
}
}
}
}} />

View file

@ -1,4 +1,10 @@
export { default as default } from './Button'
export {
default as default,
default as Button,
PrimaryButton,
SecondaryButton,
LoadingButton
} from './Button'
export {
StyledButton

View file

@ -1,8 +1,10 @@
// import * as React from 'react'
import styled from 'styled-components'
import styled, { keyframes } from 'styled-components'
import * as colorHelpers from '../helpers/colors'
// import { ButtonProps } from './types'
export const StyledButton = styled.button`
/* reset some styles */
box-shadow: none;
@ -95,3 +97,37 @@ export const StyledSecondaryButton = styled(StyledButton)`
border-color: ${props => colorHelpers.stepDown(props.theme.actions.primary)};
}
`
const loadingAnim = keyframes`
0% {
background-image: linear-gradient(to right, 0px transparent, 1px red);
}
100% {
background-image: linear-gradient(to right, 0px transparent, 100% red);
}
`
export const StyledLoadingButton = styled(StyledButton)<{loadingPct?: number}>`
--right: 0%;
&::after {
content: "";
/* z-index: ; */
top: 0;
bottom: 0;
left: 0;
right: var(--right);
border-radius: ${props => props.theme.button.borderRadius};
position: absolute;
opacity: 0.5;
/* background-color: red; */
background-image: linear-gradient(to right, 0px rgba(0,0,0,1), 100% red);
animation: ${loadingAnim} forwards infinite 1s;
}
`
StyledLoadingButton.defaultProps = {
...StyledButton.defaultProps,
loadingPct: 100
}

View file

@ -1,6 +1,6 @@
import * as Color from 'color'
const color = (i: Color | string) => {
export const color = (i: Color | string) => {
return new Color(i)
}

View file

@ -0,0 +1,4 @@
import * as Colors from './helpers/colors'
export { Colors }
export * from './button'