@kizmann/nano-ui 1.0.10 → 1.0.12

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,4 +1,4 @@
1
- import { Arr, Any, Dom } from "@kizmann/pico-js";
1
+ import { Arr, Any, Dom, Str, Locale } from "@kizmann/pico-js";
2
2
 
3
3
  export default {
4
4
 
@@ -14,17 +14,59 @@ export default {
14
14
 
15
15
  provide()
16
16
  {
17
- return { NFrame: this };
17
+ return { NFormFrame: this };
18
+ },
19
+
20
+ props: {
21
+
22
+ showSearch: {
23
+ default()
24
+ {
25
+ return false;
26
+ },
27
+ type: [Boolean]
28
+ },
29
+
30
+ searchPlaceholder: {
31
+ default()
32
+ {
33
+ return Locale.trans('Search ...');
34
+ },
35
+ type: [String]
36
+ },
37
+
38
+ searchIcon: {
39
+ default()
40
+ {
41
+ return 'fa fa-times';
42
+ },
43
+ type: [String]
44
+ },
45
+
46
+ kind: {
47
+ default()
48
+ {
49
+ return '';
50
+ },
51
+ type: [String]
52
+ },
53
+
18
54
  },
19
55
 
20
56
  data()
21
57
  {
22
- return { inview: [] };
58
+ return { search: '' };
23
59
  },
24
60
 
25
61
  mounted()
26
62
  {
27
- Any.delay(() => this.onScrollEvent());
63
+ this.$watch('search', () => {
64
+ this.onSearchInput();
65
+ });
66
+
67
+ this.$nextTick(() => {
68
+ this.onScrollEvent();
69
+ });
28
70
  },
29
71
 
30
72
  methods: {
@@ -45,27 +87,33 @@ export default {
45
87
  this.$refs.menu.scrollIntoView(selector)
46
88
 
47
89
  }, this.$el);
48
- }
90
+ },
49
91
 
50
- },
92
+ onSearchInput()
93
+ {
94
+ let search = Str.lower(this.search);
51
95
 
52
- renderMenu(item)
53
- {
54
- let labelHtml = (
55
- <span>{item.label}</span>
56
- );
96
+ Dom.find(this.$el).find(`[data-menu-key]`)
97
+ .removeClass('on-search');
57
98
 
58
- let iconHtml = null;
99
+ if ( Any.isEmpty(search) ) {
100
+ return;
101
+ }
59
102
 
60
- if ( item.icon ) {
61
- iconHtml = (<i class={item.icon} />);
62
- }
103
+ let groups = Arr.filter(this.NForm.groups, (group) => {
104
+ return Str.lower(group.label).indexOf(search) !== -1;
105
+ });
63
106
 
64
- let buttonProps = {
65
- href: '#' + item.key
66
- }
107
+ Arr.each(groups, (group) => {
108
+ Dom.find(this.$el).find(`[data-menu-key="${group.key}"]`).addClass('on-search');
109
+ });
110
+ },
67
111
 
68
- buttonProps['onClick'] = () => {
112
+ onClickEvent(item, event = null)
113
+ {
114
+ if ( ! Any.isEmpty(event) ) {
115
+ event.preventDefault();
116
+ }
69
117
 
70
118
  let selector = `[data-group-key="${item.key}"]`
71
119
 
@@ -83,7 +131,58 @@ export default {
83
131
  Dom.find(selector).removeClass('on-search');
84
132
  }, 4000);
85
133
 
86
- Dom.find(selector).addClass('on-search');
134
+ this.$nextTick(() => {
135
+ Dom.find(selector).addClass('on-search');
136
+ });
137
+
138
+ this.$refs.body.scrollIntoView(selector)
139
+ }
140
+
141
+ },
142
+
143
+ renderSearch()
144
+ {
145
+ if ( ! this.showSearch ) {
146
+ return null;
147
+ }
148
+
149
+ let searchProps = {
150
+ placeholder: this.searchPlaceholder
151
+ };
152
+
153
+ if ( ! Any.isEmpty(this.search) ) {
154
+ searchProps.icon = this.searchIcon;
155
+ }
156
+
157
+ searchProps['onIconClick'] = () => {
158
+ this.search = '';
159
+ }
160
+
161
+ return (
162
+ <div class="n-form-frame__search">
163
+ <NInput vModel={this.search} {...searchProps}></NInput>
164
+ </div>
165
+ )
166
+ },
167
+
168
+ renderMenu(item)
169
+ {
170
+ let labelHtml = (
171
+ <span>{item.label}</span>
172
+ );
173
+
174
+ let iconHtml = null;
175
+
176
+ if ( item.icon ) {
177
+ iconHtml = (<i class={item.icon} />);
178
+ }
179
+
180
+ let buttonProps = {
181
+ href: '#' + item.key
182
+ }
183
+
184
+ buttonProps['onClick'] = (e) => {
185
+ this.onClickEvent(item, e)
87
186
  };
88
187
 
89
188
  let classList = [
@@ -106,7 +205,7 @@ export default {
106
205
 
107
206
  return (
108
207
  <n-scrollbar ref="menu" class="n-form-frame__menus">
109
- { items } { this.$slots.menu && this.$slots.menu() }
208
+ { this.ctor('renderSearch')() } { items } { this.$slots.menu && this.$slots.menu() }
110
209
  </n-scrollbar>
111
210
  );
112
211
  },
@@ -135,6 +234,10 @@ export default {
135
234
  'n-form-frame--' + this.NForm.size
136
235
  ];
137
236
 
237
+ if ( ! Any.isEmpty(this.search) ) {
238
+ classList.push('n-form-frame--search')
239
+ }
240
+
138
241
  return (
139
242
  <div class={classList}>
140
243
  {[this.$slots.frame && this.$slots.frame(), this.ctor('renderMenus')(), this.ctor('renderBody')()]}
@@ -20,11 +20,34 @@
20
20
 
21
21
  .n-form-frame__menu {
22
22
  cursor: pointer;
23
+ position: relative;
23
24
  display: flex;
24
25
  align-items: center;
25
26
  width: 100%;
26
27
  border-radius: $md-radius;
27
28
  text-decoration: none;
29
+ transition: opacity 0.3s;
30
+ }
31
+
32
+ .n-form-frame--search .n-form-frame__menu:not(.on-search) {
33
+ opacity: 0.6;
34
+ }
35
+
36
+ .n-form-frame__menu:before {
37
+ content: '\00a0';
38
+ position: absolute;
39
+ top: 50%;
40
+ display: block;
41
+ width: 6px;
42
+ height: 6px;
43
+ margin-top: -3px;
44
+ border-radius: 500px;
45
+ opacity: 0;
46
+ transition: opacity 0.3s;
47
+ }
48
+
49
+ .n-form-frame__menu.on-search:before {
50
+ opacity: 1;
28
51
  }
29
52
 
30
53
  .n-form-frame__menu:not(:last-child) {
@@ -67,10 +90,19 @@
67
90
  padding: $-form-frame-size * 0.5 $-form-frame-size * 0.6;
68
91
  }
69
92
 
93
+ .n-form-frame--#{$suffix} .n-form-frame__search {
94
+ margin-bottom: $-form-frame-size * 0.4;
95
+ }
96
+
70
97
  .n-form-frame--#{$suffix} .n-form-frame__menu {
71
98
  height: $-form-frame-size;
72
99
  font-size: $-form-frame-font - 1;
73
100
  border-radius: $-form-frame-radius;
101
+ padding-right: $-form-frame-size * 0.6;
102
+ }
103
+
104
+ .n-form-frame--#{$suffix} .n-form-frame__menu:before {
105
+ right: $-form-frame-size * 0.3;
74
106
  }
75
107
 
76
108
  .n-form-frame--#{$suffix} .n-form-frame__menu i {
@@ -82,8 +114,4 @@
82
114
  padding: $-form-frame-size * 0.2 $-form-frame-size * 0.6 $-form-frame-size * 0.2 0;
83
115
  }
84
116
 
85
- .n-form-frame--#{$suffix} .n-form-frame__body .n-form-group {
86
- padding: $-form-frame-size * 0.2 $-form-frame-size * 0.6;
87
- }
88
-
89
117
  }
@@ -8,6 +8,10 @@ export default {
8
8
 
9
9
  NForm: {
10
10
  default: undefined
11
+ },
12
+
13
+ NFormFrame: {
14
+ default: undefined
11
15
  }
12
16
 
13
17
  },
@@ -56,7 +60,7 @@ export default {
56
60
  kind: {
57
61
  default()
58
62
  {
59
- return 'classic';
63
+ return '';
60
64
  },
61
65
  type: [String]
62
66
  },
@@ -243,16 +247,26 @@ export default {
243
247
 
244
248
  render()
245
249
  {
246
- let size = this.size ;
250
+ let size = this.size;
247
251
 
248
252
  if ( this.NForm ) {
249
253
  size = size || this.NForm.size;
250
254
  }
251
255
 
256
+ let kind = this.kind;
257
+
258
+ if ( this.NFormFrame ) {
259
+ kind = kind || this.NFormFrame.kind;
260
+ }
261
+
262
+ if ( this.NForm ) {
263
+ kind = kind || this.NForm.kind;
264
+ }
265
+
252
266
  let classList = [
253
267
  'n-form-group',
254
268
  'n-form-group--' + size,
255
- 'n-form-group--' + this.kind,
269
+ 'n-form-group--' + kind,
256
270
  'n-form-group--' + this.type,
257
271
  'n-form-group--' + this.align,
258
272
  ];
@@ -7,7 +7,7 @@
7
7
 
8
8
  .n-form-group:before {
9
9
  pointer-events: none;
10
- z-index: -1;
10
+ z-index: 0;
11
11
  content: '\00a0';
12
12
  position: absolute;
13
13
  top: 0;
@@ -20,7 +20,11 @@
20
20
  }
21
21
 
22
22
  .n-form-group.on-search:before {
23
- opacity: 0.15;
23
+ opacity: 0.1;
24
+ }
25
+
26
+ .n-form-group--collapse .n-form-group__legend {
27
+ cursor: pointer;
24
28
  }
25
29
 
26
30
  .n-form-group--classic .n-form-group__legend {
@@ -92,6 +96,7 @@
92
96
 
93
97
  .n-form-group--#{$suffix}.n-form-group--fieldset {
94
98
  margin-bottom: $-form-group-size;
99
+ padding: 0 $-form-group-size * 0.6;
95
100
  }
96
101
 
97
102
  .n-form-group--#{$suffix}.n-form-group--fieldset:first-child {
@@ -102,23 +107,23 @@
102
107
  margin-top: $-form-group-size * 1.4;
103
108
  }
104
109
 
105
- .n-form-group--classic.n-form-group--#{$suffix} .n-form-group__legend {
110
+ .n-form-group--#{$suffix}.n-form-group--classic .n-form-group__legend {
106
111
  font-size: $-form-group-font;
107
112
  min-height: $-form-group-size * 1.2;
108
113
  }
109
114
 
110
- .n-form-group--fieldset.n-form-group--#{$suffix} .n-form-group__legend {
115
+ .n-form-group--#{$suffix}.n-form-group--fieldset .n-form-group__legend {
111
116
  min-height: $-form-group-size;
112
117
  border-radius: $-form-group-radius;
113
118
  top: $-form-group-size * -0.5;
114
119
  padding: 0 $-form-group-size * 0.3;
115
120
  }
116
121
 
117
- .n-form-group--classic.n-form-group--#{$suffix} .n-form-group__label span {
122
+ .n-form-group--#{$suffix}.n-form-group--classic .n-form-group__label span {
118
123
  font-size: $-form-group-font + 1;
119
124
  }
120
125
 
121
- .n-form-group--fieldset.n-form-group--#{$suffix} .n-form-group__label span {
126
+ .n-form-group--#{$suffix}.n-form-group--fieldset .n-form-group__label span {
122
127
  font-size: $-form-group-font - 2;
123
128
  }
124
129
 
@@ -127,7 +132,7 @@
127
132
  height: $-form-group-size;
128
133
  }
129
134
 
130
- .n-form-group--fieldset.n-form-group--#{$suffix} .n-form-group__collapse {
135
+ .n-form-group--#{$suffix}.n-form-group--fieldset .n-form-group__collapse {
131
136
  margin-right: $-form-group-size * -0.3;
132
137
  }
133
138
 
@@ -135,12 +140,12 @@
135
140
  margin-right: $-form-group-size * $-form-group-ratio * 0.7;
136
141
  }
137
142
 
138
- .n-form-group--classic.n-form-group--#{$suffix} .n-form-group__body {
143
+ .n-form-group--#{$suffix}.n-form-group--classic .n-form-group__body {
139
144
  padding-top: $-form-group-size * $-form-group-ratio;
140
145
  }
141
146
 
142
- .n-form-group--fieldset.n-form-group--#{$suffix} .n-form-group__body {
143
- padding-top: $-form-group-size * 0.6;
147
+ .n-form-group--#{$suffix}.n-form-group--fieldset .n-form-group__body {
148
+ padding-top: $-form-group-size;
144
149
  }
145
150
 
146
151
  }
@@ -196,12 +196,12 @@ export default {
196
196
  }
197
197
  },
198
198
 
199
- scrollIntoView(selector, delay = 0)
199
+ scrollIntoView(selector, delay = 0, offset = 0)
200
200
  {
201
- Any.delay(() => this.onScrollIntoView(selector), delay);
201
+ Any.delay(() => this.onScrollIntoView(selector, offset), delay);
202
202
  },
203
203
 
204
- onScrollIntoView(selector)
204
+ onScrollIntoView(selector, offset = 0)
205
205
  {
206
206
  let $el = Dom.find(this.$el).find(selector);
207
207
 
@@ -15,6 +15,10 @@
15
15
  $-color-light: map.get($values, 'light');
16
16
  $-color-dark: map.get($values, 'dark');
17
17
 
18
+ .n-form-frame__menu--#{$color}.on-search:before {
19
+ background: $-color-base;
20
+ }
21
+
18
22
  .n-form-frame__menu--#{$color}.is-visible {
19
23
  background: rgba($-color-base, 0.15);
20
24
  }
@@ -1,7 +1,7 @@
1
1
  @use "sass:map";
2
2
  @import "../../../root/vars";
3
3
 
4
- .n-form-group--fieldset.n-form-group--collapse {
4
+ .n-form-group--fieldset {
5
5
  border: 1px solid $color-gray-10;
6
6
  }
7
7
 
@@ -36,7 +36,7 @@
36
36
  color: $-color-base;
37
37
  }
38
38
 
39
- .n-form-group--#{$color}.on-search:before {
39
+ .n-form-group--#{$color}:before {
40
40
  background: linear-gradient(135deg, $-color-base 0, transparent 300px);
41
41
  }
42
42