@gitlab/ui 72.11.0 → 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 (225) hide show
  1. package/CHANGELOG.md +14 -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/directives/safe_html/safe_html.js +5 -0
  10. package/src/directives/safe_html/safe_html.spec.js +17 -0
  11. package/src/internal/color_contrast/color_contrast.md +8 -0
  12. package/src/internal/color_contrast/color_contrast.spec.js +34 -0
  13. package/src/internal/color_contrast/color_contrast.stories.js +41 -0
  14. package/src/internal/color_contrast/color_contrast.vue +52 -0
  15. package/src/tokens/color.dark.tokens.stories.js +36 -22
  16. package/src/tokens/color.data_viz.dark.tokens.stories.js +13 -30
  17. package/src/tokens/color.data_viz.tokens.stories.js +13 -30
  18. package/src/tokens/color.theme.dark.tokens.stories.js +15 -30
  19. package/src/tokens/color.theme.tokens.stories.js +15 -30
  20. package/src/tokens/color.tokens.stories.js +36 -22
  21. package/src/tokens/color.transparency.tokens.stories.js +9 -12
  22. package/src/tokens/common_story_options.js +22 -80
  23. package/src/utils/constants.js +25 -0
  24. package/src/utils/utils.js +21 -1
  25. package/dist/charts.js +0 -14
  26. package/dist/components/base/accordion/accordion.js +0 -73
  27. package/dist/components/base/accordion/accordion_item.js +0 -133
  28. package/dist/components/base/alert/alert.js +0 -222
  29. package/dist/components/base/avatar/avatar.js +0 -160
  30. package/dist/components/base/avatar_labeled/avatar_labeled.js +0 -107
  31. package/dist/components/base/avatar_link/avatar_link.js +0 -47
  32. package/dist/components/base/avatars_inline/avatars_inline.js +0 -119
  33. package/dist/components/base/badge/badge.js +0 -105
  34. package/dist/components/base/banner/banner.js +0 -139
  35. package/dist/components/base/breadcrumb/breadcrumb.js +0 -122
  36. package/dist/components/base/breadcrumb/breadcrumb_item.js +0 -73
  37. package/dist/components/base/broadcast_message/broadcast_message.js +0 -112
  38. package/dist/components/base/broadcast_message/constants.js +0 -5
  39. package/dist/components/base/button/button.js +0 -151
  40. package/dist/components/base/button_group/button_group.js +0 -47
  41. package/dist/components/base/card/card.js +0 -71
  42. package/dist/components/base/carousel/carousel.js +0 -48
  43. package/dist/components/base/carousel/carousel_slide.js +0 -47
  44. package/dist/components/base/collapse/collapse.js +0 -59
  45. package/dist/components/base/datepicker/datepicker.js +0 -386
  46. package/dist/components/base/daterange_picker/daterange_picker.js +0 -288
  47. package/dist/components/base/drawer/drawer.js +0 -127
  48. package/dist/components/base/dropdown/dropdown.js +0 -261
  49. package/dist/components/base/dropdown/dropdown_divider.js +0 -48
  50. package/dist/components/base/dropdown/dropdown_form.js +0 -48
  51. package/dist/components/base/dropdown/dropdown_item.js +0 -131
  52. package/dist/components/base/dropdown/dropdown_section_header.js +0 -48
  53. package/dist/components/base/dropdown/dropdown_text.js +0 -48
  54. package/dist/components/base/filtered_search/common_story_options.js +0 -14
  55. package/dist/components/base/filtered_search/filtered_search.js +0 -388
  56. package/dist/components/base/filtered_search/filtered_search_suggestion.js +0 -89
  57. package/dist/components/base/filtered_search/filtered_search_suggestion_list.js +0 -138
  58. package/dist/components/base/filtered_search/filtered_search_term.js +0 -203
  59. package/dist/components/base/filtered_search/filtered_search_token.js +0 -384
  60. package/dist/components/base/filtered_search/filtered_search_token_segment.js +0 -420
  61. package/dist/components/base/filtered_search/filtered_search_utils.js +0 -242
  62. package/dist/components/base/form/form.js +0 -49
  63. package/dist/components/base/form/form_checkbox/form_checkbox.js +0 -78
  64. package/dist/components/base/form/form_checkbox/form_checkbox_group.js +0 -60
  65. package/dist/components/base/form/form_checkbox_tree/checkbox_tree_node.js +0 -79
  66. package/dist/components/base/form/form_checkbox_tree/form_checkbox_tree.js +0 -138
  67. package/dist/components/base/form/form_checkbox_tree/models/constants.js +0 -12
  68. package/dist/components/base/form/form_checkbox_tree/models/node.js +0 -51
  69. package/dist/components/base/form/form_checkbox_tree/models/tree.js +0 -199
  70. package/dist/components/base/form/form_combobox/constants.js +0 -55
  71. package/dist/components/base/form/form_combobox/form_combobox.js +0 -230
  72. package/dist/components/base/form/form_date/form_date.js +0 -143
  73. package/dist/components/base/form/form_fields/form_field_validator.js +0 -93
  74. package/dist/components/base/form/form_fields/form_fields.js +0 -214
  75. package/dist/components/base/form/form_fields/mappers.js +0 -13
  76. package/dist/components/base/form/form_fields/validators.js +0 -48
  77. package/dist/components/base/form/form_group/form_group.js +0 -97
  78. package/dist/components/base/form/form_input/form_input.js +0 -121
  79. package/dist/components/base/form/form_input_group/form_input_group.js +0 -108
  80. package/dist/components/base/form/form_input_group/form_input_group_mixin.js +0 -41
  81. package/dist/components/base/form/form_radio/form_radio.js +0 -65
  82. package/dist/components/base/form/form_radio_group/form_radio_group.js +0 -78
  83. package/dist/components/base/form/form_select/constants.js +0 -12
  84. package/dist/components/base/form/form_select/form_select.js +0 -82
  85. package/dist/components/base/form/form_text/form_text.js +0 -38
  86. package/dist/components/base/form/form_textarea/form_textarea.js +0 -112
  87. package/dist/components/base/form/input_group_text/input_group_text.js +0 -48
  88. package/dist/components/base/icon/icon.js +0 -111
  89. package/dist/components/base/infinite_scroll/infinite_scroll.js +0 -197
  90. package/dist/components/base/keyset_pagination/keyset_pagination.js +0 -151
  91. package/dist/components/base/label/label.js +0 -163
  92. package/dist/components/base/link/link.js +0 -50
  93. package/dist/components/base/loading_icon/loading_icon.js +0 -111
  94. package/dist/components/base/markdown/markdown.js +0 -52
  95. package/dist/components/base/modal/modal.js +0 -204
  96. package/dist/components/base/nav/nav.js +0 -48
  97. package/dist/components/base/nav/nav_item.js +0 -48
  98. package/dist/components/base/nav/nav_item_dropdown.js +0 -62
  99. package/dist/components/base/navbar/navbar.js +0 -48
  100. package/dist/components/base/new_dropdowns/base_dropdown/base_dropdown.js +0 -453
  101. package/dist/components/base/new_dropdowns/base_dropdown/constants.js +0 -4
  102. package/dist/components/base/new_dropdowns/constants.js +0 -21
  103. package/dist/components/base/new_dropdowns/disclosure/constants.js +0 -8
  104. package/dist/components/base/new_dropdowns/disclosure/disclosure_dropdown.js +0 -370
  105. package/dist/components/base/new_dropdowns/disclosure/disclosure_dropdown_group.js +0 -110
  106. package/dist/components/base/new_dropdowns/disclosure/disclosure_dropdown_item.js +0 -143
  107. package/dist/components/base/new_dropdowns/disclosure/mock_data.js +0 -147
  108. package/dist/components/base/new_dropdowns/disclosure/utils.js +0 -39
  109. package/dist/components/base/new_dropdowns/listbox/listbox.js +0 -767
  110. package/dist/components/base/new_dropdowns/listbox/listbox_group.js +0 -58
  111. package/dist/components/base/new_dropdowns/listbox/listbox_item.js +0 -91
  112. package/dist/components/base/new_dropdowns/listbox/listbox_search_input.js +0 -93
  113. package/dist/components/base/new_dropdowns/listbox/mock_data.js +0 -118
  114. package/dist/components/base/new_dropdowns/listbox/utils.js +0 -34
  115. package/dist/components/base/paginated_list/paginated_list.js +0 -180
  116. package/dist/components/base/pagination/pagination.js +0 -399
  117. package/dist/components/base/path/data.js +0 -34
  118. package/dist/components/base/path/path.js +0 -189
  119. package/dist/components/base/popover/popover.js +0 -110
  120. package/dist/components/base/progress_bar/progress_bar.js +0 -48
  121. package/dist/components/base/search_box_by_click/search_box_by_click.js +0 -235
  122. package/dist/components/base/search_box_by_type/search_box_by_type.js +0 -167
  123. package/dist/components/base/segmented_control/segmented_control.js +0 -109
  124. package/dist/components/base/skeleton_loader/skeleton_loader.js +0 -224
  125. package/dist/components/base/sorting/sorting.js +0 -171
  126. package/dist/components/base/sorting/sorting_item.js +0 -109
  127. package/dist/components/base/table/constants.js +0 -5
  128. package/dist/components/base/table/table.js +0 -89
  129. package/dist/components/base/table_lite/table_lite.js +0 -72
  130. package/dist/components/base/tabs/constants.js +0 -3
  131. package/dist/components/base/tabs/tab/tab.js +0 -83
  132. package/dist/components/base/tabs/tabs/scrollable_tabs.js +0 -143
  133. package/dist/components/base/tabs/tabs/tabs.js +0 -224
  134. package/dist/components/base/toast/toast.js +0 -82
  135. package/dist/components/base/toggle/toggle.js +0 -180
  136. package/dist/components/base/token/token.js +0 -85
  137. package/dist/components/base/token_selector/helpers.js +0 -5
  138. package/dist/components/base/token_selector/token_container.js +0 -165
  139. package/dist/components/base/token_selector/token_selector.js +0 -403
  140. package/dist/components/base/token_selector/token_selector_dropdown.js +0 -199
  141. package/dist/components/base/tooltip/tooltip.js +0 -55
  142. package/dist/components/charts/area/area.js +0 -311
  143. package/dist/components/charts/bar/bar.js +0 -253
  144. package/dist/components/charts/chart/chart.js +0 -215
  145. package/dist/components/charts/column/column.js +0 -226
  146. package/dist/components/charts/discrete_scatter/discrete_scatter.js +0 -203
  147. package/dist/components/charts/gauge/gauge.js +0 -208
  148. package/dist/components/charts/heatmap/heatmap.js +0 -295
  149. package/dist/components/charts/heatmap/index.js +0 -2
  150. package/dist/components/charts/legend/legend.js +0 -228
  151. package/dist/components/charts/line/line.js +0 -308
  152. package/dist/components/charts/series_label/series_label.js +0 -100
  153. package/dist/components/charts/single_stat/single_stat.js +0 -152
  154. package/dist/components/charts/sparkline/sparkline.js +0 -261
  155. package/dist/components/charts/stacked_column/stacked_column.js +0 -335
  156. package/dist/components/charts/tooltip/tooltip.js +0 -251
  157. package/dist/components/experimental/duo/chat/components/duo_chat_conversation/duo_chat_conversation.js +0 -83
  158. package/dist/components/experimental/duo/chat/components/duo_chat_loader/duo_chat_loader.js +0 -100
  159. package/dist/components/experimental/duo/chat/components/duo_chat_message/copy_code_element.js +0 -35
  160. package/dist/components/experimental/duo/chat/components/duo_chat_message/duo_chat_message.js +0 -115
  161. package/dist/components/experimental/duo/chat/components/duo_chat_message_sources/duo_chat_message_sources.js +0 -104
  162. package/dist/components/experimental/duo/chat/components/duo_chat_predefined_prompts/duo_chat_predefined_prompts.js +0 -64
  163. package/dist/components/experimental/duo/chat/constants.js +0 -23
  164. package/dist/components/experimental/duo/chat/duo_chat.js +0 -359
  165. package/dist/components/experimental/duo/chat/mock_data.js +0 -83
  166. package/dist/components/experimental/duo/user_feedback/user_feedback.js +0 -94
  167. package/dist/components/experimental/duo/user_feedback/user_feedback_modal.js +0 -124
  168. package/dist/components/experimental/experiment_badge/constants.js +0 -4
  169. package/dist/components/experimental/experiment_badge/experiment_badge.js +0 -107
  170. package/dist/components/mixins/button_mixin.js +0 -11
  171. package/dist/components/mixins/safe_link_mixin.js +0 -30
  172. package/dist/components/mixins/tooltip_mixin.js +0 -21
  173. package/dist/components/regions/dashboard_skeleton/dashboard_skeleton.js +0 -53
  174. package/dist/components/regions/empty_state/empty_state.js +0 -154
  175. package/dist/components/shared_components/charts/tooltip_default_format.js +0 -53
  176. package/dist/components/shared_components/clear_icon_button/clear_icon_button.js +0 -64
  177. package/dist/components/shared_components/close_button/close_button.js +0 -54
  178. package/dist/components/utilities/animated_number/animated_number.js +0 -131
  179. package/dist/components/utilities/friendly_wrap/friendly_wrap.js +0 -75
  180. package/dist/components/utilities/intersection_observer/intersection_observer.js +0 -88
  181. package/dist/components/utilities/intersperse/intersperse.js +0 -86
  182. package/dist/components/utilities/sprintf/sprintf.js +0 -172
  183. package/dist/components/utilities/truncate/constants.js +0 -7
  184. package/dist/components/utilities/truncate/truncate.js +0 -111
  185. package/dist/components/utilities/truncate_text/constants.js +0 -7
  186. package/dist/components/utilities/truncate_text/truncate_text.js +0 -146
  187. package/dist/config.js +0 -86
  188. package/dist/directives/collapse_toggle.js +0 -1
  189. package/dist/directives/hover_load/hover_load.js +0 -45
  190. package/dist/directives/modal.js +0 -1
  191. package/dist/directives/outside/get_event_like_time_stamp.js +0 -33
  192. package/dist/directives/outside/outside.js +0 -106
  193. package/dist/directives/resize_observer/resize_observer.js +0 -51
  194. package/dist/directives/safe_html/constants.js +0 -6
  195. package/dist/directives/safe_html/safe_html.js +0 -35
  196. package/dist/directives/safe_link/mock_data.js +0 -10
  197. package/dist/directives/safe_link/safe_link.js +0 -65
  198. package/dist/directives/tooltip.js +0 -1
  199. package/dist/index.css +0 -7
  200. package/dist/index.css.map +0 -1
  201. package/dist/index.js +0 -105
  202. package/dist/tokens/common_story_options.js +0 -109
  203. package/dist/utils/breakpoints.js +0 -20
  204. package/dist/utils/charts/config.js +0 -556
  205. package/dist/utils/charts/constants.js +0 -63
  206. package/dist/utils/charts/mock_data.js +0 -211
  207. package/dist/utils/charts/story_config.js +0 -42
  208. package/dist/utils/charts/theme.js +0 -192
  209. package/dist/utils/charts/utils.js +0 -54
  210. package/dist/utils/constants.js +0 -270
  211. package/dist/utils/data_utils.js +0 -21
  212. package/dist/utils/datetime_utility.js +0 -61
  213. package/dist/utils/i18n.js +0 -15
  214. package/dist/utils/is_slot_empty.js +0 -38
  215. package/dist/utils/number_utils.js +0 -124
  216. package/dist/utils/stories_constants.js +0 -29
  217. package/dist/utils/stories_utils.js +0 -13
  218. package/dist/utils/story_decorators/container.js +0 -16
  219. package/dist/utils/string_utils.js +0 -69
  220. package/dist/utils/svgs/svg_paths.js +0 -7
  221. package/dist/utils/test_utils.js +0 -33
  222. package/dist/utils/use_fake_date.js +0 -29
  223. package/dist/utils/use_mock_intersection_observer.js +0 -108
  224. package/dist/utils/utils.js +0 -177
  225. package/dist/utils.js +0 -5
@@ -1,40 +1,54 @@
1
- import { methods, template } from './common_story_options';
2
- import colorTokens from './color.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 Default = (args, { argTypes }) => ({
10
7
  props: Object.keys(argTypes),
11
- methods,
12
- template,
8
+ ...colorTokenStoryOptions,
13
9
  });
14
10
  Default.args = generateProps({
15
11
  tokens: {
16
- white: colorTokens.white,
17
- black: colorTokens.black,
12
+ white: COMPILED_TOKENS.white,
13
+ black: COMPILED_TOKENS.black,
18
14
  },
19
15
  });
20
16
 
21
- export const Gray = (args, { argTypes }) => ({ props: Object.keys(argTypes), methods, template });
22
- Gray.args = generateProps({ name: 'gray', tokens: colorTokens.gray });
17
+ export const Gray = (args, { argTypes }) => ({
18
+ props: Object.keys(argTypes),
19
+ ...colorTokenStoryOptions,
20
+ });
21
+ Gray.args = generateProps({ tokens: COMPILED_TOKENS.gray });
23
22
 
24
- export const Blue = (args, { argTypes }) => ({ props: Object.keys(argTypes), methods, template });
25
- Blue.args = generateProps({ name: 'blue', tokens: colorTokens.blue });
23
+ export const Blue = (args, { argTypes }) => ({
24
+ props: Object.keys(argTypes),
25
+ ...colorTokenStoryOptions,
26
+ });
27
+ Blue.args = generateProps({ tokens: COMPILED_TOKENS.blue });
26
28
 
27
- export const Green = (args, { argTypes }) => ({ props: Object.keys(argTypes), methods, template });
28
- Green.args = generateProps({ name: 'green', tokens: colorTokens.green });
29
+ export const Green = (args, { argTypes }) => ({
30
+ props: Object.keys(argTypes),
31
+ ...colorTokenStoryOptions,
32
+ });
33
+ Green.args = generateProps({ tokens: COMPILED_TOKENS.green });
29
34
 
30
- export const Orange = (args, { argTypes }) => ({ props: Object.keys(argTypes), methods, template });
31
- Orange.args = generateProps({ name: 'orange', tokens: colorTokens.orange });
35
+ export const Orange = (args, { argTypes }) => ({
36
+ props: Object.keys(argTypes),
37
+ ...colorTokenStoryOptions,
38
+ });
39
+ Orange.args = generateProps({ tokens: COMPILED_TOKENS.orange });
32
40
 
33
- export const Red = (args, { argTypes }) => ({ props: Object.keys(argTypes), methods, template });
34
- Red.args = generateProps({ name: 'red', tokens: colorTokens.red });
41
+ export const Red = (args, { argTypes }) => ({
42
+ props: Object.keys(argTypes),
43
+ ...colorTokenStoryOptions,
44
+ });
45
+ Red.args = generateProps({ tokens: COMPILED_TOKENS.red });
35
46
 
36
- export const Purple = (args, { argTypes }) => ({ props: Object.keys(argTypes), methods, template });
37
- Purple.args = generateProps({ name: 'purple', tokens: colorTokens.purple });
47
+ export const Purple = (args, { argTypes }) => ({
48
+ props: Object.keys(argTypes),
49
+ ...colorTokenStoryOptions,
50
+ });
51
+ Purple.args = generateProps({ tokens: COMPILED_TOKENS.purple });
38
52
 
39
53
  // eslint-disable-next-line storybook/csf-component
40
54
  export default {
@@ -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__;