@gitlab/ui 38.8.2 → 38.9.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 (48) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/components/base/form/form_textarea/form_textarea.js +62 -2
  3. package/dist/index.css +1 -1
  4. package/dist/index.css.map +1 -1
  5. package/dist/utils/constants.js +7 -2
  6. package/package.json +1 -1
  7. package/src/components/base/accordion/accordion.stories.js +2 -4
  8. package/src/components/base/accordion/accordion_item.stories.js +2 -4
  9. package/src/components/base/alert/alert.stories.js +2 -4
  10. package/src/components/base/avatar/avatar.stories.js +3 -9
  11. package/src/components/base/avatar_labeled/avatar_labeled.stories.js +6 -12
  12. package/src/components/base/avatar_link/avatar_link.stories.js +2 -6
  13. package/src/components/base/avatars_inline/avatars_inline.stories.js +2 -4
  14. package/src/components/base/badge/badge.scss +10 -0
  15. package/src/components/base/badge/badge.stories.js +3 -9
  16. package/src/components/base/banner/banner.stories.js +1 -3
  17. package/src/components/base/broadcast_message/broadcast_message.stories.js +4 -8
  18. package/src/components/base/button/button.stories.js +8 -16
  19. package/src/components/base/datepicker/datepicker.stories.js +2 -2
  20. package/src/components/base/daterange_picker/daterange_picker.stories.js +2 -6
  21. package/src/components/base/dropdown/dropdown.stories.js +4 -12
  22. package/src/components/base/dropdown/dropdown_item.stories.js +2 -6
  23. package/src/components/base/form/form_group/form_group.stories.js +1 -1
  24. package/src/components/base/form/form_input/form_input.stories.js +1 -3
  25. package/src/components/base/form/form_input_group/form_input_group.stories.js +4 -12
  26. package/src/components/base/form/form_radio/form_radio.stories.js +1 -3
  27. package/src/components/base/form/form_select/form_select.stories.js +4 -8
  28. package/src/components/base/form/form_textarea/form_textarea.spec.js +115 -8
  29. package/src/components/base/form/form_textarea/form_textarea.stories.js +21 -0
  30. package/src/components/base/form/form_textarea/form_textarea.vue +73 -8
  31. package/src/components/base/icon/icon.stories.js +4 -8
  32. package/src/components/base/label/label.stories.js +2 -6
  33. package/src/components/base/link/link.stories.js +2 -4
  34. package/src/components/base/loading_icon/loading_icon.stories.js +4 -8
  35. package/src/components/base/modal/modal.stories.js +16 -32
  36. package/src/components/base/path/path.stories.js +2 -6
  37. package/src/components/base/popover/popover.stories.js +2 -4
  38. package/src/components/base/progress_bar/progress_bar.stories.js +2 -4
  39. package/src/components/base/search_box_by_click/search_box_by_click.stories.js +1 -3
  40. package/src/components/base/segmented_control/segmented_control.stories.js +1 -3
  41. package/src/components/base/skeleton_loading/skeleton_loading.stories.js +2 -4
  42. package/src/components/base/table/table.stories.js +2 -4
  43. package/src/components/base/toggle/toggle.stories.js +4 -10
  44. package/src/components/base/token/token.stories.js +2 -4
  45. package/src/components/base/token_selector/token_selector.stories.js +2 -4
  46. package/src/components/charts/single_stat/single_stat.stories.js +1 -3
  47. package/src/directives/resize_observer/resize_observer.stories.js +1 -3
  48. package/src/utils/constants.js +6 -0
@@ -1,4 +1,5 @@
1
1
  import { GlFormTextarea } from '../../../../index';
2
+ import { textareaCountOptions } from '../../../../utils/constants';
2
3
  import readme from './form_textarea.md';
3
4
 
4
5
  const template = `
@@ -7,6 +8,10 @@ const template = `
7
8
  :placeholder="placeholder"
8
9
  :rows="5"
9
10
  :no-resize="noResize"
11
+ :count="count"
12
+ :countType="countType"
13
+ :character-count-text="characterCountText"
14
+ :character-count-over-limit-text="characterCountOverLimitText"
10
15
  />
