question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[feat] Sorting component or element props

See original GitHub issue

Is your feature request related to a problem? Please describe. To make it clean I always try to sort the props, event handlers, actions and so on in a consistent way. Manually, of course. Wouldn’t it be cool to do it automatically?

Describe the solution you’d like It would be super nice if this plugin could sort the props automatically with some rules, like: class, shorthand conditional class, conditional class, shorthand props, key props, actions without params, actions with params, forwarding events, handling events and, eventually, CSS vars. Maybe it would be cool to also sort them alphabetically as well. It would also be nice if it automatically grouped all these properties with an extra newline (now it removes all of them).

It would turn a messy element (real-world example, btw), like

<input
  class="input"
  class:is-success={field.isBlurred && field.isValid}
  type={field.type}
  {id}
  value={field.inputValue || ''}
  disabled={field.disabled || $formStore.formDisabled}
  placeholder={field.placeholder}
  readonly={field.readonly}
  aria-label={field.label}
  autocomplete={field.enableAutocomplete ? '' : 'off'}
  on:input={onInput}
  use:clearOnEscape
  class:is-danger={field.isBlurred && !field.isValid}
  on:blur />

into this beautiful thing:

<input
  class="input"
  class:is-success={field.isBlurred && field.isValid}
  class:is-danger={field.isBlurred && !field.isValid}
  
  {id}
  autocomplete={field.enableAutocomplete ? '' : 'off'}
  aria-label={field.label}
  disabled={field.disabled || $formStore.formDisabled}
  placeholder={field.placeholder}
  readonly={field.readonly}
  type={field.type}
  value={field.inputValue || ''}
  
  use:clearOnEscape

  on:blur 
  on:input={onInput} />

Describe alternatives you’ve considered Just do it manually.

How important is this feature to you? Not that much, but would be a very cool addition!

Additional context

  1. I’m not sure it is in the scope of the project at all
  2. I’m not sure if changing the order doesn’t have any side effects. Afaik, it is common to make templates pure-ish so they don’t change the state, but a user can still call some functions that make the order of props kind if important. I would think it is a very bad pattern but still it’s not prohibited.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:3
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
dummdidummcommented, Dec 10, 2021

I don’t think we can make this an option, because the order matters and there’s no good way to tell the user’s intent - see the last section in https://svelte.dev/docs#bind_element_property .

3reactions
pngwncommented, Nov 12, 2020

It is okay to be opinionated as long as those opinions are correct, which is to say, they agree with mine. 👹

I personally think all component should look like upside down Christmas tree.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React.js - Implementing sorting of components - Stack Overflow
Attach a function to each <div/> in <Sort/> on clicking which it calls a parent function this.props.sortBy() class Sort extends React.
Read more >
Creating Sortable Tables With React - Smashing Magazine
In this article, we're going to implement all you need to sort out all of your table ... First, let's create a sample...
Read more >
Sort React Components Using .sort() - In Plain English
A guide on the process of rendering child components from an array of objects and creating a Sort button using React.
Read more >
Controls - Storybook - JS.ORG
It creates an addon panel next to your component examples ("stories"), so you can edit them live. Controls do not require any modification...
Read more >
pcmli.umbrella.web-ui - npm
#umbrella.web-ui. This is the repository for the common code web-ui using reactjs. ####Change Logs #####v. 13.6.1. (feat) Added the range slider control.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found