-
Notifications
You must be signed in to change notification settings - Fork 536
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
Migrate utils to TypeScript #1055
Changes from all commits
7ac0956
eaeb238
d9ebb95
3be2154
bb32932
b7904f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@primer/components": patch | ||
--- | ||
|
||
Migrate `utils` to TypeScript |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
declare module 'jest-styled-components/serializer' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export default function isNumeric(n) { | ||
export default function isNumeric(n: any) { | ||
return !isNaN(parseFloat(n)) && isFinite(n) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,7 +73,7 @@ export function renderClasses(component: React.ReactElement): string { | |
/** | ||
* Returns true if a node renders with a single class. | ||
*/ | ||
export function rendersClass(node: React.ReactElement, klass: string): boolean { | ||
export function rendersClass(node: React.ReactElement, klass: string): boolean { | ||
return renderClasses(node).includes(klass) | ||
} | ||
|
||
|
@@ -96,7 +96,7 @@ export function renderStyles(node: React.ReactElement): any { | |
return getComputedStyles(className) | ||
} | ||
|
||
export function getComputedStyles(className: string): Record<string, string> { | ||
export function getComputedStyles(className: string): Record<string, string | Record<string, string>> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This feels weird, but was required to make L80 of Though, I might be misunderstanding this 😅 |
||
const div = document.createElement('div') | ||
div.className = className | ||
|
||
|
@@ -107,14 +107,14 @@ export function getComputedStyles(className: string): Record<string, string> { | |
if (rule instanceof CSSMediaRule) { | ||
readMedia(rule) | ||
} else if (rule instanceof CSSStyleRule) { | ||
readRule(rule, computed) | ||
} else { | ||
readRule(rule, computed) | ||
} else { | ||
// console.warn('rule.type =', rule.type) | ||
} | ||
} | ||
} | ||
|
||
return computed | ||
return computed | ||
|
||
function matchesSafe(node: HTMLDivElement, selector: string) { | ||
if (!selector) { | ||
|
@@ -194,16 +194,15 @@ export function unloadCSS(path: string) { | |
// to render without errors, you can pass a `toRender` function that | ||
// returns an element ready to be rendered. | ||
|
||
|
||
interface Options { | ||
skipAs?: boolean | ||
skipSx?: boolean | ||
} | ||
|
||
interface BehavesAsComponent { | ||
Component: React.FunctionComponent<any>, | ||
systemPropArray: any[], | ||
toRender?: () => React.ReactElement, | ||
Component: React.ComponentType<any> | ||
systemPropArray: any[] | ||
toRender?: () => React.ReactElement | ||
options?: Options | ||
} | ||
|
||
|
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 there a better place for this?
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.
Not sure. I think this is fine for now 👍