diff --git a/components/src/components/atoms/RecordItem/RecordItem.tsx b/components/src/components/atoms/RecordItem/RecordItem.tsx index 34c7a123..6984aaaf 100644 --- a/components/src/components/atoms/RecordItem/RecordItem.tsx +++ b/components/src/components/atoms/RecordItem/RecordItem.tsx @@ -161,90 +161,106 @@ const TrailingIcon = styled.svg<{ $rotate?: boolean }>( `, ) -export const RecordItem = ({ - as: asProp = 'button', - link, - size = 'small', - inline = false, - icon, - keyLabel, - keySublabel, - value, - children, - ...props -}: Props) => { - const { copy, copied } = useCopied() - - const generatedProps = - asProp === 'a' - ? ({ - href: link, - rel: 'nofollow noreferrer', - target: '_blank', - ...props, - } as NativeElementProps & NativeAnchorProps) - : ({ - onClick: () => { - copy(value) - }, - ...props, - } as NativeElementProps & NativeButtonProps) - - const hasPrefix = !!icon || !!keyLabel - const hasLabels = !!keyLabel || !!keySublabel - - const KeyLabel = - typeof keyLabel === 'string' ? ( - - {keyLabel} - - ) : ( - keyLabel - ) +export const RecordItem = React.forwardRef< + HTMLAnchorElement | HTMLButtonElement, + Props +>( + ( + { + as: asProp = 'button', + link, + size = 'small', + inline = false, + icon, + keyLabel, + keySublabel, + value, + children, + ...props + }, + ref, + ) => { + const { copy, copied } = useCopied() + + const generatedProps = + asProp === 'a' + ? ({ + href: link, + rel: 'nofollow noreferrer', + target: '_blank', + ...props, + } as NativeElementProps & NativeAnchorProps) + : ({ + onClick: () => { + copy(value) + }, + ...props, + } as NativeElementProps & NativeButtonProps) + + const hasPrefix = !!icon || !!keyLabel + const hasLabels = !!keyLabel || !!keySublabel - const KeySublabel = - typeof keySublabel === 'string' ? ( - + {keyLabel} + + ) : ( + keyLabel + ) + + const KeySublabel = + typeof keySublabel === 'string' ? ( + + {keySublabel} + + ) : ( + keySublabel + ) + const PostfixProps = link + ? { $rotate: true, as: UpArrowSVG } + : copied + ? { as: CheckSVG } + : { as: CopySVG } + + return ( + } > - {keySublabel} - - ) : ( - keySublabel + {hasPrefix && ( + + {icon && {icon}} + {hasLabels && ( + + {KeyLabel} + {KeySublabel} + + )} + + )} + + + ) - const PostfixProps = link - ? { $rotate: true, as: UpArrowSVG } - : copied - ? { as: CheckSVG } - : { as: CopySVG } - - return ( - - {hasPrefix && ( - - {icon && {icon}} - {hasLabels && ( - - {KeyLabel} - {KeySublabel} - - )} - - )} - - - - ) -} + }, +) RecordItem.displayName = 'RecordItem' diff --git a/package.json b/package.json index 9b4ee1f8..503d1e0c 100644 --- a/package.json +++ b/package.json @@ -94,5 +94,6 @@ "overrides": { "ts-morph": "17.0.1" } - } + }, + "packageManager": "pnpm@7.8.0" }