Skip to content

Commit 44e0713

Browse files
committed
fix(suite): Fix buy/sell/dca buttons
1 parent aff5a1c commit 44e0713

File tree

3 files changed

+85
-39
lines changed

3 files changed

+85
-39
lines changed

packages/components/src/components/form/SelectBar/SelectBar.stories.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { useArgs } from '@storybook/client-api';
22
import { Meta, StoryObj } from '@storybook/react';
33

4-
import { SelectBar as SelectBarComponent, SelectBarProps } from './SelectBar';
4+
import { fillTypes, SelectBar as SelectBarComponent, SelectBarProps } from './SelectBar';
5+
import { IconName } from '../../Icon/Icon';
56

67
const options = [
78
{ label: 'low', value: 'low' },
89
{ label: 'medium', value: 'medium' },
910
{ label: 'high', value: 'high' },
10-
{ label: 'custom', value: 'custom' },
11+
{ label: 'custom', value: 'custom', icon: 'clock' as IconName },
1112
];
1213

1314
const meta: Meta = {
@@ -18,6 +19,7 @@ const meta: Meta = {
1819
selectedOption: 'low',
1920
isDisabled: false,
2021
isFullWidth: undefined,
22+
fillType: 'default',
2123
},
2224
argTypes: {
2325
label: {
@@ -50,6 +52,12 @@ const meta: Meta = {
5052
type: 'boolean',
5153
},
5254
},
55+
fillType: {
56+
control: {
57+
type: 'radio',
58+
},
59+
options: fillTypes,
60+
},
5361
},
5462
component: SelectBarComponent,
5563
} as unknown as Meta;

packages/components/src/components/form/SelectBar/SelectBar.tsx

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,15 @@ import {
2222
withFrameProps,
2323
} from '../../../utils/frameProps';
2424
import { TransientProps } from '../../../utils/transientProps';
25+
import { Icon, IconName } from '../../Icon/Icon';
26+
import { Row } from '../../Flex/Flex';
2527

2628
export const allowedSelectBarFrameProps = ['margin', 'width'] as const satisfies FramePropsKeys[];
2729
type AllowedFrameProps = Pick<FrameProps, (typeof allowedSelectBarFrameProps)[number]>;
2830

31+
export const fillTypes = ['none', 'default'] as const;
32+
export type FillType = (typeof fillTypes)[number];
33+
2934
const Wrapper = styled.div<TransientProps<AllowedFrameProps> & { $isFullWidth?: boolean }>`
3035
display: flex;
3136
align-items: center;
@@ -63,14 +68,16 @@ const Options = styled.div<{
6368
$optionsCount: number;
6469
$isFullWidth?: boolean;
6570
$elevation: Elevation;
71+
$fillType: FillType;
6672
}>`
6773
position: relative;
6874
display: grid;
6975
grid-auto-columns: ${({ $optionsCount }) => `minmax(${getPuckWidth($optionsCount)}, 1fr)`};
7076
grid-auto-flow: column;
7177
gap: ${spacingsPx.xxs};
7278
padding: ${spacingsPx.xxs};
73-
background: ${mapElevationToBackground};
79+
background: ${({ $fillType, theme, $elevation }) =>
80+
$fillType === 'default' ? mapElevationToBackground({ theme, $elevation }) : undefined};
7481
border-radius: ${borders.radii.full};
7582
width: ${({ $isFullWidth }) => ($isFullWidth ? '100%' : 'auto')};
7683
@@ -156,6 +163,7 @@ type ValueTypes = number | string | boolean;
156163
type Option<V extends ValueTypes> = {
157164
label: ReactNode;
158165
value: V;
166+
icon?: IconName;
159167
};
160168

161169
export type SelectBarProps<V extends ValueTypes> = {
@@ -167,6 +175,7 @@ export type SelectBarProps<V extends ValueTypes> = {
167175
isFullWidth?: boolean;
168176
className?: string;
169177
'data-testid'?: string;
178+
fillType?: FillType;
170179
} & AllowedFrameProps;
171180

172181
// Generic type V is determined by selectedOption/options values
@@ -178,6 +187,7 @@ export const SelectBar = <V extends ValueTypes>({
178187
isDisabled = false,
179188
isFullWidth,
180189
className,
190+
fillType = 'default',
181191
'data-testid': dataTest,
182192
...rest
183193
}: SelectBarProps<V>) => {
@@ -247,6 +257,7 @@ export const SelectBar = <V extends ValueTypes>({
247257
$optionsCount={options.length}
248258
$isFullWidth={isFullWidth}
249259
$elevation={elevation}
260+
$fillType={fillType}
250261
>
251262
<Puck
252263
$optionsCount={options.length}
@@ -256,22 +267,38 @@ export const SelectBar = <V extends ValueTypes>({
256267
onKeyDown={handleKeyboardNav}
257268
/>
258269

259-
{options.map(option => (
260-
<Option
261-
key={String(option.value)}
262-
onClick={handleOptionClick(option)}
263-
$isDisabled={!!isDisabled}
264-
$isSelected={
265-
selectedOptionIn !== undefined
266-
? selectedOptionIn === option.value
267-
: false
268-
}
269-
data-testid={`select-bar/${String(option.value)}`}
270-
>
270+
{options.map(option => {
271+
const content = option.icon ? (
272+
<Row gap={spacings.xs}>
273+
<Icon
274+
name={option.icon}
275+
size="medium"
276+
variant={selectedOptionIn === option.value ? 'primary' : undefined}
277+
/>
278+
<span>{option.label}</span>
279+
</Row>
280+
) : (
271281
<span>{option.label}</span>
272-
<WidthMock>{option.label}</WidthMock>
273-
</Option>
274-
))}
282+
);
283+
284+
return (
285+
<Option
286+
key={String(option.value)}
287+
onClick={handleOptionClick(option)}
288+
$isDisabled={!!isDisabled}
289+
$isSelected={
290+
selectedOptionIn !== undefined
291+
? selectedOptionIn === option.value
292+
: false
293+
}
294+
data-testid={`select-bar/${String(option.value)}`}
295+
>
296+
{content}
297+
298+
<WidthMock>{content}</WidthMock>
299+
</Option>
300+
);
301+
})}
275302
</Options>
276303
</Wrapper>
277304
);
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,34 @@
1-
import { Row } from '@trezor/components';
1+
import { IconName, SelectBar } from '@trezor/components';
2+
import { Route } from '@suite-common/suite-types';
23

3-
import { CoinmarketLayoutNavigationItem } from 'src/views/wallet/coinmarket/common/CoinmarketLayout/CoinmarketLayoutNavigation/CoinmarketLayoutNavigationItem';
4+
import { Translation } from '../../../../../../components/suite';
5+
import { goto } from '../../../../../../actions/suite/routerActions';
6+
import { useDispatch, useSelector } from '../../../../../../hooks/suite';
47

5-
export const CoinmarketLayoutNavigation = () => (
6-
<Row>
7-
<CoinmarketLayoutNavigationItem
8-
route="wallet-coinmarket-buy"
9-
title="TR_NAV_BUY"
10-
icon="plus"
11-
/>
12-
<CoinmarketLayoutNavigationItem
13-
route="wallet-coinmarket-sell"
14-
title="TR_NAV_SELL"
15-
icon="minus"
16-
/>
17-
<CoinmarketLayoutNavigationItem
18-
route="wallet-coinmarket-dca"
19-
title="TR_NAV_DCA"
20-
icon="clock"
21-
/>
22-
</Row>
23-
);
8+
const options = [
9+
{
10+
label: <Translation id="TR_NAV_BUY" />,
11+
value: 'wallet-coinmarket-buy' as Route['name'],
12+
icon: 'plus' as IconName,
13+
},
14+
{
15+
label: <Translation id="TR_NAV_SELL" />,
16+
value: 'wallet-coinmarket-sell' as Route['name'],
17+
icon: 'minus' as IconName,
18+
},
19+
{
20+
label: <Translation id="TR_NAV_DCA" />,
21+
value: 'wallet-coinmarket-dca' as Route['name'],
22+
icon: 'clock' as IconName,
23+
},
24+
];
25+
26+
export const CoinmarketLayoutNavigation = () => {
27+
const dispatch = useDispatch();
28+
const routeName = useSelector(state => state.router.route?.name);
29+
const onChange = (newRoute: Route['name']) => {
30+
dispatch(goto(newRoute));
31+
};
32+
33+
return <SelectBar selectedOption={routeName} options={options} onChange={onChange} />;
34+
};

0 commit comments

Comments
 (0)