Skip to content

Commit

Permalink
Merge pull request #385 from cheeto-bandito/feature/image
Browse files Browse the repository at this point in the history
Logo Datasource and UI Improvements
  • Loading branch information
lovesitecore authored Mar 4, 2024
2 parents e09f323 + 5387906 commit ae84bb7
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import React from 'react';
import {
Image as JssImage,
Link as JssLink,
ImageField,
Field,
LinkField,
Text,
useSitecoreContext,
} from '@sitecore-jss/sitecore-jss-nextjs';

interface Fields {
Image: ImageField;
ImageCaption: Field<string>;
TargetUrl: LinkField;
}

type LogoProps = {
params: { [key: string]: string };
fields: Fields;
};

const LogoDefault = (props: LogoProps): JSX.Element => (
<div className={`component image ${props.params.styles}`.trimEnd()}>
<div className="component-content">
<span className="is-empty-hint">Logo</span>
</div>
</div>
);

export const Banner = (props: LogoProps): JSX.Element => {
const { sitecoreContext } = useSitecoreContext();
const isPageEditing = sitecoreContext.pageEditing;
const classHeroBannerEmpty =
isPageEditing && props.fields?.Image?.value?.class === 'scEmptyImage'
? 'hero-banner-empty'
: '';
const backgroundStyle = { backgroundImage: `url('${props?.fields?.Image?.value?.src}')` };
const modifyImageProps = {
...props.fields.Image,
editable: props?.fields?.Image?.editable
?.replace(`width="${props?.fields?.Image?.value?.width}"`, 'width="100%"')
.replace(`height="${props?.fields?.Image?.value?.height}"`, 'height="100%"'),
};
const id = props.params.RenderingIdentifier;

return (
<div
className={`component hero-banner ${props.params.styles} ${classHeroBannerEmpty}`}
id={id ? id : undefined}
>
<div className="component-content sc-sxa-image-hero-banner" style={backgroundStyle}>
{sitecoreContext.pageEditing ? <JssImage field={modifyImageProps} /> : ''}
</div>
</div>
);
};

export const Default = (props: LogoProps): JSX.Element => {
const { sitecoreContext } = useSitecoreContext();

if (props.fields) {
const Image = () => <JssImage field={props.fields.Image} />;
const id = props.params.RenderingIdentifier;

return (
<div className={`component image ${props.params.styles}`} id={id ? id : undefined}>
<div className="component-content">
{sitecoreContext.pageState === 'edit' || !props.fields.TargetUrl?.value?.href ? (
<Image />
) : (
<JssLink field={props.fields.TargetUrl}>
<Image />
</JssLink>
)}
<Text
tag="span"
className="image-caption field-imagecaption"
field={props.fields.ImageCaption}
/>
</div>
</div>
);
}

return <LogoDefault {...props} />;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Meta, StoryObj } from '@storybook/react';
import { Default as LogoComponent } from '../../../components/Basic Components/Logo';
const meta = {
title: 'Components/Logo',
component: LogoComponent,
parameters: {
layout: 'centered',
},
tags: ['autodocs'],
argTypes: {},
} satisfies Meta<typeof LogoComponent>;
export default meta;
type Story = StoryObj<typeof meta>;
export const Logo: Story = {
name: 'Logo ',
args: {
params: {
styles: '',
},
fields: {
Image: {
value: {
src: 'https://picsum.photos/1200/800',
alt: 'Logo',
width: '1200',
height: '800',
},
},
TargetUrl: {
value: {
href: 'https://www.sitecore.com',
anchor: 'Home',
},
},
ImageCaption: {
value: 'SUGCON 2024 Logo',
}
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ SharedFields:
- ID: "c7c26117-dbb1-42b2-ab5e-f7223845cca3"
Hint: __Thumbnail
Value: |
<image mediaid="{F5A477A7-3FBD-4EEC-9B70-230B2BCF826F}" />
<image mediaid="{3C7CD116-2486-4761-98CD-341618749452}" />
- ID: "f1a1fe9e-a60c-4ddb-a3a0-bb5b29fe732e"
Hint: __Renderings
Value: |
Expand All @@ -27,10 +27,10 @@ SharedFields:
s:ph="headless-footer"
s:ccb="Clear on publish" />
<r
uid="{BDE0EFB8-5CA0-4DD7-8821-7BEBF274B053}"
uid="{AC3606D6-5DC8-4E1A-A557-422DF65C3923}"
p:after="*[1=2]"
s:ds="query:$site/Data/Images/Logo"
s:id="{AB2EDBA0-3960-4F12-B765-579DC231894A}"
s:ds="query:$site/Data/Images/Logos/Footer"
s:id="{83D0E443-F5BB-4140-8152-BE180E05A225}"
s:par="GridParameters&amp;FieldNames&amp;Styles&amp;RenderingIdentifier&amp;CSSStyles&amp;DynamicPlaceholderId=1"
s:ph="headless-footer"
s:ccb="Clear on publish" />
Expand All @@ -54,11 +54,11 @@ Languages:
sitecore\UOUBIWQRx7
- ID: "8cdc337e-a112-42fb-bbb4-4143751e123f"
Hint: __Revision
Value: "1fefb968-58a7-427f-8678-35780324e804"
Value: "8e098e30-df96-4a5f-b288-4fb4ec555148"
- ID: "badd9cf9-53e0-4d0c-bcc0-2d784c282f6a"
Hint: __Updated by
Value: |
sitecore\x3rLvWVVyq
sitecore\cdJph8P5Hr
- ID: "d9cf14b1-fa16-4ba6-9288-e8a174d4d522"
Hint: __Updated
Value: 20240205T202038Z
Value: 20240303T200911Z
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ SharedFields:
- ID: "c7c26117-dbb1-42b2-ab5e-f7223845cca3"
Hint: __Thumbnail
Value: |
<image mediaid="{1A280859-89AA-4DBF-A234-BC7DAFC15098}" />
<image mediaid="{5F950686-5AFD-44E0-86FE-A9BC37B4F1BC}" />
- ID: "f1a1fe9e-a60c-4ddb-a3a0-bb5b29fe732e"
Hint: __Renderings
Value: |
Expand All @@ -20,9 +20,11 @@ SharedFields:
id="{FE5D7FDF-89C0-4D99-9AA3-B5FBD009C9F3}">
<r
uid="{C123A7F7-7187-464C-82AB-BC343CD151F2}"
s:ds="query:$site/Data/Images/Logos/Header"
s:id="{83D0E443-F5BB-4140-8152-BE180E05A225}"
s:par="GridParameters&amp;FieldNames&amp;Styles&amp;CacheClearingBehavior=Clear%20on%20publish&amp;RenderingIdentifier&amp;CSSStyles&amp;DynamicPlaceholderId=1"
s:ph="headless-header" />
s:par="GridParameters&amp;FieldNames&amp;Styles&amp;RenderingIdentifier&amp;CSSStyles&amp;DynamicPlaceholderId=1"
s:ph="headless-header"
s:ccb="Clear on publish" />
</d>
</r>
Languages:
Expand All @@ -43,11 +45,11 @@ Languages:
sitecore\UOUBIWQRx7
- ID: "8cdc337e-a112-42fb-bbb4-4143751e123f"
Hint: __Revision
Value: "13f6609b-81c7-475e-bd4e-37c4ec41d3d7"
Value: "f1168da9-1f08-40a9-8f8b-56882c08667f"
- ID: "badd9cf9-53e0-4d0c-bcc0-2d784c282f6a"
Hint: __Updated by
Value: |
sitecore\cdJph8P5Hr
- ID: "d9cf14b1-fa16-4ba6-9288-e8a174d4d522"
Hint: __Updated
Value: 20240226T171426Z
Value: 20240303T200808Z

0 comments on commit ae84bb7

Please sign in to comment.