Skip to content

Commit

Permalink
✨ Can now add border to image-module in sanity
Browse files Browse the repository at this point in the history
  • Loading branch information
KenAJoh committed Jan 8, 2025
1 parent 8da0af0 commit eefb0f6
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 47 deletions.
94 changes: 47 additions & 47 deletions aksel.nav.no/website/components/sanity-modules/bilde/Bilde.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,56 +17,56 @@ const Bilde = ({ node, className }: BildeProps) => {
}

return (
<>
<figure
className={cl(
"m-0 mb-8 flex flex-col group-[.aksel-artikkel]/aksel:mx-auto",
className,
{
"md:max-w-text": node?.small,
},
)}
<figure
className={cl(
"m-0 mb-8 flex flex-col group-[.aksel-artikkel]/aksel:mx-auto",
className,
{
"md:max-w-text": node?.small,
},
)}
>
<div
style={
node?.background
? {
backgroundColor: `rgba(${node.background.rgb.r},${node.background.rgb.g},${node.background.rgb.b},${node.background.rgb.a})`,
}
: { backgroundColor: "var(--a-gray-50)" }
}
className={cl("flex justify-center rounded-lg p-0", {
"ring-1 ring-border-subtle": node.border,
})}
>
<div
style={
node?.background
? {
backgroundColor: `rgba(${node.background.rgb.r},${node.background.rgb.g},${node.background.rgb.b},${node.background.rgb.a})`,
}
: { backgroundColor: "var(--a-gray-50)" }
}
className="flex justify-center rounded-lg p-0"
>
<img
alt={!node?.dekorativt ? node.alt : ""}
decoding="async"
src={urlFor(node).auto("format").url()}
className="rounded-lg"
/>
</div>
{node.caption && (
<figcaption className="mt-2 grid gap-1 px-4">
<img
alt={!node?.dekorativt ? node.alt : ""}
decoding="async"
src={urlFor(node).auto("format").url()}
className="rounded-lg"
/>
</div>
{node.caption && (
<figcaption className="mt-2 grid gap-1 px-4">
<BodyLong as="span" size="small" className="self-center">
{node.caption}
</BodyLong>
{node?.kilde?.har_kilde && (
<BodyLong as="span" size="small" className="self-center">
{node.caption}
{node?.kilde?.link ? (
<>
{`${node?.kilde?.prefix}: `}
<NextLink href={node.kilde.link} passHref legacyBehavior>
<Link className="break-normal">{node?.kilde?.tekst}</Link>
</NextLink>
</>
) : (
<>{`${node?.kilde?.prefix}: ${node?.kilde?.tekst}`}</>
)}
</BodyLong>
{node?.kilde?.har_kilde && (
<BodyLong as="span" size="small" className="self-center">
{node?.kilde?.link ? (
<>
{`${node?.kilde?.prefix}: `}
<NextLink href={node.kilde.link} passHref legacyBehavior>
<Link className="break-normal">{node?.kilde?.tekst}</Link>
</NextLink>
</>
) : (
<>{`${node?.kilde?.prefix}: ${node?.kilde?.tekst}`}</>
)}
</BodyLong>
)}
</figcaption>
)}
</figure>
</>
)}
</figcaption>
)}
</figure>
);
};

Expand Down
1 change: 1 addition & 0 deletions aksel.nav.no/website/components/types/sanity-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ export interface BildeT {
link?: string;
};
dekorativt?: boolean;
border?: boolean;
background?: {
rgb: { a: number; b: number; g: number; r: number };
alpha: number;
Expand Down
6 changes: 6 additions & 0 deletions aksel.nav.no/website/sanity/schema/objects/shared/bilde.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ export const Bilde = defineType({
type: "boolean",
initialValue: false,
}),
defineField({
name: "border",
title: "Border",
type: "boolean",
initialValue: true,
}),
defineField({
name: "background",
title: "Bakgrunnsfarge",
Expand Down

0 comments on commit eefb0f6

Please sign in to comment.