Latest Socket ResearchMalicious Chrome Extension Performs Hidden Affiliate Hijacking.Details
Socket
Book a DemoInstallSign in
Socket

c5-test-library

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

c5-test-library

component library for react

latest
Source
npmnpm
Version
0.0.1
Version published
Maintainers
1
Created
Source

c5cl

License: MIT CircleCI codecov

Installation:

npm install c5cl

Usage:

import React from 'react';
import {Button} from 'c5cl';

function App(){
  return <Button label="click me" />
}

export default App;

There are a number of helper utilites, example usage: formateDate: takes a string or a date and returns a string representation of only the date. formatMoney: fixes issues with money values that only have a decimal precision of 1. isValid: return true or false depending on the existence of a string, a number that is not zero, or an object with keys.

import {formatDate, formatMoney, isValid} from 'c5cl';

isValid(null);
// returns false
isValid(undefined)
// returns false
isValid('hello')
// returns true
isValid({name: 'mike'})
// returns true
isValid({})
// returns false

formatDate('1/1/2022 2:00 PM')
// returns '1/1/2022'

formatMoney('1.1')
// returns '$1.10

TextInput example usage:

import {TextInput} from 'c5cl';

return (
  <TextInput 
    id="someid"
    name="somename"
    label="somelabel"
    placeholder="some placeholder"
    onChange={(e) => console.log(e.target.value) }
    type="text"
    value="someValue"
    error="This field is required"
  />
)

SelectField example usage:

import {SelectField} from 'c5cl';

const states = [
  {abbr: 'AL', name:'Alabama'},
  {abbr: 'TN', name: 'Tennessee'}
]

return (
  <SelectField 
    id="someid"
    name="somename"
    label="somelabel"
    displayField="name"
    valueField="abbr"
    onChange={(e) => console.log(e.target.value)}
    emptyMsg="Please select a state"
    data={states}
    error="This field is required"
  />
)

RippleButton usage: Color, HoverColor, and TextColor are optional.

  import {RippleButton} from 'c5cl';

  return (
    <RippleButton 
      text="Click Me" 
      onClick={() => console.log('I have been clicked')}
      color={'#de34eb'}
      hoverColor={'#bb5bc2'}
      textColor={'#fff'}
    />
  )

DataGrid usage:

  import {DataGrid} from 'c5cl';

  const testData = [
  {
    id: 1,
    storeName: 'IGA 001',
    storeNumber: '001',
    termCount: 3,
  },
  {
    id: 2,
    storeName: 'IGA 002',
    storeNumber: '002',
    termCount: 4,
  },
  {
    id: 3,
    storeName: 'IGA 003',
    storeNumber: '003',
    termCount: 6,
  },
];

  return (
    <DataGrid 
      data={testData}
      identifier={'grid1'}
      headers={[
          {
            columnName: 'id',
            title: 'ID',
            visible: true,
            style: {
              textAlign: 'center',
            },
          },
          {
            columnName: 'storeName',
            title: 'Name',
            style: {
              textAlign: 'left',
            },
          },
          {
            columnName: 'storeNumber',
            title: '#',
            style: {
              textAlign: 'center',
            },
          },
        ]}
    />
  )

DataGrid Props:

Prop nameoptionaltypedescription
data[required]arrayarray of data
identifier[required]stringused for the id of the main div
customRenderers[✔]functionfunction used to render images and such
headers[✔]array of objectobject to defined the shape of the header
fill[✔]booleanwhether or not to fill the parent div
style[✔]CSSPropertiesstyle for the main div
className[✔]stringclassName for the main div
tableClassName[✔]stringclassName for the actual table
mode[✔]'light' or 'dark'changes the styles of the entire component

DataGrid Header Props

Prop nameoptionaltypedescription
columnName[required]stringrepresents the name of the column in your data
title[required]stringWhat to display in the column header
sortable[✔]booleancan make this column not sortable. default is true
visible[✔]booleancan make this column invisible. default is true
style[✔]CSSPropertiesthe style for this column. ex: textAlign: 'center'
width[✔]numberpredetermined width for the column
filterable[✔]booleancan make this column not filterable. default is true

Custom Renderers

You can for example add custom Renderers to your grid with an example like so:

const renderers = {
  active: (i: T) => (
    <input type="checkbox" checked={i.active} />;
  ),
  image: (i: T) => {
    return (
      <img
        alt={i.image.name}
        src={i.image.url}
        height={i.image.height}
        width={i.image.width}
      />
    );
  },
};

<DataGrid customRenderers={renderers} />

and then your headers would look like this:


const headers = [
  {
    columnName: 'active',
    title: 'active',
    style: {
      textAlign: 'center',
    },
  },
  {
    columnName: 'image',
    title: 'PinPad',
    style: {
      textAlign: 'center',
    },
  }
]

and your data would look like this:

const testData = [
  {
    id: 1,
    storeName: 'IGA 001',
    storeNumber: '001',
    termCount: 3,
    active: true,
    image: {
      url: 'https://www.someurl.com/_images/pinpadlogos/l5300.png',
      name: 'l5300',
      height: '20',
      width: '30',
    },
  },
]

so your columnName needs to match the name of the renderer

note: The error field in both components is used for when the form validation fails, you can send in a unique error message to each element of your form.

If for some reason you are using CRA and are getting an error about not being able to find source maps, this is a known issue with Webpack5 and is being address. The workaround is to add this to your .env file:

GENERATE_SOURCEMAP=false

DataGrid Todos

  • [✔] work on row colors based on the color that might be passed in
  • [✔] figure out how to center the column text
  • [✔] make each column sortable
  • [✔] make columns hidden
  • [✔] make column filterable by the unique values that are displayed for that column
  • [✔] make columns draggable 🚀
  • [✔] enable light and dark mode
  • [✔] change column hiding to be enabled by right clicking
  • [✔] fix column widget vertical placement
  • [✔] fix filter widget vertical placement
  • fix custom renderers

Some ideas for extra components

  • Toasts
  • Data Picker
  • Tooltips
  • [✔] Slider
  • any other thoughts
  • TreeViewer
  • Carousel

FAQs

Package last updated on 15 Mar 2022

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