forked from Kenshin/simpread
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththeme.jsx
More file actions
49 lines (43 loc) · 1.65 KB
/
theme.jsx
File metadata and controls
49 lines (43 loc) · 1.65 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
45
46
47
48
49
console.log( "===== simpread option common: ThemeSel =====" )
export default class ThemeSel extends React.Component {
changeBgColor( event ) {
if ( event.target.tagName.toLowerCase() == "sr-opt-theme" ) {
const target = event.target,
$target = $(target),
$parent = $target.parent(),
activestyl = "active",
newval = $target.attr( "name" ),
$active = $parent.find( 'sr-opt-theme[sr-type="active"]' );
if ( $active ) {
$active.removeAttr( "sr-type" );
$target.attr( "sr-type", activestyl );
}
this.props.changeBgColor( newval, $target );
}
}
componentDidMount() {
setBgThemeStyle( this.props.theme );
}
render() {
return (
<sr-opt-themes onClick={ evt=> this.changeBgColor(evt) }>
{ this.props.themes.map( (theme,idx) => <sr-opt-theme style={{backgroundColor: `rgba( ${theme} )`}} name={ this.props.names[idx] } data-tooltip={ this.props.labels[idx] } data-tooltip-position="bottom" data-tooltip-delay="50"></sr-opt-theme> )}
</sr-opt-themes>
)
}
}
/**
* Set background style
*
* @param {string} theme name
*/
function setBgThemeStyle( theme ) {
const $themes = $( "sr-opt-themes" ).children();
for ( let i = 0; i < $themes.length; i++ ) {
const $target = $($themes[i]),
name = $target.attr( "name" );
if ( theme === name ) {
$target.attr( "sr-type", "active" );
}
}
}