Skip to content

Instantly share code, notes, and snippets.

@mkircher
Created August 2, 2018 15:29
Show Gist options
  • Select an option

  • Save mkircher/255f0e13e4242b764baa9aac03305873 to your computer and use it in GitHub Desktop.

Select an option

Save mkircher/255f0e13e4242b764baa9aac03305873 to your computer and use it in GitHub Desktop.
Avatar
Avatar
Inactive
clicked -> Active
Active
clicked -> Inactive
deleted -> Deleted
Deleted
clicked -> Inactive
function render(model){
let current_state_name = model.active_states[0].name,
isActive = current_state_name == 'Active',
isDeleted = current_state_name == 'Deleted';
let css = {
avatarContainer:{
display: 'inline-block',
position: 'relative'
},
avatar:{
width: 100,
height: 100,
display: 'inline-block',
borderRadius: '50%',
overflow: 'hidden',
border: `5px solid ${ isActive ? '#EC297E' : '#DDD' }`,
cursor: 'pointer',
opacity: `${ isDeleted ? 0.25 : 1 }`
},
avatarDelete:{
position:'absolute',
top: 0,
right: 0,
borderRadius:'50%',
width: 25,
height:25,
textAlign: 'center',
border:'none',
background:'#B01800',
color:'#FFF',
boxShadow:'0px 1px 4px #000'
}
}
return (
<div style={ css.avatarContainer }>
{ isActive && !isDeleted && <button style={css.avatarDelete} onClick={ () => model.emit('deleted') }>✕</button> }
<div style={css.avatar} onClick={ () => { model.emit('clicked') } }>
<img src="https://source.unsplash.com/random/100x100" />
</div>
</div>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment