Skip to content

Question: How can I provide multiple variants a props to a custom component that uses multiple RestyleComponents? #95

@alexanderblackh

Description

@alexanderblackh

I've created a custom Button component that looks like the following:

export interface ButtonProps {
  label?: string;
  onPress: () => any;
}

type iProps = SpacingProps<Theme> &
  BorderProps<Theme> &
  BackgroundColorProps<Theme> &
  ButtonProps &
  VariantProps<Theme, 'buttonVariants'>;

const variant = createVariant<Theme>({
  themeKey: 'buttonVariants',
  defaults: {
    color: 'testColor',
    margin: {
      phone: 's',
      tablet: 'm',
    },
    backgroundColor: 'mainForeground',
  },
});

const Button = ({onPress, label, ...props}: iProps): JSX.Element => {
  const restyledProps = useRestyle([variant as any], props);

  return (
    <TouchableOpacity onPress={onPress}>
      <Box
        justifyContent="center"
        alignItems="center"
        {...restyledProps}>
        <Text variant="button">{label}</Text>
      </Box>
    </TouchableOpacity>
  );
};

How can I make it so that when I call <Button variant="primary" ... /> I can do:
<Button variant="primary" textVariant="button2" ..../>

I know I could do it manually on the ButtonProps interface, but I'd like a more intelligent way of doing this dynamically.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions