@gitlab/ui 32.57.0 → 32.61.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.
@@ -116,6 +116,7 @@ export const setupStorybookReadme = () =>
116
116
  'GlModal',
117
117
  'GlKeysetPagination',
118
118
  'GlForm',
119
+ 'GlTable',
119
120
  ],
120
121
  components: {
121
122
  GlComponentDocumentation,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gitlab/ui",
3
- "version": "32.57.0",
3
+ "version": "32.61.0",
4
4
  "description": "GitLab UI Components",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -1,6 +1,7 @@
1
1
  import { shallowMount } from '@vue/test-utils';
2
2
  import { BBreadcrumbItem } from 'bootstrap-vue';
3
- import Breadcrumb from './breadcrumb.vue';
3
+ import Breadcrumb, { COLLAPSE_AT_SIZE } from './breadcrumb.vue';
4
+ import { createMockDirective } from '~helpers/vue_mock_directive';
4
5
 
5
6
  describe('Broadcast message component', () => {
6
7
  let wrapper;
@@ -14,10 +15,24 @@ describe('Broadcast message component', () => {
14
15
  { text: 'third_breadcrumb', href: 'http://about.gitlab.com' },
15
16
  ];
16
17
 
18
+ const extraItems = [
19
+ { text: 'fourth_breadcrumb', href: 'http://gitlab.com' },
20
+ {
21
+ text: 'fifth_breadcrumb',
22
+ to: 'to_value',
23
+ },
24
+ ];
25
+
17
26
  const findAvatarSlot = () => wrapper.find('[data-testid="avatar-slot"]');
18
27
  const findSeparatorSlot = () => wrapper.find('[data-testid="separator-slot"]');
19
28
  const findBreadcrumbItems = () => wrapper.findAllComponents(BBreadcrumbItem);
20
29
  const findAllSeparators = () => wrapper.findAll('[data-testid="separator"]');
30
+ const findCollapsedListExpander = () => wrapper.find('[data-testid="collapsed-expander"]');
31
+ const findExpanderSeparator = () => wrapper.find('[data-testid="expander-separator"]');
32
+
33
+ const findVisibleBreadcrumbItems = () =>
34
+ wrapper.findAll('.gl-breadcrumb-item:not(.gl-display-none)');
35
+ const findHiddenBreadcrumbItems = () => wrapper.findAll('.gl-breadcrumb-item.gl-display-none');
21
36
 
22
37
  const createComponent = (propsData = { items }) => {
23
38
  wrapper = shallowMount(Breadcrumb, {
@@ -26,7 +41,14 @@ describe('Broadcast message component', () => {
26
41
  avatar: '<div data-testid="avatar-slot"></div>',
27
42
  separator: '<div data-testid="separator-slot"></div>',
28
43
  },
44
+ directives: { GlTooltip: createMockDirective('gl-tooltip') },
29
45
  });
46
+
47
+ wrapper.vm.$refs.firstItem = [
48
+ {
49
+ querySelector: () => ({ focus: jest.fn() }),
50
+ },
51
+ ];
30
52
  };
31
53
 
32
54
  describe('slots', () => {
@@ -82,4 +104,45 @@ describe('Broadcast message component', () => {
82
104
  });
83
105
  });
84
106
  });
107
+
108
+ describe('collapsible', () => {
109
+ describe(`when breadcrumbs list size is NOT larger than ${COLLAPSE_AT_SIZE}`, () => {
110
+ beforeEach(() => {
111
+ createComponent();
112
+ });
113
+ it('should not display collapsed list expander && separator', () => {
114
+ expect(findCollapsedListExpander().exists()).toBe(false);
115
+ expect(findExpanderSeparator().exists()).toBe(false);
116
+ });
117
+
118
+ it('should display all items visible', () => {
119
+ expect(findVisibleBreadcrumbItems()).toHaveLength(items.length);
120
+ });
121
+ });
122
+
123
+ describe(`when breadcrumbs list size is larger than ${COLLAPSE_AT_SIZE}`, () => {
124
+ beforeEach(() => {
125
+ createComponent({ items: [...items, ...extraItems] });
126
+ });
127
+ it('should display collapsed list expander && separator', () => {
128
+ expect(findCollapsedListExpander().exists()).toBe(true);
129
+ expect(findExpanderSeparator().exists()).toBe(true);
130
+ });
131
+
132
+ it('should display only first && 2 last items and the rest as hidden', () => {
133
+ const alwaysVisibleNum = 3;
134
+ expect(findVisibleBreadcrumbItems()).toHaveLength(alwaysVisibleNum);
135
+ expect(findHiddenBreadcrumbItems()).toHaveLength(
136
+ items.length + extraItems.length - alwaysVisibleNum
137
+ );
138
+ });
139
+
140
+ it('should expand the list on expander click', async () => {
141
+ findCollapsedListExpander().vm.$emit('click');
142
+ await wrapper.vm.$nextTick();
143
+ expect(findHiddenBreadcrumbItems()).toHaveLength(0);
144
+ expect(findVisibleBreadcrumbItems()).toHaveLength(items.length + extraItems.length);
145
+ });
146
+ });
147
+ });
85
148
  });
@@ -60,3 +60,25 @@ export default {
60
60
  },
61
61
  },
