-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
57 additions
and
57 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Button } from '@hyperlane-xyz/widgets'; | ||
import clsx from 'clsx'; | ||
import { ComponentProps } from 'react'; | ||
|
||
export function FormButton({ className, ...props }: ComponentProps<typeof Button>) { | ||
return ( | ||
<Button | ||
className={clsx( | ||
'flex items-center justify-between rounded-lg border border-primary-300 px-2 py-1.5 text-sm', | ||
className, | ||
)} | ||
{...props} | ||
/> | ||
); | ||
} |
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 |
---|---|---|
@@ -1,67 +1,34 @@ | ||
import { ChainSearchMenuProps, ChevronIcon } from '@hyperlane-xyz/widgets'; | ||
import { useField } from 'formik'; | ||
import { useState } from 'react'; | ||
import { ChevronIcon, useModal } from '@hyperlane-xyz/widgets'; | ||
import { FormButton } from '../../components/buttons/FormButton'; | ||
import { ChainLogo } from '../../components/icons/ChainLogo'; | ||
import { ChainSelectListModal } from './ChainSelectModal'; | ||
import { useChainDisplayName } from './hooks'; | ||
|
||
type Props = { | ||
name: string; | ||
label: string; | ||
onChange?: (id: ChainName) => void; | ||
disabled?: boolean; | ||
customListItemField?: ChainSearchMenuProps['customListItemField']; | ||
value: ChainName; | ||
onChange: (chain: ChainName) => void; | ||
}; | ||
|
||
export function ChainSelectField({ name, label, onChange, disabled, customListItemField }: Props) { | ||
const [field, , helpers] = useField<ChainName>(name); | ||
export function ChainSelectField({ value, onChange }: Props) { | ||
const displayName = useChainDisplayName(value, true); | ||
|
||
const displayName = useChainDisplayName(field.value, true); | ||
|
||
const handleChange = (chainName: ChainName) => { | ||
helpers.setValue(chainName); | ||
if (onChange) onChange(chainName); | ||
}; | ||
|
||
const [isModalOpen, setIsModalOpen] = useState(false); | ||
|
||
const onClick = () => { | ||
if (!disabled) setIsModalOpen(true); | ||
}; | ||
const { isOpen, close, open } = useModal(); | ||
|
||
return ( | ||
<div className="flex-[4]"> | ||
<button | ||
type="button" | ||
name={field.name} | ||
className={`${styles.base} ${disabled ? styles.disabled : styles.enabled}`} | ||
onClick={onClick} | ||
> | ||
<div> | ||
<FormButton onClick={open}> | ||
<div className="flex items-center gap-3"> | ||
<div className="max-w-[1.4rem] sm:max-w-fit"> | ||
<ChainLogo chainName={field.value} size={32} /> | ||
<ChainLogo chainName={value} size={32} /> | ||
</div> | ||
<div className="flex flex-col items-start gap-1"> | ||
<label htmlFor={name} className="text-xs text-gray-600"> | ||
{label} | ||
</label> | ||
<div className="gap- flex flex-col items-start"> | ||
<label className="text-xs text-gray-600">Chain</label> | ||
{displayName} | ||
</div> | ||
</div> | ||
<ChevronIcon width={12} height={8} direction="s" /> | ||
</button> | ||
<ChainSelectListModal | ||
isOpen={isModalOpen} | ||
close={() => setIsModalOpen(false)} | ||
onSelect={handleChange} | ||
customListItemField={customListItemField} | ||
/> | ||
</FormButton> | ||
<ChainSelectListModal isOpen={isOpen} close={close} onSelect={onChange} /> | ||
</div> | ||
); | ||
} | ||
|
||
const styles = { | ||
base: 'px-2 py-1.5 w-full flex items-center justify-between text-sm bg-white rounded-lg border border-primary-300 outline-none transition-colors duration-500', | ||
enabled: 'hover:bg-gray-100 active:scale-95 focus:border-primary-500', | ||
disabled: 'bg-gray-150 cursor-default', | ||
}; |
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