github.com/e154/smart-home@v0.17.2-0.20240311175135-e530a6e5cd45/static_source/admin/src/hooks/web/useIntro.ts (about)

     1  import introJs from 'intro.js'
     2  import { IntroJs, Step, Options } from 'intro.js'
     3  import 'intro.js/introjs.css'
     4  import { useI18n } from '@/hooks/web/useI18n'
     5  import { useDesign } from '@/hooks/web/useDesign'
     6  
     7  export const useIntro = (setps?: Step[], options?: Options) => {
     8    const { t } = useI18n()
     9  
    10    const { variables } = useDesign()
    11  
    12    const defaultSetps: Step[] = setps || [
    13      {
    14        element: `#${variables.namespace}-menu`,
    15        title: t('common.menu'),
    16        intro: t('common.menuDes'),
    17        position: 'right'
    18      },
    19      {
    20        element: `#${variables.namespace}-tool-header`,
    21        title: t('common.tool'),
    22        intro: t('common.toolDes'),
    23        position: 'left'
    24      },
    25      {
    26        element: `#${variables.namespace}-tags-view`,
    27        title: t('common.tagsView'),
    28        intro: t('common.tagsViewDes'),
    29        position: 'bottom'
    30      }
    31    ]
    32  
    33    const defaultOptions: Options = options || {
    34      prevLabel: t('common.prevLabel'),
    35      nextLabel: t('common.nextLabel'),
    36      skipLabel: t('common.skipLabel'),
    37      doneLabel: t('common.doneLabel')
    38    }
    39  
    40    const introRef: IntroJs = introJs()
    41  
    42    introRef.addSteps(defaultSetps).setOptions(defaultOptions)
    43  
    44    return {
    45      introRef
    46    }
    47  }