1.0.17 • Published 6 years ago

react-charges-table v1.0.17

Weekly downloads
74
License
-
Repository
github
Last release
6 years ago

react-charges-table

It is a Material UI based React Component that helps in maintaining Charges Tables.

Checkout the demo here.

Installation

npm install react-charges-table

Usage

import  ChargesTable  from  'react-charges-table'

<ChargesTable
   ref={(node) => {
	  this.chargesTable = node
   }}
   chargesConfig={sampleData.chargesConfig}
   currencyCode="$"
   hideDivider={false}
   formatValue={(value) => Math.round(value)}
   listContainerStyle={{ minWidth: '350px', maxWidth: '500px', minHeight: '150px' }}
/>

Make sure your app is wrapped inside <MuiThemeProvider> which you can import like this: import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider'.

Check out App.js for example.

Props

PropProp TypeDefault ValueisRequiredDescription
chargesConfigArray<ChargesConfig>[]trueCharges Config.
currencyCodestring / Node''falseCurrency code string or node that will be shown to the left of the charge field.
listContainerStyleObject{}falseWill override default list container styling.
onChargeChange(updatedChargesConfig: Array<ChargesConfig>) => void() => []falseWill be called everytime a charge has been changed. Will be called with the updated charges config.
hideDividerbooleanfalsefalseIf set will hide the divider after each row.
dividerStyleObject{}falseWill override the default divider styling.
formatValue(oldValue: number) => number(v: number): number => vfalseWill be called when a value has been changed. Has to return a number that will be used for setting the value of the charge.
totalLabelstringTotalfalseString that will be used as a label for the total field.
hideTotalbooleanfalsefalseIf set will hide the total field from the charges table.
totalFieldNamestringtotalfalseString that will be used as the name of the total object in the charges config.
maskstring#falseString that will be used to mask the value. For instance #.00 displays 12345 as 123.45 or $ #.00 displays 12345 as $ 123.45 For more information check out string-mask about how to write masks.
precisionnumber0falseNumber that represents to what precision should the value be processed.

Functions

Function NameFunction TypeDescription
getCharges() => Array<ChargesConfig>Returns the current list of charges.
getTotal() => numberReturns the total.

You can find the type of ChargesConfig from the next section.

You have to call these functions using the ChargesTable's ref.

ChargesConfig

type  ChargeConfigType = {
    name: string,
    primaryText: string | Node,
    secondaryText?: string | Node,
    disabled?: boolean,
    value: number,
    chargeRowStyle?: Object,
    rootTextFieldStyle?: Object,
    chargeInputStyle?: Object,
}
KeyDefault ValueisRequiredDescription
name''trueUnique value that will be used to identify the charge in the list.
disabledfalsefalseIf set, will disable editing the charge.
primaryText''trueText or Node that will be rendered as the charge's description.
secondaryText''falseSecondary Text or Node that will be rendered as the charge's description.
value0trueValue of the charge.
chargeRowStyle{}falseOverride the default style of the charge row in the charges list.
rootTextFieldStyle{}falseOverride the inline-styles of the root text element.
chargeInputStyle{}falseOverride the inline-styles of the TextField's input element.
1.0.17

6 years ago

1.0.16

6 years ago

1.0.15

6 years ago

1.0.14

6 years ago

1.0.13

6 years ago

1.0.12

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago