dlg-ui 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md ADDED
@@ -0,0 +1,9 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # dlg-ui
2
+
3
+ [Short description of the addon.]
4
+
5
+
6
+ ## Compatibility
7
+
8
+ * Ember.js v3.28 or above
9
+ * Ember CLI v3.28 or above
10
+ * Node.js v14 or above
11
+
12
+
13
+ ## Installation
14
+
15
+ ```
16
+ ember install dlg-ui
17
+ ```
18
+
19
+
20
+ ## Usage
21
+
22
+ [Longer description of how to use the addon in apps.]
23
+
24
+
25
+ ## Contributing
26
+
27
+ See the [Contributing](CONTRIBUTING.md) guide for details.
28
+
29
+
30
+ ## License
31
+
32
+ This project is licensed under the [MIT License](LICENSE.md).
@@ -0,0 +1,21 @@
1
+ <div class="dropdown-wrapper {{@class}}" {{did-insert this.loadClickListener}}>
2
+ <div class="dropdown-select {{if this.isOpen 'open'}}">
3
+ {{#if this.selectedOption}}
4
+ {{this.selectedOption.label}}
5
+ {{!-- TODO - If there is no label, then they submitted just strings and we can use those for a dropdown --}}
6
+ {{else}}
7
+ <span class="dropdown-placeholder">
8
+ {{this.placeholder}}
9
+ </span>
10
+ {{/if}}
11
+ </div>
12
+ {{#if this.isOpen}}
13
+ <div class="dropdown-options">
14
+ {{#each @options as |option|}}
15
+ <div class="dropdown-option" {{on "click" (fn this.makeSelection option)}}>
16
+ {{option.label}}
17
+ </div>
18
+ {{/each}}
19
+ </div>
20
+ {{/if}}
21
+ </div>
@@ -0,0 +1,68 @@
1
+ import Component from '@glimmer/component';
2
+ import { action } from '@ember/object';
3
+ import { tracked } from '@glimmer/tracking';
4
+
5
+ export default class DropdownComponent extends Component {
6
+ @tracked isOpen = false;
7
+ @tracked selectedOption = this.args.selectedOption;
8
+
9
+ get placeholder() {
10
+ if (this.args.placeholder) {
11
+ return this.args.placeholder;
12
+ } else {
13
+ return 'Select an option...';
14
+ }
15
+ }
16
+
17
+ constructor() {
18
+ super(...arguments);
19
+ if (!this.args.onSelect) {
20
+ console.warn('Dropdown 2-way binding needs an onSelect action');
21
+ }
22
+ if (!this.args.options) {
23
+ throw new Error('Dropdown requires an options array');
24
+ }
25
+ if (this.args.forceSelection && !this.args.selectedOption) {
26
+ throw new Error(
27
+ 'Dropdown requires a selected option when forceSelection is true'
28
+ );
29
+ }
30
+ }
31
+
32
+ saveSelection(value) {
33
+ this.selectedOption = value;
34
+ this.args.onSelect(value);
35
+ }
36
+
37
+ @action
38
+ loadClickListener(element) {
39
+ const handleClickOutside = (event) => {
40
+ if (!element.contains(event.target)) {
41
+ this.isOpen = false;
42
+ }
43
+ };
44
+
45
+ element.addEventListener('click', (event) => {
46
+ if (!event.target.classList.contains('dropdown-option')) {
47
+ this.isOpen = !this.isOpen;
48
+ }
49
+ });
50
+
51
+ document.addEventListener('click', handleClickOutside);
52
+
53
+ return () => {
54
+ document.removeEventListener('click', handleClickOutside);
55
+ };
56
+ }
57
+
58
+ @action
59
+ makeSelection(option) {
60
+ if (!this.args.forceSelection && option === this.selectedOption) {
61
+ this.saveSelection(null);
62
+ this.isOpen = false;
63
+ } else {
64
+ this.saveSelection(option);
65
+ this.isOpen = false;
66
+ }
67
+ }
68
+ }
@@ -0,0 +1,16 @@
1
+ <div class="header-dropdown-wrapper {{@class}}" {{did-insert this.loadClickListener}}>
2
+ <div class="header-dropdown-select {{if this.isOpen 'open'}}">
3
+ <span class="header-dropdown-selected">
4
+ {{this.selectedOption.label}}
5
+ </span>
6
+ </div>
7
+ {{#if this.isOpen}}
8
+ <div class="header-dropdown-options {{if this.isOpen 'open'}}" {{did-insert this.setDropdownWidth}}>
9
+ {{#each @options as |option|}}
10
+ <div class="dropdown-option" {{on "click" (fn this.makeSelection option)}}>
11
+ {{option.label}}
12
+ </div>
13
+ {{/each}}
14
+ </div>
15
+ {{/if}}
16
+ </div>
@@ -0,0 +1,82 @@
1
+ import Component from '@glimmer/component';
2
+ import { action } from '@ember/object';
3
+ import { tracked } from '@glimmer/tracking';
4
+
5
+ export default class DropdownComponent extends Component {
6
+ @tracked isOpen = false;
7
+ @tracked selectedOption = this.args.selectedOption;
8
+
9
+ get placeholder() {
10
+ if (this.args.placeholder) {
11
+ return this.args.placeholder;
12
+ } else {
13
+ return 'Select an option...';
14
+ }
15
+ }
16
+
17
+ constructor() {
18
+ super(...arguments);
19
+ if (!this.args.onSelect) {
20
+ console.warn('Dropdown 2-way binding needs an onSelect action');
21
+ }
22
+ if (!this.args.options) {
23
+ throw new Error('Dropdown requires an options array');
24
+ }
25
+ if (!this.args.selectedOption) {
26
+ throw new Error('Header dropdown requires a selected option');
27
+ }
28
+ }
29
+
30
+ saveSelection(value) {
31
+ if (!this.args.preventDefault) {
32
+ this.selectedOption = value;
33
+ }
34
+ this.args.onSelect(value);
35
+ }
36
+
37
+ @action
38
+ loadClickListener(element) {
39
+ const handleClickOutside = (event) => {
40
+ if (!element.contains(event.target)) {
41
+ this.isOpen = false;
42
+ }
43
+ };
44
+
45
+ element.addEventListener('click', (event) => {
46
+ if (!event.target.classList.contains('dropdown-option')) {
47
+ this.isOpen = !this.isOpen;
48
+ }
49
+ });
50
+
51
+ document.addEventListener('click', handleClickOutside);
52
+
53
+ return () => {
54
+ document.removeEventListener('click', handleClickOutside);
55
+ };
56
+ }
57
+
58
+ @action
59
+ makeSelection(option) {
60
+ if (option === this.selectedOption) {
61
+ this.isOpen = false;
62
+ } else {
63
+ this.saveSelection(option);
64
+ this.isOpen = false;
65
+ }
66
+ }
67
+
68
+ @action
69
+ setDropdownWidth() {
70
+ const targetElement = document.querySelector(
71
+ '.' + this.args.class + ' .header-dropdown-select'
72
+ );
73
+ const dropdownOptions = document.querySelector(
74
+ '.' + this.args.class + ' .header-dropdown-options'
75
+ );
76
+
77
+ if (targetElement && dropdownOptions) {
78
+ const targetWidth = targetElement.offsetWidth;
79
+ dropdownOptions.style.width = `${targetWidth}px`;
80
+ }
81
+ }
82
+ }
@@ -0,0 +1,31 @@
1
+ <div class="navbar-wrapper">
2
+ <div class="navbar-container">
3
+ <div class="navbar-title">
4
+ dlg-ui
5
+ </div>
6
+ <div class="navbar-elements">
7
+ {{#each this.navbarOptions as |option|}}
8
+ {{#if (eq option.type "link")}}
9
+ <div class="navbar-selection" {{on "click" (fn this.onSelect option)}}>
10
+ {{option.label}}
11
+ </div>
12
+ {{/if}}
13
+ {{#if (eq option.type "dropdown")}}
14
+ <div class="navbar-selection">
15
+ <HeaderDropdown
16
+ @class="navbar-dropdown"
17
+ @options={{option.dropdownOptions}}
18
+ @placeholder={{option.placeholder}}
19
+ @onSelect={{this.onSelect}}
20
+ @selectedOption={{option}}
21
+ @preventDefault={{true}}
22
+ />
23
+ </div>
24
+ {{/if}}
25
+ {{/each}}
26
+ </div>
27
+ </div>
28
+ <div class="navbar-yield">
29
+ {{yield}}
30
+ </div>
31
+ </div>
@@ -0,0 +1,31 @@
1
+ import Component from '@glimmer/component';
2
+ import { action } from '@ember/object';
3
+ import { service } from '@ember/service';
4
+
5
+ export default class NavbarComponent extends Component {
6
+ @service router;
7
+
8
+ get navbarOptions() {
9
+ let options = this.args.options;
10
+ return options.sort((a, b) => b.index - a.index);
11
+ }
12
+
13
+ // TODO: try and detect word wrap on first element and style accordingly, can be done with JS
14
+
15
+ constructor() {
16
+ super(...arguments);
17
+ if (!this.args.options) {
18
+ throw new Error('Navbar requires an options array');
19
+ }
20
+ }
21
+
22
+ @action
23
+ onSelect(value) {
24
+ if (this.args.onSelect) {
25
+ this.args.onSelect(value);
26
+ }
27
+ if (!this.args.preventDefault) {
28
+ this.router.transitionTo(value.route);
29
+ }
30
+ }
31
+ }
@@ -0,0 +1,22 @@
1
+ <div class="radio-container">
2
+ <div class="radio-label">
3
+ {{this.args.label}}
4
+ </div>
5
+ <div class="radio-options">
6
+ {{#each this.options as |option|}}
7
+ <div class="radio-option">
8
+ <input
9
+ type="radio"
10
+ id={{option.label}}
11
+ checked={{option.isChecked}}
12
+ name={{this.args.name}}
13
+ checked={{option.isChecked}}
14
+ {{on "change" (fn this.onChange option)}}
15
+ />
16
+ <label for={{option.label}}>
17
+ {{option.label}}
18
+ </label>
19
+ </div>
20
+ {{/each}}
21
+ </div>
22
+ </div>
@@ -0,0 +1,25 @@
1
+ import Component from '@glimmer/component';
2
+ import { action } from '@ember/object';
3
+ import { tracked } from '@glimmer/tracking';
4
+
5
+ export default class RadioComponent extends Component {
6
+ @tracked
7
+ selectedOption = this.args.defaultOption || {};
8
+
9
+ get options() {
10
+ let options = [];
11
+ this.args.options.forEach((option) => {
12
+ if (option.label === this.selectedOption.label) {
13
+ option.isChecked = true;
14
+ }
15
+ options.push(option);
16
+ });
17
+ return this.args.options || [];
18
+ }
19
+
20
+ @action
21
+ onChange(option) {
22
+ this.selectedOption = option;
23
+ this.args.onChange(option);
24
+ }
25
+ }
@@ -0,0 +1,211 @@
1
+ .dropdown-option {
2
+ border-bottom-style: solid;
3
+ border-width: 2px;
4
+ width: 100%;
5
+ padding-left: 8px;
6
+ padding-right: 8px;
7
+ padding-top: 6px;
8
+ padding-bottom: 6px;
9
+ box-sizing: border-box;
10
+ cursor: pointer;
11
+ }
12
+
13
+ .dropdown-option:hover {
14
+ background-color: black;
15
+ color: white;
16
+ border: black;
17
+ }
18
+
19
+ .dropdown-options {
20
+ white-space: normal;
21
+ overflow-wrap: break-word;
22
+ border-style: solid;
23
+ border-top-style: none;
24
+ border-bottom-style: none;
25
+ border-width: 2px;
26
+ background-color: #f6f6f6;
27
+ }
28
+
29
+ .dropdown-placeholder {
30
+ font-style: italic;
31
+ color: #444;
32
+ }
33
+
34
+ .dropdown-select {
35
+ width: 100%;
36
+ padding-left: 8px;
37
+ padding-top: 8px;
38
+ padding-bottom: 8px;
39
+ padding-right: 20px;
40
+ box-sizing: border-box;
41
+ position: relative;
42
+ overflow: hidden;
43
+ white-space: nowrap;
44
+ text-overflow: ellipsis;
45
+ cursor: pointer;
46
+ border-style: solid;
47
+ border-width: 2px;
48
+ background-color: #eee;
49
+ user-select: none;
50
+ }
51
+
52
+ .dropdown-select::after {
53
+ content: "\25BC";
54
+ display: block;
55
+ position: absolute;
56
+ right: 0px;
57
+ top: 50%;
58
+ right: 8px;
59
+ pointer-events: none;
60
+ transition: transform 0.3s ease;
61
+ top: 25%;
62
+ }
63
+
64
+ .dropdown-select.open::after {
65
+ transform: rotate(-180deg);
66
+ transform-origin: center;
67
+ padding-right: 0px;
68
+ }
69
+
70
+ .dropdown-wrapper {
71
+ width: 100%;
72
+ }
73
+
74
+ .header-dropdown-options {
75
+ white-space: normal;
76
+ overflow-wrap: break-word;
77
+ border-style: solid;
78
+ border-top-style: none;
79
+ border-bottom-style: none;
80
+ border-width: 2px;
81
+ background-color: #f6f6f6;
82
+ }
83
+
84
+ .header-dropdown-options.open {
85
+ border-top-style: solid;
86
+ }
87
+
88
+ .header-dropdown-select {
89
+ width: fit-content;
90
+ max-width: 100%;
91
+ padding-top: 8px;
92
+ padding-bottom: 2px;
93
+ padding-right: 25px;
94
+ box-sizing: border-box;
95
+ position: relative;
96
+ overflow: hidden;
97
+ white-space: nowrap;
98
+ text-overflow: ellipsis;
99
+ cursor: pointer;
100
+ border-bottom-style: solid;
101
+ border-width: 2px;
102
+ user-select: none;
103
+ }
104
+
105
+ .header-dropdown-select.open {
106
+ border-bottom-style: none;
107
+ }
108
+
109
+ .header-dropdown-select::after {
110
+ content: "\25BE";
111
+ display: block;
112
+ position: absolute;
113
+ right: 0px;
114
+ top: 20%;
115
+ pointer-events: none;
116
+ transition: transform 0.3s ease;
117
+ font-size: 1.5rem;
118
+ }
119
+
120
+ .header-dropdown-select.open::after {
121
+ transform: rotate(-180deg);
122
+ transform-origin: center;
123
+ padding-right: 0px;
124
+ top: 16%;
125
+ }
126
+
127
+ .header-dropdown-selected {
128
+ font-weight: bold;
129
+ }
130
+
131
+ .header-dropdown-wrapper {
132
+ width: 100%;
133
+ }
134
+
135
+ .navbar-container {
136
+ background-color: #eee;
137
+ position: sticky;
138
+ top: 0;
139
+ left: 0;
140
+ width: 100%;
141
+ min-height: 5vh;
142
+ height: fit-content;
143
+ display: flex;
144
+ justify-content: space-between;
145
+ align-items: center;
146
+ z-index: 10;
147
+ }
148
+
149
+ .navbar-dropdown .header-dropdown-options {
150
+ position: absolute;
151
+ min-width: 60px !important;
152
+ }
153
+
154
+ .navbar-dropdown .header-dropdown-select {
155
+ padding-top: 0px;
156
+ border-bottom-style: none;
157
+ }
158
+
159
+ .navbar-dropdown .header-dropdown-select::after {
160
+ top: 0;
161
+ height: 100%;
162
+ display: flex;
163
+ align-items: center;
164
+ padding-top: 2px;
165
+ }
166
+
167
+ .navbar-dropdown .header-dropdown-selected {
168
+ font-weight: normal;
169
+ }
170
+
171
+ .navbar-elements {
172
+ display: flex;
173
+ flex-wrap: wrap;
174
+ width: fit-content;
175
+ margin-right: 10px;
176
+ }
177
+
178
+ .navbar-selection {
179
+ margin: 8px;
180
+ display: flex;
181
+ align-items: center;
182
+ }
183
+
184
+ .navbar-title {
185
+ font-size: clamp(20px, 3vw, 30px);
186
+ margin: 0px 8px 0px 8px;
187
+ width: fit-content;
188
+ white-space: nowrap;
189
+ font-weight: bold;
190
+ }
191
+
192
+ .navbar-wrapper {
193
+ display: flex;
194
+ flex-direction: column;
195
+ min-height: 100vh;
196
+ }
197
+
198
+ .navbar-yield {
199
+ flex: 1 1 auto;
200
+ padding-top: 8px;
201
+ }
202
+
203
+ .radio-label {
204
+ font-weight: bold;
205
+ }
206
+
207
+ .radio-options {
208
+ display: flex;
209
+ flex-direction: column;
210
+ margin: 5px 0px 5px 0px;
211
+ }
@@ -0,0 +1 @@
1
+ export { default } from 'dlg-ui/components/dropdown';
@@ -0,0 +1 @@
1
+ export { default } from 'dlg-ui/components/header-dropdown';
@@ -0,0 +1 @@
1
+ export { default } from 'dlg-ui/components/navbar';
@@ -0,0 +1 @@
1
+ export { default } from 'dlg-ui/components/radio';
@@ -0,0 +1,5 @@
1
+ 'use strict';
2
+
3
+ module.exports = function (/* environment, appConfig */) {
4
+ return {};
5
+ };
package/index.js ADDED
@@ -0,0 +1,5 @@
1
+ 'use strict';
2
+
3
+ module.exports = {
4
+ name: require('./package').name,
5
+ };
package/package.json ADDED
@@ -0,0 +1,79 @@
1
+ {
2
+ "name": "dlg-ui",
3
+ "version": "0.0.0",
4
+ "description": "The default blueprint for ember-cli addons.",
5
+ "keywords": [
6
+ "ember-addon"
7
+ ],
8
+ "repository": "",
9
+ "license": "MIT",
10
+ "author": "",
11
+ "directories": {
12
+ "doc": "doc",
13
+ "test": "tests"
14
+ },
15
+ "scripts": {
16
+ "build": "ember build --environment=production",
17
+ "lint": "npm-run-all --print-name --aggregate-output --continue-on-error --parallel \"lint:!(fix)\"",
18
+ "lint:fix": "npm-run-all --print-name --aggregate-output --continue-on-error --parallel \"lint:*:fix\"",
19
+ "lint:hbs": "ember-template-lint .",
20
+ "lint:hbs:fix": "ember-template-lint . --fix",
21
+ "lint:js": "eslint . --cache",
22
+ "lint:js:fix": "eslint . --fix",
23
+ "start": "ember serve",
24
+ "test": "npm-run-all --print-name \"lint\" \"test:*\"",
25
+ "test:ember": "ember test",
26
+ "test:ember-compatibility": "ember try:each"
27
+ },
28
+ "dependencies": {
29
+ "ember-cli-babel": "^7.26.11",
30
+ "ember-cli-htmlbars": "^6.1.1"
31
+ },
32
+ "devDependencies": {
33
+ "@ember/optional-features": "^2.0.0",
34
+ "@ember/render-modifiers": "^2.1.0",
35
+ "@ember/test-helpers": "^2.8.1",
36
+ "@embroider/test-setup": "^1.8.3",
37
+ "@glimmer/component": "^1.1.2",
38
+ "@glimmer/tracking": "^1.1.2",
39
+ "babel-eslint": "^10.1.0",
40
+ "broccoli-asset-rev": "^3.0.0",
41
+ "ember-auto-import": "^2.4.3",
42
+ "ember-cli": "~4.8.1",
43
+ "ember-cli-dependency-checker": "^3.3.1",
44
+ "ember-cli-inject-live-reload": "^2.1.0",
45
+ "ember-cli-sri": "^2.1.1",
46
+ "ember-cli-terser": "^4.0.2",
47
+ "ember-disable-prototype-extensions": "^1.1.3",
48
+ "ember-load-initializers": "^2.1.2",
49
+ "ember-page-title": "^7.0.0",
50
+ "ember-qunit": "^6.0.0",
51
+ "ember-resolver": "^8.0.3",
52
+ "ember-source": "~4.8.0",
53
+ "ember-source-channel-url": "^3.0.0",
54
+ "ember-template-lint": "^4.16.1",
55
+ "ember-truth-helpers": "^4.0.3",
56
+ "ember-try": "^2.0.0",
57
+ "eslint": "^7.32.0",
58
+ "eslint-config-prettier": "^8.5.0",
59
+ "eslint-plugin-ember": "^11.1.0",
60
+ "eslint-plugin-node": "^11.1.0",
61
+ "eslint-plugin-prettier": "^4.2.1",
62
+ "eslint-plugin-qunit": "^7.3.1",
63
+ "loader.js": "^4.7.0",
64
+ "npm-run-all": "^4.1.5",
65
+ "prettier": "^2.7.1",
66
+ "qunit": "^2.19.2",
67
+ "qunit-dom": "^2.0.0",
68
+ "webpack": "^5.74.0"
69
+ },
70
+ "engines": {
71
+ "node": "14.* || 16.* || >= 18"
72
+ },
73
+ "ember": {
74
+ "edition": "octane"
75
+ },
76
+ "ember-addon": {
77
+ "configPath": "tests/dummy/config"
78
+ }
79
+ }