Skip to content

Commit

Permalink
feat: Home utils
Browse files Browse the repository at this point in the history
  • Loading branch information
LeleDallas committed Apr 29, 2023
1 parent 32d87a0 commit 3e5168e
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/Home/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

import React from 'react';
import { Button } from 'antd';
import { IObject } from 'rc-queue-anim';

export const isImg = /^http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w-./?%&=]*)?/;
export const getChildrenToRender = (item: any, i: number) => {
let tag = item.name.indexOf('title') === 0 ? 'h1' : 'div';
tag = item.href ? 'a' : tag;
let children = typeof item.children === 'string' && item.children.match(isImg)
? React.createElement('img', { src: item.children, alt: 'img' })
: item.children;
if (item.name.indexOf('button') === 0 && typeof item.children === 'object') {
children = React.createElement(Button, {
...item.children
});
}
return React.createElement(tag, { key: i.toString(), ...item }, children);
};

export const getDelay = (e: number, b: number) => (e % b) * 100 + Math.floor(e / b) * 100 + b * 100;

export const onComplete = (e: IObject, open: boolean) => {
if (open) e.target.style.height = 'auto'
}

export const getSelectedKeys = () =>
window.location.pathname === '/' ||
window.location.pathname === '/Home'
? ['item1']
: window.location.pathname === '/Service'
? ['item0']
: ['item2']

0 comments on commit 3e5168e

Please sign in to comment.