-
Notifications
You must be signed in to change notification settings - Fork 445
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
refactor: use transient props in various styled components #5093
Changes from all commits
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 |
---|---|---|
@@ -1,30 +1,25 @@ | ||
import {useLayer} from '@sanity/ui' | ||
import React, {useCallback, useMemo, useState} from 'react' | ||
import React, {useMemo} from 'react' | ||
import {ConnectorContext} from './ConnectorContext' | ||
import { | ||
ChangeBarWrapper, | ||
FieldWrapper, | ||
ChangeBar, | ||
ChangeBarMarker, | ||
ChangeBarButton, | ||
ChangeBarMarker, | ||
ChangeBarWrapper, | ||
FieldWrapper, | ||
} from './ElementWithChangeBar.styled' | ||
|
||
export function ElementWithChangeBar(props: { | ||
children: React.ReactNode | ||
disabled?: boolean | ||
hasFocus: boolean | ||
isChanged?: boolean | ||
withHoverEffect?: boolean | ||
}) { | ||
const {children, disabled, hasFocus, isChanged, withHoverEffect = true} = props | ||
const {children, disabled, isChanged, withHoverEffect = true} = props | ||
|
||
const [hover, setHover] = useState(false) | ||
const {onOpenReviewChanges, isReviewChangesOpen} = React.useContext(ConnectorContext) | ||
const {zIndex} = useLayer() | ||
|
||
const handleMouseEnter = useCallback(() => setHover(true), []) | ||
const handleMouseLeave = useCallback(() => setHover(false), []) | ||
|
||
const changeBar = useMemo( | ||
() => | ||
disabled || !isChanged ? null : ( | ||
|
@@ -35,34 +30,21 @@ export function ElementWithChangeBar(props: { | |
aria-label="Review changes" | ||
data-testid="change-bar__button" | ||
onClick={isReviewChangesOpen ? undefined : onOpenReviewChanges} | ||
onMouseEnter={handleMouseEnter} | ||
onMouseLeave={handleMouseLeave} | ||
Comment on lines
-38
to
-39
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. Similarly, this internal state has been removed as |
||
tabIndex={-1} | ||
type="button" | ||
$withHoverEffect={withHoverEffect} | ||
/> | ||
</ChangeBar> | ||
), | ||
[ | ||
disabled, | ||
isChanged, | ||
zIndex, | ||
isReviewChangesOpen, | ||
onOpenReviewChanges, | ||
handleMouseEnter, | ||
handleMouseLeave, | ||
withHoverEffect, | ||
], | ||
[disabled, isChanged, zIndex, isReviewChangesOpen, onOpenReviewChanges, withHoverEffect], | ||
) | ||
|
||
return ( | ||
<ChangeBarWrapper | ||
changed={isChanged} | ||
data-testid="change-bar-wrapper" | ||
disabled={disabled} | ||
focus={hasFocus} | ||
hover={hover} | ||
isReviewChangeOpen={isReviewChangesOpen} | ||
$changed={isChanged} | ||
$disabled={disabled} | ||
$isReviewChangeOpen={isReviewChangesOpen} | ||
> | ||
<FieldWrapper data-testid="change-bar__field-wrapper">{children}</FieldWrapper> | ||
{changeBar} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,13 +56,7 @@ function DiffTooltipWithAnnotation(props: DiffTooltipWithAnnotationsProps) { | |
|
||
return ( | ||
<LegacyLayerProvider zOffset="paneFooter"> | ||
<Tooltip | ||
content={content} | ||
// data-placement={restProps.placement} | ||
portal | ||
allowedAutoPlacements={['top', 'bottom']} | ||
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. Removed as it's now deprecated in Sanity UI, and including it would yield similar transient prop warnings |
||
{...restProps} | ||
> | ||
<Tooltip content={content} portal {...restProps}> | ||
{children} | ||
</Tooltip> | ||
</LegacyLayerProvider> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,14 @@ export const ReferenceLinkCard = forwardRef(function ReferenceLinkCard( | |
props: ReferenceLinkCardProps & React.HTMLProps<HTMLElement>, | ||
ref: React.ForwardedRef<HTMLElement>, | ||
) { | ||
const {documentType, as: asProp, ...restProps} = props | ||
const { | ||
as: asProp, | ||
// We exclude `documentId` from spread props to avoid passing it to the Card component | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
documentId, | ||
Comment on lines
+34
to
+36
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. Would love to know if there's a more elegant way to do this! 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. I think you should be able to assingn it to 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. I considered this! Though I believe we need to amend our eslint config slightly to accommodate, e.g.
Happy to add if you feel appropriate! Otherwise we can just leave as-is 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. Since There's also no-unused-vars#ignorerestsiblings, which is more specific to this particular case. |
||
documentType, | ||
...cardProps | ||
} = props | ||
const dataAs = documentType ? 'a' : undefined | ||
|
||
// If the child link is clicked without a document type, an error will be thrown. | ||
|
@@ -39,7 +46,7 @@ export const ReferenceLinkCard = forwardRef(function ReferenceLinkCard( | |
|
||
return ( | ||
<StyledCard | ||
{...restProps} | ||
{...cardProps} | ||
data-as={dataAs} | ||
documentType={documentType} | ||
forwardedAs={as} | ||
|
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.
These were removed as the styled component wasn't doing anything with these values