Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional tag name #44

Open
droganov opened this issue Jun 15, 2015 · 0 comments
Open

Conditional tag name #44

droganov opened this issue Jun 15, 2015 · 0 comments

Comments

@droganov
Copy link

Hello.
I'm working on md-button component. It has a condition — normally it should be rendered as a button element, but if href attribute is provided it should be rendered as an anchor.

How can I optimise the below template and either get rid of conditional statement or avoid atrributes copy/pasting?

View:

<index: element="md-button">
    {{ if @href }}
        <a 
            class="md-button {{ @class }} {{ disabledClass }}"
            href="{{ @href }}"
            role="{{ @role }}"
            tabindex="{{ @tabindex }}"
            target="{{ @target }}"
            title="{{ @title }}"

            on-click="handleClick($ev, $el)"
            on-dblclick="handleDblclick($ev, $el)"

            on-mousedown="handleMousedown($ev, $el)"
            on-mouseup="handleMouseup($ev, $el)"
            on-mouseover="handleMouseover($ev, $el)"
            on-mouseout="handleMouseout($ev, $el)"

            on-focus="handleFocus($ev, $el)"
            on-blur="handleBlur($ev, $el)"
        >
            <span class="md-button__label">{{ @content }}</span>
            <md-ripple />
        </a>
    {{ else }}
        <button 
            class="md-button {{ @class }} {{ disabledClass }}"
            disabled="{{ @disabled }}"
            role="{{ @role }}"
            tabindex="{{ @tabindex }}"
            title="{{ @title }}"
            type="{{ @type }}"

            on-click="handleClick($ev, $el)"
            on-dblclick="handleDblclick($ev, $el)"

            on-mousedown="handleMousedown($ev, $el)"
            on-mouseup="handleMouseup($ev, $el)"
            on-mouseover="handleMouseover($ev, $el)"
            on-mouseout="handleMouseout($ev, $el)"

            on-focus="handleFocus($ev, $el)"
            on-blur="handleBlur($ev, $el)"
        >
            <span class="md-button__label">{{ @content }}</span>
            <md-ripple />
        </button>
    {{ / }}
@droganov droganov changed the title How to optimise a component view? Conditional tag name Jun 15, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant