Skip to content
Snippets Groups Projects
Loader.tsx 1.3 KiB
Newer Older
  • Learn to ignore specific revisions
  • import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n'
    
    import { FluidType } from 'enums'
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    import React from 'react'
    import './Loader.scss'
    
    
    interface LoaderProps {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
      color?: 'gold' | 'gaz' | 'elec' | 'water' | 'black'
      fluidType?: FluidType
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    }
    
    /**
     * Loader of Ecolyo, default color is gold
    
     * @param color {'gold' | 'gaz' | 'elec' | 'water'} Default is gold
     * @param text Optional, text to be placed under the loader
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
     */
    
    const Loader = ({ color = 'gold', fluidType, text }: LoaderProps) => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
      const { t } = useI18n()
    
      let variant = color
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    
    
      if (fluidType !== undefined) {
        switch (fluidType) {
          case FluidType.ELECTRICITY:
            variant = 'elec'
            break
          case FluidType.GAS:
            variant = 'gaz'
            break
          case FluidType.WATER:
            variant = 'water'
            break
          case FluidType.MULTIFLUID:
            variant = 'gold'
            break
        }
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
      }
    
      return (
    
        <div className={`loader ${variant}`}>
          <div
    
            className="bars"
    
            role="progressbar"
    
            aria-label={t('common.accessibility.loading')}
            title={t('common.accessibility.loading')}
          >
            <div className="bar" />
            <div className="bar" />
            <div className="bar" />
          </div>
          {text}
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        </div>
      )
    }
    
    export default Loader