@gitlab/ui 72.12.0 → 72.12.1
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 +7 -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/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
|
@@ -0,0 +1,453 @@
|
|
|
1
|
+
import uniqueId from 'lodash/uniqueId';
|
|
2
|
+
import { offset, autoPlacement, size, autoUpdate, computePosition } from '@floating-ui/dom';
|
|
3
|
+
import { buttonCategoryOptions, dropdownVariantOptions, buttonSizeOptions, dropdownPlacements, dropdownAllowedAutoPlacements } from '../../../../utils/constants';
|
|
4
|
+
import { POSITION_ABSOLUTE, POSITION_FIXED, GL_DROPDOWN_CONTENTS_CLASS, GL_DROPDOWN_BEFORE_CLOSE, GL_DROPDOWN_SHOWN, GL_DROPDOWN_HIDDEN, ENTER, SPACE, ARROW_DOWN, GL_DROPDOWN_FOCUS_CONTENT } from '../constants';
|
|
5
|
+
import { isElementFocusable, isElementTabbable, logWarning } from '../../../../utils/utils';
|
|
6
|
+
import GlButton from '../../button/button';
|
|
7
|
+
import GlIcon from '../../icon/icon';
|
|
8
|
+
import { OutsideDirective } from '../../../../directives/outside/outside';
|
|
9
|
+
import { DEFAULT_OFFSET, FIXED_WIDTH_CLASS } from './constants';
|
|
10
|
+
import __vue_normalize__ from 'vue-runtime-helpers/dist/normalize-component.js';
|
|
11
|
+
|
|
12
|
+
const BASE_DROPDOWN_CLASS = 'gl-new-dropdown';
|
|
13
|
+
var script = {
|
|
14
|
+
name: 'BaseDropdown',
|
|
15
|
+
BASE_DROPDOWN_CLASS,
|
|
16
|
+
components: {
|
|
17
|
+
GlButton,
|
|
18
|
+
GlIcon
|
|
19
|
+
},
|
|
20
|
+
directives: {
|
|
21
|
+
Outside: OutsideDirective
|
|
22
|
+
},
|
|
23
|
+
props: {
|
|
24
|
+
toggleText: {
|
|
25
|
+
type: String,
|
|
26
|
+
required: false,
|
|
27
|
+
default: ''
|
|
28
|
+
},
|
|
29
|
+
textSrOnly: {
|
|
30
|
+
type: Boolean,
|
|
31
|
+
required: false,
|
|
32
|
+
default: false
|
|
33
|
+
},
|
|
34
|
+
block: {
|
|
35
|
+
type: Boolean,
|
|
36
|
+
required: false,
|
|
37
|
+
default: false
|
|
38
|
+
},
|
|
39
|
+
category: {
|
|
40
|
+
type: String,
|
|
41
|
+
required: false,
|
|
42
|
+
default: buttonCategoryOptions.primary,
|
|
43
|
+
validator: value => Object.keys(buttonCategoryOptions).includes(value)
|
|
44
|
+
},
|
|
45
|
+
variant: {
|
|
46
|
+
type: String,
|
|
47
|
+
required: false,
|
|
48
|
+
default: dropdownVariantOptions.default,
|
|
49
|
+
validator: value => Object.keys(dropdownVariantOptions).includes(value)
|
|
50
|
+
},
|
|
51
|
+
size: {
|
|
52
|
+
type: String,
|
|
53
|
+
required: false,
|
|
54
|
+
default: 'medium',
|
|
55
|
+
validator: value => Object.keys(buttonSizeOptions).includes(value)
|
|
56
|
+
},
|
|
57
|
+
icon: {
|
|
58
|
+
type: String,
|
|
59
|
+
required: false,
|
|
60
|
+
default: ''
|
|
61
|
+
},
|
|
62
|
+
disabled: {
|
|
63
|
+
type: Boolean,
|
|
64
|
+
required: false,
|
|
65
|
+
default: false
|
|
66
|
+
},
|
|
67
|
+
loading: {
|
|
68
|
+
type: Boolean,
|
|
69
|
+
required: false,
|
|
70
|
+
default: false
|
|
71
|
+
},
|
|
72
|
+
toggleClass: {
|
|
73
|
+
type: [String, Array, Object],
|
|
74
|
+
required: false,
|
|
75
|
+
default: null
|
|
76
|
+
},
|
|
77
|
+
noCaret: {
|
|
78
|
+
type: Boolean,
|
|
79
|
+
required: false,
|
|
80
|
+
default: false
|
|
81
|
+
},
|
|
82
|
+
placement: {
|
|
83
|
+
type: String,
|
|
84
|
+
required: false,
|
|
85
|
+
default: 'left',
|
|
86
|
+
validator: value => Object.keys(dropdownPlacements).includes(value)
|
|
87
|
+
},
|
|
88
|
+
// ARIA props
|
|
89
|
+
ariaHaspopup: {
|
|
90
|
+
type: [String, Boolean],
|
|
91
|
+
required: false,
|
|
92
|
+
default: false,
|
|
93
|
+
validator: value => {
|
|
94
|
+
return ['menu', 'listbox', 'tree', 'grid', 'dialog', true, false].includes(value);
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
/**
|
|
98
|
+
* Id that will be referenced by `aria-labelledby` attribute of the dropdown content`
|
|
99
|
+
*/
|
|
100
|
+
toggleId: {
|
|
101
|
+
type: String,
|
|
102
|
+
required: true
|
|
103
|
+
},
|
|
104
|
+
/**
|
|
105
|
+
* The `aria-labelledby` attribute value for the toggle `button`
|
|
106
|
+
*/
|
|
107
|
+
ariaLabelledby: {
|
|
108
|
+
type: String,
|
|
109
|
+
required: false,
|
|
110
|
+
default: null
|
|
111
|
+
},
|
|
112
|
+
/**
|
|
113
|
+
* Custom value to be passed to the offset middleware.
|
|
114
|
+
* https://floating-ui.com/docs/offset
|
|
115
|
+
*/
|
|
116
|
+
offset: {
|
|
117
|
+
type: [Number, Object],
|
|
118
|
+
required: false,
|
|
119
|
+
default: () => ({
|
|
120
|
+
mainAxis: DEFAULT_OFFSET
|
|
121
|
+
})
|
|
122
|
+
},
|
|
123
|
+
fluidWidth: {
|
|
124
|
+
type: Boolean,
|
|
125
|
+
required: false,
|
|
126
|
+
default: false
|
|
127
|
+
},
|
|
128
|
+
/**
|
|
129
|
+
* Strategy to be applied by computePosition. If this is set to fixed, the dropdown's position
|
|
130
|
+
* needs to be set to fixed in CSS as well.
|
|
131
|
+
* https://floating-ui.com/docs/computePosition#strategy
|
|
132
|
+
*/
|
|
133
|
+
positioningStrategy: {
|
|
134
|
+
type: String,
|
|
135
|
+
required: false,
|
|
136
|
+
default: POSITION_ABSOLUTE,
|
|
137
|
+
validator: strategy => [POSITION_ABSOLUTE, POSITION_FIXED].includes(strategy)
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
data() {
|
|
141
|
+
return {
|
|
142
|
+
openedYet: false,
|
|
143
|
+
visible: false,
|
|
144
|
+
baseDropdownId: uniqueId('base-dropdown-')
|
|
145
|
+
};
|
|
146
|
+
},
|
|
147
|
+
computed: {
|
|
148
|
+
isIconOnly() {
|
|
149
|
+
var _this$toggleText;
|
|
150
|
+
return Boolean(this.icon && (!((_this$toggleText = this.toggleText) !== null && _this$toggleText !== void 0 && _this$toggleText.length) || this.textSrOnly));
|
|
151
|
+
},
|
|
152
|
+
ariaAttributes() {
|
|
153
|
+
return {
|
|
154
|
+
'aria-haspopup': this.ariaHaspopup,
|
|
155
|
+
'aria-expanded': this.visible,
|
|
156
|
+
'aria-controls': this.baseDropdownId,
|
|
157
|
+
'aria-labelledby': this.toggleLabelledBy
|
|
158
|
+
};
|
|
159
|
+
},
|
|
160
|
+
toggleButtonClasses() {
|
|
161
|
+
return [this.toggleClass, {
|
|
162
|
+
'gl-new-dropdown-toggle': true,
|
|
163
|
+
'gl-new-dropdown-icon-only btn-icon': this.isIconOnly,
|
|
164
|
+
'gl-new-dropdown-toggle-no-caret': this.noCaret
|
|
165
|
+
}];
|
|
166
|
+
},
|
|
167
|
+
toggleButtonTextClasses() {
|
|
168
|
+
return this.block ? 'gl-w-full' : '';
|
|
169
|
+
},
|
|
170
|
+
toggleLabelledBy() {
|
|
171
|
+
return this.ariaLabelledby ? `${this.ariaLabelledby} ${this.toggleId}` : this.toggleId;
|
|
172
|
+
},
|
|
173
|
+
isDefaultToggle() {
|
|
174
|
+
return !this.$scopedSlots.toggle;
|
|
175
|
+
},
|
|
176
|
+
toggleOptions() {
|
|
177
|
+
if (this.isDefaultToggle) {
|
|
178
|
+
return {
|
|
179
|
+
is: GlButton,
|
|
180
|
+
icon: this.icon,
|
|
181
|
+
block: this.block,
|
|
182
|
+
buttonTextClasses: this.toggleButtonTextClasses,
|
|
183
|
+
category: this.category,
|
|
184
|
+
variant: this.variant,
|
|
185
|
+
size: this.size,
|
|
186
|
+
disabled: this.disabled,
|
|
187
|
+
loading: this.loading,
|
|
188
|
+
class: this.toggleButtonClasses,
|
|
189
|
+
...this.ariaAttributes,
|
|
190
|
+
listeners: {
|
|
191
|
+
keydown: event => this.onKeydown(event),
|
|
192
|
+
click: event => this.toggle(event)
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
return {
|
|
197
|
+
is: 'div',
|
|
198
|
+
class: 'gl-new-dropdown-custom-toggle',
|
|
199
|
+
listeners: {
|
|
200
|
+
keydown: event => this.onKeydown(event),
|
|
201
|
+
click: event => this.toggle(event)
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
},
|
|
205
|
+
toggleListeners() {
|
|
206
|
+
return this.toggleOptions.listeners;
|
|
207
|
+
},
|
|
208
|
+
toggleAttributes() {
|
|
209
|
+
const {
|
|
210
|
+
listeners,
|
|
211
|
+
is,
|
|
212
|
+
...attributes
|
|
213
|
+
} = this.toggleOptions;
|
|
214
|
+
return attributes;
|
|
215
|
+
},
|
|
216
|
+
toggleComponent() {
|
|
217
|
+
return this.toggleOptions.is;
|
|
218
|
+
},
|
|
219
|
+
toggleElement() {
|
|
220
|
+
var _this$$refs$toggle;
|
|
221
|
+
return this.$refs.toggle.$el || ((_this$$refs$toggle = this.$refs.toggle) === null || _this$$refs$toggle === void 0 ? void 0 : _this$$refs$toggle.firstElementChild);
|
|
222
|
+
},
|
|
223
|
+
panelClasses() {
|
|
224
|
+
return {
|
|
225
|
+
'gl-display-block!': this.visible,
|
|
226
|
+
[FIXED_WIDTH_CLASS]: !this.fluidWidth,
|
|
227
|
+
'gl-fixed': this.openedYet && this.isFixed,
|
|
228
|
+
'gl-absolute': this.openedYet && !this.isFixed
|
|
229
|
+
};
|
|
230
|
+
},
|
|
231
|
+
isFixed() {
|
|
232
|
+
return this.positioningStrategy === POSITION_FIXED;
|
|
233
|
+
},
|
|
234
|
+
floatingUIConfig() {
|
|
235
|
+
const placement = dropdownPlacements[this.placement];
|
|
236
|
+
const [, alignment] = placement.split('-');
|
|
237
|
+
return {
|
|
238
|
+
placement,
|
|
239
|
+
strategy: this.positioningStrategy,
|
|
240
|
+
middleware: [offset(this.offset), autoPlacement({
|
|
241
|
+
alignment,
|
|
242
|
+
allowedPlacements: dropdownAllowedAutoPlacements[this.placement]
|
|
243
|
+
}), size({
|
|
244
|
+
apply: _ref => {
|
|
245
|
+
var _this$nonScrollableCo;
|
|
246
|
+
let {
|
|
247
|
+
availableHeight,
|
|
248
|
+
elements
|
|
249
|
+
} = _ref;
|
|
250
|
+
const contentsEl = elements.floating.querySelector(`.${GL_DROPDOWN_CONTENTS_CLASS}`);
|
|
251
|
+
if (!contentsEl) {
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
const contentsAvailableHeight = availableHeight - ((_this$nonScrollableCo = this.nonScrollableContentHeight) !== null && _this$nonScrollableCo !== void 0 ? _this$nonScrollableCo : 0) - DEFAULT_OFFSET;
|
|
255
|
+
Object.assign(contentsEl.style, {
|
|
256
|
+
maxHeight: `${Math.max(contentsAvailableHeight, 0)}px`
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
})]
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
},
|
|
263
|
+
watch: {
|
|
264
|
+
ariaAttributes: {
|
|
265
|
+
deep: true,
|
|
266
|
+
handler(ariaAttributes) {
|
|
267
|
+
if (this.$scopedSlots.toggle) {
|
|
268
|
+
Object.keys(ariaAttributes).forEach(key => {
|
|
269
|
+
this.toggleElement.setAttribute(key, ariaAttributes[key]);
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
},
|
|
275
|
+
mounted() {
|
|
276
|
+
this.checkToggleFocusable();
|
|
277
|
+
},
|
|
278
|
+
beforeDestroy() {
|
|
279
|
+
this.stopFloating();
|
|
280
|
+
},
|
|
281
|
+
methods: {
|
|
282
|
+
checkToggleFocusable() {
|
|
283
|
+
if (!isElementFocusable(this.toggleElement) && !isElementTabbable(this.toggleElement)) {
|
|
284
|
+
logWarning(`GlDisclosureDropdown/GlCollapsibleListbox: Toggle is missing a 'tabindex' and cannot be focused.
|
|
285
|
+
Use 'a' or 'button' element instead or make sure to add 'role="button"' along with 'tabindex' otherwise.`, this.$el);
|
|
286
|
+
}
|
|
287
|
+
},
|
|
288
|
+
async startFloating() {
|
|
289
|
+
this.calculateNonScrollableAreaHeight();
|
|
290
|
+
this.observer = new MutationObserver(this.calculateNonScrollableAreaHeight);
|
|
291
|
+
this.observer.observe(this.$refs.content, {
|
|
292
|
+
attributes: false,
|
|
293
|
+
childList: true,
|
|
294
|
+
subtree: true
|
|
295
|
+
});
|
|
296
|
+
this.stopAutoUpdate = autoUpdate(this.toggleElement, this.$refs.content, async () => {
|
|
297
|
+
const {
|
|
298
|
+
x,
|
|
299
|
+
y
|
|
300
|
+
} = await computePosition(this.toggleElement, this.$refs.content, this.floatingUIConfig);
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Due to the asynchronous nature of computePosition, it's technically possible for the
|
|
304
|
+
* component to have been destroyed by the time the promise resolves. In such case, we exit
|
|
305
|
+
* early to prevent a TypeError.
|
|
306
|
+
*/
|
|
307
|
+
if (!this.$refs.content) return;
|
|
308
|
+
Object.assign(this.$refs.content.style, {
|
|
309
|
+
left: `${x}px`,
|
|
310
|
+
top: `${y}px`
|
|
311
|
+
});
|
|
312
|
+
});
|
|
313
|
+
},
|
|
314
|
+
stopFloating() {
|
|
315
|
+
var _this$observer, _this$stopAutoUpdate;
|
|
316
|
+
(_this$observer = this.observer) === null || _this$observer === void 0 ? void 0 : _this$observer.disconnect();
|
|
317
|
+
(_this$stopAutoUpdate = this.stopAutoUpdate) === null || _this$stopAutoUpdate === void 0 ? void 0 : _this$stopAutoUpdate.call(this);
|
|
318
|
+
},
|
|
319
|
+
async toggle(event) {
|
|
320
|
+
if (event && this.visible) {
|
|
321
|
+
let prevented = false;
|
|
322
|
+
this.$emit(GL_DROPDOWN_BEFORE_CLOSE, {
|
|
323
|
+
originalEvent: event,
|
|
324
|
+
preventDefault() {
|
|
325
|
+
prevented = true;
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
if (prevented) return false;
|
|
329
|
+
}
|
|
330
|
+
this.visible = !this.visible;
|
|
331
|
+
if (this.visible) {
|
|
332
|
+
// The dropdown needs to be actually visible before we compute its position with Floating UI.
|
|
333
|
+
await this.$nextTick();
|
|
334
|
+
this.openedYet = true;
|
|
335
|
+
/**
|
|
336
|
+
* We wait until the dropdown's position has been computed before emitting the `shown` event.
|
|
337
|
+
* This ensures that, if the parent component attempts to focus an inner element, the dropdown
|
|
338
|
+
* is already properly placed in the page. Otherwise, the page would scroll back to the top.
|
|
339
|
+
*/
|
|
340
|
+
this.startFloating();
|
|
341
|
+
this.$emit(GL_DROPDOWN_SHOWN);
|
|
342
|
+
} else {
|
|
343
|
+
this.stopFloating();
|
|
344
|
+
this.$emit(GL_DROPDOWN_HIDDEN);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// this is to check whether `toggle` was prevented or not
|
|
348
|
+
return true;
|
|
349
|
+
},
|
|
350
|
+
open() {
|
|
351
|
+
if (this.visible) {
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
this.toggle();
|
|
355
|
+
},
|
|
356
|
+
close(event) {
|
|
357
|
+
if (!this.visible) {
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
this.toggle(event);
|
|
361
|
+
},
|
|
362
|
+
/**
|
|
363
|
+
* Closes the dropdown and returns the focus to the toggle unless it has has moved outside
|
|
364
|
+
* of the dropdown, meaning that the consumer needed to put some other element in focus.
|
|
365
|
+
*
|
|
366
|
+
* @param {KeyboardEvent?} event The keyboard event that caused the dropdown to close.
|
|
367
|
+
*/
|
|
368
|
+
async closeAndFocus(event) {
|
|
369
|
+
if (!this.visible) {
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
const hasToggled = await this.toggle(event);
|
|
373
|
+
if (!this.$el.contains(document.activeElement)) {
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
if (hasToggled) {
|
|
377
|
+
this.focusToggle();
|
|
378
|
+
}
|
|
379
|
+
},
|
|
380
|
+
focusToggle() {
|
|
381
|
+
this.toggleElement.focus();
|
|
382
|
+
},
|
|
383
|
+
onKeydown(event) {
|
|
384
|
+
const {
|
|
385
|
+
code,
|
|
386
|
+
target: {
|
|
387
|
+
tagName
|
|
388
|
+
}
|
|
389
|
+
} = event;
|
|
390
|
+
let toggleOnEnter = true;
|
|
391
|
+
let toggleOnSpace = true;
|
|
392
|
+
if (tagName === 'BUTTON') {
|
|
393
|
+
toggleOnEnter = false;
|
|
394
|
+
toggleOnSpace = false;
|
|
395
|
+
} else if (tagName === 'A') {
|
|
396
|
+
toggleOnEnter = false;
|
|
397
|
+
}
|
|
398
|
+
if (code === ENTER && toggleOnEnter || code === SPACE && toggleOnSpace) {
|
|
399
|
+
this.toggle(event);
|
|
400
|
+
}
|
|
401
|
+
if (code === ARROW_DOWN) {
|
|
402
|
+
this.$emit(GL_DROPDOWN_FOCUS_CONTENT, event);
|
|
403
|
+
}
|
|
404
|
+
},
|
|
405
|
+
calculateNonScrollableAreaHeight() {
|
|
406
|
+
var _this$$refs$content;
|
|
407
|
+
const scrollableArea = (_this$$refs$content = this.$refs.content) === null || _this$$refs$content === void 0 ? void 0 : _this$$refs$content.querySelector(`.${GL_DROPDOWN_CONTENTS_CLASS}`);
|
|
408
|
+
if (!scrollableArea) return;
|
|
409
|
+
const floatingElementBoundingBox = this.$refs.content.getBoundingClientRect();
|
|
410
|
+
const scrollableAreaBoundingBox = scrollableArea.getBoundingClientRect();
|
|
411
|
+
this.nonScrollableContentHeight = floatingElementBoundingBox.height - scrollableAreaBoundingBox.height;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
/* script */
|
|
417
|
+
const __vue_script__ = script;
|
|
418
|
+
|
|
419
|
+
/* template */
|
|
420
|
+
var __vue_render__ = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{directives:[{name:"outside",rawName:"v-outside",value:(_vm.close),expression:"close"}],class:[_vm.$options.BASE_DROPDOWN_CLASS, { 'gl-display-block!': _vm.block }]},[_c(_vm.toggleComponent,_vm._g(_vm._b({ref:"toggle",tag:"component",attrs:{"id":_vm.toggleId,"data-testid":"base-dropdown-toggle"}},'component',_vm.toggleAttributes,false),_vm.toggleListeners),[_vm._t("toggle",function(){return [_c('span',{staticClass:"gl-new-dropdown-button-text",class:{ 'gl-sr-only': _vm.textSrOnly }},[_vm._v("\n "+_vm._s(_vm.toggleText)+"\n ")]),_vm._v(" "),(!_vm.noCaret)?_c('gl-icon',{staticClass:"gl-button-icon gl-new-dropdown-chevron",attrs:{"name":"chevron-down"}}):_vm._e()]})],2),_vm._v(" "),_c('div',{ref:"content",staticClass:"gl-new-dropdown-panel",class:_vm.panelClasses,attrs:{"id":_vm.baseDropdownId,"data-testid":"base-dropdown-menu"},on:{"keydown":function($event){if(!$event.type.indexOf('key')&&_vm._k($event.keyCode,"esc",27,$event.key,["Esc","Escape"])){ return null; }$event.stopPropagation();$event.preventDefault();return _vm.closeAndFocus.apply(null, arguments)}}},[_c('div',{staticClass:"gl-new-dropdown-inner"},[_vm._t("default")],2)])],1)};
|
|
421
|
+
var __vue_staticRenderFns__ = [];
|
|
422
|
+
|
|
423
|
+
/* style */
|
|
424
|
+
const __vue_inject_styles__ = undefined;
|
|
425
|
+
/* scoped */
|
|
426
|
+
const __vue_scope_id__ = undefined;
|
|
427
|
+
/* module identifier */
|
|
428
|
+
const __vue_module_identifier__ = undefined;
|
|
429
|
+
/* functional template */
|
|
430
|
+
const __vue_is_functional_template__ = false;
|
|
431
|
+
/* style inject */
|
|
432
|
+
|
|
433
|
+
/* style inject SSR */
|
|
434
|
+
|
|
435
|
+
/* style inject shadow dom */
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
const __vue_component__ = __vue_normalize__(
|
|
440
|
+
{ render: __vue_render__, staticRenderFns: __vue_staticRenderFns__ },
|
|
441
|
+
__vue_inject_styles__,
|
|
442
|
+
__vue_script__,
|
|
443
|
+
__vue_scope_id__,
|
|
444
|
+
__vue_is_functional_template__,
|
|
445
|
+
__vue_module_identifier__,
|
|
446
|
+
false,
|
|
447
|
+
undefined,
|
|
448
|
+
undefined,
|
|
449
|
+
undefined
|
|
450
|
+
);
|
|
451
|
+
|
|
452
|
+
export default __vue_component__;
|
|
453
|
+
export { BASE_DROPDOWN_CLASS };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// base dropdown events
|
|
2
|
+
const GL_DROPDOWN_SHOWN = 'shown';
|
|
3
|
+
const GL_DROPDOWN_HIDDEN = 'hidden';
|
|
4
|
+
const GL_DROPDOWN_BEFORE_CLOSE = 'beforeClose';
|
|
5
|
+
const GL_DROPDOWN_FOCUS_CONTENT = 'focusContent';
|
|
6
|
+
|
|
7
|
+
// KEY Codes
|
|
8
|
+
const ARROW_DOWN = 'ArrowDown';
|
|
9
|
+
const ARROW_UP = 'ArrowUp';
|
|
10
|
+
const END = 'End';
|
|
11
|
+
const ENTER = 'Enter';
|
|
12
|
+
const HOME = 'Home';
|
|
13
|
+
const SPACE = 'Space';
|
|
14
|
+
|
|
15
|
+
// Positioning strategies
|
|
16
|
+
// https://floating-ui.com/docs/computePosition#strategy
|
|
17
|
+
const POSITION_ABSOLUTE = 'absolute';
|
|
18
|
+
const POSITION_FIXED = 'fixed';
|
|
19
|
+
const GL_DROPDOWN_CONTENTS_CLASS = 'gl-new-dropdown-contents';
|
|
20
|
+
|
|
21
|
+
export { ARROW_DOWN, ARROW_UP, END, ENTER, GL_DROPDOWN_BEFORE_CLOSE, GL_DROPDOWN_CONTENTS_CLASS, GL_DROPDOWN_FOCUS_CONTENT, GL_DROPDOWN_HIDDEN, GL_DROPDOWN_SHOWN, HOME, POSITION_ABSOLUTE, POSITION_FIXED, SPACE };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const DISCLOSURE_DROPDOWN_ITEM_NAME = 'GlDisclosureDropdownItem';
|
|
2
|
+
const DISCLOSURE_DROPDOWN_GROUP_NAME = 'GlDisclosureDropdownGroup';
|
|
3
|
+
const DISCLOSURE_DROPDOWN_GROUP_BORDER_POSITIONS = {
|
|
4
|
+
top: 'top',
|
|
5
|
+
bottom: 'bottom'
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export { DISCLOSURE_DROPDOWN_GROUP_BORDER_POSITIONS, DISCLOSURE_DROPDOWN_GROUP_NAME, DISCLOSURE_DROPDOWN_ITEM_NAME };
|