1.4.2 • Published 3 years ago

tpk-ui v1.4.2

Weekly downloads
1
License
MIT
Repository
github
Last release
3 years ago

tpk-ui

Ui components (input, textarea, radio, checkbox, select, modal, flash messages, tooltips, etc.), with tailwindcss 1.* for ember

Compatibility

  • Ember.js v3.16 or above
  • Ember CLI v2.13 or above
  • Node.js v10 or above

Installation

ember install tpk-ui

Install will automaticaly install the validator package for the validation.

:question: This addon is using ember-base-form-validation for validation of inputs and most of components extends BaseValidationInputComponent class and so must be linked to a BaseValidationFormComponent by the @parent attribute.

Available inputs components

  • TpkTimepicker
  • TpkInput
  • TpkTextarea
  • TpkRadioGroup
  • TpkCheckboxGroup
  • TpkSelect

Other components

  • TpkFlash
  • TpkBubble
  • TpkModal
  • TpkSlider

Full example

<ValidationForm  {{on "submit" this.submit}} @schema={{this.validation}} as |tpkform|>

    <div class="block">
      <TpkTimepicker 
        @value={{mut @model.timestart}} 
        @mode="12"
        @startHour="8"
        @endHour="11"
        @onchange={{action "settime" "timestart"}}
      />
    </div>

    

    <div class="block">
      <TpkTimepicker 
        @value={{@model.datetimestart}} 
        @steps="10"
        @isDate="true"
        @onchange={{action "settime" "datetimestart"}}
      />
    </div>

    @value: valeur à traiter
    @mode 12 || 24 sytème horaire à 12 (AM/PM) ou 24h - 24 par défaut
    @isDate la valeur est une date (true/false) - false par défaut

    <div class="block">
      <TpkInput 
        @parent={{tpkform}}
        @value={{@model.firstname}} 
        @label="Firstname" 
        @validation="firstname"
        @idname="firstname"
        as |i|>
        {{#if i.error}}
          <p>{{i.error}}</p>
        {{/if}}
      </TpkInput>
    </div>

    
    <div class="block">
      <TpkTextarea 
        @parent={{tpkform}}
        @value={{@model.description}} 
        @label="Description" 
        @validation="description"
        @idname="description"
        as |i|>
        {{#if i.error}}
          <p>{{i.error}}</p>
        {{/if}}
      </TpkTextarea>
    </div>
    


    <div class="block">
      {{!-- Action on group change --}}
      <TpkRadioGroup @name="radioselect" @validation="active" @parent={{tpkform}} @onchange={{action "changeRadio"}} as |R|>

        {{!-- Action on particular radio input --}}
        <R.radio 
          @idname="radioOn"
          @value="on" 
          @label="On" 
          @model={{@model.active}}
          @onchange={{action "changeParticularRadio"}}
        />

        <R.radio 
          @idname="radioOff"
          @value="off" 
          @label="Off"
          @model={{@model.active}} 
        />

        {{#if R.error}}
          <p>{{R.error}}</p>
        {{/if}}

      </TpkRadioGroup>
      {{@model.active}}
    </div>
    
    <div class="block">
      {{!-- Action on group change --}}
      <TpkCheckboxGroup @name="checkboxselect" @validation="colors" @parent={{tpkform}} @onchange={{action "changeCheckbox"}} as |R|>

        {{!-- Action on particular checkbox input --}}
        <R.checkbox   
          @idname="checkRed"
          @value="red" 
          @label="Red" 
          @model={{@model.colors}}
          @onchange={{action "changeParticularCheckbox"}}
        />

        <R.checkbox 
          @idname="checkBlue"
          @value="blue" 
          @label="Blue" 
          @model={{@model.colors}}
        />

        <R.checkbox 
          @idname="checkGreen"
          @value="green" 
          @label="Green" 
          @model={{@model.colors}}
        />

        {{#if R.error}}
          <p>{{R.error}}</p>
        {{/if}}
        
      </TpkCheckboxGroup>
      {{@model.colors}}
    </div>
    
    <div class="block">
      <h2>Select with plain array ['admin','user']</h2>
      <TpkSelect 
        @parent={{tpkform}} 
        @validation="role" 
        @name="roleselect" 
        @selected={{@model.role}}
        @options={{this.options}} 
        @onchange={{this.changeSelect}} as |tpkselect|>

        <tpkselect.option />
      
      </TpkSelect>
      {{@model.role}}
    </div>


    <div class="block">
      <h2>Select with array of objects [{id: 1, name: 'admin'},{id: 2, name: 'user'}]</h2>
      <TpkSelect 
        @parent={{tpkform}} 
        @validation="role" 
        @name="roleselect" 
        @selected={{@model.roleobj}}
        @options={{this.optionsobj}} 
        @onchange={{this.changeSelectObj}} as |tpkselect|>

        <tpkselect.option as |opt|>
          {{opt.args.option.name}}
        </tpkselect.option>
      
      </TpkSelect>
      { id: {{@model.roleobj.id}}, name: {{@model.roleobj.name}} }
    </div>
    
    

    <div class="block">
      {{#if tpkform.validating}}
        <p>Validating...</p>
      {{else}}
        <input type="submit" {{on "click" tpkform.validate}} value="submit">
      {{/if}}
    </div>

</ValidationForm>

Other Components example

TpkFlash


In application template

<TpkFlash />

In controller

@service tpkFlash;

Create flash message

get(this, "tpkFlash").throwFlash({
  type: 'warning',
  htmlSafe: true,
  sticky: true,
  stageTime: 1000,
  message: "Flash Message",
  customClose: get(this, "customClose")
});

type: Default "success"

sticky: Auto hide the flash message, default false

stageTime: If sticky false, time in milliseconds before the flash message removes itself

htmlSafe: Allow html safe tags in message, default false

message: Content of the flash message

customClose: Custom function called on close

Delete specific Flash Message

get(this, "tpkFlash").removeFlash(flash);

Full example

@action
openFlashMessage(type){        
    get(this, "tpkFlash").throwFlash({
      message: "Flash Message",
      customClose: get(this, "customClose")
    });
}

@action
customClose(flash){
  get(this, "tpkFlash").removeFlash(flash);
}

Delete all Flash Message

get(this, "tpkFlash").clearFlashes();

TpkBubble


<TpkBubble
    @bubblePosition="top right" as |bubble|
  >
  <bubble.icon>
    Tooltip container
  </bubble.icon>

  <bubble.content>
    Tooltip content
  </bubble.content>

</TpkBubble>

@bubblePosition: top || bottom, left || right

possible to combine one vertical and one horizontal axis. eg. "top left", "bottom right"

TpkModal


<a href="#" {{action "openModal"}}>Open</a>
<TpkModal @showModal={{this.showModal}} @closePopin={{action "closePopin"}}>
  Modal Content
</TpkModal>
@action
openPopin(){
  set(this, 'showModal', true);
}

@action
closePopin(){
  set(this, 'showModal', false);
}

License

This project is licensed under the MIT License.

1.4.2

3 years ago

1.4.1

3 years ago

1.4.0

4 years ago

1.3.7

4 years ago

1.3.6

4 years ago

1.3.5

4 years ago

1.3.4

4 years ago

1.3.3

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.13

4 years ago

1.2.12

4 years ago

1.2.10

4 years ago

1.2.11

4 years ago

1.2.9

4 years ago

1.2.8

4 years ago

1.2.7

4 years ago

1.2.6

4 years ago

1.2.5

4 years ago

1.2.4

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.0

4 years ago

1.2.1

4 years ago

1.1.22

4 years ago

1.1.16

4 years ago

1.1.19

4 years ago

1.1.18

4 years ago

1.1.17

4 years ago

1.1.21

4 years ago

1.1.20

4 years ago

1.1.15

4 years ago

1.1.11

4 years ago

1.1.14

4 years ago

1.1.10

4 years ago

1.1.9

4 years ago

1.1.8

4 years ago

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.0.21

4 years ago

1.0.20

4 years ago

1.0.19

4 years ago

1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.2.12

5 years ago

0.2.11

5 years ago

0.2.10

5 years ago

0.2.9

5 years ago

0.2.8

5 years ago

0.2.7

5 years ago

0.2.6

5 years ago

0.2.5

5 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.0.0

5 years ago