Skip to content

Commit 8a34104

Browse files
Merge pull request #178 from 0101oak/feature/improve-care-composition-cards-styles
improve care composition cards styles
2 parents 6f09c69 + 0422958 commit 8a34104

File tree

5 files changed

+194
-44
lines changed

5 files changed

+194
-44
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"@types/react-color": "^3.0.7",
6969
"@types/react-image-crop": "^8.1.6",
7070
"@types/react-router-dom": "^5.3.3",
71+
"@types/react-swipeable-views": "^0.13.5",
7172
"axios": "^1.6.7",
7273
"buffer": "^6.0.3",
7374
"calculate-aspect-ratio": "^0.1.3",
@@ -99,6 +100,7 @@
99100
"react-router": "^6.22.3",
100101
"react-router-dom": "^6.22.3",
101102
"react-select-country-list": "^2.2.3",
103+
"react-swipeable-views": "^0.14.0",
102104
"react-text-expander": "^1.0.0",
103105
"react-text-truncate": "^0.19.0",
104106
"react-use-auth": "^2.1.0-14",

src/components/managers/products/genericProductComponent/care/care.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
padding: 0.4rem;
2424
display: flex;
2525
justify-content: center;
26+
align-items: center;
2627
flex: 0 0 auto;
2728
}
2829

src/components/managers/products/genericProductComponent/care/careInstructions.tsx

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
useTheme,
1313
} from '@mui/material';
1414
import { FC, useState } from 'react';
15+
import SwipeableViews from 'react-swipeable-views';
1516
import styles from './care.scss';
1617
import { careInstruction } from './careInstruction';
1718

