Skip to content

Commit aeddd6e

Browse files
Mark PowneyMark Powney
authored andcommitted
Add themeVariant and color props to WebPartTitle
1 parent e0df446 commit aeddd6e

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/controls/webPartTitle/WebPartTitle.test.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ describe('<WebPartTitle />', () => {
1414
const dummyTitle = "Dummy Title";
1515
const dummyClass = "DummyClass";
1616
const dummyMoreLink = "See all";
17+
const dummyColor = "#ffffff";
1718
const dummyPlaceholder = "News";
1819
const dummyUpdateFnc = sinon.spy((value) => { return value; });
1920

@@ -87,4 +88,17 @@ describe('<WebPartTitle />', () => {
8788
expect(webparttitle.find(`span.${styles.moreLink}`)).to.have.length(0);
8889
done();
8990
});
91+
92+
it('Check color is used if specified', (done) => {
93+
webparttitle = mount(<WebPartTitle displayMode={DisplayMode.Edit} title={dummyTitle} updateProperty={dummyUpdateFnc} color={dummyColor} />);
94+
expect(webparttitle.find(`div.${styles.webPartTitle}`).prop('style')).property("color").to.equal(dummyColor);
95+
done();
96+
});
97+
98+
it('Check theme\'s color is used if specified', (done) => {
99+
webparttitle = mount(<WebPartTitle displayMode={DisplayMode.Edit} title={dummyTitle} updateProperty={dummyUpdateFnc} themeVariant={{ semanticColors: { bodyText: dummyColor }}} />);
100+
expect(webparttitle.find(`div.${styles.webPartTitle}`).prop('style')).property("color").to.equal(dummyColor);
101+
done();
102+
});
103+
90104
});

src/controls/webPartTitle/WebPartTitle.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ export interface IWebPartTitleProps {
1111
className?: string;
1212
placeholder?: string;
1313
moreLink?: JSX.Element | Function;
14+
themeVariant?: any; // TODO: type should be IReadonlyTheme from @microsoft/sp-component-base
15+
color?: string;
1416
}
1517

1618
/**
@@ -43,10 +45,14 @@ export class WebPartTitle extends React.Component<IWebPartTitleProps, {}> {
4345
* Default React component render method
4446
*/
4547
public render(): React.ReactElement<IWebPartTitleProps> {
48+
49+
const color: string = (!!this.props.themeVariant && this.props.themeVariant.semanticColors.bodyText)
50+
|| this.props.color || null;
51+
4652
if (this.props.title || this.props.moreLink || this.props.displayMode === DisplayMode.Edit) {
4753
return (
4854
<div className={`${styles.webPartHeader} ${this.props.className ? this.props.className : ""}`}>
49-
<div className={styles.webPartTitle}>
55+
<div className={styles.webPartTitle} style={{color: color}}>
5056
{
5157
this.props.displayMode === DisplayMode.Edit && (
5258
<textarea placeholder={this.props.placeholder ? this.props.placeholder : strings.WebPartTitlePlaceholder} aria-label={strings.WebPartTitleLabel} onChange={this._onChange} defaultValue={this.props.title}></textarea>

0 commit comments

Comments
 (0)