Fluid Commons
Commonly used react components with Fluid-Func and Redux support.
Getting Started
Installation
npm install --save fluid-commons
Fluid-api
- Fluid Api configuration
; const config = environment: production: paramForProd: 'hey' development: paramForDev: 'hey dev' catch: { //catches child's component error } { //catches api call error } storage: // provides a temporary storage across the application production: {} development: {} // production: new Promise() - can be written in Promise // production: ()=>{} - can be writting in Function // accessible via FluidApi.storage(context, action); ; const Api = saveAction: { const forProd = param; // forProd = "hey" } { const forDev = param; // forDev = "hey dev" } ; { return <FluidApi environment="production" config=config api=Api> <div> content here </div> </FluidApi>; }
- To call an api method
FluidApi;
- To access the storage
/* storage: { development: { person: { name:'John' }, people: [ { name:'John' }, { name:'Mary' } ] }, } */ FluidApi; FluidApi; FluidApi ; FluidApi ; FluidApi ; FluidApi ;
Fluid-button
- Works like a normal html button with the same react attributes as Button but with fluid-func trigger.
; ; FluidFunc; { return <div> <FluidButton action="saveAction" data=input:'Hello from button!'>Save</FluidButton> </div>; }
Fluid-form (requires redux)
; const specs = { return field:'fullname' data: // see fluid-func's tranform, translate and validate field:'occupation' data: // see fluid-func's tranform, translate and validate ; }; const onSubmit = { const fullname occupation = value; } const onFailed = { const stackId error = fluidFuncError; //error.message = "error message" }; { return <FluidForm onFailed=onFailed onSubmit=onSubmit name="mainForm" specs={}> <input name="fullname"/> <input name="occupation"/> <button type="submit">Submit</button> </FluidForm>; }
Note: Form name is required.
- Using FluidFormReducer
; const rootReducer = ;
- Create a container for FluidForm
; ; ; Component { superprops; this { return field:'fullname' data: // see fluid-func's tranform, translate and validate field:'occupation' data: // see fluid-func's tranform, translate and validate ; } } { } { } { <FluidForm specs=specs name="mainForm" onSubmit=thisonSubmit onFailed=thisonFailed></FluidForm> } { return mainForm: statefluidFormmainForm || data: {} ; } const ConnectedFormSample = FormSample;
- To clear form fields
FluidFormclear'mainForm'; // form name
- To submit form
FluidForm;// form name
- To load data to form
FluidForm;
- To set value to a specific field
FluidForm;
- To listen to changes of a specific field
FluidForm;
Note: To enable these functionalities "fullname" must be tagged as public. See below:
this { return field:'fullname' data: // see fluid-func's tranform, translate and validate public: true field:'occupation' data: // see fluid-func's tranform, translate and validate ; }
Fluid-input
; const data = fullname: 'John Doe' occupation: 'Programmer' ; { return <FluidForm onFailed=onFailed onSubmit=onSubmit name="mainForm" specs={}> <FluidInput dataSrc=data name="fullname"/> <FluidInput dataSrc=data name="occupation"/> <button type="submit">Submit</button> </FluidForm>;
Fluid-label
; FluidLabel; return <div><FluidLabel locale="en" label="appName" name="mainLabel"/></div>;
- Get label using .get static method
FluidLabel; // app name in en
Fluid-merged-view
Coming soon.
Fluid-paginate
Coming soon.
Fluid-table
Coming soon.