Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌐 Added locale to Message #728

Merged
merged 3 commits into from
Jun 20, 2017
Merged
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
12 changes: 12 additions & 0 deletions docs/components.json
Original file line number Diff line number Diff line change
Expand Up @@ -4049,6 +4049,18 @@
"computed": false
}
},
"locale": {
"type": {
"name": "instanceOf",
"value": "Object"
},
"required": false,
"description": "Internationalization, defaults to English\n\nhttps://date-fns.org/docs/I18n",
"defaultValue": {
"value": "en",
"computed": true
}
},
"separator": {
"type": {
"name": "node"
Expand Down
7 changes: 5 additions & 2 deletions src/message/image-message/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class ImageMessage extends Component {
timeFormat,
enableLightbox,
collapsed,
collapsedText
collapsedText,
locale
} = this.props;
const { lightbox } = this.state;

Expand Down Expand Up @@ -87,6 +88,7 @@ class ImageMessage extends Component {
style={messageTimeStyle}
createdAt={message.createdAt}
timeFormat={timeFormat}
locale={locale}
/>
</p>
{
Expand Down Expand Up @@ -126,7 +128,8 @@ ImageMessage.propTypes = {
compact: PropTypes.bool,
color: PropTypes.string,
collapsed: PropTypes.bool,
collapsedText: PropTypes.node
collapsedText: PropTypes.node,
locale: PropTypes.instanceOf(Object).isRequired
};

ImageMessage.defaultProps = {
Expand Down
9 changes: 9 additions & 0 deletions src/message/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
import pure from 'recompose/pure';
import Radium from 'radium';
import compose from 'recompose/compose';
import en from 'date-fns/locale/en';
import IconMenu from '../icon-menu';
import IconChevronDown from '../icons/icon-chevron-down';
import getStyles from './get-styles';
Expand Down Expand Up @@ -76,6 +77,12 @@ class Message extends Component {
expandIcon: PropTypes.node,
/** Text to display for edited banner */
edited: PropTypes.node,
/**
* Internationalization, defaults to English
*
* https://date-fns.org/docs/I18n
*/
locale: PropTypes.instanceOf(Object),
/** Show a separator above the message */
separator: PropTypes.node,
color: PropTypes.string.isRequired
Expand All @@ -101,6 +108,7 @@ class Message extends Component {
expandIcon: null,
collapsedText: 'This image has been collapsed, click the button to expand it.',
edited: null,
locale: en,
separator: null
}

Expand Down Expand Up @@ -184,6 +192,7 @@ class Message extends Component {
expandIcon, // eslint-disable-line no-unused-vars
collapsedText, // eslint-disable-line no-unused-vars
edited, // eslint-disable-line no-unused-vars
locale, // eslint-disable-line no-unused-vars
color,
separator,
...custom
Expand Down
7 changes: 4 additions & 3 deletions src/message/message-time/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import format from 'date-fns/format';
import getStyles from './get-styles';
import styles from './styles';

const MessageTime = ({ myMessage, type, style, createdAt, timeFormat, edited }) => (
const MessageTime = ({ myMessage, type, style, createdAt, timeFormat, edited, locale }) => (
<span style={getStyles.root(myMessage, type, edited, style)}>
{edited ? <span style={styles.edited}>{edited}</span> : null}
<span>{format(createdAt, timeFormat)}</span>
<span>{format(createdAt, timeFormat, { locale })}</span>
</span>
);

Expand All @@ -20,7 +20,8 @@ MessageTime.propTypes = {
PropTypes.string,
PropTypes.instanceOf(Date)
]).isRequired,
edited: PropTypes.node
edited: PropTypes.node,
locale: PropTypes.instanceOf(Object).isRequired
};

MessageTime.defaultProps = {
Expand Down
7 changes: 5 additions & 2 deletions src/message/sticker-message/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const StickerMessage = ({
message,
messageBodyStyle,
messageTimeStyle,
timeFormat
timeFormat,
locale
}) => {
const headerStyle = combineStyles(messageHeaderStyle, { marginBottom: 0 });

Expand All @@ -40,6 +41,7 @@ const StickerMessage = ({
style={messageTimeStyle}
createdAt={message.createdAt}
timeFormat={timeFormat}
locale={locale}
/>
</div>
</div>
Expand All @@ -65,7 +67,8 @@ StickerMessage.propTypes = {
fontSize: PropTypes.oneOf(['small', 'medium', 'large']),
myMessage: PropTypes.bool,
compact: PropTypes.bool,
color: PropTypes.string
color: PropTypes.string,
locale: PropTypes.instanceOf(Object).isRequired
};

StickerMessage.defaultProps = {
Expand Down
13 changes: 9 additions & 4 deletions src/message/text-message/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ function createMarkup(text, enableLinks) {
if (enableLinks) {
const urlSchemeRegex = /^(?:https?:\/\/)/;

const style = 'color: inherit; font-size: inherit; font-weight: inherit; text-decoration: underline;';

parsedText = escapedText.replace(urlRegex, (url) => {
if (!urlSchemeRegex.test(url)) {
// Add default http:// scheme for urls like example.com
return (`<a href="http://${url}" target="_blank">${url}</a>`);
return (`<a style="${style}" href="http://${url}" target="_blank">${url}</a>`);
}
return (`<a href="${url}" target="_blank">${url}</a>`);
return (`<a style="${style}" href="${url}" target="_blank">${url}</a>`);
});
}

Expand All @@ -44,7 +46,8 @@ function TextMessage({
timeFormat,
emoji,
enableLinks,
edited
edited,
locale
}) {
return (
<div style={getStyles.root(color, myMessage, avatar, compact, style)}>
Expand All @@ -69,6 +72,7 @@ function TextMessage({
createdAt={message.createdAt}
timeFormat={timeFormat}
edited={edited}
locale={locale}
/>
</p>
</div>
Expand Down Expand Up @@ -97,7 +101,8 @@ TextMessage.propTypes = {
enableLinks: PropTypes.bool,
compact: PropTypes.bool,
edited: PropTypes.node,
color: PropTypes.string
color: PropTypes.string,
locale: PropTypes.instanceOf(Object).isRequired
};

TextMessage.defaultProps = {
Expand Down