1.1.0 • Published 3 years ago

friendly-guide v1.1.0

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

效果图

引导图示例

React 中的使用示例

import React, { useRef, useEffect } from 'react';
import { guide, close } from 'friendly-guide';

const STEP_ARR = [
  {
    el: 'a',
    position: 'top',
    showPrev: false,
    nextBtnText: '下一步,可自定义',
    nextBtnColor: 'red',
    explain: {
      title: 'a-title',
      content: 'a-content',
    },
  },
  {
    el: 'b',
    position: 'bottom',
    explain: {
      title: 'a-title',
      content: 'a-content',
    },
  },
  {
    el: 'c',
    position: 'right',
    explain: {
      title: 'a-title',
      content: 'a-content',
    },
  },
  {
    el: 'd',
    position: 'left',
    explain: {
      title: 'a-title',
      content: 'a-content',
    },
  },
  {
    el: 'e',
    position: 'top',
    nextBtnText: '完成',
    explain: {
      title: 'a-title',
      content: 'a-content',
    },
  },
];

const App = () => {
  const currentStep = useRef<number>(0);

  useEffect(() => {
    currentStep.current = 0;
  }, []);

  const reset = () => {
    currentStep.current = 0;
    close();
  };

  const guideFn = () => {
    const item = {
      maskClosable: false,
      onClickClose: () => {
        alert('关闭了');
        close();
      },
      onClickNext: () => {
        if (currentStep.current < STEP_ARR.length - 1) {
          currentStep.current = currentStep.current + 1;
          guideFn();
        } else {
          reset();
          return;
        }
      },
      onClickPrev: () => {
        if (currentStep.current > 0) {
          currentStep.current = currentStep.current - 1;
          guideFn();
        } else {
          reset();
          return;
        }
      },
    };

    const option = {
      ...STEP_ARR[currentStep.current],
      ...item,
    };

    console.log(option);

    guide(option);
  };
  const style = {
    width: 100,
    height: 100,
    background: 'red',
    margin: 30,
    display: 'inline-block',
  };
  return (
    <div className="App">
      <button onClick={guideFn}>button</button>

      <div
        style={{
          width: 500,
          margin: '100px auto',
        }}
      >
        <div id="a" style={style}></div>
        <div id="b" style={style}></div>
        <div id="c" style={style}></div>
        <div id="d" style={style}></div>
        <div id="e" style={style}></div>
      </div>
    </div>
  );
};

export default App;

#API

参数说明类型默认值是否必填备注
el需要引导的元素元素 id-
classWarp自定义样式覆盖原有样式String-
position方向Stringbottomtop/left/right/bottom-
onClickContainer点击容器的回调,点击任何地方都会触发Function
onClickNext点击下一步触发Function
onClickPrev点击上一步触发Function
onClickClose关闭触发Function
nextBtnColor下一步的按钮颜色否String#1890FF-
prevBtnColor上一步的按钮颜色String#c4c6cc-
nextBtnText下一步按钮文字String下一步
prevBtnText上一步按钮文字String上一步
showNext是否显示下一步按钮Booleantrue
showPrev是否显示上一步按钮Booleantrue
showClose是否显示关闭按钮Booleantrue
maskClosable点击蒙层是否允许关闭Booleantrue
explain说明 modalObject/Boolean{ width: 340 }false 的时候不显示

explain

参数说明类型默认值是否必填备注
widthNumber{ width: 340 }
titleString
contentString
1.1.0

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago