@gitlab/ui 62.0.0 → 62.2.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gitlab/ui",
3
- "version": "62.0.0",
3
+ "version": "62.2.0",
4
4
  "description": "GitLab UI Components",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -119,7 +119,7 @@
119
119
  "bootstrap": "4.6.2",
120
120
  "cypress": "^11.2.0",
121
121
  "emoji-regex": "^10.0.0",
122
- "eslint": "8.37.0",
122
+ "eslint": "8.38.0",
123
123
  "eslint-import-resolver-jest": "3.0.2",
124
124
  "eslint-plugin-cypress": "2.13.2",
125
125
  "eslint-plugin-storybook": "0.6.11",
@@ -56,4 +56,36 @@ describe('GlAvatar', () => {
56
56
  });
57
57
  });
58
58
  });
59
+
60
+ describe('fallbackOnError property', () => {
61
+ const findImage = () => wrapper.find('img');
62
+
63
+ beforeEach(() => {
64
+ createWrapper({ fallbackOnError: true, src: 'someproject.jpg' });
65
+ });
66
+
67
+ it('shows fallback identicon when image fails to load', async () => {
68
+ await findImage().trigger('error');
69
+
70
+ expect(findImage().exists()).toBe(false);
71
+ expect(wrapper.find('.gl-avatar-identicon').exists()).toBe(true);
72
+ });
73
+
74
+ it('emits load-error event when image fails to load', async () => {
75
+ await findImage().trigger('error');
76
+
77
+ expect(wrapper.emitted('load-error')).toHaveLength(1);
78
+ });
79
+
80
+ it('allows changing the source when initially provided image fails to load', async () => {
81
+ await findImage().trigger('error');
82
+
83
+ expect(findImage().exists()).toBe(false);
84
+
85
+ await wrapper.setProps({ src: 'foo.jpg' });
86
+
87
+ expect(findImage().exists()).toBe(true);
88
+ expect(wrapper.find('.gl-avatar-identicon').exists()).toBe(false);
89
+ });
90
+ });
59
91
  });
@@ -104,6 +104,22 @@ export const WithTooltip = (args, { argTypes }) => ({
104
104
  });
105
105
  WithTooltip.args = { ...generateImageProps(), ...generateTooltipProps() };
106
106
 
107
+ export const FallbackOnAvatarLoadFailure = (args, { argTypes }) => ({
108
+ components,
109
+ props: Object.keys(argTypes),
110
+ template: `
111
+ <gl-avatar
112
+ :entity-name="entityName"
113
+ :entity-id="entityId"
114
+ :size="size"
115
+ :fallback-on-error="true"
116
+ src="someproject.jpg"
117
+ alt="Some Project"
118
+ />
119
+ `,
120
+ });
121
+ FallbackOnAvatarLoadFailure.args = { ...generateProjectFallbackProps(), ...generateImageProps() };
122
+
107
123
  export default {
108
124
  title: 'base/avatar',
109
125
  component: GlAvatar,
@@ -24,6 +24,14 @@ export default {
24
24
  required: false,
25
25
  default: '',
26
26
  },
27
+ /**
28
+ * Show fallback identicon when image fails to load
29
+ */
30
+ fallbackOnError: {
31
+ type: Boolean,
32
+ required: false,
33
+ default: false,
34
+ },
27
35
  alt: {
28
36
  type: String,
29
37
  required: false,
@@ -56,6 +64,11 @@ export default {
56
64
  default: avatarShapeOptions.circle,
57
65
  },
58
66
  },
67
+ data() {
68
+ return {
69
+ imageLoadError: false,
70
+ };
71
+ },
59
72
  computed: {
60
73
  sizeClasses() {
61
74
  if (isNumber(this.size)) {
@@ -85,15 +98,38 @@ export default {
85
98
  identiconText() {
86
99
  return getAvatarChar(this.entityName);
87
100
  },
101
+ showImage() {
102
+ // Don't show when image is not present
103
+ if (!this.src) {
104
+ return false;
105
+ }
106
+ // Don't show when fallbackOnError is true and there was failure to load image
107
+ if (this.src && this.fallbackOnError && this.imageLoadError) {
108
+ return false;
109
+ }
110
+ return true;
111
+ },
112
+ },
113
+ watch: {
114
+ src(newSrc, oldSrc) {
115
+ if (newSrc !== oldSrc) this.imageLoadError = false;
116
+ },
117
+ },
118
+ methods: {
119
+ handleLoadError(event) {
120
+ this.imageLoadError = true;
121
+ this.$emit('load-error', event);
122
+ },
88
123
  },
89
124
  };
90
125
  </script>
91
126
  <template>
92
127
  <img
93
- v-if="src"
128
+ v-if="showImage"
94
129
  :src="src"
95
130
  :alt="alt"
96
131
  :class="['gl-avatar', { 'gl-avatar-circle': isCircle }, sizeClasses]"
132
+ @error="handleLoadError"
97
133
  />
98
134
  <div
99
135
  v-else
@@ -3375,6 +3375,18 @@
3375
3375
  flex-wrap: nowrap !important;
3376
3376
  }
3377
3377
 
3378
+ .gl-md-flex-nowrap {
3379
+ @include gl-media-breakpoint-up(md) {
3380
+ flex-wrap: nowrap;
3381
+ }
3382
+ }
3383
+
3384
+ .gl-md-flex-nowrap\! {
3385
+ @include gl-media-breakpoint-up(md) {
3386
+ flex-wrap: nowrap !important;
3387
+ }
3388
+ }
3389
+
3378
3390
  .gl-sm-flex-nowrap {
3379
3391
  @include gl-media-breakpoint-up(sm) {
3380
3392
  flex-wrap: nowrap;
@@ -95,6 +95,12 @@
95
95
  flex-wrap: nowrap;
96
96
  }
97
97
 
98
+ @mixin gl-md-flex-nowrap {
99
+ @include gl-media-breakpoint-up(md) {
100
+ @include gl-flex-nowrap;
101
+ }
102
+ }
103
+
98
104
  @mixin gl-sm-flex-nowrap {
99
105
  @include gl-media-breakpoint-up(sm) {
100
106
  @include gl-flex-nowrap;