-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathText.js
More file actions
44 lines (39 loc) · 1.26 KB
/
Text.js
File metadata and controls
44 lines (39 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
const Text = ({ tag, category, type, align, truncate, section, children, className, ...props }) => {
const textClassNames = classnames(
{
[`slds-text-${category}--${type}`]: type && category,
[`slds-text-${category}`]: category && !type,
'slds-truncate': truncate,
[`slds-text-align--${align}`]: align,
'slds-section-title--divider': section,
},
className
);
const Tag = tag || 'p';
const pprops = Object.assign({}, props);
delete pprops.trancate;
return (
<Tag {...pprops} className={textClassNames}>
{children}
</Tag>
);
};
const TEXT_CATEGORIES = ['body', 'heading', 'title'];
const TEXT_BODY_TYPES = ['regular', 'small', 'caps'];
const TEXT_HEADING_TYPES = ['large', 'medium', 'label'];
const TEXT_TYPES = ['small'].concat(TEXT_BODY_TYPES, TEXT_HEADING_TYPES);
const TEXT_ALIGNS = ['left', 'center', 'right'];
Text.propTypes = {
tag: PropTypes.string,
category: PropTypes.oneOf(TEXT_CATEGORIES),
type: PropTypes.oneOf(TEXT_TYPES),
align: PropTypes.oneOf(TEXT_ALIGNS),
className: PropTypes.string,
children: PropTypes.node,
truncate: PropTypes.bool,
section: PropTypes.bool,
};
export default Text;