62
62
  };
63
+
64
+ const extraItems = [
65
+ {
66
+ text: 'Fifth Item',
67
+ href: '#',
68
+ },
69
+ {
70
+ text: 'Sixth Item',
71
+ href: '#',
72
+ },
73
+ {
74
+ text: 'Seventh Item',
75
+ href: '#',
76
+ },
77
+ {
78
+ text: 'Eighth Item',
79
+ href: '#',
80
+ },
81
+ ];
82
+
83
+ export const CollapsedItems = Template.bind({});
84
+ CollapsedItems.args = generateProps({ items: [...defaultItems, ...extraItems] });
@@ -1,12 +1,20 @@
1
1
  <script>
2
2
  import { BBreadcrumb, BBreadcrumbItem } from 'bootstrap-vue';
3
3
  import GlIcon from '../icon/icon.vue';
4
+ import GlButton from '../button/button.vue';
5
+ import { GlTooltipDirective } from '../../../directives/tooltip';
6
+
7
+ export const COLLAPSE_AT_SIZE = 4;
4
8
 
5
9
  export default {
6
10
  components: {
7
11
  BBreadcrumb,
8
12
  BBreadcrumbItem,
9
13
  GlIcon,
14
+ GlButton,
15
+ },
16
+ directives: {
17
+ GlTooltip: GlTooltipDirective,
10
18
  },
11
19
  inheritAttrs: false,
12
20
  props: {
@@ -25,9 +33,45 @@ export default {
25
33
  },
26
34
  },
27
35
  },
36
+ data() {
37
+ return {
38
+ isListCollapsed: true,
39
+ };
40
+ },
41
+ computed: {
42
+ breadcrumbsSize() {
43
+ return this.items.length;
44
+ },
45
+ hasCollapsible() {
46
+ return this.breadcrumbsSize > COLLAPSE_AT_SIZE;
47
+ },
48
+ nonCollapsibleIndices() {
49
+ return [0, this.breadcrumbsSize - 1, this.breadcrumbsSize - 2];
50
+ },
51
+ },
28
52
  methods: {
29
- isLastItem(items, index) {
30
- return index === items.length - 1;
53
+ isFirstItem(index) {
54
+ return index === 0;
55
+ },
56
+ isLastItem(index) {
57
+ return index === this.breadcrumbsSize - 1;
58
+ },
59
+ expandBreadcrumbs() {
60
+ this.isListCollapsed = false;
61
+ try {
62
+ this.$refs.firstItem[0].querySelector('a').focus();
63
+ } catch (e) {
64
+ /* eslint-disable-next-line no-console */
65
+ console.error(`Failed to set focus on the last breadcrumb item.`);
66
+ }
67
+ },
68
+ showCollapsedBreadcrumbsExpander(index) {
69
+ return index === 0 && this.hasCollapsible && this.isListCollapsed;
70
+ },
71
+ isItemCollapsed(index) {
72
+ return (
73
+ this.hasCollapsible && this.isListCollapsed && !this.nonCollapsibleIndices.includes(index)
74
+ );
31
75
  },
32
76
  },
33
77
  };
