|
1 |
| -import { createStyles, Image, SimpleGrid, Text, UnstyledButton } from '@mantine/core'; |
| 1 | +import { createStyles, Image, ScrollArea, SimpleGrid, Text, UnstyledButton } from '@mantine/core'; |
2 | 2 | import { useUncontrolled } from '@mantine/hooks';
|
3 | 3 | import { useEffect, useState } from 'react';
|
4 | 4 |
|
5 |
| -const useStyles = createStyles((theme, { checked, disabled }: { checked: boolean; disabled: boolean }) => ({ |
6 |
| - button: { |
7 |
| - display: 'flex', |
8 |
| - alignItems: 'center', |
9 |
| - width: '100%', |
10 |
| - transition: 'background-color 150ms ease, border-color 150ms ease', |
11 |
| - border: `1px solid ${ |
12 |
| - checked |
13 |
| - ? theme.fn.variant({ variant: 'outline', color: theme.primaryColor }).border |
14 |
| - : theme.colorScheme === 'dark' |
15 |
| - ? theme.colors.dark[8] |
16 |
| - : theme.colors.gray[3] |
17 |
| - }`, |
18 |
| - borderRadius: theme.radius.sm, |
19 |
| - padding: theme.spacing.sm, |
20 |
| - backgroundColor: checked |
21 |
| - ? theme.fn.variant({ variant: 'light', color: theme.primaryColor }).background |
22 |
| - : disabled |
23 |
| - ? theme.colors.gray[3] |
24 |
| - : theme.white, |
25 |
| - }, |
| 5 | +const useStyles = createStyles((theme, { checked, disabled }: { checked: boolean; disabled: boolean }) => { |
| 6 | + let backgroundColor = 'light'; |
| 7 | + if (disabled) { |
| 8 | + backgroundColor = theme.colorScheme === 'dark' ? theme.colors.dark[4] : theme.colors.gray[4]; |
| 9 | + } |
| 10 | + if (checked) { |
| 11 | + backgroundColor = theme.fn.variant({ variant: 'light', color: theme.primaryColor }).background!; |
| 12 | + } |
| 13 | + return { |
| 14 | + button: { |
| 15 | + display: 'flex', |
| 16 | + alignItems: 'center', |
| 17 | + width: '100%', |
| 18 | + transition: 'background-color 150ms ease, border-color 150ms ease', |
| 19 | + border: `1px solid ${ |
| 20 | + checked |
| 21 | + ? theme.fn.variant({ variant: 'outline', color: theme.primaryColor }).border |
| 22 | + : theme.colorScheme === 'dark' |
| 23 | + ? theme.colors.dark[8] |
| 24 | + : theme.colors.gray[3] |
| 25 | + }`, |
| 26 | + borderRadius: theme.radius.sm, |
| 27 | + padding: theme.spacing.sm, |
| 28 | + backgroundColor, |
| 29 | + outline: 'none !important', |
| 30 | + }, |
26 | 31 |
|
27 |
| - body: { |
28 |
| - flex: 1, |
29 |
| - marginLeft: theme.spacing.md, |
30 |
| - }, |
31 |
| -})); |
| 32 | + body: { |
| 33 | + flex: 1, |
| 34 | + marginLeft: theme.spacing.md, |
| 35 | + }, |
| 36 | + }; |
| 37 | +}); |
32 | 38 |
|
33 | 39 | interface ImageCheckboxProps {
|
34 | 40 | checked?: boolean;
|
@@ -115,31 +121,33 @@ export function MangaSearchResult({
|
115 | 121 | }, [items]);
|
116 | 122 |
|
117 | 123 | return (
|
118 |
| - <SimpleGrid |
119 |
| - cols={2} |
120 |
| - breakpoints={[ |
121 |
| - { maxWidth: 'md', cols: 2 }, |
122 |
| - { maxWidth: 'sm', cols: 1 }, |
123 |
| - ]} |
124 |
| - > |
125 |
| - {items.map((m) => ( |
126 |
| - <ImageCheckbox |
127 |
| - key={m.title} |
128 |
| - image={m.cover || '/cover-not-found.jpg'} |
129 |
| - title={m.title} |
130 |
| - disabled={selected && m.title !== selected.title} |
131 |
| - description={m.status} |
132 |
| - onChange={(checked) => { |
133 |
| - if (checked) { |
134 |
| - setSelected(m); |
135 |
| - onSelect(m); |
136 |
| - } else { |
137 |
| - setSelected(undefined); |
138 |
| - onSelect(undefined); |
139 |
| - } |
140 |
| - }} |
141 |
| - /> |
142 |
| - ))} |
143 |
| - </SimpleGrid> |
| 124 | + <ScrollArea sx={{ height: 350 }}> |
| 125 | + <SimpleGrid |
| 126 | + cols={2} |
| 127 | + breakpoints={[ |
| 128 | + { maxWidth: 'md', cols: 2 }, |
| 129 | + { maxWidth: 'sm', cols: 1 }, |
| 130 | + ]} |
| 131 | + > |
| 132 | + {items.map((m) => ( |
| 133 | + <ImageCheckbox |
| 134 | + key={m.title} |
| 135 | + image={m.cover || '/cover-not-found.jpg'} |
| 136 | + title={m.title} |
| 137 | + disabled={selected && m.title !== selected.title} |
| 138 | + description={m.status} |
| 139 | + onChange={(checked) => { |
| 140 | + if (checked) { |
| 141 | + setSelected(m); |
| 142 | + onSelect(m); |
| 143 | + } else { |
| 144 | + setSelected(undefined); |
| 145 | + onSelect(undefined); |
| 146 | + } |
| 147 | + }} |
| 148 | + /> |
| 149 | + ))} |
| 150 | + </SimpleGrid> |
| 151 | + </ScrollArea> |
144 | 152 | );
|
145 | 153 | }
|
0 commit comments