index.tsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { use } from '../utils';
  2. import { inherit } from '../utils/functional';
  3. // Types
  4. import { CreateElement, RenderContext } from 'vue/types';
  5. import { DefaultSlots } from '../utils/use/sfc';
  6. export type LoadingProps = {
  7. size?: string;
  8. type: string;
  9. color: string;
  10. };
  11. const [sfc, bem] = use('loading');
  12. const DEFAULT_COLOR = '#c9c9c9';
  13. function Loading(
  14. h: CreateElement,
  15. props: LoadingProps,
  16. slots: DefaultSlots,
  17. ctx: RenderContext<LoadingProps>
  18. ) {
  19. const { color, size, type } = props;
  20. const colorType = color === 'white' || color === 'black' ? color : '';
  21. const style = {
  22. color: color === 'black' ? DEFAULT_COLOR : color,
  23. width: size,
  24. height: size
  25. };
  26. const Spin = [];
  27. if (type === 'spinner') {
  28. for (let i = 0; i < 12; i++) {
  29. Spin.push(<i />);
  30. }
  31. }
  32. const Circular = type === 'circular' && (
  33. <svg class={bem('circular')} viewBox="25 25 50 50">
  34. <circle cx="50" cy="50" r="20" fill="none" />
  35. </svg>
  36. );
  37. return (
  38. <div class={bem([type, colorType])} style={style} {...inherit(ctx, true)}>
  39. <span class={bem('spinner', type)}>
  40. {Spin}
  41. {Circular}
  42. </span>
  43. </div>
  44. );
  45. }
  46. Loading.props = {
  47. size: String,
  48. type: {
  49. type: String,
  50. default: 'circular'
  51. },
  52. color: {
  53. type: String,
  54. default: DEFAULT_COLOR
  55. }
  56. };
  57. export default sfc<LoadingProps>(Loading);