@gitlab/ui 56.2.1 → 56.4.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 (60) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/components/base/form/form_checkbox/form_checkbox_group.js +1 -1
  3. package/dist/components/base/form/form_radio_group/form_radio_group.js +1 -1
  4. package/dist/components/base/popover/popover.js +6 -1
  5. package/dist/components/base/table/table.js +12 -1
  6. package/dist/components/base/table_lite/table_lite.js +13 -2
  7. package/dist/components/charts/area/area.js +17 -3
  8. package/dist/components/charts/bar/bar.js +17 -3
  9. package/dist/components/charts/chart/chart.js +3 -0
  10. package/dist/components/charts/column/column.js +17 -3
  11. package/dist/components/charts/discrete_scatter/discrete_scatter.js +17 -2
  12. package/dist/components/charts/gauge/gauge.js +1 -1
  13. package/dist/components/charts/heatmap/heatmap.js +17 -3
  14. package/dist/components/charts/line/line.js +17 -3
  15. package/dist/components/charts/sparkline/sparkline.js +11 -4
  16. package/dist/components/charts/stacked_column/stacked_column.js +17 -3
  17. package/dist/index.css +2 -2
  18. package/dist/index.css.map +1 -1
  19. package/dist/utils/charts/constants.js +5 -1
  20. package/package.json +7 -7
  21. package/scss_to_js/scss_variables.js +1 -0
  22. package/scss_to_js/scss_variables.json +5 -0
  23. package/src/components/base/form/form_checkbox/form_checkbox_group.vue +1 -1
  24. package/src/components/base/form/form_input/form_input.scss +0 -5
  25. package/src/components/base/form/form_radio_group/form_radio_group.vue +1 -1
  26. package/src/components/base/form/form_select/form_select.scss +1 -6
  27. package/src/components/base/popover/popover.vue +6 -0
  28. package/src/components/base/table/table.spec.js +12 -1
  29. package/src/components/base/table/table.vue +11 -1
  30. package/src/components/base/table_lite/table_lite.spec.js +21 -0
  31. package/src/components/base/table_lite/table_lite.vue +9 -1
  32. package/src/components/charts/area/area.spec.js +9 -0
  33. package/src/components/charts/area/area.stories.js +3 -0
  34. package/src/components/charts/area/area.vue +22 -2
  35. package/src/components/charts/bar/bar.spec.js +11 -2
  36. package/src/components/charts/bar/bar.stories.js +21 -7
  37. package/src/components/charts/bar/bar.vue +22 -3
  38. package/src/components/charts/chart/chart.vue +3 -0
  39. package/src/components/charts/column/column.stories.js +3 -0
  40. package/src/components/charts/column/column.vue +26 -3
  41. package/src/components/charts/column/column_chart.spec.js +9 -0
  42. package/src/components/charts/discrete_scatter/discrete_scatter.spec.js +41 -0
  43. package/src/components/charts/discrete_scatter/discrete_scatter.stories.js +3 -0
  44. package/src/components/charts/discrete_scatter/discrete_scatter.vue +22 -2
  45. package/src/components/charts/gauge/gauge.stories.js +5 -2
  46. package/src/components/charts/gauge/gauge.vue +1 -3
  47. package/src/components/charts/heatmap/heatmap.spec.js +25 -5
  48. package/src/components/charts/heatmap/heatmap.stories.js +3 -0
  49. package/src/components/charts/heatmap/heatmap.vue +22 -3
  50. package/src/components/charts/line/line.spec.js +9 -0
  51. package/src/components/charts/line/line.stories.js +3 -0
  52. package/src/components/charts/line/line.vue +22 -2
  53. package/src/components/charts/sparkline/sparkline.spec.js +28 -1
  54. package/src/components/charts/sparkline/sparkline.stories.js +18 -10
  55. package/src/components/charts/sparkline/sparkline.vue +14 -3
  56. package/src/components/charts/stacked_column/stacked_column.spec.js +9 -0
  57. package/src/components/charts/stacked_column/stacked_column.stories.js +3 -0
  58. package/src/components/charts/stacked_column/stacked_column.vue +22 -2
  59. package/src/scss/variables.scss +1 -0
  60. package/src/utils/charts/constants.js +4 -0
@@ -64,4 +64,8 @@ const arrowSymbol = 'path://m5 229 5 8h-10z';
64
64
  const CHART_TYPE_BAR = 'bar';
65
65
  const CHART_TYPE_LINE = 'line';
66
66
 
67
- export { ANNOTATIONS_COMPONENT_TYPE, ANNOTATIONS_SERIES_NAME, ANNOTATION_TOOLTIP_TOP_OFFSET, CHART_TYPE_BAR, CHART_TYPE_LINE, DATA_TOOLTIP_LEFT_OFFSET, LEGEND_AVERAGE_TEXT, LEGEND_CURRENT_TEXT, LEGEND_LAYOUT_INLINE, LEGEND_LAYOUT_TABLE, LEGEND_MAX_TEXT, LEGEND_MIN_TEXT, TOOLTIP_LEFT_OFFSET, arrowSymbol };
67
+ // Constants for height "auto"
68
+ const HEIGHT_AUTO_CLASSES = 'gl-display-flex gl-flex-direction-column gl-h-full';
69
+ const HEIGHT_AUTO_HORIZONTAL_LAYOUT_CLASSES = 'gl-display-flex gl-h-full';
70
+
71
+ export { ANNOTATIONS_COMPONENT_TYPE, ANNOTATIONS_SERIES_NAME, ANNOTATION_TOOLTIP_TOP_OFFSET, CHART_TYPE_BAR, CHART_TYPE_LINE, DATA_TOOLTIP_LEFT_OFFSET, HEIGHT_AUTO_CLASSES, HEIGHT_AUTO_HORIZONTAL_LAYOUT_CLASSES, LEGEND_AVERAGE_TEXT, LEGEND_CURRENT_TEXT, LEGEND_LAYOUT_INLINE, LEGEND_LAYOUT_TABLE, LEGEND_MAX_TEXT, LEGEND_MIN_TEXT, TOOLTIP_LEFT_OFFSET, arrowSymbol };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gitlab/ui",
3
- "version": "56.2.1",
3
+ "version": "56.4.0",
4
4
  "description": "GitLab UI Components",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -61,7 +61,7 @@
61
61
  },
62
62
  "dependencies": {
63
63
  "@popperjs/core": "^2.11.2",
64
- "bootstrap-vue": "2.20.1",
64
+ "bootstrap-vue": "2.23.1",
65
65
  "dompurify": "^2.4.5",
66
66
  "echarts": "^5.3.2",
67
67
  "iframe-resizer": "^4.3.2",
@@ -88,7 +88,7 @@
88
88
  "@gitlab/eslint-plugin": "18.2.0",
89
89
  "@gitlab/fonts": "^1.2.0",
90
90
  "@gitlab/stylelint-config": "4.1.0",
91
- "@gitlab/svgs": "3.22.0",
91
+ "@gitlab/svgs": "3.24.0",
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",
@@ -113,7 +113,7 @@
113
113
  "babel-loader": "^8.0.5",
114
114
  "babel-plugin-require-context-hook": "^1.0.0",
115
115
  "babel-preset-vue": "^2.0.2",
116
- "bootstrap": "4.5.3",
116
+ "bootstrap": "4.6.2",
117
117
  "bootstrap-vue-vue3": "npm:bootstrap-vue@2.23.1",
118
118
  "cypress": "^11.2.0",
119
119
  "emoji-regex": "^10.0.0",
@@ -125,9 +125,9 @@
125
125
  "glob": "^7.2.0",
126
126
  "identity-obj-proxy": "^3.0.0",
127
127
  "inquirer-select-directory": "^1.2.0",
128
- "jest": "^29.4.3",
129
- "jest-circus": "29.4.3",
130
- "jest-environment-jsdom": "29.4.3",
128
+ "jest": "^29.5.0",
129
+ "jest-circus": "29.5.0",
130
+ "jest-environment-jsdom": "29.5.0",
131
131
  "markdownlint-cli": "^0.29.0",
132
132
  "mockdate": "^2.0.5",
133
133
  "npm-run-all": "^4.1.5",
@@ -341,6 +341,7 @@ export const modalTitleLineHeight = '1.25rem'
341
341
  export const modalBackdropBg = '#000'
342
342
  export const modalBackdropOpacity = '0.64'
343
343
  export const bodyColor = '#333238'
344
+ export const enableValidationIcons = 'false'
344
345
  export const secondary = '#ececef'
345
346
  export const success = '#108548'
346
347
  export const info = '#1f75cb'
@@ -1815,6 +1815,11 @@
1815
1815
  "value": "$gl-text-color",
1816
1816
  "compiledValue": "#333238"
1817
1817
  },
