material ui cardにて。
cardHeaderのtitleにカーソルがあった時に、リンクがあるため色を変えようと思い、このようにかいたのですが、
js
1import React, { Component } from 'react' 2import { Card, CardActions, CardHeader, CardText, CardTitle } from 'material-ui/Card' 3import FlatButton from 'material-ui/FlatButton' 4import { List } from 'material-ui/List' 5import Dialog from 'material-ui/Dialog' 6import Avatar from 'material-ui/Avatar' 7import ChatIcon from 'material-ui/svg-icons/communication/chat-bubble-outline' 8import Badge from 'material-ui/Badge' 9import { withStyles } from 'material-ui/styles' 10 11import Linkify from 'react-linkify' 12import Timestamp from 'react-timestamp' 13 14import firebase from 'firebase' 15 16import CommentRef from './CommentRef' 17import CommentForm from './CommentForm' 18 19 20const myStyle = { 21 title: { 22 '&:hover': { 23 background: '#E0F7FA', 24 color:'white' 25 }, 26 paddingTop:'0' 27 } 28} 29 30class PostRef extends Component { 31 constructor(props) { 32 super(props); 33 this.state = { 34 open:false, 35 star:'', 36 profile_image:'', 37 postOpen:false, 38 }; 39 } 40 41 handleClose = () => { 42 this.setState({open: false,postOpen:false}); 43 } 44 45 onCommentFncOpen = () => { 46 this.setState({open:true}) 47 } 48 49 handleCommentSubmit = (val) =>{ 50 this.writeNewComment(val) 51 } 52 53 handlePostOpen = () => { 54 this.setState({postOpen:true}) 55 } 56 57 writeNewComment(val){ 58 const self = this 59 var newCommentKey = firebase.database().ref().child('comments').push().key 60 61 firebase.database().ref('posts/' + self.props.post.postId + '/postComment').once("value").then(function(snapshot) { 62 const postCommentData = snapshot.val() 63 var commentData = { 64 author: self.props.author, 65 uid: self.props.myuid, 66 body: val, 67 commentId: newCommentKey, 68 profile_image:self.props.profile_image, 69 } 70 var updates = {} 71 updates['/comments/' + newCommentKey] = commentData 72 updates['posts/' + self.props.post.postId + '/postComment/commentCount/'] = postCommentData.commentCount+1 73 updates['posts/' + self.props.post.postId + '/postComment/comments/' + newCommentKey]= true 74 console.log(updates) 75 return firebase.database().ref().update(updates); 76 }) 77 this.setState({open:false}) 78 } 79 80 fetchPostsData(){ 81 const self = this 82 const userId = this.props.post.uid 83 firebase.database().ref('/users/'+userId).once('value',function(snapshot) { 84 self.setState({ 85 profile_image:snapshot.val().profile_image, 86 star:snapshot.val().userStar.starCount, 87 }) 88 }) 89 } 90 91 componentDidMount(){ 92 this.fetchPostsData() 93 } 94 95 render(){ 96 const actions = [ 97 <FlatButton 98 label="Cancel" 99 primary={true} 100 onClick={this.handleClose} />,] 101 return( 102 <Card style={{ 103 width:'300px', 104 display: 'inline-block', 105 marginRight:'10px', 106 verticalAlign: 'top',}} > 107 <CardHeader 108 title={ 109 <div> 110 <Badge 111 badgeContent={this.state.star} 112 secondary={true} 113 badgeStyle={{top: 12, right: 12,fontSize:1}} 114 > 115 <Avatar src={this.state.profile_image} /> 116 </Badge> 117 {this.props.post.author} 118 </div> 119 } 120 style={{ 121 height:'70px', 122 cursor: 'pointer', 123 paddingTop:'0', 124 verticalAlign:'top' 125 }} 126 classes={{ title: this.props.classes.title }} 127 onClick={() => this.props.herfUserPage(this.props.post.uid)} /> 128 <CardTitle title={this.props.post.title} 129 subtitle={ 130 <Timestamp time={this.props.post.timestamp/1000} format='full' includeDay/> 131 } 132 titleStyle={{ 133 paddingTop:'0', 134 marginTop:'-20' 135 }}/> 136 <CardText style={{ 137 paddingTop:'0', 138 }} 139 onClick={this.handlePostOpen} 140 > 141 <Linkify> {this.props.post.body} </Linkify> 142 <br /> 143 <p style={{ 144 textAlign:'center' 145 }}> 146 <img src={this.props.post.post_image} 147 alt="" 148 style={{ 149 objectFit:'cover', 150 width:'270px', 151 hight:'270px',}}></img> 152 </p> 153 </CardText> 154 <CardActions style={{ 155 paddingTop:'0', 156 }}> 157 <FlatButton 158 secondary 159 label="Comment" 160 onClick={this.onCommentFncOpen} /> 161 </CardActions> 162 163 <CardHeader showExpandableButton 164 title={ <Badge badgeContent={this.props.post.postComment.commentCount} 165 primary={true} 166 badgeStyle={{fontSize:1,top: 12, right: 12}} > 167 <ChatIcon style={{size:'10px'}}/> 168 </Badge> } 169 style={{ 170 paddingTop:'0', 171 marginTop:'-10', 172 marginBottom:'-25' 173 }}/> 174 <List expandable> 175 <CommentRef postId={this.props.post.postId} uid={this.props.post.uid}/> 176 </List> 177 178 <Dialog title="write comment" 179 actions={actions} 180 modal={false} 181 open={this.state.open} 182 onRequestClose={this.handleClose} > 183 <CommentForm onSubmit={this.handleCommentSubmit.bind(this)}/> 184 </Dialog> 185 186 <Dialog title={this.props.post.title} 187 actions={actions} 188 modal={false} 189 open={this.state.postOpen} 190 onRequestClose={this.handleClose} > 191 <div style={{ 192 paddingTop:'0', 193 }} > 194 <Linkify> {this.props.post.body} </Linkify> 195 <br /> 196 <p style={{ 197 textAlign:'center' 198 }}> 199 <img src={this.props.post.post_image} 200 alt="" 201 style={{ 202 objectFit:'cover', 203 width:'100%', 204 hight:'100%',}}></img> 205 </p> 206 </div> 207 </Dialog> 208 </Card> 209 )} 210 211} 212export default withStyles(myStyle)(PostRef) 213
これでは色を変えることができません。どこで間違えてますでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/11/20 09:56
2017/11/20 15:38
2017/11/20 16:42
2017/11/21 06:00
2017/11/21 06:12
2017/11/21 06:34
2017/11/21 07:19
2017/11/21 09:27
2017/11/21 09:58 編集
2017/11/21 10:40
2017/11/21 11:32
2017/11/21 11:44
2017/11/21 12:25
2017/11/22 04:53
2017/11/22 07:26
2017/11/22 07:50 編集
2017/11/22 07:53
2017/11/22 08:11
2017/11/22 09:11
2017/11/22 09:38
2017/11/22 09:51
2017/11/23 14:59
2017/11/23 16:50
2017/11/24 00:49
2017/11/24 05:22
2017/11/24 05:28