1.0.13 • Published 2 years ago

sm-ui-kit v1.0.13

Weekly downloads
-
License
-
Repository
-
Last release
2 years ago

SM-UI-LIBRARY

This library was generated with Angular CLI version 12.2.0.

Installing

npm install sm-ui-library

Developing Locally

To see your changes to sm-ui-library locally you'll need to link the package with npm:

$ git clone https://git.rapidops.com/salesmate/sm-ui-kit.git
$ cd /path/to/sm-ui-kit
$ npm link
$ cd /path/to/assets-frontend
$ rm -rf node_modules/sm-ui-kit
$ npm link sm-ui-kit

Put below scripts in angular.json

"options": {
            ...
            "styles": [
              ...
              "node_modules/sm-ui-library/assets/styles/scss/sm-init.scss",
              ...
            ],
            "preserveSymlinks": true
          },

Update app.module.ts file

import {CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA} from '@angular/core';
import {SmUiLibraryModule} from "sm-ui-library";

@NgModule({
  ...
  imports: [
    ...
    SmUiLibraryModule
    ...
  ],
  schemas: [NO_ERRORS_SCHEMA, CUSTOM_ELEMENTS_SCHEMA]
})
export class AppModule {
}

Restrict strictInitialization in tsconfig.app.json

{
  ...
  "compilerOptions": {
    ...
    "strictPropertyInitialization": false
  },
  ...
}

Adding various components

Textfield

@html
<sm-input-txt 
              [formGroup]="formGroup"
              [fieldMeta]="textField"
              (blur)="onBlur($event)">
</sm-input-txt>

@typescript

import {  TextField } from "sm-ui-library";
...
export class AppComponent implements OnInit {
    ...
  textField: TextField;
  formGroup: FormGroup;

  constructor(private changeRef: ChangeDetectorRef) {
    this.formGroup = new FormGroup({});
  }

  ngOnInit(): any {
    this.makeFields();
  }

  makeFields(): any {
    this.textField = new TextField({
      fieldName: 'textField',
      displayName: 'Input box'
    });
  }

  onBlur(): void {
    console.log('test blur', this.formGroup.value);
  }
}
html attributes
AttributesData-TypeDefaultsRequiredUses
formGroupFormGroup''yesreference to existing formGroup
fieldMetaTextField-yesMetadata of text field
valuestring''nodefault value for text field
showLabelbooleantruenoto show or hide the label
fieldMeta attributes
AttributesData-typeDefaultsRequiredUses
classstring''noclass to be applied on component
showLinkbooleanfalsenoto show as link above text field (should be used with type='url' or with fieldName=linkedInHandle/facebookHandle/twitterHandle/googlePlusHandle/instagramHandle)
typestring-notype of the field
inputTypestring'text'notype of input field
titlestring''notitle of the field
customLinkedInUrlstring'https://linkedin.com/in/'noto show linked in link (used with fieldName = linkedInHandle)
events
EventsUses
blurcalled on blur of field
focuscalled on focus of the field
keyupcalled on keyup of the field
functions available in TextField
FunctionDescription
getLink(value: any)It is used to return link value

DateRangePickerField

@html
<div>
  <slable>Date range picker</slable>
  <sm-daterange-picker [formGroup]="formGroup"
                       [cssClass]="'label-inline m-b-none w-md '"
                       [fieldMeta]="dateRangePickerField"
                       (blur)="onDateRangePickerBlur($event)">
  </sm-daterange-picker>
</div>

@typescript
import {  DateRangePickerField } from "sm-ui-library";

export class AppComponent implements OnInit {
    ...
  dateRangePickerField: DateRangePickerField;
  formGroup: FormGroup;
  rangeOptions:any

