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

pass props through in more places #41

Merged
merged 2 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/area.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { area } from 'd3-shape'
* @param props.curve - optional curve factory
* @param props.sx - optional sx object
*/
const Area = ({ data, color = 'primary', curve = false, sx }) => {
const Area = ({ data, color = 'primary', curve = false, sx, ...props }) => {
const { x: _x, y: _y } = useChart()

let generator = area()
Expand All @@ -34,6 +34,7 @@ const Area = ({ data, color = 'primary', curve = false, sx }) => {
fill: color,
...sx,
}}
{...props}
/>
)
}
Expand Down
6 changes: 5 additions & 1 deletion src/axis.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const styles = {
},
}

const Axis = ({ left, right, top, bottom, sx }) => {
const Axis = ({ left, right, top, bottom, sx, ...props }) => {
const leftSx = useChartPadding(({ apt, pt, pb, apb, pl }) => ({
height: `calc(100% - ${apt + pt + pb + apb}px)`,
left: `${pl}px`,
Expand Down Expand Up @@ -44,6 +44,7 @@ const Axis = ({ left, right, top, bottom, sx }) => {
...leftSx,
...sx,
}}
{...props}
/>
)}
{right && (
Expand All @@ -55,6 +56,7 @@ const Axis = ({ left, right, top, bottom, sx }) => {
...rightSx,
...sx,
}}
{...props}
/>
)}
{bottom && (
Expand All @@ -66,6 +68,7 @@ const Axis = ({ left, right, top, bottom, sx }) => {
...bottomSx,
...sx,
}}
{...props}
/>
)}
{top && (
Expand All @@ -77,6 +80,7 @@ const Axis = ({ left, right, top, bottom, sx }) => {
...topSx,
...sx,
}}
{...props}
/>
)}
</>
Expand Down
3 changes: 2 additions & 1 deletion src/circle.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { memo } from 'react'
import { Box } from 'theme-ui'
import { useChart } from './chart'

const Circle = ({ x, y, color = 'primary', size = 10, sx }) => {
const Circle = ({ x, y, color = 'primary', size = 10, sx, ...props }) => {
const { x: _x, y: _y } = useChart()

return (
Expand All @@ -19,6 +19,7 @@ const Circle = ({ x, y, color = 'primary', size = 10, sx }) => {
vectorEffect: 'non-scaling-stroke',
...sx,
}}
{...props}
/>
)
}
Expand Down
2 changes: 2 additions & 0 deletions src/donut.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const Donut = ({
outerRadius = 50,
color = 'primary',
sx,
...props
}) => {
domain = domain || [0, data.length - 1]
range = range || [0.3, 0.9]
Expand All @@ -34,6 +35,7 @@ const Donut = ({
fill: color,
...sx,
}}
{...props}
/>
)
})}
Expand Down
12 changes: 7 additions & 5 deletions src/grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const styles = {
},
}

const VerticalGrid = ({ values, x, sx }) => {
const VerticalGrid = ({ values, x, sx, ...props }) => {
return values.map((d, i) => {
return (
<Box
Expand All @@ -26,12 +26,13 @@ const VerticalGrid = ({ values, x, sx }) => {
borderLeftWidth: '1px',
...sx,
}}
{...props}
/>
)
})
}

const HorizontalGrid = ({ values, y, sx }) => {
const HorizontalGrid = ({ values, y, sx, ...props }) => {
return values.map((d, i) => {
return (
<Box
Expand All @@ -43,12 +44,13 @@ const HorizontalGrid = ({ values, y, sx }) => {
width: `calc(100%)`,
...sx,
}}
{...props}
/>
)
})
}

