-
Notifications
You must be signed in to change notification settings - Fork 700
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
typescript(vx-glyph): re-write package in TypeScript #518
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
eab01b8
deps(vx-glyph): update deps for typescript, add types entry in packag…
d97c4fe
typescript(vx-glyph): rename .jsx? => .tsx?
daa5c9c
fix(vx-glyph): remove eslintrc
89acdee
typescript(vx-glyph): re-write package in TypeScript
c155926
deps(vx-glyph): require react@^16.3.0-0 peerDep
e5d9dd0
fix(vx-glyph): fix any in Glyph.test
0bc1d0a
test(vx-glyph): fix type
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
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,22 @@ | ||
import React from 'react'; | ||
import cx from 'classnames'; | ||
import { Group } from '@vx/group'; | ||
|
||
export type GlyphProps = { | ||
/** Top offset to apply to glyph g element container. */ | ||
top?: number; | ||
/** Left offset to apply to glyph g element container. */ | ||
left?: number; | ||
/** classname to apply to glyph g element container. */ | ||
className?: string; | ||
/** Children to render. */ | ||
children?: React.ReactNode; | ||
}; | ||
|
||
export default function Glyph({ top = 0, left = 0, className, children }: GlyphProps) { | ||
return ( | ||
<Group className={cx('vx-glyph', className)} top={top} left={left}> | ||
{children} | ||
</Group> | ||
); | ||
} |
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,41 @@ | ||
import React from 'react'; | ||
import cx from 'classnames'; | ||
import { Symbol, symbol, symbolCircle } from 'd3-shape'; | ||
import Glyph from './Glyph'; | ||
|
||
export type GlyphCircleProps<Datum> = { | ||
/** Render function override which is passed the configured path generator. */ | ||
children?: ({ path }: { path: Symbol<any, Datum> }) => React.ReactNode; | ||
/** classname to apply to glyph path element. */ | ||
className?: string; | ||
/** Top offset to apply to glyph g element container. */ | ||
top?: number; | ||
/** Left offset to apply to glyph g element container. */ | ||
left?: number; | ||
/** Size of circle in px, or an accessor which takes Datum as input and returns a size. */ | ||
size?: number | ((d: Datum) => number); | ||
}; | ||
|
||
export default function GlyphCircle<Datum = any>({ | ||
children, | ||
className, | ||
top, | ||
left, | ||
size, | ||
...restProps | ||
}: GlyphCircleProps<Datum> & Omit<React.SVGProps<SVGPathElement>, keyof GlyphCircleProps<Datum>>) { | ||
const path = symbol<Datum>(); | ||
path.type(symbolCircle); | ||
|
||
// TS can't differentiate the method overload here | ||
if (typeof size === 'number') path.size(size); | ||
else if (size) path.size(size); | ||
|
||
if (children) return <>{children({ path })}</>; | ||
|
||
return ( | ||
<Glyph top={top} left={left}> | ||
<path className={cx('vx-glyph-circle', className)} d={path() || ''} {...restProps} /> | ||
</Glyph> | ||
); | ||
} |
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,41 @@ | ||
import React from 'react'; | ||
import cx from 'classnames'; | ||
import { Symbol, symbol, symbolCross } from 'd3-shape'; | ||
import Glyph from './Glyph'; | ||
|
||
export type GlyphCrossProps<Datum> = { | ||
/** Render function override which is passed the configured path generator. */ | ||
children?: ({ path }: { path: Symbol<any, Datum> }) => React.ReactNode; | ||
/** classname to apply to glyph path element. */ | ||
className?: string; | ||
/** Top offset to apply to glyph g element container. */ | ||
top?: number; | ||
/** Left offset to apply to glyph g element container. */ | ||
left?: number; | ||
/** Size of cross in px, or an accessor which takes Datum as input and returns a size. */ | ||
size?: number | ((d: Datum) => number); | ||
}; | ||
|
||
export default function GlyphCross<Datum = any>({ | ||
children, | ||
className, | ||
top, | ||
left, | ||
size, | ||
...restProps | ||
}: GlyphCrossProps<Datum> & Omit<React.SVGProps<SVGPathElement>, keyof GlyphCrossProps<Datum>>) { | ||
const path = symbol<Datum>(); | ||
path.type(symbolCross); | ||
|
||
// TS can't differentiate the method overload here | ||
if (typeof size === 'number') path.size(size); | ||
else if (size) path.size(size); | ||
|
||
if (children) return <>{children({ path })}</>; | ||
|
||
return ( | ||
<Glyph top={top} left={left}> | ||
<path className={cx('vx-glyph-cross', className)} d={path() || ''} {...restProps} /> | ||
</Glyph> | ||
); | ||
} |
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,42 @@ | ||
import React from 'react'; | ||
import cx from 'classnames'; | ||
import { Symbol, symbol, symbolDiamond } from 'd3-shape'; | ||
import Glyph from './Glyph'; | ||
|
||
export type GlyphDiamondProps<Datum> = { | ||
/** Render function override which is passed the configured path generator. */ | ||
children?: ({ path }: { path: Symbol<any, Datum> }) => React.ReactNode; | ||
/** classname to apply to glyph path element. */ | ||
className?: string; | ||
/** Top offset to apply to glyph g element container. */ | ||
top?: number; | ||
/** Left offset to apply to glyph g element container. */ | ||
left?: number; | ||
/** Size of diamond in px, or an accessor which takes Datum as input and returns a size. */ | ||
size?: number | ((d: Datum) => number); | ||
}; | ||
|
||
export default function GlyphDiamond<Datum = any>({ | ||
children, | ||
className, | ||
top, | ||
left, | ||
size, | ||
...restProps | ||
}: GlyphDiamondProps<Datum> & | ||
Omit<React.SVGProps<SVGPathElement>, keyof GlyphDiamondProps<Datum>>) { | ||
const path = symbol<Datum>(); | ||
path.type(symbolDiamond); | ||
|
||
// TS can't differentiate the method overload here | ||
if (typeof size === 'number') path.size(size); | ||
else if (size) path.size(size); | ||
|
||
if (children) return <>{children({ path })}</>; | ||
|
||
return ( | ||
<Glyph top={top} left={left}> | ||
<path className={cx('vx-glyph-diamond', className)} d={path() || ''} {...restProps} /> | ||
</Glyph> | ||
); | ||
} |
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,31 @@ | ||
import React from 'react'; | ||
import cx from 'classnames'; | ||
import Glyph from './Glyph'; | ||
|
||
export type GlyphDotProps = { | ||
/** classname to apply to glyph path element. */ | ||
className?: string; | ||
/** Top offset to apply to glyph g element container. */ | ||
top?: number; | ||
/** Left offset to apply to glyph g element container. */ | ||
left?: number; | ||
/** Radius of dot. */ | ||
r?: number; | ||
/** x coordinate of the center of the dot. */ | ||
cx?: number; | ||
/** y coordinate of the center of the dot. */ | ||
cy?: number; | ||
}; | ||
|
||
export default function GlyphDot({ | ||
top = 0, | ||
left = 0, | ||
className, | ||
...restProps | ||
}: GlyphDotProps & Omit<React.SVGProps<SVGCircleElement>, keyof GlyphDotProps>) { | ||
return ( | ||
<Glyph top={top} left={left}> | ||
<circle className={cx('vx-glyph-dot', className)} {...restProps} /> | ||
</Glyph> | ||
); | ||
} |
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,41 @@ | ||
import React from 'react'; | ||
import cx from 'classnames'; | ||
import { Symbol, symbol, symbolSquare } from 'd3-shape'; | ||
import Glyph from './Glyph'; | ||
|
||
export type GlyphSquareProps<Datum> = { | ||
/** Render function override which is passed the configured path generator. */ | ||
children?: ({ path }: { path: Symbol<any, Datum> }) => React.ReactNode; | ||
/** classname to apply to glyph path element. */ | ||
className?: string; | ||
/** Top offset to apply to glyph g element container. */ | ||
top?: number; | ||
/** Left offset to apply to glyph g element container. */ | ||
left?: number; | ||
/** Size of square in px, or an accessor which takes Datum as input and returns a size. */ | ||
size?: number | ((d: Datum) => number); | ||
}; | ||
|
||
export default function GlyphSquare<Datum = any>({ | ||
children, | ||
className, | ||
top, | ||
left, | ||
size, | ||
...restProps | ||
}: GlyphSquareProps<Datum> & Omit<React.SVGProps<SVGPathElement>, keyof GlyphSquareProps<Datum>>) { | ||
const path = symbol<Datum>(); | ||
path.type(symbolSquare); | ||
|
||
// TS can't differentiate the method overload here | ||
if (typeof size === 'number') path.size(size); | ||
else if (size) path.size(size); | ||
|
||
if (children) return <>{children({ path })}</>; | ||
|
||
return ( | ||
<Glyph top={top} left={left}> | ||
<path className={cx('vx-glyph-square', className)} d={path() || ''} {...restProps} /> | ||
</Glyph> | ||
); | ||
} |
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.
the
Datum
generic here is not useful unless the consumer leverages thechildren
override. but sinced3
ssymbol
takes it as an arg I think exposing it is good.