Adding react-doccard-faq
Adding a sample web part for react using document cards from fluent UI and bringing in modals for a new way of doing a FAQ web part.
This commit is contained in:
parent
f7e3726006
commit
fafd4caf21
|
@ -0,0 +1,25 @@
|
|||
# EditorConfig helps developers define and maintain consistent
|
||||
# coding styles between different editors and IDEs
|
||||
# editorconfig.org
|
||||
|
||||
root = true
|
||||
|
||||
|
||||
[*]
|
||||
|
||||
# change these settings to your own preference
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
# we recommend you to keep these unchanged
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[{package,bower}.json]
|
||||
indent_style = space
|
||||
indent_size = 2
|
|
@ -0,0 +1,32 @@
|
|||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
|
||||
# Dependency directories
|
||||
node_modules
|
||||
|
||||
# Build generated files
|
||||
dist
|
||||
lib
|
||||
solution
|
||||
temp
|
||||
*.sppkg
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
|
||||
# OSX
|
||||
.DS_Store
|
||||
|
||||
# Visual Studio files
|
||||
.ntvs_analysis.dat
|
||||
.vs
|
||||
bin
|
||||
obj
|
||||
|
||||
# Resx Generated Code
|
||||
*.resx.ts
|
||||
|
||||
# Styles Generated Code
|
||||
*.scss.ts
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"@microsoft/generator-sharepoint": {
|
||||
"isCreatingSolution": true,
|
||||
"environment": "spo",
|
||||
"version": "1.10.0",
|
||||
"libraryName": "react-faq-video",
|
||||
"libraryId": "881b043c-c29d-4a28-bbe7-28478486b8bb",
|
||||
"packageManager": "npm",
|
||||
"isDomainIsolated": false,
|
||||
"componentType": "webpart"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
# Title of the sample
|
||||
|
||||
React FAQ Document Card Web Part
|
||||
|
||||
|
||||
## Summary
|
||||
|
||||
For detailed instructions on how to build this web part and the needed list please watch: https://www.youtube.com/watch?v=oIr-rgGvUUk
|
||||
|
||||
|
||||
![picture of the web part in action](assets/FAQdocCardPreview.gif)
|
||||
![picture of the web part in action](assets/reactdoccardfaq.png)
|
||||
## Compatibility
|
||||
|
||||
![SPFx 1.10](https://img.shields.io/badge/SPFx-1.11.0-green.svg)
|
||||
![Node.js LTS 10.x](https://img.shields.io/badge/Node.js-LTS%2010.x-green.svg)
|
||||
![SharePoint Online](https://img.shields.io/badge/SharePoint-Online-yellow.svg)
|
||||
![Teams N/A: Untested with Microsoft Teams](https://img.shields.io/badge/Teams-N%2FA-lightgrey.svg "Untested with Microsoft Teams")
|
||||
![Workbench Local | Hosted](https://img.shields.io/badge/Workbench-Local%20%7C%20Hosted-green.svg)
|
||||
|
||||
## Applies to
|
||||
|
||||
* [SharePoint Framework](https://docs.microsoft.com/sharepoint/dev/spfx/sharepoint-framework-overview)
|
||||
|
||||
## Prerequisites
|
||||
1. Build a SharePoint Online list named "FAQ"
|
||||
2. Rename Title column to "Question"
|
||||
3. Add 3 additional columns
|
||||
|
||||
- Multiple lines of text column, toggle 'use rich text' to yes, name "Answer"
|
||||
- Choice column, Options "Work", "Personal", and "Hobby", name "Category"
|
||||
- Yes/no column, set default to No, name "Featured"
|
||||
4. Add items to your list making sure to set some to 'yes' in the featured column
|
||||
5. Navigate to your sites workbench (https://<tenant>.sharepoint.com/sites/<your site>/_layouts/15/workbench.aspx)
|
||||
|
||||
## Solution
|
||||
|
||||
Solution|Author(s)
|
||||
--------|---------
|
||||
react-doccard-faq | Sam Collins ([@samc148](https://twitter.com/samc148))
|
||||
|
||||
## Version history
|
||||
|
||||
Version|Date|Comments
|
||||
-------|----|--------
|
||||
1.0|April 5, 2021|Initial release
|
||||
|
||||
## Disclaimer
|
||||
|
||||
**THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.**
|
||||
|
||||
---
|
||||
|
||||
## Minimal Path to Awesome
|
||||
|
||||
* Clone this repository
|
||||
* in the command line run:
|
||||
* `npm install`
|
||||
* `gulp serve`
|
||||
|
||||
## Features
|
||||
|
||||
DefaultButton,
|
||||
Modal,
|
||||
DetailsList,
|
||||
IColumn,
|
||||
from office-ui-fabric-react
|
||||
|
||||
IPropertyPaneDropdownOption
|
||||
from @microsoft/sp-property-pane
|
||||
|
||||
RichText,
|
||||
Accessible Accordion
|
||||
from @pnp/spfx-controls-react
|
||||
|
||||
<img src="https://telemetry.sharepointpnp.com/sp-dev-fx-webparts/samples/readme-template" />
|
Binary file not shown.
After Width: | Height: | Size: 5.3 MiB |
Binary file not shown.
After Width: | Height: | Size: 92 KiB |
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/config.2.0.schema.json",
|
||||
"version": "2.0",
|
||||
"bundles": {
|
||||
"react-doc-card-faq-web-part": {
|
||||
"components": [
|
||||
{
|
||||
"entrypoint": "./lib/webparts/reactDocCardFaq/ReactDocCardFaqWebPart.js",
|
||||
"manifest": "./src/webparts/reactDocCardFaq/ReactDocCardFaqWebPart.manifest.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"externals": {},
|
||||
"localizedResources": {
|
||||
"ReactDocCardFaqWebPartStrings": "lib/webparts/reactDocCardFaq/loc/{locale}.js",
|
||||
"PropertyControlStrings": "node_modules/@pnp/spfx-property-controls/lib/loc/{locale}.js",
|
||||
"ControlStrings": "node_modules/@pnp/spfx-controls-react/lib/loc/{locale}.js"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/copy-assets.schema.json",
|
||||
"deployCdnPath": "temp/deploy"
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/deploy-azure-storage.schema.json",
|
||||
"workingDir": "./temp/deploy/",
|
||||
"account": "<!-- STORAGE ACCOUNT NAME -->",
|
||||
"container": "react-faq-video",
|
||||
"accessKey": "<!-- ACCESS KEY -->"
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/package-solution.schema.json",
|
||||
"solution": {
|
||||
"name": "react-faq-video-client-side-solution",
|
||||
"id": "881b043c-c29d-4a28-bbe7-28478486b8bb",
|
||||
"version": "1.0.0.0",
|
||||
"includeClientSideAssets": true,
|
||||
"isDomainIsolated": false
|
||||
},
|
||||
"paths": {
|
||||
"zippedPackage": "solution/react-faq-video.sppkg"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/core-build/serve.schema.json",
|
||||
"port": 4321,
|
||||
"https": true,
|
||||
"initialPage": "https://localhost:5432/workbench",
|
||||
"api": {
|
||||
"port": 5432,
|
||||
"entryPath": "node_modules/@microsoft/sp-webpart-workbench/lib/api/"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/write-manifests.schema.json",
|
||||
"cdnBasePath": "<!-- PATH TO CDN -->"
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
const build = require('@microsoft/sp-build-web');
|
||||
|
||||
build.addSuppression(`Warning - [sass] The local CSS class 'ms-Grid' is not camelCase and will not be type-safe.`);
|
||||
|
||||
build.initialize(require('gulp'));
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,44 @@
|
|||
{
|
||||
"name": "react-faq-video",
|
||||
"version": "0.0.1",
|
||||
"private": true,
|
||||
"main": "lib/index.js",
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "gulp bundle",
|
||||
"clean": "gulp clean",
|
||||
"test": "gulp test"
|
||||
},
|
||||
"dependencies": {
|
||||
"@microsoft/sp-core-library": "1.10.0",
|
||||
"@microsoft/sp-lodash-subset": "1.10.0",
|
||||
"@microsoft/sp-office-ui-fabric-core": "1.10.0",
|
||||
"@microsoft/sp-property-pane": "1.10.0",
|
||||
"@microsoft/sp-webpart-base": "1.10.0",
|
||||
"@pnp/spfx-controls-react": "2.5.0",
|
||||
"@pnp/spfx-property-controls": "^2.3.0",
|
||||
"@types/es6-promise": "0.0.33",
|
||||
"@types/react": "16.8.8",
|
||||
"@types/react-dom": "16.8.3",
|
||||
"@types/webpack-env": "1.13.1",
|
||||
"office-ui-fabric-react": "6.189.2",
|
||||
"react": "16.8.5",
|
||||
"react-dom": "16.8.5"
|
||||
},
|
||||
"resolutions": {
|
||||
"@types/react": "16.8.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@microsoft/sp-build-web": "1.10.0",
|
||||
"@microsoft/sp-tslint-rules": "1.10.0",
|
||||
"@microsoft/sp-module-interfaces": "1.10.0",
|
||||
"@microsoft/sp-webpart-workbench": "1.10.0",
|
||||
"@microsoft/rush-stack-compiler-3.3": "0.3.5",
|
||||
"gulp": "~3.9.1",
|
||||
"@types/chai": "3.4.34",
|
||||
"@types/mocha": "2.2.38",
|
||||
"ajv": "~5.2.2"
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
// A file is required to be in the root of the /src directory by the TypeScript compiler
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx/client-side-web-part-manifest.schema.json",
|
||||
"id": "791fb4fb-9abf-49e2-9ee4-8c5f2566e7e3",
|
||||
"alias": "ReactDocCardFaqWebPart",
|
||||
"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,
|
||||
"supportedHosts": ["SharePointWebPart"],
|
||||
|
||||
"preconfiguredEntries": [{
|
||||
"groupId": "5c03119e-3074-46fd-976b-c60198311f70", // Other
|
||||
"group": { "default": "Other" },
|
||||
"title": { "default": "react-docCard-faq" },
|
||||
"description": { "default": "react-docCard-faq description" },
|
||||
"officeFabricIconFontName": "Page",
|
||||
"properties": {
|
||||
"description": "react-docCard-faq"
|
||||
}
|
||||
}]
|
||||
}
|
|
@ -0,0 +1,103 @@
|
|||
import * as React from 'react';
|
||||
import * as ReactDom from 'react-dom';
|
||||
import { Version } from '@microsoft/sp-core-library';
|
||||
import {
|
||||
IPropertyPaneConfiguration,
|
||||
PropertyPaneTextField, IPropertyPaneDropdownOption
|
||||
} from '@microsoft/sp-property-pane';
|
||||
import { BaseClientSideWebPart } from '@microsoft/sp-webpart-base';
|
||||
|
||||
import * as strings from 'ReactDocCardFaqWebPartStrings';
|
||||
import ReactDocCardFaq from './components/ReactDocCardFaq';
|
||||
import { IReactDocCardFaqProps } from './components/IReactDocCardFaqProps';
|
||||
|
||||
import { IFAQList } from '../reactDocCardFaq/_helpers/listModel';
|
||||
import { listService } from '../reactDocCardFaq/_helpers/listService';
|
||||
|
||||
import { PropertyFieldMultiSelect } from '@pnp/spfx-property-controls/lib/PropertyFieldMultiSelect';
|
||||
|
||||
export interface IReactDocCardFaqWebPartProps {
|
||||
description: string;
|
||||
multiSelect: string[];
|
||||
}
|
||||
|
||||
export default class ReactDocCardFaqWebPart extends BaseClientSideWebPart<IReactDocCardFaqWebPartProps> {
|
||||
private _listService: listService
|
||||
private categories: IPropertyPaneDropdownOption[] = [];
|
||||
|
||||
protected onInit(): Promise<void> {
|
||||
this._listService = new listService(this.context.pageContext.web.absoluteUrl, this.context.spHttpClient);
|
||||
this._getListItems();
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
private _getListItems(): void {
|
||||
let initialCategories = [];
|
||||
let distinctCategories = [];
|
||||
this._listService.getListItems()
|
||||
.then((items: IFAQList[]) => {
|
||||
items.forEach(category => {
|
||||
initialCategories.push(category.Category);
|
||||
});
|
||||
distinctCategories = initialCategories.filter((value, index) => initialCategories.indexOf(value) === index);
|
||||
distinctCategories.forEach(item => {
|
||||
this.categories.push({
|
||||
key: item,
|
||||
text: item
|
||||
});
|
||||
});
|
||||
console.log(this.categories);
|
||||
this.context.propertyPane.refresh();
|
||||
});
|
||||
}
|
||||
|
||||
public render(): void {
|
||||
const element: React.ReactElement<IReactDocCardFaqProps> = React.createElement(
|
||||
ReactDocCardFaq,
|
||||
{
|
||||
description: this.properties.description,
|
||||
context: this.context,
|
||||
absoluteUrl: this.context.pageContext.web.absoluteUrl,
|
||||
multiSelect: this.properties.multiSelect
|
||||
}
|
||||
);
|
||||
|
||||
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: [
|
||||
PropertyPaneTextField('description', {
|
||||
label: strings.DescriptionFieldLabel
|
||||
}),
|
||||
PropertyFieldMultiSelect('multiSelect', {
|
||||
key: 'multiSelect',
|
||||
label: "Select Categories",
|
||||
options: this.categories,
|
||||
selectedKeys: this.properties.multiSelect
|
||||
})
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
export interface IFAQList {
|
||||
Title: string;
|
||||
Answer: string;
|
||||
Category: string;
|
||||
ID: string;
|
||||
Featured: boolean;
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
import {
|
||||
SPHttpClient,
|
||||
SPHttpClientResponse
|
||||
} from '@microsoft/sp-http';
|
||||
|
||||
import { IFAQList } from './listModel';
|
||||
|
||||
const LIST_API_ENDPOINT: string = `/_api/web/lists/getbytitle('FAQ')`;
|
||||
const SELECT_QUERY: string = '$select=Id,Title,Answer,Category,Featured';
|
||||
|
||||
export class listService {
|
||||
constructor(private siteAbsoluteUrl: string, private client: SPHttpClient) { }
|
||||
|
||||
public getListItems(): Promise<IFAQList[]> {
|
||||
let promise: Promise<IFAQList[]> = new Promise<IFAQList[]>((resolve, reject) => {
|
||||
this.client.get(`${this.siteAbsoluteUrl}${LIST_API_ENDPOINT}/items?${SELECT_QUERY}`,
|
||||
SPHttpClient.configurations.v1
|
||||
) // get response & parse body as JSON
|
||||
.then((response: SPHttpClientResponse): Promise<{ value: IFAQList[] }> => {
|
||||
return response.json();
|
||||
}) // get parsed response as array, and return
|
||||
.then((response: { value: IFAQList[] }) => {
|
||||
resolve(response.value);
|
||||
})
|
||||
.catch((error: any) => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
return promise;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
import * as React from 'react';
|
||||
|
||||
import { Modal } from 'office-ui-fabric-react/lib/Modal';
|
||||
import {IAnswerModalState} from './IAnswerModalState';
|
||||
|
||||
import { RichText } from "@pnp/spfx-controls-react/lib/RichText";
|
||||
|
||||
export class AnswerModal extends React.Component<{}, IAnswerModalState> {
|
||||
private myRichText;
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.closeAnswerModal = this.closeAnswerModal.bind(this);
|
||||
this.showAnswerModal = this.showAnswerModal.bind(this);
|
||||
this.state = {
|
||||
openAnswerModal: false,
|
||||
answer: "",
|
||||
question: ""
|
||||
};
|
||||
}
|
||||
|
||||
public showAnswerModal(question, answer): void {
|
||||
this.setState({
|
||||
question: question,
|
||||
answer: answer,
|
||||
openAnswerModal: true
|
||||
});
|
||||
}
|
||||
|
||||
public closeAnswerModal():void {
|
||||
this.setState({
|
||||
openAnswerModal: false
|
||||
});
|
||||
}
|
||||
|
||||
private onTextChange = (newText: string) => {
|
||||
this.myRichText = newText;
|
||||
return newText;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public render(): React.ReactElement<{}> {
|
||||
return (
|
||||
<Modal
|
||||
isOpen={this.state.openAnswerModal}
|
||||
onDismiss={this.closeAnswerModal} >
|
||||
|
||||
<div style={{ maxWidth: '700px', minWidth: '400px' }}>
|
||||
<div style={{ textAlign: 'center', fontSize: '20px', padding: '10px' }}>{this.state.question}</div>
|
||||
<div style={{ width: '100%', background: 'rgba(0, 0, 0, 0.3)', height: '2px' }}></div>
|
||||
<div>
|
||||
<RichText value={this.state.answer}
|
||||
onChange={(text) => this.onTextChange(text)} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
export interface IAnswerModalState {
|
||||
openAnswerModal: boolean;
|
||||
question: string;
|
||||
answer: string;
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
export interface IReactDocCardFaqProps {
|
||||
description: string;
|
||||
context: any;
|
||||
absoluteUrl: any;
|
||||
multiSelect: string[];
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
import { IFAQList } from '../_helpers/listModel';
|
||||
|
||||
export interface IReactDocCardFaqState {
|
||||
questions: IFAQList[];
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
import { IColumn } from 'office-ui-fabric-react/lib/DetailsList';
|
||||
import { IFAQList } from '../../_helpers/listModel';
|
||||
|
||||
export interface IQuestionsModalState {
|
||||
questions: IFAQList[];
|
||||
openQuestionsModal: boolean;
|
||||
columns: IColumn[];
|
||||
titleCategory: string;
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
import * as React from 'react';
|
||||
import { IQuestionsModalState } from './IQuestionsModalState';
|
||||
|
||||
import { Modal } from 'office-ui-fabric-react/lib/Modal';
|
||||
import {
|
||||
DetailsList,
|
||||
IColumn,
|
||||
} from 'office-ui-fabric-react/lib/DetailsList';
|
||||
|
||||
import {
|
||||
Accordion,
|
||||
AccordionItem,
|
||||
AccordionItemHeading,
|
||||
AccordionItemButton,
|
||||
AccordionItemPanel,
|
||||
} from "@pnp/spfx-controls-react/lib/AccessibleAccordion";
|
||||
import { RichText } from "@pnp/spfx-controls-react/lib/RichText";
|
||||
|
||||
export class QuestionsModal extends React.Component<{}, IQuestionsModalState> {
|
||||
private myRichText;
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.closeQuestionsModal = this.closeQuestionsModal.bind(this);
|
||||
this.showQuestionsModal = this.showQuestionsModal.bind(this);
|
||||
const columns: IColumn[] = [
|
||||
{
|
||||
key: 'Question',
|
||||
name: 'Question',
|
||||
fieldName: 'Title',
|
||||
minWidth: 210
|
||||
},
|
||||
{
|
||||
key: 'Answer',
|
||||
name: 'Answer',
|
||||
fieldName: 'Answer',
|
||||
minWidth: 210
|
||||
}
|
||||
];
|
||||
this.state = {
|
||||
columns: columns,
|
||||
questions: [],
|
||||
openQuestionsModal: false,
|
||||
titleCategory: ""
|
||||
};
|
||||
}
|
||||
|
||||
public showQuestionsModal(questions): void {
|
||||
this.setState({
|
||||
questions: questions,
|
||||
openQuestionsModal: true,
|
||||
titleCategory: questions[0].Category
|
||||
});
|
||||
}
|
||||
|
||||
public closeQuestionsModal(): void {
|
||||
this.setState({
|
||||
openQuestionsModal: false
|
||||
});
|
||||
}
|
||||
|
||||
private onTextChange = (newText: string) => {
|
||||
this.myRichText = newText;
|
||||
return newText;
|
||||
}
|
||||
|
||||
|
||||
public render(): React.ReactElement<{}> {
|
||||
return (
|
||||
<div>
|
||||
<Modal
|
||||
isOpen={this.state.openQuestionsModal}
|
||||
onDismiss={this.closeQuestionsModal}>
|
||||
|
||||
<Accordion allowZeroExpanded style={{ width: '700px' }} >
|
||||
<div style={{ textAlign: 'center', fontSize: '20px', padding: '10px' }} >{this.state.titleCategory}</div>
|
||||
|
||||
{this.state.questions.map((question) => {
|
||||
return (
|
||||
<AccordionItem >
|
||||
<AccordionItemHeading >
|
||||
<AccordionItemButton >
|
||||
{question.Title}
|
||||
</AccordionItemButton>
|
||||
</AccordionItemHeading>
|
||||
|
||||
<AccordionItemPanel>
|
||||
<RichText value={question.Answer}
|
||||
onChange={(text) => this.onTextChange(text)} />
|
||||
</AccordionItemPanel>
|
||||
|
||||
</AccordionItem>
|
||||
);
|
||||
})}
|
||||
</Accordion>
|
||||
|
||||
</Modal>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
@import '~office-ui-fabric-react/dist/sass/References.scss';
|
||||
|
||||
.docCardContainer {
|
||||
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
.docCardObj{
|
||||
display: -webkit-inline-box;
|
||||
display: -ms-inline-flexbox;
|
||||
display: inline-flex;
|
||||
margin-right: 15px;
|
||||
}
|
||||
.docCard {
|
||||
width: 300px;
|
||||
height: 300px;
|
||||
border: $ms-color-themeDark;
|
||||
border-style: double;
|
||||
margin-bottom: 15px;
|
||||
padding-bottom: 15px;
|
||||
padding-right: 15px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.docCardTitle {
|
||||
font-size: large;
|
||||
font-weight: 600;
|
||||
text-decoration: underline;
|
||||
color: $ms-color-themeDark ;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.docCardQuestionButtonDiv {
|
||||
padding-bottom: 20px;
|
||||
padding-top: 20px;
|
||||
}
|
||||
|
||||
|
||||
.docCardQuestionButton {
|
||||
width: 90%;
|
||||
color: $ms-color-themeDark;
|
||||
outline: $ms-color-themePrimary;
|
||||
outline-style: solid;
|
||||
outline-width: 1px;
|
||||
background-color: white;
|
||||
margin: 0 auto;
|
||||
display: block;
|
||||
size: 9px;
|
||||
}
|
||||
|
||||
.docCardQuestionButton:hover {
|
||||
background-color: $ms-color-themeDark;
|
||||
color: white;
|
||||
font-weight: 600;
|
||||
|
||||
}
|
|
@ -0,0 +1,100 @@
|
|||
import * as React from 'react';
|
||||
import styles from './ReactDocCardFaq.module.scss';
|
||||
import { IReactDocCardFaqProps } from './IReactDocCardFaqProps';
|
||||
import { escape, fromPairs } from '@microsoft/sp-lodash-subset';
|
||||
|
||||
import { DocumentCard, DocumentCardDetails, DocumentCardTitle } from 'office-ui-fabric-react/lib/DocumentCard';
|
||||
import { DefaultButton } from 'office-ui-fabric-react/lib/Button';
|
||||
|
||||
import { IFAQList } from '../_helpers/listModel';
|
||||
import { listService } from '../_helpers/listService';
|
||||
|
||||
import { IReactDocCardFaqState } from './IReactDocCardFaqState';
|
||||
import { AnswerModal } from './AnswerModal/AnswerModal';
|
||||
import { QuestionsModal } from './QuestionsModal/QuestionsModal';
|
||||
|
||||
export default class ReactDocCardFaq extends React.Component<IReactDocCardFaqProps, IReactDocCardFaqState> {
|
||||
private _listService: listService;
|
||||
private _AnswerModal: AnswerModal;
|
||||
private _QuestionsModal: QuestionsModal;
|
||||
private modalQuestions: IFAQList[];
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.answerModal = this.answerModal.bind(this);
|
||||
this.questionsModal = this.questionsModal.bind(this);
|
||||
this.state = {
|
||||
questions: []
|
||||
};
|
||||
}
|
||||
|
||||
private questionsModal(category)
|
||||
{
|
||||
this.modalQuestions = this.state.questions.filter((question) => {
|
||||
return question.Category === category;
|
||||
});
|
||||
this._QuestionsModal.showQuestionsModal(this.modalQuestions);
|
||||
}
|
||||
|
||||
private answerModal(question, answer)
|
||||
{
|
||||
|
||||
this._AnswerModal.showAnswerModal(question, answer);
|
||||
|
||||
}
|
||||
|
||||
public componentDidMount(): void {
|
||||
this._listService = new listService(this.props.absoluteUrl, this.props.context.spHttpClient);
|
||||
this._getFAQItems();
|
||||
}
|
||||
|
||||
private _getFAQItems(): void {
|
||||
this._listService.getListItems()
|
||||
.then((items: IFAQList[]) => {
|
||||
this.setState({ questions: items });
|
||||
});
|
||||
}
|
||||
|
||||
public render(): React.ReactElement<IReactDocCardFaqProps> {
|
||||
if (this.props.multiSelect == undefined || this.props.multiSelect.length <= 0) {
|
||||
|
||||
return (
|
||||
<div>Please Select Categories</div>
|
||||
);
|
||||
}
|
||||
else if (this.props.multiSelect.length > 0) {
|
||||
|
||||
return (
|
||||
<div className={styles.docCardContainer}>
|
||||
{this.props.multiSelect.map((category) => {
|
||||
return (
|
||||
<div className={styles.docCardObj}>
|
||||
<DocumentCard className={styles.docCard}>
|
||||
<a onClick={this.questionsModal.bind(this, category)}> <DocumentCardTitle title={category} className={styles.docCardTitle}></DocumentCardTitle></a>
|
||||
|
||||
|
||||
{this.state.questions.map((question) => {if (question.Category === category && question.Featured == true) {
|
||||
return (
|
||||
<DocumentCardDetails >
|
||||
<div className={styles.docCardQuestionButtonDiv}>
|
||||
<DefaultButton className={styles.docCardQuestionButton} onClick={this.answerModal.bind(this, question.Title, question.Answer)}>
|
||||
{question.Title}
|
||||
</DefaultButton>
|
||||
</div>
|
||||
</DocumentCardDetails>
|
||||
);
|
||||
}
|
||||
})}
|
||||
</DocumentCard>
|
||||
<AnswerModal ref={component => this._AnswerModal = component}></AnswerModal>
|
||||
<QuestionsModal ref={component => this._QuestionsModal = component}></QuestionsModal>
|
||||
|
||||
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
define([], function() {
|
||||
return {
|
||||
"PropertyPaneDescription": "Description",
|
||||
"BasicGroupName": "Group Name",
|
||||
"DescriptionFieldLabel": "Description Field"
|
||||
}
|
||||
});
|
|
@ -0,0 +1,10 @@
|
|||
declare interface IReactDocCardFaqWebPartStrings {
|
||||
PropertyPaneDescription: string;
|
||||
BasicGroupName: string;
|
||||
DescriptionFieldLabel: string;
|
||||
}
|
||||
|
||||
declare module 'ReactDocCardFaqWebPartStrings' {
|
||||
const strings: IReactDocCardFaqWebPartStrings;
|
||||
export = strings;
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 3.0 KiB |
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
|
@ -0,0 +1,38 @@
|
|||
{
|
||||
"extends": "./node_modules/@microsoft/rush-stack-compiler-3.3/includes/tsconfig-web.json",
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"jsx": "react",
|
||||
"declaration": true,
|
||||
"sourceMap": true,
|
||||
"experimentalDecorators": true,
|
||||
"skipLibCheck": true,
|
||||
"outDir": "lib",
|
||||
"inlineSources": false,
|
||||
"strictNullChecks": false,
|
||||
"noUnusedLocals": false,
|
||||
"typeRoots": [
|
||||
"./node_modules/@types",
|
||||
"./node_modules/@microsoft"
|
||||
],
|
||||
"types": [
|
||||
"es6-promise",
|
||||
"webpack-env"
|
||||
],
|
||||
"lib": [
|
||||
"es5",
|
||||
"dom",
|
||||
"es2015.collection"
|
||||
]
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.ts"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"lib"
|
||||
]
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
{
|
||||
"extends": "@microsoft/sp-tslint-rules/base-tslint.json",
|
||||
"rules": {
|
||||
"class-name": false,
|
||||
"export-name": false,
|
||||
"forin": false,
|
||||
"label-position": false,
|
||||
"member-access": true,
|
||||
"no-arg": false,
|
||||
"no-console": false,
|
||||
"no-construct": false,
|
||||
"no-duplicate-variable": true,
|
||||
"no-eval": false,
|
||||
"no-function-expression": true,
|
||||
"no-internal-module": true,
|
||||
"no-shadowed-variable": true,
|
||||
"no-switch-case-fall-through": true,
|
||||
"no-unnecessary-semicolons": true,
|
||||
"no-unused-expression": true,
|
||||
"no-use-before-declare": true,
|
||||
"no-with-statement": true,
|
||||
"semicolon": true,
|
||||
"trailing-comma": false,
|
||||
"typedef": false,
|
||||
"typedef-whitespace": false,
|
||||
"use-named-parameter": true,
|
||||
"variable-name": false,
|
||||
"whitespace": false
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue