1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 19:26:13 +02:00

Add Truncated Definition List (#10292)

This commit is contained in:
Brad Decker 2021-01-28 11:22:37 -06:00 committed by GitHub
parent ecff9dfcb0
commit 471140fdea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 139 additions and 0 deletions

View File

@ -2086,6 +2086,9 @@
"viewAccount": {
"message": "View Account"
},
"viewAllDetails": {
"message": "View all details"
},
"viewContact": {
"message": "View Contact"
},

View File

@ -0,0 +1 @@
export { default } from './truncated-definition-list'

View File

@ -0,0 +1,78 @@
import { pick } from 'lodash'
import React, { useState } from 'react'
import PropTypes from 'prop-types'
import { COLORS, SIZES } from '../../../helpers/constants/design-system'
import Box from '../box'
import Button from '../button'
import DefinitionList from '../definition-list/definition-list'
import Popover from '../popover'
import { useI18nContext } from '../../../hooks/useI18nContext'
export default function TruncatedDefinitionList({
dictionary,
tooltips,
prefaceKeys,
title,
}) {
const [isPopoverOpen, setIsPopoverOpen] = useState(false)
const t = useI18nContext()
return (
<>
<Box
margin={6}
padding={4}
paddingBottom={3}
borderRadius={SIZES.LG}
borderColor={COLORS.UI2}
>
<DefinitionList
dictionary={pick(dictionary, prefaceKeys)}
tooltips={tooltips}
/>
<Button
className="truncated-definition-list__view-more"
type="link"
onClick={() => setIsPopoverOpen(true)}
>
{t('viewAllDetails')}
</Button>
</Box>
{isPopoverOpen && (
<Popover
title={title}
open={isPopoverOpen}
onClose={() => setIsPopoverOpen(false)}
footer={
<>
<div />
<Button
type="primary"
style={{ width: '50%' }}
rounded
onClick={() => setIsPopoverOpen(false)}
>
Close
</Button>
</>
}
>
<Box padding={6} paddingTop={0}>
<DefinitionList
gap={SIZES.MD}
tooltips={tooltips}
dictionary={dictionary}
/>
</Box>
</Popover>
)}
</>
)
}
TruncatedDefinitionList.propTypes = {
dictionary: DefinitionList.propTypes.dictionary,
tooltips: DefinitionList.propTypes.dictionary,
title: PropTypes.string,
prefaceKeys: PropTypes.arrayOf(PropTypes.string),
}

View File

@ -0,0 +1,9 @@
.truncated-definition-list {
&__view-more {
@include H6;
display: inline-block;
padding: 0;
width: auto;
}
}

View File

@ -0,0 +1,47 @@
import React from 'react'
import { object, text } from '@storybook/addon-knobs'
import TruncatedDefinitionList from './truncated-definition-list'
export default {
title: 'Truncated Definition List',
}
const basic = {
term:
'a word or phrase used to describe a thing or to express a concept, especially in a particular kind of language or branch of study.',
definition:
'a statement of the exact meaning of a word, especially in a dictionary.',
dl: 'HTML tag denoting a definition list',
dt: 'HTML tag denoting a definition list term',
dd: 'HTML tag denoting a definition list definition',
}
const advanced = {
'Network Name': 'Ethereum Mainnet',
'Chain ID': '1',
Ticker: 'ETH',
}
const tooltips = {
'Network Name': 'The name that is associated with this network',
'Chain ID': 'The numeric value representing the ID of this network',
Ticker: 'The currency symbol of the primary currency for this network',
}
export const truncatedDefinitionList = () => (
<TruncatedDefinitionList
dictionary={object('dictionary', basic)}
title={text('title', 'Basic definitions')}
prefaceKeys={object('prefaceKeys', ['term', 'definition'])}
/>
)
export const withTooltips = () => (
<TruncatedDefinitionList
dictionary={object('dictionary', advanced)}
title={text('title', 'Network Details')}
tooltips={object('tooltips', tooltips)}
prefaceKeys={object('prefaceKeys', ['Chain ID'])}
/>
)

View File

@ -42,6 +42,7 @@
@import 'toggle-button/index';
@import 'token-balance/index';
@import 'tooltip/index';
@import 'truncated-definition-list/truncated-definition-list';
@import 'typography/typography';
@import 'unit-input/index';
@import 'url-icon/index';