  constructor(private changeRef: ChangeDetectorRef) {
    this.formGroup = new FormGroup({});
    this.rangeOptions = {
        'Today': [moment(), moment()],
        'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
        'This Week': [moment().startOf('week'), moment().endOf('week')],
        'Last Week': [moment().subtract(1, 'week').startOf('week'), moment().subtract(1, 'week').endOf('week')],
        'This Month': [moment().startOf('month'), moment().endOf('month')],
        'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')],
        'This Quarter': [moment().startOf('quarter'), moment().endOf('quarter')],
        'Last Quarter': [moment().subtract(1, 'quarter').startOf('quarter'), moment().subtract(1, 'quarter').endOf('quarter')],
        'This Year': [moment().startOf('year'), moment().endOf('year')],
        'Last Year': [moment().subtract(1, 'year').startOf('year'), moment().subtract(1, 'year').endOf('year')]
    }
  }

  ngOnInit(): any {
    this.dateRangePickerField = new DateRangePickerField({
      minDate: moment().startOf('d'),
      dateFormat: 'DD-MM-YYYY',
      fieldName: 'dateRange',
      opens: 'right',
      locale: {
        format: 'DD-MM-YYYY'
      },
      startDate: moment().startOf('d'),
      endDate: moment().add(30, 'days').startOf('d'),
      ranges: rangeOptions
    });
  }  

  onDateRangePickerBlur($event: any) {
      console.log($event);
  }
}
html attributes
AttributesData-TypeDefaultsRequiredUses
formGroupFormGroup''yesreference to existing formGroup
fieldMetaTextField-yesMetadata of text field
valuestring''nodefault value for text field,
showLabelbooleantruenoto show or hide the label (displayName must be there in fieldMeta)
fieldMeta attributes
AttributesData-typeDefaultsRequiredUses
dateFormatstring'DD-MM-YYYY hh:mm:ss'nodate format of the field
readOnlybooleanfalsenoto disable and enable field
classstring''noclass for the field
singleDatePickerbooleanfalsenoto show single date picker popup
timePickerbooleanfalsenoto show only time picker
startDatestring''nodefault start date
endDatestring''nodefault end date
minDatestring''nominimum date of the field
maxDatestring''nomaximum date of the field
rangesany{}yesrange options to show
opensstring'left'noto open popup position
timePicker24Hourbooleanfalsenoto show time in 24 hour format
applyButtonClassesstring''noclasses for apply button
events
EventsUses
blurcalled on blur of field
functions available in DateRangePickerField
FunctionDescription
DateRangePickerField.getDateRangeValue(rangeType)It return value of given range type (rangeType can be among these 'LAST_7_DAYS', 'LAST_30_DAYS', 'TODAY', 'YESTERDAY', 'THIS_WEEK', 'LAST_WEEK', 'NEXT_WEEK', 'THIS_MONTH', 'LAST_MONTH', 'NEXT_MONTH', 'THIS_QUARTER', 'LAST_QUARTER', 'NEXT_QUARTER', 'THIS_YEAR', 'LAST_YEAR', 'NEXT_YEAR', 'MORE_THAN_X_DAYS_AGO', 'LESS_THAN_X_DAYS_AGO', 'MORE_THAN_X_UPCOMING_DAYS', 'LESS_THAN_X_UPCOMING_DAYS')
DateRangePickerField.getPreviousDateRangeValue(rangeType)It return previous value of given range type (rangeType can be among these 'LAST_7_DAYS', 'LAST_30_DAYS', 'TODAY', 'YESTERDAY', 'THIS_WEEK', 'LAST_WEEK', 'NEXT_WEEK', 'THIS_MONTH', 'LAST_MONTH', 'NEXT_MONTH', 'THIS_QUARTER', 'LAST_QUARTER', 'NEXT_QUARTER', 'THIS_YEAR', 'LAST_YEAR', 'NEXT_YEAR', 'MORE_THAN_X_DAYS_AGO', 'LESS_THAN_X_DAYS_AGO', 'MORE_THAN_X_UPCOMING_DAYS', 'LESS_THAN_X_UPCOMING_DAYS')

CheckboxField

@html
<sm-checkbox
    [formGroup]="formGroup"
    [fieldMeta]="checkboxField"
    [value]="checkboxField.value">
</sm-checkbox>

