mrzachnugent / react-native-reusables

Universal shadcn/ui for React Native featuring a focused collection of components - Crafted with NativeWind v4 and accessibility in mind.
https://rnr-docs.vercel.app
MIT License
3.91k stars 157 forks source link

[ FEATURE ] Pass text classNames to `TextClassContext.Provider` #266

Closed izakfilmalter closed 4 weeks ago

izakfilmalter commented 4 weeks ago

Would be great to extract the text classNames and pass them to TextClassContext.Provider within button:

const Button = forwardRef<ElementRef<typeof Pressable>, ButtonProps>(
  ({ className = '', variant, size, ...props }, ref) => {
    return (
      <TextClassContext.Provider
        value={buttonTextVariants({
          variant,
          size,
          className: cn(
            'web:pointer-events-none',
            pipe(
              className,
              String.split(' '),
              Array.filter(String.includes('text-')),
              Array.join(' ')
            )
          ),
        })}
      >
        <Pressable
          className={cn(
            props.disabled && 'opacity-50 web:pointer-events-none',
            buttonVariants({ variant, size, className })
          )}
          ref={ref}
          // biome-ignore  lint/a11y/useSemanticElements: this is a button
          role='button'
          {...props}
        />
      </TextClassContext.Provider>
    )
  }
)

Sorry for the effect code, can easily do this in vanilla as well. This change helps button behave more like you expect, letting you easily customize the text attributes. The con is that it doesn't cover whitespace and some other text props.

mrzachnugent commented 4 weeks ago

Hey @izakfilmalter, react-native-reusables is made to be a starting point to make the components exactly as you need them. For that reason, we will not be adding this but I strongly suggest that you add this in the Discussions section as I'm sure a some people might want to use this in their codebase.