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

TipBox.vue: Support different size icons #124

Merged
merged 8 commits into from
Feb 4, 2020

Conversation

yash-chowdhary
Copy link

@yash-chowdhary yash-chowdhary commented Jan 22, 2020

closes MarkBind #986 (specifications of sizes can also be found there).

This is an enhancement to box icons.
Usage:

<box type="warning" icon=":fas-camera:" icon-size="2x">
    DUMMY TEXT
</box>

(Possible) Expected output(s):

  • icon-size="2x", single-para
    Screenshot 2020-01-30 at 10 03 24 PM

  • icon-size="2x", multi-para
    Screenshot 2020-01-30 at 10 02 02 PM

  • icon-size="2x", multi-para, no heading, not dismissible
    Screenshot 2020-01-30 at 10 05 48 PM

@yash-chowdhary
Copy link
Author

Ready for Review

Copy link

@acjh acjh left a comment

Choose a reason for hiding this comment

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

Only the .icon-wrapper change appears to be necessary.
My thoughts on styling: MarkBind/markbind#386 (comment), MarkBind/markbind#386 (comment)

Suggested usage:

<box icon=":rocket:" add-class="icon-large">
    DUMMY TEXT
</box>
.icon-large i {
    font-size: 3em;
}

src/TipBox.vue Outdated Show resolved Hide resolved
src/TipBox.vue Outdated
flex-direction: column;
justify-content: center;
align-content: center;
font-size: medium;
Copy link

Choose a reason for hiding this comment

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

I believe we only need display and align-content.

Copy link
Author

Choose a reason for hiding this comment

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

I tried it without the flex-direction: column, and the justify-content: center. Here's what it looks like for large paragraphs -
Screenshot 2020-01-24 at 5 16 13 PM

Here's what it looks like without justify-content: center (but with flex-direction: column). While it does work for long paragraphs, single-line content is not properly aligned -
Screenshot 2020-01-24 at 5 19 51 PM

Copy link

Choose a reason for hiding this comment

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

That appears to be because <slot></slot> is directly in contents, together with heading and dismiss-button.

I don't think it is appropriate to always centre the children in contents though, particularly the heading. Did we try extra-large (maybe extremely-large) with heading and/or dismissable?

Copy link
Author

Choose a reason for hiding this comment

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

Sorry for the late reply. I've been trying out different things to make this work. You're right, the heading and dismiss-button don't behave well when I center-align the contents. Center-aligning the contents is much harder than I thought it would be 😅

I've tried wrapping the <slot> in a <div> and <span>, but that doesn't work well. The next thing I tried was moving the heading and button outside the 'content's div and make it a 3 column container (one for the icon, one for text, one for heading and button). The problem here is that the heading messes with the text column if it is too long.
So, the latest thing I'm working on is separating out the heading into a div that would be placed on top of the container, effectively making it a 2-rowed container. The 2nd row will be a 3 column container, with the 3rd column only for the dismiss-button.

Are there any better ways to deal with this?

Copy link

Choose a reason for hiding this comment

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

I would say not to vertically center-align the contents.

Copy link
Author

Choose a reason for hiding this comment

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

Alright 👍

src/TipBox.vue Outdated Show resolved Hide resolved
@yash-chowdhary
Copy link
Author

As mentioned above, usage:

<box type="warning" add-class="icon-large">
    DUMMY TEXT
</box>

Will open a PR in markbind to add the CSS icon-size classes to the assets.

@damithc
Copy link

damithc commented Jan 25, 2020

As mentioned above, usage:

<box type="warning" add-class="icon-large">
    DUMMY TEXT
</box>

Oh? I thought it is going to be <box type="warning" icon-large>

@yash-chowdhary
Copy link
Author

I thought @acjh wanted to normalize it to using add-class?

@damithc
Copy link

damithc commented Jan 25, 2020

I thought @acjh wanted to normalize it to using add-class?

@acjh what do you think? <box type="warning" icon-large> is easier to the author but I don't mind using <box type="warning" add-class="icon-large"> if there a justification.

@acjh
Copy link

acjh commented Jan 25, 2020

Will open a PR in markbind to add the CSS icon-size classes to the assets.

By the site's own CSS file, I meant like https://github.com/nus-cs2103/website-base/blob/master/css/main.css.

@acjh what do you think? <box type="warning" icon-large> is easier to the author but I don't mind using <box type="warning" add-class="icon-large"> if there a justification.

The styles are arbitrary (2em, 3em, extra-large). If we do this, then authors may expect MarkBind to add more styles like medium-large (2.5em), extra-extra-large (5em) and text sizes next. There is little value that MarkBind can add, especially since these can be achieved with plain CSS quite easily. MarkBind should go for pleasant styling, maybe with alternative defaults if reasonable, but we should draw the line between supporting the ability to do something (add-class and the other changes in this PR) and adding arbitrary styles.

@damithc
Copy link

damithc commented Jan 25, 2020

Will open a PR in markbind to add the CSS icon-size classes to the assets.

By the site's own CSS file, I meant like https://github.com/nus-cs2103/website-base/blob/master/css/main.css.

@acjh what do you think? <box type="warning" icon-large> is easier to the author but I don't mind using <box type="warning" add-class="icon-large"> if there a justification.

The styles are arbitrary (2em, 3em, extra-large). If we do this, then authors may expect MarkBind to add more styles like medium-large (2.5em), extra-extra-large (5em) and text sizes next. There is little value that MarkBind can add, especially since these can be achieved with plain CSS quite easily. MarkBind should go for pleasant styling, maybe with alternative defaults if reasonable, but we should draw the line between supporting the ability to do something (add-class and the other changes in this PR) and adding arbitrary styles.

I agree with drawing the line somewhere. I'm also mindful that our target authors are expected to be able to use basic html-like syntax only whereas css editing is moving to web developer territory. As an author, I myself sometimes ask you guys for css hacks when I can't get MarkBind to do what I want. It's not something we can expect our target users to do (at least not the authors of education materials; might be OK for those writing project documentation if the project itself is a web project). So, it's good if we can minimize the need for css editing.

For example, the box icon size vary between different site generators (ours seem to be the smallest) but probably the 4 proposed variations can cover the full range. That way, our box can be configured to be close to most of the common box styles. If the author wants some odd-sized icon, only then they should have to resort to css editing.

Do you think it is OK to provide some built-in styles, like how Bootstrap does (e.g., text-danger text-info pr-1 pr-2 etc.)? That way, our users can kind of make their own styles without having to write css code themselves. That is, to have something like this in the UG:

You can vary the icon size by adding icon-medium, icon-large, icon-extralarge to a box via the add-class mechanism. If those sizes don't fit your needs, you can set it to your own size as follows:
Add a class to your site's custom css file.
Example:

.icon-custom i {
   font-size: 3em;
}

Then, ...

@acjh
Copy link

acjh commented Jan 25, 2020

Do you think it is OK to provide some built-in styles, like how Bootstrap does (e.g., text-danger text-info pr-1 pr-2 etc.)?

I think that is not where MarkBind should be heading.

Some investigation shows that Font Awesome already does sizing:
https://fontawesome.com/how-to-use/on-the-web/styling/sizing-icons

fa-lg is 1.33333emlarge is arbitrary.

How about:

<!-- Raw -->
<box type="warning" icon=":fas-camera:" icon-size="2x">
    DUMMY TEXT
</box>

<!-- Rendered -->
<div class="alert container alert-warning">
  <div class="icon-wrapper fa-2x">
    <span><i class="fas fa-camera"></i></span>
  </div>
  <div class="contents">
    DUMMY TEXT
  </div>
</div>

Note that fa-{iconSize} is added to icon-wrapper rather than the icon element i itself, unlike the Font Awesome examples, to simplify support for custom Markdown icon.

@damithc
Copy link

damithc commented Jan 25, 2020

<box type="warning" icon=":fas-camera:" icon-size="2x"> sounds good.

@yash-chowdhary
Copy link
Author

Usage:

<box type="warning" icon=":fas-camera:" icon-size="2x">
    DUMMY TEXT
</box>

(Possible) Expected output(s):

  • icon-size="2x", single-para
    Screenshot 2020-01-30 at 10 03 24 PM

  • icon-size="2x", multi-para
    Screenshot 2020-01-30 at 10 02 02 PM

  • icon-size="2x", multi-para, no heading, not dismissible
    Screenshot 2020-01-30 at 10 05 48 PM

Copy link

@acjh acjh left a comment

Choose a reason for hiding this comment

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

Thanks for your changes. We can clean up a little.

src/TipBox.vue Outdated
<div v-if="!isDefault && !iconSize" class="icon-wrapper">
<span v-html="iconType"></span>
</div>
<div v-if="!isDefault && iconSize" class="icon-wrapper" :class="`fa-${iconSize}`" >
Copy link

Choose a reason for hiding this comment

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

Let's do as done with lightStyle:

<div v-if="!isDefault" class="icon-wrapper" :class="[iconStyle]">

src/TipBox.vue Outdated Show resolved Hide resolved
src/TipBox.vue Outdated Show resolved Hide resolved
src/TipBox.vue Outdated
@@ -1,6 +1,6 @@
<template>
<div class="alert container" :class="[boxStyle, addClass, lightStyle]" :style="customStyle">
<div v-if="!isDefault" class="icon-wrapper">
<div v-if="!isDefault" class="icon-wrapper" :class="[`fa-${iconSize}`]" >
Copy link

Choose a reason for hiding this comment

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

Wouldn't this result in class="fa-null" if iconSize not specified?

Copy link
Author

Choose a reason for hiding this comment

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

Fixed

src/TipBox.vue Outdated
@@ -1,6 +1,6 @@
<template>
<div class="alert container" :class="[boxStyle, addClass, lightStyle]" :style="customStyle">
<div v-if="!isDefault" class="icon-wrapper">
<div v-if="!isDefault" class="icon-wrapper" :class="`${iconSize ? `fa-${iconSize}`: ''}`" >
Copy link

Choose a reason for hiding this comment

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

Let's do as done with lightStyle as suggested in #124 (comment):

<div v-if="!isDefault" class="icon-wrapper" :class="[iconStyle]">

src/TipBox.vue Outdated
@@ -1,6 +1,6 @@
<template>
<div class="alert container" :class="[boxStyle, addClass, lightStyle]" :style="customStyle">
<div v-if="!isDefault" class="icon-wrapper">
<div v-if="!isDefault" class="icon-wrapper" :class="[iconStyle]" >
Copy link

Choose a reason for hiding this comment

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

Remove stray whitespace:

Suggested change
<div v-if="!isDefault" class="icon-wrapper" :class="[iconStyle]" >
<div v-if="!isDefault" class="icon-wrapper" :class="[iconStyle]">

src/TipBox.vue Outdated
}
}
}
}
Copy link

Choose a reason for hiding this comment

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

  • Misplaced closing brace.
  • Missing default return value.
      iconStyle() {
        if (this.iconSize) {
          return `fa-${this.iconSize}`;
+       }
+       return '';
      }
    }
  }
- }

Copy link
Member

@yamgent yamgent left a comment

Choose a reason for hiding this comment

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

Remember to update the docs in the MarkBind repo.

@yamgent yamgent merged commit 94ca196 into MarkBind:master Feb 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
4 participants