-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add: currency-dropdown ui/components and icons
- Loading branch information
1 parent
365a111
commit cb101d8
Showing
6 changed files
with
109 additions
and
2 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
libs/features/settings/src/lib/GlobalSettings/CurrencyDropdownClient.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
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
38 changes: 38 additions & 0 deletions
38
libs/ui/components/src/lib/currency-dropdown/CurrencyDropdown.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,38 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
import { screen, userEvent } from '@storybook/testing-library'; | ||
import { CurrencyDropdown } from './CurrencyDropdown'; | ||
import { CurrencyDropdownExample, currencyItems } from './examples'; | ||
|
||
const helperText = 'Select a language'; | ||
|
||
const meta = { | ||
title: 'Molecules/CurrencyDropdown', | ||
component: CurrencyDropdown, | ||
render: CurrencyDropdownExample, | ||
args: { | ||
items: currencyItems, | ||
helperText, | ||
}, | ||
} satisfies Meta<typeof CurrencyDropdown>; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Default: Story = { | ||
play: async ({ canvasElement }) => { | ||
const button = screen.getByRole('button'); | ||
await userEvent.hover(button); | ||
// Check that the helper text is present | ||
await screen.findByText((content, element) => { | ||
return ( | ||
element?.getAttribute('data-state') === 'delayed-open' && | ||
content.includes(helperText) | ||
); | ||
}); | ||
await userEvent.click(button); | ||
// Check that the language items are present | ||
await screen.findByText('EUR'); | ||
await screen.findByText('USD'); | ||
}, | ||
}; |
33 changes: 33 additions & 0 deletions
33
libs/ui/components/src/lib/currency-dropdown/CurrencyDropdown.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,33 @@ | ||
import { Button, ButtonProps } from '../button/Button'; | ||
import { | ||
DropdownMenu, | ||
DropdownMenuTrigger, | ||
} from '../dropdown-menu/DropdownMenu'; | ||
import { | ||
DropdownMenuItems, | ||
DropdownMenuItemsProps, | ||
} from '../dropdown-menu/DropdownMenuItems'; | ||
|
||
import { CurrencySettings } from '@ui/icons'; | ||
|
||
export interface CurrencyDropdownProps | ||
extends DropdownMenuItemsProps, | ||
ButtonProps {} | ||
|
||
export function CurrencyDropdown({ items, ...props }: CurrencyDropdownProps) { | ||
return ( | ||
<DropdownMenu> | ||
<DropdownMenuTrigger asChild> | ||
<Button | ||
variant="outline" | ||
aria-label={props.helperText as string} | ||
icon={<CurrencySettings />} | ||
{...props} | ||
/> | ||
</DropdownMenuTrigger> | ||
<DropdownMenuItems items={items} className="w-auto" /> | ||
</DropdownMenu> | ||
); | ||
} | ||
|
||
export default CurrencyDropdown; |
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,23 @@ | ||
import { Check } from '@ui/icons'; | ||
import { CurrencyDropdown, CurrencyDropdownProps } from './CurrencyDropdown'; | ||
|
||
export const currencyItems: CurrencyDropdownProps['items'] = [ | ||
{ | ||
type: 'item', | ||
text: 'EUR', | ||
icon: <Check />, | ||
disabled: true, | ||
}, | ||
{ | ||
type: 'item', | ||
text: 'USD', | ||
}, | ||
]; | ||
|
||
export function CurrencyDropdownExample(props: CurrencyDropdownProps) { | ||
return ( | ||
<div className="flex"> | ||
<CurrencyDropdown {...props} /> | ||
</div> | ||
); | ||
} |
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