const Grid = ({ horizontal, vertical, count = 5, values, sx }) => {
const Grid = ({ horizontal, vertical, count = 5, values, sx, ...props }) => {
const { x, y, logx, logy } = useChart()
const verticalSx = useChartPadding(
({ apt, pt, pb, apb, apl, pl, pr, apr }) => ({
Expand Down Expand Up @@ -77,7 +79,7 @@ const Grid = ({ horizontal, vertical, count = 5, values, sx }) => {
...verticalSx,
}}
>
<VerticalGrid values={values.vertical} x={x} sx={sx} />
<VerticalGrid values={values.vertical} x={x} sx={sx} {...props} />
</Box>
)}
{horizontal && (
Expand All @@ -87,7 +89,7 @@ const Grid = ({ horizontal, vertical, count = 5, values, sx }) => {
...horizontalSx,
}}
>
<HorizontalGrid bottom values={values.horizontal} y={y} sx={sx} />
<HorizontalGrid values={values.horizontal} y={y} sx={sx} {...props} />
</Box>
)}
</>
Expand Down
13 changes: 12 additions & 1 deletion src/label.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,17 @@ import React from 'react'
import { Box } from 'theme-ui'
import Point from './point'

const Label = ({ x, y, children, align, verticalAlign, width, height, sx }) => {
const Label = ({
x,
y,
children,
align,
verticalAlign,
width,
height,
sx,
...props
}) => {
return (
<Point
x={x}
Expand All @@ -22,6 +32,7 @@ const Label = ({ x, y, children, align, verticalAlign, width, height, sx }) => {
textAlign: align,
...sx,
}}
{...props}
>
{children}
</Box>
Expand Down
10 changes: 9 additions & 1 deletion src/line.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ import { Box } from 'theme-ui'
import { useChart } from './chart'
import { line } from 'd3-shape'

const Line = ({ data, color = 'primary', width = 1, curve = false, sx }) => {
const Line = ({
data,
color = 'primary',
width = 1,
curve = false,
sx,
...props
}) => {
const { x: _x, y: _y } = useChart()

let generator = line()
Expand All @@ -27,6 +34,7 @@ const Line = ({ data, color = 'primary', width = 1, curve = false, sx }) => {
vectorEffect: 'non-scaling-stroke',
...sx,
}}
{...props}
/>
)
}
Expand Down
3 changes: 2 additions & 1 deletion src/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import { Box } from 'theme-ui'
import useChartPadding from './utils/use-chart-padding'

const Plot = ({ children, sx, mode = 'svg', square = false }) => {
const Plot = ({ children, sx, mode = 'svg', square = false, ...props }) => {
const responsiveSx = useChartPadding(
({ apt, pt, pb, apb, apl, pl, pr, apr }) => ({
height: `calc(100% - ${apt + pt + pb + apb}px)`,
Expand Down Expand Up @@ -31,6 +31,7 @@ const Plot = ({ children, sx, mode = 'svg', square = false }) => {
overflow: 'visible',
...sx,
}}
{...props}
>
{children}
</Box>
Expand Down
2 changes: 2 additions & 0 deletions src/point.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const Point = ({
verticalAlign = 'top',
width,
height,
...props
}) => {
const { x: _x, y: _y } = useChart()
const responsiveSx = useChartPadding(
Expand Down Expand Up @@ -104,6 +105,7 @@ const Point = ({
...verticalPosition,
...flexStyles,
}}
{...props}
>
{children}
</Box>
Expand Down
11 changes: 10 additions & 1 deletion src/scatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@ import React, { memo } from 'react'
import { Box } from 'theme-ui'
import { useChart } from './chart'

const Scatter = ({ data, x, y, color = 'primary', size = 10, sx }) => {
const Scatter = ({
data,
x,
y,
color = 'primary',
size = 10,
sx,
...props
}) => {
const { x: _x, y: _y } = useChart()
x = x || ((d) => d[0])
y = y || ((d) => d[1])
Expand All @@ -29,6 +37,7 @@ const Scatter = ({ data, x, y, color = 'primary', size = 10, sx }) => {
vectorEffect: 'non-scaling-stroke',
...sx,
}}
{...props}
/>
)
}
Expand Down
Loading