Skip to content

Commit edafd19

Browse files
committed
Hiding title on small zones
1 parent 94b0920 commit edafd19

File tree

5 files changed

+68
-7
lines changed

5 files changed

+68
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## 1.2.4
44

5+
**Enhancements**
6+
- Hiding placeholder web part on small zones
7+
58
**Fixes**
69
- iFrame dialog reference fix [#52 - Need some more implementation documentation on IFrameDialog](https://github.com/SharePoint/sp-dev-fx-controls-react/issues/52)
710

docs/documentation/docs/about/release-notes.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## 1.2.4
44

5+
**Enhancements**
6+
- Hiding placeholder web part on small zones
7+
58
**Fixes**
69
- iFrame dialog reference fix [#52 - Need some more implementation documentation on IFrameDialog](https://github.com/SharePoint/sp-dev-fx-controls-react/issues/52)
710

src/controls/placeholder/IPlaceholderComponent.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,7 @@ export interface IPlaceholderProps {
3232
*/
3333
contentClassName?: string;
3434
}
35+
36+
export interface IPlaceholderState {
37+
width: number;
38+
}

src/controls/placeholder/PlaceholderComponent.module.scss

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,13 @@
2929
}
3030

3131
.placeholderText {
32-
display: inline-block;
32+
display: inline;
3333
vertical-align: middle;
34-
white-space: normal
34+
white-space: normal;
35+
36+
&.hide {
37+
display: none;
38+
}
3539
}
3640
}
3741

src/controls/placeholder/PlaceholderComponent.tsx

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,24 @@ import { IPlaceholderProps } from './IPlaceholderComponent';
33
import { PrimaryButton } from 'office-ui-fabric-react/lib/Button';
44
import styles from './PlaceholderComponent.module.scss';
55
import * as appInsights from '../../common/appInsights';
6+
import { IPlaceholderState } from '.';
67

78
/**
89
* Placeholder component
910
*/
10-
export class Placeholder extends React.Component<IPlaceholderProps, {}> {
11+
export class Placeholder extends React.Component<IPlaceholderProps, IPlaceholderState> {
12+
private _crntElm: HTMLDivElement = null;
13+
1114
/**
1215
* Constructor
1316
*/
1417
constructor(props: IPlaceholderProps) {
1518
super(props);
1619

20+
this.state = {
21+
width: null
22+
};
23+
1724
appInsights.track('ReactPlaceholder', {
1825
description: !!props.description,
1926
iconName: !!props.iconName,
@@ -22,32 +29,72 @@ export class Placeholder extends React.Component<IPlaceholderProps, {}> {
2229
onConfigure: !!props.onConfigure,
2330
contentClassName: !!props.contentClassName
2431
});
32+
}
33+
34+
/**
35+
* componentDidMount lifecycle hook
36+
*/
37+
public componentDidMount(): void {
38+
this._setZoneWidth();
39+
}
40+
41+
/**
42+
* componentDidUpdate lifecycle hook
43+
* @param prevProps
44+
* @param prevState
45+
*/
46+
public componentDidUpdate(prevProps: IPlaceholderProps, prevState: IPlaceholderState): void {
47+
this._setZoneWidth();
48+
}
2549

26-
this._handleBtnClick = this._handleBtnClick.bind(this);
50+
/**
51+
* shouldComponentUpdate lifecycle hook
52+
* @param nextProps
53+
* @param nextState
54+
*/
55+
public shouldComponentUpdate(nextProps: IPlaceholderProps, nextState: IPlaceholderState): boolean {
56+
return this.state.width !== nextState.width;
2757
}
2858

2959
/**
3060
* Execute the onConfigure function
3161
*/
32-
private _handleBtnClick(event?: React.MouseEvent<HTMLButtonElement>) {
62+
private _handleBtnClick = (event?: React.MouseEvent<HTMLButtonElement>): void => {
3363
this.props.onConfigure();
3464
}
3565

66+
/**
67+
* Set the current zone width
68+
*/
69+
private _setZoneWidth = () => {
70+
this.setState({
71+
width: this._crntElm.clientWidth
72+
});
73+
console.log(this._crntElm.offsetWidth, this._crntElm.clientWidth);
74+
}
75+
76+
/**
77+
* Stores the current element
78+
*/
79+
private _linkElm = (e: HTMLDivElement) => {
80+
this._crntElm = e;
81+
}
82+
3683
/**
3784
* Default React component render method
3885
*/
3986
public render(): React.ReactElement<IPlaceholderProps> {
4087
const iconName = typeof this.props.iconName !== 'undefined' && this.props.iconName !== null ? `ms-Icon--${this.props.iconName}` : '';
4188

4289
return (
43-
<div className={`${styles.placeholder} ${this.props.contentClassName ? this.props.contentClassName : ''}`}>
90+
<div className={`${styles.placeholder} ${this.props.contentClassName ? this.props.contentClassName : ''}`} ref={this._linkElm}>
4491
<div className={styles.placeholderContainer}>
4592
<div className={styles.placeholderHead}>
4693
<div className={styles.placeholderHeadContainer}>
4794
{
4895
iconName ? <i className={`${styles.placeholderIcon} ms-fontSize-su ms-Icon ${iconName}`}></i> : ''
4996
}
50-
<span className={`${styles.placeholderText} ms-fontWeight-light ms-fontSize-xxl`}>{this.props.iconText}</span>
97+
<span className={`${styles.placeholderText} ms-fontWeight-light ms-fontSize-xxl ${(this.state.width && this.state.width <= 380) ? styles.hide : "" }`}>{this.props.iconText}</span>
5198
</div>
5299
</div>
53100
<div className={styles.placeholderDescription}>

0 commit comments

Comments
 (0)