-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #385 from cheeto-bandito/feature/image
Logo Datasource and UI Improvements
- Loading branch information
Showing
4 changed files
with
141 additions
and
12 deletions.
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
src/Project/Sugcon2024/Sugcon/src/components/Basic Components/Logo.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} />; | ||
}; |
40 changes: 40 additions & 0 deletions
40
src/Project/Sugcon2024/Sugcon/src/stories/components/Basic Components/Logo.stories.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
} | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters