@gitlab/ui 38.10.1 → 38.12.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.
Files changed (23) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/components/base/alert/alert.js +1 -1
  3. package/dist/components/base/filtered_search/filtered_search.js +18 -2
  4. package/dist/components/base/filtered_search/filtered_search_term.js +6 -1
  5. package/dist/components/base/filtered_search/filtered_search_token.js +32 -4
  6. package/dist/components/base/filtered_search/filtered_search_token_segment.js +36 -16
  7. package/dist/components/charts/tooltip/tooltip.js +7 -1
  8. package/dist/index.css +1 -1
  9. package/dist/index.css.map +1 -1
  10. package/package.json +9 -9
  11. package/src/components/base/alert/alert.vue +8 -8
  12. package/src/components/base/filtered_search/__snapshots__/filtered_search_term.spec.js.snap +4 -4
  13. package/src/components/base/filtered_search/filtered_search.stories.js +8 -1
  14. package/src/components/base/filtered_search/filtered_search.vue +19 -0
  15. package/src/components/base/filtered_search/filtered_search_term.spec.js +1 -0
  16. package/src/components/base/filtered_search/filtered_search_term.vue +11 -1
  17. package/src/components/base/filtered_search/filtered_search_token.spec.js +1 -0
  18. package/src/components/base/filtered_search/filtered_search_token.vue +41 -1
  19. package/src/components/base/filtered_search/filtered_search_token_segment.spec.js +2 -2
  20. package/src/components/base/filtered_search/filtered_search_token_segment.vue +33 -12
  21. package/src/components/base/form/form_checkbox/form_checkbox.scss +4 -2
  22. package/src/components/charts/tooltip/tooltip.spec.js +42 -0
  23. package/src/components/charts/tooltip/tooltip.vue +13 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gitlab/ui",
3
- "version": "38.10.1",
3
+ "version": "38.12.0",
4
4
  "description": "GitLab UI Components",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -92,15 +92,15 @@
92
92
  "@rollup/plugin-commonjs": "^11.1.0",
93
93
  "@rollup/plugin-node-resolve": "^7.1.3",
94
94
  "@rollup/plugin-replace": "^2.3.2",
95
- "@storybook/addon-a11y": "6.4.20",
96
- "@storybook/addon-docs": "6.4.20",
97
- "@storybook/addon-essentials": "6.4.20",
95
+ "@storybook/addon-a11y": "6.4.22",
96
+ "@storybook/addon-docs": "6.4.22",
97
+ "@storybook/addon-essentials": "6.4.22",
98
98
  "@storybook/addon-knobs": "6.4.0",
99
- "@storybook/addon-storyshots": "6.4.20",
100
- "@storybook/addon-storyshots-puppeteer": "6.4.20",
101
- "@storybook/addon-viewport": "6.4.20",
102
- "@storybook/theming": "6.4.20",
103
- "@storybook/vue": "6.4.20",
99
+ "@storybook/addon-storyshots": "6.4.22",
100
+ "@storybook/addon-storyshots-puppeteer": "6.4.22",
101
+ "@storybook/addon-viewport": "6.4.22",
102
+ "@storybook/theming": "6.4.22",
103
+ "@storybook/vue": "6.4.22",
104
104
  "@vue/test-utils": "1.3.0",
105
105
  "autoprefixer": "^9.7.6",
106
106
  "babel-jest": "^26.6.3",
