-
Notifications
You must be signed in to change notification settings - Fork 598
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
TypeScript refactor #959
Merged
Merged
TypeScript refactor #959
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
b6458df
Install @babel/preset-typescript
colebemis 23c8eaf
index.js → index.ts
colebemis 666f5c3
Create tsconfig.json
colebemis 2fc81bb
constants.js → constants.ts
colebemis 68715a3
sx.js → sx.ts
colebemis 699ce1c
Box.js → Box.tsx
colebemis 2531d4a
Export BoxProps interface
colebemis f67eb88
Add "dist:types" script
colebemis 52cce3f
Clean up "dist" scripts
colebemis 35fb829
Use @babel/eslint-parser
colebemis af86a1c
Install gatsby-plugin-typescript
colebemis ea4f79c
Install typescript in docs
colebemis 912c737
Update webpack js rule
colebemis 7e30bf6
Filter out tsx rule
colebemis b816dda
Try removing rule overrides
colebemis 79481b9
Remove playroom from now build
colebemis 28de9c6
Import box types
colebemis 0b0de5e
Create StyledComponentProps interface
colebemis 3898ce0
Add html attributes to box props
colebemis 919b46f
Use TypeScript for Box tests
colebemis 09354a3
Refactor BoxProps
colebemis e24f64b
Restore rule overrides
colebemis 04dd454
Remove typescript dep from docs
colebemis cf7b3ce
Rename system prop interfaces
colebemis c2ca680
Explain @ts-ignore reason
colebemis 6f93b2e
Move @types/styled-system__* deps
colebemis f0508b1
Merge remote-tracking branch 'origin/main' into colebemis/ts-refactor
colebemis decbbf3
Revert index.d.ts
colebemis 083129e
Remove types directory from published files
colebemis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"parser": "@babel/eslint-parser", | ||
"extends": [ | ||
"plugin:github/es6", | ||
"plugin:github/react", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ lib/ | |
lib-esm/ | ||
public/ | ||
stats.html | ||
types |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// @ts-ignore @styled-system/prop-types does not provide type definitions | ||
import systemPropTypes from '@styled-system/prop-types' | ||
import {themeGet} from '@styled-system/theme-get' | ||
import PropTypes from 'prop-types' | ||
import React from 'react' | ||
import * as styledSystem from 'styled-system' | ||
import theme from './theme' | ||
|
||
interface StyleFn extends styledSystem.styleFn { | ||
propTypes?: React.WeakValidationMap<any> | ||
} | ||
|
||
const {get: getKey, compose, system} = styledSystem | ||
|
||
export const get = (key: string) => themeGet(key, getKey(theme, key)) | ||
|
||
// Common props | ||
|
||
export const COMMON: StyleFn = compose(styledSystem.space, styledSystem.color, styledSystem.display) | ||
|
||
export interface SystemCommonProps | ||
extends styledSystem.ColorProps, | ||
styledSystem.SpaceProps, | ||
styledSystem.DisplayProps {} | ||
|
||
COMMON.propTypes = { | ||
...systemPropTypes.space, | ||
...systemPropTypes.color, | ||
} | ||
|
||
// Typography props | ||
|
||
const whiteSpace = system({ | ||
whiteSpace: { | ||
property: 'whiteSpace', | ||
// cssProperty: 'whiteSpace', | ||
}, | ||
}) | ||
|
||
export const TYPOGRAPHY: StyleFn = compose(styledSystem.typography, whiteSpace) | ||
|
||
export interface SystemTypographyProps extends styledSystem.TypographyProps { | ||
whiteSpace?: 'normal' | 'nowrap' | 'pre' | 'pre-wrap' | 'pre-line' | ||
} | ||
|
||
TYPOGRAPHY.propTypes = { | ||
...systemPropTypes.typography, | ||
whiteSpace: PropTypes.oneOf(['normal', 'nowrap', 'pre-wrap', 'pre', 'pre-line']), | ||
} | ||
|
||
// Border props | ||
|
||
export const BORDER: StyleFn = compose(styledSystem.border, styledSystem.shadow) | ||
|
||
export interface SystemBorderProps extends styledSystem.BorderProps, styledSystem.ShadowProps {} | ||
|
||
BORDER.propTypes = { | ||
...systemPropTypes.border, | ||
...systemPropTypes.shadow, | ||
} | ||
|
||
// Layout props | ||
|
||
export const LAYOUT: StyleFn = styledSystem.layout | ||
|
||
export interface SystemLayoutProps extends styledSystem.LayoutProps {} | ||
|
||
LAYOUT.propTypes = systemPropTypes.layout | ||
|
||
// Position props | ||
|
||
export const POSITION: StyleFn = styledSystem.position | ||
|
||
export interface SystemPositionProps extends styledSystem.PositionProps {} | ||
|
||
POSITION.propTypes = systemPropTypes.position | ||
|
||
// Flex props | ||
|
||
export const FLEX: StyleFn = styledSystem.flexbox | ||
|
||
export interface SystemFlexProps extends styledSystem.FlexboxProps {} | ||
|
||
FLEX.propTypes = systemPropTypes.flexbox | ||
|
||
// Grid props | ||
|
||
export const GRID: StyleFn = styledSystem.grid | ||
|
||
export interface SystemGridProps extends styledSystem.GridProps {} | ||
|
||
GRID.propTypes = systemPropTypes.grid |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import PropTypes from 'prop-types' | ||
colebemis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import css, {SystemStyleObject} from '@styled-system/css' | ||
|
||
export interface SxProp { | ||
sx?: SystemStyleObject | ||
} | ||
|
||
const sx = (props: SxProp) => css(props.sx) | ||
|
||
sx.propTypes = { | ||
sx: PropTypes.object, | ||
} | ||
|
||
export default sx |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it worth re-considering using
default
exports as well? It is probably a breaking change if anyone was consuming directly from@primer/components/lib/Box
or something like that, but if we're going to be making other breaking changes, it might be a fair time to consider it.I'm not really aware of the main pros/cons of default exports, and it seems like in other code at GitHub we're inconsistent on this already, so maybe it's not even worth looking at 😅
For example, https://github.com/github/details-dialog-element/blob/main/src/index.ts uses a default export, and web components in the dotcom codebase itself seem to be about 50/50.
Just thought I'd mention it to see if it sparks thoughts for others.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally I prefer not to use default exports. Here is a good article about it: https://basarat.gitbook.io/typescript/main-1/defaultisbad
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm open to moving away from default exports for our components. A few thoughts:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-default-export.md