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

Feat: Allow text styling in Segmented Button's label

Open fwielstra opened this issue 2 years ago • 1 comments

Is your feature request related to a problem? Please describe.

We would like to add support for 'rich text' to the SegmentedButtons control, so that parts of the text can be given a different font weight. This should also depend on selection state

Describe the solution you'd like

  1. Change the type of the label property from string to ReactNode
  2. Alternatively, add an optional LabelComponent or renderLabel callback that returns a react component, which is passed the relevant props. We'd also need a way to pass our custom 'sublabel' property then.

Describe alternatives you've considered

  • Copy / pasting the component into our own project and making the adjustments ourselves, but there's a lot of internal dependencies that we'd have to copy as well.

Additional context

Here's what our designer would like to see possible:

image

Note the bold "Stroom" vs the regular "(kWh)"

And more variants, with and without icons, selected / deselected, and disabled states:

image

All these are mostly possible already, bar the bold text style. For now we'll give feedback to the developer that it's not possible yet. I can have a go at submitting a PR myself if I can find some headspace to work on it.

fwielstra avatar Sep 20 '23 12:09 fwielstra

I second this

SOLUTION: pass in a component to label and pass it your own styles

{
  label: <em style={styles.myLabel}>{myText}</em>
}

nickkhall avatar Dec 04 '23 15:12 nickkhall