Simplified Img component

This commit is contained in:
DrMint 2022-02-21 01:32:22 +01:00
parent c89fdbb499
commit d28d28bfea
8 changed files with 35 additions and 43 deletions

View File

@ -59,30 +59,22 @@ type ImgProps = {
}; };
export default function Img(props: ImgProps): JSX.Element { export default function Img(props: ImgProps): JSX.Element {
if (props.layout == "fill") { const imgSize = getImgSizesByQuality(
return (
<Image
src={getAssetURL(props.image.url, props.quality)}
alt={props.alt ? props.alt : props.image.alternativeText}
layout={props.layout}
objectFit={props.objectFit}
priority={props.priority}
/>
);
} else {
return (
<Image
src={getAssetURL(props.image.url, props.quality)}
alt={props.alt ? props.alt : props.image.alternativeText}
{...getImgSizesByQuality(
props.image.width, props.image.width,
props.image.height, props.image.height,
props.quality ? props.quality : ImageQuality.Small props.quality ? props.quality : ImageQuality.Small
)} );
return (
<Image
className={props.className}
src={getAssetURL(props.image.url, props.quality)}
alt={props.alt ? props.alt : props.image.alternativeText}
width={props.layout === "fill" ? undefined : imgSize.width}
height={props.layout === "fill" ? undefined : imgSize.height}
layout={props.layout} layout={props.layout}
objectFit={props.objectFit} objectFit={props.objectFit}
priority={props.priority} priority={props.priority}
unoptimized
/> />
); );
}
} }

View File

@ -27,7 +27,7 @@ export default function NavOption(props: NavOptionProps): JSX.Element {
<Link href={props.url} passHref> <Link href={props.url} passHref>
<div <div
onClick={props.onClick} onClick={props.onClick}
data-html={true} data-html
data-tip={` data-tip={`
<div class="px-4 py-3"> <div class="px-4 py-3">
<h3 class="text-2xl">${props.title}</h3> <h3 class="text-2xl">${props.title}</h3>
@ -39,7 +39,7 @@ export default function NavOption(props: NavOptionProps): JSX.Element {
</div> </div>
`} `}
data-for={props.tooltipId} data-for={props.tooltipId}
data-multiline={true} data-multiline
className={`grid grid-flow-col grid-cols-[auto] auto-cols-fr justify-center ${ className={`grid grid-flow-col grid-cols-[auto] auto-cols-fr justify-center ${
props.icon ? "text-left" : "text-center" props.icon ? "text-left" : "text-center"
} ${divCommon}`} } ${divCommon}`}

View File

@ -34,14 +34,14 @@ export default function useMediaQuery(query: string): boolean {
} }
export function useMediaThin() { export function useMediaThin() {
return useMediaQuery("(max-width: 50ch)"); return useMediaQuery("(max-width: 25rem)");
} }
export function useMediaMobile() { export function useMediaMobile() {
return useMediaQuery("(max-width: 120ch)"); return useMediaQuery("(max-width: 60rem)");
} }
export function useMediaDesktop() { export function useMediaDesktop() {
return useMediaQuery("(min-width: 120ch)"); return useMediaQuery("(min-width: 60rem)");
} }

View File

@ -12,7 +12,7 @@ export default function Home(props: HomeProps): JSX.Element {
const langui = props.langui.websiteInterfaces.data[0].attributes; const langui = props.langui.websiteInterfaces.data[0].attributes;
const contentPanel = ( const contentPanel = (
<ContentPanel autoformat={true}> <ContentPanel autoformat>
<div className="grid place-items-center place-content-center w-full gap-5 text-center"> <div className="grid place-items-center place-content-center w-full gap-5 text-center">
<SVG <SVG
className="w-32 mobile:w-1/2" className="w-32 mobile:w-1/2"

View File

@ -23,13 +23,13 @@ export default function Library(props: LibraryProps): JSX.Element {
url="/library/items" url="/library/items"
title={langui.library_items} title={langui.library_items}
subtitle={langui.library_items_description} subtitle={langui.library_items_description}
border={true} border
/> />
<NavOption <NavOption
url="/library/content" url="/library/content"
title={langui.library_content} title={langui.library_content}
subtitle={langui.library_content_description} subtitle={langui.library_content_description}
border={true} border
/> />
</SubPanel> </SubPanel>
); );

View File

@ -63,7 +63,7 @@ export default function LibrarySlug(props: LibrarySlugProps): JSX.Element {
<NavOption <NavOption
title={langui.library_item_summary} title={langui.library_item_summary}
url="#summary" url="#summary"
border={true} border
onClick={() => dispatch(setSubPanelOpen(false))} onClick={() => dispatch(setSubPanelOpen(false))}
/> />
@ -71,7 +71,7 @@ export default function LibrarySlug(props: LibrarySlugProps): JSX.Element {
<NavOption <NavOption
title={langui.library_item_gallery} title={langui.library_item_gallery}
url="#gallery" url="#gallery"
border={true} border
onClick={() => dispatch(setSubPanelOpen(false))} onClick={() => dispatch(setSubPanelOpen(false))}
/> />
) : ( ) : (
@ -81,7 +81,7 @@ export default function LibrarySlug(props: LibrarySlugProps): JSX.Element {
<NavOption <NavOption
title={langui.library_item_details} title={langui.library_item_details}
url="#details" url="#details"
border={true} border
onClick={() => dispatch(setSubPanelOpen(false))} onClick={() => dispatch(setSubPanelOpen(false))}
/> />
@ -93,7 +93,7 @@ export default function LibrarySlug(props: LibrarySlugProps): JSX.Element {
: langui.library_item_subitems : langui.library_item_subitems
} }
url={isVariantSet ? "#variants" : "#subitems"} url={isVariantSet ? "#variants" : "#subitems"}
border={true} border
onClick={() => dispatch(setSubPanelOpen(false))} onClick={() => dispatch(setSubPanelOpen(false))}
/> />
) : ( ) : (
@ -104,7 +104,7 @@ export default function LibrarySlug(props: LibrarySlugProps): JSX.Element {
<NavOption <NavOption
title={langui.library_item_content} title={langui.library_item_content}
url="#content" url="#content"
border={true} border
/> />
) : ( ) : (
"" ""

View File

@ -80,7 +80,7 @@ export default function DataChronology(
subtitle={ subtitle={
era.attributes.starting_year + " → " + era.attributes.ending_year era.attributes.starting_year + " → " + era.attributes.ending_year
} }
border={true} border
/> />
))} ))}
</SubPanel> </SubPanel>

View File

@ -15,9 +15,9 @@ module.exports = {
monospace: ["monospace"], monospace: ["monospace"],
}, },
screens: { screens: {
desktop: { min: "120ch" }, desktop: { min: "60rem" },
mobile: { max: "120ch" }, mobile: { max: "60rem" },
thin: { max: "50ch" }, thin: { max: "25rem" },
coarse: { raw: "(pointer: coarse)" }, coarse: { raw: "(pointer: coarse)" },
fine: { raw: "(pointer: fine)" }, fine: { raw: "(pointer: fine)" },
}, },