iconograph-ui 1.2.11 → 1.2.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.
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
import { createEventDispatcher } from 'svelte';
|
|
4
|
+
import {clickOutside} from './../utils/clickOutside.js';
|
|
5
|
+
import UserPicture from './UserPicture.svelte';
|
|
6
|
+
|
|
7
|
+
const dispatch = createEventDispatcher();
|
|
8
|
+
|
|
9
|
+
function handleUserSelection(uid) {
|
|
10
|
+
isOpen = false;
|
|
11
|
+
inputFilter = null;
|
|
12
|
+
filteredUsers = users;
|
|
13
|
+
|
|
14
|
+
dispatch('selectUser', {
|
|
15
|
+
id: uid
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function handleFilter() {
|
|
20
|
+
filteredUsers = users.filter((user) => {
|
|
21
|
+
let str = (user.firstname + ' ' + user.lastname).normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase();
|
|
22
|
+
const inputStr = inputFilter.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase();
|
|
23
|
+
return (typeFilter == null || user.type.value == typeFilter) && str.includes(inputStr);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export let users = []
|
|
28
|
+
export let typeFilter = null;
|
|
29
|
+
|
|
30
|
+
let inputFilter;
|
|
31
|
+
let filteredUsers = users.filter((user) => {
|
|
32
|
+
return (typeFilter == null || user.type.value == typeFilter);
|
|
33
|
+
});
|
|
34
|
+
let isOpen = false;
|
|
35
|
+
</script>
|
|
36
|
+
|
|
37
|
+
<div id="user-select-wrapper" use:clickOutside on:click_outside={() => {isOpen = false}}>
|
|
38
|
+
<div>
|
|
39
|
+
<input type="text" bind:value={inputFilter} on:keyup={handleFilter} on:focus={() => (isOpen = !isOpen)} placeholder="Ajouter un utilisateur"/>
|
|
40
|
+
</div>
|
|
41
|
+
{#if isOpen}
|
|
42
|
+
<div>
|
|
43
|
+
{#each filteredUsers as user}
|
|
44
|
+
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
|
45
|
+
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
|
46
|
+
<div on:click|stopPropagation|preventDefault={handleUserSelection(user.id)}>
|
|
47
|
+
<UserPicture user={user} size={24}></UserPicture>
|
|
48
|
+
<span>{user.firstname} {user.lastname}</span>
|
|
49
|
+
</div>
|
|
50
|
+
{/each}
|
|
51
|
+
</div>
|
|
52
|
+
{/if}
|
|
53
|
+
</div>
|
|
54
|
+
|
|
55
|
+
<style>
|
|
56
|
+
input {
|
|
57
|
+
border: none
|
|
58
|
+
}
|
|
59
|
+
#user-select-wrapper {
|
|
60
|
+
background-color: #f5f5fb;
|
|
61
|
+
border-radius: 6px;
|
|
62
|
+
padding: 2px 0px;
|
|
63
|
+
transition: 0.3s ease-in-out all;
|
|
64
|
+
width: 220px;
|
|
65
|
+
position: relative;
|
|
66
|
+
z-index: 100;
|
|
67
|
+
}
|
|
68
|
+
#user-select-wrapper > div:nth-of-type(1) {
|
|
69
|
+
background-image: url('/icons/icon-user-add.svg');
|
|
70
|
+
background-size: 20px auto;
|
|
71
|
+
background-repeat: no-repeat;
|
|
72
|
+
background-position: left center;
|
|
73
|
+
margin-right: 6px;
|
|
74
|
+
margin-left: 12px;
|
|
75
|
+
padding-left: 24px;
|
|
76
|
+
}
|
|
77
|
+
#user-select-wrapper > div:nth-of-type(1) > input{
|
|
78
|
+
background-color: #f5f5fb;
|
|
79
|
+
border-radius: 0px;
|
|
80
|
+
padding: 4px 6px;
|
|
81
|
+
height: 20px;
|
|
82
|
+
font-size: 14px;
|
|
83
|
+
font-weight: 500;
|
|
84
|
+
color: #333;
|
|
85
|
+
cursor: pointer;
|
|
86
|
+
width: calc(100% - 12px);
|
|
87
|
+
}
|
|
88
|
+
#user-select-wrapper > div:nth-of-type(1) > input:focus{
|
|
89
|
+
cursor: initial;
|
|
90
|
+
}
|
|
91
|
+
#user-select-wrapper > div:nth-of-type(1) > input::placeholder {
|
|
92
|
+
color: #777;
|
|
93
|
+
}
|
|
94
|
+
#user-select-wrapper > div:nth-of-type(2) {
|
|
95
|
+
display: flex;
|
|
96
|
+
flex-direction: column;
|
|
97
|
+
padding-bottom: 8px;
|
|
98
|
+
background-color: #f5f5fb;
|
|
99
|
+
width: 220px;
|
|
100
|
+
z-index: 1000;
|
|
101
|
+
}
|
|
102
|
+
#user-select-wrapper > div:nth-of-type(2) > div {
|
|
103
|
+
padding: 4px 12px;
|
|
104
|
+
flex: 1;
|
|
105
|
+
display: flex;
|
|
106
|
+
align-items: center;
|
|
107
|
+
}
|
|
108
|
+
#user-select-wrapper > div:nth-of-type(2) > div > span {
|
|
109
|
+
color: #333;
|
|
110
|
+
font-weight: 600;
|
|
111
|
+
cursor: pointer;
|
|
112
|
+
margin-left: 8px;
|
|
113
|
+
}
|
|
114
|
+
#user-select-wrapper > div:nth-of-type(2) > div:hover {
|
|
115
|
+
background-color: #eee;
|
|
116
|
+
}
|
|
117
|
+
</style>
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
import { createEventDispatcher } from 'svelte';
|
|
4
|
+
import UserSelect from "./UserSelect.svelte";
|
|
5
|
+
import UserPicture from './UserPicture.svelte';
|
|
6
|
+
|
|
7
|
+
const dispatch = createEventDispatcher();
|
|
8
|
+
|
|
9
|
+
export let users = [];
|
|
10
|
+
export let typeFilter = null;
|
|
11
|
+
export let selected = false;
|
|
12
|
+
export let selectedUser = null;
|
|
13
|
+
|
|
14
|
+
function handleUserSelection(e) {
|
|
15
|
+
selectedUser = users.filter((user) => {
|
|
16
|
+
return user.id == e.detail.id;
|
|
17
|
+
}).at(-1);
|
|
18
|
+
selected = true;
|
|
19
|
+
|
|
20
|
+
dispatch('selectUser', {
|
|
21
|
+
id: e.detail.id
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function handleRemove() {
|
|
26
|
+
selected = false;
|
|
27
|
+
selectedUser = null;
|
|
28
|
+
|
|
29
|
+
dispatch('selectUser', {
|
|
30
|
+
id: null
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
</script>
|
|
34
|
+
|
|
35
|
+
<div id="single-select-wrapper">
|
|
36
|
+
{#if !selected}
|
|
37
|
+
<UserSelect on:selectUser={handleUserSelection} users={users} typeFilter={typeFilter}></UserSelect>
|
|
38
|
+
{:else}
|
|
39
|
+
<div>
|
|
40
|
+
<UserPicture size={24} user={selectedUser}></UserPicture>
|
|
41
|
+
<span>{selectedUser.firstname} {selectedUser.lastname}</span>
|
|
42
|
+
<div on:click={handleRemove}>+</div>
|
|
43
|
+
</div>
|
|
44
|
+
{/if}
|
|
45
|
+
</div>
|
|
46
|
+
|
|
47
|
+
<style>
|
|
48
|
+
#single-select-wrapper {
|
|
49
|
+
display: flex;
|
|
50
|
+
position: relative;
|
|
51
|
+
z-index: 1000;
|
|
52
|
+
}
|
|
53
|
+
#single-select-wrapper > div {
|
|
54
|
+
background-color: #f5f5fb;
|
|
55
|
+
border-radius: 6px;
|
|
56
|
+
width: inherit;
|
|
57
|
+
transition: 0.3s ease-in-out all;
|
|
58
|
+
display: flex;
|
|
59
|
+
height: 34px;
|
|
60
|
+
align-items: center;
|
|
61
|
+
padding-left: 12px;
|
|
62
|
+
}
|
|
63
|
+
#single-select-wrapper > div > span {
|
|
64
|
+
color: #333;
|
|
65
|
+
font-weight: 600;
|
|
66
|
+
max-width: 125px;
|
|
67
|
+
flex: 1;
|
|
68
|
+
margin-left: 8px;
|
|
69
|
+
margin-right: 8px;
|
|
70
|
+
overflow: hidden;
|
|
71
|
+
white-space: nowrap;
|
|
72
|
+
text-overflow: ellipsis;
|
|
73
|
+
}
|
|
74
|
+
#single-select-wrapper > div > div:nth-of-type(2) {
|
|
75
|
+
cursor: pointer;
|
|
76
|
+
margin-right: 12px;
|
|
77
|
+
margin-left: 8px;
|
|
78
|
+
height: 16px;
|
|
79
|
+
width: 16px;
|
|
80
|
+
min-width: 16px;
|
|
81
|
+
background-color: #ddd;
|
|
82
|
+
border-radius: 20px;
|
|
83
|
+
font-weight: 600;
|
|
84
|
+
text-align: center;
|
|
85
|
+
line-height: 16px;
|
|
86
|
+
color: #777;
|
|
87
|
+
transform: rotate(45deg);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
</style>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
|
|
3
|
+
export function clickOutside(node) {
|
|
4
|
+
const handleClick = event => {
|
|
5
|
+
if (node && !node.contains(event.target) && !event.defaultPrevented) {
|
|
6
|
+
node.dispatchEvent(
|
|
7
|
+
new CustomEvent('click_outside', node)
|
|
8
|
+
)
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
document.addEventListener('click', handleClick, true);
|
|
13
|
+
|
|
14
|
+
return {
|
|
15
|
+
destroy() {
|
|
16
|
+
document.removeEventListener('click', handleClick, true);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|