@@ -173,14 +173,6 @@ export default {
173
173
  :class="{ 'gl-alert-icon': true, 'gl-alert-icon-no-title': !title }"
174
174
  />
175
175
 
176
- <close-button
177
- v-if="dismissible"
178
- ref="dismiss"
179
- class="gl-dismiss-btn"
180
- :label="dismissLabel"
181
- @click="onDismiss"
182
- />
183
-
184
176
  <div class="gl-alert-content" role="alert">
185
177
  <h4 v-if="title" class="gl-alert-title">{{ title }}</h4>
186
178
 
@@ -204,5 +196,13 @@ export default {
204
196
  </slot>
205
197
  </div>
206
198
  </div>
199
+
200
+ <close-button
201
+ v-if="dismissible"
202
+ ref="dismiss"
203
+ class="gl-dismiss-btn"
204
+ :label="dismissLabel"
205
+ @click="onDismiss"
206
+ />
207
207
  </div>
208
208
  </template>
@@ -1,13 +1,13 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
3
  exports[`Filtered search term renders input with value in active mode 1`] = `
4
- <div class="gl-h-auto gl-filtered-search-term">
5
- <div active="true" value="test-value" class="gl-filtered-search-term-token">test-value</div>
4
+ <div data-testid="filtered-search-term" class="gl-h-auto gl-filtered-search-term">
5
+ <div active="true" cursor-position="end" value="test-value" class="gl-filtered-search-term-token">test-value</div>
6
6
  </div>
7
7
  `;
8
8
 
9
9
  exports[`Filtered search term renders value in inactive mode 1`] = `
10
- <div class="gl-h-auto gl-filtered-search-term">
11
- <div value="test-value" class="gl-filtered-search-term-token">test-value</div>
10
+ <div data-testid="filtered-search-term" class="gl-h-auto gl-filtered-search-term">
11
+ <div cursor-position="end" value="test-value" class="gl-filtered-search-term-token">test-value</div>
12
12
  </div>
13
13
  `;
@@ -9,6 +9,7 @@ import {
9
9
  GlIcon,
10
10
  GlToken,
11
11
  GlAvatar,
12
+ GlDropdownDivider,
12
13
  } from '../../../index';
13
14
  import { setStoryTimeout } from '../../../utils/test_utils';
14
15
  import { makeContainer } from '../../../utils/story_decorators/container';
@@ -178,7 +179,13 @@ const MilestoneToken = {
178
179
 
179
180
  const LabelToken = {
180
181
  name: 'LabelToken',
181
- components: { GlFilteredSearchToken, GlFilteredSearchSuggestion, GlLoadingIcon, GlToken },
182
+ components: {
183
+ GlFilteredSearchToken,
184
+ GlFilteredSearchSuggestion,
185
+ GlLoadingIcon,
186
+ GlToken,
187
+ GlDropdownDivider,
188
+ },
182
189
  props: ['value', 'active'],
183
190
  inheritAttrs: false,
184
191
  data() {
@@ -119,6 +119,7 @@ export default {
119
119
  tokens: initialState(),
120
120
  activeTokenIdx: null,
121
121
  suggestionsStyle: {},
122
+ intendedCursorPosition: 'end',
122
123
  };
123
124
  },
124
125
  computed: {
@@ -210,6 +211,20 @@ export default {
210
211
  this.activeTokenIdx = idx;
211
212
  },
212
213
 
214
+ activatePreviousToken() {
215
+ if (this.activeTokenIdx > 0) {
216
+ this.activeTokenIdx -= 1;
217
+ this.intendedCursorPosition = 'end';
218
+ }
219
+ },
220
+
221
+ activateNextToken() {
222
+ if (this.activeTokenIdx < this.value.length) {
223
+ this.activeTokenIdx += 1;
224
+ this.intendedCursorPosition = 'start';
225
+ }
226
+ },
227
+
213
228
  alignSuggestions(ref) {
214
229
  const offsetRef = ref.getBoundingClientRect().left;
215
230
  const offsetMenu = this.$el.getBoundingClientRect().left;
@@ -218,6 +233,7 @@ export default {
218
233
  },
219
234
 
220
235
  deactivate(token) {
236
+ this.intendedCursorPosition = 'end';
221
237
  const tokenIdx = this.tokens.indexOf(token);
222
238
  if (tokenIdx === -1 || this.activeTokenIdx !== tokenIdx) {
223
239
  return;
@@ -341,6 +357,7 @@ export default {
341
357
  v-model="token.value"
342
358
  :config="getTokenEntry(token.type)"
343
359
  :active="activeTokenIdx === idx"
360
+ :cursor-position="intendedCursorPosition"
344
361
  :available-tokens="currentAvailableTokens"
345
362
  :current-value="tokens"
346
363
  :index="idx"
@@ -359,6 +376,8 @@ export default {
359
376
  @complete="completeToken"
360
377
  @submit="submit"
361
378
  @split="createTokens(idx, $event)"
379
+ @previous="activatePreviousToken"
380
+ @next="activateNextToken"
362
381
  />
363
382
  </template>
364
383
  </div>
@@ -17,6 +17,7 @@ describe('Filtered search term', () => {
17
17
 
18
18
  const defaultProps = {
19
19
  availableTokens: [],
20
+ cursorPosition: 'end',
20
21
  };
21
22
 
22
23
  const segmentStub = {
@@ -63,6 +63,11 @@ export default {
63
63
  required: false,
64
64
  default: () => [],
65
65
  },
66
+ cursorPosition: {
67
+ type: String,
68
+ required: true,
69
+ validator: (value) => ['start', 'end'].includes(value),
70
+ },
66
71
  },
67
72
  computed: {
68
73
  suggestedTokens() {
@@ -101,7 +106,7 @@ export default {
101
106
  </script>
102
107
 
103
108
  <template>
104
- <div class="gl-h-auto gl-filtered-search-term">
109
+ <div class="gl-h-auto gl-filtered-search-term" data-testid="filtered-search-term">
105
110
  <!--
106
111
  Emitted when this term token is clicked.
107
112
  @event activate
@@ -125,9 +130,11 @@ export default {
125
130
  @property {array} newTokens Token configurations
126
131
  -->
127
132
  <gl-filtered-search-token-segment
133
+ ref="segment"
128
134
  v-model="internalValue"
129
135
  class="gl-filtered-search-term-token"
130
136
  :active="active"
137
+ :cursor-position="cursorPosition"
131
138
  :class="{ 'gl-w-full': placeholder }"
132
139
  :search-input-attributes="searchInputAttributes"
133
140
  :is-last-token="isLastToken"
@@ -138,6 +145,8 @@ export default {
138
145
  @backspace="onBackspace"
139
146
  @submit="$emit('submit')"
140
147
  @split="$emit('split', $event)"
148
+ @previous="$emit('previous')"
149
+ @next="$emit('next')"
141
150
  >
142
151
  <template #suggestions>
143
152
  <gl-filtered-search-suggestion
@@ -156,6 +165,7 @@ export default {
156
165
  class="gl-filtered-search-term-input"
157
166
  :placeholder="placeholder"
158
167
  :aria-label="placeholder"
168
+ data-testid="filtered-search-term-input"
159
169
  />
160
170
  <template v-else>{{ value.data }}</template>
161
171
  </template>
@@ -30,6 +30,7 @@ describe('Filtered search token', () => {
30
30
  const defaultProps = {
31
31
  config: { title: 'testTitle' },
32
32
  availableTokens,
33
+ cursorPosition: 'end',
33
34
  };
34
35
 
35
36
  const createComponent = (props) => {
@@ -65,11 +65,17 @@ export default {
65
65
  required: false,
66
66
  default: false,
67
67
  },
68
+ cursorPosition: {
69
+ type: String,
70
+ required: true,
71
+ validator: (value) => ['start', 'end'].includes(value),
72
+ },
68
73
  },
69
74
  data() {
70
75
  return {
71
76
  activeSegment: null,
72
77
  tokenValue: cloneDeep(this.value),
78
+ intendedCursorPosition: this.cursorPosition,
73
79
  };
74
80
  },
75
81
 
@@ -127,6 +133,7 @@ export default {
127
133
  immediate: true,
128
134
  handler(newValue) {
129
135
  if (newValue) {
136
+ this.intendedCursorPosition = this.cursorPosition;
130
137
  if (!this.activeSegment) {
131
138
  this.activateSegment(this.tokenValue.data !== '' ? SEGMENT_DATA : SEGMENT_OPERATOR);
132
139
  }
@@ -239,6 +246,26 @@ export default {
239
246
  this.activateSegment(this.$options.segments.SEGMENT_DATA);
240
247
  },
241
248
 
249
+ activatePreviousOperatorSegment() {
250
+ this.activateSegment(this.$options.segments.SEGMENT_OPERATOR);
251
+ this.intendedCursorPosition = 'end';
252
+ },
253
+
254
+ activatePreviousTitleSegment() {
255
+ this.activateSegment(this.$options.segments.SEGMENT_TITLE);
256
+ this.intendedCursorPosition = 'end';
257
+ },
258
+
259
+ activateNextDataSegment() {
260
+ this.activateDataSegment();
261
+ this.intendedCursorPosition = 'start';
262
+ },
263
+
264
+ activateNextOperatorSegment() {
265
+ this.activateSegment(this.$options.segments.SEGMENT_OPERATOR);
266
+ this.intendedCursorPosition = 'start';
267
+ },
268
+
242
269
  handleComplete() {
243
270
  if (this.config.multiSelect) {
244
271
  this.$emit('input', { ...this.tokenValue, data: this.multiSelectValues.join(COMMA) });
@@ -263,7 +290,11 @@ export default {
263
290
  </script>
264
291
 
265
292
  <template>
266
- <div class="gl-filtered-search-token" :class="{ 'gl-filtered-search-token-active': active }">
293
+ <div
294
+ class="gl-filtered-search-token"
295
+ :class="{ 'gl-filtered-search-token-active': active }"
296
+ data-testid="filtered-search-token"
297
+ >
267
298
  <!--
268
299
  Emitted when the token is submitted.
269
300
  @event submit
@@ -272,12 +303,15 @@ export default {
272
303
  key="title-segment"
273
304
  :value="config.title"
274
305
  :active="isSegmentActive($options.segments.SEGMENT_TITLE)"
306
+ :cursor-position="intendedCursorPosition"
275
307
  :options="availableTokensWithSelf"
276
308
  @activate="activateSegment($options.segments.SEGMENT_TITLE)"
277
309
  @deactivate="$emit('deactivate')"
278
310
  @complete="replaceToken"
279
311
  @backspace="$emit('destroy')"
280
312
  @submit="$emit('submit')"
313
+ @previous="$emit('previous')"
314
+ @next="activateNextOperatorSegment"
281
315
  >
282
316
  <template #view="{ inputValue }">
283
317
  <gl-token
@@ -292,6 +326,7 @@ export default {
292
326
  key="operator-segment"
293
327
  v-model="tokenValue.operator"
294
328
  :active="isSegmentActive($options.segments.SEGMENT_OPERATOR)"
329
+ :cursor-position="intendedCursorPosition"
295
330
  :options="operators"
296
331
  :custom-input-keydown-handler="handleOperatorKeydown"
297
332
  view-only
@@ -299,6 +334,8 @@ export default {
299
334
  @backspace="replaceWithTermIfEmpty"
300
335
  @complete="activateSegment($options.segments.SEGMENT_DATA)"
301
336
  @deactivate="$emit('deactivate')"
337
+ @previous="activatePreviousTitleSegment"
338
+ @next="activateNextDataSegment"
302
339
  >
303
340
  <template #view>
304
341
  <gl-token
@@ -333,6 +370,7 @@ export default {
333
370
  key="data-segment"
334
371
  v-model="tokenValue.data"
335
372
  :active="isSegmentActive($options.segments.SEGMENT_DATA)"
373
+ :cursor-position="intendedCursorPosition"
336
374
  :multi-select="config.multiSelect"
337
375
  :options="config.options"
338
376
  option-text-field="title"
@@ -343,6 +381,8 @@ export default {
343
381
  @submit="$emit('submit')"
344
382
  @deactivate="$emit('deactivate')"
345
383
  @split="$emit('split', $event)"
384
+ @previous="activatePreviousOperatorSegment"
385
+ @next="$emit('next')"
346
386
  >
347
387
  <template #suggestions>
348
388
  <!-- @slot The suggestions (implemented with GlFilteredSearchSuggestion). -->
@@ -35,7 +35,7 @@ describe('Filtered search token segment', () => {
35
35
  };
36
36
 
37
37
  wrapper = shallowMount(GlFilteredSearchTokenSegment, {
38
- propsData: props,
38
+ propsData: { ...props, cursorPosition: 'end' },
39
39
  provide: {
40
40
  portalName: 'fakePortal',
41
41
  alignSuggestions: alignSuggestionsMock,
@@ -64,7 +64,7 @@ describe('Filtered search token segment', () => {
64
64
  };
65
65
 
66
66
  wrapper = shallowMount(fakeParent, {
67
- propsData: otherProps,
67
+ propsData: { ...otherProps, cursorPosition: 'end' },
68
68
  stubs: { GlFilteredSearchTokenSegment },
69
69
  });
70
70
  };
@@ -77,6 +77,11 @@ export default {
77
77
  required: false,
78
78
  default: () => [],
79
79
  },
80
+ cursorPosition: {
81
+ type: String,
82
+ required: true,
83
+ validator: (value) => ['start', 'end'].includes(value),
84
+ },
80
85
  },
81
86
 
82
87
  data() {
@@ -198,6 +203,9 @@ export default {
198
203
  input.focus();
199
204
  input.scrollIntoView({ block: 'nearest', inline: 'end' });
200
205
  this.alignSuggestions(input);
206
+ if (this.cursorPosition === 'start') {
207
+ input?.setSelectionRange(0, 0);
208
+ }
201
209
  }
202
210
  });
203
211
  },
@@ -230,20 +238,31 @@ export default {
230
238
 
231
239
  handleInputKeydown(e) {
232
240
  const { key } = e;
233
- const { suggestions } = this.$refs;
241
+ const { suggestions, input } = this.$refs;
234
242
  const suggestedValue = suggestions?.getValue();
235
- if (key === 'Backspace') {
236
- if (this.inputValue === '') {
237
- e.preventDefault();
238
- /**
239
- * Emitted when Backspace is pressed and the value is empty
240
- */
241
- this.$emit('backspace');
242
- }
243
- return;
244
- }
245
243
 
246
244
  const handlers = {
245
+ ArrowLeft: () => {
246
+ if (input.selectionStart === 0) {
247
+ e.preventDefault();
248
+ this.$emit('previous');
249
+ }
250
+ },
251
+ ArrowRight: () => {
252
+ if (input.selectionEnd === this.inputValue.length) {
253
+ e.preventDefault();
254
+ this.$emit('next');
255
+ }
256
+ },
257
+ Backspace: () => {
258
+ if (this.inputValue === '') {
259
+ e.preventDefault();
260
+ /**
261
+ * Emitted when Backspace is pressed and the value is empty
262
+ */
263
+ this.$emit('backspace');
264
+ }
265
+ },
247
266
  Enter: () => {
248
267
  e.preventDefault();
249
268
  if (suggestedValue != null) {
@@ -311,7 +330,9 @@ export default {
311
330
  <div
312
331
  v-bind="containerAttributes"
313
332
  class="gl-filtered-search-token-segment"
314
- :class="{ 'gl-filtered-search-token-segment-active': active }"
333
+ :class="{
334
+ 'gl-filtered-search-token-segment-active': active,
335
+ }"
315
336
  data-testid="filtered-search-token-segment"
316
337
  @mousedown.left="emitIfInactive"
317
338
  >
@@ -43,9 +43,11 @@
43
43
  }
44
44
 
45
45
  .form-check-input:disabled,
46
- .form-check-input:disabled ~ .form-check-label {
46
+ .form-check-input:disabled ~ .form-check-label,
47
+ .custom-control-input:disabled,
48
+ .custom-control-input:disabled ~ .custom-control-label {
47
49
  @include gl-cursor-not-allowed;
48
- @include gl-text-gray-500;
50
+ @include gl-text-gray-400;
49
51
  }
50
52
 
51
53
  &.custom-control {
@@ -0,0 +1,42 @@
1
+ import { shallowMount } from '@vue/test-utils';
2
+ import GlPopover from '../../base/popover/popover.vue';
3
+ import { popoverPlacements } from '../../../utils/constants';
4
+ import ChartTooltip from './tooltip.vue';
5
+ import { createMockChartInstance } from '~helpers/chart_stubs';
6
+
7
+ let mockChartInstance;
8
+
9
+ jest.mock('echarts', () => ({
10
+ getInstanceByDom: () => mockChartInstance,
11
+ }));
12
+
13
+ describe('ChartTooltip', () => {
14
+ let wrapper;
15
+
16
+ const findGlPopover = () => wrapper.findComponent(GlPopover);
17
+
18
+ const createWrapper = (props = {}) => {
19
+ mockChartInstance = createMockChartInstance();
20
+ wrapper = shallowMount(ChartTooltip, {
21
+ propsData: {
22
+ chart: mockChartInstance,
23
+ ...props,
24
+ },
25
+ });
26
+ };
27
+
28
+ describe('GlPopover', () => {
29
+ it('is right-positioned by default', () => {
30
+ createWrapper();
31
+
32
+ expect(findGlPopover().props('placement')).toBe(popoverPlacements.right);
33
+ });
34
+
35
+ it('applies passed placement if any', () => {
36
+ const placement = popoverPlacements.bottom;
37
+ createWrapper({ placement });
38
+
39
+ expect(findGlPopover().props('placement')).toBe(placement);
40
+ });
41
+ });
42
+ });
@@ -2,6 +2,7 @@
2
2
  import * as echarts from 'echarts';
3
3
  import { uid } from '../../../utils/utils';
4
4
  import GlPopover from '../../base/popover/popover.vue';
5
+ import { popoverPlacements } from '../../../utils/constants';
5
6
 
6
7
  export default {
7
8
  components: {
@@ -41,6 +42,11 @@ export default {
41
42
  required: false,
42
43
  default: null,
43
44
  },
45
+ placement: {
46
+ type: String,
47
+ required: false,
48
+ default: popoverPlacements.right,
49
+ },
44
50
  },
45
51
  computed: {
46
52
  containerId() {
@@ -80,7 +86,13 @@ export default {
80
86
  Needs to be triggered programatically using `show` property
81
87
  This is why `triggers` is currently set to an empty string
82
88
  -->
83
- <gl-popover v-bind="$attrs" :target="containerId" :container="containerId" triggers="">
89
+ <gl-popover
90
+ v-bind="$attrs"
91
+ :target="containerId"
92
+ :container="containerId"
93
+ :placement="placement"
94
+ triggers=""
95
+ >
84
96
  <template v-if="$scopedSlots.title" #title>
85
97
  <slot name="title"></slot>
86
98
  </template>