@soleil-se/config-svelte 1.17.0 → 1.18.0

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/CHANGELOG.md CHANGED
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.18.0] - 2023-01-20
9
+
10
+ - Option templating in [CustomSelector](./components/CustomSelector).
11
+ - Add global Select2 styling.
12
+ - Modal now closes open Select2 dropdowns.
13
+
8
14
  ## [1.17.0] - 2022-12-01
9
15
 
10
16
  - New component: [RepositoryNodeSelector](./components/RepositoryNodeSelector).
@@ -1,6 +1,7 @@
1
1
  <script>
2
2
  import { createEventDispatcher, onMount, tick } from 'svelte';
3
- import { generateId, setupComponent } from '../../utils';
3
+ import { generateId } from '../../utils';
4
+ import i18n from './i18n';
4
5
 
5
6
  const values = window.CONFIG_VALUES || {};
6
7
  const dispatch = createEventDispatcher();
@@ -8,6 +9,7 @@
8
9
  export let id = generateId();
9
10
  export let label;
10
11
  export let name = undefined;
12
+ export let placeholder = i18n('placeholder');
11
13
  export let options = [];
12
14
  export let searchable = false;
13
15
  export let required = false;
@@ -32,14 +34,31 @@
32
34
 
33
35
  $: if (element && options) triggerChange();
34
36
 
37
+ function template(option) {
38
+ const content = document.querySelector(`[data-option="${id}_${option.id}"]`)?.innerHTML;
39
+ return content ? jQuery(content) : option.text;
40
+ }
41
+
35
42
  onMount(() => {
36
- [element] = setupComponent(id).on('change', (e) => {
37
- if (e.val !== undefined && value !== e.val) {
38
- value = e.val;
39
- dispatch('input', value);
40
- dispatch('change', value);
41
- }
42
- });
43
+ // Instansiate select2 ourselves to be able to use more options.
44
+ jQuery(element)
45
+ .select2({
46
+ placeholder,
47
+ width: '100%',
48
+ allowClear: true,
49
+ minimumResultsForSearch: searchable ? 0 : Infinity,
50
+ templateResult: template,
51
+ formatResult: template,
52
+ templateSelection: template,
53
+ formatSelection: template,
54
+ })
55
+ .on('change', (e) => {
56
+ if (e.val !== undefined && value !== e.val) {
57
+ value = e.val;
58
+ dispatch('input', value);
59
+ dispatch('change', value);
60
+ }
61
+ });
43
62
  });
44
63
  </script>
45
64
 
@@ -51,17 +70,23 @@
51
70
  -->
52
71
 
53
72
  <div class="form-group {className}" class:hidden={!show}>
