Skip to content

Commit d1846fe

Browse files
Dropdown cpm developed buttonProps added.
Document upgrade Button cpm buttonRef prop added. Dropdown target prop removed. Input cmp unnecessary overflow removed.
1 parent 7593463 commit d1846fe

7 files changed

Lines changed: 99 additions & 64 deletions

File tree

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ import { Button } from 'react-chat-elements'
218218
| type | none | string | button type (outlined, transparent) |
219219
| disabled | none | string | button is disabled? |
220220
| text | none | string | button text |
221+
| buttonRef | none | function | button ref |
221222

222223
## Popup Component
223224

@@ -320,17 +321,16 @@ import { Navbar } from 'react-chat-elements'
320321
import { Dropdown } from 'react-chat-elements'
321322

322323
<Dropdown
323-
target={{
324-
X: 400,
325-
Y: 100
326-
}}
324+
buttonProps={{
325+
text: 'Dropdown',
326+
}}
327327
items={[
328328
'merhaba',
329329
'lorem',
330330
'ipsum',
331331
'dolor',
332332
'sit',
333-
'amet'
333+
'amet',
334334
]}/>
335335
```
336336

@@ -342,4 +342,4 @@ import { Dropdown } from 'react-chat-elements'
342342
| animationPosition | nortwest | string | animation start position (nortwest, norteast, southwest, southeast) |
343343
| items | none | array | dropdown items array |
344344
| onSelect | none | function | item on select |
345-
| target | { X: 0, Y: 0 } | object | dropdown target |
345+
| buttonProps | none | object | button properties |

example/App.js

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -101,19 +101,6 @@ export class App extends Component {
101101

102102
return (
103103
<div className='container'>
104-
<Dropdown
105-
target={{
106-
X: 400,
107-
Y: 100
108-
}}
109-
items={[
110-
's.a',
111-
'lorem',
112-
'ipsum',
113-
'dolor',
114-
'sit',
115-
'amet'
116-
]}/>
117104
<div
118105
className='chat-list'>
119106
<SideBar
@@ -180,21 +167,18 @@ export class App extends Component {
180167
multiline={true}
181168
// buttonsFloat='left'
182169
rightButtons={
183-
<div>
184-
<Button
185-
color='white'
186-
backgroundColor='black'
187-
onClick={(e => {
188-
this.addMessage();
189-
this.refs.input.clear();
190-
}).bind(this)}
191-
icon={{
192-
component: <FaSearch />,
193-
size: 18,
194-
float: 'right'
195-
}}/>
196-
197-
</div>
170+
<Dropdown
171+
items={[
172+
'asdasd',
173+
'asdasdasd',
174+
]}
175+
buttonProps={{
176+
text: 'Boşu Boşuna'
177+
}}
178+
onSelect={(i) => {
179+
console.log(`${i}'nci nesne seçildi`)
180+
}}
181+
animationPosition='southeast'/>
198182
}/>
199183
</div>
200184

src/Button/Button.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export class Button extends Component {
77
render() {
88
return (
99
<button
10+
ref={this.props.buttonRef}
1011
className={classNames('rce-button', this.props.type, this.props.className)}
1112
style={{
1213
backgroundColor: this.props.backgroundColor,
@@ -39,6 +40,7 @@ Button.defaultProps = {
3940
backgroundColor: '#3979aa',
4041
color: 'white',
4142
className: null,
43+
buttonRef: null,
4244
};
4345

44-
export default Button;
46+
export default Button;

src/Dropdown/Dropdown.css

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
.rce-dropdown-container {
2+
position: relative;
3+
}
14
.rce-dropdown {
25
padding: 5px 10px;
36
background: #f5f5f5;
@@ -30,18 +33,30 @@
3033

3134
.rce-dropdown-open__nortwest {
3235
transform-origin: left top;
36+
left: 0;
37+
top: 100%;
38+
margin-top: 5px
3339
}
3440

3541
.rce-dropdown-open__norteast {
3642
transform-origin: right top;
43+
right: 0;
44+
top: 100%;
45+
margin-top: 5px
3746
}
3847

3948
.rce-dropdown-open__southwest {
4049
transform-origin: left bottom;
50+
left: 0;
51+
bottom: 100%;
52+
margin-bottom: 5px
4153
}
4254

4355
.rce-dropdown-open__southeast {
4456
transform-origin: right bottom;
57+
right: 0;
58+
bottom: 100%;
59+
margin-bottom: 5px
4560
}
4661

4762
.rce-dropdown ul {
@@ -88,4 +103,4 @@
88103
100% {
89104
opacity: 1;
90105
}
91-
}
106+
}

src/Dropdown/Dropdown.js

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,64 @@
11
import React, { Component } from 'react';
22
import './Dropdown.css';
33

4+
import Button from '../Button/Button';
5+
46
const classNames = require('classnames');
57

68
export class Dropdown extends Component {
9+
constructor(props) {
10+
super(props);
11+
12+
this.state = {
13+
show: false,
14+
};
15+
}
16+
17+
onBlur(e) {
18+
if (this.state.show === true)
19+
this.setState({show: false});
20+
}
21+
722
render() {
8-
if (this.props.show === true)
923
return (
10-
<div
11-
style={{
12-
top: this.props.target.Y,
13-
left: this.props.target.X,
14-
}}
15-
className={
16-
classNames(
17-
'rce-dropdown',
18-
this.props.animationType,
19-
'rce-dropdown-open__' + this.props.animationPosition,
20-
)
21-
}>
22-
<ul>
23-
{
24-
this.props.items.map((x, i) => (
25-
<li key={i} onClick={() => this.props.onSelect(i)}>
26-
<a>{x}</a>
27-
</li>
28-
))
29-
}
30-
</ul>
24+
<div className='rce-dropdown-container' onBlur={this.onBlur.bind(this)}>
25+
{
26+
<Button
27+
{...this.props.buttonProps}
28+
onClick={() => this.setState({show: !this.state.show})}/>
29+
}
30+
{
31+
this.state.show &&
32+
<div
33+
className={
34+
classNames(
35+
'rce-dropdown',
36+
this.props.animationType,
37+
'rce-dropdown-open__' + this.props.animationPosition,
38+
)
39+
}>
40+
<ul>
41+
{
42+
this.props.items.map((x, i) => (
43+
<li key={i} onMouseDown={(e) => this.props.onSelect(i)}>
44+
<a>{x}</a>
45+
</li>
46+
))
47+
}
48+
</ul>
49+
</div>
50+
}
3151
</div>
3252
);
33-
return null;
3453
}
3554
}
3655

3756
Dropdown.defaultProps = {
38-
show: false,
3957
animationType: 'default',
4058
animationPosition: 'nortwest',
4159
items: [],
4260
onSelect: Function,
43-
target: { X: 0, Y: 0 },
61+
buttonProps: null
4462
};
4563

46-
export default Dropdown;
64+
export default Dropdown;
Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`Dropdown component should render without issues 1`] = `null`;
3+
exports[`Dropdown component should render without issues 1`] = `
4+
<div
5+
className="rce-dropdown-container"
6+
onBlur={[Function]}
7+
>
8+
<Button
9+
backgroundColor="#3979aa"
10+
buttonRef={null}
11+
className={null}
12+
color="white"
13+
disabled={false}
14+
icon={null}
15+
onClick={[Function]}
16+
text=""
17+
type={null}
18+
/>
19+
</div>
20+
`;

src/Input/Input.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
.rce-container-input {
22
display: flex;
3-
overflow: hidden;
43
min-width: 100%;
54
box-sizing: border-box;
65
flex-direction: row;

0 commit comments

Comments
 (0)