Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-common-use-components

Package Overview
Dependencies
Maintainers
0
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-common-use-components

A React mobile commonly used component library

  • 1.1.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4
Maintainers
0
Weekly downloads
 
Created
Source

react-common-use-components npm npm

All Contributors

A library of commonly used React components,Contains the following components: FlexBox, CountDown,InfiniteScroll,Modal,ToastProvider,Toast,Uploader

Install

  npm install --save react-common-use-components

  or

  yarn add react-common-use-components

  // in code ES6
  import InfiniteScroll from 'react-common-use-components';
  // or commonjs
  var InfiniteScroll = require('react-common-use-components');

Using

Button

import React, {useState} from 'react';
import {Button} from "react-common-use-components";

const YourComponent = () => {
    const onClick = () => {

    }
    return (
        <div>
            <Button type={'primary'} disabled={false} onClick={onClick} isDebounce={true}
                    debounceDelay={2000}>购买</Button>
        </div>
    );
};

export default YourComponent;

Button props

nameparamstypedescription
onClick() => {}functionclick function
type'default','primary','success','danger','warning'stringbutton type
debounceDelay5000numberAnti shake delay time
isDebouncefalsebooleanIs click stabilization enabled
disabledfalsebooleanIs disabled

CountDown

import React, {useState} from 'react';
import {CountDown} from "react-common-use-components";

const YourComponent = () => {
    const [startTimer, setStartTimer] = useState(false)
    const onClick = () => {
        setStartTimer(true)
    }
    return (
        <div>
            <CountDown style={{
                width: "8rem",
                height: "1.25rem",
                borderRadius: "0.375rem",
                textAlign: 'center',
                lineHeight: "1.25rem",
                fontsize: "1.25rem !important",
                marginRight: "0.25rem",
                backgroundColor: "#F8F8F8",
                color: '#3370DA',
                cursor: "pointer"
            }} onClick={onClick} status={startTimer}/>
        </div>
    );
};

export default YourComponent;

CountDown props

nametypedescription
startTimerbooleantimer switch
onClickfunctioncallback function
styleCSSPropertiescountdown style

InfiniteScroll

import React, {useState, useEffect} from 'react';
import {InfiniteScroll} from "react-common-use-components";
import {getList} from "services"

const YourComponent = () => {
    const [list, setList] = useState([])
    const [total, setTotal] = useState(0)
    const [page, setPage] = useState(0)
    useEffect(() => {
        //get list data
        getList({page: page, limit: 10}).then((res) => {
            if (res.data.code === 0) {
                if (page === 0) {
                    setList(res.data.list)
                } else {
                    setList([...list, ...res.data.list])
                }
            }
        })
    }, [page])

    function loadMore() {
        if (page * 10 > total) {
            return;
        }
        let nextPage = page + 1
        setPage(nextPage)
    }

    return (
        <InfiniteScroll loadMore={loadMore}
                        hasMore={list.length < total}
                        dataLength={list.length}
                        total={total}
                        threshold={25}
        >
            {list.map((item, index) => {
                return (
                    <YourChildComponent key={index}/>
                )
            })}
        </InfiniteScroll>
    );
};

export default YourComponent;

InfiniteScroll props

nametypedescription
loadMorefunctionload more callback functions
hasMorebooleanDo you have any more data
dataLengthnumberlist or data length
totalnumberlist or data total
**
threshold**numberThe distance from the bottom of the container, triggered by the callback function when touching the bottom, in pixels
endreactNodeend component
loadingreactNodeloading component

Toast

//App.js
import React, {useState} from 'react';
import {ToastProvider} from "react-common-use-components";

const App = () => {
    return (
        <ToastProvider>
            {/*Your child pages or child components*/}
            <ChildComponent/>
        </ToastProvider>
    );
};

export default App;

//Home.js
import React, {useState} from 'react';
import {Toast} from "react-common-use-components";

const Home = () => {
    return (
        <div onClick={() => Toast.show({text: 'hello', type: 'success', duration: 2000})}>
            home page
        </div>
    );
};

export default Home;

Toast props

nameparamstypedescription
show{text,type,duration}functionopen toast function
text'hello'stringopen toast text
typesuccess,fail,warning,loadingstringtoast status
**
duration**2000numberPrompt duration, if 0, will not automatically close, default to 2000
show{timeout}functionClose the current toast
timeout2000numberDelaying Toast shutdown time

Modal

//App.js
import React, {useState} from 'react';
import {Modal} from "react-common-use-components";

const App = () => {
    const [modal, setModal] = useState(false)
    return (
        <div>
            <Modal position={"center"} onClose={() => {
                setModal(false)
            }} openModal={modal}>
                {/*Your modal child components*/}
            </Modal>
            {/*Your child pages or child components*/}
            <ChildComponent/>
        </div>
    );
};

export default App;

Modal props

nameparamstypedescription
openModalfalsebooleanopen modal
positiontop,right,bottom,leftstringmodal position
onClosesuccess,fail,warning,loadingfunctionclose the current modal
style{background:'rgba(0,0,0,0.5)'}CSSPropertiesModal container style

Uploader

//App.js
import React, {useState} from 'react';
import {Uploader} from "react-common-use-components";