@typescript
import {  CheckboxField } from "sm-ui-library";
...
export class AppComponent implements OnInit {
    ...
    checkboxField: CheckboxField;
    formGroup:FormGroup;
    checkOptions:Array<any>;
    ...
    constructor(private changeRef: ChangeDetectorRef) {
        this.formGroup = new FormGroup({});
        this.checkOptions = [{label: 'one', value: 'one'}, {label: 'two', value: 'two'}]
    }
    ngOnInit(){
        this.checkboxField = new CheckboxField({
              fieldName: 'email_isTracking',
              displayName: 'Checkboxes',
              options: checkOptions
            });
        this.checkboxField.value = 'one'
    }
}
html attributes
AttributesData-TypeDefaultsRequiredUses
formGroupFormGroup''yesreference to existing formGroup
fieldMetaTextField-yesMetadata of text field
valuestring''nodefault value for text field,
showLabelbooleantruenoto show or hide the label,
fieldMeta attributes
AttributesData-typeDefaultsRequiredUses
readOnlybooleanfalsenoto disable and enable field
classstring''noclass for the field
optionsArray[]nooptions to show in checkboxes
newLinebooleanfalsenoto show the checkboxes in new line
events
EventsUses
blurcalled on blur of field

TextareaField

@html
<sm-textarea-txt
    [showLabel]="true"
    [formGroup]="formGroup"
    [fieldMeta]="textAreaField">
</sm-textarea-txt>

@typescript
import { TextareaField } from "sm-ui-library";
...
export class AppComponent implements OnInit {
    ...
    textAreaField: TextareaField;
    formGroup:FormGroup;
    ...
    constructor(private changeRef: ChangeDetectorRef) {
        this.formGroup = new FormGroup({});
    }

    ngOnInit(){
        this.textAreaField = new TextareaField({
              fieldName: 'reason',
              displayName: 'Text Area',
              placeholder: 'Your text area field'
        });
    }
}
html attributes
AttributesData-TypeDefaultsRequiredUses
formGroupFormGroup''yesreference to existing formGroup
fieldMetaTextField-yesMetadata of text field
valuestring''nodefault value for text field,
showLabelbooleantruenoto show or hide the label,
doTrimbooleantruenotrims the value of the text area
fieldMeta attributes
AttributesData-typeDefaultsRequiredUses
fieldNamestring''trueto set the value of field in formGroup
displayNamestring''falseto show label and title of the field
placeholderstring''noplaceholder of the field
events
EventsUses
blurcalled on blur of field

RadioField

@html
<sm-radio
  [fieldMeta]="radioField"
  [formGroup]="formGroup"
  (blur)="onRadioChanged($event)">
</sm-radio>

@typescript
import { RadioField } from "sm-ui-library";

...
export class AppComponent implements OnInit {
    ...
    radioField: RadioField;
    formGroup:FormGroup;
    radioOptions: Array<any>;
    ...
    constructor(private changeRef: ChangeDetectorRef) {
        this.formGroup = new FormGroup({});
        this.radioOptions = [
                           {label: 'DAYS', value: 'DAYS'},
                           {label: 'RANGE', value: 'RANGE'},
                           {label: 'NONE', value: 'NONE'},
                         ]
    }

    ngOnInit(){
        this.radioField = new RadioField({
              fieldName: 'meetingDateRangeType',
              options: this.radioOptions
        });
    }
}
html attributes
AttributesData-TypeDefaultsRequiredUses
formGroupFormGroup''yesreference to existing formGroup
fieldMetaTextField-yesMetadata of text field
valuestring''nodefault value for text field,
showLabelbooleantruenoto show or hide the label
fieldMeta attributes
AttributesData-typeDefaultsRequiredUses
fieldNamestring''trueto set the value of field in formGroup
displayNamestring''falseto show label and title of the field
optionsArray[]nooptions to show in radios
optionClassstring''noif you want to apply class in options
readOnlybooleanfalsenoto enable disable the fields
events
EventsUses
blurcalled on blur of field

SelectField

@html
<sm-select-box
      [formGroup]="formGroup"
      [fieldMeta]="selectField"
      [value]="selectField.value">
</sm-select-box>

