crutch12

ParamType.tsx

Oct 14th, 2021 (edited)
407
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { LIGHT_THEME } from '@vtb/ui-kit3';
  2. import cn from 'classnames';
  3. import React from 'react';
  4. import styled, { css } from 'styled-components';
  5.  
  6. const lightPalette = LIGHT_THEME.color;
  7.  
  8. export type TagLightVariant = keyof typeof variantStyles;
  9.  
  10. export interface ParamTypeProps {
  11.   title?: string;
  12.   className?: string;
  13.   children?: React.ReactNode;
  14.   variant?: TagLightVariant;
  15.   textColor?: keyof typeof lightPalette.text;
  16.   theme?: typeof LIGHT_THEME;
  17. }
  18.  
  19. const ParamType: React.FC<ParamTypeProps> = ({
  20.   children,
  21.   className,
  22.   variant = 'outline',
  23.   textColor = 'staticWhite',
  24.   ...props
  25. }) => {
  26.   return (
  27.     <InnerTag className={cn(className, variant && variantStyles[variant])}>
  28.       <Overflow textColor={textColor} {...props}>
  29.         {children}
  30.       </Overflow>
  31.     </InnerTag>
  32.   );
  33. };
  34.  
  35. const maxWidth = 400;
  36. const InnerTag = styled.span`
  37.   display: inline-flex;
  38.   box-sizing: border-box;
  39.   flex-wrap: wrap;
  40.   align-items: center;
  41.   font-size: 12px;
  42.   line-height: 16px;
  43.   padding: 0 8px; /* + 1px border */
  44.   height: 16px;
  45.   border-radius: 3px;
  46.   box-shadow: 0 0 0 2px #fff;
  47. `;
  48. const Overflow = styled.span<Pick<ParamTypeProps, 'textColor'>>`
  49.   font-style: normal;
  50.   display: inline-block;
  51.   max-width: ${maxWidth}px;
  52.   white-space: nowrap;
  53.   overflow: hidden;
  54.   text-overflow: ellipsis;
  55.   color: ${(props) => lightPalette.text[props.textColor ? props.textColor : 'primary']};
  56.   border-radius: 4px;
  57. `;
  58.  
  59. const variantStyles = {
  60.   outline: css`
  61.     background-color: ${lightPalette.background.tertiary};
  62.   `,
  63.   neutral: css`
  64.     background-color: ${lightPalette.background.tertiary};
  65.   `,
  66.   processing: css`
  67.     background-color: ${lightPalette.special.blue};
  68.   `,
  69.   success: css`
  70.     background-color: ${lightPalette.status.success};
  71.   `,
  72.   confirmed: css`
  73.     background-color: ${lightPalette.special.lightBlue};
  74.   `,
  75.   warning: css`
  76.     background-color: ${lightPalette.status.warn};
  77.   `,
  78.   error: css`
  79.     background-color: ${lightPalette.special.red};
  80.   `,
  81. };
  82.  
  83. export default ParamType;
  84.  
Add Comment
Please, Sign In to add comment