circletone.mjs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. import { DOCUMENT, NgClass } from '@angular/common';
  2. import * as i0 from '@angular/core';
  3. import { Component, ChangeDetectionStrategy, Inject, Input } from '@angular/core';
  4. const icons = `
  5. <svg xmlns="http://www.w3.org/2000/svg" style="display:none">
  6. <symbol id="arrow-down" viewBox="0 0 24 24" fill="none" stroke-width="1.5" stroke="currentColor">
  7. <path stroke-linecap="round" stroke-linejoin="round" d="M19.5 13.5L12 21m0 0l-7.5-7.5M12 21V3" />
  8. </symbol>
  9. <symbol id="information-circle" viewBox="0 0 24 24" fill="none">
  10. <path stroke-linecap="round" stroke-linejoin="round" d="m11.25 11.25.041-.02a.75.75 0 0 1 1.063.852l-.708 2.836a.75.75 0 0 0 1.063.853l.041-.021M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Zm-9-3.75h.008v.008H12V8.25Z" />
  11. </symbol>
  12. <symbol id="paper-clip" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
  13. <path stroke-linecap="round" stroke-linejoin="round" d="m18.375 12.739-7.693 7.693a4.5 4.5 0 0 1-6.364-6.364l10.94-10.94A3 3 0 1 1 19.5 7.372L8.552 18.32m.009-.01-.01.01m5.699-9.941-7.81 7.81a1.5 1.5 0 0 0 2.112 2.13" />
  14. </symbol>
  15. </svg>
  16. `;
  17. class IconComponent {
  18. constructor(renderer, document, el) {
  19. this.renderer = renderer;
  20. this.document = document;
  21. this.el = el;
  22. this.icon = '';
  23. this.iconClass = '';
  24. this.fill = 'currentColor';
  25. this.strokeWidth = 1.5;
  26. this.strokeColor = 'currentColor';
  27. this.size = 'base';
  28. this.iconPath = '';
  29. }
  30. ngOnInit() {
  31. this.injectSVG();
  32. this.strokeColor = this.getFormattedColor(this.strokeColor);
  33. this.fill = this.getFormattedColor(this.fill);
  34. }
  35. getFormattedColor(color) {
  36. if (color.startsWith('--')) {
  37. const rgbValue = getComputedStyle(document.documentElement).getPropertyValue(color).trim();
  38. return `rgb(${rgbValue})`;
  39. }
  40. return color;
  41. }
  42. getIconPath() {
  43. return `#${this.icon}`;
  44. }
  45. injectSVG() {
  46. const svgElement = this.renderer.createElement('div');
  47. this.renderer.setProperty(svgElement, 'innerHTML', icons);
  48. this.renderer.setStyle(svgElement, 'display', 'none');
  49. this.renderer.appendChild(this.document.body, svgElement);
  50. }
  51. static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.1", ngImport: i0, type: IconComponent, deps: [{ token: i0.Renderer2 }, { token: DOCUMENT }, { token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Component }); }
  52. static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.3.1", type: IconComponent, isStandalone: true, selector: "ct-icon", inputs: { icon: "icon", iconClass: "iconClass", fill: "fill", strokeWidth: "strokeWidth", strokeColor: "strokeColor", size: "size" }, ngImport: i0, template: "<svg\n [ngClass]=\"iconClass\"\n [attr.fill]=\"fill\"\n [attr.stroke-width]=\"strokeWidth\"\n [attr.stroke]=\"strokeColor\"\n class=\"flex\"\n [class.size-3]=\"size === 'xs'\"\n [class.size-4]=\"size === 'sm'\"\n [class.size-5]=\"size === 'base'\"\n [class.size-6]=\"size === 'lg'\"\n [class.size-8]=\"size === 'xl'\">\n <use [attr.xlink:href]=\"getIconPath()\"></use>\n</svg>\n", dependencies: [{ kind: "directive", type: NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
  53. }
  54. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.1", ngImport: i0, type: IconComponent, decorators: [{
  55. type: Component,
  56. args: [{ selector: 'ct-icon', standalone: true, imports: [NgClass], changeDetection: ChangeDetectionStrategy.OnPush, template: "<svg\n [ngClass]=\"iconClass\"\n [attr.fill]=\"fill\"\n [attr.stroke-width]=\"strokeWidth\"\n [attr.stroke]=\"strokeColor\"\n class=\"flex\"\n [class.size-3]=\"size === 'xs'\"\n [class.size-4]=\"size === 'sm'\"\n [class.size-5]=\"size === 'base'\"\n [class.size-6]=\"size === 'lg'\"\n [class.size-8]=\"size === 'xl'\">\n <use [attr.xlink:href]=\"getIconPath()\"></use>\n</svg>\n" }]
  57. }], ctorParameters: () => [{ type: i0.Renderer2 }, { type: Document, decorators: [{
  58. type: Inject,
  59. args: [DOCUMENT]
  60. }] }, { type: i0.ElementRef }], propDecorators: { icon: [{
  61. type: Input
  62. }], iconClass: [{
  63. type: Input
  64. }], fill: [{
  65. type: Input
  66. }], strokeWidth: [{
  67. type: Input
  68. }], strokeColor: [{
  69. type: Input
  70. }], size: [{
  71. type: Input
  72. }] } });
  73. class ButtonComponent {
  74. constructor() {
  75. this.text = '';
  76. this.type = 'default';
  77. this.size = 'base';
  78. this.variant = 'default';
  79. this.icon = undefined;
  80. }
  81. getCssClasses() {
  82. const sizeAndTextClasses = this.getSizeAndTextClasses();
  83. const borderClasses = this.getBorderClasses();
  84. const backgroundClasses = this.getBackgroundClasses();
  85. const allClasses = { ...sizeAndTextClasses, ...borderClasses, ...backgroundClasses };
  86. return this.getClassesAsString(allClasses);
  87. }
  88. getBackgroundClasses() {
  89. return {
  90. 'bg-primary hover:bg-primary-variation dark:bg-primary-dark': this.type === 'default' && this.variant === 'default',
  91. 'bg-secondary hover:bg-primary dark:bg-secondary-dark': this.type === 'alternate' && this.variant === 'default',
  92. 'bg-warning hover:bg-warning-variation': this.type === 'warning' && this.variant === 'default',
  93. 'bg-error hover:bg-error-variation': this.type === 'error' && this.variant === 'default',
  94. 'bg-success hover:bg-success-variation': this.type === 'success' && this.variant === 'default',
  95. };
  96. }
  97. getBorderClasses() {
  98. return {
  99. border: this.variant === 'outline',
  100. 'border-primary dark:border-primary-dark': this.type === 'default' && this.variant === 'outline',
  101. 'border-secondary dark:border-secondary-dark': this.type === 'alternate' && this.variant === 'outline',
  102. 'border-warning': this.type === 'warning' && this.variant === 'outline',
  103. 'border-error': this.type === 'error' && this.variant === 'outline',
  104. 'border-success': this.type === 'success' && this.variant === 'outline',
  105. };
  106. }
  107. getSizeAndTextClasses() {
  108. return {
  109. 'px-3 py-2': this.size === 'xs' || this.size === 'sm',
  110. 'px-5 py-2.5': this.size === 'base' || this.size === 'lg',
  111. 'px-6 py-3.5': this.size === 'xl',
  112. 'text-xs': this.size === 'xs',
  113. 'text-sm': this.size === 'sm' || this.size === 'base',
  114. 'text-base': this.size === 'lg' || this.size === 'xl',
  115. };
  116. }
  117. getClassesAsString(classesObj) {
  118. return Object.entries(classesObj)
  119. .filter(([_, value]) => value)
  120. .map(([key, _]) => key)
  121. .join(' ');
  122. }
  123. static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.1", ngImport: i0, type: ButtonComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
  124. 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 }); }
  125. }
  126. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.1", ngImport: i0, type: ButtonComponent, decorators: [{
  127. type: Component,
  128. 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" }]
  129. }], propDecorators: { text: [{
  130. type: Input,
  131. args: [{ required: true }]
  132. }], type: [{
  133. type: Input
  134. }], size: [{
  135. type: Input
  136. }], variant: [{
  137. type: Input
  138. }], icon: [{
  139. type: Input
  140. }] } });
  141. /*
  142. * Public API Surface of circletone
  143. */
  144. /**
  145. * Generated bundle index. Do not edit.
  146. */
  147. export { ButtonComponent, IconComponent };
  148. //# sourceMappingURL=circletone.mjs.map