@@ -40,14 +84,16 @@ export default {
40
84
  <template v-for="(item, index) in items">
41
85
  <b-breadcrumb-item
42
86
  :key="index"
87
+ :ref="isFirstItem(index) ? 'firstItem' : null"
43
88
  class="gl-breadcrumb-item"
44
89
  :text="item.text"
45
90
  :href="item.href"
46
91
  :to="item.to"
92
+ :class="{ 'gl-display-none': isItemCollapsed(index) }"
47
93
  >
48
94
  <span>{{ item.text }}</span>
49
95
  <span
50
- v-if="!isLastItem(items, index)"
96
+ v-if="!isLastItem(index)"
51
97
  :key="`${index} ${item.text}`"
52
98
  class="gl-breadcrumb-separator"
53
99
  data-testid="separator"
@@ -58,6 +104,28 @@ export default {
58
104
  </slot>
59
105
  </span>
60
106
  </b-breadcrumb-item>
107
+
108
+ <template v-if="showCollapsedBreadcrumbsExpander(index)">
109
+ <!-- eslint-disable-next-line vue/valid-v-for -->
110
+ <gl-button
111
+ v-gl-tooltip.hover="'Show all breadcrumbs'"
112
+ aria-label="Show all breadcrumbs"
113
+ data-testid="collapsed-expander"
114
+ icon="ellipsis_h"
115
+ category="primary"
116
+ @click="expandBreadcrumbs"
117
+ />
118
+ <!-- eslint-disable-next-line vue/require-v-for-key -->
119
+ <span
120
+ key="expander"
121
+ class="gl-display-inline-flex gl-text-gray-500"
122
+ data-testid="expander-separator"
123
+ >
124
+ <slot name="separator">
125
+ <gl-icon name="chevron-right" />
126
+ </slot>
127
+ </span>
128
+ </template>
61
129
  </template>
62
130
  </b-breadcrumb>
63
131
  </nav>
@@ -1,9 +1,6 @@
1
- import examples from './examples';
2
1
  import description from './table.md';
3
2
 
4
3
  export default {
5
4
  followsDesignSystem: false,
6
5
  description,
7
- examples,
8
- bootstrapComponent: 'b-table',
9
6
  };
@@ -1,13 +1,6 @@
1
- import { withKnobs, boolean, select, text } from '@storybook/addon-knobs';
2
- import { documentedStoriesOf } from '../../../../documentation/documented_stories';
3
1
  import { GlTable } from '../../../../index';
4
- import { variantOptions } from '../../../utils/constants';
5
2
  import readme from './table.md';
6
3
 
7
- const components = {
8
- GlTable,
9
- };
10
-
11
4
  const tableItems = [
12
5
  {
13
6
  column_one: 'test',
@@ -23,75 +16,96 @@ const tableItems = [
23
16
  },
24
17
  ];
25
18
 
26
- function generateProps() {
27
- const props = {
28
- fixed: {
29
- type: Boolean,
30
- default: boolean('fixed', false),
31
- },
32
- footClone: {
33
- type: Boolean,
34
- default: boolean('foot-clone', false),
19
+ const generateProps = ({ fixed = false, footClone = false, stacked = false } = {}) => ({
20
+ fixed,
21
+ footClone,
22
+ stacked,
23
+ });
24
+
25
+ export const Default = (args, { argTypes }) => ({
26
+ props: Object.keys(argTypes),
27
+ template: `
28
+ <gl-table
29
+ :items="$options.items"
30
+ :fields="$options.fields"
31
+ :fixed="fixed"
32
+ :stacked="stacked"
33
+ :foot-clone="footClone"
34
+ hover
35
+ selectable
36
+ selected-variant="primary"
37
+ />
38
+ `,
39
+ fields: [
40
+ {
41
+ key: 'column_one',
42
+ label: 'Column One',
43
+ variant: 'secondary',
44
+ sortable: false,
45
+ isRowHeader: false,
35
46
  },
36
- stacked: {
37
- type: [String, Boolean],
38
- default: select('stacked', ['sm', 'md', 'lg', 'xl', true, false], false),
47
+ {
48
+ key: 'col_2',
49
+ label: 'Column 2',
50
+ formatter: (value) => value,
39
51
  },
40
- };
52
+ ],
53
+ items: tableItems,
54
+ });
55
+ Default.args = generateProps();
41
56
 
42
- return props;
43
- }
44
-
45
- documentedStoriesOf('base/table/table', readme)
46
- .addDecorator(withKnobs)
47
- .add('default', () => ({
48
- components,
49
- props: generateProps(),
50
- template: `
51
- <gl-table
52
- :items="$options.items"
53
- :fields="$options.fields"
54
- :fixed="fixed"
55
- :stacked="stacked"
56
- :foot-clone="footClone"
57
- hover
58
- selectable
59
- selected-variant="primary"
60
- />
61
- `,
62
- fields: [
63
- {
64
- key: 'column_one',
65
- label: 'Column One',
66
- variant: select('variant', variantOptions, variantOptions.secondary),
67
- sortable: boolean('sortable', false),
68
- isRowHeader: boolean('isRowHeader', false),
69
- },
70
- {
71
- key: 'col_2',
72
- label: 'Column 2',
73
- formatter: (value) => `${text('formatterExample', '$')}${value}`,
74
- },
75
- ],
76
- items: tableItems,
77
- }))
78
- .add('empty', () => ({
79
- components,
80
- template: `
57
+ export const Empty = (args, { argTypes }) => ({
58
+ props: Object.keys(argTypes),
59
+ template: `
81
60
  <gl-table show-empty />
82
61
  `,
83
- }))
84
- .add('with filter', () => ({
85
- components,
86
- template: `<div class="gl-line-height-normal">
62
+ });
63
+ Empty.parameters = { controls: { disable: true } };
64
+
65
+ export const WithFilter = (args, { argTypes }) => ({
66
+ props: Object.keys(argTypes),
67
+ template: `<div class="gl-line-height-normal">
87
68
  <gl-form-input v-model="filter" placeholder="Type to search" />
88
69
  <br />
89
- <gl-table :items="$options.items" :fields="$options.fields" :filter=filter />
90
- </div>`,
91
- items: tableItems,
92
- data() {
93
- return {
94
- filter: null,
95
- };
70
+ <gl-table
71
+ :items="$options.items"
72
+ :fields="$options.fields"
73
+ :filter=filter
74
+ :fixed="fixed"
75
+ :stacked="stacked"
76
+ :foot-clone="footClone"
77
+ hover
78
+ selectable
79
+ selected-variant="primary"
80
+ />
81
+ </div>`,
82
+ items: tableItems,
83
+ data() {
84
+ return {
85
+ filter: null,
86
+ };
87
+ },
88
+ });
89
+ WithFilter.args = generateProps();
90
+
91
+ export default {
92
+ title: 'base/table/table',
93
+ component: GlTable,
94
+ parameters: {
95
+ bootstrapComponent: 'b-table',
96
+ knobs: { disable: true },
97
+ docs: {
98
+ description: {
99
+ component: readme,
100
+ },
96
101
  },
97
- }));
102
+ },
103
+ argTypes: {
104
+ stacked: {
105
+ control: {
106
+ type: 'select',
107
+ options: ['sm', 'md', 'lg', 'xl', true, false],
108
+ },
109
+ },
110
+ },
111
+ };
@@ -4263,6 +4263,18 @@
4263
4263
  }
4264
4264
  }
4265
4265
 
4266
+ .gl-lg-w-25p {
4267
+ @include gl-media-breakpoint-up(lg) {
4268
+ width: 25%;
4269
+ }
4270
+ }
4271
+
4272
+ .gl-lg-w-25p\! {
4273
+ @include gl-media-breakpoint-up(lg) {
4274
+ width: 25% !important;
4275
+ }
4276
+ }
4277
+
4266
4278
  .gl-lg-w-50p {
4267
4279
  @include gl-media-breakpoint-up(lg) {
4268
4280
  width: 50%;
@@ -5574,6 +5586,16 @@
5574
5586
  margin-bottom: $gl-spacing-scale-3 !important;
5575
5587
  }
5576
5588
  }
5589
+ .gl-xs-mb-4 {
5590
+ @include gl-media-breakpoint-down(sm) {
5591
+ margin-bottom: $gl-spacing-scale-4;
5592
+ }
5593
+ }
5594
+ .gl-xs-mb-4\! {
5595
+ @include gl-media-breakpoint-down(sm) {
5596
+ margin-bottom: $gl-spacing-scale-4 !important;
5597
+ }
5598
+ }
5577
5599
  .gl-sm-ml-3 {
5578
5600
  @include gl-media-breakpoint-up(sm) {
5579
5601
  margin-left: $gl-spacing-scale-3;
@@ -6284,6 +6306,16 @@
6284
6306
  padding-left: $gl-spacing-scale-5 !important;
6285
6307
  }
6286
6308
  }
6309
+ .gl-md-pl-7 {
6310
+ @include gl-media-breakpoint-up(md) {
6311
+ padding-left: $gl-spacing-scale-7;
6312
+ }
6313
+ }
6314
+ .gl-md-pl-7\! {
6315
+ @include gl-media-breakpoint-up(md) {
6316
+ padding-left: $gl-spacing-scale-7 !important;
6317
+ }
6318
+ }
6287
6319
  .gl-lg-pt-0 {
6288
6320
  @include gl-media-breakpoint-up(lg) {
6289
6321
  padding-top: 0;
@@ -7167,6 +7199,14 @@
7167
7199
  font-size: $gl-font-size-compact-markdown-h1 !important;
7168
7200
  }
7169
7201
 
7202
+ .gl-reset-font-size {
7203
+ font-size: inherit;
7204
+ }
7205
+
7206
+ .gl-reset-font-size\! {
7207
+ font-size: inherit !important;
7208
+ }
7209
+
7170
7210
  .gl-font-weight-100 {
7171
7211
  font-weight: 100;
7172
7212
  }
@@ -236,6 +236,12 @@
236
236
  }
237
237
  }
238
238
 
239
+ @mixin gl-lg-w-25p {
240
+ @include gl-media-breakpoint-up(lg) {
241
+ width: 25%;
242
+ }
243
+ }
244
+
239
245
  @mixin gl-lg-w-50p {
240
246
  @include gl-media-breakpoint-up(lg) {
241
247
  width: 50%;
@@ -761,6 +761,12 @@
761
761
  }
762
762
  }
763
763
 
764
+ @mixin gl-xs-mb-4 {
765
+ @include gl-media-breakpoint-down(sm) {
766
+ @include gl-mb-4;
767
+ }
768
+ }
769
+
764
770
  @mixin gl-sm-ml-3 {
765
771
  @include gl-media-breakpoint-up(sm) {
766
772
  @include gl-ml-3;
@@ -1189,6 +1195,12 @@
1189
1195
  }
1190
1196
  }
1191
1197
 
1198
+ @mixin gl-md-pl-7 {
1199
+ @include gl-media-breakpoint-up(md) {
1200
+ @include gl-pl-7;
1201
+ }
1202
+ }
1203
+
1192
1204
  @mixin gl-lg-pt-0 {
1193
1205
  @include gl-media-breakpoint-up(lg) {
1194
1206
  @include gl-pt-0;
@@ -110,6 +110,10 @@
110
110
  font-size: $gl-font-size-compact-markdown-h1;
111
111
  }
112
112
 
113
+ @mixin gl-reset-font-size {
114
+ font-size: inherit;
115
+ }
116
+
113
117
  /**
114
118
  * Font-weight utilities.
115
119
  *
@@ -1,19 +0,0 @@
1
- import component from './table.basic.example';
2
- import componentCustomFields from './table.custom_fields.example';
3
-
4
- var index = [{
5
- name: 'Basic',
6
- items: [{
7
- id: 'table-basic',
8
- name: 'Basic',
9
- description: 'Basic Table',
10
- component
11
- }, {
12
- id: 'table-custom-fields',
13
- name: 'Custom Fields',
14
- description: 'Custom component fields',
15
- component: componentCustomFields
16
- }]
17
- }];
18
-
19
- export default index;
@@ -1,59 +0,0 @@
1
- import __vue_normalize__ from 'vue-runtime-helpers/dist/normalize-component.js';
2
-
3
- var script = {
4
- fields: [{
5
- key: 'column_one',
6
- label: 'Column One'
7
- }, {
8
- key: 'col_2',
9
- label: 'Column 2'
10
- }],
11
- items: [{
12
- column_one: 'test',
13
- col_2: 1234
14
- }, {
15
- column_one: 'test2',
16
- col_2: 5678
17
- }, {
18
- column_one: 'test3',
19
- col_2: 9101
20
- }]
21
- };
22
-
23
- /* script */
24
- const __vue_script__ = script;
25
-
26
- /* template */
27
- var __vue_render__ = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('gl-table',{attrs:{"items":_vm.$options.items,"fields":_vm.$options.fields}})};
28
- var __vue_staticRenderFns__ = [];
29
-
30
- /* style */
31
- const __vue_inject_styles__ = undefined;
32
- /* scoped */
33
- const __vue_scope_id__ = undefined;
34
- /* module identifier */
35
- const __vue_module_identifier__ = undefined;
36
- /* functional template */
37
- const __vue_is_functional_template__ = false;
38
- /* style inject */
39
-
40
- /* style inject SSR */
41
-
42
- /* style inject shadow dom */
43
-
44
-
45
-
46
- const __vue_component__ = __vue_normalize__(
47
- { render: __vue_render__, staticRenderFns: __vue_staticRenderFns__ },
48
- __vue_inject_styles__,
49
- __vue_script__,
50
- __vue_scope_id__,
51
- __vue_is_functional_template__,
52
- __vue_module_identifier__,
53
- false,
54
- undefined,
55
- undefined,
56
- undefined
57
- );
58
-
59
- export default __vue_component__;