@typescript
import { SelectField } from "sm-ui-library";
...
export class AppComponent implements OnInit {
    ...
    selectField: SelectField;
    formGroup:FormGroup;
    selectOptions: Array<any>;
    ...
    constructor(private changeRef: ChangeDetectorRef) {
        this.formGroup = new FormGroup({});
        this.selectOptions = [{label: 'First option', value: 'Value One'}, {label: 'Second option', value: 'Value Two'}]
    }

    ngOnInit(){
        this.selectField = new SelectField({
              fieldName: 'fromUser',
              displayName: 'Select Field',
              defaultSelectFirst: true,
              options: this.selectOptions,
              container: '.test-container'
        });
        this.selectField.value = 'Value One'
    }
}
html attributes
AttributesData-TypeDefaultsRequiredUses
formGroupFormGroup''yesreference to existing formGroup
fieldMetaTextField-yesMetadata of text field
valuestring''nodefault value for text field,
showLabelbooleantruenoto show or hide the label
dropdownItemTemplatestring''notemplate for the open dropdown
selectionTemplatestring''notemplate for the selected values
fieldMeta attributes
AttributesData-typeDefaultsRequiredUses
fieldNamestring''trueto set the value of field in formGroup
displayNamestring''falseto show label and title of the field
optionsArray[]nooptions to show in radios
readOnlybooleanfalsenoto enable disable the fields
placeholderstring''noto show the placeholder of the dropdown
isMultiplebooleanfalsenoto enable multiple selection in select box
countSelectedTextstring''nodefault count selection
hasAddButtonbooleanfalsenoto show add button in select box
addButtonTitlestring'Add New'nobutton title for add button
addButtonHtmlstring<div class="btn">${this.addButtonTitle}</div>nohtml for add button
onAddNewfunction_.noopnodefined function when add button get clicked
events
EventsUses
blurcalled on blur of field

SwitchField

@html
<sm-switch [formGroup]="formGroup"
           [fieldMeta]="switchField">
</sm-switch>

@typescript
import { SwitchField } from "sm-ui-library";
...
export class AppComponent implements OnInit {
    ...
    switchField: SwitchField;
    formGroup:FormGroup;
    ...
    constructor(private changeRef: ChangeDetectorRef) {
        this.formGroup = new FormGroup({});
    }

    ngOnInit(){
        this.switchField = new SwitchField({
              fieldName: 'switch',
              displayName: 'Switch field'
        });
    }
}
html attributes
AttributesData-TypeDefaultsRequiredUses
formGroupFormGroup''yesreference to existing formGroup
fieldMetaTextField-yesMetadata of text field
valuestring''nodefault value for text field,
showLabelbooleantruenoto show or hide the label
fieldMeta attributes
AttributesData-typeDefaultsRequiredUses
classstring''falseclass to be applied on field
optionsArray[]nooptions to show in field
readOnlybooleanfalsenoto enable disable the fields
newLinebooleanfalsenoto show new line in switch
events
EventsUses
blurcalled on blur of field

TagField

@html
<sm-tag id="tagsToAdd" [formGroup]="formGroup"
          [fieldMeta]="tagsField">
</sm-tag>

@typescript
import { TagField } from "sm-ui-library";
...
export class AppComponent implements OnInit {
    ...
    tagsField: TagField;
    formGroup:FormGroup;
    ...
    constructor(private changeRef: ChangeDetectorRef) {
        this.formGroup = new FormGroup({});
    }

    ngOnInit(){
        this.tagsField = new TagField({
              fieldName: 'tagsToAdd',
        });
    }
}
html attributes
AttributesData-TypeDefaultsRequiredUses
formGroupFormGroup''yesreference to existing formGroup
fieldMetaTextField-yesMetadata of text field
valuestring''nodefault value for text field,
events
EventsUses
blurcalled on blur of field
tagClickedcalled when tag is clicked

DateTimePicker

@html
<sm-datetime-picker [formGroup]="formGroup"
                    [fieldMeta]="dateTimeField"
                    [cssClass]="'m-b-none'"
                    [showLabel]="true">
</sm-datetime-picker>

@typescript
import { DateTimePickerField } from "sm-ui-library";
...
export class AppComponent implements OnInit {
    ...
    dateTimeField: DateTimePickerField;
    formGroup:FormGroup;
    ...
    constructor(private changeRef: ChangeDetectorRef) {
        this.formGroup = new FormGroup({});
    }

    ngOnInit(){
        this.dateTimeField = new DateTimePickerField({
              dateFormat: 'DD-MM-YYYY',
              fieldName: 'startDate',
              displayName: 'Date time field',
              sideBySide: false
        });
    }
}
html attributes
AttributesData-TypeDefaultsRequiredUses
formGroupFormGroup''yesreference to existing formGroup
fieldMetaTextField-yesMetadata of text field
valuestring''nodefault value for text field,
showLabelbooleantruenoto show or hide the label
fieldMeta attributes
AttributesData-typeDefaultsRequiredUses
classstring''falseclass to be applied on field
readOnlybooleanfalsenoto enable disable the fields
dateFormatstring'DD-MM-YYYY hh:mm:ss'nodefault date format
toolbarPlacementstring'top'noposition of the toolbar
minDatestring''nominimum date for field
maxDatestring''nomaximum date for field
inlinebooleanfalsenothis shows the datetime picker inline (not as popup)
events
EventsUses
blurcalled on blur of field
functions available in DateTimePickerField
FunctionDescription
DateTimePickerField.isIsoDate(dateString:any)It returns whether the date is in ISO format or not

ButtonField

@html
<sm-button
    [fieldMeta]="buttonField"
    (btnClicked)="buttonClicked($event)">
</sm-button>

@typescript
import { ButtonField } from "sm-ui-library";
...
export class AppComponent implements OnInit {
    ...
    buttonField: ButtonField;
    formGroup:FormGroup;
    ...
    constructor(private changeRef: ChangeDetectorRef) {
        this.formGroup = new FormGroup({});
    }

    ngOnInit(){
        this.buttonField = new ButtonField({
              fieldName: 'buttonField',
              btnText: 'Button',
              class: 'btn btn-primary pull-left m-l-sm',
              type: 'Button',
              disable: false
        });
    }
}
html attributes
AttributesData-TypeDefaultsRequiredUses
formGroupFormGroup''yesreference to existing formGroup
fieldMetaTextField-yesMetadata of text field
fieldMeta attributes
AttributesData-typeDefaultsRequiredUses
btnTextstring''notext of the button
fieldNamestring''yesit used as a key in formGroup
disablebooleanfalsenothis allows to enable disable the button
classstring'btn-default'noto apply class on the button
iconCssClassstring''noto apply class on icon of button
showCompletedbooleanfalsenothis shows complete tick mark on button
showLoadingbooleanfalsenothis shows loading mask on button
events
EventsUses
btnClickedcalled on blur of field

Some general function can be used in all the components

FunctionDescription
this.setValidation(validations: any)This applies various validations on field. Validations can be like this ({required:{message:"your message"}, pattern:{value:"your regex",message:""},maxlength:{value:"your length",message:""},minlength:{value:"your length",message:""},min:{value:"your length",message:""},max:{value:"your length",message:""},number:{message:""},integer:{message:""},email:{message:""},minTags:{value:"",message:""},maxTags:{value:"",message:""}})
this.clearValidation()clears the validation of field
this.setPlaceholder(placeholder:string)sets the place holder for field

Some formElementService function can be used in general

FunctionDescription
this.formElementService.showCompletedMark(event:any, changeRef?: any)it shows completed mark on button
this.formElementService.showLoading(event:any, changeRef?: any)it shows loader on button
this.formElementService.stopLoading(event:any, changeRef?: any)it stops loader on button
this.formElementService.isFormValid(formGroup:any, elementRef?:any, changeRef?:any)it validates the form and return true/false with respect to valid/invalid
this.formElementService.getSuggestionsDropdownTemplate(name:any, email:any, image?:any, searchText?:any, icon?:any)This returns dropdown selections template based on given params
this.formElementService.getDropdownTemplate(name:any, iconClass?:any, searchText?:any)This returns dropdown template based on given params