New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

react-configured

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-configured

Configure react components with default props and styles

latest
npmnpm
Version
0.0.1-alpha
Version published
Weekly downloads
4
300%
Maintainers
1
Weekly downloads
 
Created
Source

react-configured

npm package License: MIT

Configure react components with default props and styles

Installation

Using npm

npm install react-configured

Using yarn

yarn add react-configured

Usage example (React Native)

import { ElementType } from 'react';
import configured, { PartialProps } from 'react-configured';

export const mergePropsWithStyle = <T extends ElementType,
  TProps extends PartialProps<T>,
  TSecondProps extends PartialProps<T>,
  >(
  baseProps: TProps,
  variantProps: TSecondProps,
): TProps | TSecondProps => ({
  ...baseProps,
  ...variantProps,
  ...('style' in baseProps && 'style' in variantProps
    ? {
      style: StyleSheet.compose(baseProps.style, variantProps.style),
    }
    : {}),
});

export type ButtonConfig = ComponentConfig<typeof BaseButton>;

export type FuncButtonConfig = FuncComponentConfig<typeof BaseButton, ButtonConfig>;

export const Button = configured(BaseButton, (props): ButtonConfig => {
  const theme = useUIKitTheme();

  const { disabled, variant } = props;

  const styles = StyleSheet.create({
    baseStyle: {
      height: 54,
      paddingHorizontal: 16,
      borderRadius: 12,
      justifyContent: 'center',
      alignItems: 'center',
      flexDirection: 'row',
      borderStyle: 'solid',
      borderWidth: 0,
    },
    disabled: {
      backgroundColor: theme.colors.gray['5'],
    },
    disabled__text: {
      color: theme.colors.gray['3'],
    },
    'variant:primary': {
      backgroundColor: theme.colors.primary,
    },
    'variant:primary__text': {
      color: theme.colors.white,
    },
    'variant:secondary': {
      backgroundColor: theme.colors.white,
      borderWidth: 1,
      borderColor: theme.colors.gray['5'],
    },
    'variant:secondary__text': {
      color: theme.colors.black['2'],
    },
  });

  return {
    style: StyleSheet.flatten([
      styles.baseStyle,
      variant === 'primary' ? styles['variant:primary'] : styles['variant:secondary'],
      disabled && styles.disabled,
    ]),
    loaderColor: theme.colors.white,
    activeOpacity: 0.85,
    labelProps: {
      variant: 'p3',
      style: [styles['variant:primary__text'], disabled && styles.disabled__text],
    },
  };
}, { mergeProps: mergePropsWithStyle });

Keywords

react

FAQs

Package last updated on 16 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts