@gitlab/ui 42.14.0 → 42.17.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": "42.14.0",
3
+ "version": "42.17.0",
4
4
  "description": "GitLab UI Components",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -83,7 +83,7 @@
83
83
  "@babel/preset-env": "^7.10.2",
84
84
  "@gitlab/eslint-plugin": "13.0.0",
85
85
  "@gitlab/stylelint-config": "4.1.0",
86
- "@gitlab/svgs": "2.25.0",
86
+ "@gitlab/svgs": "2.26.0",
87
87
  "@rollup/plugin-commonjs": "^11.1.0",
88
88
  "@rollup/plugin-node-resolve": "^7.1.3",
89
89
  "@rollup/plugin-replace": "^2.3.2",
@@ -1,5 +1,6 @@
1
1
  $gl-drawer-width: 400px;
2
2
  $gl-sidebar-width: 290px;
3
+ $gl-drawer-scrim-gradient: linear-gradient(to bottom, $transparent-rgba, $white);
3
4
 
4
5
  .gl-drawer {
5
6
  @include gl-right-0;
@@ -61,6 +62,20 @@ $gl-sidebar-width: 290px;
61
62
  @include gl-py-5;
62
63
  }
63
64
 
65
+ .gl-drawer-body-scrim-on-footer {
66
+ &::before {
67
+ background: $gl-drawer-scrim-gradient;
68
+ top: -$gl-border-size-1;
69
+ @include gl-translate-y-n100;
70
+ @include gl-content-empty;
71
+ @include gl-left-0;
72
+ @include gl-absolute;
73
+ @include gl-pointer-events-none;
74
+ @include gl-w-full;
75
+ @include gl-h-7;
76
+ }
77
+ }
78
+
64
79
  .gl-drawer-footer-sticky {
65
80
  @include gl-bg-white;
66
81
  @include gl-bottom-0;
@@ -94,6 +109,18 @@ $gl-sidebar-width: 290px;
94
109
  @include gl-flex-grow-1;
95
110
  }
96
111
 
