@aquera/nile-elements 0.0.5-9 → 0.0.6

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.
Files changed (43) hide show
  1. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/index.d.ts +1 -0
  2. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/index.js +1 -0
  3. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/index.js.map +1 -1
  4. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-switcher/index.d.ts +1 -0
  5. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-switcher/index.js +2 -0
  6. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-switcher/index.js.map +1 -0
  7. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-switcher/nile-switcher.css.d.ts +12 -0
  8. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-switcher/nile-switcher.css.js +35 -0
  9. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-switcher/nile-switcher.css.js.map +1 -0
  10. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-switcher/nile-switcher.d.ts +60 -0
  11. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-switcher/nile-switcher.js +124 -0
  12. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-switcher/nile-switcher.js.map +1 -0
  13. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/tsconfig.tsbuildinfo +1 -1
  14. package/dist/index.cjs.js +1 -1
  15. package/dist/index.esm.js +1 -1
  16. package/dist/index.iife.js +57 -1
  17. package/dist/nile-switcher/index.cjs.js +2 -0
  18. package/dist/nile-switcher/index.cjs.js.map +1 -0
  19. package/dist/nile-switcher/index.esm.js +1 -0
  20. package/dist/nile-switcher/nile-switcher.cjs.js +2 -0
  21. package/dist/nile-switcher/nile-switcher.cjs.js.map +1 -0
  22. package/dist/nile-switcher/nile-switcher.css.cjs.js +2 -0
  23. package/dist/nile-switcher/nile-switcher.css.cjs.js.map +1 -0
  24. package/dist/nile-switcher/nile-switcher.css.esm.js +23 -0
  25. package/dist/nile-switcher/nile-switcher.esm.js +30 -0
  26. package/dist/src/index.d.ts +1 -0
  27. package/dist/src/index.js +1 -0
  28. package/dist/src/index.js.map +1 -1
  29. package/dist/src/nile-switcher/index.d.ts +1 -0
  30. package/dist/src/nile-switcher/index.js +2 -0
  31. package/dist/src/nile-switcher/index.js.map +1 -0
  32. package/dist/src/nile-switcher/nile-switcher.css.d.ts +12 -0
  33. package/dist/src/nile-switcher/nile-switcher.css.js +35 -0
  34. package/dist/src/nile-switcher/nile-switcher.css.js.map +1 -0
  35. package/dist/src/nile-switcher/nile-switcher.d.ts +60 -0
  36. package/dist/src/nile-switcher/nile-switcher.js +124 -0
  37. package/dist/src/nile-switcher/nile-switcher.js.map +1 -0
  38. package/dist/tsconfig.tsbuildinfo +1 -1
  39. package/package.json +1 -1
  40. package/src/index.ts +2 -1
  41. package/src/nile-switcher/index.ts +1 -0
  42. package/src/nile-switcher/nile-switcher.css.ts +37 -0
  43. package/src/nile-switcher/nile-switcher.ts +185 -0
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Webcomponent nile-elements following open-wc recommendations",
4
4
  "license": "MIT",
5
5
  "author": "nile-elements",
6
- "version": "0.0.5-9",
6
+ "version": "0.0.6",
7
7
  "main": "dist/src/index.js",
8
8
  "type": "module",
9
9
  "module": "dist/src/index.js",
package/src/index.ts CHANGED
@@ -29,4 +29,5 @@ export { NileErrorMessage } from './nile-error-message';
29
29
  export { NileFormErrorMessage } from './nile-form-error-message';
30
30
  export { NileFormHelpText } from './nile-form-help-text';
31
31
  export { NileCalendar } from './nile-calendar';
32
- export { NileLink} from './nile-link';
32
+ export { NileLink } from './nile-link';
33
+ export { NileSwitcher } from './nile-switcher';
@@ -0,0 +1 @@
1
+ export { NileSwitcher } from './nile-switcher';
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Copyright Aquera Inc 2023
3
+ *
4
+ * This source code is licensed under the BSD-3-Clause license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import { css } from 'lit-element';
9
+
10
+ /**
11
+ * FieldGenerator CSS
12
+ */
13
+ export const styles = css`
14
+ :host {
15
+ display: inline-block;
16
+ width: 100%;
17
+ box-sizing: border-box;
18
+ }
19
+
20
+ .pointer-cursor {
21
+ cursor: pointer;
22
+ }
23
+ .input-container {
24
+ display: flex;
25
+ }
26
+
27
+ .input-container > :first-child {
28
+ width: 100%;
29
+ padding-right: 12px;
30
+ }
31
+ .flex-start {
32
+ align-items: flex-start;
33
+ padding-top: 10px;
34
+ }
35
+ `;
36
+
37
+ export default [styles];
@@ -0,0 +1,185 @@
1
+ /**
2
+ * Copyright Aquera Inc 2023
3
+ *
4
+ * This source code is licensed under the BSD-3-Clause license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import { html, property, TemplateResult } from 'lit-element';
9
+ import { customElement } from 'lit/decorators.js';
10
+ import { styles } from './nile-switcher.css';
11
+ import NileElement from '../internal/nile-element';
12
+ import { CSSResultGroup } from 'lit';
13
+ import { choose } from 'lit/directives/choose.js';
14
+ import { classMap } from 'lit/directives/class-map.js';
15
+
16
+ /**
17
+ * @summary Allows you to switch between nile elements
18
+
19
+ * @dependency nile-icon
20
+ * @dependency nile-input
21
+ * @dependency nile-checkbox
22
+ * @dependency nile-dropdown
23
+ * @dependency nile-textarea
24
+ *
25
+
26
+ * @event nile-change - Emitted when the control's value changes.
27
+ */
28
+
29
+ export interface switchconfig {
30
+ toggleSwitch: boolean;
31
+ defaultInput: switchInputType;
32
+ switchInput: switchInputType;
33
+ }
34
+
35
+ export interface switchInputType {
36
+ inputType: 'dropdown' | 'text' | 'checkbox' | 'text-area';
37
+ value?: String | boolean;
38
+ label?: String;
39
+ placeholder?: string;
40
+ options?: Array<any>;
41
+ multiple?: boolean;
42
+ }
43
+
44
+ @customElement('nile-switcher')
45
+ export class NileSwitcher extends NileElement {
46
+ /**
47
+ * The styles for nile switcher
48
+ * @remarks If you are extending this class you can extend the base styles with super. Eg `return [super(), myCustomStyles]`
49
+ */
50
+ static styles: CSSResultGroup = styles;
51
+ @property() nileSwitchConfig: switchconfig;
52
+
53
+ connectedCallback() {
54
+ super.connectedCallback();
55
+ this.emit('nile-init');
56
+ }
57
+
58
+ disconnectedCallback() {
59
+ super.disconnectedCallback();
60
+ this.emit('nile-destroy');
61
+ }
62
+
63
+ renderNileText(defaultInput: switchInputType) {
64
+ const { value, label, placeholder } = defaultInput;
65
+ return html`<nile-input
66
+ .value=${value}
67
+ .label=${label}
68
+ .placeholder=${placeholder}
69
+ @nile-input=${this.handleChange}
70
+ ></nile-input>`;
71
+ }
72
+
73
+ renderNileTextArea(switchInput: switchInputType) {
74
+ const { value } = switchInput;
75
+ return html`<nile-textarea
76
+ .value=${value}
77
+ @nile-input=${this.handleChange}
78
+ ></nile-textarea>`;
79
+ }
80
+
81
+ renderNileCheckBox(defaultInput: switchInputType) {
82
+ const { value, label } = defaultInput;
83
+
84
+ return html`<nile-checkbox
85
+ .checked=${value}
86
+ .label=${label}
87
+ @valueChange="${this.handleChangeCheckbox}"
88
+ ></nile-checkbox>`;
89
+ }
90
+
91
+ handleChange(event: CustomEvent) {
92
+ this.emit('nile-change', { value: event.detail.value });
93
+ }
94
+
95
+ handleChangeCheckbox(event: CustomEvent) {
96
+ this.emit('nile-change', { value: event.detail.checked });
97
+ }
98
+
99
+ renderDropdown(defaultInput: switchInputType) {
100
+ const { options, multiple, placeholder } = defaultInput;
101
+ return html`<nile-select
102
+ .placeholder=${placeholder}
103
+ .multiple="${multiple}"
104
+ @nile-change="${this.handleChange}"
105
+ >
106
+ ${options &&
107
+ options.map((option: any) => {
108
+ return html`<nile-option .value="${option}">${option} </nile-option>`;
109
+ })}
110
+ </nile-select>`;
111
+ }
112
+
113
+ renderIcon() {
114
+ const icon = !this.nileSwitchConfig.toggleSwitch
115
+ ? 'header-functions'
116
+ : 'stringinput';
117
+ return html`<nile-icon
118
+ size="14"
119
+ class=${classMap({
120
+ 'pointer-cursor': true,
121
+ 'flex-start': icon === 'stringinput',
122
+ })}
123
+ .name=${icon}
124
+ color="#005EA6"
125
+ @click=${this.toggleField}
126
+ ></nile-icon>`;
127
+ }
128
+
129
+ toggleField() {
130
+ this.nileSwitchConfig = {
131
+ ...this.nileSwitchConfig,
132
+ toggleSwitch: !this.nileSwitchConfig.toggleSwitch,
133
+ };
134
+ }
135
+
136
+ singleFieldSwitcher(
137
+ defaultInput: switchInputType,
138
+ switchInput: switchInputType,
139
+ toggleField: boolean
140
+ ) {
141
+ const defaultInputType = defaultInput.inputType;
142
+ const switchInputType = switchInput.inputType;
143
+ return html`
144
+ ${!toggleField
145
+ ? choose(
146
+ defaultInputType,
147
+ [
148
+ ['text', () => this.renderNileText(defaultInput)],
149
+ ['checkbox', () => this.renderNileCheckBox(defaultInput)],
150
+ [
151
+ 'dropdown',
152
+ () => this.renderDropdown(this.nileSwitchConfig.defaultInput),
153
+ ],
154
+ ],
155
+ () => this.renderNileText(defaultInput)
156
+ )
157
+ : choose(
158
+ switchInputType,
159
+ [['text-area', () => this.renderNileTextArea(switchInput)]],
160
+
161
+ () => this.renderNileTextArea(switchInput)
162
+ )}
163
+ ${this.renderIcon()}
164
+ `;
165
+ }
166
+ public render(): TemplateResult {
167
+ const {
168
+ toggleSwitch: toggleField,
169
+ defaultInput,
170
+ switchInput,
171
+ } = this.nileSwitchConfig;
172
+
173
+ return html`<div class="input-container">
174
+ ${this.singleFieldSwitcher(defaultInput, switchInput, toggleField)}
175
+ </div>`;
176
+ }
177
+ }
178
+
179
+ export default NileSwitcher;
180
+
181
+ declare global {
182
+ interface HTMLElementTagNameMap {
183
+ 'nile-switcher': NileSwitcher;
184
+ }
185
+ }