Added hover styles that leverage theme variants

This commit is contained in:
Hugo Bernier 2020-04-18 15:41:24 -04:00
parent 5b3309e5c7
commit 3d0700133a
3 changed files with 54 additions and 26 deletions

View File

@ -40,6 +40,7 @@ export class DateBox extends React.Component<IDateBoxProps, {}> {
style={ style={
themeVariant && themeVariant &&
{ {
// KLUDGE: It seems like the themeVariant palette doesn't expose primaryBackground
backgroundColor: themeVariant.palette["primaryBackground"], backgroundColor: themeVariant.palette["primaryBackground"],
borderColor: themeVariant.semanticColors.bodyDivider borderColor: themeVariant.semanticColors.bodyDivider
}}> }}>

View File

@ -5,6 +5,7 @@ import Slider from 'react-slick';
import { SPComponentLoader } from '@microsoft/sp-loader'; import { SPComponentLoader } from '@microsoft/sp-loader';
import styles from "./FilmstripLayout.module.scss"; import styles from "./FilmstripLayout.module.scss";
import { useRef } from 'react'; import { useRef } from 'react';
import { IReadonlyTheme } from '@microsoft/sp-component-base';
function useBreakpoints(currentWidth: number, breakpoints: number[]) { function useBreakpoints(currentWidth: number, breakpoints: number[]) {
return breakpoints.map(breakpoint => currentWidth < breakpoint); return breakpoints.map(breakpoint => currentWidth < breakpoint);
@ -14,7 +15,7 @@ function useBreakpoints(currentWidth: number, breakpoints: number[]) {
* Filmstrip layout * Filmstrip layout
* Presents the child compoments as a slick slide * Presents the child compoments as a slick slide
*/ */
export const FilmstripLayout = (props: { children: any; clientWidth: number; ariaLabel?: string; }) => { export const FilmstripLayout = (props: { children: any; clientWidth: number; themeVariant?: IReadonlyTheme, ariaLabel?: string; }) => {
let ref: React.MutableRefObject<HTMLDivElement> = useRef<HTMLDivElement>(null); let ref: React.MutableRefObject<HTMLDivElement> = useRef<HTMLDivElement>(null);
// // the slick slider used in normal views // // the slick slider used in normal views
@ -62,6 +63,30 @@ export const FilmstripLayout = (props: { children: any; clientWidth: number; ari
}; };
return ( return (
<>
{/*
KLUDGE:
This is a cheaty way to inject styles from the theme variant when the component does not support theme variant customizations.
We can do this without too much nastiness because this component is added only once per web part
... but I still wish there was a better way
*/}
{props.themeVariant && <style>{`
.${styles.carouselDot} {
background-color: ${props.themeVariant.palette.black}!important;
border-color: ${props.themeVariant.palette.black}!important;
}
.slick-active .${styles.carouselDot} {
background-color: ${props.themeVariant.palette.themeDark}!important;
border-color: ${props.themeVariant.palette.themeDark}!important;
}
.${styles.filmstripLayout} .ms-DocumentCard--actionable:hover {
border-color: ${props.themeVariant.semanticColors.variantBorderHovered}!important;
}
`}
</style>
}
<div> <div>
<div className={css(styles.filmstripLayout, styles.filmStrip)} aria-label={props.ariaLabel} ref={ref}> <div className={css(styles.filmstripLayout, styles.filmStrip)} aria-label={props.ariaLabel} ref={ref}>
<Slider ref={_slider} {...settings}> <Slider ref={_slider} {...settings}>
@ -89,5 +114,6 @@ export const FilmstripLayout = (props: { children: any; clientWidth: number; ari
</div> </div>
</div> </div>
</div> </div>
</>
); );
}; };

View File

@ -298,6 +298,7 @@ export default class CalendarFeedSummary extends React.Component<ICalendarFeedSu
<FilmstripLayout <FilmstripLayout
ariaLabel={strings.FilmStripAriaLabel} ariaLabel={strings.FilmStripAriaLabel}
clientWidth={this.props.clientWidth} clientWidth={this.props.clientWidth}
themeVariant={this.props.themeVariant}
> >
{events.map((event: ICalendarEvent, index: number) => { {events.map((event: ICalendarEvent, index: number) => {
return (<EventCard return (<EventCard