Merge pull request #2416 from omarelanis/master
Hero Webpart Collage feature
This commit is contained in:
commit
bedabbea9d
|
@ -31,3 +31,7 @@ obj
|
|||
|
||||
# Styles Generated Code
|
||||
*.scss.ts
|
||||
# .CER Certificates
|
||||
*.cer
|
||||
# .PEM Certificates
|
||||
*.pem
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
|
||||
## Summary
|
||||
|
||||
This solution creates a customisable Hero web part, it uses a stored collection from the PnP PropertyFieldCollectionData control
|
||||
This solution creates a customisable Hero web part, it uses a stored collection from the PnP `PropertyFieldCollectionData` control
|
||||
|
||||
![Preview](./assets/Hero-Webpart.gif)
|
||||
|
||||
![Preview](./assets/collage-hero-webpart.PNG)
|
||||
|
||||
## Compatibility
|
||||
|
||||
|
@ -34,17 +34,18 @@ hero-webpart | [Omar El-Anis](https://github.com/omarelanis) @ SP Bytes www.spby
|
|||
|
||||
Version|Date|Comments
|
||||
-------|----|--------
|
||||
1.3|March 11, 2022|At the request of another user a option has been added to allow a collage of images to be shown in a flex grid layout<br/>Added in placeholder configuration screen<br/>Fixed webpart not loading the 5 temporary items on first adding webpart to new page in local workbench<br/>General maintenance to remove unused imports<br/>Updated CSS to add in collage feature
|
||||
1.2|July 27, 2021|Updated to automatically detect how many items are being displayed and adjust the display layout based on this<br/>Updated design to show the title on all images<br/>Updated description area on hover<br/>Updated hover effect of image to show a zoom effect when hovering over an item<br/>General cleaning up of CSS and code
|
||||
1.1|March 10, 2021|Update comment
|
||||
1.0|January 29, 2021|Initial release
|
||||
|
||||
## Minimal Path to Awesome
|
||||
|
||||
- Clone this repository
|
||||
- Ensure that you are at the solution folder
|
||||
- in the command-line run:
|
||||
- `npm install`
|
||||
- `gulp serve`
|
||||
* Clone this repository (or [download this solution as a .ZIP file](https://pnp.github.io/download-partial/?url=https://github.com/pnp/sp-dev-fx-webparts/tree/main/samples/react-hero-webpart) then unzip it)
|
||||
* From your command line, change your current directory to the directory containing this sample (`react-hero-webpart`, located under `samples`)
|
||||
* in the command line run:
|
||||
* `npm install`
|
||||
* `gulp serve`
|
||||
|
||||
> This sample can also be opened with [VS Code Remote Development](https://code.visualstudio.com/docs/remote/remote-overview). Visit https://aka.ms/spfx-devcontainer for further instructions.
|
||||
|
||||
|
@ -66,16 +67,22 @@ This extension illustrates the following concepts:
|
|||
- [Publish SharePoint Framework applications to the Marketplace](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/publish-to-marketplace-overview)
|
||||
- [Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp) - Guidance, tooling, samples and open-source controls for your Microsoft 365 development
|
||||
|
||||
|
||||
## Help
|
||||
|
||||
We do not support samples, but we this community is always willing to help, and we want to improve these samples. We use GitHub to track issues, which makes it easy for community members to volunteer their time and help resolve issues.
|
||||
|
||||
We do not support samples, but this community is always willing to help, and we want to improve these samples. We use GitHub to track issues, which makes it easy for community members to volunteer their time and help resolve issues.
|
||||
|
||||
If you're having issues building the solution, please run [spfx doctor](https://pnp.github.io/cli-microsoft365/cmd/spfx/spfx-doctor/) from within the solution folder to diagnose incompatibility issues with your environment.
|
||||
|
||||
You can try looking at [issues related to this sample](https://github.com/pnp/sp-dev-fx-webparts/issues?q=label%3A%22sample%3A%20react-hero-webpart%22) to see if anybody else is having the same issues.
|
||||
|
||||
You can also try looking at [discussions related to this sample](https://github.com/pnp/sp-dev-fx-webparts/discussions?discussions_q=react-hero-webpart) and see what the community is saying.
|
||||
|
||||
If you encounter any issues while using this sample, [create a new issue](https://github.com/pnp/sp-dev-fx-webparts/issues/new?assignees=&labels=Needs%3A+Triage+%3Amag%3A%2Ctype%3Abug-suspected%2Csample%3A%20react-hero-webpart&template=bug-report.yml&sample=react-hero-webpart&authors=@omarelanis&title=react-hero-webpart%20-%20).
|
||||
|
||||
For questions regarding this sample, [create a new question](https://github.com/pnp/sp-dev-fx-webparts/issues/new?assignees=&labels=Needs%3A+Triage+%3Amag%3A%2Ctype%3Aquestion%2Csample%3A%20react-hero-webpart&template=question.yml&sample=react-hero-webpart&authors=@omarelanis&title=react-hero-webpart%20-%20).
|
||||
|
||||
Finally, if you have an idea for improvement, [make a suggestion](https://github.com/pnp/sp-dev-fx-webparts/issues/new?assignees=&labels=Needs%3A+Triage+%3Amag%3A%2Ctype%3Aenhancement%2Csample%3A%20react-hero-webpart&template=question.yml&sample=react-hero-webpart&authors=@omarelanis&title=react-hero-webpart%20-%20).
|
||||
Finally, if you have an idea for improvement, [make a suggestion](https://github.com/pnp/sp-dev-fx-webparts/issues/new?assignees=&labels=Needs%3A+Triage+%3Amag%3A%2Ctype%3Aenhancement%2Csample%3A%20react-hero-webpart&template=suggestion.yml&sample=react-hero-webpart&authors=@omarelanis&title=react-hero-webpart%20-%20).
|
||||
|
||||
## Disclaimer
|
||||
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 1.8 MiB |
|
@ -9,7 +9,7 @@
|
|||
"This solution creates a customisable Hero web part, it uses a stored collection from the PnP PropertyFieldCollectionData control "
|
||||
],
|
||||
"creationDateTime": "2021-04-02",
|
||||
"updateDateTime": "2021-07-27",
|
||||
"updateDateTime": "2022-03-11",
|
||||
"products": [
|
||||
"SharePoint",
|
||||
"Office"
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
"solution": {
|
||||
"name": "Hero Layout Webpart",
|
||||
"id": "5efc0426-3e59-4fc7-b638-73eb77aaf788",
|
||||
"version": "1.2.0.0",
|
||||
"version": "1.3.0.0",
|
||||
"includeClientSideAssets": true,
|
||||
"skipFeatureDeployment": true,
|
||||
"isDomainIsolated": false,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "hero-webpart",
|
||||
"version": "0.0.1",
|
||||
"version": "1.3.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "hero-webpart",
|
||||
"version": "1.2.0",
|
||||
"version": "1.3.0",
|
||||
"private": true,
|
||||
"main": "lib/index.js",
|
||||
"scripts": {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"id": "71d58a4f-1896-46aa-94a5-dbef33d14166",
|
||||
"alias": "HeroWebpartWebPart",
|
||||
"componentType": "WebPart",
|
||||
"version": "0.0.1",
|
||||
"version": "1.3.0",
|
||||
"manifestVersion": 2,
|
||||
"requiresCustomScript": false,
|
||||
"supportedHosts": [
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -11,9 +11,8 @@ export default class Hero extends React.Component<IHeroLayoutProps> {
|
|||
|
||||
|
||||
public render(): React.ReactElement<IHeroLayoutProps> {
|
||||
//const classTotal = "itemShow"+this.props.totalShow;
|
||||
const items = this.props.items;
|
||||
const viewType = items.length==1 ? "heroOne" : items.length==2 ? "heroTwo" : items.length==3 ? "heroThree" :
|
||||
const viewType = this.props.isCollage ? "heroCollage" : items.length==1 ? "heroOne" : items.length==2 ? "heroTwo" : items.length==3 ? "heroThree" :
|
||||
items.length==4 ? "heroFour" : items.length==5 ? "heroFive" : "heroFive";
|
||||
var arr = [];
|
||||
arr.push(items);
|
||||
|
@ -25,7 +24,7 @@ export default class Hero extends React.Component<IHeroLayoutProps> {
|
|||
className={styles.heroItem}
|
||||
items={arr}
|
||||
getItemCountForPage={this._getItemCountForPage}
|
||||
onRenderCell={this._onRenderHeroItem}
|
||||
onRenderCell={this.props.isCollage?this._onRenderHeroCollage:this._onRenderHeroItem}
|
||||
{...this.props.listProps}
|
||||
/>
|
||||
</div>
|
||||
|
@ -70,4 +69,25 @@ export default class Hero extends React.Component<IHeroLayoutProps> {
|
|||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
private _onRenderHeroCollage = (items: any, index: number | undefined): JSX.Element => {
|
||||
const thumbRend = "https://media.akamai.odsp.cdn.office.net/uksouth1-mediap.svc.ms/transform/thumbnail?provider=url&inputFormat=jpg&docid=";
|
||||
var smalltemUrl;
|
||||
return(
|
||||
<div className={styles["collageContainer"]}>
|
||||
{items.map((item) => (
|
||||
smalltemUrl= item.Hyperlink ? item.Hyperlink : "#",
|
||||
<div className={styles["collageitem"]}>
|
||||
<div className={styles["collageItemInner"]}>
|
||||
<a href={smalltemUrl}>
|
||||
<img src={item.filePicker[0].fileNameWithoutExtension=='blankEntry154873'?item.filePicker[0].fileAbsoluteUrl:thumbRend+item.filePicker[0].fileAbsoluteUrl+"&w=960"}/>
|
||||
<div className={styles.heroTitle}>{item.Title}</div>
|
||||
<div className={styles.description}><div className={styles.heroTitleHover}>{item.Title}</div><div className={styles.info}>{item.Description ? item.Description.length>150 ? item.Description.substring(0, 150)+".." : item.Description : "Description coming soon"}</div></div>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
|
@ -285,6 +285,65 @@
|
|||
}
|
||||
}
|
||||
|
||||
:global(.heroCollage) .collageContainer
|
||||
{
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
|
||||
.collageitem {
|
||||
overflow: hidden;
|
||||
flex-shrink: 1;
|
||||
padding: 6px;
|
||||
width: calc(33% - 12px);
|
||||
a{
|
||||
width: 100%;
|
||||
}
|
||||
img{
|
||||
width: inherit;
|
||||
}
|
||||
.heroTitle {
|
||||
font-size: 14px;
|
||||
width: calc(33% - 22px);
|
||||
margin: -80px 0px 0px 0px;
|
||||
position: absolute;
|
||||
bottom: unset;
|
||||
}
|
||||
.heroTitleHover{
|
||||
font-size: 16px;
|
||||
}
|
||||
.info{
|
||||
font-size: 12px;
|
||||
}
|
||||
.description{
|
||||
@include ms-fontColor-white;
|
||||
position: absolute;
|
||||
margin: -90px 0px 0px 0px;
|
||||
bottom: unset;
|
||||
background: rgba(0, 0, 0, 0);
|
||||
width: calc(33% - 22px);
|
||||
transition: .5s ease;
|
||||
font-size: 18px;
|
||||
padding: 20px 0px;;
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
|
||||
.collageItemInner:hover {
|
||||
.description {
|
||||
background: rgba(0, 0, 0, 0.9);
|
||||
width: calc(33% - 22px);
|
||||
position: absolute;
|
||||
margin: -90px 0px 0px 0px;
|
||||
bottom: unset;
|
||||
.info,.heroTitleHover{
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@media all and (max-width: 768px) {
|
||||
.heroItem {
|
||||
|
|
|
@ -8,6 +8,8 @@ import { sp } from '@pnp/sp';
|
|||
import { Stack, IStackProps, IStackTokens } from 'office-ui-fabric-react/lib/Stack';
|
||||
import { Label } from 'office-ui-fabric-react/lib/Label';
|
||||
import { Spinner, SpinnerSize } from 'office-ui-fabric-react/lib/Spinner';
|
||||
import { Placeholder } from "@pnp/spfx-controls-react/lib/Placeholder";
|
||||
import { DisplayMode } from '@microsoft/sp-core-library';
|
||||
|
||||
const stackTokens: IStackTokens = { childrenGap: 20 };
|
||||
|
||||
|
@ -87,11 +89,17 @@ export default class HeroWebpart extends React.Component<IHeroWebpartProps, IHer
|
|||
<Stack {...rowProps} tokens={tokens.spinnerStack}>
|
||||
<Label>Loading</Label>
|
||||
<Spinner size={SpinnerSize.large} />
|
||||
</Stack>
|
||||
</Stack> &&
|
||||
<Placeholder iconName='Edit'
|
||||
iconText='Configure your web part'
|
||||
description='Please configure the web part.'
|
||||
buttonLabel='Configure'
|
||||
hideButton={this.props.displayMode === DisplayMode.Read}
|
||||
onConfigure={this._onConfigure} />
|
||||
);
|
||||
}else{
|
||||
var itemList:any[];
|
||||
this.props.showAllHero ? itemList = this.state.itemsPaginated : itemList = this.state.items;
|
||||
var itemList:any[] = this.state.items;
|
||||
this.props.showAllHero && !this.props.showCollage ? itemList = this.state.itemsPaginated : itemList = this.state.items;
|
||||
}
|
||||
|
||||
return (
|
||||
|
@ -99,9 +107,10 @@ export default class HeroWebpart extends React.Component<IHeroWebpartProps, IHer
|
|||
<div className={styles.titleHead}>
|
||||
{this.props.title}
|
||||
</div>
|
||||
<Hero items={this.props.showAllHero ? this.state.itemsPaginated : this.state.items.slice(0, 5)}/>
|
||||
{this.props.showAllHero ?
|
||||
<Pagination
|
||||
{this.props.showAllHero &&
|
||||
<>
|
||||
<Hero items={this.props.showAllHero ? this.state.itemsPaginated : this.state.items.slice(0, 5)} isCollage={this.props.showCollage}/>
|
||||
<Pagination
|
||||
currentPage={this.state.currentPage}
|
||||
totalPages={this.state.totalPages}
|
||||
onChange={(page) => this._getPage(page)}
|
||||
|
@ -109,10 +118,20 @@ export default class HeroWebpart extends React.Component<IHeroWebpartProps, IHer
|
|||
hideFirstPageJump={this.props.hideFirstPageJump} // Optional
|
||||
hideLastPageJump={this.props.hideLastPageJump} // Optional
|
||||
limiterIcon={"Emoji12"} // Optional
|
||||
/> : "" }
|
||||
</div>
|
||||
/>
|
||||
</>
|
||||
}
|
||||
{!this.props.showAllHero &&
|
||||
<Hero items={this.state.items} isCollage={this.props.showCollage}/>
|
||||
}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
private _onConfigure() {
|
||||
// Context of the web part
|
||||
this.props.spfxContext.propertyPane.open();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -4,4 +4,5 @@ import { IListProps } from 'office-ui-fabric-react/lib/List';
|
|||
export interface IHeroLayoutProps {
|
||||
items:any[];
|
||||
listProps?: Partial<IListProps>;
|
||||
isCollage:boolean;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { WebPartContext } from '@microsoft/sp-webpart-base';
|
||||
import { DisplayMode } from '@microsoft/sp-core-library';
|
||||
|
||||
export interface IHeroWebpartProps {
|
||||
title: string;
|
||||
|
@ -8,5 +9,7 @@ export interface IHeroWebpartProps {
|
|||
hideFirstPageJump: boolean;
|
||||
hideLastPageJump: boolean;
|
||||
showAllHero: boolean;
|
||||
showCollage: boolean;
|
||||
items:any[];
|
||||
displayMode: DisplayMode;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue