Skip to content

Commit

Permalink
Merge pull request #261 from 1Hive/details-on-click
Browse files Browse the repository at this point in the history
Details on click
  • Loading branch information
Corantin committed May 6, 2022
2 parents e6f417f + ac2e1c7 commit 214cfc6
Show file tree
Hide file tree
Showing 7 changed files with 245 additions and 149 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TextInput, EthIdenticon, AddressField } from '@1hive/1hive-ui';
import { TextInput, EthIdenticon, TextCopy } from '@1hive/1hive-ui';
import { noop } from 'lodash-es';
import React from 'react';
import styled from 'styled-components';
Expand All @@ -8,20 +8,25 @@ import { FieldInput } from './field-input';

const TextInputStyled = styled(TextInput)`
border-radius: 12px;
width: 100%;
text-overflow: ellipsis;
padding-right: 42px;
`;
const TextCopyStyled = styled(TextCopy)`
margin-left: 1px;
`;

const EthIdenticonStyled = styled(EthIdenticon)`
border-radius: 0 12px 12px 0;
const EthIdenticonStyled = styled(EthIdenticon)<{ isEdit: boolean }>`
border-radius: ${({ isEdit }) => (isEdit ? '0 12px 12px 0' : '4px 0 0 4px')};
padding: 0;
`;

const AddressWrapperStyled = styled.div<{
wide: boolean;
isEdit: boolean;
}>`
align-items: center;
display: flex;
flex-wrap: nowrap;
max-width: 400px;
width: 100%;
Expand Down Expand Up @@ -59,20 +64,34 @@ export function AddressFieldInput({
error,
}: Props) {
const loadableContent = (
<AddressWrapperStyled isEdit={isEdit} wide={wide}>
<AddressWrapperStyled isEdit={isEdit} wide={wide} onClick={(e) => e.stopPropagation()}>
{isEdit ? (
<TextInputStyled
isEdit={isEdit}
wide={wide}
id={id}
value={value}
disabled={!isEdit}
onChange={onChange}
onBlur={onBlur}
adornment={<EthIdenticonStyled address={value} scale={1.66} />}
adornmentPosition="end"
adornment={<EthIdenticonStyled isEdit={isEdit} address={value} scale={1.66} />}
adornmentPosition={isEdit ? 'end' : 'start'}
adornmentSettings={{ padding: 0, width: 36 }}
/>
) : (
<AddressField address={value} wide={wide} autofocus={false} />
<TextCopyStyled
isEdit={isEdit}
wide={wide}
message="Address copied to clipboard"
id={id}
value={value}
disabled={!isEdit}
onChange={onChange}
onBlur={onBlur}
adornment={<EthIdenticonStyled isEdit={isEdit} address={value} scale={1.66} />}
adornmentPosition={isEdit ? 'end' : 'start'}
adornmentSettings={{ padding: 0, width: 36 }}
/>
)}
</AddressWrapperStyled>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ const TokenAmountBadge = React.memo(
return temp;
}, [token, amount, usdValue]);

const onBadgeClick = (event: Event) => {
copyCode(token.token, `${token.symbol} address copied to clipboard`);
event.stopPropagation();
};

return (
<TokenAmountButtonStyled
className={className}
Expand All @@ -127,7 +132,7 @@ const TokenAmountBadge = React.memo(
size="mini"
label={label}
title={`Copy : ${token.token}`}
onClick={() => copyCode(token.token, `${token.symbol} address copied to clipboard`)}
onClick={onBadgeClick}
/>
);
},
Expand Down
87 changes: 54 additions & 33 deletions packages/react-app/src/components/field-input/help-tooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,42 @@
import { Help, useTheme } from '@1hive/1hive-ui';
import { ReactNode, useRef } from 'react';
import { useTheme, Button, IconQuestion, Popover } from '@1hive/1hive-ui';
import { ReactNode, useRef, useState } from 'react';
import { ThemeInterface } from 'src/styles/theme';
import { GUpx } from 'src/utils/style.util';
import styled from 'styled-components';

// #region Styled

const TooltipWrapperStyled = styled.div`
color: #637381;
const HelpWrapperStyled = styled.div`
margin: 0 ${GUpx(1)};
`;

const HelpWrapperStyled = styled.div<{ theme: ThemeInterface }>`
margin-left: ${GUpx(1)};
margin-right: ${GUpx(0.5)};
svg {
color: ${({ theme }) => theme.hint}!important;
}
button:focus::after {
border: none;
const HelpButtonStyled = styled(Button)<{ theme: ThemeInterface }>`
border: none;
background: ${({ theme }) => theme.help};
box-shadow: 0px 0px 7px 1px rgb(0 0 0 / 25%);
width: 16px;
height: 16px;
& > span {
color: ${({ theme }) => theme.helpContent};
width: 14px;
}
`;

const PopoverStyled = styled(Popover)<{ theme: ThemeInterface }>`
box-shadow: 0px 0px 8px 6px rgb(0 0 0 / 25%);
border: none;
`;

const TooltipWrapperStyled = styled.div<{ theme: ThemeInterface }>`
position: relative;
max-width: 400px;
min-width: 160px;
padding: ${GUpx(3)};
background: ${({ theme }) => theme.accent};
color: ${({ theme }) => theme.helpContent};
`;

// #endregion

type Props = {
Expand All @@ -30,32 +46,37 @@ type Props = {

export const HelpTooltip = ({ tooltip, children }: Props) => {
const theme = useTheme();
const wrapperRef = useRef<HTMLDivElement>(null);
const buttonElement = useRef();
const [visible, setVisible] = useState(false);

const handleEnter = () => {
// Simulate help button click
const btn = wrapperRef.current?.getElementsByTagName('button')[0];
btn?.click();
};
const handleLeave = () => {
// Simulate ESC key press
document.dispatchEvent(new KeyboardEvent('keydown', { keyCode: 27 }));
const handleClick = (e: Event) => {
e.stopPropagation();
setVisible(true);
};

return (
<>
<HelpWrapperStyled
<HelpWrapperStyled>
<HelpButtonStyled
onMouseEnter={() => setVisible(true)}
ref={buttonElement}
icon={<IconQuestion />}
mode="normal"
size="mini"
display="icon"
label="Open tooltip"
onClick={handleClick}
theme={theme}
/>
<PopoverStyled
visible={visible}
opener={buttonElement.current}
onClose={() => setVisible(false)}
theme={theme}
onMouseEnter={handleEnter}
onMouseLeave={handleLeave}
ref={wrapperRef}
>
<Help hint="">
<TooltipWrapperStyled color={theme.accentContent}>
{children ?? tooltip}
</TooltipWrapperStyled>
</Help>
</HelpWrapperStyled>
</>
<TooltipWrapperStyled theme={theme} onMouseLeave={() => setVisible(false)}>
{children ?? tooltip}
</TooltipWrapperStyled>
</PopoverStyled>
</HelpWrapperStyled>
);
};
Loading

1 comment on commit 214cfc6

@vercel
Copy link

@vercel vercel bot commented on 214cfc6 May 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

quests – ./

quests.vercel.app
quests-1hive.vercel.app
quests-git-main-1hive.vercel.app

Please sign in to comment.