diff --git a/samples/react-calendar-feed/package-lock.json b/samples/react-calendar-feed/package-lock.json index 17fe2a7a9..e92ca3c3a 100644 --- a/samples/react-calendar-feed/package-lock.json +++ b/samples/react-calendar-feed/package-lock.json @@ -4878,6 +4878,11 @@ "integrity": "sha512-NsEzBVa5aMgn/n79piyJtpUQFzJ97tB2R2r8PSJlLnMA6LJmchKuv7ATN+/nZH/3QRd/+uFXEq07/i/ajsqVGQ==", "dev": true }, + "@rehooks/component-size": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@rehooks/component-size/-/component-size-1.0.3.tgz", + "integrity": "sha512-pnYld+8SSF2vXwdLOqBGUyOrv/SjzwLjIUcs/4c1JJgR0q4E9eBtBfuZMD6zUD51fvSehSsbnlQMzotSmPTXPg==" + }, "@types/adal-angular": { "version": "1.0.1", "resolved": "http://registry.npmjs.org/@types/adal-angular/-/adal-angular-1.0.1.tgz", diff --git a/samples/react-calendar-feed/package.json b/samples/react-calendar-feed/package.json index 3b811f9b6..1a97a4811 100644 --- a/samples/react-calendar-feed/package.json +++ b/samples/react-calendar-feed/package.json @@ -23,6 +23,7 @@ "@pnp/sp": "^1.2.8", "@pnp/spfx-controls-react": "^1.11.0", "@pnp/spfx-property-controls": "^1.13.1", + "@rehooks/component-size": "^1.0.3", "@types/es6-promise": "0.0.33", "@types/react": "16.8.8", "@types/react-dom": "16.8.3", diff --git a/samples/react-calendar-feed/src/shared/components/DateBox/DateBox.tsx b/samples/react-calendar-feed/src/shared/components/DateBox/DateBox.tsx index 81eefb650..99e213c77 100644 --- a/samples/react-calendar-feed/src/shared/components/DateBox/DateBox.tsx +++ b/samples/react-calendar-feed/src/shared/components/DateBox/DateBox.tsx @@ -3,12 +3,11 @@ import { css } from "office-ui-fabric-react/lib/Utilities"; import * as React from "react"; import styles from "./DateBox.module.scss"; import { DateBoxSize, IDateBoxProps } from "."; -import { IDateBoxState } from "./IDateBoxState"; /** * Shows a date in a SharePoint-looking date */ -export class DateBox extends React.Component { +export class DateBox extends React.Component { public render(): React.ReactElement { // convert start and end date into moments so that we can manipulate them const startMoment: moment.Moment = moment(this.props.startDate); diff --git a/samples/react-calendar-feed/src/shared/components/DateBox/IDateBoxState.ts b/samples/react-calendar-feed/src/shared/components/DateBox/IDateBoxState.ts deleted file mode 100644 index 6fa6c990a..000000000 --- a/samples/react-calendar-feed/src/shared/components/DateBox/IDateBoxState.ts +++ /dev/null @@ -1,3 +0,0 @@ -export interface IDateBoxState { - // you just proved advertising works! -} diff --git a/samples/react-calendar-feed/src/shared/components/EventCard/EventCard.tsx b/samples/react-calendar-feed/src/shared/components/EventCard/EventCard.tsx index 7f2662c39..bc06b2da7 100644 --- a/samples/react-calendar-feed/src/shared/components/EventCard/EventCard.tsx +++ b/samples/react-calendar-feed/src/shared/components/EventCard/EventCard.tsx @@ -5,14 +5,13 @@ import * as moment from "moment"; import { ActionButton, DocumentCard, DocumentCardType, FocusZone, css } from "office-ui-fabric-react"; import * as React from "react"; import { IEventCardProps } from "."; -import { IEventCardState } from "./IEventCardState"; import { DateBox, DateBoxSize } from "../DateBox"; import styles from "./EventCard.module.scss"; import { Text } from "@microsoft/sp-core-library"; /** * Shows an event in a document card */ -export class EventCard extends React.Component { +export class EventCard extends React.Component { public render(): React.ReactElement { const { isNarrow } = this.props; @@ -51,7 +50,7 @@ export class EventCard extends React.Component onClickHref={isEditMode ? null : url} > -
+
{category}
-
{title}
+
{title}
{dateString}
{location}
type={DocumentCardType.compact} onClickHref={url} > -
+
/>
-
{title}
+
{title}
{dateString}
diff --git a/samples/react-calendar-feed/src/shared/components/EventCard/IEventCardState.ts b/samples/react-calendar-feed/src/shared/components/EventCard/IEventCardState.ts deleted file mode 100644 index 0e00fb847..000000000 --- a/samples/react-calendar-feed/src/shared/components/EventCard/IEventCardState.ts +++ /dev/null @@ -1,3 +0,0 @@ -export interface IEventCardState { - // Not in use -} diff --git a/samples/react-calendar-feed/src/shared/components/Paging/IPagingState.ts b/samples/react-calendar-feed/src/shared/components/Paging/IPagingState.ts deleted file mode 100644 index 4fd69e701..000000000 --- a/samples/react-calendar-feed/src/shared/components/Paging/IPagingState.ts +++ /dev/null @@ -1,3 +0,0 @@ -export interface IPagingState { - // Not in use -} diff --git a/samples/react-calendar-feed/src/shared/components/Paging/Paging.tsx b/samples/react-calendar-feed/src/shared/components/Paging/Paging.tsx index c1cfe9fcd..8badaa246 100644 --- a/samples/react-calendar-feed/src/shared/components/Paging/Paging.tsx +++ b/samples/react-calendar-feed/src/shared/components/Paging/Paging.tsx @@ -3,14 +3,13 @@ import { Icon } from "office-ui-fabric-react/lib/Icon"; import { css } from "office-ui-fabric-react/lib/Utilities"; import * as React from "react"; import { IPagingProps } from "."; -import { IPagingState } from "./IPagingState"; import styles from "./Paging.module.scss"; import * as strings from "CalendarFeedSummaryWebPartStrings"; /** * A custom pagination control designed to look & feel like Office UI Fabric */ -export class Paging extends React.Component { +export class Paging extends React.Component { public render(): React.ReactElement { const { currentPage } = this.props; diff --git a/samples/react-calendar-feed/src/shared/components/filmstripLayout/FilmstripLayout.module.scss b/samples/react-calendar-feed/src/shared/components/filmstripLayout/FilmstripLayout.module.scss index e4e8853bc..5c029fca3 100644 --- a/samples/react-calendar-feed/src/shared/components/filmstripLayout/FilmstripLayout.module.scss +++ b/samples/react-calendar-feed/src/shared/components/filmstripLayout/FilmstripLayout.module.scss @@ -7,7 +7,7 @@ position: relative; &.filmStrip { - margin: 0 -10px; + margin-bottom: 27px; :global(.slick-slide) { box-sizing: border-box; diff --git a/samples/react-calendar-feed/src/shared/components/filmstripLayout/FilmstripLayout.tsx b/samples/react-calendar-feed/src/shared/components/filmstripLayout/FilmstripLayout.tsx index 20ab6f971..93aadc197 100644 --- a/samples/react-calendar-feed/src/shared/components/filmstripLayout/FilmstripLayout.tsx +++ b/samples/react-calendar-feed/src/shared/components/filmstripLayout/FilmstripLayout.tsx @@ -2,153 +2,91 @@ import { css } from '@uifabric/utilities/lib/css'; import { IconButton } from 'office-ui-fabric-react/lib/Button'; import * as React from 'react'; import Slider from 'react-slick'; -import { IFilmstripLayoutProps } from "./IFilmstripLayoutProps"; -import { IFilmstripLayoutState} from "./IFilmstripLayoutState"; import { SPComponentLoader } from '@microsoft/sp-loader'; import styles from "./FilmstripLayout.module.scss"; +import { useRef } from 'react'; +import useComponentSize, { ComponentSize } from '@rehooks/component-size'; /** * Filmstrip layout * Presents the child compoments as a slick slide */ -export class FilmstripLayout extends React.Component< - IFilmstripLayoutProps, - IFilmstripLayoutState - > { - // the slick slider used in normal views - private _slider: Slider; +export const FilmstripLayout = (props: { children: any; ariaLabel?: string; }) => { + let ref: React.MutableRefObject = useRef(null); + let size: ComponentSize = useComponentSize(ref); + let { width } = size; - private _container: HTMLDivElement; + // // the slick slider used in normal views + let _slider: React.MutableRefObject = useRef(null); - /** - * - */ - constructor(props: IFilmstripLayoutProps) { - super(props); + SPComponentLoader.loadCss('https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.css'); + SPComponentLoader.loadCss('https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick-theme.min.css'); - this.state = { - dimensions: undefined - }; - - SPComponentLoader.loadCss('https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.css'); - SPComponentLoader.loadCss('https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick-theme.min.css'); + // slick seems to have an issue with having "infinite" mode set to true and having less items than the number of slides per page + // set infinite to true only if there are more than 3 children + let numSlides: number = 3; + if (width) { + if (width > 927) { + numSlides = 4; + } else if (width <= 695) { + numSlides = 2; + } } - public componentDidMount(): void { - if (this._container) { - this.setState({ - dimensions: { - width: this._container.offsetWidth, - height: this._container.offsetHeight, - }, - }); - } - - } - /** - * Renders a slick switch, a slide for each child, and next/previous arrows - */ - public render(): React.ReactElement { - // slick seems to have an issue with having "infinite" mode set to true and having less items than the number of slides per page - // set infinite to true only if there are more than 3 children - - let numSlides: number = 3; - if (this.state.dimensions) { - if (this.state.dimensions.width > 927) { - numSlides = 4; - } else if (this.state.dimensions.width <= 695) { - numSlides = 2; - } - } - - var isInfinite: boolean = React.Children.count(this.props.children) > numSlides; - var settings: any = { - accessibility: true, - arrows: false, - autoplaySpeed: 5000, - dots: true, - //dotsClass: css("slick-dots", styles.slickDots), - customPaging: (i:number)=> { - return ( - -
- -
-
- ); - }, - infinite: isInfinite, - slidesToShow: numSlides, - slidesToScroll: numSlides, - speed: 500, - centerPadding: styles.centerPadding, - pauseOnHover: true, - variableWidth: false, - useCSS: true, - rows: 1, - respondTo: "slider", - // responsive: [ - // // { - // // breakpoint: 1440, - // // settings: { - // // slidesToShow: 4, - // // slidesToScroll: 4, - // // infinite: isInfinite, - // // dots: true - // // } - // // }, - // { - // breakpoint: 1024, - // settings: { - // slidesToShow: 3, - // slidesToScroll: 3, - // infinite: isInfinite, - // dots: true - // } - // }, - // { - // // breakpoint: 754, - // breakpoint: 767, - // settings: { - // slidesToShow: 2, - // slidesToScroll: 2, - // infinite: isInfinite, - // dots: true - // } - // } - // ] - }; - - console.log("Dimensions", this.state.dimensions); - return ( -
- WIDTH: {this.state.dimensions && this.state.dimensions.width} -
(this._container = el)}> - (this._slider = c)} {...settings}> - {this.props.children} - -
this._slider.slickPrev()} - > - -
-
this._slider.slickNext()} - > - + var isInfinite: boolean = React.Children.count(props.children) > numSlides; + var settings: any = { + accessibility: true, + arrows: false, + autoplaySpeed: 5000, + dots: true, + customPaging: (i: number) => { + return ( + +
+
+
+ ); + }, + infinite: isInfinite, + slidesToShow: numSlides, + slidesToScroll: numSlides, + speed: 500, + centerPadding: styles.centerPadding, + pauseOnHover: true, + variableWidth: false, + useCSS: true, + rows: 1, + respondTo: "slider", + }; + + return ( +
+
+ + {props.children} + +
_slider.current.slickPrev()} + > + +
+
_slider.current.slickNext()} + > +
- ); - } -} +
+ ); +}; diff --git a/samples/react-calendar-feed/src/shared/components/filmstripLayout/IFilmstripLayoutProps.ts b/samples/react-calendar-feed/src/shared/components/filmstripLayout/IFilmstripLayoutProps.ts deleted file mode 100644 index a0a8c4663..000000000 --- a/samples/react-calendar-feed/src/shared/components/filmstripLayout/IFilmstripLayoutProps.ts +++ /dev/null @@ -1,3 +0,0 @@ -export interface IFilmstripLayoutProps { - ariaLabel?: string; - } diff --git a/samples/react-calendar-feed/src/shared/components/filmstripLayout/IFilmstripLayoutState.ts b/samples/react-calendar-feed/src/shared/components/filmstripLayout/IFilmstripLayoutState.ts deleted file mode 100644 index 233dfd256..000000000 --- a/samples/react-calendar-feed/src/shared/components/filmstripLayout/IFilmstripLayoutState.ts +++ /dev/null @@ -1,7 +0,0 @@ - -export interface IFilmstripLayoutState { - dimensions: { - width: any; - height: any; - }; - } diff --git a/samples/react-calendar-feed/src/shared/components/filmstripLayout/index.ts b/samples/react-calendar-feed/src/shared/components/filmstripLayout/index.ts index 873b25bc5..db53a6c19 100644 --- a/samples/react-calendar-feed/src/shared/components/filmstripLayout/index.ts +++ b/samples/react-calendar-feed/src/shared/components/filmstripLayout/index.ts @@ -1,2 +1 @@ export * from "./FilmstripLayout"; -export * from "./IFilmstripLayoutProps";