Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ import Avatar, { ConfigProvider } from 'react-avatar';
| `src` | *string* | | Fallback image to use |
| `style` | *object* | | Style that will be applied on the root element |
| `unstyled` | *bool* | false | Disable all styles |
| `selectable` | *bool* | false | Whether it is possible to select the initials text. |
| `onClick` | *function* | | Mouse click event |

### ConfigProvider
Expand Down
4 changes: 4 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ export interface ReactAvatarProps {
* Disable all styles
*/
unstyled?: boolean;
/**
* Whether it is possible to select the initials text.
*/
selectable?: boolean;
/**
* Mouse click event
* @param {React.SyntheticEvent<any>} e
Expand Down
17 changes: 14 additions & 3 deletions src/components/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class AvatarText extends React.PureComponent {
PropTypes.number,
PropTypes.string
]),
selectable: PropTypes.bool,
}

static defaultProps = {
Expand All @@ -45,7 +46,8 @@ class AvatarText extends React.PureComponent {
size: 100,
textSizeRatio: 3,
textMarginRatio: .15,
unstyled: false
unstyled: false,
selectable: false,
}

componentDidMount() {
Expand Down Expand Up @@ -122,7 +124,8 @@ class AvatarText extends React.PureComponent {
title,
name,
value,
avatar
avatar,
selectable
} = this.props;

const size = parseSize(this.props.size);
Expand All @@ -144,11 +147,19 @@ class AvatarText extends React.PureComponent {
height: '100%'
};

const unselectableStyle = {
WebkitUserSelect: 'none',
MsUserSelect: 'none',
userSelect: 'none',
};

const spanStyle = unstyled ? null : {
display: 'table-cell',
verticalAlign: 'middle',
fontSize: '100%',
whiteSpace: 'nowrap'
whiteSpace: 'nowrap',

...(!selectable && unselectableStyle)
};

// Ensure the text node is updated and scaled when any of these
Expand Down