Skip to content

Commit

Permalink
Update Select component (#1799)
Browse files Browse the repository at this point in the history
  • Loading branch information
grod220 authored Sep 20, 2024
1 parent e3d0ac3 commit f3500b8
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 48 deletions.
26 changes: 12 additions & 14 deletions apps/minifront/src/components/ibc/ibc-in/ibc-in-request.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,21 @@ export const IbcInRequest = () => {
)}
<div className='flex w-full gap-2'>
<Select onValueChange={v => setCoin(data.find(b => b.displayDenom === v))}>
<SelectTrigger className='truncate rounded-lg bg-white p-2' variant='light'>
<SelectTrigger className='truncate rounded-lg p-2' variant='light'>
<SelectValue placeholder='Select Asset' />
</SelectTrigger>
<SelectContent className='max-w-52 bg-white text-stone-700'>
{data.map(b => {
return (
<SelectItem value={b.displayDenom} key={b.displayDenom} className='p-2'>
<div className='flex gap-2 text-stone-700'>
<Avatar className='size-6'>
<AvatarImage src={getIconWithUmFallback(b)} />
<Identicon uniqueIdentifier={b.displayDenom} type='gradient' size={22} />
</Avatar>
<span className=''>{b.displayDenom}</span>
</div>
</SelectItem>
);
})}
{data.map(b => (
<SelectItem value={b.displayDenom} key={b.displayDenom}>
<div className='flex items-center gap-2 text-stone-700'>
<Avatar className='size-6'>
<AvatarImage src={getIconWithUmFallback(b)} />
<Identicon uniqueIdentifier={b.displayDenom} type='gradient' size={22} />
</Avatar>
<span className=''>{b.displayDenom}</span>
</div>
</SelectItem>
))}
</SelectContent>
</Select>
<AmountInput />
Expand Down
8 changes: 2 additions & 6 deletions apps/minifront/src/components/ibc/ibc-out/chain-selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
SelectValue,
} from '@penumbra-zone/ui/components/ui/select';
import { cn } from '@penumbra-zone/ui/lib/utils';
import { useState } from 'react';
import { AllSlices } from '../../../state';
import { Chain } from '@penumbra-labs/registry';
import { useStoreShallow } from '../../../utils/use-store-shallow';
Expand All @@ -20,18 +19,15 @@ const chainSelectorSelector = (state: AllSlices) => ({
export const ChainSelector = () => {
const { chain, setChain } = useStoreShallow(chainSelectorSelector);
const chains = useChains();
const [openSelect, setOpenSelect] = useState(false);

return (
<div className='flex flex-col gap-3 rounded-lg border bg-background px-4 pb-5 pt-3'>
<p className='text-base font-bold'>Chain</p>
<Select
value={chain?.displayName ?? ''}
onValueChange={v => setChain(chains.data?.find(i => i.displayName === v))}
open={openSelect}
onOpenChange={open => setOpenSelect(open)}
>
<SelectTrigger open={openSelect}>
<SelectTrigger className='border-none'>
<SelectValue placeholder='Select chain'>
{chain && (
<div className='flex gap-2'>
Expand All @@ -41,7 +37,7 @@ export const ChainSelector = () => {
)}
</SelectValue>
</SelectTrigger>
<SelectContent className='left-[-17px]'>
<SelectContent>
{chains.data?.map((i, index) => (
<SelectItem
key={index}
Expand Down
1 change: 0 additions & 1 deletion packages/ui/components/ui/select/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export {
SelectSeparator,
SelectTrigger,
SelectValue,
type SelectTriggerProps,
} from './select';
export { SelectAccount, type SelectAccountProps } from './select-account';
export { SelectList } from './select-list';
61 changes: 43 additions & 18 deletions packages/ui/components/ui/select/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

import * as React from 'react';
import * as SelectPrimitive from '@radix-ui/react-select';
import { cn } from '../../../lib/utils';
import { ChevronDownIcon } from '@radix-ui/react-icons';
import { cva, type VariantProps } from 'class-variance-authority';
import { ChevronDown, ChevronUp } from 'lucide-react';
import { cn } from '../../../lib/utils.ts';
import { cva, VariantProps } from 'class-variance-authority';

const selectVariants = cva('', {
variants: {
variant: {
dark: 'text-muted',
light: 'text-stone-700',
dark: 'bg-background text-muted',
light: 'bg-white text-stone-700',
},
},
defaultVariants: {
Expand All @@ -27,37 +27,58 @@ const SelectValue = SelectPrimitive.Value;
export interface SelectTriggerProps
extends React.ComponentPropsWithoutRef<typeof SelectPrimitive.Trigger>,
VariantProps<typeof selectVariants> {
open?: boolean;
textColor?: string;
}

const SelectTrigger = React.forwardRef<
React.ElementRef<typeof SelectPrimitive.Trigger>,
SelectTriggerProps
>(({ className, children, open, variant, ...props }, ref) => (
>(({ className, children, variant, ...props }, ref) => (
<SelectPrimitive.Trigger
ref={ref}
className={cn(
'flex w-full items-center justify-between bg-background ring-offset-background focus:outline-none focus:ring-0 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 text-[15px] leading-[22px] font-bold text-light-brown',
'flex h-10 w-full items-center justify-between rounded-md border border-input px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1',
selectVariants({ variant }),
className,
)}
{...props}
>
{children}
<SelectPrimitive.Icon asChild>
<ChevronDownIcon
className={cn(
'h-6 w-6 transition-all duration-500',
open && 'rotate-180',
selectVariants({ variant }),
)}
/>
<ChevronDown className='size-4 opacity-50' />
</SelectPrimitive.Icon>
</SelectPrimitive.Trigger>
));
SelectTrigger.displayName = SelectPrimitive.Trigger.displayName;

const SelectScrollUpButton = React.forwardRef<
React.ElementRef<typeof SelectPrimitive.ScrollUpButton>,
React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollUpButton>
>(({ className, ...props }, ref) => (
<SelectPrimitive.ScrollUpButton
ref={ref}
className={cn('flex cursor-default items-center justify-center py-1', className)}
{...props}
>
<ChevronUp className='size-4' />
</SelectPrimitive.ScrollUpButton>
));
SelectScrollUpButton.displayName = SelectPrimitive.ScrollUpButton.displayName;

const SelectScrollDownButton = React.forwardRef<
React.ElementRef<typeof SelectPrimitive.ScrollDownButton>,
React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollDownButton>
>(({ className, ...props }, ref) => (
<SelectPrimitive.ScrollDownButton
ref={ref}
className={cn('flex cursor-default items-center justify-center py-1', className)}
{...props}
>
<ChevronDown className='size-4' />
</SelectPrimitive.ScrollDownButton>
));
SelectScrollDownButton.displayName = SelectPrimitive.ScrollDownButton.displayName;

const SelectContent = React.forwardRef<
React.ElementRef<typeof SelectPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Content>
Expand All @@ -66,23 +87,25 @@ const SelectContent = React.forwardRef<
<SelectPrimitive.Content
ref={ref}
className={cn(
'relative z-50 border border-t-0 overflow-hidden rounded-b-md bg-background text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 px-4',
'relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-background text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2',
position === 'popper' &&
'data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1',
className,
)}
position={position}
{...props}
>
<SelectScrollUpButton />
<SelectPrimitive.Viewport
className={cn(
'',
'p-1',
position === 'popper' &&
'h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]',
)}
>
{children}
</SelectPrimitive.Viewport>
<SelectScrollDownButton />
</SelectPrimitive.Content>
</SelectPrimitive.Portal>
));
Expand All @@ -107,7 +130,7 @@ const SelectItem = React.forwardRef<
<SelectPrimitive.Item
ref={ref}
className={cn(
'relative flex w-full select-none items-center font-bold text-muted-foreground outline-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 cursor-pointer py-[10px]',
'relative flex w-full cursor-default select-none items-center text-muted-foreground rounded-sm py-1.5 px-2 text-sm outline-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50',
className,
)}
{...props}
Expand Down Expand Up @@ -138,4 +161,6 @@ export {
SelectLabel,
SelectItem,
SelectSeparator,
SelectScrollUpButton,
SelectScrollDownButton,
};
2 changes: 1 addition & 1 deletion packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"@radix-ui/react-popover": "^1.0.7",
"@radix-ui/react-progress": "^1.0.3",
"@radix-ui/react-radio-group": "^1.2.0",
"@radix-ui/react-select": "^2.0.0",
"@radix-ui/react-select": "^2.1.1",
"@radix-ui/react-slider": "^1.1.2",
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-switch": "^1.0.3",
Expand Down
16 changes: 8 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f3500b8

Please sign in to comment.