Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ exports[`ConfirmInfo should match snapshot 1`] = `
>
<div
class="mm-box confirm-info-row mm-box--margin-top-2 mm-box--margin-bottom-2 mm-box--padding-right-2 mm-box--padding-left-2 mm-box--display-flex mm-box--flex-direction-row mm-box--flex-wrap-wrap mm-box--justify-content-space-between mm-box--color-text-default mm-box--rounded-lg"
style="overflow-wrap: anywhere; min-height: 24px;"
style="overflow-wrap: anywhere; min-height: 24px; position: relative;"
>
<div
class="mm-box mm-box--display-flex mm-box--flex-direction-row mm-box--justify-content-center mm-box--align-items-center"
Expand Down Expand Up @@ -81,7 +81,7 @@ exports[`ConfirmInfo should match snapshot 1`] = `
/>
<div
class="mm-box confirm-info-row mm-box--margin-top-2 mm-box--margin-bottom-2 mm-box--padding-right-2 mm-box--padding-left-2 mm-box--display-flex mm-box--flex-direction-row mm-box--flex-wrap-wrap mm-box--justify-content-space-between mm-box--color-text-default mm-box--rounded-lg"
style="overflow-wrap: anywhere; min-height: 24px;"
style="overflow-wrap: anywhere; min-height: 24px; position: relative;"
>
<div
class="mm-box mm-box--display-flex mm-box--flex-direction-row mm-box--justify-content-center mm-box--align-items-center"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`CopyIcon should match snapshot 1`] = `
<div>
<span
class="mm-box mm-icon mm-icon--size-sm mm-box--display-inline-block mm-box--color-icon-alternative"
style="mask-image: url('./images/icons/copy.svg'); cursor: pointer; position: absolute; right: 0px; top: 2px;"
/>
</div>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exports[`ConfirmInfoExpandableRow should match snapshot 1`] = `
<div>
<div
class="mm-box confirm-info-row mm-box--margin-top-2 mm-box--margin-bottom-2 mm-box--padding-right-2 mm-box--padding-left-2 mm-box--display-flex mm-box--flex-direction-row mm-box--flex-wrap-wrap mm-box--justify-content-space-between mm-box--color-text-default mm-box--rounded-lg"
style="overflow-wrap: anywhere; min-height: 24px;"
style="overflow-wrap: anywhere; min-height: 24px; position: relative;"
>
<div
class="mm-box mm-box--display-flex mm-box--flex-direction-row mm-box--justify-content-center mm-box--align-items-center"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ConfirmInfoRow should match snapshot 1`] = `
<div>
<div
class="mm-box confirm-info-row mm-box--margin-top-2 mm-box--margin-bottom-2 mm-box--padding-right-2 mm-box--padding-left-2 mm-box--display-flex mm-box--flex-direction-row mm-box--flex-wrap-wrap mm-box--justify-content-space-between mm-box--color-text-default mm-box--rounded-lg"
style="overflow-wrap: anywhere; min-height: 24px; position: relative;"
>
<div
class="mm-box mm-box--display-flex mm-box--flex-direction-row mm-box--justify-content-center mm-box--align-items-center"
>
<p
class="mm-box mm-text mm-text--body-md-medium mm-box--color-inherit"
>
some label
</p>
</div>
<p
class="mm-box mm-text mm-text--body-md mm-box--color-text-default"
>
Some text
</p>
</div>
</div>
`;

exports[`ConfirmInfoRow should match snapshot when copy is enabled 1`] = `
<div>
<div
class="mm-box confirm-info-row mm-box--margin-top-2 mm-box--margin-bottom-2 mm-box--padding-right-5 mm-box--padding-left-2 mm-box--display-flex mm-box--flex-direction-row mm-box--flex-wrap-wrap mm-box--justify-content-space-between mm-box--color-text-default mm-box--rounded-lg"
style="overflow-wrap: anywhere; min-height: 24px; position: relative;"
>
<span
class="mm-box mm-icon mm-icon--size-sm mm-box--display-inline-block mm-box--color-icon-alternative"
style="mask-image: url('./images/icons/copy.svg'); cursor: pointer; position: absolute; right: 0px; top: 2px;"
/>
<div
class="mm-box mm-box--display-flex mm-box--flex-direction-row mm-box--justify-content-center mm-box--align-items-center"
>
<p
class="mm-box mm-text mm-text--body-md-medium mm-box--color-inherit"
>
some label
</p>
</div>
<p
class="mm-box mm-text mm-text--body-md mm-box--color-text-default"
>
Some text
</p>
</div>
</div>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exports[`AlertRow matches snapshot with no alert 1`] = `
<div>
<div
class="mm-box confirm-info-row mm-box--margin-top-2 mm-box--margin-bottom-2 mm-box--padding-right-2 mm-box--padding-left-2 mm-box--display-flex mm-box--flex-direction-row mm-box--flex-wrap-wrap mm-box--justify-content-space-between mm-box--color-text-default mm-box--rounded-lg"
style="overflow-wrap: anywhere; min-height: 24px; background: transparent;"
style="overflow-wrap: anywhere; min-height: 24px; position: relative; background: transparent;"
>
<div
class="mm-box mm-box--display-flex mm-box--flex-direction-row mm-box--justify-content-center mm-box--align-items-center mm-box--color-text-default"
Expand Down
11 changes: 11 additions & 0 deletions ui/components/app/confirm/info/row/copy-icon.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react';
import { render } from '@testing-library/react';

import { CopyIcon } from './copy-icon';

describe('CopyIcon', () => {
it('should match snapshot', () => {
const { container } = render(<CopyIcon copyText="dummy text" />);
expect(container).toMatchSnapshot();
});
});
25 changes: 25 additions & 0 deletions ui/components/app/confirm/info/row/copy-icon.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<Icon
color={IconColor.iconAlternative}
name={copied ? IconName.CopySuccess : IconName.Copy}
size={IconSize.Sm}
style={{ cursor: 'pointer', position: 'absolute', right: 0, top: 2 }}
onClick={handleClick}
/>
);
};
11 changes: 11 additions & 0 deletions ui/components/app/confirm/info/row/row.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,15 @@ DefaultStory.args = {
children: 'Value',
};

export const CopyEnabledStory = (args) => <ConfirmInfoRow {...args} />;

CopyEnabledStory.storyName = 'CopyEnabled';

CopyEnabledStory.args = {
label: 'Key',
children: 'Value',
copyEnabled: true,
copyText: 'Some copy text'
};

export default ConfirmInfoRowStory;
25 changes: 25 additions & 0 deletions ui/components/app/confirm/info/row/row.test.tsx
Original file line number Diff line number Diff line change
@@ -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(
<ConfirmInfoRow label="some label">
<Text>Some text</Text>
</ConfirmInfoRow>,
);
expect(container).toMatchSnapshot();
});

it('should match snapshot when copy is enabled', () => {
const { container } = render(
<ConfirmInfoRow label="some label" copyEnabled copyText="dummy text">
<Text>Some text</Text>
</ConfirmInfoRow>,
);
expect(container).toMatchSnapshot();
});
});
13 changes: 11 additions & 2 deletions ui/components/app/confirm/info/row/row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
TextColor,
TextVariant,
} from '../../../../../helpers/constants/design-system';
import { CopyIcon } from './copy-icon';

export enum ConfirmInfoRowVariant {
Default = 'default',
Expand All @@ -36,6 +37,8 @@ export type ConfirmInfoRowProps = {
style?: React.CSSProperties;
labelChildren?: React.ReactNode;
color?: TextColor;
copyEnabled?: boolean;
copyText?: string;
};

const BACKGROUND_COLORS = {
Expand Down Expand Up @@ -74,6 +77,8 @@ export const ConfirmInfoRow: React.FC<ConfirmInfoRowProps> = ({
style,
labelChildren,
color,
copyEnabled = false,
copyText = undefined,
}) => (
<ConfirmInfoRowContext.Provider value={{ variant }}>
<Box
Expand All @@ -87,14 +92,16 @@ export const ConfirmInfoRow: React.FC<ConfirmInfoRowProps> = ({
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 && <CopyIcon copyText={copyText ?? ''} />}
<Box
display={Display.Flex}
flexDirection={FlexDirection.Row}
Expand Down Expand Up @@ -122,7 +129,9 @@ export const ConfirmInfoRow: React.FC<ConfirmInfoRowProps> = ({
)}
</Box>
{typeof children === 'string' ? (
<Text color={TextColor.inherit}>{children}</Text>
<Text marginRight={copyEnabled ? 3 : 0} color={TextColor.inherit}>
{children}
</Text>
) : (
children
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ exports[`Info renders info section for personal sign request 1`] = `
>
<div
class="mm-box confirm-info-row mm-box--margin-top-2 mm-box--margin-bottom-2 mm-box--padding-right-2 mm-box--padding-left-2 mm-box--display-flex mm-box--flex-direction-row mm-box--flex-wrap-wrap mm-box--justify-content-space-between mm-box--color-text-default mm-box--rounded-lg"
style="overflow-wrap: anywhere; min-height: 24px; background: transparent;"
style="overflow-wrap: anywhere; min-height: 24px; position: relative; background: transparent;"
>
<div
class="mm-box mm-box--display-flex mm-box--flex-direction-row mm-box--justify-content-center mm-box--align-items-center mm-box--color-text-default"
Expand Down Expand Up @@ -49,7 +49,7 @@ exports[`Info renders info section for personal sign request 1`] = `
>
<div
class="mm-box confirm-info-row mm-box--margin-top-2 mm-box--margin-bottom-2 mm-box--padding-right-2 mm-box--padding-left-2 mm-box--display-flex mm-box--flex-direction-row mm-box--flex-wrap-wrap mm-box--justify-content-space-between mm-box--color-text-default mm-box--rounded-lg"
style="overflow-wrap: anywhere; min-height: 24px; background: transparent;"
style="overflow-wrap: anywhere; min-height: 24px; position: relative; background: transparent;"
>
<div
class="mm-box mm-box--display-flex mm-box--flex-direction-row mm-box--justify-content-center mm-box--align-items-center mm-box--color-text-default"
Expand Down Expand Up @@ -82,7 +82,7 @@ exports[`Info renders info section for typed sign request 1`] = `
>
<div
class="mm-box confirm-info-row mm-box--margin-top-2 mm-box--margin-bottom-2 mm-box--padding-right-2 mm-box--padding-left-2 mm-box--display-flex mm-box--flex-direction-row mm-box--flex-wrap-wrap mm-box--justify-content-space-between mm-box--color-text-default mm-box--rounded-lg"
style="overflow-wrap: anywhere; min-height: 24px;"
style="overflow-wrap: anywhere; min-height: 24px; position: relative;"
>
<div
class="mm-box mm-box--display-flex mm-box--flex-direction-row mm-box--justify-content-center mm-box--align-items-center"
Expand Down Expand Up @@ -120,7 +120,7 @@ exports[`Info renders info section for typed sign request 1`] = `
</div>
<div
class="mm-box confirm-info-row mm-box--margin-top-2 mm-box--margin-bottom-2 mm-box--padding-right-2 mm-box--padding-left-2 mm-box--display-flex mm-box--flex-direction-row mm-box--flex-wrap-wrap mm-box--justify-content-space-between mm-box--color-text-default mm-box--rounded-lg"
style="overflow-wrap: anywhere; min-height: 24px;"
style="overflow-wrap: anywhere; min-height: 24px; position: relative;"
>
<div
class="mm-box mm-box--display-flex mm-box--flex-direction-row mm-box--justify-content-center mm-box--align-items-center"
Expand Down Expand Up @@ -195,7 +195,7 @@ exports[`Info renders info section for typed sign request 1`] = `
>
<div
class="mm-box confirm-info-row mm-box--margin-top-2 mm-box--margin-bottom-2 mm-box--padding-right-2 mm-box--padding-left-2 mm-box--display-flex mm-box--flex-direction-row mm-box--flex-wrap-wrap mm-box--justify-content-space-between mm-box--color-text-default mm-box--rounded-lg"
style="overflow-wrap: anywhere; min-height: 24px;"
style="overflow-wrap: anywhere; min-height: 24px; position: relative;"
>
<div
class="mm-box mm-box--display-flex mm-box--flex-direction-row mm-box--justify-content-center mm-box--align-items-center"
Expand All @@ -211,7 +211,7 @@ exports[`Info renders info section for typed sign request 1`] = `
>
<div
class="mm-box confirm-info-row mm-box--margin-top-2 mm-box--margin-bottom-2 mm-box--padding-right-2 mm-box--padding-left-2 mm-box--display-flex mm-box--flex-direction-row mm-box--flex-wrap-wrap mm-box--justify-content-space-between mm-box--color-text-default mm-box--rounded-lg"
style="overflow-wrap: anywhere; min-height: 24px; padding-left: 0px; padding-right: 0px;"
style="overflow-wrap: anywhere; min-height: 24px; position: relative; padding-left: 0px; padding-right: 0px;"
>
<div
class="mm-box mm-box--display-flex mm-box--flex-direction-row mm-box--justify-content-center mm-box--align-items-center"
Expand Down Expand Up @@ -242,7 +242,7 @@ exports[`Info renders info section for typed sign request 1`] = `
>
<div
class="mm-box confirm-info-row mm-box--margin-top-2 mm-box--margin-bottom-2 mm-box--padding-right-2 mm-box--padding-left-2 mm-box--display-flex mm-box--flex-direction-row mm-box--flex-wrap-wrap mm-box--justify-content-space-between mm-box--color-text-default mm-box--rounded-lg"
style="overflow-wrap: anywhere; min-height: 24px; padding-right: 0px;"
style="overflow-wrap: anywhere; min-height: 24px; position: relative; padding-right: 0px;"
>
<div
class="mm-box mm-box--display-flex mm-box--flex-direction-row mm-box--justify-content-center mm-box--align-items-center"
Expand All @@ -258,7 +258,7 @@ exports[`Info renders info section for typed sign request 1`] = `
>
<div
class="mm-box confirm-info-row mm-box--margin-top-2 mm-box--margin-bottom-2 mm-box--padding-right-2 mm-box--padding-left-2 mm-box--display-flex mm-box--flex-direction-row mm-box--flex-wrap-wrap mm-box--justify-content-space-between mm-box--color-text-default mm-box--rounded-lg"
style="overflow-wrap: anywhere; min-height: 24px; padding-right: 0px;"
style="overflow-wrap: anywhere; min-height: 24px; position: relative; padding-right: 0px;"
>
<div
class="mm-box mm-box--display-flex mm-box--flex-direction-row mm-box--justify-content-center mm-box--align-items-center"
Expand All @@ -282,7 +282,7 @@ exports[`Info renders info section for typed sign request 1`] = `
</div>
<div
class="mm-box confirm-info-row mm-box--margin-top-2 mm-box--margin-bottom-2 mm-box--padding-right-2 mm-box--padding-left-2 mm-box--display-flex mm-box--flex-direction-row mm-box--flex-wrap-wrap mm-box--justify-content-space-between mm-box--color-text-default mm-box--rounded-lg"
style="overflow-wrap: anywhere; min-height: 24px; padding-right: 0px;"
style="overflow-wrap: anywhere; min-height: 24px; position: relative; padding-right: 0px;"
>
<div
class="mm-box mm-box--display-flex mm-box--flex-direction-row mm-box--justify-content-center mm-box--align-items-center"
Expand Down Expand Up @@ -355,7 +355,7 @@ exports[`Info renders info section for typed sign request 1`] = `
</div>
<div
class="mm-box confirm-info-row mm-box--margin-top-2 mm-box--margin-bottom-2 mm-box--padding-right-2 mm-box--padding-left-2 mm-box--display-flex mm-box--flex-direction-row mm-box--flex-wrap-wrap mm-box--justify-content-space-between mm-box--color-text-default mm-box--rounded-lg"
style="overflow-wrap: anywhere; min-height: 24px; padding-right: 0px;"
style="overflow-wrap: anywhere; min-height: 24px; position: relative; padding-right: 0px;"
>
<div
class="mm-box mm-box--display-flex mm-box--flex-direction-row mm-box--justify-content-center mm-box--align-items-center"
Expand All @@ -371,7 +371,7 @@ exports[`Info renders info section for typed sign request 1`] = `
>
<div
class="mm-box confirm-info-row mm-box--margin-top-2 mm-box--margin-bottom-2 mm-box--padding-right-2 mm-box--padding-left-2 mm-box--display-flex mm-box--flex-direction-row mm-box--flex-wrap-wrap mm-box--justify-content-space-between mm-box--color-text-default mm-box--rounded-lg"
style="overflow-wrap: anywhere; min-height: 24px; padding-right: 0px;"
style="overflow-wrap: anywhere; min-height: 24px; position: relative; padding-right: 0px;"
>
<div
class="mm-box mm-box--display-flex mm-box--flex-direction-row mm-box--justify-content-center mm-box--align-items-center"
Expand All @@ -395,7 +395,7 @@ exports[`Info renders info section for typed sign request 1`] = `
</div>
<div
class="mm-box confirm-info-row mm-box--margin-top-2 mm-box--margin-bottom-2 mm-box--padding-right-2 mm-box--padding-left-2 mm-box--display-flex mm-box--flex-direction-row mm-box--flex-wrap-wrap mm-box--justify-content-space-between mm-box--color-text-default mm-box--rounded-lg"
style="overflow-wrap: anywhere; min-height: 24px; padding-right: 0px;"
style="overflow-wrap: anywhere; min-height: 24px; position: relative; padding-right: 0px;"
>
<div
class="mm-box mm-box--display-flex mm-box--flex-direction-row mm-box--justify-content-center mm-box--align-items-center"
Expand Down Expand Up @@ -468,7 +468,7 @@ exports[`Info renders info section for typed sign request 1`] = `
</div>
<div
class="mm-box confirm-info-row mm-box--margin-top-2 mm-box--margin-bottom-2 mm-box--padding-right-2 mm-box--padding-left-2 mm-box--display-flex mm-box--flex-direction-row mm-box--flex-wrap-wrap mm-box--justify-content-space-between mm-box--color-text-default mm-box--rounded-lg"
style="overflow-wrap: anywhere; min-height: 24px; padding-right: 0px;"
style="overflow-wrap: anywhere; min-height: 24px; position: relative; padding-right: 0px;"
>
<div
class="mm-box mm-box--display-flex mm-box--flex-direction-row mm-box--justify-content-center mm-box--align-items-center"
Expand Down
Loading