-
Notifications
You must be signed in to change notification settings - Fork 108
feat: simple ui #2059
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: simple ui #2059
Changes from all commits
2a295e8
9f9ab57
56d2b5d
68a1686
f5fae33
2189d3a
6ab2106
a348603
b157a74
f77aa12
cd20550
5fc105e
dc60a84
be6866b
c92e017
dcb61cf
d7b1995
ef5288b
2bd0c74
d61f23b
3a7003d
64ccd91
a66d875
31eb08f
0efe77d
78d2813
42e2155
8757f9d
6823512
558d0ba
ec4cda2
e3f3c38
5c32311
5f51df4
2bb8b34
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,7 +80,7 @@ export function calculateTradeSummary( | |
|
|
||
| const fieldStates = getTradeFormFieldStates(state, accountData, baseAccount); | ||
|
|
||
| const effectiveTrade = mapValues(fieldStates, (s) => s.effectiveValue) as TradeForm; | ||
| const effectiveTrade = mapValues(fieldStates, (s) => s?.effectiveValue) as TradeForm; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You shouldn't need the |
||
|
|
||
| const options = calculateTradeFormOptions(state.type, fieldStates, baseAccount); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -120,6 +120,8 @@ export type TradeForm = { | |
| // additional triggers | ||
| stopLossOrder: TriggerOrderState | undefined; | ||
| takeProfitOrder: TriggerOrderState | undefined; | ||
|
|
||
| isClosingPosition?: boolean; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand the rationale behind adding this as a type of Can we think of a different way i.e. maybe add to
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can keep it in field but we definitely don't need it in makeVisible right?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since you are using a completely new route i.e. trade-form, we could technically use a new route like close-form and not bother with state either |
||
| }; | ||
|
|
||
| // Define the FieldState type with conditional properties | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| import { forwardRef } from 'react'; | ||
|
|
||
| import { Content, Item, Portal, Root, Separator, Trigger } from '@radix-ui/react-dropdown-menu'; | ||
| import { CaretDownIcon } from '@radix-ui/react-icons'; | ||
| import { Fragment } from 'react/jsx-runtime'; | ||
| import styled from 'styled-components'; | ||
|
|
||
| import { forwardRefFn } from '@/lib/genericFunctionalComponentUtils'; | ||
|
|
||
| import { Button, ButtonProps } from './Button'; | ||
| import { DropdownMenuItem } from './DropdownMenu'; | ||
|
|
||
| type StyleProps = { | ||
| align?: 'center' | 'start' | 'end'; | ||
| side?: 'top' | 'bottom'; | ||
| sideOffset?: number; | ||
| className?: string; | ||
| withPortal?: boolean; | ||
| }; | ||
|
|
||
| export const MobileDropdownMenu = forwardRefFn( | ||
| <T extends string>({ | ||
| className, | ||
| children, | ||
| items, | ||
| slotTop, | ||
| align, | ||
| side, | ||
| sideOffset, | ||
| withPortal = true, | ||
| }: StyleProps & { | ||
| children: React.ReactNode; | ||
| items: DropdownMenuItem<T>[]; | ||
| slotTop?: React.ReactNode; | ||
| }) => { | ||
| const content = ( | ||
| <Content | ||
| align={align} | ||
| side={side} | ||
| sideOffset={sideOffset} | ||
| tw="z-20 w-fit overflow-hidden rounded-[0.5rem] border border-solid border-color-border bg-color-layer-4" | ||
| > | ||
| {slotTop && ( | ||
| <> | ||
| <div tw="px-1 py-0.5">{slotTop}</div> | ||
| <Separator tw="border-b-[length:--border-width] border-b-color-border [border-bottom-style:solid]" /> | ||
| </> | ||
| )} | ||
| {items.map((item, idx) => ( | ||
| <Fragment key={item.value}> | ||
| <Item | ||
| tw="row cursor-pointer select-none justify-between px-1 py-0.75 font-medium-book first:rounded-tl-[0.5rem] first:rounded-tr-[0.5rem] last:rounded-bl-[0.5rem] last:rounded-br-[0.5rem] disabled:cursor-default" | ||
| onSelect={item.onSelect} | ||
| disabled={!item.onSelect} | ||
| css={{ | ||
| ...(item.active ? { backgroundColor: 'var(--color-layer-3)' } : {}), | ||
| cursor: item.onSelect ? 'pointer' : 'not-allowed', | ||
| color: { | ||
| active: 'var(--color-text-0)', | ||
| accent: 'var(--color-accent)', | ||
| create: 'var(--color-green)', | ||
| destroy: 'var(--color-red)', | ||
| none: item.onSelect ? undefined : 'var(--color-text-1)', | ||
| }[item.highlightColor ?? (item.active ? 'active' : 'none')], | ||
| }} | ||
| > | ||
| <span tw="whitespace-nowrap">{item.label}</span> | ||
| {item.icon && <span tw="row ml-1">{item.icon}</span>} | ||
| </Item> | ||
| {idx !== items.length - 1 && ( | ||
| <Separator tw="border-b-[length:--border-width] border-b-color-border [border-bottom-style:solid]" /> | ||
| )} | ||
| </Fragment> | ||
| ))} | ||
| </Content> | ||
| ); | ||
|
|
||
| const dropdownContent = withPortal ? <Portal>{content}</Portal> : content; | ||
|
|
||
| return ( | ||
| <Root> | ||
| <Trigger className={className} asChild> | ||
| {children} | ||
| </Trigger> | ||
|
|
||
| {dropdownContent} | ||
| </Root> | ||
| ); | ||
| } | ||
| ); | ||
|
|
||
| export const DropdownMenuTrigger = forwardRef<HTMLButtonElement | HTMLAnchorElement, ButtonProps>( | ||
| ({ children, ...props }, ref) => ( | ||
| <DropdownMenuButton {...props} ref={ref}> | ||
| {children} <CaretDownIcon /> | ||
| </DropdownMenuButton> | ||
| ) | ||
| ); | ||
|
|
||
| const DropdownMenuButton = styled(Button)` | ||
| display: flex; | ||
| justify-content: space-between; | ||
| align-items: center; | ||
| border-radius: 8px; | ||
| border-width: 1.5px; | ||
| border-color: var(--color-layer-4); | ||
|
|
||
| &[data-state='open'] { | ||
| svg { | ||
| transition: rotate 0.3s var(--ease-out-expo); | ||
| rotate: -0.5turn; | ||
| } | ||
| } | ||
| `; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be fine. but I think we need to have some reasoning or consistency behind assigning z-index to items.