Skip to content

Commit 64c1813

Browse files
committed
Merge pull request #236 from salesforce-ux/page-header
Added the page header component and associated demo page
2 parents 40a26bb + 6633a47 commit 64c1813

File tree

27 files changed

+1985
-2
lines changed

27 files changed

+1985
-2
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
Copyright (c) 2015, salesforce.com, inc. All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5+
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6+
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
7+
Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
8+
9+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
10+
*/
11+
12+
import React, { Component } from 'react';
13+
import classnames from 'classnames';
14+
import omit from 'lodash.omit';
15+
16+
const displayName = 'SLDSPageHeaderBase';
17+
const propTypes = {
18+
/**
19+
* Icon node passed by SLDSPageHeader
20+
*/
21+
icon: React.PropTypes.node,
22+
/**
23+
* Title node passed by SLDSPageHeader
24+
*/
25+
title: React.PropTypes.node,
26+
/**
27+
* Info node passed by SLDSPageHeader
28+
*/
29+
info: React.PropTypes.node,
30+
};
31+
const defaultProps = {};
32+
33+
class Base extends Component {
34+
render() {
35+
return (
36+
<div className="slds-media slds-media--center">
37+
<div className="slds-media__figure">
38+
{ this.props.icon }
39+
</div>
40+
<div className="slds-media__body">
41+
{ this.props.title }
42+
{ this.props.info }
43+
</div>
44+
</div>
45+
);
46+
}
47+
}
48+
49+
Base.displayName = displayName;
50+
Base.propTypes = propTypes;
51+
Base.defaultProps = defaultProps;
52+
53+
module.exports = Base;
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import React, { Component } from 'react';
2+
import randomId from '../randomId';
3+
4+
const displayName = 'SLDSBreadCrumb';
5+
const propTypes = {
6+
/**
7+
* The assistive text for the breadcrumb trail
8+
*/
9+
assistiveText: React.PropTypes.string,
10+
/**
11+
* An array of react elements presumably anchor elements.
12+
*/
13+
trail: React.PropTypes.array,
14+
};
15+
const defaultProps = {};
16+
17+
class SLDSBreadCrumb extends Component {
18+
render() {
19+
const {
20+
assistiveText,
21+
trail,
22+
} = this.props;
23+
const id = `SLDSBreadCrumb.${randomId()}`;
24+
let trailElement;
25+
26+
const renderTrail = () => {
27+
const breadCrumbTrail = trail.map((crumb, i) => {
28+
const crumbId = `${id}.${i}`;
29+
30+
return (
31+
<li
32+
key={crumbId}
33+
className="slds-list__item slds-text-heading--label"
34+
>{crumb}</li>
35+
);
36+
});
37+
38+
return (
39+
<ol className="slds-breadcrumb slds-list--horizontal" aria-labelledby={id}>
40+
{breadCrumbTrail}
41+
</ol>
42+
);
43+
};
44+
45+
trailElement = renderTrail();
46+
47+
return (
48+
<nav role="navigation">
49+
<p id={id} className="slds-assistive-text">{assistiveText}</p>
50+
{trailElement}
51+
</nav>
52+
);
53+
}
54+
}
55+
56+
SLDSBreadCrumb.displayName = displayName;
57+
SLDSBreadCrumb.propTypes = propTypes;
58+
SLDSBreadCrumb.defaultProps = defaultProps;
59+
60+
export default SLDSBreadCrumb;
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/*
2+
Copyright (c) 2015, salesforce.com, inc. All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5+
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6+
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
7+
Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
8+
9+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
10+
*/
11+
12+
import React, { Component } from 'react';
13+
import classnames from 'classnames';
14+
import omit from 'lodash.omit';
15+
16+
const displayName = 'SLDSPageHeaderDetailRow';
17+
const propTypes = {
18+
/**
19+
* Optional class name
20+
*/
21+
className: React.PropTypes.string,
22+
/**
23+
* label
24+
*/
25+
label: React.PropTypes.oneOfType([
26+
React.PropTypes.string,
27+
React.PropTypes.element,
28+
]),
29+
/**
30+
* The content property can be a string or a React element
31+
*/
32+
content: React.PropTypes.oneOfType([
33+
React.PropTypes.string,
34+
React.PropTypes.element,
35+
]),
36+
/**
37+
* Sets whether the fields truncate
38+
*/
39+
truncate: React.PropTypes.bool.isRequired,
40+
flavor: React.PropTypes.string,
41+
};
42+
const defaultProps = {
43+
label: '',
44+
content: '',
45+
truncate: true,
46+
flavor: '1-of-4',
47+
};
48+
49+
class DetailBlock extends Component {
50+
render() {
51+
const {
52+
className,
53+
label,
54+
content,
55+
truncate,
56+
flavor,
57+
} = this.props;
58+
const attr = omit([
59+
'className',
60+
'label',
61+
'content',
62+
'truncate',
63+
'flavor',
64+
], this.props);
65+
const classes = this._getClassNames(className, flavor);
66+
let labelElement;
67+
let contentElement;
68+
69+
/**
70+
* Render the label
71+
*/
72+
const renderLabel = () => {
73+
const type = typeof label;
74+
75+
if (type === 'string') {
76+
const labelClasses = classnames('slds-text-heading--label-normal', {
77+
'slds-truncate': truncate,
78+
});
79+
80+
return (
81+
<p className={labelClasses} title={label}>{label}</p>
82+
);
83+
} else {
84+
return label;
85+
}
86+
};
87+
88+
/**
89+
* Render the title
90+
*/
91+
const renderContent = () => {
92+
const type = typeof content;
93+
94+
if (type === 'string') {
95+
const labelClasses = classnames('slds-text-body--regular', {
96+
'slds-truncate': truncate,
97+
});
98+
99+
return (
100+
<p className={labelClasses} content={content}>{content}</p>
101+
);
102+
} else {
103+
return content;
104+
}
105+
};
106+
107+
labelElement = renderLabel();
108+
contentElement = renderContent();
109+
110+
return (
111+
<li className={classes} {...attr}>
112+
{labelElement}
113+
{contentElement}
114+
</li>
115+
);
116+
}
117+
118+
_getClassNames(className, flavor) {
119+
return classnames('slds-page-header__detail-block', className, {
120+
[`slds-size--${flavor}`]: flavor,
121+
});
122+
}
123+
}
124+
125+
DetailBlock.displayName = displayName;
126+
DetailBlock.propTypes = propTypes;
127+
DetailBlock.defaultProps = defaultProps;
128+
129+
module.exports = DetailBlock;
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
Copyright (c) 2015, salesforce.com, inc. All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5+
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6+
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
7+
Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
8+
9+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
10+
*/
11+
12+
import React, { Component } from 'react';
13+
import classnames from 'classnames';
14+
import omit from 'lodash.omit';
15+
import randomId from './randomId';
16+
import DetailBlock from './DetailBlock';
17+
18+
const displayName = 'SLDSPageHeaderDetailRow';
19+
const propTypes = {
20+
/**
21+
* Optional class name
22+
*/
23+
className: React.PropTypes.string,
24+
/**
25+
* An array of detail blocks
26+
*/
27+
details: React.PropTypes.array,
28+
};
29+
const defaultProps = {};
30+
31+
class DetailRow extends Component {
32+
render() {
33+
const { children, className, details } = this.props;
34+
const attr = omit(['children', 'className'], this.props);
35+
const classes = this._getClassNames(className);
36+
37+
let detailsElement;
38+
39+
/**
40+
* Render the deets
41+
*/
42+
const renderDetails = () => {
43+
if (children !== void(0)) {
44+
return children;
45+
} else {
46+
return details.map((detail, i) => {
47+
const id = randomId();
48+
const key = `SLDSPageHeader.detailBlock.${i}.${id}`;
49+
50+
return (
51+
<DetailBlock
52+
key={key}
53+
flavor={detail.flavor}
54+
label={detail.label}
55+
content={detail.content} />
56+
);
57+
});
58+
}
59+
};
60+
61+
detailsElement = renderDetails();
62+
63+
return (
64+
<ul className={classes} {...attr}>
65+
{detailsElement}
66+
</ul>
67+
);
68+
}
69+
70+
_getClassNames(className) {
71+
return classnames('slds-grid slds-page-header__detail-row', className);
72+
}
73+
}
74+
75+
DetailRow.displayName = displayName;
76+
DetailRow.propTypes = propTypes;
77+
DetailRow.defaultProps = defaultProps;
78+
79+
module.exports = DetailRow;

components/SLDSPageHeader/Info.jsx

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
Copyright (c) 2015, salesforce.com, inc. All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5+
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6+
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
7+
Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
8+
9+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
10+
*/
11+
12+
import React, { Component } from 'react';
13+
import classnames from 'classnames';
14+
import omit from 'lodash.omit';
15+
16+
const displayName = 'SLDSPageHeaderInfo';
17+
const propTypes = {
18+
/**
19+
* Optional class name
20+
*/
21+
className: React.PropTypes.string,
22+
};
23+
const defaultProps = {
24+
className: '',
25+
};
26+
27+
class Info extends Component {
28+
render() {
29+
const { children, className } = this.props;
30+
const attr = omit(['children', 'className'], this.props);
31+
const classes = this._getClassNames(className);
32+
33+
return (
34+
<p className={classes} {...attr}>
35+
{children}
36+
</p>
37+
);
38+
}
39+
40+
_getClassNames(className) {
41+
return classnames('slds-page-header__info', className);
42+
}
43+
}
44+
45+
Info.displayName = displayName;
46+
Info.propTypes = propTypes;
47+
Info.defaultProps = defaultProps;
48+
49+
module.exports = Info;

0 commit comments

Comments
 (0)