Skip to content

Commit

Permalink
Merge pull request #29 from gjovanovicst/main
Browse files Browse the repository at this point in the history
Implemented radio-button and radio-group components, cosmetics and ui…
  • Loading branch information
gjovanovicst authored Feb 21, 2022
2 parents d8a746c + 68c5b44 commit a7b762b
Show file tree
Hide file tree
Showing 86 changed files with 3,195 additions and 1,780 deletions.
2 changes: 1 addition & 1 deletion packages/angular/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/angular/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@anywhere-ui/angular",
"version": "0.2.0+7",
"version": "0.2.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
Expand Down Expand Up @@ -42,5 +42,5 @@
"tslint": "~6.1.0",
"typescript": "~4.4.4"
},
"buildnum": "7"
"buildnum": "8"
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
import { NgModule } from '@angular/core';
import { defineCustomElements } from '@anywhere-ui/core/loader';
import { CommonModule, DOCUMENT } from '@angular/common';
import {
ModuleWithProviders,
APP_INITIALIZER,
NgModule,
NgZone,
InjectionToken,
} from '@angular/core';
import { AnywhereUIConfig } from '@anywhere-ui/core';
import { appInitialize } from './app-initialize';
import { ConfigToken } from './providers/config';

import { BooleanValueAccessor } from './directives/boolean-value-accessor';
// import { NumericValueAccessor } from './directives/number-value-accessor';
// import { RadioValueAccessor } from './directives/radio-value-accessor';
import { RadioValueAccessor } from './directives/radio-value-accessor';
import { SelectValueAccessor } from './directives/select-value-accessor';
import { TextValueAccessor } from './directives/text-value-accessor';

Expand All @@ -20,9 +29,11 @@ import {
AnyBadgeOverlay,
AnyRippleEffect,
AnyInputSwitch,
AnyRadioButton,
AnyRadioGroup,
} from './directives/proxies';

defineCustomElements(window);
// defineCustomElements(window);