const App = () => {
    const callback = (file) => {
        console.log('file:', file)
    }
    return (
        <div>
            <Uploader accept={'image/*'} id={'upload-img'} style={{width: "1.5rem", height: "3rem",}}
                      onSuccess={(file) => {
                          callback(file)
                      }}>
                <ChildComponent/>
            </Uploader>
        </div>
    );
};

export default App;

Uploader props

nameparamstypedescription
id'uploader_1'stringuploader id
accept'image/*stringinput attribute, restricting file types
onSuccess(file) => {}functioncallback function for successful file selection
style{background:'rgba(0,0,0,0.5)'}CSSPropertiesUploader container style

PreviewVideo

//App.js
import React, {useState} from 'react';
import {PreviewVideo, Button} from "react-common-use-components";

const App = () => {

    return (
        <div>
            <PreviewVideo autoPlay={true} url={'your video url'}>
                <Button type={'primary'}>预览</Button>
            </PreviewVideo>
        </div>
    );
};

export default App;

PreviewVideo props

nameparamstypedescription
url''stringvideo url
autoPlaytruebooleanautoplay video
playIconrequire file or image urlstring
videoStyle{width:"200px"}CSSPropertiesvideo style

FlexBox

//App.js
import React, {useState} from 'react';
import {FlexBox} from "react-common-use-components";

const App = () => {
    return (
        <div>
            <FlexBox style={{justifyContent: "flex-start",}} onClick={(file) => {
            }}>
                <ChildComponent/>
            </FlexBox>
        </div>
    );
};

export default App;

FlexBox props

nameparamstypedescription
onClick() => {}functionclick function
style{background:'rgba(0,0,0,0.5)'}CSSPropertiesFlexBox style

Tabs

//App.js
import React, {useState} from 'react';
import {Tabs} from "react-common-use-components";

const App = () => {
    const tabItems = [{key: '1', label: '香蕉'}, {key: '2', label: '哈密瓜'}]
    return (
        <div>
            <Tabs items={tabItems}
                  defaultActiveKey={1}
                  onChange={(key) => {
                      console.log(key)
                  }}
            />
        </div>
    );
};

export default App;

Tabs props

nameparamstypedescription
items[{key:string,label:string}]arraytabs options
containerStyle{background:'rgba(0,0,0,0.5)'}CSSPropertiescontainer style
onChange(key:string) => {}functionclick function
itemStyle{background:'rgba(0,0,0,0.5)'}CSSPropertiesitem style
activeKey'1'stringactive item
defaultActiveKey'2'stringinit default item
activeLineColor'#666666'stringactive item line color

ProgressBar

//App.js
import React, {useState} from 'react';
import {ProgressBar} from "react-common-use-components";

const App = () => {
    return (
        <div>
            <ProgressBar percent={20}/>
        </div>
    );
};

export default App;

ProgressBar props

nameparamstypedescription
percent20numberProgress value , total is 100
barWidth"100px"stringProgressBar width
barHeight"16px"stringProgressBar height
barBgColor"#000000"stringProgressBar background color
trackBgColor"#b3b3b3"stringProgressBar track background color
min"100px"stringProgressBar min num
max"16px"stringProgressBar max num
onChange(percent: number) => voidfunctionSlide the slider to return the callback function of the current precision
isOpenSlideBlocktruebooleanopen the slider operation progress

AudioPlayer

//App.js
import React from 'react';
import {AudioPlayer} from "react-common-use-components";

const App = () => {
    return (
        <div>
            <AudioPlayer url={'https://example.cpm/xxx.mp4'}/>
        </div>
    );
};

export default App;

AudioPlayer props

nameparamstypedescription
url'https://example.cpm/xxx.mp4'stringvideo url
playIconReactNodeplay button
pauseIconReactNodepause button
forwardIconReactNodeFast forward button
backwardIconReactNodeback button
timeTextStyle{color:'rgba(0,0,0,0)'}CSSPropertiesplay time text style

VideoPlayer

//App.js
import React from 'react';
import {AudioPlayer} from "react-common-use-components";

const App = () => {
    return (
        <VideoPlayer width={"80vw"} height={"80vh"} url={'https://xxxx.mp4'}/>
    );
};

export default App;

VideoPlayer props

nameparamstypedescription
url'https://example.cpm/xxx.mp4'stringvideo url
playIconReactNodeplay button
pauseIconReactNodepause button
forwardIconReactNodeFast forward button
backwardIconReactNodeback button
timeTextStyle{color:'rgba(0,0,0,0)'}CSSPropertiesplay time text style
width"80vw"stringVideoPlayer width
height"80vh"stringVideoPlayer height

PasswordInput

//App.js
import React from 'react';
import {PasswordInput} from "react-common-use-components";

const App = () => {
    return (
        <div>
            <PasswordInput/>
        </div>
    );
};

export default App;

PasswordInput props

nameparamstypedescription
value''stringinput value
maxLength6numberinput maxLength
autoFocustruebooleaninput autoFocus (default: true)
onChange(value: string) => voidfunctioninput onchange callback method
onSubmit(value: string) => voidfunctionThe callback function after input completion,this function is triggered when the value length is equal to maxLength
style{color:'rgba(0,0,0,0)'}CSSPropertiesinput container style
inputItemStyle{color:'rgba(0,0,0,0)'}CSSPropertiesinput item style
iconStyle{color:'rgba(0,0,0,0)'}CSSPropertiesinput item icon style

LICENSE

MIT

Keywords

FAQs

Package last updated on 22 Oct 2024

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc