react-native-paper icon indicating copy to clipboard operation
react-native-paper copied to clipboard

New component: SegmentedButton

Open okwasniewski opened this issue 3 years ago • 20 comments
trafficstars

This PR introduces new component named: SegmentedButton.

Summary

General overview of the component: https://m3.material.io/components/segmented-buttons/overview

Highlights:

  • single or multi-selection
  • segmented buttons can have 2-5 segments, segments cannot wrap into a new line
  • icons can be used in place of labels
  • icon next to the label is optional

Screenshots

Version 3

ios android
Screenshot 2022-08-08 at 11 32 58 Screenshot 2022-08-08 at 11 32 52

Version 2

ios android
Screenshot 2022-08-08 at 11 33 23 Screenshot 2022-08-08 at 11 33 21

Test plan

Write tests for this component.

okwasniewski avatar Jul 30 '22 18:07 okwasniewski

The mobile version of example app from this branch is ready! You can see it here

.

github-actions[bot] avatar Jul 30 '22 18:07 github-actions[bot]

Hey @okwasniewski, thank you for your pull request 🤗. The documentation from this branch can be viewed here.

callstack-bot avatar Jul 30 '22 18:07 callstack-bot

The mobile version of example app from this branch is ready! You can see it here

.

github-actions[bot] avatar Jul 30 '22 18:07 github-actions[bot]

The mobile version of example app from this branch is ready! You can see it here

.

github-actions[bot] avatar Aug 01 '22 20:08 github-actions[bot]

The mobile version of example app from this branch is ready! You can see it here

.

github-actions[bot] avatar Aug 02 '22 08:08 github-actions[bot]

The mobile version of example app from this branch is ready! You can see it here

.

github-actions[bot] avatar Aug 02 '22 14:08 github-actions[bot]

The mobile version of example app from this branch is ready! You can see it here

.

github-actions[bot] avatar Aug 03 '22 11:08 github-actions[bot]

The mobile version of example app from this branch is ready! You can see it here

.

github-actions[bot] avatar Aug 03 '22 11:08 github-actions[bot]

The mobile version of example app from this branch is ready! You can see it here

.

github-actions[bot] avatar Aug 03 '22 12:08 github-actions[bot]

The mobile version of example app from this branch is ready! You can see it here

.

github-actions[bot] avatar Aug 03 '22 13:08 github-actions[bot]

The mobile version of example app from this branch is ready! You can see it here

.

github-actions[bot] avatar Aug 03 '22 13:08 github-actions[bot]

The mobile version of example app from this branch is ready! You can see it here

.

github-actions[bot] avatar Aug 03 '22 14:08 github-actions[bot]

The mobile version of example app from this branch is ready! You can see it here

.

github-actions[bot] avatar Aug 04 '22 10:08 github-actions[bot]

The mobile version of example app from this branch is ready! You can see it here

.

github-actions[bot] avatar Aug 07 '22 15:08 github-actions[bot]

The mobile version of example app from this branch is ready! You can see it here

.

github-actions[bot] avatar Aug 07 '22 17:08 github-actions[bot]

The mobile version of example app from this branch is ready! You can see it here

.

github-actions[bot] avatar Aug 08 '22 12:08 github-actions[bot]

The mobile version of example app from this branch is ready! You can see it here

.

github-actions[bot] avatar Aug 08 '22 16:08 github-actions[bot]

The mobile version of example app from this branch is ready! You can see it here

.

github-actions[bot] avatar Aug 10 '22 07:08 github-actions[bot]

The mobile version of example app from this branch is ready! You can see it here

.

github-actions[bot] avatar Aug 11 '22 07:08 github-actions[bot]

The mobile version of example app from this branch is ready! You can see it here

.

github-actions[bot] avatar Aug 14 '22 11:08 github-actions[bot]

The mobile version of example app from this branch is ready! You can see it here

.

github-actions[bot] avatar Aug 14 '22 11:08 github-actions[bot]

@satya164 Thanks for your feedback 👍 I have a few questions about what to do next with this component.

I'm not sure about the API of SegementedButton and SegmentedButton.Group given that SegementedButton cannot be used on its own similar to other components which have individual components as well as a group component.

It's more similar to the FAB.Group component. Probably it's better to have a single component that takes an array of items instead of having a group and children.

You are right, this component is not consistent with others (like ToggleButton and ToggleButton.Group) and it would be misleading. There are two options: allow it to be used without SegmentedButton.Group or refactor the API to pass array of items.

First option is pretty straight forward just remove the context check. This approach maybe useful for people who want to customize and implement their own logic for handling the checked state.

Second approach would make the component easier to use, however less customizable - I'm not sure which one is better.

Regarding the second approach implementation: Should I just change the Children.map inside SegmentedButton.Group to map an array of passed items? Then rename the SegmentedButton.Group to a SegmentedButton and remove the current SegmentedButton export (to use it only internally) or how you would go about it?

cc: @lukewalczak @Drakeoon - What do you guys think?

okwasniewski avatar Aug 14 '22 12:08 okwasniewski

The mobile version of example app from this branch is ready! You can see it here

.

github-actions[bot] avatar Aug 14 '22 12:08 github-actions[bot]

The mobile version of example app from this branch is ready! You can see it here

.

github-actions[bot] avatar Aug 15 '22 14:08 github-actions[bot]

The mobile version of example app from this branch is ready! You can see it here

.

github-actions[bot] avatar Aug 15 '22 14:08 github-actions[bot]

I can agree with @satya164, that we can change the API since SegmentedButton isn't an individual component. Imo I would prefer the approach of removing the context check rather than passing an array with items.

lukewalczak avatar Aug 15 '22 19:08 lukewalczak

After internal discussion we decided to refactor the component API to pass the items array. Using the SegmentedButton component without group doesn't make sense. Current SegmentedButton export will be removed and used only internally and SegmentedButton.Group will be renamed to SegmentedButtons.

okwasniewski avatar Aug 16 '22 07:08 okwasniewski

The mobile version of example app from this branch is ready! You can see it here

.

github-actions[bot] avatar Aug 20 '22 16:08 github-actions[bot]

The mobile version of example app from this branch is ready! You can see it here

.

github-actions[bot] avatar Aug 20 '22 17:08 github-actions[bot]

The mobile version of example app from this branch is ready! You can see it here

.

github-actions[bot] avatar Aug 20 '22 17:08 github-actions[bot]