Commit f0ff168e authored by Enrique Alcántara's avatar Enrique Alcántara

Merge branch '329568-update-md-header-buttons' into 'master'

Migrate md header buttons to gl-buttons

See merge request gitlab-org/gitlab!67872
parents 67b3d52f 4bf3cc6e
<script> <script>
import { GlPopover, GlButton, GlTooltipDirective, GlIcon } from '@gitlab/ui'; import { GlPopover, GlButton, GlTooltipDirective } from '@gitlab/ui';
import $ from 'jquery'; import $ from 'jquery';
import { keysFor, BOLD_TEXT, ITALIC_TEXT, LINK_TEXT } from '~/behaviors/shortcuts/keybindings'; import { keysFor, BOLD_TEXT, ITALIC_TEXT, LINK_TEXT } from '~/behaviors/shortcuts/keybindings';
import { getSelectedFragment } from '~/lib/utils/common_utils'; import { getSelectedFragment } from '~/lib/utils/common_utils';
...@@ -10,7 +10,6 @@ import ToolbarButton from './toolbar_button.vue'; ...@@ -10,7 +10,6 @@ import ToolbarButton from './toolbar_button.vue';
export default { export default {
components: { components: {
ToolbarButton, ToolbarButton,
GlIcon,
GlPopover, GlPopover,
GlButton, GlButton,
}, },
...@@ -46,6 +45,7 @@ export default { ...@@ -46,6 +45,7 @@ export default {
data() { data() {
return { return {
tag: '> ', tag: '> ',
suggestPopoverVisible: false,
}; };
}, },
computed: { computed: {
...@@ -76,15 +76,27 @@ export default { ...@@ -76,15 +76,27 @@ export default {
return this.isMac ? '' : s__('KeyboardKey|Ctrl+'); return this.isMac ? '' : s__('KeyboardKey|Ctrl+');
}, },
}, },
watch: {
showSuggestPopover() {
this.updateSuggestPopoverVisibility();
},
},
mounted() { mounted() {
$(document).on('markdown-preview:show.vue', this.previewMarkdownTab); $(document).on('markdown-preview:show.vue', this.previewMarkdownTab);
$(document).on('markdown-preview:hide.vue', this.writeMarkdownTab); $(document).on('markdown-preview:hide.vue', this.writeMarkdownTab);
this.updateSuggestPopoverVisibility();
}, },
beforeDestroy() { beforeDestroy() {
$(document).off('markdown-preview:show.vue', this.previewMarkdownTab); $(document).off('markdown-preview:show.vue', this.previewMarkdownTab);
$(document).off('markdown-preview:hide.vue', this.writeMarkdownTab); $(document).off('markdown-preview:hide.vue', this.writeMarkdownTab);
}, },
methods: { methods: {
async updateSuggestPopoverVisibility() {
await this.$nextTick();
this.suggestPopoverVisible = this.showSuggestPopover && this.canSuggest;
},
isValid(form) { isValid(form) {
return ( return (
!form || !form ||
...@@ -153,7 +165,6 @@ export default { ...@@ -153,7 +165,6 @@ export default {
</button> </button>
</li> </li>
<li :class="{ active: !previewMarkdown }" class="md-header-toolbar"> <li :class="{ active: !previewMarkdown }" class="md-header-toolbar">
<div class="d-inline-block">
<toolbar-button <toolbar-button
tag="**" tag="**"
:button-title=" :button-title="
...@@ -177,8 +188,6 @@ export default { ...@@ -177,8 +188,6 @@ export default {
icon="quote" icon="quote"
@click="handleQuote" @click="handleQuote"
/> />
</div>
<div class="d-inline-block ml-md-2 ml-0">
<template v-if="canSuggest"> <template v-if="canSuggest">
<toolbar-button <toolbar-button
ref="suggestButton" ref="suggestButton"
...@@ -193,11 +202,11 @@ export default { ...@@ -193,11 +202,11 @@ export default {
@click="handleSuggestDismissed" @click="handleSuggestDismissed"
/> />
<gl-popover <gl-popover
v-if="showSuggestPopover && $refs.suggestButton" v-if="suggestPopoverVisible"
:target="$refs.suggestButton" :target="$refs.suggestButton.$el"
:css-classes="['diff-suggest-popover']" :css-classes="['diff-suggest-popover']"
placement="bottom" placement="bottom"
:show="showSuggestPopover" :show="suggestPopoverVisible"
> >
<strong>{{ __('New! Suggest changes directly') }}</strong> <strong>{{ __('New! Suggest changes directly') }}</strong>
<p class="mb-2"> <p class="mb-2">
...@@ -210,7 +219,7 @@ export default { ...@@ -210,7 +219,7 @@ export default {
<gl-button <gl-button
variant="info" variant="info"
category="primary" category="primary"
size="sm" size="small"
@click="handleSuggestDismissed" @click="handleSuggestDismissed"
> >
{{ __('Got it') }} {{ __('Got it') }}
...@@ -227,8 +236,6 @@ export default { ...@@ -227,8 +236,6 @@ export default {
:shortcuts="$options.shortcuts.link" :shortcuts="$options.shortcuts.link"
icon="link" icon="link"
/> />
</div>
<div class="d-inline-block ml-md-2 ml-0">
<toolbar-button <toolbar-button
:prepend="true" :prepend="true"
tag="- " tag="- "
...@@ -260,20 +267,12 @@ export default { ...@@ -260,20 +267,12 @@ export default {
:button-title="__('Add a table')" :button-title="__('Add a table')"
icon="table" icon="table"
/> />
</div> <toolbar-button
<div class="d-inline-block ml-md-2 ml-0"> class="js-zen-enter"
<button :prepend="true"
v-gl-tooltip :button-title="__('Go full screen')"
:aria-label="__('Go full screen')" icon="maximize"
class="toolbar-btn toolbar-fullscreen-btn js-zen-enter" />
data-container="body"
tabindex="-1"
:title="__('Go full screen')"
type="button"
>
<gl-icon name="maximize" />
</button>
</div>
</li> </li>
</ul> </ul>
</div> </div>
......
<script> <script>
import { GlTooltipDirective, GlIcon } from '@gitlab/ui'; import { GlTooltipDirective, GlButton } from '@gitlab/ui';
export default { export default {
components: { components: {
GlIcon, GlButton,
}, },
directives: { directives: {
GlTooltip: GlTooltipDirective, GlTooltip: GlTooltipDirective,
...@@ -19,7 +19,8 @@ export default { ...@@ -19,7 +19,8 @@ export default {
}, },
tag: { tag: {
type: String, type: String,
required: true, required: false,
default: '',
}, },
tagBlock: { tagBlock: {
type: String, type: String,
...@@ -71,7 +72,7 @@ export default { ...@@ -71,7 +72,7 @@ export default {
</script> </script>
<template> <template>
<button <gl-button
v-gl-tooltip v-gl-tooltip
:data-md-tag="tag" :data-md-tag="tag"
:data-md-cursor-offset="cursorOffset" :data-md-cursor-offset="cursorOffset"
...@@ -82,11 +83,11 @@ export default { ...@@ -82,11 +83,11 @@ export default {
:data-md-shortcuts="shortcutsString" :data-md-shortcuts="shortcutsString"
:title="buttonTitle" :title="buttonTitle"
:aria-label="buttonTitle" :aria-label="buttonTitle"
:icon="icon"
type="button" type="button"
class="toolbar-btn js-md" category="tertiary"
class="js-md"
data-container="body" data-container="body"
@click="() => $emit('click')" @click="() => $emit('click')"
> />
<gl-icon :name="icon" />
</button>
</template> </template>
...@@ -98,7 +98,6 @@ ...@@ -98,7 +98,6 @@
} }
.note-action-button, .note-action-button,
.toolbar-btn,
.dropdown-toggle-caret { .dropdown-toggle-caret {
@include transition(color); @include transition(color);
} }
......
...@@ -131,36 +131,6 @@ ...@@ -131,36 +131,6 @@
width: 100%; width: 100%;
} }
.toolbar-btn {
float: left;
padding: 0 7px;
background: transparent;
border: 0;
outline: 0;
svg {
width: 14px;
height: 14px;
vertical-align: middle;
fill: $gl-text-color-secondary;
}
&:hover,
&:focus {
svg {
fill: $blue-600;
}
}
}
.toolbar-fullscreen-btn {
margin-right: -5px;
@include media-breakpoint-down(xs) {
margin-right: 0;
}
}
.md-suggestion-diff { .md-suggestion-diff {
display: table !important; display: table !important;
border: 1px solid $border-color !important; border: 1px solid $border-color !important;
......
...@@ -250,7 +250,7 @@ module MarkupHelper ...@@ -250,7 +250,7 @@ module MarkupHelper
data = options[:data].merge({ container: 'body' }) data = options[:data].merge({ container: 'body' })
content_tag :button, content_tag :button,
type: 'button', type: 'button',
class: 'toolbar-btn js-md has-tooltip', class: 'gl-button btn btn-default-tertiary btn-icon js-md has-tooltip',
data: data, data: data,
title: options[:title], title: options[:title],
aria: { label: options[:title] } do aria: { label: options[:title] } do
......
...@@ -24,5 +24,5 @@ ...@@ -24,5 +24,5 @@
title: _("Add a collapsible section") }) title: _("Add a collapsible section") })
= markdown_toolbar_button({ icon: "table", data: { "md-tag" => "| header | header |\n| ------ | ------ |\n| cell | cell |\n| cell | cell |", "md-prepend" => true }, title: _("Add a table") }) = markdown_toolbar_button({ icon: "table", data: { "md-tag" => "| header | header |\n| ------ | ------ |\n| cell | cell |\n| cell | cell |", "md-prepend" => true }, title: _("Add a table") })
- if show_fullscreen_button - if show_fullscreen_button
%button.toolbar-btn.toolbar-fullscreen-btn.js-zen-enter.has-tooltip{ type: "button", tabindex: -1, "aria-label": "Go full screen", title: _("Go full screen"), data: { container: "body" } } %button.gl-button.btn.btn-default-tertiary.btn-icon.js-zen-enter.has-tooltip{ type: "button", tabindex: -1, "aria-label": "Go full screen", title: _("Go full screen"), data: { container: "body" } }
= sprite_icon("maximize") = sprite_icon("maximize")
...@@ -55,7 +55,7 @@ RSpec.describe 'Project > Tags', :js do ...@@ -55,7 +55,7 @@ RSpec.describe 'Project > Tags', :js do
note_textarea = page.find('.js-gfm-input') note_textarea = page.find('.js-gfm-input')
# Click on Bold button # Click on Bold button
page.find('.md-header-toolbar button.toolbar-btn:first-child').click page.find('.md-header-toolbar button:first-child').click
expect(note_textarea.value).to eq('****') expect(note_textarea.value).to eq('****')
end end
......
import { GlButton } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import ToolbarButton from '~/vue_shared/components/markdown/toolbar_button.vue'; import ToolbarButton from '~/vue_shared/components/markdown/toolbar_button.vue';
...@@ -25,7 +26,7 @@ describe('toolbar_button', () => { ...@@ -25,7 +26,7 @@ describe('toolbar_button', () => {
}); });
const getButtonShortcutsAttr = () => { const getButtonShortcutsAttr = () => {
return wrapper.find('button').attributes('data-md-shortcuts'); return wrapper.find(GlButton).attributes('data-md-shortcuts');
}; };
describe('keyboard shortcuts', () => { describe('keyboard shortcuts', () => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment