inviton-powerduck 0.0.168 → 0.0.169

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.
@@ -1,18 +1,19 @@
1
1
  import type { DropdownButtonItemArgs } from '../dropdown-button/dropdown-button-item';
2
2
  import type { FormItemWrapperArgs, HintType, MarginType } from '../form/form-item-wrapper';
3
+ import { render } from 'vue';
3
4
  import { Prop, toNative } from 'vue-facing-decorator';
4
5
  import TsxComponent, { Component } from '../../app/vuetsx';
6
+ import { capitalize } from '../../common/extensions/string-extensions';
5
7
  import { PortalUtils } from '../../common/utils/utils';
6
8
  import FormItemWrapper from '../form/form-item-wrapper';
7
9
  import HtmlLiteral from '../html-literal/html-literal';
8
10
  import './css/radio-button-group.css';
9
- import { capitalize } from '../../common/extensions/string-extensions';
10
11
 
11
12
  type RowToString = (row) => string;
12
13
  interface RadioButtonGroupArgs extends FormItemWrapperArgs {
13
14
  changed: (newValue: string | any) => void;
14
- formatResult?: (state: RadioDisplayArgs) => JQuery | string;
15
- formatSelection?: (state: RadioDisplayArgs) => JQuery | string;
15
+ customRenderOption?: (h, state: RadioDisplayArgs) => any;
16
+ customRenderSelectionResult?: (h, state: RadioDisplayArgs) => any;
16
17
  options: Array<string> | Array<any>;
17
18
  displayMember?: string | RowToString;
18
19
  valueMember?: string | RowToString;
@@ -53,12 +54,12 @@ class RadioButtonGroupComponent extends TsxComponent<RadioButtonGroupArgs> imple
53
54
  @Prop() valueMember!: (row) => string | string;
54
55
  @Prop() selected!: string | any;
55
56
  @Prop() changed: (newValue: string | any) => void;
56
- @Prop() formatResult!: (state: RadioDisplayArgs) => JQuery | string;
57
- @Prop() formatSelection!: (state: RadioDisplayArgs) => JQuery | string;
57
+ @Prop() customRenderOption?: (h, state: RadioDisplayArgs) => any;
58
+ @Prop() customRenderSelectionResult?: (h, state: RadioDisplayArgs) => any;
58
59
 
59
- getFormatedResult(item: RadioDisplayArgs): string {
60
- if (this.formatResult != null) {
61
- return (this.formatResult(item) as JQuery<HTMLElement>).html();
60
+ getCustomFormatOptions(h, item: RadioDisplayArgs): string {
61
+ if (this.customRenderOption != null) {
62
+ return this.customRenderOption(h, item);
62
63
  }
63
64
  }
64
65
 
@@ -116,7 +117,7 @@ class RadioButtonGroupComponent extends TsxComponent<RadioButtonGroupArgs> imple
116
117
  }
117
118
  }
118
119
 
119
- getOptions(): RadioDisplayArgs[] {
120
+ getOptions(h): RadioDisplayArgs[] {
120
121
  const retVal: RadioDisplayArgs[] = [];
121
122
  const opts = this.options as any;
122
123
 
@@ -130,7 +131,7 @@ class RadioButtonGroupComponent extends TsxComponent<RadioButtonGroupArgs> imple
130
131
  opts.forEach((item) => {
131
132
  retVal.push({
132
133
  id: this.getReflectedRowValue(item, true),
133
- text: this.formatResult != null ? this.getFormatedResult(item) : this.getReflectedRowValue(item, false),
134
+ text: this.customRenderOption != null ? this.handleCustomRenderResult(h, this.customRenderOption(h, item)) : this.getReflectedRowValue(item, false),
134
135
  dataRow: item,
135
136
  });
136
137
  });
@@ -140,8 +141,26 @@ class RadioButtonGroupComponent extends TsxComponent<RadioButtonGroupArgs> imple
140
141
  return retVal;
141
142
  }
142
143
 
143
- getSelectedItem(opts?: RadioDisplayArgs[]): RadioDisplayArgs {
144
- opts = opts || this.getOptions();
144
+ private handleCustomRenderResult(h: any, renderResult: any): string {
145
+ if (renderResult == null) {
146
+ return '';
147
+ }
148
+
149
+ if (renderResult?.__v_isVNode) {
150
+ const container = document.createElement('div');
151
+ render(renderResult as any, container);
152
+ return container.innerHTML;
153
+ }
154
+
155
+ if (renderResult instanceof HTMLElement) {
156
+ return renderResult.outerHTML;
157
+ }
158
+
159
+ return renderResult;
160
+ }
161
+
162
+ getSelectedItem(h, opts?: RadioDisplayArgs[]): RadioDisplayArgs {
163
+ opts = opts || this.getOptions(h);
145
164
 
146
165
  if (this.selected == null || opts.length == 0) {
147
166
  return opts[0];
@@ -189,10 +208,10 @@ class RadioButtonGroupComponent extends TsxComponent<RadioButtonGroupArgs> imple
189
208
  );
190
209
  }
191
210
 
192
- handleRadioValueChanged() {
211
+ handleRadioValueChanged(h) {
193
212
  const selectedValue = this.$el.querySelector('input[type="radio"]:checked').value;
194
213
  if (selectedValue != null) {
195
- const opts = this.getOptions();
214
+ const opts = this.getOptions(h);
196
215
  for (let i = 0, len = opts.length; i < len; i++) {
197
216
  const optItem = opts[i];
198
217
  if (optItem.id == selectedValue) {
@@ -205,12 +224,12 @@ class RadioButtonGroupComponent extends TsxComponent<RadioButtonGroupArgs> imple
205
224
 
206
225
  renderInput(h) {
207
226
  const nameId = `iei-group-${PortalUtils.randomString(6)}`;
208
- const selectedItem = this.getSelectedItem();
227
+ const selectedItem = this.getSelectedItem(h);
209
228
  const isSmall = this.radioButtonSize === RadioButtonSize.Small;
210
229
 
211
230
  return (
212
231
  <div class="radio-group-wrap">
213
- {this.getOptions().map((optionItem) => {
232
+ {this.getOptions(h).map((optionItem) => {
214
233
  const uuid = `iei-input-${PortalUtils.randomString(10)}`;
215
234
  const selected = optionItem.id == selectedItem?.id;
216
235
  const disabled = optionItem.dataRow?.disabled ?? false;
@@ -234,7 +253,7 @@ class RadioButtonGroupComponent extends TsxComponent<RadioButtonGroupArgs> imple
234
253
  id={uuid}
235
254
  value={optionItem.id}
236
255
  disabled={disabled}
237
- onChange={() => this.handleRadioValueChanged()}
256
+ onChange={() => this.handleRadioValueChanged(h)}
238
257
  />
239
258
  <label class="form-check-label" for={uuid}>
240
259
  <HtmlLiteral innerHTML={optionItem.text} />
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "inviton-powerduck",
3
3
  "type": "module",
4
- "version": "0.0.168",
4
+ "version": "0.0.169",
5
5
  "files": [
6
6
  "app/",
7
7
  "common/",