@gitlab/ui 32.29.1 → 32.29.2

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.29.2](https://gitlab.com/gitlab-org/gitlab-ui/compare/v32.29.1...v32.29.2) (2021-11-01)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **Avatar:** Parse emoji for avatar name ([d23c341](https://gitlab.com/gitlab-org/gitlab-ui/commit/d23c341bb8cef5683bf2d49556dabe4008be76cf))
7
+
1
8
  ## [32.29.1](https://gitlab.com/gitlab-org/gitlab-ui/compare/v32.29.0...v32.29.1) (2021-10-29)
2
9
 
3
10
 
@@ -1,4 +1,5 @@
1
1
  import { avatarSizeOptions, avatarShapeOptions } from '../../../utils/constants';
2
+ import { getAvatarChar } from '../../../utils/string_utils';
2
3
  import __vue_normalize__ from 'vue-runtime-helpers/dist/normalize-component.js';
3
4
 
4
5
  const IDENTICON_BG_COUNT = 7;
@@ -64,7 +65,7 @@ var script = {
64
65
  },
65
66
 
66
67
  identiconText() {
67
- return this.entityName ? this.entityName.charAt(0).toUpperCase() : '';
68
+ return getAvatarChar(this.entityName);
68
69
  }
69
70
 
70
71
  }
@@ -60,5 +60,20 @@ const splitAfterSymbols = (symbols, string) => {
60
60
 
61
61
  return textParts;
62
62
  };
63
+ const getAvatarChar = name => {
64
+ if (name) {
65
+ // Check if first character is an emjoi
66
+ const match = name.match(/^\p{Emoji}/u);
63
67
 
64
- export { splitAfterSymbols };
68
+ if (match) {
69
+ // Return the first match
70
+ return match[0];
71
+ }
72
+
73
+ return name.charAt(0).toUpperCase();
74
+ }
75
+
76
+ return '';
77
+ };
78
+
79
+ export { getAvatarChar, splitAfterSymbols };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gitlab/ui",
3
- "version": "32.29.1",
3
+ "version": "32.29.2",
4
4
  "description": "GitLab UI Components",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -43,6 +43,26 @@ function generateProjectFallbackProps() {
43
43
  return props;
44
44
  }
45
45
 
46
+ function generateEmojiProjectProps() {
47
+ const defaultSize = avatarSizeOptions[1];
48
+ const props = {
49
+ entityId: {
50
+ type: Number,
51
+ default: number('entityId', 123),
52
+ },
53
+ entityName: {
54
+ type: String,
55
+ default: text('entityName', '🦊Tanuki'),
56
+ },
57
+ size: {
58
+ type: Number,
59
+ default: select('size', avatarSizeOptions, defaultSize),
60
+ },
61
+ };
62
+
63
+ return props;
64
+ }
65
+
46
66
  function generateTooltipProps() {
47
67
  const props = {
48
68
  tooltipText: {
@@ -80,6 +100,16 @@ documentedStoriesOf('base/avatar', readme)
80
100
  shape="rect" />
81
101
  `,
82
102
  }))
103
+ .add('emoji-project-name', () => ({
104
+ props: generateEmojiProjectProps(),
105
+ template: `
106
+ <gl-avatar
107
+ :entity-name="entityName"
108
+ :entity-id="entityId"
109
+ :size="size"
110
+ shape="rect" />
111
+ `,
112
+ }))
83
113
  .add('with-tooltip', () => ({
84
114
  props: {
85
115
  ...generateImageProps(),
@@ -1,5 +1,6 @@
1
1
  <script>
2
2
  import { avatarShapeOptions, avatarSizeOptions } from '../../../utils/constants';
3
+ import { getAvatarChar } from '../../../utils/string_utils';
3
4
 
4
5
  const IDENTICON_BG_COUNT = 7;
5
6
 
@@ -62,7 +63,7 @@ export default {
62
63
  return `gl-avatar-identicon-bg${type}`;
63
64
  },
64
65
  identiconText() {
65
- return this.entityName ? this.entityName.charAt(0).toUpperCase() : '';
66
+ return getAvatarChar(this.entityName);
66
67
  },
67
68
  },
68
69
  };
@@ -59,3 +59,17 @@ export const splitAfterSymbols = (symbols, string) => {
59
59
 
60
60
  return textParts;
61
61
  };
62
+
63
+ export const getAvatarChar = (name) => {
64
+ if (name) {
65
+ // Check if first character is an emjoi
66
+ const match = name.match(/^\p{Emoji}/u);
67
+ if (match) {
68
+ // Return the first match
69
+ return match[0];
70
+ }
71
+ return name.charAt(0).toUpperCase();
72
+ }
73
+
74
+ return '';
75
+ };
@@ -1,4 +1,4 @@
1
- import { splitAfterSymbols } from './string_utils';
1
+ import { splitAfterSymbols, getAvatarChar } from './string_utils';
2
2
 
3
3
  describe('string utils', () => {
4
4
  describe('splitAfterSymbols', () => {
@@ -27,4 +27,22 @@ describe('string utils', () => {
27
27
  expect(actual.join('')).toEqual(string);
28
28
  });
29
29
  });
30
+
31
+ describe('Avatar name parsing', () => {
32
+ it('Returns first character of name', () => {
33
+ expect(getAvatarChar('Some Project')).toBe('S');
34
+ });
35
+
36
+ it('Returns empty if name is empty', () => {
37
+ expect(getAvatarChar('')).toBe('');
38
+ });
39
+
40
+ it('Returns emoji if it is first character in name', () => {
41
+ expect(getAvatarChar('🦊Tanuki')).toBe('🦊');
42
+ });
43
+
44
+ it('Returns first character if emoji is not first in name', () => {
45
+ expect(getAvatarChar('tanuki🦊')).toBe('T');
46
+ });
47
+ });
30
48
  });