12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
- import { IconComponent } from '../icon/icon.component';
- import { NgClass } from '@angular/common';
- import * as i0 from "@angular/core";
- export class ButtonComponent {
- constructor() {
- this.text = '';
- this.type = 'default';
- this.size = 'base';
- this.variant = 'default';
- this.icon = undefined;
- }
- getCssClasses() {
- const sizeAndTextClasses = this.getSizeAndTextClasses();
- const borderClasses = this.getBorderClasses();
- const backgroundClasses = this.getBackgroundClasses();
- const allClasses = { ...sizeAndTextClasses, ...borderClasses, ...backgroundClasses };
- return this.getClassesAsString(allClasses);
- }
- getBackgroundClasses() {
- return {
- 'bg-primary hover:bg-primary-variation dark:bg-primary-dark': this.type === 'default' && this.variant === 'default',
- 'bg-secondary hover:bg-primary dark:bg-secondary-dark': this.type === 'alternate' && this.variant === 'default',
- 'bg-warning hover:bg-warning-variation': this.type === 'warning' && this.variant === 'default',
- 'bg-error hover:bg-error-variation': this.type === 'error' && this.variant === 'default',
- 'bg-success hover:bg-success-variation': this.type === 'success' && this.variant === 'default',
- };
- }
- getBorderClasses() {
- return {
- border: this.variant === 'outline',
- 'border-primary dark:border-primary-dark': this.type === 'default' && this.variant === 'outline',
- 'border-secondary dark:border-secondary-dark': this.type === 'alternate' && this.variant === 'outline',
- 'border-warning': this.type === 'warning' && this.variant === 'outline',
- 'border-error': this.type === 'error' && this.variant === 'outline',
- 'border-success': this.type === 'success' && this.variant === 'outline',
- };
- }
- getSizeAndTextClasses() {
- return {
- 'px-3 py-2': this.size === 'xs' || this.size === 'sm',
- 'px-5 py-2.5': this.size === 'base' || this.size === 'lg',
- 'px-6 py-3.5': this.size === 'xl',
- 'text-xs': this.size === 'xs',
- 'text-sm': this.size === 'sm' || this.size === 'base',
- 'text-base': this.size === 'lg' || this.size === 'xl',
- };
- }
- getClassesAsString(classesObj) {
- return Object.entries(classesObj)
- .filter(([_, value]) => value)
- .map(([key, _]) => key)
- .join(' ');
- }
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.1", ngImport: i0, type: ButtonComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "17.3.1", type: ButtonComponent, isStandalone: true, selector: "ct-button", inputs: { text: "text", type: "type", size: "size", variant: "variant", icon: "icon" }, ngImport: i0, template: "<button class=\"flex flex-row items-center gap-1.5 rounded-md\" [ngClass]=\"getCssClasses()\">\n @if (icon) {\n <ct-icon class=\"flex\" [size]=\"size || 'base'\" [icon]=\"icon\" />\n }\n {{ text }}\n</button>\n", dependencies: [{ kind: "directive", type: NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "component", type: IconComponent, selector: "ct-icon", inputs: ["icon", "iconClass", "fill", "strokeWidth", "strokeColor", "size"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
- }
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.1", ngImport: i0, type: ButtonComponent, decorators: [{
- type: Component,
- args: [{ selector: 'ct-button', standalone: true, imports: [NgClass, IconComponent], changeDetection: ChangeDetectionStrategy.OnPush, template: "<button class=\"flex flex-row items-center gap-1.5 rounded-md\" [ngClass]=\"getCssClasses()\">\n @if (icon) {\n <ct-icon class=\"flex\" [size]=\"size || 'base'\" [icon]=\"icon\" />\n }\n {{ text }}\n</button>\n" }]
- }], propDecorators: { text: [{
- type: Input,
- args: [{ required: true }]
- }], type: [{
- type: Input
- }], size: [{
- type: Input
- }], variant: [{
- type: Input
- }], icon: [{
- type: Input
- }] } });
|