@gitlab/ui 72.12.0 → 72.12.2
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.
- package/CHANGELOG.md +15 -0
- package/dist/charts.js +14 -0
- package/dist/components/base/accordion/accordion.js +73 -0
- package/dist/components/base/accordion/accordion_item.js +133 -0
- package/dist/components/base/alert/alert.js +222 -0
- package/dist/components/base/avatar/avatar.js +160 -0
- package/dist/components/base/avatar_labeled/avatar_labeled.js +107 -0
- package/dist/components/base/avatar_link/avatar_link.js +47 -0
- package/dist/components/base/avatars_inline/avatars_inline.js +119 -0
- package/dist/components/base/badge/badge.js +105 -0
- package/dist/components/base/banner/banner.js +139 -0
- package/dist/components/base/breadcrumb/breadcrumb.js +122 -0
- package/dist/components/base/breadcrumb/breadcrumb_item.js +73 -0
- package/dist/components/base/broadcast_message/broadcast_message.js +112 -0
- package/dist/components/base/broadcast_message/constants.js +5 -0
- package/dist/components/base/button/button.js +151 -0
- package/dist/components/base/button_group/button_group.js +47 -0
- package/dist/components/base/card/card.js +71 -0
- package/dist/components/base/carousel/carousel.js +48 -0
- package/dist/components/base/carousel/carousel_slide.js +47 -0
- package/dist/components/base/collapse/collapse.js +59 -0
- package/dist/components/base/datepicker/datepicker.js +386 -0
- package/dist/components/base/daterange_picker/daterange_picker.js +288 -0
- package/dist/components/base/drawer/drawer.js +127 -0
- package/dist/components/base/dropdown/dropdown.js +261 -0
- package/dist/components/base/dropdown/dropdown_divider.js +48 -0
- package/dist/components/base/dropdown/dropdown_form.js +48 -0
- package/dist/components/base/dropdown/dropdown_item.js +131 -0
- package/dist/components/base/dropdown/dropdown_section_header.js +48 -0
- package/dist/components/base/dropdown/dropdown_text.js +48 -0
- package/dist/components/base/filtered_search/common_story_options.js +14 -0
- package/dist/components/base/filtered_search/filtered_search.js +388 -0
- package/dist/components/base/filtered_search/filtered_search_suggestion.js +89 -0
- package/dist/components/base/filtered_search/filtered_search_suggestion_list.js +138 -0
- package/dist/components/base/filtered_search/filtered_search_term.js +203 -0
- package/dist/components/base/filtered_search/filtered_search_token.js +384 -0
- package/dist/components/base/filtered_search/filtered_search_token_segment.js +420 -0
- package/dist/components/base/filtered_search/filtered_search_utils.js +242 -0
- package/dist/components/base/form/form.js +49 -0
- package/dist/components/base/form/form_checkbox/form_checkbox.js +78 -0
- package/dist/components/base/form/form_checkbox/form_checkbox_group.js +60 -0
- package/dist/components/base/form/form_checkbox_tree/checkbox_tree_node.js +79 -0
- package/dist/components/base/form/form_checkbox_tree/form_checkbox_tree.js +138 -0
- package/dist/components/base/form/form_checkbox_tree/models/constants.js +12 -0
- package/dist/components/base/form/form_checkbox_tree/models/node.js +51 -0
- package/dist/components/base/form/form_checkbox_tree/models/tree.js +199 -0
- package/dist/components/base/form/form_combobox/constants.js +55 -0
- package/dist/components/base/form/form_combobox/form_combobox.js +230 -0
- package/dist/components/base/form/form_date/form_date.js +143 -0
- package/dist/components/base/form/form_fields/form_field_validator.js +93 -0
- package/dist/components/base/form/form_fields/form_fields.js +214 -0
- package/dist/components/base/form/form_fields/mappers.js +13 -0
- package/dist/components/base/form/form_fields/validators.js +48 -0
- package/dist/components/base/form/form_group/form_group.js +97 -0
- package/dist/components/base/form/form_input/form_input.js +121 -0
- package/dist/components/base/form/form_input_group/form_input_group.js +108 -0
- package/dist/components/base/form/form_input_group/form_input_group_mixin.js +41 -0
- package/dist/components/base/form/form_radio/form_radio.js +65 -0
- package/dist/components/base/form/form_radio_group/form_radio_group.js +78 -0
- package/dist/components/base/form/form_select/constants.js +12 -0
- package/dist/components/base/form/form_select/form_select.js +82 -0
- package/dist/components/base/form/form_text/form_text.js +38 -0
- package/dist/components/base/form/form_textarea/form_textarea.js +112 -0
- package/dist/components/base/form/input_group_text/input_group_text.js +48 -0
- package/dist/components/base/icon/icon.js +111 -0
- package/dist/components/base/infinite_scroll/infinite_scroll.js +197 -0
- package/dist/components/base/keyset_pagination/keyset_pagination.js +151 -0
- package/dist/components/base/label/label.js +163 -0
- package/dist/components/base/link/link.js +50 -0
- package/dist/components/base/loading_icon/loading_icon.js +111 -0
- package/dist/components/base/markdown/markdown.js +52 -0
- package/dist/components/base/modal/modal.js +204 -0
- package/dist/components/base/nav/nav.js +48 -0
- package/dist/components/base/nav/nav_item.js +48 -0
- package/dist/components/base/nav/nav_item_dropdown.js +62 -0
- package/dist/components/base/navbar/navbar.js +48 -0
- package/dist/components/base/new_dropdowns/base_dropdown/base_dropdown.js +453 -0
- package/dist/components/base/new_dropdowns/base_dropdown/constants.js +4 -0
- package/dist/components/base/new_dropdowns/constants.js +21 -0
- package/dist/components/base/new_dropdowns/disclosure/constants.js +8 -0
- package/dist/components/base/new_dropdowns/disclosure/disclosure_dropdown.js +370 -0
- package/dist/components/base/new_dropdowns/disclosure/disclosure_dropdown_group.js +110 -0
- package/dist/components/base/new_dropdowns/disclosure/disclosure_dropdown_item.js +143 -0
- package/dist/components/base/new_dropdowns/disclosure/mock_data.js +147 -0
- package/dist/components/base/new_dropdowns/disclosure/utils.js +39 -0
- package/dist/components/base/new_dropdowns/listbox/listbox.js +767 -0
- package/dist/components/base/new_dropdowns/listbox/listbox_group.js +58 -0
- package/dist/components/base/new_dropdowns/listbox/listbox_item.js +91 -0
- package/dist/components/base/new_dropdowns/listbox/listbox_search_input.js +93 -0
- package/dist/components/base/new_dropdowns/listbox/mock_data.js +118 -0
- package/dist/components/base/new_dropdowns/listbox/utils.js +34 -0
- package/dist/components/base/paginated_list/paginated_list.js +180 -0
- package/dist/components/base/pagination/pagination.js +399 -0
- package/dist/components/base/path/data.js +34 -0
- package/dist/components/base/path/path.js +189 -0
- package/dist/components/base/popover/popover.js +110 -0
- package/dist/components/base/progress_bar/progress_bar.js +48 -0
- package/dist/components/base/search_box_by_click/search_box_by_click.js +235 -0
- package/dist/components/base/search_box_by_type/search_box_by_type.js +167 -0
- package/dist/components/base/segmented_control/segmented_control.js +109 -0
- package/dist/components/base/skeleton_loader/skeleton_loader.js +224 -0
- package/dist/components/base/sorting/sorting.js +171 -0
- package/dist/components/base/sorting/sorting_item.js +109 -0
- package/dist/components/base/table/constants.js +5 -0
- package/dist/components/base/table/table.js +89 -0
- package/dist/components/base/table_lite/table_lite.js +72 -0
- package/dist/components/base/tabs/constants.js +3 -0
- package/dist/components/base/tabs/tab/tab.js +83 -0
- package/dist/components/base/tabs/tabs/scrollable_tabs.js +143 -0
- package/dist/components/base/tabs/tabs/tabs.js +224 -0
- package/dist/components/base/toast/toast.js +82 -0
- package/dist/components/base/toggle/toggle.js +180 -0
- package/dist/components/base/token/token.js +85 -0
- package/dist/components/base/token_selector/helpers.js +5 -0
- package/dist/components/base/token_selector/token_container.js +165 -0
- package/dist/components/base/token_selector/token_selector.js +403 -0
- package/dist/components/base/token_selector/token_selector_dropdown.js +199 -0
- package/dist/components/base/tooltip/tooltip.js +55 -0
- package/dist/components/charts/area/area.js +311 -0
- package/dist/components/charts/bar/bar.js +253 -0
- package/dist/components/charts/chart/chart.js +215 -0
- package/dist/components/charts/column/column.js +226 -0
- package/dist/components/charts/discrete_scatter/discrete_scatter.js +203 -0
- package/dist/components/charts/gauge/gauge.js +208 -0
- package/dist/components/charts/heatmap/heatmap.js +295 -0
- package/dist/components/charts/heatmap/index.js +2 -0
- package/dist/components/charts/legend/legend.js +228 -0
- package/dist/components/charts/line/line.js +308 -0
- package/dist/components/charts/series_label/series_label.js +100 -0
- package/dist/components/charts/single_stat/single_stat.js +152 -0
- package/dist/components/charts/sparkline/sparkline.js +261 -0
- package/dist/components/charts/stacked_column/stacked_column.js +335 -0
- package/dist/components/charts/tooltip/tooltip.js +251 -0
- package/dist/components/experimental/duo/chat/components/duo_chat_conversation/duo_chat_conversation.js +83 -0
- package/dist/components/experimental/duo/chat/components/duo_chat_loader/duo_chat_loader.js +100 -0
- package/dist/components/experimental/duo/chat/components/duo_chat_message/copy_code_element.js +35 -0
- package/dist/components/experimental/duo/chat/components/duo_chat_message/duo_chat_message.js +115 -0
- package/dist/components/experimental/duo/chat/components/duo_chat_message_sources/duo_chat_message_sources.js +104 -0
- package/dist/components/experimental/duo/chat/components/duo_chat_predefined_prompts/duo_chat_predefined_prompts.js +64 -0
- package/dist/components/experimental/duo/chat/constants.js +23 -0
- package/dist/components/experimental/duo/chat/duo_chat.js +359 -0
- package/dist/components/experimental/duo/chat/mock_data.js +83 -0
- package/dist/components/experimental/duo/user_feedback/user_feedback.js +94 -0
- package/dist/components/experimental/duo/user_feedback/user_feedback_modal.js +124 -0
- package/dist/components/experimental/experiment_badge/constants.js +4 -0
- package/dist/components/experimental/experiment_badge/experiment_badge.js +107 -0
- package/dist/components/mixins/button_mixin.js +11 -0
- package/dist/components/mixins/safe_link_mixin.js +30 -0
- package/dist/components/mixins/tooltip_mixin.js +21 -0
- package/dist/components/regions/dashboard_skeleton/dashboard_skeleton.js +53 -0
- package/dist/components/regions/empty_state/empty_state.js +154 -0
- package/dist/components/shared_components/charts/tooltip_default_format.js +53 -0
- package/dist/components/shared_components/clear_icon_button/clear_icon_button.js +64 -0
- package/dist/components/shared_components/close_button/close_button.js +54 -0
- package/dist/components/utilities/animated_number/animated_number.js +131 -0
- package/dist/components/utilities/friendly_wrap/friendly_wrap.js +75 -0
- package/dist/components/utilities/intersection_observer/intersection_observer.js +88 -0
- package/dist/components/utilities/intersperse/intersperse.js +86 -0
- package/dist/components/utilities/sprintf/sprintf.js +172 -0
- package/dist/components/utilities/truncate/constants.js +7 -0
- package/dist/components/utilities/truncate/truncate.js +111 -0
- package/dist/components/utilities/truncate_text/constants.js +7 -0
- package/dist/components/utilities/truncate_text/truncate_text.js +146 -0
- package/dist/config.js +86 -0
- package/dist/directives/collapse_toggle.js +1 -0
- package/dist/directives/hover_load/hover_load.js +45 -0
- package/dist/directives/modal.js +1 -0
- package/dist/directives/outside/get_event_like_time_stamp.js +33 -0
- package/dist/directives/outside/outside.js +106 -0
- package/dist/directives/resize_observer/resize_observer.js +51 -0
- package/dist/directives/safe_html/constants.js +6 -0
- package/dist/directives/safe_html/safe_html.js +39 -0
- package/dist/directives/safe_link/mock_data.js +10 -0
- package/dist/directives/safe_link/safe_link.js +65 -0
- package/dist/directives/tooltip.js +1 -0
- package/dist/index.css +7 -0
- package/dist/index.css.map +1 -0
- package/dist/index.js +105 -0
- package/dist/tokens/common_story_options.js +54 -0
- package/dist/tokens/css/tokens.css +1 -1
- package/dist/tokens/css/tokens.dark.css +1 -1
- package/dist/tokens/js/tokens.dark.js +1 -1
- package/dist/tokens/js/tokens.js +1 -1
- package/dist/tokens/scss/_tokens.dark.scss +1 -1
- package/dist/tokens/scss/_tokens.scss +1 -1
- package/dist/utility_classes.css +1 -1
- package/dist/utility_classes.css.map +1 -1
- package/dist/utils/breakpoints.js +20 -0
- package/dist/utils/charts/config.js +556 -0
- package/dist/utils/charts/constants.js +63 -0
- package/dist/utils/charts/mock_data.js +211 -0
- package/dist/utils/charts/story_config.js +42 -0
- package/dist/utils/charts/theme.js +192 -0
- package/dist/utils/charts/utils.js +54 -0
- package/dist/utils/constants.js +288 -0
- package/dist/utils/data_utils.js +21 -0
- package/dist/utils/datetime_utility.js +61 -0
- package/dist/utils/i18n.js +15 -0
- package/dist/utils/is_slot_empty.js +38 -0
- package/dist/utils/number_utils.js +124 -0
- package/dist/utils/stories_constants.js +29 -0
- package/dist/utils/stories_utils.js +13 -0
- package/dist/utils/story_decorators/container.js +16 -0
- package/dist/utils/string_utils.js +69 -0
- package/dist/utils/svgs/svg_paths.js +7 -0
- package/dist/utils/test_utils.js +33 -0
- package/dist/utils/use_fake_date.js +29 -0
- package/dist/utils/use_mock_intersection_observer.js +108 -0
- package/dist/utils/utils.js +197 -0
- package/dist/utils.js +5 -0
- package/package.json +1 -1
- package/src/components/base/new_dropdowns/listbox/listbox.vue +0 -1
- package/src/scss/utilities.scss +8 -8
- package/src/scss/utility-mixins/typography.scss +4 -4
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wrapper around setTimeout which executes immediately in visual tests
|
|
3
|
+
* in order to avoid flaky tests
|
|
4
|
+
*/
|
|
5
|
+
function setStoryTimeout(fn, timeout) {
|
|
6
|
+
return setTimeout(fn, process.env.IS_VISUAL_TEST ? 0 : timeout);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// adopted this method from Bootstraps utils
|
|
10
|
+
// https://github.com/bootstrap-vue/bootstrap-vue/blob/2fd03f0b1d0cc41f9930078ba8b1c16b10e4ac2f/tests/utils.js#L6
|
|
11
|
+
const waitForAnimationFrame = () => new Promise(resolve => {
|
|
12
|
+
requestAnimationFrame(resolve);
|
|
13
|
+
});
|
|
14
|
+
const getResetAnimationsCSS = () => `
|
|
15
|
+
*, *::after, *::before {
|
|
16
|
+
-webkit-transition: none !important;
|
|
17
|
+
-moz-transition: none !important;
|
|
18
|
+
-ms-transition: none !important;
|
|
19
|
+
-o-transition: none !important;
|
|
20
|
+
transition: none !important;
|
|
21
|
+
|
|
22
|
+
-webkit-animation: none !important;
|
|
23
|
+
-moz-animation: none !important;
|
|
24
|
+
-ms-animation: none !important;
|
|
25
|
+
-o-animation: none !important;
|
|
26
|
+
animation: none !important;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
input, textarea {
|
|
30
|
+
caret-color: transparent !important;
|
|
31
|
+
}`;
|
|
32
|
+
|
|
33
|
+
export { getResetAnimationsCSS, setStoryTimeout, waitForAnimationFrame };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import MockDate from 'mockdate';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* When applied to a story, this mixin mocks the current date to make
|
|
5
|
+
* visual tests that rely on the date deterministic
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
*
|
|
9
|
+
* import { useFakeDate } from '../../../../tests/utils/use_fake_date';
|
|
10
|
+
* documentedStoriesOf('some|story')
|
|
11
|
+
* .add('default', () => ({
|
|
12
|
+
* mixins: [useFakeDate()],
|
|
13
|
+
* })
|
|
14
|
+
*/
|
|
15
|
+
const useFakeDate = () => {
|
|
16
|
+
if (process.env.IS_VISUAL_TEST) {
|
|
17
|
+
return {
|
|
18
|
+
created() {
|
|
19
|
+
MockDate.set('2020-01-10', 0);
|
|
20
|
+
},
|
|
21
|
+
destroyed() {
|
|
22
|
+
MockDate.reset();
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
return {};
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export { useFakeDate };
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import isMatch from 'lodash/isMatch';
|
|
2
|
+
|
|
3
|
+
/* global jest, beforeEach, afterEach */
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* This class gives us a JSDom friendly DOM observer which we can manually trigger in tests
|
|
7
|
+
*
|
|
8
|
+
* Use this in place of MutationObserver or IntersectionObserver
|
|
9
|
+
*
|
|
10
|
+
* This class is largely influenced from [a test helper][1] in the main GitLab project
|
|
11
|
+
*
|
|
12
|
+
* [1]: https://gitlab.com/gitlab-org/gitlab/blob/a123813c63147392b95cd03c4744ae9db0575b0f/spec/frontend/helpers/mock_dom_observer.js#L95
|
|
13
|
+
*/
|
|
14
|
+
class MockObserver {
|
|
15
|
+
constructor(cb) {
|
|
16
|
+
this.$_cb = cb;
|
|
17
|
+
this.$_observers = [];
|
|
18
|
+
}
|
|
19
|
+
observe(node) {
|
|
20
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
21
|
+
this.$_observers.push([node, options]);
|
|
22
|
+
}
|
|
23
|
+
disconnect() {
|
|
24
|
+
this.$_observers = [];
|
|
25
|
+
}
|
|
26
|
+
takeRecords() {}
|
|
27
|
+
|
|
28
|
+
// eslint-disable-next-line camelcase
|
|
29
|
+
$_triggerObserve(nodeParam) {
|
|
30
|
+
let {
|
|
31
|
+
entry = {},
|
|
32
|
+
options = {}
|
|
33
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
34
|
+
const nodes = this.$_getNodesFromParam(nodeParam);
|
|
35
|
+
nodes.forEach(node => {
|
|
36
|
+
if (this.$_hasObserver(node, options)) {
|
|
37
|
+
this.$_cb([{
|
|
38
|
+
target: node,
|
|
39
|
+
...entry
|
|
40
|
+
}]);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// eslint-disable-next-line camelcase
|
|
46
|
+
$_hasObserver(node) {
|
|
47
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
48
|
+
return this.$_observers.some(_ref => {
|
|
49
|
+
let [obvNode, obvOptions] = _ref;
|
|
50
|
+
return node === obvNode && isMatch(options, obvOptions);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
$_getNodesFromParam(nodeParam) {
|
|
54
|
+
if (!nodeParam) {
|
|
55
|
+
return this.$_observers.map(_ref2 => {
|
|
56
|
+
let [node] = _ref2;
|
|
57
|
+
return node;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
if (!Array.isArray(nodeParam)) {
|
|
61
|
+
return [nodeParam];
|
|
62
|
+
}
|
|
63
|
+
return nodeParam;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
class MockIntersectionObserver extends MockObserver {
|
|
67
|
+
unobserve(node) {
|
|
68
|
+
this.$_observers = this.$_observers.filter(_ref3 => {
|
|
69
|
+
let [obvNode] = _ref3;
|
|
70
|
+
return node !== obvNode;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const useMockIntersectionObserver = () => {
|
|
75
|
+
let instances;
|
|
76
|
+
let origObserver;
|
|
77
|
+
beforeEach(() => {
|
|
78
|
+
instances = [];
|
|
79
|
+
origObserver = global.IntersectionObserver;
|
|
80
|
+
global.IntersectionObserver = jest.fn().mockImplementation(function () {
|
|
81
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
82
|
+
args[_key] = arguments[_key];
|
|
83
|
+
}
|
|
84
|
+
const mockObserver = new MockIntersectionObserver(...args);
|
|
85
|
+
instances.push(mockObserver);
|
|
86
|
+
return mockObserver;
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
afterEach(() => {
|
|
90
|
+
instances = [];
|
|
91
|
+
global.IntersectionObserver = origObserver;
|
|
92
|
+
});
|
|
93
|
+
const trigger = function (observer) {
|
|
94
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
95
|
+
args[_key2 - 1] = arguments[_key2];
|
|
96
|
+
}
|
|
97
|
+
observer.$_triggerObserve(...args);
|
|
98
|
+
};
|
|
99
|
+
const getInstances = () => {
|
|
100
|
+
return instances;
|
|
101
|
+
};
|
|
102
|
+
return {
|
|
103
|
+
getInstances,
|
|
104
|
+
trigger
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export { useMockIntersectionObserver };
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { isVisible } from 'bootstrap-vue/esm/utils/dom';
|
|
2
|
+
import { COMMA, labelColorOptions, CONTRAST_LEVELS, focusableTags } from './constants';
|
|
3
|
+
|
|
4
|
+
function debounceByAnimationFrame(fn) {
|
|
5
|
+
let requestId;
|
|
6
|
+
return function debounced() {
|
|
7
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
8
|
+
args[_key] = arguments[_key];
|
|
9
|
+
}
|
|
10
|
+
if (requestId) {
|
|
11
|
+
window.cancelAnimationFrame(requestId);
|
|
12
|
+
}
|
|
13
|
+
requestId = window.requestAnimationFrame(() => fn.apply(this, args));
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function throttle(fn) {
|
|
17
|
+
let frameId = null;
|
|
18
|
+
return function () {
|
|
19
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
20
|
+
args[_key2] = arguments[_key2];
|
|
21
|
+
}
|
|
22
|
+
if (frameId) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
frameId = window.requestAnimationFrame(() => {
|
|
26
|
+
fn(...args);
|
|
27
|
+
frameId = null;
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function rgbFromHex(hex) {
|
|
32
|
+
const cleanHex = hex.replace('#', '');
|
|
33
|
+
const rgb = cleanHex.length === 3 ? cleanHex.split('').map(val => val + val) : cleanHex.match(/[\da-f]{2}/gi);
|
|
34
|
+
const [r, g, b] = rgb.map(val => parseInt(val, 16));
|
|
35
|
+
return [r, g, b];
|
|
36
|
+
}
|
|
37
|
+
function rgbFromString(color, sub) {
|
|
38
|
+
const rgb = color.substring(sub, color.length - 1).split(COMMA);
|
|
39
|
+
const [r, g, b] = rgb.map(i => parseInt(i, 10));
|
|
40
|
+
return [r, g, b];
|
|
41
|
+
}
|
|
42
|
+
function hexToRgba(hex) {
|
|
43
|
+
let opacity = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
44
|
+
const [r, g, b] = rgbFromHex(hex);
|
|
45
|
+
return `rgba(${r}, ${g}, ${b}, ${opacity})`;
|
|
46
|
+
}
|
|
47
|
+
function toSrgb(value) {
|
|
48
|
+
const normalized = value / 255;
|
|
49
|
+
return normalized <= 0.03928 ? normalized / 12.92 : ((normalized + 0.055) / 1.055) ** 2.4;
|
|
50
|
+
}
|
|
51
|
+
function relativeLuminance(rgb) {
|
|
52
|
+
// WCAG 2.1 formula: https://www.w3.org/TR/WCAG21/#dfn-relative-luminance
|
|
53
|
+
// -
|
|
54
|
+
// WCAG 3.0 will use APAC
|
|
55
|
+
// Using APAC would be the ultimate goal, but was dismissed by engineering as of now
|
|
56
|
+
// See https://gitlab.com/gitlab-org/gitlab-ui/-/merge_requests/3418#note_1370107090
|
|
57
|
+
return 0.2126 * toSrgb(rgb[0]) + 0.7152 * toSrgb(rgb[1]) + 0.0722 * toSrgb(rgb[2]);
|
|
58
|
+
}
|
|
59
|
+
function colorFromBackground(backgroundColor) {
|
|
60
|
+
let contrastRatio = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2.4;
|
|
61
|
+
let color;
|
|
62
|
+
const lightColor = rgbFromHex('#FFFFFF');
|
|
63
|
+
const darkColor = rgbFromHex('#1f1e24');
|
|
64
|
+
if (backgroundColor.startsWith('#')) {
|
|
65
|
+
color = rgbFromHex(backgroundColor);
|
|
66
|
+
} else if (backgroundColor.startsWith('rgba(')) {
|
|
67
|
+
color = rgbFromString(backgroundColor, 5);
|
|
68
|
+
} else if (backgroundColor.startsWith('rgb(')) {
|
|
69
|
+
color = rgbFromString(backgroundColor, 4);
|
|
70
|
+
}
|
|
71
|
+
const luminance = relativeLuminance(color);
|
|
72
|
+
const lightLuminance = relativeLuminance(lightColor);
|
|
73
|
+
const darkLuminance = relativeLuminance(darkColor);
|
|
74
|
+
const contrastLight = (lightLuminance + 0.05) / (luminance + 0.05);
|
|
75
|
+
const contrastDark = (luminance + 0.05) / (darkLuminance + 0.05);
|
|
76
|
+
|
|
77
|
+
// Using a default threshold contrast of 2.4 instead of 3
|
|
78
|
+
// as this will solve weird color combinations in the mid tones
|
|
79
|
+
return contrastLight >= contrastRatio || contrastLight > contrastDark ? labelColorOptions.light : labelColorOptions.dark;
|
|
80
|
+
}
|
|
81
|
+
function getColorContrast(foreground, background) {
|
|
82
|
+
// Formula: http://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef
|
|
83
|
+
const backgroundLuminance = relativeLuminance(rgbFromHex(background)) + 0.05;
|
|
84
|
+
const foregroundLuminance = relativeLuminance(rgbFromHex(foreground)) + 0.05;
|
|
85
|
+
let score = backgroundLuminance / foregroundLuminance;
|
|
86
|
+
if (foregroundLuminance > backgroundLuminance) {
|
|
87
|
+
score = 1 / score;
|
|
88
|
+
}
|
|
89
|
+
const level = CONTRAST_LEVELS.find(_ref => {
|
|
90
|
+
let {
|
|
91
|
+
min,
|
|
92
|
+
max
|
|
93
|
+
} = _ref;
|
|
94
|
+
return score >= min && score < max;
|
|
95
|
+
});
|
|
96
|
+
return {
|
|
97
|
+
score: (Math.round(score * 10) / 10).toFixed(1),
|
|
98
|
+
level
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
function uid() {
|
|
102
|
+
return Math.random().toString(36).substring(2);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Receives an element and validates that it can be focused
|
|
107
|
+
* @param { HTMLElement } The element we want to validate
|
|
108
|
+
* @return { boolean } Is the element focusable
|
|
109
|
+
*/
|
|
110
|
+
|
|
111
|
+
function isElementFocusable(elt) {
|
|
112
|
+
if (!elt) return false;
|
|
113
|
+
const {
|
|
114
|
+
tagName
|
|
115
|
+
} = elt;
|
|
116
|
+
const isValidTag = focusableTags.includes(tagName);
|
|
117
|
+
const hasValidType = elt.getAttribute('type') !== 'hidden';
|
|
118
|
+
const isDisabled = elt.getAttribute('disabled') === '' || elt.getAttribute('disabled');
|
|
119
|
+
const hasValidZIndex = elt.getAttribute('z-index') !== '-1';
|
|
120
|
+
const isInvalidAnchorTag = tagName === 'A' && !elt.getAttribute('href');
|
|
121
|
+
return isValidTag && hasValidType && !isDisabled && hasValidZIndex && !isInvalidAnchorTag;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Receives an element and validates that it is reachable via sequential keyboard navigation
|
|
126
|
+
* @param { HTMLElement } The element to validate
|
|
127
|
+
* @return { boolean } Is the element focusable in a sequential tab order
|
|
128
|
+
*/
|
|
129
|
+
|
|
130
|
+
function isElementTabbable(el) {
|
|
131
|
+
if (!el) return false;
|
|
132
|
+
const tabindex = parseInt(el.getAttribute('tabindex'), 10);
|
|
133
|
+
return tabindex > -1;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Receives an array of HTML elements and focus the first one possible
|
|
138
|
+
* @param { Array.<HTMLElement> } An array of element to potentially focus
|
|
139
|
+
* @return { undefined }
|
|
140
|
+
*/
|
|
141
|
+
|
|
142
|
+
function focusFirstFocusableElement(elts) {
|
|
143
|
+
const focusableElt = elts.find(el => isElementFocusable(el));
|
|
144
|
+
if (focusableElt) focusableElt.focus();
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Returns true if the current environment is considered a development environment (it's not
|
|
149
|
+
* production or test).
|
|
150
|
+
*
|
|
151
|
+
* @returns {boolean}
|
|
152
|
+
*/
|
|
153
|
+
function isDev() {
|
|
154
|
+
return !['test', 'production'].includes(process.env.NODE_ENV);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Prints a warning message to the console in non-test and non-production environments.
|
|
159
|
+
* @param {string} message message to print to the console
|
|
160
|
+
* @param {HTMLElement} element component that triggered the warning
|
|
161
|
+
*/
|
|
162
|
+
function logWarning() {
|
|
163
|
+
let message = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
164
|
+
let element = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
165
|
+
if (message.length && isDev()) {
|
|
166
|
+
console.warn(message, element); // eslint-disable-line no-console
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Stop default event handling and propagation
|
|
172
|
+
*/
|
|
173
|
+
function stopEvent(event) {
|
|
174
|
+
let {
|
|
175
|
+
preventDefault = true,
|
|
176
|
+
stopPropagation = true,
|
|
177
|
+
stopImmediatePropagation = false
|
|
178
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
179
|
+
if (preventDefault) {
|
|
180
|
+
event.preventDefault();
|
|
181
|
+
}
|
|
182
|
+
if (stopPropagation) {
|
|
183
|
+
event.stopPropagation();
|
|
184
|
+
}
|
|
185
|
+
if (stopImmediatePropagation) {
|
|
186
|
+
event.stopImmediatePropagation();
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Return an Array of visible items
|
|
192
|
+
*/
|
|
193
|
+
function filterVisible(els) {
|
|
194
|
+
return (els || []).filter(el => isVisible(el));
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export { colorFromBackground, debounceByAnimationFrame, filterVisible, focusFirstFocusableElement, getColorContrast, hexToRgba, isDev, isElementFocusable, isElementTabbable, logWarning, relativeLuminance, rgbFromHex, rgbFromString, stopEvent, throttle, toSrgb, uid };
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { GlBreakpointInstance, breakpoints } from './utils/breakpoints';
|
|
2
|
+
import * as validators from './components/base/form/form_fields/validators';
|
|
3
|
+
export { validators as formValidators };
|
|
4
|
+
import * as mappers from './components/base/form/form_fields/mappers';
|
|
5
|
+
export { mappers as formMappers };
|
package/package.json
CHANGED
package/src/scss/utilities.scss
CHANGED
|
@@ -8837,42 +8837,42 @@ $gl-animate-skeleton-loader-max-width: 64 * $grid-size;
|
|
|
8837
8837
|
font-style: normal !important;
|
|
8838
8838
|
}
|
|
8839
8839
|
|
|
8840
|
-
.gl-heading-
|
|
8840
|
+
.gl-heading-6{
|
|
8841
8841
|
@include gl-heading-scale-200;
|
|
8842
8842
|
margin-bottom: $gl-mb-heading;
|
|
8843
8843
|
}
|
|
8844
8844
|
|
|
8845
|
-
.gl-heading-
|
|
8845
|
+
.gl-heading-6\!{
|
|
8846
8846
|
@include gl-heading-scale-200;
|
|
8847
8847
|
margin-bottom: $gl-mb-heading !important;
|
|
8848
8848
|
}
|
|
8849
8849
|
|
|
8850
|
-
.gl-heading-
|
|
8850
|
+
.gl-heading-6-fixed{
|
|
8851
8851
|
@include gl-heading-scale-200-fixed;
|
|
8852
8852
|
margin-bottom: $gl-mb-heading;
|
|
8853
8853
|
}
|
|
8854
8854
|
|
|
8855
|
-
.gl-heading-
|
|
8855
|
+
.gl-heading-6-fixed\!{
|
|
8856
8856
|
@include gl-heading-scale-200-fixed;
|
|
8857
8857
|
margin-bottom: $gl-mb-heading !important;
|
|
8858
8858
|
}
|
|
8859
8859
|
|
|
8860
|
-
.gl-heading-
|
|
8860
|
+
.gl-heading-5{
|
|
8861
8861
|
@include gl-heading-scale-300;
|
|
8862
8862
|
margin-bottom: $gl-mb-heading;
|
|
8863
8863
|
}
|
|
8864
8864
|
|
|
8865
|
-
.gl-heading-
|
|
8865
|
+
.gl-heading-5\!{
|
|
8866
8866
|
@include gl-heading-scale-300;
|
|
8867
8867
|
margin-bottom: $gl-mb-heading !important;
|
|
8868
8868
|
}
|
|
8869
8869
|
|
|
8870
|
-
.gl-heading-
|
|
8870
|
+
.gl-heading-5-fixed{
|
|
8871
8871
|
@include gl-heading-scale-300-fixed;
|
|
8872
8872
|
margin-bottom: $gl-mb-heading;
|
|
8873
8873
|
}
|
|
8874
8874
|
|
|
8875
|
-
.gl-heading-
|
|
8875
|
+
.gl-heading-5-fixed\!{
|
|
8876
8876
|
@include gl-heading-scale-300-fixed;
|
|
8877
8877
|
margin-bottom: $gl-mb-heading !important;
|
|
8878
8878
|
}
|
|
@@ -37,22 +37,22 @@
|
|
|
37
37
|
* https://design.gitlab.com/product-foundations/type-fundamentals
|
|
38
38
|
*/
|
|
39
39
|
|
|
40
|
-
@mixin gl-heading-
|
|
40
|
+
@mixin gl-heading-6 {
|
|
41
41
|
@include gl-heading-scale-200;
|
|
42
42
|
margin-bottom: $gl-mb-heading;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
@mixin gl-heading-
|
|
45
|
+
@mixin gl-heading-6-fixed {
|
|
46
46
|
@include gl-heading-scale-200-fixed;
|
|
47
47
|
margin-bottom: $gl-mb-heading;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
@mixin gl-heading-
|
|
50
|
+
@mixin gl-heading-5 {
|
|
51
51
|
@include gl-heading-scale-300;
|
|
52
52
|
margin-bottom: $gl-mb-heading;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
@mixin gl-heading-
|
|
55
|
+
@mixin gl-heading-5-fixed {
|
|
56
56
|
@include gl-heading-scale-300-fixed;
|
|
57
57
|
margin-bottom: $gl-mb-heading;
|
|
58
58
|
}
|