@gitlab/ui 32.29.2 → 32.33.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 (29) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/components/base/icon/icon.js +2 -19
  3. package/dist/components/base/toggle/toggle.js +8 -8
  4. package/dist/components/utilities/truncate/truncate.documentation.js +3 -0
  5. package/dist/components/utilities/truncate/truncate.js +34 -2
  6. package/dist/directives/resize_observer/resize_observer.documentation.js +1 -1
  7. package/dist/directives/resize_observer/resize_observer.js +43 -23
  8. package/dist/index.css +1 -1
  9. package/dist/index.css.map +1 -1
  10. package/dist/utility_classes.css +1 -1
  11. package/dist/utility_classes.css.map +1 -1
  12. package/package.json +2 -2
  13. package/scss_to_js/scss_variables.js +0 -1
  14. package/scss_to_js/scss_variables.json +0 -5
  15. package/src/components/base/icon/icon.scss +1 -1
  16. package/src/components/base/icon/icon.spec.js +4 -24
  17. package/src/components/base/icon/icon.vue +1 -16
  18. package/src/components/base/toggle/toggle.spec.js +1 -3
  19. package/src/components/base/toggle/toggle.vue +7 -8
  20. package/src/components/utilities/truncate/truncate.documentation.js +3 -0
  21. package/src/components/utilities/truncate/truncate.spec.js +8 -0
  22. package/src/components/utilities/truncate/truncate.stories.js +6 -2
  23. package/src/components/utilities/truncate/truncate.vue +57 -7
  24. package/src/directives/resize_observer/resize_observer.js +34 -19
  25. package/src/directives/resize_observer/resize_observer.md +20 -0
  26. package/src/directives/resize_observer/resize_observer.spec.js +33 -1
  27. package/src/scss/utilities.scss +32 -0
  28. package/src/scss/utility-mixins/border.scss +8 -0
  29. package/src/scss/variables.scss +0 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gitlab/ui",
3
- "version": "32.29.2",
3
+ "version": "32.33.0",
4
4
  "description": "GitLab UI Components",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -84,7 +84,7 @@
84
84
  "@babel/preset-env": "^7.10.2",
85
85
  "@gitlab/eslint-plugin": "9.4.0",
86
86
  "@gitlab/stylelint-config": "2.6.0",
87
- "@gitlab/svgs": "1.218.0",
87
+ "@gitlab/svgs": "1.219.0",
88
88
  "@rollup/plugin-commonjs": "^11.1.0",
89
89
  "@rollup/plugin-node-resolve": "^7.1.3",
90
90
  "@rollup/plugin-replace": "^2.3.2",
@@ -295,7 +295,6 @@ export const glIconChevronRight = '#{'data:image/svg+xml}'
295
295
  export const glIconChevronDown = '#{'data:image/svg+xml}'
296
296
  export const defaultIconSize = '1rem'
297
297
  export const glIconSizes = '8 12 14 16 24 32 48 72'
298
- export const glDeprecatedIconSizes = '8 12 14 16 24 32 48 72 10 18'
299
298
  export const glDropdownWidth = '15rem'
300
299
  export const glDropdownWidthNarrow = '10rem'
301
300
  export const glDropdownWidthWide = '25rem'
@@ -1557,11 +1557,6 @@
1557
1557
  "value": "8 12 14 16 24 32 48 72",
1558
1558
  "compiledValue": "8 12 14 16 24 32 48 72"
1559
1559
  },
1560
- {
1561
- "name": "$gl-deprecated-icon-sizes",
1562
- "value": "join($gl-icon-sizes, 10 18)",
1563
- "compiledValue": "8 12 14 16 24 32 48 72 10 18"
1564
- },
1565
1560
  {
1566
1561
  "name": "$gl-dropdown-width",
1567
1562
  "value": "px-to-rem(240px)",
@@ -1,6 +1,6 @@
1
1
  .gl-icon {
2
2
  fill: currentColor;
3
- @each $size in $gl-deprecated-icon-sizes {
3
+ @each $size in $gl-icon-sizes {
4
4
  &.s#{$size} {
5
5
  width: #{$size}px;
6
6
  height: #{$size}px;
@@ -25,6 +25,7 @@ describe('Icon component', () => {
25
25
  });
26
26
  };
27
27
 
28
+ const validateSize = (size) => Icon.props.size.validator(size);
28
29
  const validateName = (name) => Icon.props.name.validator(name);
29
30
 
30
31
  afterEach(() => {
@@ -52,35 +53,14 @@ describe('Icon component', () => {
52
53
  });
53
54
 
54
55
  describe('size validator', () => {
55
- beforeEach(() => {
56
- consoleSpy = jest.spyOn(console, 'warn').mockImplementation();
57
- });
58
-
59
56
  const maxSize = Math.max(...iconSizeOptions);
60
57
 
61
- it('fails with size outside options', async () => {
62
- createComponent({
63
- size: maxSize + 10,
64
- });
65
-
66
- expect(consoleSpy).toBeCalledWith(
67
- `[gitlab-ui] Unexpected value '${maxSize + 10}' was provided for the icon size`
68
- );
69
- });
70
-
71
- it('passes with use-deprecated-sizes', () => {
72
- createComponent({
73
- size: maxSize + 10,
74
- useDeprecatedSizes: true,
75
- });
76
-
77
- expect(consoleSpy).not.toBeCalled();
58
+ it('fails with size outside options', () => {
59
+ expect(validateSize(maxSize + 10)).toBe(false);
78
60
  });
79
61
 
80
62
  it('passes with size in options', () => {
81
- createComponent({ size: maxSize });
82
-
83
- expect(consoleSpy).not.toBeCalled();
63
+ expect(validateSize(maxSize)).toBe(true);
84
64
  });
85
65
  });
86
66
 
@@ -55,15 +55,7 @@ export default {
55
55
  type: Number,
56
56
  required: false,
57
57
  default: 16,
58
- },
59
- /**
60
- * Is used to deprecate 10&18 icon sizes iteratively.
61
- * More info here https://gitlab.com/gitlab-org/gitlab-ui/-/issues/1232
62
- */
63
- useDeprecatedSizes: {
64
- type: Boolean,
65
- required: false,
66
- default: false,
58
+ validator: (value) => iconSizeOptions.includes(value),
67
59
  },
68
60
  },
69
61
  computed: {
@@ -74,13 +66,6 @@ export default {
74
66
  return this.size ? `s${this.size}` : '';
75
67
  },
76
68
  },
77
-
78
- created() {
79
- if (!iconSizeOptions.includes(this.size) && !this.useDeprecatedSizes) {
80
- // eslint-disable-next-line no-console
81
- console.warn(`[gitlab-ui] Unexpected value '${this.size}' was provided for the icon size`);
82
- }
83
- },
84
69
  };
85
70
  </script>
86
71
 
@@ -8,14 +8,12 @@ describe('toggle', () => {
8
8
  let wrapper;
9
9
 
10
10
  const label = 'toggle label';
11
- const labelId = 'toggle-label-id';
12
11
  const helpText = 'help text';
13
12
 
14
13
  const createWrapper = (props = {}) => {
15
14
  wrapper = shallowMount(Toggle, {
16
15
  propsData: {
17
16
  label,
18
- labelId,
19
17
  ...props,
20
18
  },
21
19
  });
@@ -131,7 +129,7 @@ describe('toggle', () => {
131
129
  });
132
130
 
133
131
  it('has accessible name for the button', () => {
134
- expect(findButton().attributes('aria-labelledby')).toBe(labelId);
132
+ expect(findButton().attributes('aria-labelledby')).toBeDefined();
135
133
  });
136
134
  });
137
135
  });
@@ -1,4 +1,6 @@
1
1
  <script>
2
+ import { uniqueId } from 'lodash';
3
+
2
4
  import { toggleLabelPosition } from '../../../utils/constants';
3
5
  import GlIcon from '../icon/icon.vue';
4
6
  import GlLoadingIcon from '../loading_icon/loading_icon.vue';
@@ -60,13 +62,6 @@ export default {
60
62
  required: false,
61
63
  default: undefined,
62
64
  },
63
- /**
64
- * The id for the label. This id is used by the aria-labelledby attribute on the toggle button.
65
- */
66
- labelId: {
67
- type: String,
68
- required: true,
69
- },
70
65
  /**
71
66
  * The label's position relative to the toggle. If 'hidden', the toggle will add the .gl-sr-only class so the label is still accessible to screen readers.
72
67
  */
@@ -79,7 +74,11 @@ export default {
79
74
  },
80
75
  },
81
76
  },
82
-
77
+ data() {
78
+ return {
79
+ labelId: uniqueId('toggle-label-'),
80
+ };
81
+ },
83
82
  computed: {
84
83
  icon() {
85
84
  return this.value ? 'mobile-issue-close' : 'close';
@@ -12,5 +12,8 @@ export default {
12
12
  additionalInfo: 'Ellipsis position',
13
13
  enum: 'truncateOptions',
14
14
  },
15
+ withTooltip: {
16
+ additionalInfo: 'Display the full text in a tooltip only if it is being truncated',
17
+ },
15
18
  },
16
19
  };
@@ -1,6 +1,7 @@
1
1
  import { shallowMount } from '@vue/test-utils';
2
2
  import { POSITION } from './constants';
3
3
  import Truncate from './truncate.vue';
4
+ import { createMockDirective, getBinding } from '~helpers/vue_mock_directive';
4
5
 
5
6
  const removeSpecialChar = (text) => {
6
7
  return text.replace(/&lrm;|\u200E/gi, '');
@@ -18,6 +19,9 @@ describe('Truncate component', () => {
18
19
  const createComponent = (props) => {
19
20
  wrapper = shallowMount(Truncate, {
20
21
  propsData: { ...defaultProps, ...props },
22
+ directives: {
23
+ GlTooltip: createMockDirective(),
24
+ },
21
25
  });
22
26
  };
23
27
 
@@ -45,6 +49,10 @@ describe('Truncate component', () => {
45
49
  it('should have the default position', () => {
46
50
  expect(wrapper.props('position')).toBe('end');
47
51
  });
52
+
53
+ it('disables the tooltip by default', () => {
54
+ expect(getBinding(wrapper.element, 'gl-tooltip').value.disabled).toBe(true);
55
+ });
48
56
  });
49
57
 
50
58
  describe('start truncation', () => {
@@ -1,4 +1,4 @@
1
- import { withKnobs, text, select } from '@storybook/addon-knobs';
1
+ import { withKnobs, text, select, boolean } from '@storybook/addon-knobs';
2
2
  import { documentedStoriesOf } from '../../../../documentation/documented_stories';
3
3
  import { GlTruncate } from '../../../../index';
4
4
  import { POSITION } from './constants';
@@ -8,11 +8,12 @@ const components = {
8
8
  GlTruncate,
9
9
  };
10
10
 
11
- const template = '<gl-truncate :text="text" :position="position" />';
11
+ const template = '<gl-truncate :text="text" :position="position" :with-tooltip="withTooltip" />';
12
12
 
13
13
  function generateProps({
14
14
  longText = 'src/thisIs/AVeryLongFilePath/that/needs/to/be/smartly/truncated/from/the/middle/so/we/dont/lose/important/information/here.vue',
15
15
  position = 'middle',
16
+ withTooltip = false,
16
17
  } = {}) {
17
18
  return {
18
19
  text: {
@@ -23,6 +24,9 @@ function generateProps({
23
24
  type: String,
24
25
  default: select('position', Object.values(POSITION), position),
25
26
  },
27
+ withTooltip: {
28
+ default: boolean('withTooltip', withTooltip),
29
+ },
26
30
  };
27
31
  }
28
32
 
@@ -1,7 +1,14 @@
1
1
  <script>
2
+ import { GlTooltipDirective } from '../../../directives/tooltip';
3
+ import { GlResizeObserverDirective } from '../../../directives/resize_observer/resize_observer';
2
4
  import { POSITION } from './constants';
3
5
 
4
6
  export default {
7
+ POSITION,
8
+ directives: {
9
+ GlTooltip: GlTooltipDirective,
10
+ GlResizeObserver: GlResizeObserverDirective,
11
+ },
5
12
  props: {
6
13
  text: {
7
14
  type: String,
@@ -13,10 +20,15 @@ export default {
13
20
  default: POSITION.END,
14
21
  validator: (value) => Object.values(POSITION).includes(value),
15
22
  },
23
+ withTooltip: {
24
+ type: Boolean,
25
+ required: false,
26
+ default: false,
27
+ },
16
28
  },
17
29
  data() {
18
30
  return {
19
- POSITION,
31
+ isTruncated: false,
20
32
  };
21
33
  },
22
34
  computed: {
@@ -30,24 +42,62 @@ export default {
30
42
  last() {
31
43
  return this.text.slice(this.middleIndex);
32
44
  },
45
+ isTooltipDisabled() {
46
+ return !this.withTooltip || !this.isTruncated;
47
+ },
48
+ },
49
+ watch: {
50
+ withTooltip(withTooltip) {
51
+ if (withTooltip) {
52
+ this.checkTruncationState();
53
+ }
54
+ },
55
+ },
56
+ methods: {
57
+ checkTruncationState() {
58
+ if (this.withTooltip) {
59
+ this.isTruncated = this.$refs.text.scrollWidth > this.$refs.text.offsetWidth;
60
+ }
61
+ },
33
62
  },
34
63
  };
35
64
  </script>
36
65
 
37
66
  <template>
38
67
  <!-- START -->
39
- <span v-if="position === POSITION.START" class="gl-truncate" :title="text">
40
- <span class="gl-truncate-start gl-text-overflow-ellipsis!">&lrm;{{ text }}&lrm;</span>
68
+ <span
69
+ v-if="position === $options.POSITION.START"
70
+ v-gl-tooltip="{ disabled: isTooltipDisabled }"
71
+ v-gl-resize-observer:[withTooltip]="checkTruncationState"
72
+ class="gl-truncate"
73
+ :title="text"
74
+ >
75
+ <span ref="text" class="gl-truncate-start gl-text-overflow-ellipsis!"
76
+ >&lrm;{{ text }}&lrm;</span
77
+ >
41
78
  </span>
42
79
 
43
80
  <!-- MIDDLE -->
44
- <span v-else-if="position === POSITION.MIDDLE" class="gl-truncate" :title="text">
45
- <span class="gl-truncate-end">{{ first }}</span
81
+ <span
82
+ v-else-if="position === $options.POSITION.MIDDLE"
83
+ v-gl-tooltip="{ disabled: isTooltipDisabled }"
84
+ v-gl-resize-observer:[withTooltip]="checkTruncationState"
85
+ class="gl-truncate"
86
+ :title="text"
87
+ >
88
+ <span ref="text" class="gl-truncate-end">{{ first }}</span
46
89
  ><span class="gl-truncate-start">&lrm;{{ last }}&lrm;</span>
47
90
  </span>
48
91
 
49
92
  <!-- END -->
50
- <span v-else class="gl-truncate" :title="text">
51
- <span class="gl-truncate-end">{{ text }}</span>
93
+ <span
94
+ v-else
95
+ v-gl-tooltip="{ disabled: isTooltipDisabled }"
96
+ v-gl-resize-observer:[withTooltip]="checkTruncationState"
97
+ class="gl-truncate"
98
+ data-testid="truncate-end-container"
99
+ :title="text"
100
+ >
101
+ <span ref="text" class="gl-truncate-end">{{ text }}</span>
52
102
  </span>
53
103
  </template>
@@ -2,29 +2,44 @@ import isFunction from 'lodash/isFunction';
2
2
 
3
3
  let observer = null;
4
4
 
5
- export const GlResizeObserverDirective = {
6
- bind(el, { value: resizeHandler }) {
7
- if (!isFunction(resizeHandler)) {
8
- throw TypeError('directive value must be a function');
9
- }
5
+ const attachObserver = (el, resizeHandler) => {
6
+ if (!isFunction(resizeHandler)) {
7
+ throw TypeError('directive value must be a function');
8
+ }
10
9
 
11
- if (!observer) {
12
- // the observer instance is shared for performance reasons
13
- // more information: https://github.com/WICG/ResizeObserver/issues/59
14
- observer = new ResizeObserver((entries) => {
15
- entries.forEach((event) => {
16
- event.target.glResizeHandler(event);
17
- });
10
+ if (!observer) {
11
+ // the observer instance is shared for performance reasons
12
+ // more information: https://github.com/WICG/ResizeObserver/issues/59
13
+ observer = new ResizeObserver((entries) => {
14
+ entries.forEach((event) => {
15
+ event.target.glResizeHandler(event);
18
16
  });
19
- }
17
+ });
18
+ }
19
+
20
+ el.glResizeHandler = resizeHandler;
21
+ observer.observe(el);
22
+ };
20
23
 
21
- el.glResizeHandler = resizeHandler;
22
- observer.observe(el);
24
+ const detachObserver = (el) => {
25
+ if (el.glResizeHandler) {
26
+ delete el.glResizeHandler;
27
+ observer?.unobserve(el);
28
+ }
29
+ };
30
+
31
+ export const GlResizeObserverDirective = {
32
+ bind(el, { value: resizeHandler, arg: enabled = true }) {
33
+ if (enabled) {
34
+ attachObserver(el, resizeHandler);
35
+ }
23
36
  },
24
- unbind(el) {
25
- if (el.glResizeHandler) {
26
- delete el.glResizeHandler;
27
- observer?.unobserve(el);
37
+ update(el, { value: resizeHandler, arg: enabled = true }) {
38
+ if (enabled) {
39
+ attachObserver(el, resizeHandler);
40
+ } else {
41
+ detachObserver(el);
28
42
  }
29
43
  },
44
+ unbind: detachObserver,
30
45
  };
@@ -38,3 +38,23 @@ export default {
38
38
  </div>
39
39
  </template>
40
40
  ```
41
+
42
+ The observer can be toggled on or off by passing a boolean argument to the directive:
43
+
44
+ ```html
45
+ <script>
46
+ export default {
47
+ data() {
48
+ return {
49
+ shouldObserve: true,
50
+ };
51
+ },
52
+ methods: {
53
+ handleResize() {},
54
+ },
55
+ };
56
+ </script>
57
+ <template>
58
+ <div v-gl-resize-observer-directive[shouldObserve]="handleResize"></div>
59
+ </template>
60
+ ```
@@ -10,7 +10,7 @@ describe('resize observer directive', () => {
10
10
  const localVue = createLocalVue();
11
11
  let wrapper;
12
12
 
13
- const createComponent = ({ template } = {}) => {
13
+ const createComponent = ({ template, data = {} } = {}) => {
14
14
  const defaultTemplate = `<div v-resize-observer="handleResize"></div>`;
15
15
 
16
16
  const component = {
@@ -21,6 +21,9 @@ describe('resize observer directive', () => {
21
21
  handleResize: mockHandleResize,
22
22
  },
23
23
  template: template || defaultTemplate,
24
+ data() {
25
+ return data;
26
+ },
24
27
  };
25
28
 
26
29
  wrapper = shallowMount(component, { localVue });
@@ -52,6 +55,13 @@ describe('resize observer directive', () => {
52
55
  expect(observesElement(wrapper.element)).toBe(true);
53
56
  });
54
57
 
58
+ it('does not subscribe if the argument is false', () => {
59
+ createComponent({ template: '<div v-resize-observer:[false]="handleResize"></div>' });
60
+
61
+ expect(observersCount()).toBe(0);
62
+ expect(observesElement(wrapper.element)).toBe(false);
63
+ });
64
+
55
65
  it('passes the first entries "contentRect" and "target" to the given handler', () => {
56
66
  createComponent();
57
67
 
@@ -61,6 +71,28 @@ describe('resize observer directive', () => {
61
71
  expect(mockHandleResize).toHaveBeenCalledWith({ contentRect: {}, target: wrapper.element });
62
72
  });
63
73
 
74
+ it("detaches then reattaches observer based on argument's value", async () => {
75
+ expect(observersCount()).toBe(0);
76
+
77
+ createComponent({
78
+ template: '<div v-resize-observer:[isEnabled]="handleResize"></div>',
79
+ data: {
80
+ isEnabled: true,
81
+ },
82
+ });
83
+
84
+ expect(observersCount()).toBe(1);
85
+ expect(wrapper.element.glResizeHandler).not.toBeFalsy();
86
+
87
+ await wrapper.setData({ isEnabled: false });
88
+
89
+ expect(wrapper.element.glResizeHandler).toBeFalsy();
90
+
91
+ await wrapper.setData({ isEnabled: true });
92
+
93
+ expect(wrapper.element.glResizeHandler).not.toBeFalsy();
94
+ });
95
+
64
96
  it('does a clean up when the component is destroyed', () => {
65
97
  createComponent();
66
98
 
@@ -889,6 +889,38 @@
889
889
  border-style: solid !important;
890
890
  }
891
891
 
892
+ .gl-border-dashed {
893
+ border-style: dashed;
894
+ }
895
+
896
+ .gl-hover-border-dashed:hover {
897
+ border-style: dashed;
898
+ }
899
+
900
+ .gl-border-dashed\! {
901
+ border-style: dashed !important;
902
+ }
903
+
904
+ .gl-hover-border-dashed\!:hover {
905
+ border-style: dashed !important;
906
+ }
907
+
908
+ .gl-border-dotted {
909
+ border-style: dotted;
910
+ }
911
+
912
+ .gl-hover-border-dotted:hover {
913
+ border-style: dotted;
914
+ }
915
+
916
+ .gl-border-dotted\! {
917
+ border-style: dotted !important;
918
+ }
919
+
920
+ .gl-hover-border-dotted\!:hover {
921
+ border-style: dotted !important;
922
+ }
923
+
892
924
  .gl-border-t-solid {
893
925
  border-top-style: solid;
894
926
  }
@@ -15,6 +15,14 @@
15
15
  border-style: solid;
16
16
  }
17
17
 
18
+ @mixin gl-border-dashed($hover: true) {
19
+ border-style: dashed;
20
+ }
21
+
22
+ @mixin gl-border-dotted($hover: true) {
23
+ border-style: dotted;
24
+ }
25
+
18
26
  @mixin gl-border-t-solid($hover: true) {
19
27
  border-top-style: solid;
20
28
  }
@@ -427,12 +427,7 @@ $gl-icon-chevron-down: 'data:image/svg+xml;utf8,<svg viewBox="0 0 16 16" xmlns="
427
427
 
428
428
  // Icons
429
429
  $default-icon-size: px-to-rem(16px);
430
- // $gl-deprecated-icon-sizes is used for css classes generation as there are still instances around codebase
431
- // where $gl-icon-sizes is a new list of supported icon sizes and will be used for icon size validation
432
- // $gl-deprecated-icon-sizes should be replaced with $gl-icon-sizes in scope
433
- // of this issue https://gitlab.com/gitlab-org/gitlab-ui/-/issues/1232
434
430
  $gl-icon-sizes: 8 12 14 16 24 32 48 72;
435
- $gl-deprecated-icon-sizes: join($gl-icon-sizes, 10 18);
436
431
 
437
432
  // Dropdowns
438
433
  $gl-dropdown-width: px-to-rem(240px);