Initial commit
This commit is contained in:
1
src/index.ts
Normal file
1
src/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
// A file is required to be in the root of the /src directory by the TypeScript compiler
|
||||
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx/client-side-web-part-manifest.schema.json",
|
||||
"id": "70bdea85-6ba4-4d45-82dd-2a2b4b95684b",
|
||||
"alias": "FullWidthSectionWebPartWebPart",
|
||||
"componentType": "WebPart",
|
||||
|
||||
// The "*" signifies that the version should be taken from the package.json
|
||||
"version": "*",
|
||||
"manifestVersion": 2,
|
||||
|
||||
// If true, the component can only be installed on sites where Custom Script is allowed.
|
||||
// Components that allow authors to embed arbitrary script code should set this to true.
|
||||
// https://support.office.com/en-us/article/Turn-scripting-capabilities-on-or-off-1f2c515f-5d7e-448a-9fd7-835da935584f
|
||||
"requiresCustomScript": false,
|
||||
|
||||
"preconfiguredEntries": [{
|
||||
"groupId": "5c03119e-3074-46fd-976b-c60198311f70", // Other
|
||||
"group": { "default": "Other" },
|
||||
"title": { "default": "FullWidthSectionWebPart" },
|
||||
"description": { "default": "FullWidthSectionWebPart" },
|
||||
"officeFabricIconFontName": "Page",
|
||||
"properties": {
|
||||
"horizontalPadding": 20
|
||||
}
|
||||
}]
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
import * as React from 'react';
|
||||
import * as ReactDom from 'react-dom';
|
||||
import { DisplayMode, Version } from '@microsoft/sp-core-library';
|
||||
import {
|
||||
BaseClientSideWebPart,
|
||||
IPropertyPaneConfiguration,
|
||||
PropertyPaneSlider
|
||||
} from '@microsoft/sp-webpart-base';
|
||||
|
||||
import * as strings from 'FullWidthSectionWebPartWebPartStrings';
|
||||
import FullWidthSectionWebPart from './components/FullWidthSectionWebPart';
|
||||
import { IFullWidthSectionWebPartProps } from './components/IFullWidthSectionWebPartProps';
|
||||
|
||||
export interface IFullWidthSectionWebPartWebPartProps {
|
||||
horizontalPadding: number;
|
||||
padding?: number;
|
||||
}
|
||||
|
||||
export default class FullWidthSectionWebPartWebPart extends BaseClientSideWebPart<IFullWidthSectionWebPartWebPartProps> {
|
||||
|
||||
protected onInit(): Promise<void> {
|
||||
return super.onInit().then(() => {
|
||||
if (typeof this.properties.horizontalPadding !== 'number' && typeof this.properties.padding === 'number') {
|
||||
this.properties.horizontalPadding = this.properties.padding;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public render(): void {
|
||||
let horizontalPadding = 20;
|
||||
|
||||
if (typeof this.properties.horizontalPadding === 'number') {
|
||||
horizontalPadding = this.properties.horizontalPadding;
|
||||
} else if (typeof this.properties.padding === 'number') {
|
||||
horizontalPadding = this.properties.padding;
|
||||
}
|
||||
|
||||
const element: React.ReactElement<IFullWidthSectionWebPartProps> = React.createElement(
|
||||
FullWidthSectionWebPart,
|
||||
{
|
||||
horizontalPadding: horizontalPadding,
|
||||
domElement: this.domElement,
|
||||
displayMode: this.displayMode
|
||||
}
|
||||
);
|
||||
|
||||
ReactDom.render(element, this.domElement);
|
||||
}
|
||||
|
||||
protected onDispose(): void {
|
||||
ReactDom.unmountComponentAtNode(this.domElement);
|
||||
}
|
||||
|
||||
protected get dataVersion(): Version {
|
||||
return Version.parse('1.0');
|
||||
}
|
||||
|
||||
protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
|
||||
return {
|
||||
pages: [
|
||||
{
|
||||
header: {
|
||||
description: strings.PropertyPaneDescription
|
||||
},
|
||||
groups: [
|
||||
{
|
||||
groupName: strings.BasicGroupName,
|
||||
groupFields: [
|
||||
PropertyPaneSlider('horizontalPadding', {
|
||||
label: strings.HorizontalPaddingFieldLabel,
|
||||
min: 0,
|
||||
max: 100,
|
||||
step: 1,
|
||||
showValue: true
|
||||
})
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
@import '~@microsoft/sp-office-ui-fabric-core/dist/sass/SPFabricCore.scss';
|
||||
|
||||
:global(.SPCanvas-canvas) {
|
||||
max-width: unset !important
|
||||
}
|
||||
|
||||
.fullWidthSectionWebPart {
|
||||
.container {
|
||||
max-width: 99%;
|
||||
margin: 0px auto;
|
||||
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2), 0 25px 50px 0 rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.row {
|
||||
@include ms-Grid-row;
|
||||
@include ms-fontColor-white;
|
||||
background-color: $ms-color-themeDark;
|
||||
padding-top: 20px;
|
||||
padding-bottom: 20px;
|
||||
}
|
||||
|
||||
.column {
|
||||
@include ms-Grid-col;
|
||||
@include ms-lg10;
|
||||
@include ms-xl8;
|
||||
@include ms-xlPush2;
|
||||
@include ms-lgPush1;
|
||||
}
|
||||
|
||||
.title {
|
||||
@include ms-font-xl;
|
||||
@include ms-fontColor-white;
|
||||
}
|
||||
|
||||
.subTitle {
|
||||
@include ms-font-l;
|
||||
@include ms-fontColor-white;
|
||||
}
|
||||
|
||||
.description {
|
||||
@include ms-font-l;
|
||||
@include ms-fontColor-white;
|
||||
}
|
||||
|
||||
.button {
|
||||
text-decoration: none;
|
||||
height: 32px;
|
||||
min-width: 80px;
|
||||
background-color: $ms-color-themePrimary;
|
||||
border-color: $ms-color-themePrimary;
|
||||
color: $ms-color-white;
|
||||
outline: transparent;
|
||||
position: relative;
|
||||
font-family: "Segoe UI WestEuropean","Segoe UI",-apple-system,BlinkMacSystemFont,Roboto,"Helvetica Neue",sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
font-size: $ms-font-size-m;
|
||||
font-weight: $ms-font-weight-regular;
|
||||
border-width: 0;
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
display: inline-block;
|
||||
padding: 0 16px;
|
||||
|
||||
.label {
|
||||
font-weight: $ms-font-weight-semibold;
|
||||
font-size: $ms-font-size-m;
|
||||
height: 32px;
|
||||
line-height: 32px;
|
||||
margin: 0 4px;
|
||||
vertical-align: top;
|
||||
display: inline-block;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
import * as React from 'react';
|
||||
import { DisplayMode } from '@microsoft/sp-core-library';
|
||||
import styles from './FullWidthSectionWebPart.module.scss';
|
||||
import { IFullWidthSectionWebPartProps } from './IFullWidthSectionWebPartProps';
|
||||
|
||||
const DESCRIPTION_TEXT = 'FullWidthSectionWebPart';
|
||||
|
||||
export default class FullWidthSectionWebPart extends React.Component<IFullWidthSectionWebPartProps, {}> {
|
||||
|
||||
public componentDidMount(): void {
|
||||
this.applySectionStyling();
|
||||
}
|
||||
|
||||
public componentDidUpdate(): void {
|
||||
this.applySectionStyling();
|
||||
}
|
||||
|
||||
public componentWillUnmount(): void {
|
||||
const section = this.getSectionElement();
|
||||
|
||||
if (section) {
|
||||
section.style.paddingLeft = '';
|
||||
section.style.paddingRight = '';
|
||||
section.classList.remove('CanvasZone--fullWidth');
|
||||
section.classList.remove('CanvasZone--fullWidth--read');
|
||||
}
|
||||
}
|
||||
|
||||
private getSectionElement(): HTMLElement | null {
|
||||
return this.props.domElement.closest('[data-automation-id="CanvasZone"]') as HTMLElement;
|
||||
}
|
||||
|
||||
private applySectionStyling(): void {
|
||||
const section = this.getSectionElement();
|
||||
|
||||
if (section) {
|
||||
section.classList.add('CanvasZone--fullWidth');
|
||||
section.classList.add('CanvasZone--fullWidth--read');
|
||||
section.style.paddingLeft = this.props.horizontalPadding + 'px';
|
||||
section.style.paddingRight = this.props.horizontalPadding + 'px';
|
||||
}
|
||||
}
|
||||
|
||||
public render(): React.ReactElement<IFullWidthSectionWebPartProps> {
|
||||
if (this.props.displayMode !== DisplayMode.Edit) {
|
||||
return <div dangerouslySetInnerHTML={{ __html: '<!--- Full Width Section --->' }} />;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={styles.fullWidthSectionWebPart}>
|
||||
<div className={styles.container}>
|
||||
<div className={styles.row}>
|
||||
<div className={styles.column}>
|
||||
<span className={styles.title}>Full Width Web Part</span>
|
||||
<p className={styles.subTitle}></p>
|
||||
<p className={styles.description}>{DESCRIPTION_TEXT}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import { DisplayMode } from '@microsoft/sp-core-library';
|
||||
|
||||
export interface IFullWidthSectionWebPartProps {
|
||||
horizontalPadding: number;
|
||||
domElement: HTMLElement;
|
||||
displayMode: DisplayMode;
|
||||
}
|
||||
7
src/webparts/fullWidthSectionWebPart/loc/en-us.js
Normal file
7
src/webparts/fullWidthSectionWebPart/loc/en-us.js
Normal file
@@ -0,0 +1,7 @@
|
||||
define([], function() {
|
||||
return {
|
||||
"PropertyPaneDescription": "Layout settings",
|
||||
"BasicGroupName": "Spacing",
|
||||
"HorizontalPaddingFieldLabel": "Horizontal padding (left/right, px)"
|
||||
}
|
||||
});
|
||||
10
src/webparts/fullWidthSectionWebPart/loc/mystrings.d.ts
vendored
Normal file
10
src/webparts/fullWidthSectionWebPart/loc/mystrings.d.ts
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
declare interface IFullWidthSectionWebPartWebPartStrings {
|
||||
PropertyPaneDescription: string;
|
||||
BasicGroupName: string;
|
||||
HorizontalPaddingFieldLabel: string;
|
||||
}
|
||||
|
||||
declare module 'FullWidthSectionWebPartWebPartStrings' {
|
||||
const strings: IFullWidthSectionWebPartWebPartStrings;
|
||||
export = strings;
|
||||
}
|
||||
Reference in New Issue
Block a user