From e78f48329ebe688c955318b5cb17a5e78469195f Mon Sep 17 00:00:00 2001
From: Eugen Ciur <eugen@papermerge.com>
Date: Sat, 2 Oct 2021 09:19:48 +0200
Subject: [PATCH] awesome components!

---
 app/components/button/new.hbs     | 17 ++++++++++++++++
 app/components/button/new.js      | 32 +++++++++++++++++++++++++++++++
 app/components/tag/new.hbs        |  5 ++---
 app/templates/automates/index.hbs |  6 +-----
 4 files changed, 52 insertions(+), 8 deletions(-)
 create mode 100644 app/components/button/new.hbs
 create mode 100644 app/components/button/new.js

diff --git a/app/components/button/new.hbs b/app/components/button/new.hbs
new file mode 100644
index 0000000..1f0f5f9
--- /dev/null
+++ b/app/components/button/new.hbs
@@ -0,0 +1,17 @@
+{{#if @route}}
+  <LinkTo
+      @route={{@route}}
+      class="btn btn-success">
+        <i class="bi bi-plus-lg mx-1"></i>
+        {{this.text}}
+  </LinkTo>
+{{else}}
+  <button
+    class="btn btn-success"
+    type="button"
+    {{on "click" @onClick}}>
+      <i class="bi bi-plus-lg mx-1"></i>
+    {{this.text}}
+  </button>
+{{/if}}
+
diff --git a/app/components/button/new.js b/app/components/button/new.js
new file mode 100644
index 0000000..bd571eb
--- /dev/null
+++ b/app/components/button/new.js
@@ -0,0 +1,32 @@
+import Component from '@glimmer/component';
+
+
+class ButtonNewComponent extends Component {
+  /*
+    "New Button" component. Renders a button as either
+    html <a> tag or as <button>.
+
+    Arguments:
+      @route - if `route` argument is provided, button will
+        be rendered as <a>.
+      @onClick - if `onClick` argument is provided - button
+        will be rendered as <button>.
+      @text - button's text. Default value is "New".
+
+    Examples:
+
+      Render component as <button> with `onClick` handler:
+
+        <Button::New @onClick={{this.onToggleNew}} />
+
+      Render componet as <a> with given route:
+
+        <Button::New @route="automates.add" />
+  */
+
+  get text() {
+    return this.args.text || "New";
+  }
+}
+
+export default ButtonNewComponent;
\ No newline at end of file
diff --git a/app/components/tag/new.hbs b/app/components/tag/new.hbs
index 865a831..c35bca1 100644
--- a/app/components/tag/new.hbs
+++ b/app/components/tag/new.hbs
@@ -1,6 +1,5 @@
-<button class="btn btn-success" type="button" {{on "click" this.onToggleNew}}>
-    <i class="bi bi-plus-lg mx-1"></i>New
-</button>
+<Button::New @onClick={{this.onToggleNew}} />
+
 
 {{#if this.form_visible}}
     <form>
diff --git a/app/templates/automates/index.hbs b/app/templates/automates/index.hbs
index 83cb76b..4c77266 100644
--- a/app/templates/automates/index.hbs
+++ b/app/templates/automates/index.hbs
@@ -1,8 +1,4 @@
-<LinkTo
-  @route="automates.add"
-  class="btn btn-success">
-  <i class="bi bi-plus-lg mx-1"></i>New
-</LinkTo>
+<Button::New @route="automates.add" />
 
 <div class="tags">
   <table class="table table-striped align-middle">
-- 
GitLab