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

Improve shorthands for component that contains collection shorthands #984

Closed
mnajdova opened this issue Feb 27, 2019 · 0 comments · Fixed by #996
Closed

Improve shorthands for component that contains collection shorthands #984

mnajdova opened this issue Feb 27, 2019 · 0 comments · Fixed by #996
Labels
vsts Paired with ticket in vsts

Comments

@mnajdova
Copy link
Contributor

mnajdova commented Feb 27, 2019

Feature Request

Problem description

When we are using components that contains collection of other components (like Menu, or some group components - ButtonGroup), we should provide different processing of the shorthand if an array is provided. For example, let's take a look on the actionMenu prop in the ChatMessage:

<ChatMessage 
  author='John Doe' 
  timestamp='27/2' 
  actionMenu={{items: ['like', 'dislike']}} 
  content='Content of the message'
/>

This is not really user friendly API, as the actionMenu should probably be referred as actions. Moreover the user has to create an object with the items as a key to finally define the actions they want to have on the ChatMessage.

Proposed solution

Much clear API for achieving the same thing, would be the following:

<ChatMessage 
  author='John Doe' 
  timestamp='27/2' 
  actions={['like', 'dislike']}
  content='Content of the message'
/>

With this the user should be able to define the same thing as above. Furthermore, if they want to customize the menu, they can still use the same old object for defining the Menu:

<ChatMessage 
  author='John Doe' 
  timestamp='27/2' 
  actions={{items: ['like', 'dislike'], vertical: true}}
  content='Content of the message'
/>

For this to work, we may add additional parameter to the createShorthandFactory, that will handle arrays, the same way as we currently handle the string literals. The signature would be something like this:

Menu.create = createShorthandFactory(
  Menu, 
  'children', /* what is the default prop when string is passed */
  'items' /* what is the default prop when array is passed */
)
ButtonGroup.create = createShorthandFactory(
  ButtonGroup, 
  'content', /* what is the default prop when string is passed */ 
  'buttons' /* what is the default prop when array is passed */
)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
vsts Paired with ticket in vsts
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants