chore(release): 0.3.0
[risinglegends.git] / src / server / views / components / button.ts
1 import { map } from 'lodash';
2
3 interface CoreAttributes {
4   id: string;
5   class?: string[];
6 }
7
8 export function ButtonWithBlock(attrs: CoreAttributes & Record<string, any>, value: string, blockTime: number): string {
9   if(!attrs.class) {
10     attrs.class = [];
11   }
12
13   attrs.class.push('disabled');
14   attrs['data-block'] = blockTime;
15   attrs['disabled'] = 'disabled';
16   
17   return Button(attrs, value);
18 }
19
20 export function Button(attrs: CoreAttributes & Record<string, any>, value: string): string {
21   const attributes: string[] = [];
22
23   map(attrs, function(value, key) {
24     switch(key) {
25       case 'class':
26         attributes.push(`${key}="${value.join(' ')}"`);
27       break;
28       default:
29         attributes.push(`${key}="${value}"`);
30       break;
31     }
32   });
33
34   return `<button ${attributes.join(" ")}>${value}</button>`;
35 }