Skip to content

Commit

Permalink
chore: drop default-props (#374)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats authored Jul 18, 2024
1 parent 0dfe964 commit 9ab0879
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 71 deletions.
49 changes: 27 additions & 22 deletions packages/react/src/components/Card/CardWrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,29 +78,34 @@ const Element = styled('a')(
contrast && (!color || !backgroundColor) && hoverStyle
)

const CardWrap = forwardRef(({ href, rel, target, ...restProps }, ref) => {
const {
state: { backgroundColor, color, title },
props: { size: $cardSize }
} = useContext(GlobalContext)

return createElement(Element, {
...(restProps.as === 'a' ? { href, rel, target } : undefined),
...restProps,
backgroundColor,
$cardSize,
color,
ref,
title
})
})
const CardWrap = forwardRef(
(
{
href,
rel = 'noopener noreferrer',
target = '_blank',
as = 'a',
...restProps
},
ref
) => {
const {
state: { backgroundColor, color, title },
props: { size: $cardSize }
} = useContext(GlobalContext)

return createElement(Element, {
...(as === 'a' ? { href, rel, target } : undefined),
...restProps,
backgroundColor,
$cardSize,
color,
ref,
title
})
}
)

CardWrap.displayName = 'CardWrap'

CardWrap.defaultProps = {
as: 'a',
rel: 'noopener noreferrer',
target: '_blank'
}

export default CardWrap
49 changes: 32 additions & 17 deletions packages/react/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,25 +209,40 @@ microlink.io/${error.code.toLowerCase()}
)
}

const Microlink = props => (
<GlobalState {...props}>{otherProps => <Card {...otherProps} />}</GlobalState>
const Microlink = ({
className = '',
apiKey = undefined,
autoPlay = true,
controls = true,
direction = 'ltr',
lazy = true,
loop = true,
media = ['iframe', 'video', 'audio', 'image', 'logo'],
fetchData = true,
muted = true,
playsInline = true,
size = 'normal',
...props
}) => (
<GlobalState
className={className}
apiKey={apiKey}
autoPlay={autoPlay}
controls={controls}
direction={direction}
lazy={lazy}
loop={loop}
media={media}
fetchData={fetchData}
muted={muted}
playsInline={playsInline}
size={size}
{...props}
>
{otherProps => <Card {...otherProps} />}
</GlobalState>
)

Microlink.defaultProps = {
className: '',
apiKey: undefined,
autoPlay: true,
controls: true,
direction: 'ltr',
lazy: true,
loop: true,
media: ['iframe', 'video', 'audio', 'image', 'logo'],
fetchData: true,
muted: true,
playsInline: true,
size: 'normal'
}

Microlink.propTypes = {
apiKey: PropTypes.string,
autoPlay: PropTypes.bool,
Expand Down
34 changes: 2 additions & 32 deletions packages/react/test/snapshots/build.mjs.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,7 @@ Generated by [AVA](https://avajs.dev).
`{␊
fetchFromApi: [Getter],␊
default: [Function: Microlink] {␊
defaultProps: {␊
className: '',␊
apiKey: undefined,␊
autoPlay: true,␊
controls: true,␊
direction: 'ltr',␊
lazy: true,␊
loop: true,␊
media: [Array],␊
fetchData: true,␊
muted: true,␊
playsInline: true,␊
size: 'normal'␊
}␊
},␊
default: [Function: Microlink],␊
getApiUrl: [Function: getApiUrl],␊
imageProxy: [Function: imageProxy]␊
}`
Expand All @@ -35,22 +20,7 @@ Generated by [AVA](https://avajs.dev).
> Snapshot 1
`[Module: null prototype] {␊
default: [Function: Microlink] {␊
defaultProps: {␊
className: '',␊
apiKey: undefined,␊
autoPlay: true,␊
controls: true,␊
direction: 'ltr',␊
lazy: true,␊
loop: true,␊
media: [Array],␊
fetchData: true,␊
muted: true,␊
playsInline: true,␊
size: 'normal'␊
}␊
},␊
default: [Function: Microlink],␊
fetchFromApi: [AsyncFunction: fetchFromApi],␊
getApiUrl: [Function: getApiUrl],␊
imageProxy: [Function: imageProxy]␊
Expand Down
Binary file modified packages/react/test/snapshots/build.mjs.snap
Binary file not shown.

0 comments on commit 9ab0879

Please sign in to comment.