1.0.10 • Published 5 years ago

eternus-react-component v1.0.10

Weekly downloads
14
License
ISC
Repository
github
Last release
5 years ago

Eternus-React-Components

www.eternussolutions.com

eternussolutions

NPM

React components inspired by react-bootstrap.

Available components

  • Dropdown
  • Login Component
  • File Upload
  • Export to Excel
  • Modal Component
  • Menu Component

Install

$npm install eternus-react-component

Dropdown

Usage

import {Dropdown} from "eternus-react-component";

export default class Sample extends Component {

    optionClicked = () => {
        ...
    }

    render() {
        const options = [
               {
                    optionName :"Action 1",
                    onClick:this.optionClicked,
                    Link :"#/action1",
                    icon :"fa fa-arrow-right"
                },
                {
                    ...
                }
           ];
        return (
            <div>;
                <Dropdown
                    title = "Dropdown"
                    variant = "success"
                    dropDirection = "down"
                    options = {options}
                    error = {true}
                    errorMessage = "error message"
                />
            </div>
        )
    }
}

Props

Common props you need to specify include:

PropsDefaultTypeDescription
titleDropdownStringTitle for the dropdown
variantsuccessString 'primary', 'secondary' , 'success' ,'danger' , 'warning' , 'info' , 'dark' , 'light'Color for the dropdown
dropDirectiondownString 'up', 'down', 'left', 'right'Determines the direction and location of the Menu in relation to its toggle
optionsEmpty arrayArray of objectsOption menu for dropdown menu items
errorfalseBooleanAllows the user to trigger an error
errorMessageEmpty StringStringError message to be displayed

Options array object keys

KeyTypeDefaultDescription
optionNameStringName for menu item
onClickFunctionCallback fired when the menu item is clicked
LinkStringhref link associated with menu item
iconStringIcon to be displayed along with menu item name
disabledBooleanfalseDisable the menu item, making it unselectable

Login

Usage

import {Login} from "eternus-react-component";

export default class Sample extends Component {

    onChangeComponent=(e) => {
        ...
    }

    onSubmit =()=>{
        ...
    }

    render() { 
        return (
                <Login
                    title="Login"
                    usernameType="email"
                    usernamePlaceholder="Username" 
                    passwordPlaceholder="Password"
                    buttonTitle="Sign In"
                    onChange={this.onChangeComponent.bind(this)}
                    position="Left"  
                    username ="usernameValue"     
                    passwordName="userPasswordValue"   
                    usernameValue={this.state.usernameValue}
                    userPasswordValue={this.state.userPasswordValue}
                    error={false}
                    errorMessage="Invalid username or password"  
                    onSubmit= {this.onSubmit}  
                />
        )
    }
}

Props

Common props you need to specify include:

PropsDefaultTypeDescription
titleLoginStringTitle for the login page
variantinfoString 'primary', 'secondary', 'success', 'danger', 'warning' , 'info' , 'dark' , 'light'Color for sign in button
usernameTypetextString email, number, textInput type for username field
passwordTypepasswordString passwordInput type for password field
usernamePlaceholderUsernameStringPlaceholder for username field
passwordPlaceholderPasswordStringPlaceholder for password field
buttonTitleSign InStringText for sign in button
onChangeFunctiononChange handler for username and password fields
positioncenterStringcenter,leftPosition for login page title
usernameusernameStringInput name for username field
passwordNamepasswordStringInput name for password field
usernameValueEmpty StringStringValue for username field
userPasswordValueEmpty StringStringValue for password field
forgotPasswordLinkStringRedirect link for forgot password
signUpLinkStringRedirect link for sign up
errorfalseBooleanTrigger error
errorMessageEmpty StringStringError message to be displayed
onSubmitFunctionCallback function to submit the login credentials

File Upload

Usage

import {FileUpload} from "eternus-react-component";

export default class Sample extends Component {

   getFiles = (files) => {
        //console.log("files",files)
    }
  render() {
 
        return (  
				<FileUpload  
					browseButtonTitle = "Browse"
					uploadButtonTitle = "Upload"
					accept = ".xls,.xlsx,.txt"
					size = {1} // size in kb
					multiple = {true}
                    variant = "success"
                    fileResponse = {this.getFiles}
				/> 
        )
    }
}

Props

Common props you need to specify include:

PropsDefaultTypeDescription
browseButtonTitleBrowseStringTitle for the Browse Button
uploadButtonTitleUploadStringTitle for the Upload Button
acceptEmpty StringString ".xls,.xlsx,.txt"Allows the user to restrict file extensions
sizeNumberNumberAllows the user to restrict file size. File size should be in KB
multiplefalseBooleanDefine single or multiple file selection criteria
variantsuccessString 'primary', 'secondary' , 'success' ,'danger' , 'warning' , 'info' , 'dark' , 'light'Color for the Browse and Upload Button
fileResponseFunctionCallback function to recieve uploaded files

File response array structure after upload

[
	{
        name: "fileName.txt",
        lastModified: 1560493560484,
        lastModifiedDate: Fri Jun 14 2019 11:56:00 GMT+0530 (India Standard Time),
        webkitRelativePath: "",
        size: 967
    }
]

Export to excel

Usage

import {ExportToExcel} from "eternus-react-component";

export default class Sample extends Component {

   render() {
        const data= [
            {id : 1, name: 'name1', gender: 'female'},
            {id : 2, name: 'name2', gender: 'female'},
            {id : 3, name: 'name3', gender: 'male'},
            {id : 4, name: 'name4', gender: 'female'},
            {id : 5, name: 'name5', gender: 'male'},
        ]
        return (
            <div>
                <ExportToExcel 
                    variant="success" 
                    title="Export to excel" 
                    data={data} 
                    fileName="dataFile" 
                    sheetName="sheet1"/>
            </div>
        )
    }
}
}

Props

Common props you need to specify include:

PropsDefaultTypeDescription
titleDropdownStringTitle for the export button
variantinfoString 'primary', 'secondary', 'success','danger', 'warning' , 'info' , 'dark' , 'light'Color for the button
dataArray of objects JSONJson data to export to the excel file
fileNameexcelStringFile name for excel file
sheetNamesheet1StringSheet name for the data sheet
extensionxlsxString 'xlsx', 'csv', 'tsv'File extension for export file

Modal Component

Usage

import {Modal} from "eternus-react-component";

export default class Sample extends Component {
     
    this.state = {
            show: false
        }

    handleClose = () => {
        this.setState({
            show: !this.state.show
        });
    }

    handleShow = () => {
        this.setState({
            show: true
        });
    }

   render() {
        return (
            <div>
                <Modal
                        size="md"
                        variant="#FFCC00"
                        modalType="confirm"
                        show={this.state.show} 
                        handleClose={this.handleClose}
                        handleConfirm={this.handleShow}
                        modalHeading="Modal Heading"
                        modalMessage ="Modal Message"
                        confirmButtonText = "Save data"
                        cancelButtonText = "Ok"
                    />
            </div>
        )
    }
}

Props

Common props you need to specify include:

PropsDefaultTypeDescription
variantString Any color codeColor for modal heading background
modalType'message'String 'message' , 'confirm'Modal type for displaying message modal or a confirmation modal
showfalseBooleanShow and hide the modal using this attribute
handleCloseFunctionCallback function for cancel button
handleConfirmFunctionCallback function for confirm button
modalHeadingStringModal heading text to be displayed
modalMessageStringModal message to be displayed
cancelButtonText'Cancel'StringText for cancel button
confirmButtonText'Confirm'StringText for confirm button
size'md'String'sm','md','lg'Size of modal

Menu Component

Usage

import {Menu} from "eternus-react-component";
import eternusLogo from "./eternus.png";
import profile from "./profile.png";
export default class Sample extends Component {
    constructor(props) {
        super(props)
        this.state = {
            searchKey: ''
        };
    }
    onSearchKeyChange = (e) => {
        //...
    }

    onSearch = () => {
        //....
    }

    render() {
            const menuOptions = [{
                    name: "Dashboard",
                    url: "/",
                    icon: "fa fa-tasks"

                },
                {
                    name: "Home",
                    url: "/",
                    icon: "fa fa-home",
                    rootParent: true,
                    children: [{
                        name: "Link1",
                        url: "/",
                        icon: "fa fa-user",
                        children: [
                            //Upto any level
                        ]
                    }],
                }
            ]

            const profileOptions = [{
                name: "Logout",
                url: "#",
                icon: "fa fa-sign-out"
            }]

        return (
            <div>
                {/* --------- For horizontal menu ----------*/}
                <Menu 
                    alignment = "horizontal"
                    menuOptions={menuOptions}
                    logoUrl={eternusLogo}
                    brandName="Eternus"  //optional
                    profileUrl= {profile}
                    searchOption={true}
                    profileOptions={profileOptions}
                    onSearchKeyChange ={this.onSearchKeyChange}
                    searchKey = {this.state.searchKey}
                    onSearch = {this.onSearch} />

                {/* -------- For vertical menu ------------*/}
                <Menu 
                    alignment="vertical" 
                    menuOptions={menuOptions}
                    brandName="Eternus" //optional
                    logoUrl={eternusLogo}
                    />
            </div>
        )
    }
}

Props

Common props you need to specify include:

PropsDefaultTypeDescription
alignment"horizontal"Stringvertical,horizontalAlignment of menu
menuOptionsArray contains home optionArray of objectsOption menu for menu items
logoUrlEmpty StringStringContains URL for logo
profileUrlUser imageStringContains URL for profile
searchOptiontrueBooleanDisplay or hide search option
profileOptionsArray of objectsOption menu for profile
onSearchKeyChangeFunctionHandle onChange of search text box
searchKeyStringValue of search text box
onSearchFunctionHandle onClick event of search button
brandName"Eternus"StringTitle for menu

License

This project is licensed under the MIT License.