@juspay/svelte-ui-components 1.7.0 → 1.8.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.
@@ -192,6 +192,7 @@ $: {
192
192
  .input-container {
193
193
  display: flex;
194
194
  flex-direction: column;
195
+ margin: var(--input-container-margin);
195
196
  }
196
197
 
197
198
  .label {
@@ -21,6 +21,11 @@ function leftButtonClick(event) {
21
21
  event.preventDefault();
22
22
  dispatch("leftButtonClick");
23
23
  }
24
+ function bottomButtonClick() {
25
+ if (state === "Valid") {
26
+ dispatch("bottomButtonClick", { value: properties.inputProperties.value });
27
+ }
28
+ }
24
29
  function triggerRightClickIfValid(event) {
25
30
  if (event?.key === "Enter") {
26
31
  rightButtonClick();
@@ -65,6 +70,11 @@ function handleState(event) {
65
70
  </div>
66
71
  {/if}
67
72
  </div>
73
+ {#if properties.bottomButtonProperties != null}
74
+ <div class="bottom-button">
75
+ <Button properties={properties.bottomButtonProperties} on:click={bottomButtonClick} />
76
+ </div>
77
+ {/if}
68
78
  </div>
69
79
  {#if properties.inputProperties.message.onError !== '' && state === 'Invalid'}
70
80
  <div class="error-message">
@@ -110,6 +120,20 @@ function handleState(event) {
110
120
  --button-height: 54px;
111
121
  }
112
122
 
123
+ .bottom-button {
124
+ padding: var(--input-bottom-btn-padding, 10px 0px);
125
+ --cursor: var(--bottom-button-cursor);
126
+ --button-color: var(--bottom-button-color);
127
+ --button-text-color: var(--bottom-button-text-color);
128
+ --button-font-family: var(--bottom-button-font-family);
129
+ --button-font-weight: var(--bottom-button-font-weight);
130
+ --button-font-size: var(--bottom-button-font-size);
131
+ --button-height: var(--bottom-button-height, 54px);
132
+ --button-padding: var(--bottom-button-padding);
133
+ --button-border-radius: var(--bottom-button-border-radius);
134
+ --button-width: var(--bottom-button-width);
135
+ }
136
+
113
137
  .label {
114
138
  font-weight: var(--input-label-msg-text-weight, 400);
115
139
  font-size: var(--input-label-msg-text-size, 12px);
@@ -9,6 +9,7 @@ declare const __propDef: {
9
9
  input: CustomEvent<any>;
10
10
  rightButtonClick: CustomEvent<any>;
11
11
  leftButtonClick: CustomEvent<any>;
12
+ bottomButtonClick: CustomEvent<any>;
12
13
  stateChange: CustomEvent<any>;
13
14
  } & {
14
15
  [evt: string]: CustomEvent<any>;
@@ -4,5 +4,6 @@ export type InputButtonProperties = {
4
4
  inputProperties: InputProperties;
5
5
  rightButtonProperties: ButtonProperties | null;
6
6
  leftButtonProperties: ButtonProperties | null;
7
+ bottomButtonProperties: ButtonProperties | null;
7
8
  };
8
9
  export declare const defaultInputButtonProperties: InputButtonProperties;
@@ -13,5 +13,6 @@ const rightButtonProperties = {
13
13
  export const defaultInputButtonProperties = {
14
14
  inputProperties,
15
15
  rightButtonProperties,
16
- leftButtonProperties: null
16
+ leftButtonProperties: null,
17
+ bottomButtonProperties: null
17
18
  };
@@ -1,6 +1,7 @@
1
1
  <script>import { createEventDispatcher, onDestroy, onMount } from "svelte";
2
2
  import Img from "../Img/Img.svelte";
3
3
  import Button from "../Button/Button.svelte";
4
+ import { InputButton, defaultInputButtonProperties } from "..";
4
5
  let selectedElementDiv = null;
5
6
  export let dropDownIconAlt = "";
6
7
  export let properties = {
@@ -36,14 +37,22 @@ const clearAllButtonProps = {
36
37
  type: "submit"
37
38
  };
38
39
  let isSelectOpen = false;
40
+ let isInput = false;
39
41
  const dispatch = createEventDispatcher();
40
42
  $:
41
43
  nonSelectedItems = properties.allItems.filter(
42
44
  (item) => properties.selectMultipleItems ? !properties.selectedItem.includes(item) : item !== properties.selectedItem
43
45
  );
46
+ function isSelected(selectedItem, item) {
47
+ if (Array.isArray(selectedItem)) {
48
+ return selectedItem.includes(item);
49
+ } else {
50
+ return selectedItem.trim() === item.trim();
51
+ }
52
+ }
44
53
  function selectItem(item) {
45
54
  if (properties.selectMultipleItems && Array.isArray(properties.selectedItemLabel) && Array.isArray(properties.selectedItem)) {
46
- if (properties.selectedItem.includes(item)) {
55
+ if (isSelected(properties.selectedItem, item)) {
47
56
  properties.selectedItem = properties.selectedItem.filter(
48
57
  (selectedItem) => selectedItem !== item
49
58
  );
@@ -56,6 +65,7 @@ function selectItem(item) {
56
65
  }
57
66
  } else {
58
67
  properties.selectedItem = [item];
68
+ properties.selectedItemLabel = [item];
59
69
  }
60
70
  if (!properties.selectMultipleItems) {
61
71
  toggleSelect();
@@ -84,11 +94,24 @@ function closeSelect(event) {
84
94
  const isApplyButtonClicked = clickedElement.classList.contains("apply-btn");
85
95
  const isClearAllButtonClicked = clickedElement.innerText === "Clear All";
86
96
  const isSelectAllButtonClicked = clickedElement.innerText === "Select All";
87
- if (!isItemClicked && !isApplyButtonClicked && !isClearAllButtonClicked && !isSelectAllButtonClicked) {
97
+ const isInputSelected = properties.addInputButton && isInput;
98
+ if (!isItemClicked && !isApplyButtonClicked && !isClearAllButtonClicked && !isSelectAllButtonClicked && isInputSelected) {
88
99
  isSelectOpen = false;
89
100
  }
90
101
  }
91
102
  }
103
+ function handleSelectInput(event) {
104
+ if (event && event.detail) {
105
+ properties.selectedItem = event.detail.value;
106
+ properties.selectedItemLabel = event.detail.value;
107
+ }
108
+ dispatch("selectInput", event.detail.value);
109
+ isInput = false;
110
+ isSelectOpen = false;
111
+ }
112
+ function toggleIsInput() {
113
+ isInput = true;
114
+ }
92
115
  onMount(() => {
93
116
  document.addEventListener("click", closeSelect);
94
117
  });
@@ -162,7 +185,7 @@ onDestroy(() => {
162
185
  on:click={() => {
163
186
  selectItem(item);
164
187
  }}
165
- class="item {properties.selectedItem.includes(item) ? 'selected item-selected' : ''}"
188
+ class="item {isSelected(properties.selectedItem, item) ? 'selected item-selected' : ''}"
166
189
  role="button"
167
190
  tabindex="0"
168
191
  >
@@ -170,6 +193,11 @@ onDestroy(() => {
170
193
  </div>
171
194
  {/each}
172
195
  </div>
196
+ {#if properties.addInputButton && properties.addInputButtonProps}
197
+ <div class="input-button">
198
+ <InputButton properties = {{...defaultInputButtonProperties, rightButtonProperties: null, bottomButtonProperties: properties.addInputButtonProps}} on:input={toggleIsInput} on:bottomButtonClick={handleSelectInput}/>
199
+ </div>
200
+ {/if}
173
201
  </div>
174
202
  </div>
175
203
  {/if}
@@ -196,6 +224,7 @@ onDestroy(() => {
196
224
  color: var(--select-color);
197
225
  --button-margin: 1px;
198
226
  --button-border-radius: 2px;
227
+ --input-button-margin: 10px;
199
228
  }
200
229
 
201
230
  .select:hover {
@@ -9,6 +9,7 @@ declare const __propDef: {
9
9
  keydown: KeyboardEvent;
10
10
  message: CustomEvent<any>;
11
11
  dropdownClick: CustomEvent<any>;
12
+ selectInput: CustomEvent<any>;
12
13
  } & {
13
14
  [evt: string]: CustomEvent<any>;
14
15
  };
@@ -1,3 +1,4 @@
1
+ import type { ButtonProperties } from '../Button/properties';
1
2
  import type { ImgProps } from '../Img/properties';
2
3
  export type SelectProperties = {
3
4
  placeholder: string;
@@ -10,4 +11,6 @@ export type SelectProperties = {
10
11
  hideDropDownIcon?: boolean;
11
12
  dropDownIcon?: string;
12
13
  leftIcon: ImgProps | null;
14
+ addInputButton?: boolean;
15
+ addInputButtonProps?: ButtonProperties;
13
16
  };
@@ -3,6 +3,10 @@ import { fly } from "svelte/transition";
3
3
  import { defaultToastProperties } from "./properties";
4
4
  export let properties = defaultToastProperties;
5
5
  const dispatch = createEventDispatcher();
6
+ const animationConfig = getAnimationConfig(
7
+ properties.direction,
8
+ properties.overlapPage ?? true
9
+ );
6
10
  let showToast = false;
7
11
  let timeoutId = null;
8
12
  function hideToast() {
@@ -11,6 +15,43 @@ function hideToast() {
11
15
  function handleAnimationEnd() {
12
16
  dispatch("onToastHide");
13
17
  }
18
+ function getAnimationConfig(toastDirection = null, overlapPage) {
19
+ let inX = 0;
20
+ let inY = 0;
21
+ let outX = 0;
22
+ let outY = 0;
23
+ switch (toastDirection) {
24
+ case "left-to-right":
25
+ inX = -1 * (properties.inAnimationOffset ?? 500);
26
+ outX = -1 * (properties.outAnimationOffset ?? 500);
27
+ break;
28
+ case "right-to-left":
29
+ inX = properties.inAnimationOffset ?? 500;
30
+ outX = properties.outAnimationOffset ?? 500;
31
+ break;
32
+ case "bottom-to-top":
33
+ inY = properties.inAnimationOffset ?? (overlapPage ? 500 : 20);
34
+ outY = properties.outAnimationOffset ?? (overlapPage ? 500 : 20);
35
+ break;
36
+ case "top-to-bottom":
37
+ default:
38
+ inY = -1 * (properties.inAnimationOffset ?? (overlapPage ? 500 : 20));
39
+ outY = -1 * (properties.outAnimationOffset ?? (overlapPage ? 100 : 20));
40
+ break;
41
+ }
42
+ return {
43
+ in: {
44
+ x: inX,
45
+ y: inY,
46
+ duration: properties.inAnimationDuration ?? 400
47
+ },
48
+ out: {
49
+ x: outX,
50
+ y: outY,
51
+ duration: properties.outAnimationDuration ?? 800
52
+ }
53
+ };
54
+ }
14
55
  onMount(() => {
15
56
  showToast = true;
16
57
  timeoutId = setTimeout(hideToast, properties.duration);
@@ -25,8 +66,9 @@ onDestroy(() => {
25
66
  {#if showToast}
26
67
  <div
27
68
  class="toast {properties.type ?? ''}"
28
- in:fly={{ x: 500, y: 0, duration: 400 }}
29
- out:fly={{ x: 500, y: 0, duration: 800 }}
69
+ class:no-page-overlap={!(properties?.overlapPage ?? true)}
70
+ in:fly={animationConfig.in}
71
+ out:fly={animationConfig.out}
30
72
  on:outroend={handleAnimationEnd}
31
73
  >
32
74
  {#if properties.leftIcon}
@@ -60,10 +102,16 @@ onDestroy(() => {
60
102
  z-index: var(--toast-z-index, 1000);
61
103
  display: var(--taost-dispay, flex);
62
104
  position: var(--toast-position, absolute);
105
+ top: var(--toast-top, 10px);
63
106
  left: var(--toast-left, 0);
64
107
  right: var(--toast-right, 0);
65
108
  background-color: var(--default-background-color, #87ceeb);
66
109
  }
110
+
111
+ .no-page-overlap {
112
+ position: var(--toast-position, relative);
113
+ }
114
+
67
115
  .toast-icon-wrapper {
68
116
  width: var(--toast-icon-wrapper-width, 20px);
69
117
  height: var(--toast-icon-wrapper-height, 20px);
@@ -1,9 +1,16 @@
1
1
  export type ToastType = 'success' | 'error' | 'info' | 'warn';
2
+ export type ToastDirection = 'left-to-right' | 'right-to-left' | 'top-to-bottom' | 'bottom-to-top';
2
3
  export type ToastProperties = {
3
4
  duration: number;
4
5
  leftIcon?: string;
5
6
  message: string;
6
7
  rightIcon?: string;
7
8
  type?: ToastType;
9
+ direction?: ToastDirection;
10
+ overlapPage?: boolean;
11
+ inAnimationOffset?: number;
12
+ inAnimationDuration?: number;
13
+ outAnimationOffset?: number;
14
+ outAnimationDuration?: number;
8
15
  };
9
16
  export declare const defaultToastProperties: ToastProperties;
package/dist/index.d.ts CHANGED
@@ -30,6 +30,7 @@ export type { InputDataType } from './types';
30
30
  export type { AutoCompleteType } from './types';
31
31
  export type { CustomValidator } from './types';
32
32
  export type { ValidationState } from './types';
33
+ export type { FlyAnimationConfig } from './types';
33
34
  export type { IconProperties } from './Icon/properties';
34
35
  export type { BrandLoaderProperties } from './BrandLoader/properties';
35
36
  export type { StatusProperties } from './Status/properties';
package/dist/types.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { FlyParams } from 'svelte/transition';
1
2
  /**
2
3
  * @name InputDataType
3
4
  * @description Different types of input data which can be passed to the Input Component
@@ -18,3 +19,10 @@ export type TextTransformer = (text: string) => string;
18
19
  * @description Type Map for All possible output of an Input Filed Validation
19
20
  */
20
21
  export type ValidationState = 'Valid' | 'InProgress' | 'Invalid';
22
+ /**
23
+ * @description Type for animation configuration
24
+ */
25
+ export type FlyAnimationConfig = {
26
+ in: FlyParams;
27
+ out: FlyParams;
28
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juspay/svelte-ui-components",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run package",