-
Notifications
You must be signed in to change notification settings - Fork 429
/
Copy pathindex.jsx
91 lines (79 loc) · 2.02 KB
/
index.jsx
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/* Copyright (c) 2015-present, salesforce.com, inc. All rights reserved */
/* Licensed under BSD 3-Clause - see LICENSE.txt or git.io/sfdc-license */
// Implements the [Files design pattern](https://lightningdesignsystem.com/components/files/) in React.
// Based on SLDS v2.4.0
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { FILES } from '../../utilities/constants';
import generateId from '../../utilities/generate-id';
const displayName = FILES;
const propTypes = {
/**
* CSS class names to be added to the container element. `array`, `object`, or `string` are accepted.
*/
className: PropTypes.oneOfType([
PropTypes.array,
PropTypes.object,
PropTypes.string,
]),
/**
* HTML id for component.
*/
id: PropTypes.string,
/**
* Crop ratio for the file preview image
*/
crop: PropTypes.oneOf(['16-by-9', '4-by-3', '1-by-1']),
/**
* Column class names to be added each file in the grid
*/
columnClassName: PropTypes.string,
};
const defaultProps = {
crop: '4-by-3',
};
/**
* Files is a component that wraps multiple file components that represent an attachment
*/
class Files extends React.Component {
constructor(props) {
super(props);
this.generatedId = generateId();
}
/**
* Get the File's HTML id. Generate a new one if no ID present.
*/
getId() {
return this.props.id || this.generatedId;
}
render() {
const files = React.Children.map(this.props.children, (option) => (
<li
className={classNames(
`slds-p-horizontal_xx-small slds-size_1-of-3 slds-medium-size_1-of-4`,
this.props.columnClassName
)}
>
{React.cloneElement(option, {
crop: option.props.crop ? option.props.crop : this.props.crop,
})}
</li>
));
return (
<ul
className={classNames(
'slds-grid slds-grid_pull-padded',
this.props.className
)}
id={this.getId()}
>
{files}
</ul>
);
}
}
Files.displayName = displayName;
Files.propTypes = propTypes;
Files.defaultProps = defaultProps;
export default Files;