73
+ {#if $$slots.option}
74
+ {#each options as option}
75
+ <span hidden data-option="{id}_{option.value ?? option}">
76
+ <slot name="option" {option} />
77
+ </span>
78
+ {/each}
79
+ {/if}
54
80
  <label for={id} class="control-label {required ? 'control-label--required' : ''}">{label}</label>
55
81
  <select
82
+ bind:this={element}
56
83
  {id}
57
84
  {required}
58
85
  {disabled}
59
86
  {multiple}
60
87
  name={!multiple ? name : undefined}
61
- data-component="custom-selector"
62
- data-removable
63
- data-searchable={searchable ? '' : undefined}
64
88
  >
89
+ <option />
65
90
  {#each options as option}
66
91
  <option value={option.value ?? option}>
67
92
  {option.label ?? option}
@@ -77,19 +102,3 @@
77
102
  </select>
78
103
  {/if}
79
104
  </div>
80
-
81
- <style>
82
- div :global(.select2-container-multi .select2-search-choice-close) {
83
- top: 3px;
84
- }
85
-
86
- div :global(.select2-container-multi ul.select2-choices) {
87
- border: 1px solid #ccc;
88
- box-shadow: inset 0 1px 1px rgb(0 0 0 / 8%);
89
- }
90
-
91
- div :global(.select2-container-multi .select2-choices .select2-search-choice) {
92
- padding: 4px 5px 4px 18px;
93
- margin-top: 4px;
94
- }
95
- </style>
@@ -11,6 +11,7 @@ Wrapper component for Sitevision [Custom selector](https://developer.sitevision.
11
11
  export let id = generateId();
12
12
  export let label; // Required
13
13
  export let name = undefined;
14
+ export let placeholder;
14
15
  export let options = [];
15
16
  export let searchable = false;
16
17
  export let required = false;
@@ -72,3 +73,24 @@ Default slot after selector.
72
73
  <p class="help-block">Some helpful text.</p>
73
74
  </CustomSelector>
74
75
  ```
76
+
77
+ Option slot for custom templating.
78
+ The option is available as slot prop.
79
+
80
+ ```svelte
81
+ <script>
82
+ import { Panel, CustomSelector } from '@soleil-se/svelte-config';
83
+
84
+ const options = [
85
+ { label: 'Värde 1', value: 'value1', type: 'Typ 1' },
86
+ { label: 'Värde 2', value: 'value2', type: 'Typ 2' },
87
+ { label: 'Värde 3', value: 'value3', type: 'Typ 3' },
88
+ ];
89
+ </script>
90
+
91
+ <Panel>
92
+ <CustomSelector name="custom" label="Custom selector" {options} >
93
+ <span slot="option" let:option>{option.label} ({option.type})</span>
94
+ </CustomSelector>
95
+ </Panel>
96
+ ```
@@ -0,0 +1,13 @@
1
+ import createI18n from '../../utils/createI18n';
2
+
3
+ export default createI18n({
4
+ sv: {
5
+ placeholder: 'Välj',
6
+ },
7
+ no: {
8
+ placeholder: 'Velj',
9
+ },
10
+ en: {
11
+ placeholder: 'Select',
12
+ },
13
+ });
@@ -42,9 +42,9 @@
42
42
  });
43
43
 
44
44
  /*
45
- * The sv:loaded event is only triggered on initial load, if the component rerenders check if any
46
- * children are present and set value of select element.
47
- */
45
+ * The sv:loaded event is only triggered on initial load, if the component rerenders check if any
46
+ * children are present and set value of select element.
47
+ */
48
48
  if (el?.childElementCount > 0) {
49
49
  setValue(el);
50
50
  }
@@ -71,34 +71,3 @@
71
71
  />
72
72
  <slot />
73
73
  </div>
74
-
75
- <style global>
76
- .select2-container .select2-choice {
77
- height: 34px;
78
- padding-left: 12px;
79
- line-height: 32px;
80
- border: 1px solid #ccc;
81
- box-shadow: inset 0 1px 1px rgb(0 0 0 / 7.5%);
82
- }
83
-
84
- .select2-container .select2-choice .select2-arrow b {
85
- background-position-y: 3px;
86
- }
87
-
88
- .select2-container .select2-choice abbr {
89
- top: 9px;
90
- }
91
-
92
- .select2-container.select2-container-disabled .select2-choice {
93
- cursor: not-allowed;
94
- background-color: white;
95
- background-image: none;
96
- border: 1px solid #ccc;
97
- opacity: 0.7;
98
- }
99
-
100
- .select2-container.select2-container-disabed .select2-choice .select2-arrow {
101
- background-color: white;
102
- border-left: 1px solid #aaa;
103
- }
104
- </style>
@@ -52,6 +52,7 @@ Possible values for `type`:
52
52
  - `image`
53
53
  - `user`
54
54
  - `userfield`
55
+ - `template`
55
56
 
56
57
  For `tags-selector` use [TagSelector](../TagSelector).
57
58
 
@@ -56,6 +56,7 @@
56
56
  a11yDialog.show();
57
57
  } else {
58
58
  a11yDialog.hide();
59
+ jQuery(element).find('.select2-offscreen')?.select2('close');
59
60
  }
60
61
  }
61
62
  };
@@ -23,14 +23,14 @@
23
23
  </div>
24
24
  </div>
25
25
 
26
- <style lang="scss">
27
- :global(html) {
26
+ <style lang="scss" global>
27
+ html {
28
28
  position: fixed;
29
29
  overflow: hidden;
30
30
  background-color: transparent;
31
31
  }
32
32
 
33
- :global(body) {
33
+ body {
34
34
  overflow: auto;
35
35
  background: none;
36
36
  }
@@ -47,4 +47,47 @@
47
47
  content: '*';
48
48
  }
49
49
  }
50
+
51
+ .select2-container-multi .select2-search-choice-close {
52
+ top: 3px;
53
+ }
54
+
55
+ .select2-container-multi ul.select2-choices {
56
+ border: 1px solid #ccc;
57
+ box-shadow: inset 0 1px 1px rgb(0 0 0 / 8%);
58
+ }
59
+
60
+ .select2-container-multi .select2-choices .select2-search-choice {
61
+ padding: 4px 5px 4px 18px;
62
+ margin-top: 4px;
63
+ }
64
+
65
+ .select2-container .select2-choice {
66
+ height: 34px;
67
+ padding-left: 12px;
68
+ line-height: 32px;
69
+ border: 1px solid #ccc;
70
+ box-shadow: inset 0 1px 1px rgb(0 0 0 / 7.5%);
71
+ }
72
+
73
+ .select2-container .select2-choice .select2-arrow b {
74
+ background-position-y: 3px;
75
+ }
76
+
77
+ .select2-container .select2-choice abbr {
78
+ top: 9px;
79
+ }
80
+
81
+ .select2-container.select2-container-disabled .select2-choice {
82
+ cursor: not-allowed;
83
+ background-color: white;
84
+ background-image: none;
85
+ border: 1px solid #ccc;
86
+ opacity: 0.7;
87
+ }
88
+
89
+ .select2-container.select2-container-disabed .select2-choice .select2-arrow {
90
+ background-color: white;
91
+ border-left: 1px solid #aaa;
92
+ }
50
93
  </style>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soleil-se/config-svelte",
3
- "version": "1.17.0",
3
+ "version": "1.18.0",
4
4
  "main": "./index.js",
5
5
  "module": "./index.js",
6
6
  "svelte": "./index.js",