1818
+ {
1819
+ "name": "$enable-validation-icons",
1820
+ "value": "false",
1821
+ "compiledValue": "false"
1822
+ },
1818
1823
  {
1819
1824
  "name": "$secondary",
1820
1825
  "value": "$gray-50",
@@ -1,6 +1,6 @@
1
1
  <script>
2
2
  import { BFormCheckboxGroup } from 'bootstrap-vue';
3
- import formOptionsMixin from 'bootstrap-vue/src/mixins/form-options';
3
+ import { formOptionsMixin } from 'bootstrap-vue/src/mixins/form-options';
4
4
  import { SafeHtmlDirective as SafeHtml } from '../../../../directives/safe_html/safe_html';
5
5
  import GlFormCheckbox from './form_checkbox.vue';
6
6
 
@@ -31,17 +31,12 @@
31
31
 
32
32
  &.is-invalid {
33
33
  @include gl-inset-border-1-red-500;
34
- background-image: none;
35
34
 
36
35
  &:focus {
37
36
  @include gl-focus($color: $red-500);
38
37
  }
39
38
  }
40
39
 
41
- &.is-valid {
42
- background-image: none;
43
- }
44
-
45
40
  &::placeholder {
46
41
  @include gl-text-gray-400;
47
42
  }
@@ -1,6 +1,6 @@
1
1
  <script>
2
2
  import { BFormRadioGroup } from 'bootstrap-vue';
3
- import formOptionsMixin from 'bootstrap-vue/src/mixins/form-options';
3
+ import { formOptionsMixin } from 'bootstrap-vue/src/mixins/form-options';
4
4
  import { SafeHtmlDirective as SafeHtml } from '../../../../directives/safe_html/safe_html';
5
5
  import GlFormRadio from '../form_radio/form_radio.vue';
6
6
 
@@ -16,6 +16,7 @@ See: https://gitlab.com/gitlab-org/gitlab/issues/30055
16
16
  @include gl-line-height-normal;
17
17
  @include gl-py-3;
18
18
  @include gl-pl-4;
19
+ padding-right: $gl-spacing-scale-2 + $gl-spacing-scale-6;
19
20
  @include gl-h-auto;
20
21
  @include gl-inset-border-1-gray-400;
21
22
  @include gl-border-none;
@@ -36,12 +37,6 @@ See: https://gitlab.com/gitlab-org/gitlab/issues/30055
36
37
  @include gl-cursor-not-allowed;
37
38
  }
38
39
 
39
- &.is-valid,
40
- &.is-invalid {
41
- padding-right: $gl-spacing-scale-2 + $gl-spacing-scale-6;
42
- background-image: url($gl-icon-select-chevron-down);
43
- }
44
-
45
40
  &.is-invalid:not(:disabled) {
46
41
  @include gl-inset-border-1-red-400;
47
42
 
@@ -45,6 +45,11 @@ export default {
45
45
  required: false,
46
46
  default: popoverPlacements.top,
47
47
  },
48
+ boundaryPadding: {
49
+ type: [Number, String],
50
+ required: false,
51
+ default: 5,
52
+ },
48
53
  },