11
16
  `;
12
17
 
@@ -14,10 +19,18 @@ const generateProps = ({
14
19
  model = 'We take inspiration from other companies, and we always go for the boring solutions. Just like the rest of our work, we continually adjust our values and strive always to make them better. We used to have more values, but it was difficult to remember them all, so we condensed them and gave sub-values and created an acronym. Everyone is welcome to suggest improvements.',
15
20
  placeholder = 'hello',
16
21
  noResize = GlFormTextarea.props.noResize.default,
22
+ count = 400,
23
+ countType = textareaCountOptions.max,
24
+ characterCountText = '%{count} characters left',
25
+ characterCountOverLimitText = '%{count} characters over limit',
17
26
  } = {}) => ({
18
27
  model,
19
28
  placeholder,
20
29
  noResize,
30
+ count,
31
+ countType,
32
+ characterCountText,
33
+ characterCountOverLimitText,
21
34
  });
22
35
 
23
36
  const Template = (args) => ({
@@ -41,4 +54,12 @@ export default {
41
54
  },
42
55
  },
43
56
  },
57
+ argTypes: {
58
+ countType: {
59
+ control: {
60
+ type: 'select',
61
+ options: textareaCountOptions,
62
+ },
63
+ },
64
+ },
44
65
  };
@@ -1,5 +1,7 @@
1
1
  <script>
2
2
  import { BFormTextarea } from 'bootstrap-vue';
3
+ import GlSprintf from '../../../utilities/sprintf/sprintf.vue';
4
+ import { textareaCountOptions } from '../../../../utils/constants';
3
5
 
4
6
  const model = {
5
7
  prop: 'value',
@@ -9,6 +11,7 @@ const model = {
9
11
  export default {
10
12
  components: {
11
13
  BFormTextarea,
14
+ GlSprintf,
12
15
  },
13
16
  inheritAttrs: false,
14
17
  model,
@@ -30,6 +33,27 @@ export default {
30
33
  required: false,
31
34
  default: false,
32
35
  },
36
+ count: {
37
+ type: Number,
38
+ required: false,
39
+ default: 0,
40
+ },
41
+ countType: {
42
+ required: false,
43
+ type: String,
44
+ default: textareaCountOptions.max,
45
+ validator: (value) => Object.keys(textareaCountOptions).includes(value),
46
+ },
47
+ characterCountText: {
48
+ required: false,
49
+ type: String,
50
+ default: '',
51
+ },
52
+ characterCountOverLimitText: {
53
+ required: false,
54
+ type: String,
55
+ default: '',
56
+ },
33
57
  },
34
58
  computed: {
35
59
  listeners() {
@@ -56,6 +80,37 @@ export default {
56
80
  keypressEvent() {
57
81
  return this.submitOnEnter ? 'keyup' : null;
58
82
  },
83
+ characters() {
84
+ return this.value.length;
85
+ },
86
+ remainingCharacters() {
87
+ if (this.count) {
88
+ return Math.abs(this.count - this.characters);
89
+ }
90
+
91
+ return null;
92
+ },
93
+ characterCountClasses() {
94
+ switch (this.countType) {
95
+ case textareaCountOptions.max:
96
+ return {
97
+ 'gl-text-red-500': this.value.length > this.count,
98
+ 'gl-text-gray-500': this.value.length <= this.count,
99
+ };
100
+ case textareaCountOptions.recommended:
101
+ return 'gl-text-gray-500';
102
+ default:
103
+ return {};
104
+ }
105
+ },
106
+ hasCount() {
107
+ return this.remainingCharacters != null;
108
+ },
109
+ characterCountMessage() {
110
+ return this.characters > this.count
111
+ ? this.characterCountOverLimitText
112
+ : this.characterCountText;
113
+ },
59
114
  },
60
115
  methods: {
61
116
  handleKeyPress(e) {
@@ -68,12 +123,22 @@ export default {
68
123
  </script>
69
124
 
70
125
  <template>
71
- <b-form-textarea
72
- class="gl-form-input gl-form-textarea"
73
- :no-resize="noResize"
74
- v-bind="$attrs"
75
- :value="value"
76
- v-on="listeners"
77
- @[keypressEvent].native="handleKeyPress"
78
- />
126
+ <div>
127
+ <b-form-textarea
128
+ ref="textarea"
129
+ class="gl-form-input gl-form-textarea"
130
+ :no-resize="noResize"
131
+ v-bind="$attrs"
132
+ :value="value"
133
+ v-on="listeners"
134
+ @[keypressEvent].native="handleKeyPress"
135
+ />
136
+ <div v-if="hasCount">
137
+ <small :class="characterCountClasses" aria-live="polite">
138
+ <gl-sprintf :message="characterCountMessage">
139
+ <template #count>{{ remainingCharacters }}</template>
140
+ </gl-sprintf>
141
+ </small>
142
+ </div>
143
+ </div>
79
144
  </template>
@@ -44,16 +44,12 @@ export default {
44
44
  argTypes: {
45
45
  ...disableControls(['useDeprecatedSizes']),
46
46
  name: {
47
- control: {
48
- type: 'select',
49
- options: iconSpriteInfo.icons,
50
- },
47
+ options: iconSpriteInfo.icons,
48
+ control: 'select',
51
49
  },
52
50
  size: {
53
- control: {
54
- type: 'select',
55
- options: iconSizeOptions,
56
- },
51
+ options: iconSizeOptions,
52
+ control: 'select',
57
53
  },
58
54
  },
59
55
  };
@@ -67,18 +67,14 @@ export default {
67
67
  },
68
68
  argTypes: {
69
69
  backgroundColor: {
70
- control: {
71
- type: 'color',
72
- },
70
+ control: 'color',
73
71
  },
74
72
  size: {
75
73
  options: labelSizeOptions,
76
74
  },
77
75
  tooltipPlacement: {
78
76
  options: tooltipPlacements,
79
- control: {
80
- type: 'select',
81
- },
77
+ control: 'select',
82
78
  },
83
79
  },
84
80
  };
@@ -40,10 +40,8 @@ export default {
40
40
  },
41
41
  argTypes: {
42
42
  target: {
43
- control: {
44
- type: 'select',
45
- options: targetOptions,
46
- },
43
+ options: targetOptions,
44
+ control: 'select',
47
45
  },
48
46
  },
49
47
  };
@@ -46,16 +46,12 @@ export default {
46
46
  },
47
47
  argTypes: {
48
48
  color: {
49
- control: {
50
- type: 'select',
51
- options: viewModeOptions,
52
- },
49
+ options: viewModeOptions,
50
+ control: 'select',
53
51
  },
54
52
  size: {
55
- control: {
56
- type: 'select',
57
- options: loadingIconSizes,
58
- },
53
+ options: loadingIconSizes,
54
+ control: 'select',
59
55
  },
60
56
  },
61
57
  };
@@ -115,52 +115,36 @@ export default {
115
115
  },
116
116
  argTypes: {
117
117
  headerBgVariant: {
118
- control: {
119
- type: 'select',
120
- options: variantOptionsWithNoDefault,
121
- },
118
+ options: variantOptionsWithNoDefault,
119
+ control: 'select',
122
120
  },
123
121
  headerBorderVariant: {
124
- control: {
125
- type: 'select',
126
- options: variantOptionsWithNoDefault,
127
- },
122
+ options: variantOptionsWithNoDefault,
123
+ control: 'select',
128
124
  },
129
125
  headerTextVariant: {
130
- control: {
131
- type: 'select',
132
- options: variantOptionsWithNoDefault,
133
- },
126
+ options: variantOptionsWithNoDefault,
127
+ control: 'select',
134
128
  },
135
129
  bodyBgVariant: {
136
- control: {
137
- type: 'select',
138
- options: variantOptionsWithNoDefault,
139
- },
130
+ options: variantOptionsWithNoDefault,
131
+ control: 'select',
140
132
  },
141
133
  bodyTextVariant: {
142
- control: {
143
- type: 'select',
144
- options: variantOptionsWithNoDefault,
145
- },
134
+ options: variantOptionsWithNoDefault,
135
+ control: 'select',
146
136
  },
147
137
  footerBgVariant: {
148
- control: {
149
- type: 'select',
150
- options: variantOptionsWithNoDefault,
151
- },
138
+ options: variantOptionsWithNoDefault,
139
+ control: 'select',
152
140
  },
153
141
  footerBorderVariant: {
154
- control: {
155
- type: 'select',
156
- options: variantOptionsWithNoDefault,
157
- },
142
+ options: variantOptionsWithNoDefault,
143
+ control: 'select',
158
144
  },
159
145
  footerTextVariant: {
160
- control: {
161
- type: 'select',
162
- options: variantOptionsWithNoDefault,
163
- },
146
+ options: variantOptionsWithNoDefault,
147
+ control: 'select',
164
148
  },
165
149
  },
166
150
  };
@@ -75,14 +75,10 @@ export default {
75
75
  argTypes: {
76
76
  theme: {
77
77
  options: glThemes,
78
- control: {
79
- type: 'select',
80
- },
78
+ control: 'select',
81
79
  },
82
80
  backgroundColor: {
83
- control: {
84
- type: 'color',
85
- },
81
+ control: 'color',
86
82
  },
87
83
  },
88
84
  };
@@ -87,12 +87,10 @@ export default {
87
87
  argTypes: {
88
88
  placement: {
89
89
  options: Object.values(popoverPlacements),
90
- control: {
91
- type: 'select',
92
- },
90
+ control: 'select',
93
91
  },
94
92
  title: {
95
- control: { type: 'text' },
93
+ control: 'text',
96
94
  },
97
95
  },
98
96
  };
@@ -28,10 +28,8 @@ export default {
28
28
  },
29
29
  argTypes: {
30
30
  variant: {
31
- control: {
32
- type: 'select',
33
- options: variantOptions,
34
- },
31
+ options: variantOptions,
32
+ control: 'select',
35
33
  },
36
34
  },
37
35
  };
@@ -92,9 +92,7 @@ export default {
92
92
  argTypes: {
93
93
  ...disableControls(['tooltipContainer']),
94
94
  historyItems: {
95
- control: {
96
- type: 'object',
97
- },
95
+ control: 'object',
98
96
  },
99
97
  },
100
98
  };
@@ -51,9 +51,7 @@ export default {
51
51
  options: Object.values(defaultOptions)
52
52
  .filter(({ disabled }) => !disabled)
53
53
  .map(({ value }) => value),
54
- control: {
55
- type: 'radio',
56
- },
54
+ control: 'radio',
57
55
  table: {
58
56
  disable: true,
59
57
  },
@@ -35,10 +35,8 @@ export default {
35
35
  },
36
36
  argTypes: {
37
37
  lines: {
38
- control: {
39
- type: 'select',
40
- options: [1, 2, 3],
41
- },
38
+ options: [1, 2, 3],
39
+ control: 'select',
42
40
  },
43
41
  },
44
42
  };
@@ -107,10 +107,8 @@ export default {
107
107
  },
108
108
  argTypes: {
109
109
  stacked: {
110
- control: {
111
- type: 'select',
112
- options: ['sm', 'md', 'lg', 'xl', true, false],
113
- },
110
+ options: ['sm', 'md', 'lg', 'xl', true, false],
111
+ control: 'select',
114
112
  },
115
113
  },
116
114
  };
@@ -56,20 +56,14 @@ export default {
56
56
  argTypes: {
57
57
  ...disableControls(['name']),
58
58
  labelPosition: {
59
- control: {
60
- type: 'select',
61
- options: toggleLabelPosition,
62
- },
59
+ options: toggleLabelPosition,
60
+ control: 'select',
63
61
  },
64
62
  label: {
65
- control: {
66
- type: 'text',
67
- },
63
+ control: 'text',
68
64
  },
69
65
  help: {
70
- control: {
71
- type: 'text',
72
- },
66
+ control: 'text',
73
67
  },
74
68
  },
75
69
  };
@@ -50,10 +50,8 @@ export default {
50
50
  },
51
51
  argTypes: {
52
52
  variant: {
53
- control: {
54
- type: 'select',
55
- options: tokenVariants,
56
- },
53
+ options: tokenVariants,
54
+ control: 'select',
57
55
  },
58
56
  },
59
57
  };
@@ -104,10 +104,8 @@ export default {
104
104
  },
105
105
  argTypes: {
106
106
  state: {
107
- control: {
108
- type: 'radio',
109
- options: [true, false, null],
110
- },
107
+ options: [true, false, null],
108
+ control: 'radio',
111
109
  },
112
110
  },
113
111
  };
@@ -74,9 +74,7 @@ export default {
74
74
  argTypes: {
75
75
  variant: {
76
76
  options: Object.values(badgeVariantOptions),
77
- control: {
78
- type: 'select',
79
- },
77
+ control: 'select',
80
78
  },
81
79
  metaIcon: {
82
80
  options: iconSpriteInfo.icons,
@@ -55,9 +55,7 @@ Default.args = generateProps();
55
55
 
56
56
  const makeControl = () => ({
57
57
  options: ['100%', '75%', '50%'],
58
- control: {
59
- type: 'select',
60
- },
58
+ control: 'select',
61
59
  });
62
60
 
63
61
  export default {
@@ -37,6 +37,7 @@ export const badgeVariantOptions = {
37
37
  success: 'success',
38
38
  warning: 'warning',
39
39
  danger: 'danger',
40
+ tier: 'tier',
40
41
  };
41
42
 
42
43
  export const variantCssColorMap = {
@@ -297,3 +298,8 @@ export const loadingIconSizes = {
297
298
  'lg (32x32)': 'lg',
298
299
  'xl (64x64)': 'xl',
299
300
  };
301
+
302
+ export const textareaCountOptions = {
303
+ max: 'max',
304
+ recommended: 'recommended',
305
+ };