Skip to content
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

feat: simple key-> value component for text value type #11497

Merged
merged 6 commits into from
Oct 2, 2024
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
1 change: 1 addition & 0 deletions .storybook/storybook.requires.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ const getStories = () => {
"./app/component-library/base-components/TagBase/TagBase.stories.tsx": require("../app/component-library/base-components/TagBase/TagBase.stories.tsx"),
"./app/component-library/components-temp/TagColored/TagColored.stories.tsx": require("../app/component-library/components-temp/TagColored/TagColored.stories.tsx"),
"./app/component-library/components-temp/KeyValueRow/KeyValueRow.stories.tsx": require("../app/component-library/components-temp/KeyValueRow/KeyValueRow.stories.tsx"),
"./app/components/UI/InfoRow/InfoRow.stories.tsx": require("../app/components/UI/InfoRow/InfoRow.stories.tsx"),
};
};

Expand Down
30 changes: 30 additions & 0 deletions app/components/UI/InfoRow/InfoRow.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from 'react';
import { storiesOf } from '@storybook/react-native';
import { StyleProp, Text, TextStyle, View } from 'react-native';

import InfoRow from './InfoRow';
import InfoSection from './InfoSection';

const style = {
container: { padding: 8 },
title: { marginTop: 20, fontSize: 20, fontWeight: '700' },
};

storiesOf('App Components / InfoRow', module)
.addDecorator((getStory) => getStory())
.add('Default', () => (
<View style={style.container}>
<Text style={style.title as StyleProp<TextStyle>}>Simple Info Row</Text>
<InfoSection>
<InfoRow label="label-Key">Value-Text</InfoRow>
</InfoSection>
<Text style={style.title as StyleProp<TextStyle>}>Value wrapped</Text>
<InfoSection>
<InfoRow label="label-Key">
Value-Text Value-Text Value-Text Value-Text Value-Text Value-Text
Value-Text Value-Text Value-Text Value-Text Value-Text Value-Text
Value-Text Value-Text Value-Text Value-Text
</InfoRow>
</InfoSection>
</View>
));
11 changes: 11 additions & 0 deletions app/components/UI/InfoRow/InfoRow.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-native';

import InfoRow from './index';

describe('InfoRow', () => {
it('should match snapshot for simple text value', async () => {
const container = render(<InfoRow label="label-Key">Value-Text</InfoRow>);
expect(container).toMatchSnapshot();
});
});
30 changes: 30 additions & 0 deletions app/components/UI/InfoRow/InfoRow.tsx
jpuri marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from 'react';
import { Text, View } from 'react-native';

import { useTheme } from '../../../util/theme';
import createStyles from './style';

interface InfoRowProps {
label: string;
children: React.ReactNode | string;
jpuri marked this conversation as resolved.
Show resolved Hide resolved
tooltip?: string;
jpuri marked this conversation as resolved.
Show resolved Hide resolved
}

const InfoRow = ({ label, children }: InfoRowProps) => {
const { colors } = useTheme();

const styles = createStyles(colors);

return (
<View style={styles.container}>
<Text style={styles.label}>{label}</Text>
{typeof children === 'string' ? (
<Text style={styles.value}>{children}</Text>
) : (
children
)}
</View>
);
};

export default InfoRow;
18 changes: 18 additions & 0 deletions app/components/UI/InfoRow/InfoSection/InfoSection.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';
import { Text, View } from 'react-native';
import { render } from '@testing-library/react-native';

import InfoSection from './index';

describe('InfoSection', () => {
it('should match snapshot for simple text value', async () => {
const container = render(
<InfoSection>
<View>
<Text>Test</Text>
</View>
</InfoSection>,
);
expect(container).toMatchSnapshot();
});
});
18 changes: 18 additions & 0 deletions app/components/UI/InfoRow/InfoSection/InfoSection.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';
import { View } from 'react-native';

import { useTheme } from '../../../../util/theme';
import createStyles from './style';

interface InfoSectionProps {
children: React.ReactNode | string;
}

const InfoSection = ({ children }: InfoSectionProps) => {
const { colors } = useTheme();
const styles = createStyles(colors);

return <View style={styles.container}>{children}</View>;
};

export default InfoSection;
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`InfoSection should match snapshot for simple text value 1`] = `
<View
style={
{
"backgroundColor": "#ffffff",
"borderColor": "#bbc0c566",
"borderRadius": 8,
"borderWidth": 1,
"padding": 8,
}
}
>
<View>
<Text>
Test
</Text>
</View>
</View>
`;
1 change: 1 addition & 0 deletions app/components/UI/InfoRow/InfoSection/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './InfoSection';
16 changes: 16 additions & 0 deletions app/components/UI/InfoRow/InfoSection/style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { StyleSheet } from 'react-native';

import { Colors } from '../../../../util/theme/models';

const createStyles = (colors: Colors) =>
StyleSheet.create({
container: {
backgroundColor: colors.background.default,
borderColor: colors.border.muted,
borderRadius: 8,
borderWidth: 1,
padding: 8,
},
});

export default createStyles;
43 changes: 43 additions & 0 deletions app/components/UI/InfoRow/__snapshots__/InfoRow.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`InfoRow should match snapshot for simple text value 1`] = `
<View
style={
{
"display": "flex",
"flexDirection": "row",
"flexWrap": "wrap",
"justifyContent": "space-between",
"paddingBottom": 8,
"paddingHorizontal": 8,
}
}
>
<Text
style={
{
"color": "#141618",
"fontFamily": "EuclidCircularB-Bold",
"fontSize": 14,
"fontWeight": "500",
"marginTop": 8,
}
}
>
label-Key
</Text>
<Text
style={
{
"color": "#141618",
"fontFamily": "EuclidCircularB-Regular",
"fontSize": 14,
"fontWeight": "400",
"marginTop": 8,
}
}
>
Value-Text
</Text>
</View>
`;
1 change: 1 addition & 0 deletions app/components/UI/InfoRow/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './InfoRow';
31 changes: 31 additions & 0 deletions app/components/UI/InfoRow/style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { StyleSheet } from 'react-native';

import { Colors } from '../../../util/theme/models';
import { fontStyles } from '../../../styles/common';

const createStyles = (colors: Colors) =>
StyleSheet.create({
container: {
display: 'flex',
flexDirection: 'row',
justifyContent: 'space-between',
flexWrap: 'wrap',
paddingBottom: 8,
paddingHorizontal: 8,
},
label: {
color: colors.text.default,
...fontStyles.bold,
fontSize: 14,
fontWeight: '500',
marginTop: 8,
},
value: {
color: colors.text.default,
...fontStyles.normal,
fontSize: 14,
marginTop: 8,
}
});

export default createStyles;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useMemo } from 'react';
import React from 'react';
import { Text, View } from 'react-native';
import { TransactionType } from '@metamask/transaction-controller';

Expand All @@ -20,11 +20,8 @@ const Title = () => {
const { approvalRequest } = useApprovalRequest();
const { colors } = useTheme();

const title = getTitle(approvalRequest?.type);
const styles = createStyles(colors);
const title = useMemo(
() => getTitle(approvalRequest?.type),
[approvalRequest?.type],
);

jpuri marked this conversation as resolved.
Show resolved Hide resolved
return (
<View style={styles.titleContainer}>
Expand Down
Loading