49
54
  computed: {
50
55
  customClass() {
@@ -74,6 +79,7 @@ export default {
74
79
  :triggers="triggers"
75
80
  :title="title"
76
81
  :placement="placement"
82
+ :boundary-padding="boundaryPadding"
77
83
  v-bind="$attrs"
78
84
  v-on="$listeners"
79
85
  >
@@ -1,4 +1,5 @@
1
1
  import { shallowMount } from '@vue/test-utils';
2
+ import { BTable } from 'bootstrap-vue';
2
3
  import { logWarning } from '../../../utils/utils';
3
4
  import { waitForAnimationFrame } from '../../../utils/test_utils';
4
5
  import { glTableLiteWarning } from './constants';
@@ -10,18 +11,22 @@ jest.mock('../../../utils/utils', () => ({
10
11
  }));
11
12
 
12
13
  describe('GlTable', () => {
14
+ let wrapper;
15
+
13
16
  const slotsTemplate = {
14
17
  empty: `
15
18
  <p>Placeholder empty text</p>`,
16
19
  };
17
20
 
18
21
  const factory = ({ props = {}, scopedSlots = {} } = {}) => {
19
- shallowMount(Table, {
22
+ wrapper = shallowMount(Table, {
20
23
  scopedSlots,
21
24
  propsData: props,
22
25
  });
23
26
  };
24
27
 
28
+ const findBTable = () => wrapper.findComponent(BTable);
29
+
25
30
  afterEach(() => {
26
31
  logWarning.mockClear();
27
32
  });
@@ -46,4 +51,10 @@ describe('GlTable', () => {
46
51
 
47
52
  expect(logWarning).not.toHaveBeenCalled();
48
53
  });
54
+
55
+ it('adds gl-table class to tableClass prop', () => {
56
+ factory({ props: { tableClass: 'test-class' } });
57
+
58
+ expect(findBTable().props().tableClass).toEqual(['gl-table', 'test-class']);
59
+ });
49
60
  });
@@ -11,11 +11,21 @@ const shouldUseFullTable = ({ $attrs, $scopedSlots }) => {
11
11
  );
12
12
  };
13
13
 
14
+ const { tableClass } = BTable.options.props;
15
+
14
16
  export default {
15
17
  components: {
16
18
  BTable,
17
19
  },
18
20
  inheritAttrs: false,
21
+ props: {
22
+ tableClass,
23
+ },
24
+ computed: {
25
+ localTableClass() {
26
+ return ['gl-table', this.tableClass];
27
+ },
28
+ },
19
29
  mounted() {
20
30
  // logWarning will call isDev before logging any message
21
31
  // this additional call to isDev is being made to exit the condition early when run in production
@@ -27,7 +37,7 @@ export default {
27
37
  </script>
28
38
 
29
39
  <template>
30
- <b-table class="gl-table" v-bind="$attrs" v-on="$listeners">
40
+ <b-table :table-class="localTableClass" v-bind="$attrs" v-on="$listeners">
31
41
  <template v-for="slot in Object.keys($scopedSlots)" #[slot]="scope">
32
42
  <slot :name="slot" v-bind="scope"></slot>
33
43
  </template>
@@ -0,0 +1,21 @@
1
+ import { shallowMount } from '@vue/test-utils';
2
+ import { BTableLite } from 'bootstrap-vue';
3
+ import GlTableLite from './table_lite.vue';
4
+
5
+ describe('GlTableLite', () => {
6
+ let wrapper;
7
+
8
+ const factory = (propsData) => {
9
+ wrapper = shallowMount(GlTableLite, {
10
+ propsData,
11
+ });
12
+ };
13
+
14
+ const findBTableLite = () => wrapper.findComponent(BTableLite);
15
+
16
+ it('adds gl-table class to tableClass prop', () => {
17
+ factory({ tableClass: 'test-class' });
18
+
19
+ expect(findBTableLite().props().tableClass).toEqual(['gl-table', 'test-class']);
20
+ });
21
+ });
@@ -1,16 +1,24 @@
1
1
  <script>
2
2
  import { BTableLite } from 'bootstrap-vue';
3
3
 
4
+ const { tableClass } = BTableLite.options.props;
5
+
4
6
  export default {
5
7
  components: {
6
8
  BTableLite,
7
9
  },
8
10
  inheritAttrs: false,
11
+ props: { tableClass },
12
+ computed: {
13
+ localTableClass() {
14
+ return ['gl-table', this.tableClass];
15
+ },
16
+ },
9
17
  };
10
18
  </script>
11
19
 
12
20
  <template>
13
- <b-table-lite class="gl-table" v-bind="$attrs" v-on="$listeners">
21
+ <b-table-lite :table-class="localTableClass" v-bind="$attrs" v-on="$listeners">
14
22
  <template v-for="slot in Object.keys($scopedSlots)" #[slot]="scope">
15
23
  <!-- @slot See https://bootstrap-vue.org/docs/components/table#comp-ref-b-table-lite-slots for available slots. -->
16
24
  <slot :name="slot" v-bind="scope"></slot>
@@ -2,6 +2,7 @@ import { shallowMount } from '@vue/test-utils';
2
2
 
3
3
  import { LEGEND_LAYOUT_INLINE, LEGEND_LAYOUT_TABLE } from '~/utils/charts/constants';
4
4
  import { createMockChartInstance, ChartTooltipStub } from '~helpers/chart_stubs';
5
+ import { expectHeightAutoClasses } from '~helpers/chart_height';
5
6
  import Chart from '../chart/chart.vue';
6
7
  import ChartLegend from '../legend/legend.vue';
7
8
  import AreaChart from './area.vue';
@@ -183,4 +184,12 @@ describe('area component', () => {
183
184
  expect(findLegend().props('layout')).toBe(LEGEND_LAYOUT_TABLE);
184
185
  });
185
186
  });
187
+
188
+ describe('height', () => {
189
+ expectHeightAutoClasses({
190
+ createComponent: createShallowWrapper,
191
+ findContainer: () => wrapper,
192
+ findChart,
193
+ });
194
+ });
186
195
  });
@@ -34,6 +34,7 @@ const template = `<gl-area-chart
34
34
  :thresholds="thresholds"
35
35
  :annotations="annotations"
36
36
  :includeLegendAvgMax="includeLegendAvgMax"
37
+ :height="height"
37
38
  />`;
38
39
 
39
40
  const generateProps = ({
@@ -42,12 +43,14 @@ const generateProps = ({
42
43
  thresholds = [],
43
44
  annotations = [],
44
45
  includeLegendAvgMax = true,
46
+ height = null,
45
47
  } = {}) => ({
46
48
  data,
47
49
  option,
48
50
  thresholds,
49
51
  annotations,
50
52
  includeLegendAvgMax,
53
+ height,
51
54
  });
52
55
 
53
56
  const Template = (args, { argTypes }) => ({
@@ -38,6 +38,7 @@ import {
38
38
  LEGEND_CURRENT_TEXT,
39
39
  LEGEND_MIN_TEXT,
40
40
  LEGEND_MAX_TEXT,
41
+ HEIGHT_AUTO_CLASSES,
41
42
  } from '../../../utils/charts/constants';
42
43
  import { colorFromDefaultPalette } from '../../../utils/charts/theme';
43
44
  import { seriesHasAnnotations, isDataPointAnnotation } from '../../../utils/charts/utils';
@@ -118,6 +119,14 @@ export default {
118
119
  return [LEGEND_LAYOUT_INLINE, LEGEND_LAYOUT_TABLE].indexOf(layout) !== -1;
119
120
  },
120
121
  },
122
+ /**
123
+ * Sets the chart's height in pixels. Set to `"auto"` to use the height of the container.
124
+ */
125
+ height: {
126
+ type: [Number, String],
127
+ required: false,
128
+ default: null,
129
+ },
121
130
  },
122
131
  data() {
123
132
  // Part of the tooltip related data can be
@@ -247,6 +256,9 @@ export default {
247
256
  return acc;
248
257
  }, []);
249
258
  },
259
+ autoHeight() {
260
+ return this.height === 'auto';
261
+ },
250
262
  },
251
263
  beforeDestroy() {
252
264
  this.chart.getDom().removeEventListener('mousemove', this.debouncedShowHideTooltip);
@@ -328,12 +340,20 @@ export default {
328
340
  this.selectedFormatTooltipText(params);
329
341
  },
330
342
  },
343
+ HEIGHT_AUTO_CLASSES,
331
344
  };
332
345
  </script>
333
346
 
334
347
  <template>
335
- <div class="position-relative">
336
- <chart v-bind="$attrs" :options="options" v-on="$listeners" @created="onCreated" />
348
+ <div class="position-relative" :class="{ [$options.HEIGHT_AUTO_CLASSES]: autoHeight }">
349
+ <chart
350
+ v-bind="$attrs"
351
+ :class="{ 'gl-flex-grow-1': autoHeight }"
352
+ :height="height"
353
+ :options="options"
354
+ v-on="$listeners"
355
+ @created="onCreated"
356
+ />
337
357
  <chart-tooltip
338
358
  v-if="shouldShowAnnotationsTooltip"
339
359
  id="annotationsTooltip"
@@ -1,6 +1,7 @@
1
1
  import { shallowMount } from '@vue/test-utils';
2
2
  import TooltipDefaultFormat from '~/components/shared_components/charts/tooltip_default_format.vue';
3
3
  import { createMockChartInstance } from '~helpers/chart_stubs';
4
+ import { expectHeightAutoClasses } from '~helpers/chart_height';
4
5
  import Chart from '../chart/chart.vue';
5
6
  import BarChart from './bar.vue';
6
7
 
@@ -29,9 +30,9 @@ describe('Bar chart component', () => {
29
30
  const getOptions = () => findChart().props('options');
30
31
  const emitChartCreated = () => findChart().vm.$emit('created', mockChartInstance);
31
32
 
32
- const createComponent = () => {
33
+ const createComponent = (props = {}) => {
33
34
  wrapper = shallowMount(BarChart, {
34
- propsData: defaultChartProps,
35
+ propsData: { ...defaultChartProps, ...props },
35
36
  stubs: {
36
37
  'tooltip-default-format': TooltipDefaultFormat,
37
38
  },
@@ -116,4 +117,12 @@ describe('Bar chart component', () => {
116
117
  });
117
118
  });
118
119
  });
120
+
121
+ describe('height', () => {
122
+ expectHeightAutoClasses({
123
+ createComponent,
124
+ findContainer: () => wrapper,
125
+ findChart,
126
+ });
127
+ });
119
128
  });
@@ -1,16 +1,20 @@
1
1
  import { GlBarChart } from '../../../charts';
2
+ import { makeContainer } from '../../../utils/story_decorators/container';
2
3
  import readme from './bar.md';
3
4
 
4
5
  const Template = (args, { argTypes }) => ({
5
6
  components: { GlBarChart },
6
7
  props: Object.keys(argTypes),
7
- template: `<gl-bar-chart
8
- :data="data"
9
- :option="option"
10
- :y-axis-title="yAxisTitle"
11
- :x-axis-title="xAxisTitle"
12
- :x-axis-type="xAxisType"
13
- />`,
8
+ template: `
9
+ <gl-bar-chart
10
+ :data="data"
11
+ :option="option"
12
+ :y-axis-title="yAxisTitle"
13
+ :x-axis-title="xAxisTitle"
14
+ :x-axis-type="xAxisType"
15
+ :height="height"
16
+ />
17
+ `,
14
18
  });
15
19
 
16
20
  const mockData = {
@@ -34,17 +38,27 @@ const generateProps = ({
34
38
  xAxisTitle = 'Pushes per day',
35
39
  yAxisTitle = 'User',
36
40
  xAxisType = 'value',
41
+ height = null,
37
42
  } = {}) => ({
38
43
  data,
39
44
  option,
40
45
  xAxisTitle,
41
46
  yAxisTitle,
42
47
  xAxisType,
48
+ height,
43
49
  });
44
50
 
45
51
  export const Default = Template.bind({});
46
52
  Default.args = generateProps();
47
53
 
54
+ export const AutoHeight = Template.bind({});
55
+ Object.assign(AutoHeight, {
56
+ args: generateProps({
57
+ height: 'auto',
58
+ }),
59
+ decorators: [makeContainer({ height: '600px' })],
60
+ });
61
+
48
62
  export default {
49
63
  title: 'charts/bar-chart',
50
64
  component: GlBarChart,
@@ -3,7 +3,7 @@
3
3
  import merge from 'lodash/merge';
4
4
  import truncate from 'lodash/truncate';
5
5
  import { grid, dataZoomAdjustments, mergeSeriesToOptions } from '../../../utils/charts/config';
6
- import { TOOLTIP_LEFT_OFFSET } from '../../../utils/charts/constants';
6
+ import { TOOLTIP_LEFT_OFFSET, HEIGHT_AUTO_CLASSES } from '../../../utils/charts/constants';
7
7
  import { colorFromDefaultPalette } from '../../../utils/charts/theme';
8
8
  import { engineeringNotation } from '../../../utils/number_utils';
9
9
  import { hexToRgba, debounceByAnimationFrame } from '../../../utils/utils';
@@ -85,6 +85,14 @@ export default {
85
85
  required: false,
86
86
  default: 'value',
87
87
  },
88
+ /**
89
+ * Sets the chart's height in pixels. Set to `"auto"` to use the height of the container.
90
+ */
91
+ height: {
92
+ type: [Number, String],
93
+ required: false,
94
+ default: null,
95
+ },
88
96
  },
89
97
  data() {
90
98
  return {
@@ -160,6 +168,9 @@ export default {
160
168
  // needs to be handled specially
161
169
  return mergeSeriesToOptions(mergedOptions, this.series);
162
170
  },
171
+ autoHeight() {
172
+ return this.height === 'auto';
173
+ },
163
174
  },
164
175
  beforeDestroy() {
165
176
  if (this.chart) {
@@ -223,12 +234,20 @@ export default {
223
234
  return { yLabels, tooltipContent };
224
235
  },
225
236
  },
237
+ HEIGHT_AUTO_CLASSES,
226
238
  };
227
239
  </script>
228
240
 
229
241
  <template>
230
- <div class="position-relative">
231
- <chart v-bind="$attrs" :options="options" v-on="$listeners" @created="onCreated" />
242
+ <div class="position-relative" :class="{ [$options.HEIGHT_AUTO_CLASSES]: autoHeight }">
243
+ <chart
244
+ v-bind="$attrs"
245
+ :class="{ 'gl-flex-grow-1': autoHeight }"
246
+ :height="height"
247
+ :options="options"
248
+ v-on="$listeners"
249
+ @created="onCreated"
250
+ />
232
251
  <chart-tooltip
233
252
  v-if="chart"
234
253
  :show="showTooltip"
@@ -55,6 +55,9 @@ export default {
55
55
  default: null,
56
56
  validator: sizeValidator,
57
57
  },
58
+ /**
59
+ * Sets the chart's height in pixels. Set to `"auto"` to use the height of the container.
60
+ */
58
61
  height: {
59
62
  type: [Number, String],
60
63
  required: false,
@@ -17,6 +17,7 @@ const template = `
17
17
  :secondary-data-title="secondaryDataTitle"
18
18
  :x-axis-title="xAxisTitle"
19
19
  :x-axis-type="xAxisType"
20
+ :height="height"
20
21
  />
21
22
  `;
22
23
 
@@ -29,6 +30,7 @@ const generateProps = ({
29
30
  xAxisType = 'category',
30
31
  secondaryData = [],
31
32
  secondaryDataTitle = '',
33
+ height = null,
32
34
  } = {}) => ({
33
35
  bars,
34
36
  lines,
@@ -38,6 +40,7 @@ const generateProps = ({
38
40
  xAxisType,
39
41
  secondaryData,
40
42
  secondaryDataTitle,
43
+ height,
41
44
  });
42
45
 
43
46
  const Template = (args, { argTypes }) => ({
@@ -12,7 +12,11 @@ import {
12
12
  generateBarSeries,
13
13
  generateLineSeries,
14
14
  } from '../../../utils/charts/config';
15
- import { TOOLTIP_LEFT_OFFSET, CHART_TYPE_LINE } from '../../../utils/charts/constants';
15
+ import {
16
+ TOOLTIP_LEFT_OFFSET,
17
+ CHART_TYPE_LINE,
18
+ HEIGHT_AUTO_CLASSES,
19
+ } from '../../../utils/charts/constants';
16
20
  import { colorFromDefaultPalette } from '../../../utils/charts/theme';
17
21
  import { columnOptions } from '../../../utils/constants';
18
22
  import { debounceByAnimationFrame } from '../../../utils/utils';
@@ -74,6 +78,14 @@ export default {
74
78
  required: true,
75
79
  validator: (value) => ['value', 'category', 'time', 'log'].indexOf(value) !== -1,
76
80
  },
81
+ /**
82
+ * Sets the chart's height in pixels. Set to `"auto"` to use the height of the container.
83
+ */
84
+ height: {
85
+ type: [Number, String],
86
+ required: false,
87
+ default: null,
88
+ },
77
89
  },
78
90
  data() {
79
91
  return {
@@ -168,6 +180,9 @@ export default {
168
180
  // needs to be handled specially
169
181
  return mergeSeriesToOptions(mergedOptions, this.series);
170
182
  },
183
+ autoHeight() {
184
+ return this.height === 'auto';
185
+ },
171
186
  },
172
187
  beforeDestroy() {
173
188
  this.chart.getDom().removeEventListener('mousemove', this.debouncedMoveShowTooltip);
@@ -194,11 +209,19 @@ export default {
194
209
  this.tooltipTitle = xLabels.join(', ');
195
210
  },
196
211
  },
212
+ HEIGHT_AUTO_CLASSES,
197
213
  };
198
214
  </script>
199
215
  <template>
200
- <div class="position-relative">
201
- <chart v-bind="$attrs" :options="options" v-on="$listeners" @created="onCreated" />
216
+ <div class="position-relative" :class="{ [$options.HEIGHT_AUTO_CLASSES]: autoHeight }">
217
+ <chart
218
+ v-bind="$attrs"
219
+ :class="{ 'gl-flex-grow-1': autoHeight }"
220
+ :height="height"
221
+ :options="options"
222
+ v-on="$listeners"
223
+ @created="onCreated"
224
+ />
202
225
  <chart-tooltip
203
226
  v-if="chart"
204
227
  :show="showTooltip"
@@ -1,5 +1,6 @@
1
1
  import { shallowMount } from '@vue/test-utils';
2
2
  import { createMockChartInstance, ChartTooltipStub } from '~helpers/chart_stubs';
3
+ import { expectHeightAutoClasses } from '~helpers/chart_height';
3
4
  import {
4
5
  mockDefaultLineData,
5
6
  mockDefaultBarData,
@@ -120,4 +121,12 @@ describe('column chart component', () => {
120
121
  expect(findTooltip().text()).toContain(expectedTooltipTitle);
121
122
  });
122
123
  });
124
+
125
+ describe('height', () => {
126
+ expectHeightAutoClasses({
127
+ createComponent: (props) => factory({ ...defaultChartProps, ...props }),
128
+ findContainer: () => wrapper,
129
+ findChart,
130
+ });
131
+ });
123
132
  });