@@ -41,6 +42,11 @@ export const CareInstructions: FC<CareInstructionsProps> = ({
4142
const [selectedCare, setSelectedCare] = useState<string | null>('Washing');
4243
const theme = useTheme();
4344
const isMobile = useMediaQuery(theme.breakpoints.down('sm'));
45+
const currentCategoryIndex = careCategories.indexOf(selectedCare!);
46+
47+
const handleCategorySwipe = (index: number) => {
48+
setSelectedCare(careCategories[index]);
49+
};
4450

4551
const handleSelectCare = (category: string) => {
4652
setSelectedCare(category);
@@ -65,16 +71,23 @@ export const CareInstructions: FC<CareInstructionsProps> = ({
6571
<Grid container className={styles['care-card']}>
6672
{img && (
6773
<Grid className={styles['care-card-img-container']}>
68-
<img src={img} alt={method} style={{ width: isMobile ? '25px' : '50px' }} />
74+
<img
75+
src={img}
76+
alt={method}
77+
style={{
78+
width: isMobile ? '30px' : '50px',
79+
...(isSelected && { width: '80%' }),
80+
}}
81+
/>
6982
</Grid>
7083
)}
7184
<Grid className={styles['care-card-text']}>
7285
<Typography
7386
variant='overline'
74-
fontSize={isMobile ? '0.4em' : '0.55em'}
87+
fontSize={isMobile ? '0.4em' : '0.58em'}
7588
className={styles.text}
7689
>
77-
{method}
90+
{isSelected ? code : method}
7891
</Typography>
7992
</Grid>
8093
</Grid>
@@ -119,23 +132,45 @@ export const CareInstructions: FC<CareInstructionsProps> = ({
119132
</IconButton>
120133
<Grid container spacing={2} sx={{ p: 2 }}>
121134
<Grid size={{ xs: 12 }} sx={{ display: 'flex', justifyContent: 'center' }}>
122-
<FormControl>
123-
<RadioGroup
124-
row
125-
value={selectedCare}
126-
onChange={(e) => handleSelectCare(e.target.value)}
127-
sx={{ gap: 4 }}
135+
{isMobile ? (
136+
<SwipeableViews
137+
index={currentCategoryIndex}
138+
onChangeIndex={handleCategorySwipe}
139+
enableMouseEvents
140+
resistance
141+
style={{ width: '100%' }}
128142
>
129143
{careCategories.map((category) => (
130-
<FormControlLabel
144+
<Typography
131145
key={category}
132-
value={category}
133-
control={<Radio />}
134-
label={category}
135-
/>
146+
variant='h6'
147+
textTransform='uppercase'
148+
align='center'
149+
sx={{ p: 1 }}
150+
>
151+
{category}
152+
</Typography>
136153
))}
137-
</RadioGroup>
138-
</FormControl>
154+
</SwipeableViews>
155+
) : (
156+
<FormControl>
157+
<RadioGroup
158+
row
159+
value={selectedCare}
160+
onChange={(e) => handleSelectCare(e.target.value)}
161+
sx={{ gap: 4 }}
162+
>
163+
{careCategories.map((category) => (
164+
<FormControlLabel
165+
key={category}
166+
value={category}
167+
control={<Radio />}
168+
label={category.toUpperCase()}
169+
/>
170+
))}
171+
</RadioGroup>
172+
</FormControl>
173+
)}
139174
</Grid>
140175
{selectedCare && (
141176
<Grid size={{ xs: 12 }}>

src/components/managers/products/genericProductComponent/composition/composition-modal/composition-modal.tsx

Lines changed: 55 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ import {
99
RadioGroup,
1010
TextField,
1111
Typography,
12+
useMediaQuery,
13+
useTheme,
1214
} from '@mui/material';
1315
import { FC, useEffect, useMemo, useState } from 'react';
16+
import SwipeableViews from 'react-swipeable-views';
1417
import { composition } from '../garment-composition/garment-composition';
1518
import styles from '../styles/composition.scss';
1619

@@ -41,6 +44,9 @@ export const CompositionModal: FC<CompositionModalProps> = ({
4144
const isSelected = (key: string) => {
4245
return !!localSelectedInstructions[key];
4346
};
47+
const theme = useTheme();
48+
const isMobile = useMediaQuery(theme.breakpoints.down('sm'));
49+
const currentCategoryIndex = compositionCategories.indexOf(selectedCategory);
4450

4551
useEffect(() => {
4652
setLocalSelectedInstructions(selectedInstructions);
@@ -50,6 +56,10 @@ export const CompositionModal: FC<CompositionModalProps> = ({
5056
return Object.values(localSelectedInstructions).reduce((acc, curr) => acc + curr.percentage, 0);
5157
}, [localSelectedInstructions]);
5258

59+
const handleCategorySwipe = (index: number) => {
60+
setSelectedCategory(compositionCategories[index]);
61+
};
62+
5363
const handlePercentageChange = (key: string, value: string) => {
5464
const percentage = parseInt(value) || 0;
5565
if (percentage >= 0 && percentage <= 100) {
@@ -97,6 +107,7 @@ export const CompositionModal: FC<CompositionModalProps> = ({
97107
<Dialog
98108
open={isOpen}
99109
onClose={onClose}
110+
fullScreen={isMobile}
100111
fullWidth
101112
maxWidth='xl'
102113
PaperProps={{ sx: { p: 2, position: 'relative' } }}
@@ -105,29 +116,54 @@ export const CompositionModal: FC<CompositionModalProps> = ({
105116
<CloseIcon />
106117
</IconButton>
107118
<Grid container spacing={2}>
108-
<Grid size={{ xs: 12 }} sx={{ display: 'flex', justifyContent: 'center', p: 2 }}>
109-
<FormControl>
110-
<RadioGroup
111-
row
112-
value={selectedCategory}
113-
onChange={(e) => handleSelectCategory(e.target.value)}
114-
sx={{
115-
gap: 1,
116-
'& .MuiFormControlLabel-root': {
117-
minWidth: 'fit-content',
118-
},
119-
}}
119+
<Grid
120+
size={{ xs: 12 }}
121+
sx={{ display: 'flex', justifyContent: 'center', alignItems: 'center', p: 1 }}
122+
>
123+
{isMobile ? (
124+
<SwipeableViews
125+
index={currentCategoryIndex}
126+
onChangeIndex={handleCategorySwipe}
127+
enableMouseEvents
128+
resistance
129+
style={{ width: '100%' }}
120130
>
121131
{compositionCategories.map((category) => (
122-
<FormControlLabel
132+
<Typography
123133
key={category}
124-
value={category}
125-
control={<Radio />}
126-
label={category}
127-
/>
134+
variant='h6'
135+
textTransform='uppercase'
136+
align='center'
137+
sx={{ p: 1 }}
138+
>
139+
{category}
140+
</Typography>
128141
))}
129-
</RadioGroup>
130-
</FormControl>
142+
</SwipeableViews>
143+
) : (
144+
<FormControl>
145+
<RadioGroup
146+
value={selectedCategory}
147+
onChange={(e) => handleSelectCategory(e.target.value)}
148+
sx={{
149+
display: 'grid',
150+
gridTemplateColumns: 'repeat(2, 1fr)',
151+
'& .MuiFormControlLabel-root': {
152+
minWidth: 'fit-content',
153+
},
154+
}}
155+
>
156+
{compositionCategories.map((category) => (
157+
<FormControlLabel
158+
key={category}
159+
value={category}
160+
control={<Radio />}
161+
label={category.toUpperCase()}
162+
/>
163+
))}
164+
</RadioGroup>
165+
</FormControl>
166+
)}
131167
</Grid>
132168
<Grid size={{ xs: 12 }}>
133169
<Grid container spacing={2}>

0 commit comments

Comments
 (0)