diff --git a/ui/components/app/confirm/info/__snapshots__/info.test.tsx.snap b/ui/components/app/confirm/info/__snapshots__/info.test.tsx.snap index a257e3ee3fa8..495c94f5cc19 100644 --- a/ui/components/app/confirm/info/__snapshots__/info.test.tsx.snap +++ b/ui/components/app/confirm/info/__snapshots__/info.test.tsx.snap @@ -7,7 +7,7 @@ exports[`ConfirmInfo should match snapshot 1`] = ` >
+ +
+`; diff --git a/ui/components/app/confirm/info/row/__snapshots__/expandable-row.test.tsx.snap b/ui/components/app/confirm/info/row/__snapshots__/expandable-row.test.tsx.snap index db8407fd7bb9..1551e3922c4c 100644 --- a/ui/components/app/confirm/info/row/__snapshots__/expandable-row.test.tsx.snap +++ b/ui/components/app/confirm/info/row/__snapshots__/expandable-row.test.tsx.snap @@ -4,7 +4,7 @@ exports[`ConfirmInfoExpandableRow should match snapshot 1`] = `
+
+
+

+ some label +

+
+

+ Some text +

+
+
+`; + +exports[`ConfirmInfoRow should match snapshot when copy is enabled 1`] = ` +
+
+ +
+

+ some label +

+
+

+ Some text +

+
+
+`; diff --git a/ui/components/app/confirm/info/row/alert-row/__snapshots__/alert-row.test.tsx.snap b/ui/components/app/confirm/info/row/alert-row/__snapshots__/alert-row.test.tsx.snap index de65d1c7d004..a62665ef428c 100644 --- a/ui/components/app/confirm/info/row/alert-row/__snapshots__/alert-row.test.tsx.snap +++ b/ui/components/app/confirm/info/row/alert-row/__snapshots__/alert-row.test.tsx.snap @@ -4,7 +4,7 @@ exports[`AlertRow matches snapshot with no alert 1`] = `
{ + it('should match snapshot', () => { + const { container } = render(); + expect(container).toMatchSnapshot(); + }); +}); diff --git a/ui/components/app/confirm/info/row/copy-icon.tsx b/ui/components/app/confirm/info/row/copy-icon.tsx new file mode 100644 index 000000000000..ce349089dac3 --- /dev/null +++ b/ui/components/app/confirm/info/row/copy-icon.tsx @@ -0,0 +1,25 @@ +import React, { useCallback } from 'react'; + +import { useCopyToClipboard } from '../../../../../hooks/useCopyToClipboard'; +import { IconColor } from '../../../../../helpers/constants/design-system'; +import { Icon, IconName, IconSize } from '../../../../component-library'; + +type CopyCallback = (text: string) => void; + +export const CopyIcon: React.FC<{ copyText: string }> = ({ copyText }) => { + const [copied, handleCopy] = useCopyToClipboard(); + + const handleClick = useCallback(async () => { + (handleCopy as CopyCallback)(copyText); + }, [copyText]); + + return ( + + ); +}; diff --git a/ui/components/app/confirm/info/row/row.stories.tsx b/ui/components/app/confirm/info/row/row.stories.tsx index 5205c0301b86..ae15bfd79d09 100644 --- a/ui/components/app/confirm/info/row/row.stories.tsx +++ b/ui/components/app/confirm/info/row/row.stories.tsx @@ -28,4 +28,15 @@ DefaultStory.args = { children: 'Value', }; +export const CopyEnabledStory = (args) => ; + +CopyEnabledStory.storyName = 'CopyEnabled'; + +CopyEnabledStory.args = { + label: 'Key', + children: 'Value', + copyEnabled: true, + copyText: 'Some copy text' +}; + export default ConfirmInfoRowStory; diff --git a/ui/components/app/confirm/info/row/row.test.tsx b/ui/components/app/confirm/info/row/row.test.tsx new file mode 100644 index 000000000000..3a6a77e4b354 --- /dev/null +++ b/ui/components/app/confirm/info/row/row.test.tsx @@ -0,0 +1,25 @@ +import React from 'react'; +import { render } from '@testing-library/react'; + +import { Text } from '../../../../component-library'; +import { ConfirmInfoRow } from './row'; + +describe('ConfirmInfoRow', () => { + it('should match snapshot', () => { + const { container } = render( + + Some text + , + ); + expect(container).toMatchSnapshot(); + }); + + it('should match snapshot when copy is enabled', () => { + const { container } = render( + + Some text + , + ); + expect(container).toMatchSnapshot(); + }); +}); diff --git a/ui/components/app/confirm/info/row/row.tsx b/ui/components/app/confirm/info/row/row.tsx index 1455c46c44ef..b33b64227462 100644 --- a/ui/components/app/confirm/info/row/row.tsx +++ b/ui/components/app/confirm/info/row/row.tsx @@ -21,6 +21,7 @@ import { TextColor, TextVariant, } from '../../../../../helpers/constants/design-system'; +import { CopyIcon } from './copy-icon'; export enum ConfirmInfoRowVariant { Default = 'default', @@ -36,6 +37,8 @@ export type ConfirmInfoRowProps = { style?: React.CSSProperties; labelChildren?: React.ReactNode; color?: TextColor; + copyEnabled?: boolean; + copyText?: string; }; const BACKGROUND_COLORS = { @@ -74,6 +77,8 @@ export const ConfirmInfoRow: React.FC = ({ style, labelChildren, color, + copyEnabled = false, + copyText = undefined, }) => ( = ({ marginTop={2} marginBottom={2} paddingLeft={2} - paddingRight={2} + paddingRight={copyEnabled ? 5 : 2} color={TEXT_COLORS[variant] as TextColor} style={{ overflowWrap: OverflowWrap.Anywhere, minHeight: '24px', + position: 'relative', ...style, }} > + {copyEnabled && } = ({ )} {typeof children === 'string' ? ( - {children} + + {children} + ) : ( children )} diff --git a/ui/pages/confirmations/components/confirm/info/__snapshots__/info.test.tsx.snap b/ui/pages/confirmations/components/confirm/info/__snapshots__/info.test.tsx.snap index d9f473782e78..b7dfc0084551 100644 --- a/ui/pages/confirmations/components/confirm/info/__snapshots__/info.test.tsx.snap +++ b/ui/pages/confirmations/components/confirm/info/__snapshots__/info.test.tsx.snap @@ -7,7 +7,7 @@ exports[`Info renders info section for personal sign request 1`] = ` >
renders component for contract interaction >
renders component for contract interaction
renders component for contract interaction >
renders component for contract interaction
renders component for contract interaction >
renders component for contract interaction
renders component for contract interaction >
renders component for contract interaction
renders component for contract interaction >
renders component for contract interaction
renders component for contract interaction >
renders component for contract interaction
does not render component for advanced transaction >
does not render component for advanced transaction >
renders component for advanced transaction details >
renders component for advanced transaction details >
renders component 1`] = `
renders component for gas fees section with advanced
renders component for gas fees section with advanced
renders component for gas fees section with advanced
renders component for gas fees section with advanced
renders component for gas fees section with advanced
renders component 1`] = `
renders component for gas fees section with advanced >
renders component for gas fees section with advanced
renders component for gas fees section with advanced >
renders component for gas fees section with advanced
renders component for gas fees section with advanced
renders component for transaction details 1`] = >
renders component for transaction details 1`] =