Skip to content

Commit f39d1a5

Browse files
IRSA-6571: Separate defaultProps logic into functions
1 parent 363ad8e commit f39d1a5

File tree

1 file changed

+50
-45
lines changed

1 file changed

+50
-45
lines changed

src/firefly/js/templates/hydra/HydraViewer.jsx

Lines changed: 50 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -160,54 +160,59 @@ const HydraAppBranding = ({title, desc}) => (
160160
</Stacker>
161161
);
162162

163+
const defaultCommonProps = ({title, desc}) => ({
164+
bgMonitorHint: { sx: { right: 50 } },
165+
topSection: { title, desc }
166+
});
167+
168+
169+
const defaultPropsWithoutBgImage = ({icon}) => ({
170+
contentSection: { sx: { maxWidth: '80rem', mx: 'auto' } },
171+
topSection: { component: HydraAppBranding }, // use custom topSection instead of DefaultAppBranding
172+
bottomSection: { icon }
173+
});
174+
175+
const defaultPropsWithBgImage = ({bgImage}) => ({
176+
// visually combine topSection & bottomSection into contentSection that can contrast with the bgContainer
177+
bgContainer: {
178+
sx: {
179+
display: 'flex', flexGrow: 1,
180+
backgroundImage: `url(${bgImage})`, backgroundSize: 'cover', backgroundPosition: 'center'
181+
}
182+
},
183+
contentSection: {
184+
sx: (theme) => {
185+
// background image will remain same in both the theme modes, and we need text to contrast with the image,
186+
// so we create a translucent dark overlay and put text over it as if it's dark theme
187+
const darkPalette = theme.colorSchemes.dark.palette;
188+
return {
189+
maxWidth: '56rem', m: 'auto',
190+
backgroundColor: hexColorWithAlpha(darkPalette.background.surface.split(', ')?.[1]?.slice(0, -1) ?? '#000', 0.6),
191+
backdropFilter: 'blur(1px)',
192+
'.MuiTypography-body-md, .MuiTypography-body-lg': { color: darkPalette.text.secondary },
193+
'.MuiTypography-h2': { color: darkPalette.text.primary },
194+
'.MuiTypography-colorPrimary': { color: `rgb(${darkPalette.primary.mainChannel})` },
195+
'.MuiDivider-root': { backgroundColor: darkPalette.neutral.solidBg }
196+
};
197+
},
198+
divider: <Divider sx={{ width: '4rem', alignSelf: 'center' }} />
199+
},
200+
bottomSection: {
201+
icon: false, // to prevent default being applied (on undefined)
202+
slotProps: {
203+
root: { sx: { py: 4, pb: 0, backgroundColor: 'transparent' } }
204+
}
205+
}
206+
});
207+
208+
163209
export function HydraLanding({icon, title, desc, bgImage, slotProps={}, ...props} ) {
164210
const mSlotProps = cloneDeep(slotProps);
165-
defaultsDeep(mSlotProps, {
166-
bgMonitorHint: { sx: { right: 50 } },
167-
topSection: { title, desc }
168-
});
211+
defaultsDeep(mSlotProps, defaultCommonProps({title, desc}));
169212

170-
if (bgImage) {
171-
// visually combine topSection & bottomSection into contentSection that can contrast with the bgContainer
172-
defaultsDeep(mSlotProps, {
173-
bgContainer: {
174-
sx: {
175-
display: 'flex', flexGrow: 1,
176-
backgroundImage: `url(${bgImage})`, backgroundSize: 'cover', backgroundPosition: 'center'
177-
}
178-
},
179-
contentSection: {
180-
sx: (theme) => {
181-
// background image will remain same in both the theme modes, and we need text to contrast with the image,
182-
// so we create a translucent dark overlay and put text over it as if it's dark theme
183-
const darkPalette = theme.colorSchemes.dark.palette;
184-
return {
185-
maxWidth: '56rem', m: 'auto',
186-
backgroundColor: hexColorWithAlpha(darkPalette.background.surface.split(', ')?.[1]?.slice(0, -1) ?? '#000', 0.6),
187-
backdropFilter: 'blur(1px)',
188-
'.MuiTypography-body-md, .MuiTypography-body-lg': { color: darkPalette.text.secondary },
189-
'.MuiTypography-h2': { color: darkPalette.text.primary },
190-
'.MuiTypography-colorPrimary': { color: `rgb(${darkPalette.primary.mainChannel})` },
191-
'.MuiDivider-root': { backgroundColor: darkPalette.neutral.solidBg }
192-
};
193-
},
194-
divider: <Divider sx={{ width: '4rem', alignSelf: 'center' }} />
195-
},
196-
bottomSection: {
197-
icon: false, // to prevent default being applied (on undefined)
198-
slotProps: {
199-
root: { sx: { py: 4, pb: 0, backgroundColor: 'transparent' } }
200-
}
201-
}
202-
});
203-
}
204-
else {
205-
defaultsDeep(mSlotProps, {
206-
contentSection: { sx: { maxWidth: '80rem', mx: 'auto' } },
207-
topSection: { component: HydraAppBranding }, // use custom topSection instead of DefaultAppBranding
208-
bottomSection: { icon }
209-
});
210-
}
213+
bgImage
214+
? defaultsDeep(mSlotProps, defaultPropsWithBgImage({bgImage}))
215+
: defaultsDeep(mSlotProps, defaultPropsWithoutBgImage({icon}));
211216

212217
return <LandingPage slotProps={mSlotProps} {...props}/>;
213218
}

0 commit comments

Comments
 (0)