-
Notifications
You must be signed in to change notification settings - Fork 5.5k
feat: implement market list search #39307
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
6e4ffcd
feat: implement market list search
geositta 8623e11
feat: layout changes to follow mobile design
geositta a814695
fix: use correct styles on max leverage label
geositta 579edf3
feat: introduce stock/comm subfilter
geositta a14bf6e
feat: make perp search global
geositta 6c613b8
fix: rm extra route
geositta cdbbc08
feat: use dropdown for perps sorting
geositta a8ec594
chore: rm duplicate sort market fn
geositta 109b4b2
chore: add labels
geositta c84a73f
chore: add labels and tests
geositta 8967662
chore: use ButtonBase in dropdown and search
geositta 3f89c39
chore: rm polling and refresh
geositta e95ab3d
chore: button style fixes
geositta 0203aa0
chore: replace div with Box in dropdown
geositta c3c06fc
chore: rm unused filter-chips component
geositta f92e982
chore: bug fixes, rm unused code
geositta 2cb8ea9
chore: fix rebase typo
geositta 1084704
chore: fix text color potential bug
geositta 0f0158b
chore: refactor filterByType logic
geositta 9c916c3
chore: fix whitespace potential bug
geositta 74fb958
chore: rm unused market badge component
geositta 9f3c496
fix: add types to tests
geositta 6fccb18
fix: add tests to console baseline config
geositta 1a2a3c4
Fix: a11y navigation for filter dropdown, use ButtonBase for back arrow
geositta ae225af
chore: rm unused hooks
geositta 4e8ffb9
chore: update selected perp test
geositta be9f504
chore: add missing translations
geositta fd3b9de
chore: linting for jsdoc
geositta 4b5551f
feat: use textfieldsearch component
geositta 48a7008
chore: linting
geositta 597b58e
fix: use ml-auto in dropdown
geositta da52964
chore: use existing getChangeColor util
geositta 94ce943
chore: use feature flag for market-list, include test
geositta 8a52a6f
feat: use DS skeleton
geositta e4edf37
Merge branch 'main' into perps/search-market-list
geositta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: use dropdown for perps sorting
- Loading branch information
commit cdbbc085c085a3ede6d530854be45115e7c1451d
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
143 changes: 143 additions & 0 deletions
143
ui/pages/perps/market-list/components/dropdown/dropdown.tsx
This file contains hidden or 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,143 @@ | ||
| import React, { useState, useCallback, useRef, useEffect } from 'react'; | ||
| import { | ||
| Box, | ||
| BoxFlexDirection, | ||
| Text, | ||
| TextVariant, | ||
| TextColor, | ||
| Icon, | ||
| IconName, | ||
| IconSize, | ||
| IconColor, | ||
| ButtonBase, | ||
| ButtonBaseSize, | ||
| } from '@metamask/design-system-react'; | ||
|
|
||
| export type DropdownOption<T extends string> = { | ||
| id: T; | ||
| label: string; | ||
| }; | ||
|
|
||
| export type DropdownProps<T extends string> = { | ||
| /** Available options */ | ||
| options: DropdownOption<T>[]; | ||
| /** Currently selected option ID */ | ||
| selectedId: T; | ||
| /** Callback when selection changes */ | ||
| onChange: (id: T) => void; | ||
| /** Test ID prefix for testing */ | ||
| testId: string; | ||
| }; | ||
|
|
||
| /** | ||
| * Reusable dropdown component styled like PickerNetwork | ||
| * | ||
| * @param props - Component props | ||
| * @param props.options - Available options to display | ||
| * @param props.selectedId - Currently selected option ID | ||
| * @param props.onChange - Callback when selection changes | ||
| * @param props.testId - Test ID prefix for testing | ||
| */ | ||
| export function Dropdown<T extends string>({ | ||
| options, | ||
| selectedId, | ||
| onChange, | ||
| testId, | ||
| }: DropdownProps<T>) { | ||
| const [isOpen, setIsOpen] = useState(false); | ||
| const dropdownRef = useRef<HTMLDivElement>(null); | ||
|
|
||
| const selectedOption = options.find((opt) => opt.id === selectedId); | ||
|
|
||
| // Close dropdown when clicking outside | ||
| useEffect(() => { | ||
| const handleClickOutside = (event: MouseEvent) => { | ||
| if ( | ||
| dropdownRef.current && | ||
| !dropdownRef.current.contains(event.target as Node) | ||
| ) { | ||
| setIsOpen(false); | ||
| } | ||
| }; | ||
|
|
||
| if (isOpen) { | ||
| document.addEventListener('mousedown', handleClickOutside); | ||
| } | ||
|
|
||
| return () => { | ||
| document.removeEventListener('mousedown', handleClickOutside); | ||
| }; | ||
| }, [isOpen]); | ||
|
|
||
| const handleToggle = useCallback(() => { | ||
| setIsOpen((prev) => !prev); | ||
| }, []); | ||
|
|
||
| const handleSelect = useCallback( | ||
| (option: DropdownOption<T>) => { | ||
| onChange(option.id); | ||
| setIsOpen(false); | ||
| }, | ||
| [onChange], | ||
| ); | ||
|
|
||
| return ( | ||
| <div ref={dropdownRef} className="relative"> | ||
| {/* Trigger button styled like PickerNetwork */} | ||
| <ButtonBase | ||
| size={ButtonBaseSize.Sm} | ||
| className="flex items-center justify-start gap-1 rounded-lg bg-background-muted px-3 py-2 hover:bg-hover active:opacity-70" | ||
| onClick={handleToggle} | ||
| data-testid={`${testId}-button`} | ||
| > | ||
| <Text variant={TextVariant.BodySm} color={TextColor.TextDefault}> | ||
| {selectedOption?.label ?? ''} | ||
| </Text> | ||
| <Icon | ||
| name={isOpen ? IconName.ArrowUp : IconName.ArrowDown} | ||
| size={IconSize.Xs} | ||
| color={IconColor.IconAlternative} | ||
| /> | ||
| </ButtonBase> | ||
|
|
||
| {/* Dropdown menu */} | ||
| {isOpen && ( | ||
| <Box | ||
| className="absolute left-0 top-full z-10 mt-1 min-w-[120px] overflow-hidden rounded-lg border border-border-muted bg-background-default shadow-lg" | ||
| flexDirection={BoxFlexDirection.Column} | ||
| data-testid={`${testId}-menu`} | ||
| > | ||
| {options.map((option) => ( | ||
| <button | ||
| key={option.id} | ||
| type="button" | ||
| onClick={() => handleSelect(option)} | ||
| className="flex w-full items-center justify-between px-3 py-2 text-left hover:bg-hover active:bg-pressed" | ||
| data-testid={`${testId}-option-${option.id}`} | ||
| > | ||
| <Text | ||
| variant={TextVariant.BodySm} | ||
| color={ | ||
| option.id === selectedId | ||
| ? TextColor.TextDefault | ||
| : TextColor.TextAlternative | ||
| } | ||
| > | ||
| {option.label} | ||
| </Text> | ||
| {option.id === selectedId && ( | ||
| <Icon | ||
| name={IconName.Check} | ||
| size={IconSize.Sm} | ||
| color={IconColor.PrimaryDefault} | ||
| /> | ||
| )} | ||
| </button> | ||
geositta marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ))} | ||
| </Box> | ||
| )} | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| export default Dropdown; | ||
This file contains hidden or 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,5 @@ | ||
| export { | ||
| Dropdown, | ||
| type DropdownOption, | ||
| type DropdownProps, | ||
| } from './dropdown'; |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.