Skip to content

Commit cf1ae61

Browse files
props was dynamic.theme and view props added.
1 parent 8ebe4bf commit cf1ae61

4 files changed

Lines changed: 28 additions & 1 deletion

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,8 @@ import { LocationMessage } from 'react-chat-elements'
436436
import { SpotifyMessage } from 'react-chat-elements'
437437

438438
<SpotifyMessage
439+
theme='white'
440+
view='coverart'
439441
uri={'spotify:user:spotify:playlist:3rgsDhGHZxZ9sB9DQWQfuf'}/>
440442
```
441443

@@ -444,6 +446,8 @@ import { SpotifyMessage } from 'react-chat-elements'
444446
| prop | default | type | description |
445447
| ---- | ---- | ---- | ---- |
446448
| uri | none | uri | spotify uri |
449+
| theme | black | string | spotify theme color (black or white) |
450+
| view | list | string | spotify view type (list or coverart) |
447451
| data | {} | object | message data |
448452
| width | 300 | int | spotify embed width |
449453
| height | 380 | int | spotify embed height |

example/App.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ export class App extends Component {
9090
position: (this.token() >= 1 ? 'right' : 'left'),
9191
forwarded: true,
9292
type: type,
93+
theme: 'white',
94+
view: 'list',
9395
title: loremIpsum({ count: 2, units: 'words' }),
9496
titleColor: this.getRandomColor(),
9597
text: type === 'spotify' ? 'spotify:user:spotify:playlist:3rgsDhGHZxZ9sB9DQWQfuf' : loremIpsum({ count: 1, units: 'sentences' }),

src/MessageBox/MessageBox.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ export class MessageBox extends Component {
9393
<SpotifyMessage
9494
width={this.props.width}
9595
height={this.props.height}
96+
theme={this.props.theme}
97+
view={this.props.view}
9698
data={this.props.data}
9799
uri={this.props.uri || this.props.text} />
98100
}

src/SpotifyMessage/SpotifyMessage.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,29 @@ import './SpotifyMessage.css';
44
const classNames = require('classnames');
55

66
export class SpotifyMessage extends Component {
7+
toUrl() {
8+
var formBody = [];
9+
var data = {
10+
uri: this.props.uri,
11+
theme: this.props.theme,
12+
view: this.props.view,
13+
};
14+
for (var property in data) {
15+
var encodedKey = encodeURIComponent(property);
16+
var encodedValue = encodeURIComponent(data[property]);
17+
formBody.push(encodedKey + "=" + encodedValue);
18+
}
19+
formBody = formBody.join("&");
20+
return formBody;
21+
}
22+
723
render() {
824
if (!this.props.uri)
925
return null;
1026
return (
1127
<div className="rce-mbox-spotify">
1228
<iframe
13-
src={"https://open.spotify.com/embed?uri=" + this.props.uri}
29+
src={"https://open.spotify.com/embed?" + this.toUrl()}
1430
width={this.props.width}
1531
height={this.props.height}
1632
frameBorder="0"
@@ -21,6 +37,9 @@ export class SpotifyMessage extends Component {
2137
}
2238

2339
SpotifyMessage.defaultProps = {
40+
uri: '',
41+
theme: 'black',
42+
view: 'list',
2443
width: 300,
2544
height: 380,
2645
}

0 commit comments

Comments
 (0)