const DECLARATIONS = [
// proxies
Expand All @@ -38,18 +49,44 @@ const DECLARATIONS = [
AnyBadgeOverlay,
AnyRippleEffect,
AnyInputSwitch,
AnyRadioButton,
AnyRadioGroup,

// Value Accessors
BooleanValueAccessor,
// NumericValueAccessor,
// RadioValueAccessor,
RadioValueAccessor,
SelectValueAccessor,
TextValueAccessor,
];

@NgModule({
declarations: DECLARATIONS,
exports: DECLARATIONS,
imports: [],
imports: [CommonModule],
})
export class AnywhereUiModule {}
export class AnywhereUiModule {
static forRoot(
config?: AnywhereUIConfig
): ModuleWithProviders<AnywhereUiModule> {
return {
ngModule: AnywhereUiModule,
providers: [
{
provide: ConfigToken,
useValue: config,
},
// {
// provide: ConfigToken,
// useValue: config,
// },
{
provide: APP_INITIALIZER,
useFactory: appInitialize,
multi: true,
deps: [ConfigToken, DOCUMENT, NgZone],
},
],
};
}
}
40 changes: 40 additions & 0 deletions packages/angular/projects/anywhere-ui/src/lib/app-initialize.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { NgZone } from '@angular/core';
import { setupConfig } from '@anywhere-ui/core';
import { applyPolyfills, defineCustomElements } from '@anywhere-ui/core/loader';

import { Config } from './providers/config';
// import { IonicWindow } from './types/interfaces';
import { raf } from './util/util';

export const appInitialize = (config: Config, doc: Document, zone: NgZone) => {
return (): any => {
// const win: IonicWindow | undefined = doc.defaultView as any;
const win = window;
if (win && typeof (window as any) !== 'undefined') {
setupConfig({
...config,
_zoneGate: (h: any) => zone.run(h),
});

const aelFn =
'__zone_symbol__addEventListener' in (doc.body as any)
? '__zone_symbol__addEventListener'
: 'addEventListener';

return applyPolyfills().then(() => {
return defineCustomElements(win, {
// exclude: ['ion-tabs', 'ion-tab'],
syncQueue: true,
raf,
jmp: (h: any) => zone.runOutsideAngular(h),
ael(elm, eventName, cb, opts) {
(elm as any)[aelFn](eventName, cb, opts);
},
rel(elm, eventName, cb, opts) {
elm.removeEventListener(eventName, cb, opts);
},
});
});
}
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ export const defineCustomElement = (tagName: string, customElement: any) => {
}

// tslint:disable-next-line: only-arrow-functions
export function ProxyCmp(opts: { tagName: string, customElement?: any, inputs?: any; methods?: any }) {
export function ProxyCmp(opts: { defineCustomElementFn?: () => void, inputs?: any; methods?: any }) {
const decorator = function (cls: any) {
const { tagName, customElement, inputs, methods } = opts;
const { defineCustomElementFn, inputs, methods } = opts;

defineCustomElement(tagName, customElement);
if (defineCustomElementFn !== undefined) {
defineCustomElementFn();
}

if (inputs) {
proxyInputs(cls, inputs);
Expand Down
105 changes: 79 additions & 26 deletions packages/angular/projects/anywhere-ui/src/lib/directives/proxies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import { Components } from '@anywhere-ui/core';
export declare interface AnyBadge extends Components.AnyBadge {}

@ProxyCmp({
tagName: 'any-badge',
customElement: undefined,
defineCustomElementFn: undefined,
inputs: ['anyStyle', 'severity', 'size', 'styleClass', 'value']
})
@Component({
Expand All @@ -33,8 +32,7 @@ export class AnyBadge {
export declare interface AnyBadgeOverlay extends Components.AnyBadgeOverlay {}

@ProxyCmp({
tagName: 'any-badge-overlay',
customElement: undefined,
defineCustomElementFn: undefined,
inputs: ['styleClass']
})
@Component({
Expand Down Expand Up @@ -69,8 +67,7 @@ export declare interface AnyButton extends Components.AnyButton {
}

@ProxyCmp({
tagName: 'any-button',
customElement: undefined,
defineCustomElementFn: undefined,
inputs: ['anyStyle', 'badge', 'badgeClass', 'disabled', 'icon', 'iconHeight', 'iconPos', 'iconWidth', 'label', 'loading', 'loadingIcon', 'loadingIconStyleClass', 'styleClass', 'type']
})
@Component({
Expand Down Expand Up @@ -106,16 +103,15 @@ export declare interface AnyCheckbox extends Components.AnyCheckbox {
}

@ProxyCmp({
tagName: 'any-checkbox',
customElement: undefined,
inputs: ['anyStyle', 'binary', 'checkboxIcon', 'checked', 'disabled', 'inputId', 'label', 'labelStyleClass', 'name', 'readonly', 'styleClass', 'value'],
defineCustomElementFn: undefined,
inputs: ['anyStyle', 'anyTabIndex', 'binary', 'checkboxIcon', 'checked', 'disabled', 'inputId', 'label', 'labelStyleClass', 'name', 'readonly', 'styleClass', 'value'],
methods: ['inputFocus']
})
@Component({
selector: 'any-checkbox',
changeDetection: ChangeDetectionStrategy.OnPush,
template: '<ng-content></ng-content>',
inputs: ['anyStyle', 'binary', 'checkboxIcon', 'checked', 'disabled', 'inputId', 'label', 'labelStyleClass', 'name', 'readonly', 'styleClass', 'value']
inputs: ['anyStyle', 'anyTabIndex', 'binary', 'checkboxIcon', 'checked', 'disabled', 'inputId', 'label', 'labelStyleClass', 'name', 'readonly', 'styleClass', 'value']
})
export class AnyCheckbox {
protected el: HTMLElement;
Expand Down Expand Up @@ -164,8 +160,7 @@ export declare interface AnyDropdown extends Components.AnyDropdown {
}

@ProxyCmp({
tagName: 'any-dropdown',
customElement: undefined,
defineCustomElementFn: undefined,
inputs: ['anyStyle', 'anyTabIndex', 'autoZIndex', 'baseZIndex', 'clearIcon', 'disabled', 'dropdownIcon', 'hideAnimation', 'inputId', 'name', 'optionLabel', 'optionValue', 'options', 'panelScrollHeight', 'placeholder', 'readonly', 'showAnimation', 'showClear', 'value', 'virtualScroll']
})
@Component({
Expand Down Expand Up @@ -201,8 +196,7 @@ export declare interface AnyInputSwitch extends Components.AnyInputSwitch {
}

@ProxyCmp({
tagName: 'any-input-switch',
customElement: undefined,
defineCustomElementFn: undefined,
inputs: ['anyStyle', 'anyTabIndex', 'ariaLabeledBy', 'checked', 'disabled', 'falseValue', 'inputId', 'name', 'readonly', 'styleClass', 'trueValue']
})
@Component({
Expand Down Expand Up @@ -230,8 +224,7 @@ export declare interface AnyInputText extends Components.AnyInputText {
}

@ProxyCmp({
tagName: 'any-input-text',
customElement: undefined,
defineCustomElementFn: undefined,
inputs: ['disabled', 'floatLabel', 'inputId', 'inputWrapperClass', 'label', 'leftIconClass', 'name', 'placeholder', 'readonly', 'rightIconClass', 'value'],
methods: ['getInputRef']
})
Expand Down Expand Up @@ -260,8 +253,7 @@ export declare interface AnyListbox extends Components.AnyListbox {
}

@ProxyCmp({
tagName: 'any-listbox',
customElement: undefined,
defineCustomElementFn: undefined,
inputs: ['anyStyle', 'disabled', 'inputId', 'listStyle', 'name', 'optionLabel', 'optionValue', 'options', 'readonly', 'scrollerHeight', 'value', 'virtualScroll']
})
@Component({
Expand All @@ -280,11 +272,75 @@ export class AnyListbox {
}


export declare interface AnyRadioButton extends Components.AnyRadioButton {
/**
* Callback to invoke on radio button select.
*/
aOnSelect: EventEmitter<CustomEvent<any>>;
/**
* Callback to invoke when the radio button receives focus.
*/
aOnFocus: EventEmitter<CustomEvent<any>>;
/**
* Callback to invoke when the radio button loses focus.
*/
aOnBlur: EventEmitter<CustomEvent<any>>;

}

@ProxyCmp({
defineCustomElementFn: undefined,
inputs: ['anyStyle', 'anyTabIndex', 'disabled', 'inputId', 'label', 'labelStyleClass', 'name', 'styleClass', 'value'],
methods: ['setFocus']
})
@Component({
selector: 'any-radio-button',
changeDetection: ChangeDetectionStrategy.OnPush,
template: '<ng-content></ng-content>',
inputs: ['anyStyle', 'anyTabIndex', 'disabled', 'inputId', 'label', 'labelStyleClass', 'name', 'styleClass', 'value']
})
export class AnyRadioButton {
protected el: HTMLElement;
constructor(c: ChangeDetectorRef, r: ElementRef, protected z: NgZone) {
c.detach();
this.el = r.nativeElement;
proxyOutputs(this, this.el, ['aOnSelect', 'aOnFocus', 'aOnBlur']);
}
}

import type { RadioGroupChangeEventDetail as IRadioGroupRadioGroupChangeEventDetail } from '@anywhere-ui/core';
export declare interface AnyRadioGroup extends Components.AnyRadioGroup {
/**
* Emitted when the value has changed.
*/
valueChange: EventEmitter<CustomEvent<IRadioGroupRadioGroupChangeEventDetail>>;

}

@ProxyCmp({
defineCustomElementFn: undefined,
inputs: ['allowEmptySelection', 'name', 'value']
})
@Component({
selector: 'any-radio-group',
changeDetection: ChangeDetectionStrategy.OnPush,
template: '<ng-content></ng-content>',
inputs: ['allowEmptySelection', 'name', 'value']
})
export class AnyRadioGroup {
protected el: HTMLElement;
constructor(c: ChangeDetectorRef, r: ElementRef, protected z: NgZone) {
c.detach();
this.el = r.nativeElement;
proxyOutputs(this, this.el, ['valueChange']);
}
}


export declare interface AnyRippleEffect extends Components.AnyRippleEffect {}

@ProxyCmp({
tagName: 'any-ripple-effect',
customElement: undefined,
defineCustomElementFn: undefined,
inputs: ['type']
})
@Component({
Expand All @@ -305,8 +361,7 @@ export class AnyRippleEffect {
export declare interface AnyTabPanel extends Components.AnyTabPanel {}

@ProxyCmp({
tagName: 'any-tab-panel',
customElement: undefined,
defineCustomElementFn: undefined,
inputs: ['disabled', 'header', 'selected']
})
@Component({
Expand All @@ -327,8 +382,7 @@ export class AnyTabPanel {
export declare interface AnyTabView extends Components.AnyTabView {}

@ProxyCmp({
tagName: 'any-tab-view',
customElement: undefined,
defineCustomElementFn: undefined,
inputs: ['activeIndex', 'anyStyle', 'styleClass']
})
@Component({
Expand Down Expand Up @@ -371,8 +425,7 @@ export declare interface AnyVirtualScroller extends Components.AnyVirtualScrolle
}

@ProxyCmp({
tagName: 'any-virtual-scroller',
customElement: undefined,
defineCustomElementFn: undefined,
inputs: ['anyStyle', 'contentElemClass', 'contentElemTag', 'delay', 'itemElemClass', 'itemSize', 'itemTag', 'items', 'lazy', 'noDataText', 'rowsPerPage', 'scrollElemClass', 'scrollerHeight', 'styleClass']
})
@Component({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Directive, ElementRef } from '@angular/core';
import { NG_VALUE_ACCESSOR } from '@angular/forms';

import { ValueAccessor } from './value-accessor';

@Directive({
/* tslint:disable-next-line:directive-selector */
selector: 'any-radio-button',
host: {
'(aOnSelect)': 'handleChangeEvent($event.target.checked)'
},
providers: [
{
provide: NG_VALUE_ACCESSOR,
useExisting: RadioValueAccessor,
multi: true
}
]
})
export class RadioValueAccessor extends ValueAccessor {
constructor(el: ElementRef) {
super(el);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ValueAccessor } from './value-accessor';

@Directive({
/* tslint:disable-next-line:directive-selector */
selector: 'any-dropdown, any-listbox, any-virtual-scroller',
selector: 'any-dropdown, any-listbox, any-virtual-scroller, any-radio-group',
host: {
'(valueChange)': 'handleChangeEvent($event.target.value)'
},
Expand Down
Loading

0 comments on commit a7b762b

Please sign in to comment.