This repository has been archived by the owner on Oct 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ActionButton * Use ActionButton in ActivePools * Use ActionButton in PoolTitle * Fix AssetIcon style to avoid `max-width: 100%` - for img by default, which might troubles layouts (e.g. in PoolTitle)
- Loading branch information
Showing
12 changed files
with
228 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/renderer/components/uielements/button/ActionButton.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { ComponentMeta, StoryFn } from '@storybook/react' | ||
|
||
import { ActionButton as Component, Props } from './ActionButton' | ||
|
||
const Template: StoryFn<Props> = (args) => <Component {...args} /> | ||
export const Default = Template.bind({}) | ||
|
||
const meta: ComponentMeta<typeof Component> = { | ||
title: 'Components/button/ActionButton', | ||
argTypes: { | ||
size: { | ||
control: { | ||
type: 'select', | ||
options: ['small', 'medium', 'normal', 'large'] | ||
} | ||
} | ||
}, | ||
args: { | ||
actions: [ | ||
{ | ||
label: 'swap', | ||
callback: () => { | ||
console.log('swap') | ||
}, | ||
disabled: false | ||
}, | ||
{ | ||
label: 'manage', | ||
callback: () => { | ||
console.log('manage') | ||
}, | ||
disabled: false | ||
}, | ||
{ | ||
label: 'savers', | ||
callback: () => { | ||
console.log('savers') | ||
}, | ||
disabled: true | ||
}, | ||
{ | ||
label: 'send', | ||
callback: () => { | ||
console.log('send') | ||
}, | ||
disabled: false | ||
}, | ||
{ | ||
label: 'deposit', | ||
callback: () => { | ||
console.log('deposit') | ||
}, | ||
disabled: false | ||
}, | ||
{ | ||
label: 'upgrade', | ||
callback: () => { | ||
console.log('upgrade') | ||
}, | ||
disabled: true | ||
} | ||
], | ||
disabled: false, | ||
size: 'normal' | ||
}, | ||
decorators: [ | ||
(Story) => ( | ||
<div className="flex h-full w-full items-center justify-center"> | ||
<Story /> | ||
</div> | ||
) | ||
] | ||
} | ||
|
||
export default meta |
66 changes: 66 additions & 0 deletions
66
src/renderer/components/uielements/button/ActionButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import React from 'react' | ||
|
||
import { Popover } from '@headlessui/react' | ||
import { ChevronDownIcon } from '@heroicons/react/24/outline' | ||
import * as A from 'fp-ts/lib/Array' | ||
import * as FP from 'fp-ts/lib/function' | ||
import { useIntl } from 'react-intl' | ||
|
||
import type { Props as ButtonProps } from './FlatButton' | ||
import { TextButton, FlatButton } from './index' | ||
|
||
export type Action = { label: string; callback: FP.Lazy<void>; disabled?: boolean } | ||
export type Props = Omit<ButtonProps, 'onClick'> & { | ||
actions: Action[] | ||
isTextView?: boolean | ||
} | ||
|
||
export const ActionButton: React.FC<Props> = (props): JSX.Element => { | ||
const { size, actions, isTextView = true, disabled = false } = props | ||
|
||
const intl = useIntl() | ||
|
||
return ( | ||
<Popover className="relative"> | ||
<Popover.Button as="div" className="group"> | ||
{({ open }) => ( | ||
<FlatButton size={size} disabled={disabled}> | ||
<span className={`${isTextView ? 'mr-10px' : 'hidden'}`}> | ||
{intl.formatMessage({ id: 'common.action' })} | ||
</span> | ||
<ChevronDownIcon | ||
className={`ease h-[20px] w-[20px] text-inherit group-hover:rotate-180 ${ | ||
open ? 'rotate-180' : 'rotate-0' | ||
}`} | ||
/> | ||
</FlatButton> | ||
)} | ||
</Popover.Button> | ||
<Popover.Panel className="absolute left-[50%] z-[2000] min-w-[100%] translate-x-[-50%] bg-bg0 shadow-full dark:bg-bg0d dark:shadow-fulld "> | ||
{({ close }) => ( | ||
<div> | ||
{FP.pipe( | ||
actions, | ||
A.mapWithIndex((index, { label, callback, disabled = false }) => ( | ||
<TextButton | ||
className={`w-full hover:bg-bg2 dark:hover:bg-bg2d`} | ||
disabled={disabled} | ||
size={size} | ||
color="neutral" | ||
key={index} | ||
onClick={(event: React.MouseEvent<HTMLElement, MouseEvent>) => { | ||
event.preventDefault() | ||
event.stopPropagation() | ||
callback() | ||
close() | ||
}}> | ||
{label} | ||
</TextButton> | ||
)) | ||
)} | ||
</div> | ||
)} | ||
</Popover.Panel> | ||
</Popover> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.