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

Suggestion: global custom attributes #19910

Open
jsenaribeiro opened this issue Sep 25, 2020 · 1 comment
Open

Suggestion: global custom attributes #19910

jsenaribeiro opened this issue Sep 25, 2020 · 1 comment

Comments

@jsenaribeiro
Copy link

@jsenaribeiro jsenaribeiro commented Sep 25, 2020

Hi,

I would like to suggest this new feature that may be useful: a custom global attribute as a DRY and KISS feature for sharing some repetitive coding or verbose styling. It is a bit familiar to Angular directive concept, but it is more functional and react-like.

  • alternative 1: using @ token in component attribute working as a function injetor
const glyphIcon = (elm, val) => elm.className = "glyphicon glyphicon-" + val + " icon";

<div @glyphIcon="ok" >...</div>
  • alternative 2: function decorators (not support in ecmascript) would be nice for kebab-case notation
@directive("glyph-icon")
const glyphIcon = (elm, val) => elm.className = "glyphicon glyphicon-" + val + " icon";

<div glyph-icon="ok" >...</div>
@vkurchatkin
Copy link

@vkurchatkin vkurchatkin commented Sep 25, 2020

That is something you can already do:

const glyphIcon = (val) => ({ className: "glyphicon glyphicon-" + val + " icon" });

<div {...glyphIcon("ok")} >...</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.