not-bulma 1.0.27 → 1.0.28

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "not-bulma",
3
- "version": "1.0.27",
3
+ "version": "1.0.28",
4
4
  "description": "not-* family UI components on Bulma CSS Framework",
5
5
  "main": "src/index.js",
6
6
  "svelte": "src/index.js",
@@ -1,6 +1,8 @@
1
1
  <script>
2
+ import {createEventDispatcher } from 'svelte';
3
+ const dispatch = createEventDispatcher();
2
4
  import {LOCALE} from '../../locale';
3
-
5
+
4
6
  export let title = '';
5
7
  export let light = false;
6
8
  export let loading = false;
@@ -17,10 +19,17 @@
17
19
  export let icon = false;
18
20
  export let iconSide = 'right';
19
21
  export let action = ()=>{ return true; };
22
+
23
+
24
+ function onClick(e){
25
+ dispatch('click', e);
26
+ return action(e);
27
+ }
28
+
20
29
  </script>
21
30
 
22
31
  <button
23
- on:click="{action}"
32
+ on:click={onClick}
24
33
  {disabled}
25
34
  type={type?type:""}
26
35
  class="
@@ -37,17 +46,19 @@
37
46
  {size?`is-${size}`:''}
38
47
  "
39
48
  >
40
- {#if icon }
41
- {#if iconSide === 'left' }
42
- <span class="icon"><i class="fas fa-{icon} {size?`is-${size}`:''}"></i></span>
43
- {/if}
44
- {#if title }
45
- <span>{$LOCALE[title]}</span>
46
- {/if}
47
- {#if iconSide === 'right' }
49
+ <slot>
50
+ {#if icon }
51
+ {#if iconSide === 'left' }
48
52
  <span class="icon"><i class="fas fa-{icon} {size?`is-${size}`:''}"></i></span>
49
- {/if}
50
- {:else}
51
- {$LOCALE[title]}
52
- {/if}
53
+ {/if}
54
+ {#if title }
55
+ <span>{$LOCALE[title]}</span>
56
+ {/if}
57
+ {#if iconSide === 'right' }
58
+ <span class="icon"><i class="fas fa-{icon} {size?`is-${size}`:''}"></i></span>
59
+ {/if}
60
+ {:else}
61
+ {$LOCALE[title]}
62
+ {/if}
63
+ </slot>
53
64
  </button>
@@ -0,0 +1,24 @@
1
+ <script>
2
+ import {createEventDispatcher } from 'svelte';
3
+ let dispatch = createEventDispatcher();
4
+
5
+ import {LOCALE} from '../../locale';
6
+
7
+ export let id = -1;
8
+ export let type = -1;
9
+ export let title = -1;
10
+ export let readonly = false;
11
+
12
+ function remove(e){
13
+ e && e.preventDefault();
14
+ dispatch('delete', id);
15
+ return false;
16
+ }
17
+
18
+ </script>
19
+
20
+ <span class="mx-1 tag is-{type}">{$LOCALE[title]}
21
+ {#if !readonly }
22
+ <button data-id="{id}" class="delete is-small" on:click="{remove}"></button>
23
+ {/if}
24
+ </span>
@@ -0,0 +1,128 @@
1
+ <script>
2
+ import {createEventDispatcher } from 'svelte';
3
+ let dispatch = createEventDispatcher();
4
+
5
+ import {LOCALE} from '../../locale';
6
+ const LC_ADD = 'not-node:add_label';
7
+ const LC_SELECT_FROM_LIST = 'not-node:select_from_list_label';
8
+
9
+ import ErrorsList from '../various/ui.errors.list.svelte';
10
+ import UICommon from '../common.js';
11
+ import UISelectComplexItem from './ui.select.complex.item.svelte';
12
+ import UIButton from '../button/ui.button.svelte';
13
+
14
+ //list of item ids
15
+ export let value = []; //raw ids of variants
16
+ export let inputStarted = false;
17
+ export let variants = [];
18
+ export let fieldname = 'tag';
19
+ export let required = true;
20
+ export let readonly = false;
21
+ export let valid = true;
22
+ export let validated = false;
23
+ export let errors = false;
24
+ export let formErrors = false;
25
+ export let formLevelError = false;
26
+ //
27
+ export let ItemComponent = UISelectComplexItem;
28
+
29
+ export let beforeAdd = (/*variant, variants*/)=>{
30
+ return true;
31
+ };
32
+
33
+ export let getItemId = (variant)=>{
34
+ return variant.id;
35
+ };
36
+
37
+ export let getItemTitle = (variant)=>{
38
+ return variant.title;
39
+ };
40
+
41
+ export let getItemType = (variant)=>{
42
+ return 'info';
43
+ };
44
+
45
+ export let buildItem = (variant)=>{
46
+ return {
47
+ id: getItemId(variant),
48
+ title: getItemTitle(variant),
49
+ type: getItemType(variant)
50
+ };
51
+ };
52
+
53
+ function variantIdToVariant(id){
54
+ return variants.find(variant => getItemId(variant) === id);
55
+ }
56
+
57
+ function changeEvent(){
58
+ let data = {
59
+ field: fieldname,
60
+ value
61
+ };
62
+ dispatch('change', data);
63
+ }
64
+
65
+ function remove(e){
66
+ e && e.preventDefault();
67
+ let id = e.currentTarget.dataset.id;
68
+ if(value.includes(id)){
69
+ value.splice(value.indexOf(id), 1);
70
+ value = value;
71
+ changeEvent();
72
+ }
73
+ return false;
74
+ }
75
+
76
+ function add(e){
77
+ e && e.preventDefault();
78
+ let id = e.currentTarget.parentNode.querySelector('select').value;
79
+ const variant = variantIdToVariant(id);
80
+ if(!variant){
81
+ return false;
82
+ }
83
+ if(!beforeAdd(variant, variants)){
84
+ return false;
85
+ }
86
+ if(id && (value.indexOf(id) === -1)){
87
+ value.push(id);
88
+ value = value;
89
+ changeEvent();
90
+ }
91
+ return false;
92
+ }
93
+
94
+
95
+ //item = {
96
+ // id, //unique
97
+ // title, //some text
98
+ // type //for coloring items, usual html template names danger, success, etc
99
+ //}
100
+
101
+ $: items = value.map(variantIdToVariant).map(buildItem);
102
+ $: allErrors = [].concat(errors?errors:[], formErrors?formErrors:[]);
103
+ $: showErrors = (!(validated && valid) && (inputStarted));
104
+ $: invalid = ((valid===false) || (formLevelError));
105
+ $: validationClasses = (valid===true || !inputStarted)?UICommon.CLASS_OK:UICommon.CLASS_ERR;
106
+
107
+ </script>
108
+
109
+ <div class="control columns">
110
+ <div class="column {validationClasses}">
111
+ {#each items as item (item.id)}
112
+ <UISelectComplexItem {...item} {readonly} />
113
+ {/each}
114
+ </div>
115
+ {#if !readonly }
116
+ <div class="column">
117
+ <div class="control">
118
+ <UIButton primary={true} size="small" on:click={add} title={LC_ADD} />
119
+ </div>
120
+ </div>
121
+ {/if}
122
+ </div>
123
+ <ErrorsList
124
+ bind:errors={allErrors}
125
+ bind:show={showErrors}
126
+ bind:classes={validationClasses}
127
+ id="input-field-helper-{fieldname}"
128
+ />
@@ -6,17 +6,21 @@
6
6
  export let size = 1;
7
7
  export let subsize;
8
8
  export let spaced = false;
9
+ export let align = 'left';
9
10
 
10
11
  let size2;
11
12
  $: size2 = subsize?subsize:(size<6?size+1:size);
12
13
  $: spacedStyle = (spaced?'is-spaced':'');
13
14
 
14
- $: resultTitle = `<h${size} class="title ${spacedStyle} is-${size}">${$LOCALE[title]}</h${size}>`;
15
- $: resultSubtitle = `<h${size2} class="subtitle is-${size2}">${$LOCALE[subtitle]}</h${size2}>`;
15
+ $: resultTitle = `<h${size} style="text-align: ${align};" class="title ${spacedStyle} is-${size}">${$LOCALE[title]}</h${size}>`;
16
+ $: resultSubtitle = `<h${size2} style="text-align: ${align};" class="subtitle is-${size2}">${$LOCALE[subtitle]}</h${size2}>`;
16
17
 
17
18
  </script>
18
19
 
20
+
21
+ {#if title }
19
22
  {@html resultTitle }
23
+ {/if}
20
24
 
21
25
  {#if subtitle }
22
26
  {@html resultSubtitle }