112
+ .gl-drawer-body-scrim {
113
+ &::after {
114
+ background: $gl-drawer-scrim-gradient;
115
+ @include gl-content-empty;
116
+ @include gl-bottom-0;
117
+ @include gl-pointer-events-none;
118
+ @include gl-w-full;
119
+ @include gl-fixed;
120
+ @include gl-h-7;
121
+ }
122
+ }
123
+
97
124
  .gl-drawer-body > * {
98
125
  @include gl-border-b-solid;
99
126
  @include gl-border-b-gray-100;
@@ -101,6 +101,28 @@ describe('drawer component', () => {
101
101
  expect(wrapper.find(parentSelector).find(`[data-testid="${slot}"]`).exists()).toBe(true);
102
102
  });
103
103
 
104
+ it('should add scrim to footer', () => {
105
+ mountWithOpts({
106
+ slots: {
107
+ footer: `<div data-testid="footer" />`,
108
+ },
109
+ });
110
+
111
+ expect(wrapper.find('.gl-drawer-footer').classes()).toContain('gl-drawer-body-scrim-on-footer');
112
+ expect(wrapper.find('.gl-drawer-body').classes()).not.toContain('gl-drawer-body-scrim');
113
+ });
114
+
115
+ it('should add scrim to scrollable container', () => {
116
+ mountWithOpts({
117
+ slots: {
118
+ default: `<div data-testid="default" />`,
119
+ },
120
+ });
121
+
122
+ expect(wrapper.find('.gl-drawer-footer').exists()).toBe(false);
123
+ expect(wrapper.find('.gl-drawer-body').classes()).toContain('gl-drawer-body-scrim');
124
+ });
125
+
104
126
  it.each`
105
127
  variant | variantClass
106
128
  ${'default'} | ${'gl-drawer-default'}
@@ -1,8 +1,33 @@
1
- import { GlDrawer, GlButton } from '../../../index';
1
+ import { GlDrawer, GlButton, GlMarkdown } from '../../../index';
2
2
  import { drawerVariants } from '../../../utils/constants';
3
3
  import readme from './drawer.md';
4
4
 
5
- const components = { GlDrawer, GlButton };
5
+ const components = { GlDrawer, GlButton, GlMarkdown };
6
+
7
+ const generateStaticContent = (number = 1) =>
8
+ Array.from(
9
+ Array(number),
10
+ (_, index) => `
11
+ <div class="gl-mb-8">
12
+ <h4 class="gl-mb-4">View jobs in a pipeline ${index}</h4>
13
+ <p>
14
+ Pipeline configuration begins with jobs. Jobs are the most fundamental element of a .gitlab-ci.yml file.
15
+ </p>
16
+ <p>Jobs are:</p>
17
+ <ul>
18
+ <li>Defined with constraints stating under what conditions they should be executed. </li>
19
+ <li>Top-level elements with an arbitrary name and must contain at least the script clause.</li>
20
+ <li>Not limited in how many can be defined.</li>
21
+ </ul>
22
+ <p>For example:</p>
23
+ <gl-markdown compact>
24
+ <code>job1: script: "execute-script-for-job1"</code>
25
+ <br />
26
+ <code>job2: script: "execute-script-for-job2"</code>
27
+ </gl-markdown>
28
+ </div>
29
+ `
30
+ ).join('');
6
31
 
7
32
  const generateDrawerContent = (items) =>
8
33
  items
@@ -145,6 +170,24 @@ export const WithStickyFooter = (_args, { viewMode }) => ({
145
170
 
146
171
  WithStickyFooter.args = generateProps();
147
172
 
173
+ export const WithScrimAndStaticContent = (_args, { viewMode }) => ({
174
+ ...storyOptions(viewMode),
175
+ template: `
176
+ <div>
177
+ <gl-button @click="toggle">Toggle Drawer</gl-button>
178
+ ${createSidebarTemplate(`
179
+ <template #title>List Settings</template>
180
+ <div>
181
+ ${generateStaticContent(3)}
182
+ </div>
183
+ `)}
184
+ </div>`,
185
+ });
186
+
187
+ WithScrimAndStaticContent.args = generateProps({
188
+ headerSticky: true,
189
+ });
190
+
148
191
  export const SidebarVariant = (_args, { viewMode }) => ({
149
192
  ...storyOptions(viewMode),
150
193
  template: `
@@ -110,12 +110,13 @@ export default {
110
110
  </span>
111
111
  <slot name="header"></slot>
112
112
  </div>
113
- <div class="gl-drawer-body">
113
+ <div class="gl-drawer-body" :class="{ 'gl-drawer-body-scrim': !shouldRenderFooter }">
114
114
  <slot></slot>
115
115
  </div>
116
116
  <div
117
117
  v-if="shouldRenderFooter"
118
118
  class="gl-drawer-footer gl-drawer-footer-sticky"
119
+ :class="{ 'gl-drawer-body-scrim-on-footer': shouldRenderFooter }"
119
120
  :style="{ zIndex }"
120
121
  >
121
122
  <slot name="footer"></slot>
@@ -71,6 +71,29 @@ describe('GlTokenContainer', () => {
71
71
  });
72
72
  });
73
73
 
74
+ describe('clearing all tokens', () => {
75
+ const findClearAllButton = () => wrapper.find('[data-testid="clear-all-button"]');
76
+
77
+ it('does not render `Clear all` button by default', () => {
78
+ createComponent();
79
+
80
+ expect(findClearAllButton().exists()).toBe(false);
81
+ });
82
+
83
+ it('renders `Clear all` button when `showClearAllButton` prop is true', () => {
84
+ createComponent({ propsData: { showClearAllButton: true } });
85
+
86
+ expect(findClearAllButton().exists()).toBe(true);
87
+ });
88
+
89
+ it('emits `clear-all` event when `Clear all` button is clicked', () => {
90
+ createComponent({ propsData: { showClearAllButton: true } });
91
+ findClearAllButton().vm.$emit('click', new MouseEvent('click'));
92
+
93
+ expect(wrapper.emitted('clear-all')).toEqual([[]]);
94
+ });
95
+ });
96
+
74
97
  describe('state', () => {
75
98
  describe('when `state` is `false`', () => {
76
99
  it('adds `aria-invalid="true"` attribute`', () => {
@@ -1,10 +1,11 @@
1
1
  <script>
2
2
  import GlToken from '../token/token.vue';
3
+ import GlButton from '../button/button.vue';
3
4
  import { tokensValidator } from './helpers';
4
5
 
5
6
  export default {
6
7
  name: 'GlTokenContainer',
7
- components: { GlToken },
8
+ components: { GlToken, GlButton },
8
9
  props: {
9
10
  tokens: {
10
11
  type: Array,
@@ -26,6 +27,11 @@ export default {
26
27
  required: false,
27
28
  default: false,
28
29
  },
30
+ showClearAllButton: {
31
+ type: Boolean,
32
+ required: false,
33
+ default: false,
34
+ },
29
35
  },
30
36
  data() {
31
37
  return {
@@ -124,7 +130,7 @@ export default {
124
130
  <template>
125
131
  <div
126
132
  ref="tokenContainer"
127
- class="gl-display-flex gl-flex-wrap gl-align-items-center gl-my-n1 gl-mx-n1"
133
+ class="gl-display-flex gl-flex-wrap gl-align-items-center gl-my-n1 gl-mx-n1 gl-w-full"
128
134
  role="listbox"
129
135
  aria-multiselectable="false"
130
136
  aria-orientation="horizontal"
@@ -162,5 +168,14 @@ export default {
162
168
  </gl-token>
163
169
  </div>
164
170
  <slot name="text-input"></slot>
171
+ <gl-button
172
+ v-if="showClearAllButton"
173
+ size="small"
174
+ aria-label="Clear all"
175
+ icon="clear"
176
+ category="tertiary"
177
+ data-testid="clear-all-button"
178
+ @click.stop="$emit('clear-all')"
179
+ />
165
180
  </div>
166
181
  </template>
@@ -86,6 +86,8 @@ describe('GlTokenSelector', () => {
86
86
 
87
87
  const findContainer = () => wrapper.findComponent({ ref: 'container' });
88
88
 
89
+ const findTokenContainer = () => wrapper.findComponent(GlTokenContainer);
90
+
89
91
  beforeAll(() => {
90
92
  if (!HTMLElement.prototype.scrollIntoView) {
91
93
  HTMLElement.prototype.scrollIntoView = jest.fn();
@@ -149,7 +151,7 @@ describe('GlTokenSelector', () => {
149
151
  });
150
152
 
151
153
  it('passes `viewOnly` prop to GlTokenContainer', () => {
152
- expect(wrapper.findComponent(GlTokenContainer).props('viewOnly')).toBe(true);
154
+ expect(findTokenContainer().props('viewOnly')).toBe(true);
153
155
  });
154
156
 
155
157
  it('disables input field if viewOnly is true', () => {
@@ -159,6 +161,16 @@ describe('GlTokenSelector', () => {
159
161
  });
160
162
  });
161
163
 
164
+ describe('when there are tokens and `allowClearAll` is true', () => {
165
+ beforeEach(() => {
166
+ createComponent({ propsData: { allowClearAll: true, selectedTokens: tokens } });
167
+ });
168
+
169
+ it('passes `showClearAllButton` prop as `true` to token-container', () => {
170
+ expect(findTokenContainer().props('showClearAllButton')).toBe(true);
171
+ });
172
+ });
173
+
162
174
  describe('containerClass', () => {
163
175
  it('renders passed CSS classes', () => {
164
176
  createComponent({
@@ -290,7 +302,7 @@ describe('GlTokenSelector', () => {
290
302
  },
291
303
  });
292
304
 
293
- expect(wrapper.findComponent(GlTokenContainer).props('state')).toBe(true);
305
+ expect(findTokenContainer().props('state')).toBe(true);
294
306
  });
295
307
  });
296
308
 
@@ -589,7 +601,7 @@ describe('GlTokenSelector', () => {
589
601
  propsData: { selectedTokens: [token] },
590
602
  });
591
603
 
592
- wrapper.findComponent(GlTokenContainer).vm.$emit('token-remove', token);
604
+ findTokenContainer().vm.$emit('token-remove', token);
593
605
 
594
606
  await nextTick();
595
607
  });
@@ -631,7 +643,7 @@ describe('GlTokenSelector', () => {
631
643
  selectedTokens: tokens,
632
644
  });
633
645
 
634
- wrapper.findComponent(GlTokenContainer).vm.$emit('cancel-focus');
646
+ findTokenContainer().vm.$emit('cancel-focus');
635
647
 
636
648
  await nextTick();
637
649
 
@@ -1,6 +1,5 @@
1
1
  <script>
2
2
  import { uniqueId } from 'lodash';
3
-
4
3
  import { tokensValidator } from './helpers';
5
4
  import GlTokenContainer from './token_container.vue';
6
5
  import GlTokenSelectorDropdown from './token_selector_dropdown.vue';
@@ -8,7 +7,10 @@ import GlTokenSelectorDropdown from './token_selector_dropdown.vue';
8
7
  export default {
9
8
  name: 'GlTokenSelector',
10
9
  componentId: uniqueId('token-selector'),
11
- components: { GlTokenContainer, GlTokenSelectorDropdown },
10
+ components: {
11
+ GlTokenContainer,
12
+ GlTokenSelectorDropdown,
13
+ },
12
14
  model: {
13
15
  prop: 'selectedTokens',
14
16
  event: 'input',
@@ -121,6 +123,14 @@ export default {
121
123
  required: false,
122
124
  default: false,
123
125
  },
126
+ /**
127
+ * Allows user to bulk delete tokens when enabled
128
+ */
129
+ allowClearAll: {
130
+ type: Boolean,
131
+ required: false,
132
+ default: false,
133
+ },
124
134
  },
125
135
  data() {
126
136
  return {
@@ -173,8 +183,14 @@ export default {
173
183
  ? 'is-valid gl-inset-border-1-gray-400!'
174
184
  : 'is-invalid gl-inset-border-1-red-500!';
175
185
  },
186
+ hasSelectedTokens() {
187
+ return this.selectedTokens.length > 0;
188
+ },
176
189
  showEmptyPlaceholder() {
177
- return this.selectedTokens.length === 0 && !this.inputFocused;
190
+ return !this.hasSelectedTokens && !this.inputFocused;
191
+ },
192
+ showClearAllButton() {
193
+ return this.hasSelectedTokens && this.allowClearAll;
178
194
  },
179
195
  },
180
196
  watch: {
@@ -357,6 +373,10 @@ export default {
357
373
  registerFocusOnToken(focusOnToken) {
358
374
  this.focusOnToken = focusOnToken;
359
375
  },
376
+ clearAll() {
377
+ this.$emit('input', []);
378
+ this.focusTextInput();
379
+ },
360
380
  },
361
381
  };
362
382
  </script>
@@ -377,8 +397,10 @@ export default {
377
397
  :state="state"
378
398
  :register-focus-on-token="registerFocusOnToken"
379
399
  :view-only="viewOnly"
400
+ :show-clear-all-button="showClearAllButton"
380
401
  @token-remove="removeToken"
381
402
  @cancel-focus="cancelTokenFocus"
403
+ @clear-all="clearAll"
382
404
  >
383
405
  <template #token-content="{ token }">
384
406
  <!-- @slot Content to pass to the token component slot. Can be used
@@ -6178,6 +6178,12 @@
6178
6178
  .gl-gap-3\! {
6179
6179
  gap: $gl-spacing-scale-3 !important;
6180
6180
  }
6181
+ .gl-gap-5 {
6182
+ gap: $gl-spacing-scale-5;
6183
+ }
6184
+ .gl-gap-5\! {
6185
+ gap: $gl-spacing-scale-5 !important;
6186
+ }
6181
6187
  .gl-gap-6 {
6182
6188
  gap: $gl-spacing-scale-6;
6183
6189
  }
@@ -817,6 +817,10 @@
817
817
  gap: $gl-spacing-scale-3;
818
818
  }
819
819
 
820
+ @mixin gl-gap-5 {
821
+ gap: $gl-spacing-scale-5;
822
+ }
823
+
820
824
  @mixin gl-gap-6 {
821
825
  gap: $gl-spacing-scale-6;
822
826
  }