1.0.0 • Published 1 year ago

rn-steps-indicator v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

React Native Step Indicator

A simple react-native Step Indicator widget with custom styling using react-native-reanimated for introducing custom animations, in the manner we have it as a peer dependency, and implemented completely with typescript.

Installation

npm install rn-steps-indicator react-native-reanimated

Simple Usage

import StepIndicator from 'rn-steps-indicator';

// ...

const steps = ["This is my label", "This is my other label", "This is the third label"]

const defaultStyles = {
    completed: {
        label: {
            fontSize: 14,
            fontFamily: 'Roboto'
        };
        indicator: {
            borderWidth: 1,
            size: 30,
            color: 'red',
        };
        stroke: {};
    },
    uncompleted: {
        label: {
            fontSize: 14,
            fontFamily: 'Roboto'
        };
        indicator: {
            borderWidth: 1,
            size: 30,
            color: 'blue',
        };
        stroke: {
            style: 'dashed'
            thickness: 3,
        };
    },
    current: {
        label: {
            fontSize: 18,
            fontFamily: 'Roboto'
        };
        indicator: {
            borderWidth: 3,
            size: 45,
            color: 'green',
        };
    }
}

const MyRNStepIndicator = () => {
    return (
        <StepIndicator
            steps={steps}
            currentStep={currentStep}
            setCurrentStep={setCurrentStep}
            customStyles={defaultStyles}
        />
    )
}

export default MyRNStepIndicator;

Customizing Indicator and Label

import StepIndicator from 'rn-steps-indicator';

// ...

const steps = ["This is my label", "This is my other label", "This is the third label"]

const defaultStyles = {
    ...
}

const renderCustomLabel = (step, status) => {
    switch (status) {
        case 'current':
            return (
            <Text style={styles.customStepIndicatorLabel}>{step}</Text>
            );
        case 'completed':
        case 'uncompleted':
        default:
            return null;
    }
}

const renderCustomIndicator = (step, status) => {
    switch (status) {
        case 'current':
            return <Ionicons name="analytics-sharp" />;
        case 'completed':
            return <Ionicons name="checkmark" />;
        case 'uncompleted':
        default:
            return null;
    }
}

const MyRNStepIndicator = () => {
    return (
        <StepIndicator
            steps={steps}
            currentStep={currentStep}
            setCurrentStep={setCurrentStep}
            customStyles={defaultStyles}
            renderLabel={renderCustomLabel}
            renderStepIndicator={renderCustomIndicator}
        />
    )
}

export default MyRNStepIndicator;

Step Indicator Properties

NameDescriptionTypeDefault
horizontalUsed for defining the direction of the step indicatorBooleantrue
stepsArray of steps used in the step indicatorString[][]
currentStepCurrent position of the stepsNumber0
setCurrentStepFunction for updating the current positionFunction (stepPosition: number)() => {}
renderLabelFunction that receives step and stepStatus as params and expects an element or null being returned as a custom labelFunction(step: Step, status: StepStatus)undefined
renderStepIndicatorFunction that receives step and stepStatus as params and expects an element or null being returned as a custom indicatorString[]true
customStylesStyles for customizing as the user wishes, the step indicatorStepIndicatorStyles{}

Custom Styles

NameTypeDefault
completedStepStyles{}
currentStepStyles{}
uncompletedStepStyles{}

Indicator

NameTypeDefault
borderWidthNumber2
sizeNumber30
StyleTextStyle{}
colorString'skyblue'

Stroke

NameTypeDefault
style'solid' or 'dashed''solid'
dashStylesDashStyle{}
thicknessNumber4
colorString'skyblue'

DashStyles

NameTypeDefault
gapNumber2
lengthNumber4
thicknessNumber1
colorString'gray'
NameTypeDefault
labelTextStyle{ fontSize: 18, fontWeight: '700' }
indicatorIndicatorStyles{}
strokeStrokeStyles{}

Indicator

NameTypeDefault
borderWidthNumber4
sizeNumber40
StyleTextStyle{}
colorString'green'

Indicator

NameTypeDefault
borderWidthNumber2
sizeNumber30
StyleTextStyle{}
colorString'gray'

Stroke

NameTypeDefault
style'solid' or 'dashed''solid'
dashStylesDashStyle{}
thicknessNumber2
colorString''gray

DashStyles

NameTypeDefault
gapNumber2
lengthNumber4
thicknessNumber1
colorString'gray'

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT


Made with create-react-native-library

1.0.0

1 year ago

1.1.0

1 year ago