Skip to content
This repository has been archived by the owner on Jul 12, 2020. It is now read-only.

Fix seamless panel caret #88

Merged
merged 7 commits into from
Jul 31, 2018

Conversation

yamgent
Copy link
Member

@yamgent yamgent commented Jul 27, 2018

What is the purpose of this pull request? (put "X" next to an item, remove the rest)

• [X] Bug fix

Fixes MarkBind/markbind#383, fixes MarkBind/markbind#373.

What is the rationale for this request?
Fix the seamless panel caret once and for all, by just moving the caret outside the panel header.

What changes did you make? (Give an overview)
Since PR #81, carets were inserted inside the header. However, the algorithm for inserting the caret is not perfect, and there were many edge cases. This has lead to many issues as reported as comments in #74
, #81, #83, MarkBind/markbind#373, MarkBind/markbind#383.

Those fixes were unsustainable. Therefore, the relevant PRs have been reverted, and this PR tries a new fix for the original issue.

Provide some example code that this change will affect:
NA

Is there anything you'd like reviewers to focus on?
Ensuring that the panel rendering did not break.

Testing instructions:

  1. Compile vue-strap.min.js and copy to MarkBind repository.
  2. Serve the MarkBind user guide documentation website and check that the panels are OK.
  3. Also create a new MarkBind website and try these out in index.md:
<panel type="seamless" header="Normal">
</panel>

<panel type="seamless" header="# Heading 1">
</panel>

<panel type="seamless" header="## Heading 2">
</panel>

<panel type="seamless" header="### Heading 3">
</panel>

<panel type="seamless" header="#### Heading 4">
</panel>

<panel type="seamless" header="##### Heading 5">
</panel>

<panel type="seamless" header="###### Heading 6">
</panel>

<panel header="Normal panel">
</panel>

<panel header="# Normal panel 2">
</panel>

<panel type="seamless" header="%%Some gray text lalalalalalalalalalalala%%">
</panel>

<panel type="seamless">
  <p slot="header" class="card-title" style="display: inline-block;">
    <i><strong>
      <span style="color:#FF0000;">R  </span>
      <span style="color:#FF7F00;">A  </span>
      <span style="color:#FFFF00;">I  </span>
      <span style="color:#00FF00;">N  </span>
      <span style="color:#0000FF;">B  </span>
      <span style="color:#4B0082;">O  </span>
      <span style="color:#9400D3;">W  </span>
      Custom slot
    </strong></i>
  </p>
</panel>

<panel type="seamless">
<span slot="header" class="card-title">
This header won't break even if I used <code>card-title</code>, hooray!
</span>
</panel>

<panel type="seamless">
<span slot="header">
No breaking as <code>card-title</code> not used, hip hip hooray!
</span>
</panel>

<panel type="seamless" header="Normal seamless">
Normal seamless panel content.
</panel>

<panel type="seamless" header="To websites" popup-url="https://www.yahoo.com">
  Go to website.
</panel>

yamgent added 4 commits July 27, 2018 13:51
…ret"

This reverts commit 576952c, reversing
changes made to 1ce9ce3.
…s-panel"

This reverts commit d7626b3, reversing
changes made to a0bae9e.
The caret is combined with the header content. It is usually rendered
like this:

> Some heading

However, custom header contents, after markdown rendering, will be
wrapped with block HTML tags such as <p> and <h1>, which will make
browsers render a line break between the caret and header content:

>
Some heading

Let's fix this by moving the caret to a separate div. Then, make
everything inside a panel header be on a single line by using CSS
'display: inline-block' and 'width: ...', such that the width adds up to
100%.

    +--------+-----------------+---------+
    | caret  |  header-content | buttons |
    | (32px) | (100% - 32 - 32)|  (32px) |
    +--------+-----------------+---------+

Thanks to @nusjzx for providing the fix to the button-wrapper in PR
MarkBind#86, in which his use of
'calc(100% - 32px)' provided a source of inspiration for this fix. His
fix in that PR is incorporated into this commit because without it, the
responsive design will not work.

An alternative fix considered was to use md.renderInline(). However,
md.renderInline() does not render markdown headings.

Another alternative fix was to insert the caret directly inside the
header content. However, after PR MarkBind#74, MarkBind#81 and MarkBind#83 were merged, new
problems continue to emerge.

These problems are reported as comments in these pages:
- MarkBind#74
- MarkBind#81
- MarkBind#83
- MarkBind/markbind#373
- MarkBind/markbind#383

As such, the PRs for this alternative fix has been reverted by the
previous commits before this commit.
Copy link

@Chng-Zhi-Xuan Chng-Zhi-Xuan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and works great.

Just need to recover certain changes made previously.

src/Panel.vue Outdated
@@ -16,7 +16,10 @@
<div :class="['card-header',{'header-toggle':isExpandableCard}, cardType, borderType]"
@click.prevent.stop="isExpandableCard && toggle()"
@mouseover="onHeaderHover = true" @mouseleave="onHeaderHover = false">
<div class="header-wrapper" ref="headerWrapper">
<div class="caret-wrapper">
<span :class="['glyphicon', localExpanded ? 'glyphicon-chevron-down' : 'glyphicon-chevron-right']" v-show="showCaret"></span>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v-if is preferred since it doesn't need to be rendered.

src/Panel.vue Outdated
@@ -27,12 +30,12 @@
@click.native.stop.prevent="expand()"
@is-open-event="retrieveOnOpen" :is-light-bg="isLightBg"></panel-switch>
<button type="button" :class="['close-button', 'btn', isLightBg ? 'btn-outline-secondary' : 'btn-outline-light']"
v-show="isSeamless ? onHeaderHover : (!noCloseBool)"
v-show="!isSeamless ? (!noCloseBool) : onHeaderHover"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes reverted from #74

src/Panel.vue Outdated
@click.stop="close()">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
<button type="button" :class="['popup-button', 'btn', isLightBg ? 'btn-outline-secondary' : 'btn-outline-light']"
v-show="((this.popupUrl !== null) && (!isSeamless || onHeaderHover))"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes reverted from #74

yamgent added 3 commits July 30, 2018 09:52
This change will improve rendering performance, as `v-if` will ensure
that the caret will never get rendered if it shouldn't appear in the
first place.
For seamless panels, header buttons should only show when the user
hovers over the title.

However, the popup button is always shown to the user regardless of
whether the user hovers over it or not.

Let's fix the popup button showing behavior so that it will only show
when the user hovers over it.
@yamgent
Copy link
Member Author

yamgent commented Jul 30, 2018

Update:

  • Changes requested made.
  • Example code updated to include the popup button bug when using seamless panel (fixed by 93515d4).

Copy link

@Chng-Zhi-Xuan Chng-Zhi-Xuan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested, everything works well 👍

@yamgent yamgent added this to the v2.0.1-markbind.17 milestone Jul 30, 2018
@yamgent yamgent merged commit 8484add into MarkBind:master Jul 31, 2018
@yamgent yamgent deleted the 383-fix-seamless-panel-caret branch July 31, 2018 00:48
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants