@gitlab/ui 32.51.0 → 32.51.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [32.51.1](https://gitlab.com/gitlab-org/gitlab-ui/compare/v32.51.0...v32.51.1) (2022-01-05)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **Avatar:** Add support for multiple-character emojis ([f3fcb2f](https://gitlab.com/gitlab-org/gitlab-ui/commit/f3fcb2ff5a2e74f77b3a96dc8922a3821c86e2fa))
7
+
1
8
  # [32.51.0](https://gitlab.com/gitlab-org/gitlab-ui/compare/v32.50.0...v32.51.0) (2021-12-29)
2
9
 
3
10
 
@@ -1,3 +1,5 @@
1
+ import emojiRegexFactory from 'emoji-regex';
2
+
1
3
  /**
2
4
  * Split the given string after each occurrence of each of the given symbols.
3
5
  *
@@ -16,6 +18,7 @@
16
18
  * @param {string} string The string to split.
17
19
  * @returns {string[]} The resulting strings.
18
20
  */
21
+
19
22
  const splitAfterSymbols = (symbols, string) => {
20
23
  const textParts = [];
21
24
  let textPartStartIndex = 0;
@@ -60,10 +63,11 @@ const splitAfterSymbols = (symbols, string) => {
60
63
 
61
64
  return textParts;
62
65
  };
66
+ const startsWithEmojiRegex = `^(${emojiRegexFactory().source})`;
63
67
  const getAvatarChar = name => {
64
68
  if (name) {
65
- // Check if first character is an emjoi
66
- const match = name.match(/^\p{Emoji}/u);
69
+ // Check if string starts with an emoji (which could be multiple characters and zero-width joined)
70
+ const match = name.match(startsWithEmojiRegex);
67
71
 
68
72
  if (match) {
69
73
  // Return the first match
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gitlab/ui",
3
- "version": "32.51.0",
3
+ "version": "32.51.1",
4
4
  "description": "GitLab UI Components",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -72,6 +72,7 @@
72
72
  },
73
73
  "peerDependencies": {
74
74
  "@gitlab/svgs": "^1.116.0 || ^2.0.0",
75
+ "emoji-regex": ">=10.0.0",
75
76
  "bootstrap": "4.5.3",
76
77
  "pikaday": "^1.8.0",
77
78
  "vue": "^2.6.10"
@@ -107,6 +108,7 @@
107
108
  "babel-preset-vue": "^2.0.2",
108
109
  "bootstrap": "4.5.3",
109
110
  "cypress": "^6.6.0",
111
+ "emoji-regex": "^10.0.0",
110
112
  "eslint": "7.32.0",
111
113
  "eslint-import-resolver-jest": "3.0.2",
112
114
  "eslint-plugin-cypress": "2.12.1",
@@ -1,3 +1,5 @@
1
+ import emojiRegexFactory from 'emoji-regex';
2
+
1
3
  /**
2
4
  * Split the given string after each occurrence of each of the given symbols.
3
5
  *
@@ -60,10 +62,12 @@ export const splitAfterSymbols = (symbols, string) => {
60
62
  return textParts;
61
63
  };
62
64
 
65
+ const startsWithEmojiRegex = `^(${emojiRegexFactory().source})`;
66
+
63
67
  export const getAvatarChar = (name) => {
64
68
  if (name) {
65
- // Check if first character is an emjoi
66
- const match = name.match(/^\p{Emoji}/u);
69
+ // Check if string starts with an emoji (which could be multiple characters and zero-width joined)
70
+ const match = name.match(startsWithEmojiRegex);
67
71
  if (match) {
68
72
  // Return the first match
69
73
  return match[0];
@@ -44,5 +44,13 @@ describe('string utils', () => {
44
44
  it('Returns first character if emoji is not first in name', () => {
45
45
  expect(getAvatarChar('tanuki🦊')).toBe('T');
46
46
  });
47
+
48
+ it('Returns zero-width joined emoji if the name starts with it', () => {
49
+ expect(getAvatarChar('🏴‍☠️Zero-width join')).toBe('🏴‍☠️');
50
+ });
51
+
52
+ it('Returns only first emoji if the name starts with multiple', () => {
53
+ expect(getAvatarChar('🏴‍☠️🙂Multiple Emoji')).toBe('🏴‍☠️');
54
+ });
47
55
  });
48
56
  });