@gitlab/ui 72.11.1 → 72.12.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 (223) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/tokens/css/tokens.css +1 -1
  3. package/dist/tokens/css/tokens.dark.css +1 -1
  4. package/dist/tokens/js/tokens.dark.js +1 -1
  5. package/dist/tokens/js/tokens.js +1 -1
  6. package/dist/tokens/scss/_tokens.dark.scss +1 -1
  7. package/dist/tokens/scss/_tokens.scss +1 -1
  8. package/package.json +1 -1
  9. package/src/internal/color_contrast/color_contrast.md +8 -0
  10. package/src/internal/color_contrast/color_contrast.spec.js +34 -0
  11. package/src/internal/color_contrast/color_contrast.stories.js +41 -0
  12. package/src/internal/color_contrast/color_contrast.vue +52 -0
  13. package/src/tokens/color.dark.tokens.stories.js +36 -22
  14. package/src/tokens/color.data_viz.dark.tokens.stories.js +13 -30
  15. package/src/tokens/color.data_viz.tokens.stories.js +13 -30
  16. package/src/tokens/color.theme.dark.tokens.stories.js +15 -30
  17. package/src/tokens/color.theme.tokens.stories.js +15 -30
  18. package/src/tokens/color.tokens.stories.js +36 -22
  19. package/src/tokens/color.transparency.tokens.stories.js +9 -12
  20. package/src/tokens/common_story_options.js +22 -80
  21. package/src/utils/constants.js +25 -0
  22. package/src/utils/utils.js +21 -1
  23. package/dist/charts.js +0 -14
  24. package/dist/components/base/accordion/accordion.js +0 -73
  25. package/dist/components/base/accordion/accordion_item.js +0 -133
  26. package/dist/components/base/alert/alert.js +0 -222
  27. package/dist/components/base/avatar/avatar.js +0 -160
  28. package/dist/components/base/avatar_labeled/avatar_labeled.js +0 -107
  29. package/dist/components/base/avatar_link/avatar_link.js +0 -47
  30. package/dist/components/base/avatars_inline/avatars_inline.js +0 -119
  31. package/dist/components/base/badge/badge.js +0 -105
  32. package/dist/components/base/banner/banner.js +0 -139
  33. package/dist/components/base/breadcrumb/breadcrumb.js +0 -122
  34. package/dist/components/base/breadcrumb/breadcrumb_item.js +0 -73
  35. package/dist/components/base/broadcast_message/broadcast_message.js +0 -112
  36. package/dist/components/base/broadcast_message/constants.js +0 -5
  37. package/dist/components/base/button/button.js +0 -151
  38. package/dist/components/base/button_group/button_group.js +0 -47
  39. package/dist/components/base/card/card.js +0 -71
  40. package/dist/components/base/carousel/carousel.js +0 -48
  41. package/dist/components/base/carousel/carousel_slide.js +0 -47
  42. package/dist/components/base/collapse/collapse.js +0 -59
  43. package/dist/components/base/datepicker/datepicker.js +0 -386
  44. package/dist/components/base/daterange_picker/daterange_picker.js +0 -288
  45. package/dist/components/base/drawer/drawer.js +0 -127
  46. package/dist/components/base/dropdown/dropdown.js +0 -261
  47. package/dist/components/base/dropdown/dropdown_divider.js +0 -48
  48. package/dist/components/base/dropdown/dropdown_form.js +0 -48
  49. package/dist/components/base/dropdown/dropdown_item.js +0 -131
  50. package/dist/components/base/dropdown/dropdown_section_header.js +0 -48
  51. package/dist/components/base/dropdown/dropdown_text.js +0 -48
  52. package/dist/components/base/filtered_search/common_story_options.js +0 -14
  53. package/dist/components/base/filtered_search/filtered_search.js +0 -388
  54. package/dist/components/base/filtered_search/filtered_search_suggestion.js +0 -89
  55. package/dist/components/base/filtered_search/filtered_search_suggestion_list.js +0 -138
  56. package/dist/components/base/filtered_search/filtered_search_term.js +0 -203
  57. package/dist/components/base/filtered_search/filtered_search_token.js +0 -384
  58. package/dist/components/base/filtered_search/filtered_search_token_segment.js +0 -420
  59. package/dist/components/base/filtered_search/filtered_search_utils.js +0 -242
  60. package/dist/components/base/form/form.js +0 -49
  61. package/dist/components/base/form/form_checkbox/form_checkbox.js +0 -78
  62. package/dist/components/base/form/form_checkbox/form_checkbox_group.js +0 -60
  63. package/dist/components/base/form/form_checkbox_tree/checkbox_tree_node.js +0 -79
  64. package/dist/components/base/form/form_checkbox_tree/form_checkbox_tree.js +0 -138
  65. package/dist/components/base/form/form_checkbox_tree/models/constants.js +0 -12
  66. package/dist/components/base/form/form_checkbox_tree/models/node.js +0 -51
  67. package/dist/components/base/form/form_checkbox_tree/models/tree.js +0 -199
  68. package/dist/components/base/form/form_combobox/constants.js +0 -55
  69. package/dist/components/base/form/form_combobox/form_combobox.js +0 -230
  70. package/dist/components/base/form/form_date/form_date.js +0 -143
  71. package/dist/components/base/form/form_fields/form_field_validator.js +0 -93
  72. package/dist/components/base/form/form_fields/form_fields.js +0 -214
  73. package/dist/components/base/form/form_fields/mappers.js +0 -13
  74. package/dist/components/base/form/form_fields/validators.js +0 -48
  75. package/dist/components/base/form/form_group/form_group.js +0 -97
  76. package/dist/components/base/form/form_input/form_input.js +0 -121
  77. package/dist/components/base/form/form_input_group/form_input_group.js +0 -108
  78. package/dist/components/base/form/form_input_group/form_input_group_mixin.js +0 -41
  79. package/dist/components/base/form/form_radio/form_radio.js +0 -65
  80. package/dist/components/base/form/form_radio_group/form_radio_group.js +0 -78
  81. package/dist/components/base/form/form_select/constants.js +0 -12
  82. package/dist/components/base/form/form_select/form_select.js +0 -82
  83. package/dist/components/base/form/form_text/form_text.js +0 -38
  84. package/dist/components/base/form/form_textarea/form_textarea.js +0 -112
  85. package/dist/components/base/form/input_group_text/input_group_text.js +0 -48
  86. package/dist/components/base/icon/icon.js +0 -111
  87. package/dist/components/base/infinite_scroll/infinite_scroll.js +0 -197
  88. package/dist/components/base/keyset_pagination/keyset_pagination.js +0 -151
  89. package/dist/components/base/label/label.js +0 -163
  90. package/dist/components/base/link/link.js +0 -50
  91. package/dist/components/base/loading_icon/loading_icon.js +0 -111
  92. package/dist/components/base/markdown/markdown.js +0 -52
  93. package/dist/components/base/modal/modal.js +0 -204
  94. package/dist/components/base/nav/nav.js +0 -48
  95. package/dist/components/base/nav/nav_item.js +0 -48
  96. package/dist/components/base/nav/nav_item_dropdown.js +0 -62
  97. package/dist/components/base/navbar/navbar.js +0 -48
  98. package/dist/components/base/new_dropdowns/base_dropdown/base_dropdown.js +0 -453
  99. package/dist/components/base/new_dropdowns/base_dropdown/constants.js +0 -4
  100. package/dist/components/base/new_dropdowns/constants.js +0 -21
  101. package/dist/components/base/new_dropdowns/disclosure/constants.js +0 -8
  102. package/dist/components/base/new_dropdowns/disclosure/disclosure_dropdown.js +0 -370
  103. package/dist/components/base/new_dropdowns/disclosure/disclosure_dropdown_group.js +0 -110
  104. package/dist/components/base/new_dropdowns/disclosure/disclosure_dropdown_item.js +0 -143
  105. package/dist/components/base/new_dropdowns/disclosure/mock_data.js +0 -147
  106. package/dist/components/base/new_dropdowns/disclosure/utils.js +0 -39
  107. package/dist/components/base/new_dropdowns/listbox/listbox.js +0 -767
  108. package/dist/components/base/new_dropdowns/listbox/listbox_group.js +0 -58
  109. package/dist/components/base/new_dropdowns/listbox/listbox_item.js +0 -91
  110. package/dist/components/base/new_dropdowns/listbox/listbox_search_input.js +0 -93
  111. package/dist/components/base/new_dropdowns/listbox/mock_data.js +0 -118
  112. package/dist/components/base/new_dropdowns/listbox/utils.js +0 -34
  113. package/dist/components/base/paginated_list/paginated_list.js +0 -180
  114. package/dist/components/base/pagination/pagination.js +0 -399
  115. package/dist/components/base/path/data.js +0 -34
  116. package/dist/components/base/path/path.js +0 -189
  117. package/dist/components/base/popover/popover.js +0 -110
  118. package/dist/components/base/progress_bar/progress_bar.js +0 -48
  119. package/dist/components/base/search_box_by_click/search_box_by_click.js +0 -235
  120. package/dist/components/base/search_box_by_type/search_box_by_type.js +0 -167
  121. package/dist/components/base/segmented_control/segmented_control.js +0 -109
  122. package/dist/components/base/skeleton_loader/skeleton_loader.js +0 -224
  123. package/dist/components/base/sorting/sorting.js +0 -171
  124. package/dist/components/base/sorting/sorting_item.js +0 -109
  125. package/dist/components/base/table/constants.js +0 -5
  126. package/dist/components/base/table/table.js +0 -89
  127. package/dist/components/base/table_lite/table_lite.js +0 -72
  128. package/dist/components/base/tabs/constants.js +0 -3
  129. package/dist/components/base/tabs/tab/tab.js +0 -83
  130. package/dist/components/base/tabs/tabs/scrollable_tabs.js +0 -143
  131. package/dist/components/base/tabs/tabs/tabs.js +0 -224
  132. package/dist/components/base/toast/toast.js +0 -82
  133. package/dist/components/base/toggle/toggle.js +0 -180
  134. package/dist/components/base/token/token.js +0 -85
  135. package/dist/components/base/token_selector/helpers.js +0 -5
  136. package/dist/components/base/token_selector/token_container.js +0 -165
  137. package/dist/components/base/token_selector/token_selector.js +0 -403
  138. package/dist/components/base/token_selector/token_selector_dropdown.js +0 -199
  139. package/dist/components/base/tooltip/tooltip.js +0 -55
  140. package/dist/components/charts/area/area.js +0 -311
  141. package/dist/components/charts/bar/bar.js +0 -253
  142. package/dist/components/charts/chart/chart.js +0 -215
  143. package/dist/components/charts/column/column.js +0 -226
  144. package/dist/components/charts/discrete_scatter/discrete_scatter.js +0 -203
  145. package/dist/components/charts/gauge/gauge.js +0 -208
  146. package/dist/components/charts/heatmap/heatmap.js +0 -295
  147. package/dist/components/charts/heatmap/index.js +0 -2
  148. package/dist/components/charts/legend/legend.js +0 -228
  149. package/dist/components/charts/line/line.js +0 -308
  150. package/dist/components/charts/series_label/series_label.js +0 -100
  151. package/dist/components/charts/single_stat/single_stat.js +0 -152
  152. package/dist/components/charts/sparkline/sparkline.js +0 -261
  153. package/dist/components/charts/stacked_column/stacked_column.js +0 -335
  154. package/dist/components/charts/tooltip/tooltip.js +0 -251
  155. package/dist/components/experimental/duo/chat/components/duo_chat_conversation/duo_chat_conversation.js +0 -83
  156. package/dist/components/experimental/duo/chat/components/duo_chat_loader/duo_chat_loader.js +0 -100
  157. package/dist/components/experimental/duo/chat/components/duo_chat_message/copy_code_element.js +0 -35
  158. package/dist/components/experimental/duo/chat/components/duo_chat_message/duo_chat_message.js +0 -115
  159. package/dist/components/experimental/duo/chat/components/duo_chat_message_sources/duo_chat_message_sources.js +0 -104
  160. package/dist/components/experimental/duo/chat/components/duo_chat_predefined_prompts/duo_chat_predefined_prompts.js +0 -64
  161. package/dist/components/experimental/duo/chat/constants.js +0 -23
  162. package/dist/components/experimental/duo/chat/duo_chat.js +0 -359
  163. package/dist/components/experimental/duo/chat/mock_data.js +0 -83
  164. package/dist/components/experimental/duo/user_feedback/user_feedback.js +0 -94
  165. package/dist/components/experimental/duo/user_feedback/user_feedback_modal.js +0 -124
  166. package/dist/components/experimental/experiment_badge/constants.js +0 -4
  167. package/dist/components/experimental/experiment_badge/experiment_badge.js +0 -107
  168. package/dist/components/mixins/button_mixin.js +0 -11
  169. package/dist/components/mixins/safe_link_mixin.js +0 -30
  170. package/dist/components/mixins/tooltip_mixin.js +0 -21
  171. package/dist/components/regions/dashboard_skeleton/dashboard_skeleton.js +0 -53
  172. package/dist/components/regions/empty_state/empty_state.js +0 -154
  173. package/dist/components/shared_components/charts/tooltip_default_format.js +0 -53
  174. package/dist/components/shared_components/clear_icon_button/clear_icon_button.js +0 -64
  175. package/dist/components/shared_components/close_button/close_button.js +0 -54
  176. package/dist/components/utilities/animated_number/animated_number.js +0 -131
  177. package/dist/components/utilities/friendly_wrap/friendly_wrap.js +0 -75
  178. package/dist/components/utilities/intersection_observer/intersection_observer.js +0 -88
  179. package/dist/components/utilities/intersperse/intersperse.js +0 -86
  180. package/dist/components/utilities/sprintf/sprintf.js +0 -172
  181. package/dist/components/utilities/truncate/constants.js +0 -7
  182. package/dist/components/utilities/truncate/truncate.js +0 -111
  183. package/dist/components/utilities/truncate_text/constants.js +0 -7
  184. package/dist/components/utilities/truncate_text/truncate_text.js +0 -146
  185. package/dist/config.js +0 -86
  186. package/dist/directives/collapse_toggle.js +0 -1
  187. package/dist/directives/hover_load/hover_load.js +0 -45
  188. package/dist/directives/modal.js +0 -1
  189. package/dist/directives/outside/get_event_like_time_stamp.js +0 -33
  190. package/dist/directives/outside/outside.js +0 -106
  191. package/dist/directives/resize_observer/resize_observer.js +0 -51
  192. package/dist/directives/safe_html/constants.js +0 -6
  193. package/dist/directives/safe_html/safe_html.js +0 -39
  194. package/dist/directives/safe_link/mock_data.js +0 -10
  195. package/dist/directives/safe_link/safe_link.js +0 -65
  196. package/dist/directives/tooltip.js +0 -1
  197. package/dist/index.css +0 -7
  198. package/dist/index.css.map +0 -1
  199. package/dist/index.js +0 -105
  200. package/dist/tokens/common_story_options.js +0 -109
  201. package/dist/utils/breakpoints.js +0 -20
  202. package/dist/utils/charts/config.js +0 -556
  203. package/dist/utils/charts/constants.js +0 -63
  204. package/dist/utils/charts/mock_data.js +0 -211
  205. package/dist/utils/charts/story_config.js +0 -42
  206. package/dist/utils/charts/theme.js +0 -192
  207. package/dist/utils/charts/utils.js +0 -54
  208. package/dist/utils/constants.js +0 -270
  209. package/dist/utils/data_utils.js +0 -21
  210. package/dist/utils/datetime_utility.js +0 -61
  211. package/dist/utils/i18n.js +0 -15
  212. package/dist/utils/is_slot_empty.js +0 -38
  213. package/dist/utils/number_utils.js +0 -124
  214. package/dist/utils/stories_constants.js +0 -29
  215. package/dist/utils/stories_utils.js +0 -13
  216. package/dist/utils/story_decorators/container.js +0 -16
  217. package/dist/utils/string_utils.js +0 -69
  218. package/dist/utils/svgs/svg_paths.js +0 -7
  219. package/dist/utils/test_utils.js +0 -33
  220. package/dist/utils/use_fake_date.js +0 -29
  221. package/dist/utils/use_mock_intersection_observer.js +0 -108
  222. package/dist/utils/utils.js +0 -177
  223. package/dist/utils.js +0 -5
@@ -1,24 +1,21 @@
1
- import { methods, template } from './common_story_options';
2
- import colorTokens from './color.transparency.tokens.json';
1
+ import COMPILED_TOKENS from '../../dist/tokens/json/tokens.json';
2
+ import { colorTokenStoryOptions } from './common_story_options';
3
3
 
4
- const generateProps = ({ name = '', tokens = colorTokens } = {}) => ({
5
- name,
6
- tokens,
7
- });
4
+ const generateProps = ({ tokens = {} } = {}) => ({ tokens });
8
5
 
9
6
  export const Gray = (args, { argTypes }) => ({
10
7
  props: Object.keys(argTypes),
11
- methods,
12
- template,
8
+ ...colorTokenStoryOptions,
13
9
  });
14
- Gray.args = generateProps({ name: 't-gray-a', tokens: colorTokens['t-gray-a'] });
10
+ Gray.args = generateProps({ tokens: COMPILED_TOKENS['t-gray-a'] });
15
11
 
16
12
  export const White = (args, { argTypes }) => ({
17
13
  props: Object.keys(argTypes),
18
- methods,
19
- template: `<div class="gl-bg-gray-900 gl-text-white">${template}</div>`,
14
+ components: colorTokenStoryOptions.components,
15
+ methods: colorTokenStoryOptions.methods,
16
+ template: `<div class="gl-bg-gray-900 gl-text-white">${colorTokenStoryOptions.template}</div>`,
20
17
  });
21
- White.args = generateProps({ name: 't-white-a', tokens: colorTokens['t-white-a'] });
18
+ White.args = generateProps({ tokens: COMPILED_TOKENS['t-white-a'] });
22
19
 
23
20
  // eslint-disable-next-line storybook/csf-component
24
21
  export default {
@@ -1,35 +1,17 @@
1
- import { colorFromBackground, relativeLuminance, rgbFromHex } from '../utils/utils';
2
1
  import { WHITE, GRAY_950 } from '../../dist/tokens/js/tokens';
2
+ import { colorFromBackground } from '../utils/utils';
3
+ import GlColorContrast from '../internal/color_contrast/color_contrast.vue';
3
4
 
4
- const CONTRAST_LEVELS = [
5
- {
6
- grade: 'F',
7
- min: 0,
8
- max: 3,
9
- },
10
- {
11
- grade: 'AA+',
12
- min: 3,
13
- max: 4.5,
14
- },
15
- {
16
- grade: 'AA',
17
- min: 4.5,
18
- max: 7,
19
- },
20
- {
21
- grade: 'AAA',
22
- min: 7,
23
- max: 22,
24
- },
25
- ];
5
+ export const components = {
6
+ GlColorContrast,
7
+ };
26
8
 
27
9
  export const methods = {
28
10
  isAlpha(value) {
29
11
  return value.startsWith('rgba(');
30
12
  },
31
- getTokenName(name, key) {
32
- return [name, key].filter(Boolean).join('.');
13
+ getTokenName(token) {
14
+ return token.path.filter(Boolean).join('.');
33
15
  },
34
16
  getTextColorClass(value) {
35
17
  if (this.isAlpha(value)) return '';
@@ -39,71 +21,31 @@ export const methods = {
39
21
  'gl-text-white': textColorVariant === 'light',
40
22
  };
41
23
  },
42
- getColorContrast(foreground = 'light', background) {
43
- const foregroundColor = {
44
- light: WHITE,
45
- dark: GRAY_950,
46
- };
47
- // Formula: http://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef
48
- const foregroundLuminance = relativeLuminance(rgbFromHex(foregroundColor[foreground])) + 0.05;
49
- const backgroundLuminance = relativeLuminance(rgbFromHex(background)) + 0.05;
50
-
51
- let score = foregroundLuminance / backgroundLuminance;
52
- if (backgroundLuminance > foregroundLuminance) {
53
- score = 1 / score;
54
- }
55
-
56
- const level = CONTRAST_LEVELS.find(({ min, max }) => {
57
- return score >= min && score < max;
58
- });
59
-
60
- return {
61
- score: (Math.round(score * 10) / 10).toFixed(1),
62
- level,
63
- };
64
- },
65
- getColorContrastClass(foreground, background) {
66
- const { grade } = this.getColorContrast(foreground, background).level;
67
- const isFail = grade === 'F';
68
- const classes = {
69
- light: isFail ? 'gl-inset-border-1-red-500 gl-text-red-500' : 'gl-text-gray-950',
70
- dark: isFail ? 'gl-inset-border-1-red-300 gl-text-red-300' : 'gl-text-white',
71
- };
72
- return classes[foreground];
73
- },
74
24
  };
75
25
 
76
- export const template = `
26
+ export const template = (lightBackground = WHITE, darkBackground = GRAY_950) => `
77
27
  <ul
78
28
  class="gl-list-style-none gl-m-0 gl-p-0"
79
29
  >
80
30
  <li
81
- v-for="(token, key) in tokens"
82
- :key="key"
31
+ v-for="token in tokens"
32
+ :key="token.name"
83
33
  class="gl-display-flex gl-flex-wrap gl-align-items-center gl-justify-content-space-between gl-gap-3 gl-p-3"
84
- :class="getTextColorClass(token.$value)"
85
- :style="{ backgroundColor: token.$value }"
34
+ :class="getTextColorClass(token.value)"
35
+ :style="{ backgroundColor: token.value }"
86
36
  >
87
- <code class="gl-reset-color">{{ getTokenName(name, key) }}</code>
37
+ <code class="gl-reset-color">{{ getTokenName(token) }}</code>
88
38
  <div class="gl-display-flex gl-align-items-center gl-gap-3">
89
- <code class="gl-reset-color">{{ token.$value }}</code>
90
- <code
91
- v-if="!isAlpha(token.$value)"
92
- class="gl-w-10 gl-text-center gl-rounded-base gl-font-xs gl-p-2 gl-bg-gray-950"
93
- :class="getColorContrastClass('dark', token.$value)"
94
- >
95
- {{ getColorContrast('dark', token.$value).level.grade }}
96
- {{ getColorContrast('dark', token.$value).score }}
97
- </code>
98
- <code
99
- v-if="!isAlpha(token.$value)"
100
- class="gl-w-10 gl-text-center gl-rounded-base gl-font-xs gl-p-2 gl-bg-white"
101
- :class="getColorContrastClass('light', token.$value)"
102
- >
103
- {{ getColorContrast('light', token.$value).level.grade }}
104
- {{ getColorContrast('light', token.$value).score }}
105
- </code>
39
+ <code class="gl-reset-color">{{ token.value }}</code>
40
+ <gl-color-contrast v-if="!isAlpha(token.value)" :foreground="token.value" background="${darkBackground}" />
41
+ <gl-color-contrast v-if="!isAlpha(token.value)" :foreground="token.value" background="${lightBackground}" />
106
42
  </div>
107
43
  </li>
108
44
  </ul>
109
45
  `;
46
+
47
+ export const colorTokenStoryOptions = {
48
+ components,
49
+ methods,
50
+ template: template(),
51
+ };
@@ -6,6 +6,31 @@ function appendDefaultOption(options) {
6
6
 
7
7
  export const COMMA = ',';
8
8
 
9
+ export const CONTRAST_LEVELS = [
10
+ {
11
+ grade: 'F',
12
+ min: 0,
13
+ max: 3,
14
+ },
15
+ {
16
+ grade: 'AA+',
17
+ min: 3,
18
+ max: 4.5,
19
+ },
20
+ {
21
+ grade: 'AA',
22
+ min: 4.5,
23
+ max: 7,
24
+ },
25
+ {
26
+ grade: 'AAA',
27
+ min: 7,
28
+ max: 22,
29
+ },
30
+ ];
31
+
32
+ export const HEX_REGEX = /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;
33
+
9
34
  export const LEFT_MOUSE_BUTTON = 0;
10
35
 
11
36
  export const glThemes = ['indigo', 'blue', 'light-blue', 'green', 'red', 'light-red'];
@@ -1,5 +1,5 @@
1
1
  import { isVisible } from 'bootstrap-vue/src/utils/dom';
2
- import { COMMA, labelColorOptions, focusableTags } from './constants';
2
+ import { COMMA, CONTRAST_LEVELS, labelColorOptions, focusableTags } from './constants';
3
3
 
4
4
  export function debounceByAnimationFrame(fn) {
5
5
  let requestId;
@@ -90,6 +90,26 @@ export function colorFromBackground(backgroundColor, contrastRatio = 2.4) {
90
90
  : labelColorOptions.dark;
91
91
  }
92
92
 
93
+ export function getColorContrast(foreground, background) {
94
+ // Formula: http://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef
95
+ const backgroundLuminance = relativeLuminance(rgbFromHex(background)) + 0.05;
96
+ const foregroundLuminance = relativeLuminance(rgbFromHex(foreground)) + 0.05;
97
+
98
+ let score = backgroundLuminance / foregroundLuminance;
99
+ if (foregroundLuminance > backgroundLuminance) {
100
+ score = 1 / score;
101
+ }
102
+
103
+ const level = CONTRAST_LEVELS.find(({ min, max }) => {
104
+ return score >= min && score < max;
105
+ });
106
+
107
+ return {
108
+ score: (Math.round(score * 10) / 10).toFixed(1),
109
+ level,
110
+ };
111
+ }
112
+
93
113
  export function uid() {
94
114
  return Math.random().toString(36).substring(2);
95
115
  }
package/dist/charts.js DELETED
@@ -1,14 +0,0 @@
1
- export { default as GlChart } from './components/charts/chart/chart';
2
- export { default as GlAreaChart } from './components/charts/area/area';
3
- export { default as GlBarChart } from './components/charts/bar/bar';
4
- export { default as GlGaugeChart } from './components/charts/gauge/gauge';
5
- export { default as GlLineChart } from './components/charts/line/line';
6
- export { default as GlChartLegend } from './components/charts/legend/legend';
7
- export { default as GlChartSeriesLabel } from './components/charts/series_label/series_label';
8
- export { default as GlChartTooltip } from './components/charts/tooltip/tooltip';
9
- export { default as GlHeatmap } from './components/charts/heatmap';
10
- export { default as GlColumnChart } from './components/charts/column/column';
11
- export { default as GlStackedColumnChart } from './components/charts/stacked_column/stacked_column';
12
- export { default as GlDiscreteScatterChart } from './components/charts/discrete_scatter/discrete_scatter';
13
- export { default as GlSingleStat } from './components/charts/single_stat/single_stat';
14
- export { default as GlSparklineChart } from './components/charts/sparkline/sparkline';
@@ -1,73 +0,0 @@
1
- import uniqueId from 'lodash/uniqueId';
2
- import __vue_normalize__ from 'vue-runtime-helpers/dist/normalize-component.js';
3
-
4
- var script = {
5
- name: 'GlAccordion',
6
- provide() {
7
- const accordionId = uniqueId('accordion-set-');
8
- // temporary fix for this issue: https://gitlab.com/gitlab-org/gitlab-ui/-/merge_requests/2019#note_514671251
9
- // MR for the upstream pending: https://github.com/vuejs/apollo/pull/1153
10
- return {
11
- defaultHeaderLevel: () => this.headerLevel,
12
- accordionSetId: () => this.autoCollapse && accordionId
13
- };
14
- },
15
- props: {
16
- /*
17
- When true, will have the effect of closing other accordion items when one accordion item is visible.
18
- */
19
- autoCollapse: {
20
- type: Boolean,
21
- required: false,
22
- default: false
23
- },
24
- /*
25
- The header tag used in the accordion (h1/h2/h3/h4/h5/h6). This overrides the value provided by GlAccordion. For accessibility this should be set to an appropriate value in the context where the accordion is used.
26
- */
27
- headerLevel: {
28
- type: Number,
29
- required: true,
30
- validator(value) {
31
- return value > 0 && value <= 6;
32
- }
33
- }
34
- }
35
- };
36
-
37
- /* script */
38
- const __vue_script__ = script;
39
-
40
- /* template */
41
- var __vue_render__ = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',[_vm._t("default")],2)};
42
- var __vue_staticRenderFns__ = [];
43
-
44
- /* style */
45
- const __vue_inject_styles__ = undefined;
46
- /* scoped */
47
- const __vue_scope_id__ = undefined;
48
- /* module identifier */
49
- const __vue_module_identifier__ = undefined;
50
- /* functional template */
51
- const __vue_is_functional_template__ = false;
52
- /* style inject */
53
-
54
- /* style inject SSR */
55
-
56
- /* style inject shadow dom */
57
-
58
-
59
-
60
- const __vue_component__ = __vue_normalize__(
61
- { render: __vue_render__, staticRenderFns: __vue_staticRenderFns__ },
62
- __vue_inject_styles__,
63
- __vue_script__,
64
- __vue_scope_id__,
65
- __vue_is_functional_template__,
66
- __vue_module_identifier__,
67
- false,
68
- undefined,
69
- undefined,
70
- undefined
71
- );
72
-
73
- export default __vue_component__;
@@ -1,133 +0,0 @@
1
- import { BCollapse } from 'bootstrap-vue/esm/index.js';
2
- import uniqueId from 'lodash/uniqueId';
3
- import { GlCollapseToggleDirective } from '../../../directives/collapse_toggle';
4
- import GlButton from '../button/button';
5
- import __vue_normalize__ from 'vue-runtime-helpers/dist/normalize-component.js';
6
-
7
- var script = {
8
- name: 'GlAccordionItem',
9
- components: {
10
- BCollapse,
11
- GlButton
12
- },
13
- directives: {
14
- GlCollapseToggle: GlCollapseToggleDirective
15
- },
16
- inject: ['accordionSetId', 'defaultHeaderLevel'],
17
- inheritAttrs: false,
18
- model: {
19
- prop: 'visible',
20
- event: 'input'
21
- },
22
- props: {
23
- /**
24
- * Used to set the title of accordion link
25
- */
26
- title: {
27
- type: String,
28
- required: true
29
- },
30
- /**
31
- * Used to set the title of accordion link when the content is visible
32
- * */
33
- titleVisible: {
34
- type: String,
35
- default: null,
36
- required: false
37
- },
38
- /**
39
- * When set, it will ensure the accordion item is initially visible
40
- */
41
- visible: {
42
- type: Boolean,
43
- default: false,
44
- required: false
45
- },
46
- /**
47
- * The header tag used in the accordion (h1/h2/h3/h4/h5/h6). This overrides the value provided by GlAccordion. For accessibility this should be set to an appropriate value in the context where the accordion is used.,
48
- */
49
- headerLevel: {
50
- type: Number,
51
- required: false,
52
- default: null,
53
- validator(value) {
54
- return value > 0 && value <= 6;
55
- }
56
- },
57
- /**
58
- * Additional CSS class(es) to be applied to the header
59
- */
60
- headerClass: {
61
- type: [String, Object, Array],
62
- required: false,
63
- default: ''
64
- }
65
- },
66
- data() {
67
- return {
68
- accordionItemId: uniqueId('accordion-item-'),
69
- isVisible: this.visible
70
- };
71
- },
72
- computed: {
73
- headerComponent() {
74
- const level = this.headerLevel || this.defaultHeaderLevel();
75
- return `h${level}`;
76
- },
77
- accordion() {
78
- return this.accordionSetId() || undefined;
79
- },
80
- icon() {
81
- return this.isVisible ? 'chevron-down' : 'chevron-right';
82
- },
83
- buttonTitle() {
84
- return this.isVisible && this.titleVisible ? this.titleVisible : this.title;
85
- }
86
- },
87
- watch: {
88
- isVisible: {
89
- immediate: true,
90
- handler(isVisible) {
91
- this.$emit('input', isVisible);
92
- }
93
- }
94
- }
95
- };
96
-
97
- /* script */
98
- const __vue_script__ = script;
99
-
100
- /* template */
101
- var __vue_render__ = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{staticClass:"gl-accordion-item"},[_c(_vm.headerComponent,{tag:"component",staticClass:"gl-accordion-item-header",class:_vm.headerClass},[_c('gl-button',{directives:[{name:"gl-collapse-toggle",rawName:"v-gl-collapse-toggle",value:(_vm.accordionItemId),expression:"accordionItemId"}],attrs:{"variant":"link","button-text-classes":"gl-display-flex","icon":_vm.icon}},[_vm._v("\n "+_vm._s(_vm.buttonTitle)+"\n ")])],1),_vm._v(" "),_c('b-collapse',{staticClass:"gl-mt-3 gl-font-base",attrs:{"id":_vm.accordionItemId,"visible":_vm.isVisible,"accordion":_vm.accordion,"data-testid":("accordion-item-collapse-" + _vm.accordionItemId)},model:{value:(_vm.isVisible),callback:function ($$v) {_vm.isVisible=$$v;},expression:"isVisible"}},[_vm._t("default")],2)],1)};
102
- var __vue_staticRenderFns__ = [];
103
-
104
- /* style */
105
- const __vue_inject_styles__ = undefined;
106
- /* scoped */
107
- const __vue_scope_id__ = undefined;
108
- /* module identifier */
109
- const __vue_module_identifier__ = undefined;
110
- /* functional template */
111
- const __vue_is_functional_template__ = false;
112
- /* style inject */
113
-
114
- /* style inject SSR */
115
-
116
- /* style inject shadow dom */
117
-
118
-
119
-
120
- const __vue_component__ = __vue_normalize__(
121
- { render: __vue_render__, staticRenderFns: __vue_staticRenderFns__ },
122
- __vue_inject_styles__,
123
- __vue_script__,
124
- __vue_scope_id__,
125
- __vue_is_functional_template__,
126
- __vue_module_identifier__,
127
- false,
128
- undefined,
129
- undefined,
130
- undefined
131
- );
132
-
133
- export default __vue_component__;
@@ -1,222 +0,0 @@
1
- import { alertVariantOptions, alertVariantIconMap, buttonCategoryOptions } from '../../../utils/constants';
2
- import CloseButton from '../../shared_components/close_button/close_button';
3
- import GlButton from '../button/button';
4
- import GlIcon from '../icon/icon';
5
- import __vue_normalize__ from 'vue-runtime-helpers/dist/normalize-component.js';
6
-
7
- //
8
- var script = {
9
- name: 'GlAlert',
10
- components: {
11
- GlIcon,
12
- CloseButton,
13
- GlButton
14
- },
15
- props: {
16
- title: {
17
- type: String,
18
- required: false,
19
- default: ''
20
- },
21
- /**
22
- * Controls the dismiss button's visibility.
23
- */
24
- dismissible: {
25
- type: Boolean,
26
- required: false,
27
- default: true
28
- },
29
- /**
30
- * Shows icon based on variant.
31
- */
32
- showIcon: {
33
- type: Boolean,
34
- required: false,
35
- default: true
36
- },
37
- /**
38
- * Dismiss button's aria-label.
39
- */
40
- dismissLabel: {
41
- type: String,
42
- required: false,
43
- default: 'Dismiss'
44
- },
45
- variant: {
46
- type: String,
47
- required: false,
48
- default: alertVariantOptions.info,
49
- validator: value => Object.keys(alertVariantOptions).includes(value)
50
- },
51
- /**
52
- * If provided, renders the primary button as a link.
53
- */
54
- primaryButtonLink: {
55
- type: String,
56
- required: false,
57
- default: ''
58
- },
59
- /**
60
- * If provided, renders a primary action button.
61
- */
62
- primaryButtonText: {
63
- type: String,
64
- required: false,
65
- default: ''
66
- },
67
- /**
68
- * If provided, renders the secondary button as a link.
69
- */
70
- secondaryButtonLink: {
71
- type: String,
72
- required: false,
73
- default: ''
74
- },
75
- /**
76
- * If provided, renders a secondary action button.
77
- */
78
- secondaryButtonText: {
79
- type: String,
80
- required: false,
81
- default: ''
82
- },
83
- sticky: {
84
- type: Boolean,
85
- required: false,
86
- default: false
87
- }
88
- },
89
- computed: {
90
- ariaLive() {
91
- if ([alertVariantOptions.danger, alertVariantOptions.warning].includes(this.variant)) {
92
- return 'assertive';
93
- }
94
- return 'polite';
95
- },
96
- role() {
97
- if ([alertVariantOptions.danger, alertVariantOptions.warning, alertVariantOptions.success].includes(this.variant)) {
98
- return 'alert';
99
- }
100
- return 'status';
101
- },
102
- iconName() {
103
- return alertVariantIconMap[this.variant];
104
- },
105
- shouldRenderActions() {
106
- // eslint-disable-next-line @gitlab/vue-prefer-dollar-scopedslots
107
- return Boolean(this.$slots.actions || this.actionButtons.length);
108
- },
109
- actionButtons() {
110
- return [{
111
- text: this.primaryButtonText,
112
- attrs: {
113
- href: this.primaryButtonLink,
114
- variant: 'confirm',
115
- category: buttonCategoryOptions.primary
116
- },
117
- listeners: {
118
- click: this.primaryButtonClicked
119
- }
120
- }, {
121
- text: this.secondaryButtonText,
122
- attrs: {
123
- href: this.secondaryButtonLink,
124
- variant: 'default',
125
- category: buttonCategoryOptions.secondary
126
- },
127
- listeners: {
128
- click: this.secondaryButtonClicked
129
- }
130
- }].reduce((acc, actionButton) => {
131
- if (!actionButton.text) return acc;
132
- const attrs = {
133
- ...actionButton.attrs
134
- };
135
- if (!attrs.href) {
136
- delete attrs.href;
137
- }
138
- acc.push({
139
- ...actionButton,
140
- attrs
141
- });
142
- return acc;
143
- }, []);
144
- },
145
- variantClass() {
146
- return `gl-alert-${this.variant}`;
147
- }
148
- },
149
- methods: {
150
- primaryButtonClicked(event) {
151
- /**
152
- * Emitted when the primary action button is clicked.
153
- *
154
- * @event primaryAction
155
- * @type {object}
156
- */
157
- this.$emit('primaryAction', event);
158
- },
159
- secondaryButtonClicked(event) {
160
- /**
161
- * Emitted when the secondary action button is clicked.
162
- *
163
- * @event secondaryAction
164
- * @type {object}
165
- */
166
- this.$emit('secondaryAction', event);
167
- },
168
- onDismiss() {
169
- /**
170
- * Emitted when the dismiss button is clicked.
171
- *
172
- * @event dismiss
173
- * @type {object}
174
- */
175
- this.$emit('dismiss');
176
- }
177
- }
178
- };
179
-
180
- /* script */
181
- const __vue_script__ = script;
182
-
183
- /* template */
184
- var __vue_render__ = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{class:[
185
- 'gl-alert',
186
- { 'gl-alert-sticky': _vm.sticky },
187
- { 'gl-alert-not-dismissible': !_vm.dismissible },
188
- { 'gl-alert-no-icon': !_vm.showIcon },
189
- { 'gl-alert-has-title': !!_vm.title },
190
- _vm.variantClass ]},[(_vm.showIcon)?_c('div',{staticClass:"gl-alert-icon-container"},[_c('gl-icon',{staticClass:"gl-alert-icon",attrs:{"name":_vm.iconName}})],1):_vm._e(),_vm._v(" "),_c('div',{staticClass:"gl-alert-content",attrs:{"role":_vm.role,"aria-live":_vm.ariaLive}},[(_vm.title)?_c('h2',{staticClass:"gl-alert-title"},[_vm._v(_vm._s(_vm.title))]):_vm._e(),_vm._v(" "),_c('div',{staticClass:"gl-alert-body"},[_vm._t("default")],2),_vm._v(" "),(_vm.shouldRenderActions)?_c('div',{staticClass:"gl-alert-actions"},[_vm._t("actions",function(){return _vm._l((_vm.actionButtons),function(actionButton,index){return _c('gl-button',_vm._g(_vm._b({key:index,staticClass:"gl-alert-action"},'gl-button',actionButton.attrs,false),actionButton.listeners),[_vm._v("\n "+_vm._s(actionButton.text)+"\n ")])})})],2):_vm._e()]),_vm._v(" "),(_vm.dismissible)?_c('close-button',{ref:"dismiss",staticClass:"gl-dismiss-btn",attrs:{"label":_vm.dismissLabel},on:{"click":_vm.onDismiss}}):_vm._e()],1)};
191
- var __vue_staticRenderFns__ = [];
192
-
193
- /* style */
194
- const __vue_inject_styles__ = undefined;
195
- /* scoped */
196
- const __vue_scope_id__ = undefined;
197
- /* module identifier */
198
- const __vue_module_identifier__ = undefined;
199
- /* functional template */
200
- const __vue_is_functional_template__ = false;
201
- /* style inject */
202
-
203
- /* style inject SSR */
204
-
205
- /* style inject shadow dom */
206
-
207
-
208
-
209
- const __vue_component__ = __vue_normalize__(
210
- { render: __vue_render__, staticRenderFns: __vue_staticRenderFns__ },
211
- __vue_inject_styles__,
212
- __vue_script__,
213
- __vue_scope_id__,
214
- __vue_is_functional_template__,
215
- __vue_module_identifier__,
216
- false,
217
- undefined,
218
- undefined,
219
- undefined
220
- );
221
-
222
- export default __vue_component__;