-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
515b8a0
commit 1e2ae41
Showing
10 changed files
with
353 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/components/elements/messages/AuthorDropdown/AuthorDropdown.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
.AuthorDropdown { | ||
padding: 0.5rem; | ||
|
||
.link { | ||
font-weight: bold; | ||
} | ||
|
||
.last-seen { | ||
font-size: 95%; | ||
} | ||
|
||
.btns { | ||
min-width: 250px; | ||
width: 100%; | ||
} | ||
.btn { | ||
float: right; | ||
margin-right: 0.5rem !important; | ||
margin-top: 0.5rem; | ||
padding-top: 0.5rem; | ||
padding-bottom: 0.5rem; | ||
|
||
.title { | ||
vertical-align: middle; | ||
margin-left: 5px; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/components/elements/messages/LetteredAvatar/LetteredAvatar.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
.lettered-avatar-wrapper { | ||
text-align: center; | ||
} | ||
|
||
.lettered-avatar-wrapper.light { | ||
color: #000; | ||
} | ||
|
||
.lettered-avatar-wrapper.dark { | ||
color: #fff; | ||
} | ||
|
||
.lettered-avatar { | ||
white-space: nowrap; | ||
overflow: hidden; | ||
font-size: 24px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
export const defaultColors = [ | ||
'#e25f51',// A | ||
'#f26091',// B | ||
'#bb65ca',// C | ||
'#9572cf',// D | ||
'#7884cd',// E | ||
'#5b95f9',// F | ||
'#48c2f9',// G | ||
'#45d0e2',// H | ||
'#48b6ac',// I | ||
'#52bc89',// J | ||
'#9bce5f',// K | ||
'#d4e34a',// L | ||
'#feda10',// M | ||
'#f7c000',// N | ||
'#ffa800',// O | ||
'#ff8a60',// P | ||
'#c2c2c2',// Q | ||
'#8fa4af',// R | ||
'#a2887e',// S | ||
'#a3a3a3',// T | ||
'#afb5e2',// U | ||
'#b39bdd',// V | ||
'#c2c2c2',// W | ||
'#7cdeeb',// X | ||
'#bcaaa4',// Y | ||
'#add67d'// Z | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// Copyright (c) https://github.com/ipavlyukov/react-lettered-avatar | ||
// The MIT License | ||
import React, { Component } from "react"; | ||
import PropTypes from "prop-types"; | ||
|
||
import { defaultColors } from "./colors"; | ||
|
||
import "./LetteredAvatar.css"; | ||
|
||
class LetteredAvatar extends Component { | ||
render() { | ||
const { | ||
name, | ||
color, | ||
backgroundColors, | ||
backgroundColor, | ||
radius, | ||
size, | ||
} = this.props; | ||
let initials = "", | ||
defaultBackground = ""; | ||
|
||
const sumChars = (str) => { | ||
let sum = 0; | ||
for (let i = 0; i < str.length; i++) { | ||
sum += str.charCodeAt(i); | ||
} | ||
return sum; | ||
}; | ||
|
||
// GET AND SET INITIALS | ||
const names = name.split(" "); | ||
if (names.length === 1) { | ||
initials = names[0].substring(0, 1).toUpperCase(); | ||
} else if (names.length > 1) { | ||
names.forEach((n, i) => { | ||
initials += names[i].substring(0, 1).toUpperCase(); | ||
}); | ||
} | ||
|
||
// SET BACKGROUND COLOR | ||
if (/[A-Z]/.test(initials)) { | ||
if (backgroundColor) { | ||
defaultBackground = backgroundColor; | ||
} else { | ||
let colors = backgroundColors | ||
if (backgroundColors && backgroundColors.length) { | ||
colors = backgroundColors | ||
} else { | ||
colors = defaultColors | ||
} | ||
let i = sumChars(name) % colors.length | ||
defaultBackground = colors[i] | ||
} | ||
} else if (/[\d]/.test(initials)) { | ||
defaultBackground = defaultColors[parseInt(initials)]; | ||
} else { | ||
defaultBackground = "#051923"; | ||
} | ||
|
||
const fontSize = size / 2 | ||
|
||
const styles = { | ||
color, | ||
backgroundColor: `${defaultBackground}`, | ||
width: size, | ||
height: size, | ||
lineHeight: `${size}px`, | ||
borderRadius: `${radius || radius === 0 ? radius : size}px`, | ||
fontSize: `100%`, | ||
}; | ||
return ( | ||
<div | ||
className={`lettered-avatar-wrapper dark`} | ||
style={styles} | ||
aria-label={name} | ||
> | ||
<div className="lettered-avatar" style={{ fontSize }}>{initials}</div> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
LetteredAvatar.propTypes = { | ||
name: PropTypes.string.isRequired, | ||
color: PropTypes.string, | ||
backgroundColor: PropTypes.string, | ||
radius: PropTypes.number, | ||
size: PropTypes.number, | ||
}; | ||
|
||
LetteredAvatar.defaultProps = { | ||
name: "Lettered Avatar", | ||
color: "", | ||
size: 48, | ||
}; | ||
|
||
export default LetteredAvatar; |
Oops, something went wrong.