Skip to content

Feature idea: easy classNames #6

@staltz

Description

@staltz

One feature I like in hyperscript is the ability to easily write the className using CSS selectors:

h('div.foo'), not h('div', {className: 'foo'}).

In Cycle.js, it's also convenient to have the . dot there, because later the classes are used in selectors, e.g. DOM.select('.foo').events('click'). So it's not great if sometimes you need the dot, and sometimes you don't (in className), that's why I like hyperscript keeping it consistent.

Proposal:
How about allowing a string parameter to the hyperscript helper? If the first parameter is a string, then it's interpreted as the selector, so its classes will be parsed out in hyperscript. If the first parameter is an object, we know its the properties object.

E.g.
div('.foo') instead of div({className: 'foo'}).

Of course one would be able to still provide properties and children:

div('.foo', {'data-id': 'headline-6.1.2'}, [
  img({src: user.avatar})
])

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions