Skip to content

Commit cd4b474

Browse files
committed
feat: add mobile styles to contract pages
1 parent 8b04a32 commit cd4b474

File tree

6 files changed

+62
-16
lines changed

6 files changed

+62
-16
lines changed

templates/chain-template/components/contract/MyContractsTab.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ export const MyContractsTab = ({ show, switchTab }: MyContractsTabProps) => {
3737
) : myContracts.length === 0 ? (
3838
<EmptyState text="No contracts found" />
3939
) : (
40-
<Box width="$full" alignSelf="start">
41-
<Table>
40+
<Box width="$full" alignSelf="start" overflowX="auto">
41+
<Table minWidth="650px">
4242
<Table.Header>
4343
<Table.Row height="$fit">
4444
<Table.HeaderCell width="15%">

templates/chain-template/components/contract/SelectAssetItem.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import {
1010
PopoverTrigger,
1111
SelectButton,
1212
Text,
13+
useColorModeValue,
14+
useTheme,
1315
} from '@interchain-ui/react';
1416

1517
import { Button } from '@/components';
@@ -69,6 +71,7 @@ export const SelectAssetItem = ({
6971
});
7072
};
7173

74+
const { theme } = useTheme();
7275
const { isMobile } = useDetectBreakpoints();
7376

7477
return (
@@ -104,9 +107,11 @@ export const SelectAssetItem = ({
104107
flexDirection="column"
105108
width="140px"
106109
py="10px"
107-
bg="$white"
110+
bg="$background"
108111
borderRadius="4px"
109-
boxShadow="0px 4px 20px 0px rgba(0, 0, 0, 0.1)"
112+
boxShadow={`0px 4px 20px 0px rgba(${
113+
theme === 'light' ? '0,0,0' : '128,128,128'
114+
}, 0.1)`}
110115
maxHeight="220px"
111116
overflowY="auto"
112117
>
@@ -158,6 +163,7 @@ const AssetOption = ({
158163
disabled: boolean;
159164
onClick: () => void;
160165
}) => {
166+
const hoverBg = useColorModeValue('$blackAlpha100', '$whiteAlpha100');
161167
return (
162168
<Box
163169
display="flex"
@@ -168,8 +174,8 @@ const AssetOption = ({
168174
cursor={disabled ? 'default' : 'pointer'}
169175
opacity={disabled ? 0.3 : 1}
170176
bg={{
171-
hover: disabled ? '$white' : '$blackAlpha100',
172-
base: '$white',
177+
hover: disabled ? '$background' : hoverBg,
178+
base: '$background',
173179
}}
174180
attributes={{ onClick: disabled ? undefined : onClick }}
175181
>

templates/chain-template/components/contract/SelectCodeModal.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
} from '@/utils';
1414
import { PermissionValue, StoredCodesFilter } from './StoredCodesFilter';
1515
import { EmptyState } from './EmptyState';
16+
import styles from '@/styles/comp.module.css';
1617

1718
type SelectCodeModalProps = {
1819
isOpen: boolean;
@@ -52,14 +53,16 @@ export const SelectCodeModal = ({
5253
setPermissionValue('all');
5354
}}
5455
renderCloseButton={() => null}
56+
modalContentClassName={styles.modal}
5557
>
5658
<CustomThemeProvider>
5759
<Box
5860
display="flex"
5961
flexDirection="column"
6062
gap="20px"
61-
width="760px"
62-
px="10px"
63+
width="90vw"
64+
maxWidth="760px"
65+
p="30px"
6366
pt="20px"
6467
>
6568
<Box display="flex" alignItems="center" mb="10px">
@@ -103,8 +106,8 @@ export const SelectCodeModal = ({
103106
) : filteredCodes.length === 0 ? (
104107
<EmptyState text="No matched codes found" />
105108
) : (
106-
<Box width="$full" alignSelf="start">
107-
<Table>
109+
<Box width="$full" alignSelf="start" overflowX="auto">
110+
<Table minWidth="550px">
108111
<Table.Header>
109112
<Table.Row height="$fit">
110113
<Table.HeaderCell width="10%">Code</Table.HeaderCell>

templates/chain-template/components/contract/StoredCodesFilter.tsx

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState } from 'react';
1+
import { useEffect, useState } from 'react';
22
import {
33
Box,
44
Popover,
@@ -35,6 +35,8 @@ export const permissionOptions: PermissionOption[] = [
3535
},
3636
];
3737

38+
const FLEX_GAP = 20;
39+
3840
type StoredCodesFilterProps = {
3941
searchValue: string;
4042
setSearchValue: (value: string) => void;
@@ -50,16 +52,39 @@ export const StoredCodesFilter = ({
5052
}: StoredCodesFilterProps) => {
5153
const [elemRef, setElemRef] = useState<HTMLDivElement>();
5254
const [isPopoverOpen, setIsPopoverOpen] = useState(false);
55+
const [elemWidth, setElemWidth] = useState(0);
5356

5457
const { theme } = useTheme();
5558
const { isMobile } = useDetectBreakpoints();
5659

60+
useEffect(() => {
61+
const handleResize = () => {
62+
if (elemRef) {
63+
const width = isMobile
64+
? elemRef.offsetWidth
65+
: (elemRef.offsetWidth - FLEX_GAP) / 2;
66+
setElemWidth(width);
67+
}
68+
};
69+
70+
handleResize();
71+
window.addEventListener('resize', handleResize);
72+
73+
return () => window.removeEventListener('resize', handleResize);
74+
}, [elemRef, isMobile]);
75+
5776
const permissionOption = permissionOptions.find(
5877
(p) => p.value === permissionValue
5978
)!;
6079

6180
return (
62-
<Box display="flex" justifyContent="space-between" gap="20px">
81+
<Box
82+
ref={setElemRef}
83+
display="flex"
84+
flexDirection={isMobile ? 'column' : 'row'}
85+
justifyContent="space-between"
86+
gap={`${FLEX_GAP}px`}
87+
>
6388
<Box flex={1}>
6489
<Text fontSize="16px" fontWeight="600" attributes={{ mb: '10px' }}>
6590
Search
@@ -72,7 +97,7 @@ export const StoredCodesFilter = ({
7297
autoComplete="off"
7398
/>
7499
</Box>
75-
<Box flex={1} ref={setElemRef}>
100+
<Box flex={1}>
76101
<Text fontSize="16px" fontWeight="600" attributes={{ mb: '10px' }}>
77102
Filter by Instantiate Permission
78103
</Text>
@@ -89,14 +114,14 @@ export const StoredCodesFilter = ({
89114
<SelectButton
90115
onClick={() => {}}
91116
placeholder={permissionOption.label}
92-
_css={{ width: `${elemRef?.offsetWidth}px` }}
117+
attributes={{ width: `${elemWidth}px` }}
93118
/>
94119
</PopoverTrigger>
95120
<PopoverContent showArrow={false}>
96121
<Box
97122
display="flex"
98123
flexDirection="column"
99-
width={`${elemRef?.offsetWidth}px`}
124+
width={`${elemWidth}px`}
100125
py="10px"
101126
bg="$background"
102127
borderRadius="4px"

templates/chain-template/pages/contract.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
UploadTab,
1111
} from '@/components';
1212
import { splitCamelCase } from '@/utils';
13+
import styles from '@/styles/comp.module.css';
1314

1415
export enum TabLabel {
1516
MyContracts,
@@ -47,7 +48,7 @@ export default function Contract() {
4748
}))}
4849
activeTab={activeTab}
4950
onActiveTabChange={(tabId) => setActiveTab(tabId)}
50-
attributes={{ width: '860px' }}
51+
className={styles.tabs}
5152
/>
5253
<Box mt="40px">
5354
<MyContractsTab
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.tabs {
2+
width: 100%;
3+
}
4+
5+
.tabs ul {
6+
max-width: 860px;
7+
}
8+
9+
.modal div[data-modal-part='children'] {
10+
padding: 0;
11+
}

0 commit comments

Comments
 (0)