tweb/src/components/button.ts

38 lines
919 B
TypeScript
Raw Normal View History

2021-04-08 15:52:31 +02:00
/*
* https://github.com/morethanwords/tweb
* Copyright (C) 2019-2021 Eduard Kuzmenko
* https://github.com/morethanwords/tweb/blob/master/LICENSE
*/
2021-03-21 10:59:59 +01:00
import { i18n, LangPackKey } from "../lib/langPack";
import { ripple } from "./ripple";
2021-03-21 10:59:59 +01:00
const Button = (className: string, options: Partial<{noRipple: true, onlyMobile: true, icon: string, rippleSquare: true, text: LangPackKey, disabled: boolean}> = {}) => {
const button = document.createElement('button');
button.className = className + (options.icon ? ' tgico-' + options.icon : '');
2021-01-01 20:44:31 +01:00
if(!options.noRipple) {
if(options.rippleSquare) {
button.classList.add('rp-square');
}
ripple(button);
}
if(options.onlyMobile) {
button.classList.add('only-handhelds');
}
2021-02-01 04:07:44 +01:00
if(options.disabled) {
button.disabled = true;
}
2021-01-01 20:44:31 +01:00
if(options.text) {
2021-03-21 10:59:59 +01:00
button.append(i18n(options.text));
2021-01-01 20:44:31 +01:00
}
return button;
};
2021-03-16 16:18:51 +01:00
export default Button;