Skip to content

Commit

Permalink
refactor default props to fix error message
Browse files Browse the repository at this point in the history
  • Loading branch information
andre19980 authored and plouc committed Jan 7, 2024
1 parent 71f3496 commit 0bc2fe8
Show file tree
Hide file tree
Showing 15 changed files with 379 additions and 376 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@ const CartesianMarkersItem = ({
lineStyle,
textStyle,
legend,
legendPosition,
legendOffsetX,
legendOffsetY,
legendOrientation,
legendPosition = 'top-right',
legendOffsetX = 14,
legendOffsetY = 14,
legendOrientation = 'horizontal',
}) => {
const theme = useTheme()

Expand Down Expand Up @@ -256,11 +256,5 @@ CartesianMarkersItem.propTypes = {
legendOffsetY: PropTypes.number.isRequired,
legendOrientation: PropTypes.oneOf(['horizontal', 'vertical']).isRequired,
}
CartesianMarkersItem.defaultProps = {
legendPosition: 'top-right',
legendOffsetX: 14,
legendOffsetY: 14,
legendOrientation: 'horizontal',
}

export default memo(CartesianMarkersItem)
23 changes: 14 additions & 9 deletions packages/core/src/components/defs/patterns/PatternDots.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
import { memo } from 'react'
import PropTypes from 'prop-types'

export const PatternDots = memo(({ id, background, color, size, padding, stagger }) => {
export const PatternDotsDefaultProps = {
color: '#000000',
background: '#ffffff',
size: 4,
padding: 4,
stagger: false,
}

export const PatternDots = memo(props => {
const { id, background, color, size, padding, stagger } = {
...PatternDotsDefaultProps,
...props,
}

let fullSize = size + padding
const radius = size / 2
const halfPadding = padding / 2
Expand Down Expand Up @@ -35,14 +48,6 @@ PatternDots.propTypes = {
stagger: PropTypes.bool.isRequired,
}

PatternDots.defaultProps = {
color: '#000000',
background: '#ffffff',
size: 4,
padding: 4,
stagger: false,
}

export const patternDotsDef = (id, options = {}) => ({
id,
type: 'patternDots',
Expand Down
24 changes: 16 additions & 8 deletions packages/core/src/components/defs/patterns/PatternLines.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,23 @@ import { memo } from 'react'
import PropTypes from 'prop-types'
import { degreesToRadians } from '../../../lib/polar'

export const PatternLinesDefaultProps = {
spacing: 5,
rotation: 0,
background: '#000000',
color: '#ffffff',
lineWidth: 2,
}

export const PatternLines = memo(
({ id, spacing: _spacing, rotation: _rotation, background, color, lineWidth }) => {
({
id,
spacing: _spacing = PatternLinesDefaultProps.spacing,
rotation: _rotation = PatternLinesDefaultProps.rotation,
background = PatternLinesDefaultProps.background,
color = PatternLinesDefaultProps.color,
lineWidth = PatternLinesDefaultProps.lineWidth,
}) => {
let rotation = Math.round(_rotation) % 360
const spacing = Math.abs(_spacing)

Expand Down Expand Up @@ -69,13 +84,6 @@ PatternLines.propTypes = {
color: PropTypes.string.isRequired,
lineWidth: PropTypes.number.isRequired,
}
PatternLines.defaultProps = {
spacing: 5,
rotation: 0,
color: '#000000',
background: '#ffffff',
lineWidth: 2,
}

export const patternLinesDef = (id, options = {}) => ({
id,
Expand Down
22 changes: 14 additions & 8 deletions packages/core/src/components/defs/patterns/PatternSquares.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
import { memo } from 'react'
import PropTypes from 'prop-types'

export const PatternSquares = memo(({ id, background, color, size, padding, stagger }) => {
export const PatternSquaresDefaultProps = {
color: '#000000',
background: '#ffffff',
size: 4,
padding: 4,
stagger: false,
}

export const PatternSquares = memo(props => {
const { id, color, background, size, padding, stagger } = {
...PatternSquaresDefaultProps,
...props,
}

let fullSize = size + padding
const halfPadding = padding / 2
if (stagger === true) {
Expand Down Expand Up @@ -34,13 +47,6 @@ PatternSquares.propTypes = {
padding: PropTypes.number.isRequired,
stagger: PropTypes.bool.isRequired,
}
PatternSquares.defaultProps = {
color: '#000000',
background: '#ffffff',
size: 4,
padding: 4,
stagger: false,
}

export const patternSquaresDef = (id, options = {}) => ({
id,
Expand Down
16 changes: 8 additions & 8 deletions packages/core/src/motion/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ import { config as presets } from '@react-spring/web'

export const motionConfigContext = createContext()

export const MotionConfigProvider = ({ children, animate, config }) => {
export const motionDefaultProps = {
animate: true,
config: 'default',
}

export const MotionConfigProvider = props => {
const { children, animate, config } = { ...motionDefaultProps, ...props }

const value = useMemo(() => {
const reactSpringConfig = isString(config) ? presets[config] : config

Expand Down Expand Up @@ -40,10 +47,3 @@ MotionConfigProvider.propTypes = {
animate: motionPropTypes.animate,
config: motionPropTypes.motionConfig,
}

export const motionDefaultProps = {
animate: true,
config: 'default',
}

MotionConfigProvider.defaultProps = motionDefaultProps
6 changes: 3 additions & 3 deletions packages/funnel/src/props.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @ts-ignore
import { MotionConfigProvider } from '@nivo/core'
import { motionDefaultProps } from '@nivo/core'
import { FunnelLayerId } from './types'

export const svgDefaultProps = {
Expand Down Expand Up @@ -34,6 +34,6 @@ export const svgDefaultProps = {

role: 'img',

animate: MotionConfigProvider.defaultProps.animate,
motionConfig: MotionConfigProvider.defaultProps.config,
animate: motionDefaultProps.animate,
motionConfig: motionDefaultProps.config,
}
Loading

0 comments on commit 0bc2fe8

Please sign in to comment.