@juspay/svelte-ui-components 1.6.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
  });
@@ -139,7 +162,7 @@ onDestroy(() => {
139
162
  {#if !properties.hideDropDownIcon}
140
163
  <img
141
164
  src={dropDownIcon}
142
- alt= {dropDownIconAlt}
165
+ alt={dropDownIconAlt}
143
166
  class="arrow {isSelectOpen ? 'active' : ''}"
144
167
  />
145
168
  {/if}
@@ -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 {
@@ -252,6 +281,10 @@ onDestroy(() => {
252
281
  word-wrap: var(--non-selected-word-break, break-word);
253
282
  white-space: var(--non-selected-white-space);
254
283
  font-weight: var(--non-select-font-weight, 500);
284
+ left: var(--non-selected-left);
285
+ right: var(--non-selected-right);
286
+ top: var(--non-selected-top);
287
+ bottom: var(--non-selected-bottom);
255
288
  }
256
289
 
257
290
  ::-webkit-scrollbar {
@@ -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,4 +1,5 @@
1
- import type { ImgProps } from "../Img/properties";
1
+ import type { ButtonProperties } from '../Button/properties';
2
+ import type { ImgProps } from '../Img/properties';
2
3
  export type SelectProperties = {
3
4
  placeholder: string;
4
5
  label: 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
  };
@@ -0,0 +1,164 @@
1
+ <script>import { createEventDispatcher, onDestroy, onMount } from "svelte";
2
+ import { fly } from "svelte/transition";
3
+ import { defaultToastProperties } from "./properties";
4
+ export let properties = defaultToastProperties;
5
+ const dispatch = createEventDispatcher();
6
+ const animationConfig = getAnimationConfig(
7
+ properties.direction,
8
+ properties.overlapPage ?? true
9
+ );
10
+ let showToast = false;
11
+ let timeoutId = null;
12
+ function hideToast() {
13
+ showToast = false;
14
+ }
15
+ function handleAnimationEnd() {
16
+ dispatch("onToastHide");
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
+ }
55
+ onMount(() => {
56
+ showToast = true;
57
+ timeoutId = setTimeout(hideToast, properties.duration);
58
+ });
59
+ onDestroy(() => {
60
+ if (timeoutId !== null) {
61
+ clearTimeout(timeoutId);
62
+ }
63
+ });
64
+ </script>
65
+
66
+ {#if showToast}
67
+ <div
68
+ class="toast {properties.type ?? ''}"
69
+ class:no-page-overlap={!(properties?.overlapPage ?? true)}
70
+ in:fly={animationConfig.in}
71
+ out:fly={animationConfig.out}
72
+ on:outroend={handleAnimationEnd}
73
+ >
74
+ {#if properties.leftIcon}
75
+ <div class="toast-icon-wrapper">
76
+ <img class="toast-icon" src={properties.leftIcon} alt="toast-icon" />
77
+ </div>
78
+ {/if}
79
+
80
+ <div class="toast-message">
81
+ {properties.message}
82
+ </div>
83
+
84
+ {#if properties.rightIcon}
85
+ <div class="close-button" tabindex="0" role="button" on:click={hideToast} on:keypress>
86
+ <img class="toast-icon" src={properties.rightIcon} alt="close-icon" />
87
+ </div>
88
+ {/if}
89
+ </div>
90
+ {/if}
91
+
92
+ <style>
93
+ .toast {
94
+ padding: var(--toast-padding, 10px);
95
+ font-size: var(--toast-font-size, 14px);
96
+ height: var(--toast-height, auto);
97
+ border-radius: var(--toast-border-radius, 0px);
98
+ width: var(--toast-width, auto);
99
+ align-items: var(--toast-align-items, center);
100
+ margin: var(--toast-margin, 0px 10px 10px 10px);
101
+ justify-content: var(--toast-justify-content, space-between);
102
+ z-index: var(--toast-z-index, 1000);
103
+ display: var(--taost-dispay, flex);
104
+ position: var(--toast-position, absolute);
105
+ top: var(--toast-top, 10px);
106
+ left: var(--toast-left, 0);
107
+ right: var(--toast-right, 0);
108
+ background-color: var(--default-background-color, #87ceeb);
109
+ }
110
+
111
+ .no-page-overlap {
112
+ position: var(--toast-position, relative);
113
+ }
114
+
115
+ .toast-icon-wrapper {
116
+ width: var(--toast-icon-wrapper-width, 20px);
117
+ height: var(--toast-icon-wrapper-height, 20px);
118
+ margin: var(--toast-icon-margin, 0 6px 0 0);
119
+ padding: var(--toast-icon-wrapper-padding, 1px);
120
+ }
121
+
122
+ .toast-icon {
123
+ height: var(--toast-icon-height, 100%);
124
+ border-radius: var(--toast-icon-border-radius, 50%);
125
+ }
126
+
127
+ .toast-message {
128
+ display: var(--toast-message-display, flex);
129
+ flex: var(--taost-message-flex, 1);
130
+ padding: var(--toast-message-padding, 1px);
131
+ }
132
+
133
+ .close-button {
134
+ width: var(--toast-close-button-width, 20px);
135
+ height: var(--toast-close-button-height, 20px);
136
+ cursor: var(--toast-close-button-cursor, pointer);
137
+ gap: var(--toast-close-button-gap, 6px);
138
+ margin: var(--toast-close-button-margin, 0 0 0 10px);
139
+ display: var(--toast-close-button-display, flex);
140
+ align-items: var(--toast-close-button-align-items, center);
141
+ justify-content: var(--toast-close-button-justify-content, center);
142
+ padding: var(--toast-close-button-padding, 1px);
143
+ }
144
+
145
+ .success {
146
+ color: var(--toast-success-text, #fff);
147
+ background-color: var(--toast-background-color, #24aa5a);
148
+ }
149
+
150
+ .info {
151
+ color: var(--toast-info-text, #fff);
152
+ background-color: var(--toast-background-color, #87ceeb);
153
+ }
154
+
155
+ .warn {
156
+ color: var(--toast-warn-text, #fff);
157
+ background-color: var(--toast-background-color, #f3a42d);
158
+ }
159
+
160
+ .error {
161
+ color: var(--toast-error-text, #fff);
162
+ background-color: var(--toast-background-color, #f04438);
163
+ }
164
+ </style>
@@ -0,0 +1,20 @@
1
+ import { SvelteComponent } from "svelte";
2
+ import { type ToastProperties } from './properties';
3
+ declare const __propDef: {
4
+ props: {
5
+ properties?: ToastProperties | undefined;
6
+ };
7
+ events: {
8
+ keypress: KeyboardEvent;
9
+ onToastHide: CustomEvent<any>;
10
+ } & {
11
+ [evt: string]: CustomEvent<any>;
12
+ };
13
+ slots: {};
14
+ };
15
+ export type ToastProps = typeof __propDef.props;
16
+ export type ToastEvents = typeof __propDef.events;
17
+ export type ToastSlots = typeof __propDef.slots;
18
+ export default class Toast extends SvelteComponent<ToastProps, ToastEvents, ToastSlots> {
19
+ }
20
+ export {};
@@ -0,0 +1,16 @@
1
+ export type ToastType = 'success' | 'error' | 'info' | 'warn';
2
+ export type ToastDirection = 'left-to-right' | 'right-to-left' | 'top-to-bottom' | 'bottom-to-top';
3
+ export type ToastProperties = {
4
+ duration: number;
5
+ leftIcon?: string;
6
+ message: string;
7
+ rightIcon?: string;
8
+ type?: ToastType;
9
+ direction?: ToastDirection;
10
+ overlapPage?: boolean;
11
+ inAnimationOffset?: number;
12
+ inAnimationDuration?: number;
13
+ outAnimationOffset?: number;
14
+ outAnimationDuration?: number;
15
+ };
16
+ export declare const defaultToastProperties: ToastProperties;
@@ -0,0 +1,4 @@
1
+ export const defaultToastProperties = {
2
+ duration: 2000,
3
+ message: ''
4
+ };
@@ -45,7 +45,7 @@ function handleBackClick() {
45
45
  padding: var(--toolbar-padding, 0px);
46
46
  height: fit-content;
47
47
  width: 100vw;
48
- position: fixed;
48
+ position: var(--toolbar-position, fixed);
49
49
  top: 0;
50
50
  left: 0;
51
51
  right: 0;
package/dist/index.d.ts CHANGED
@@ -20,6 +20,7 @@ export { default as CheckListItem } from './CheckListItem/CheckListItem.svelte';
20
20
  export { default as Table } from './Table/Table.svelte';
21
21
  export { default as Stepper } from './Stepper/Stepper.svelte';
22
22
  export { default as Step } from './Stepper/Step.svelte';
23
+ export { default as Toast } from './Toast/Toast.svelte';
23
24
  export type { ButtonProperties } from './Button/properties';
24
25
  export type { ModalProperties, ModalAlign, ModalSize } from './Modal/properties';
25
26
  export type { InputProperties } from './Input/properties';
@@ -29,6 +30,7 @@ export type { InputDataType } from './types';
29
30
  export type { AutoCompleteType } from './types';
30
31
  export type { CustomValidator } from './types';
31
32
  export type { ValidationState } from './types';
33
+ export type { FlyAnimationConfig } from './types';
32
34
  export type { IconProperties } from './Icon/properties';
33
35
  export type { BrandLoaderProperties } from './BrandLoader/properties';
34
36
  export type { StatusProperties } from './Status/properties';
@@ -39,6 +41,7 @@ export type { BadgeProperties } from './Badge/properties';
39
41
  export type { BannerProperties } from './Banner/properties';
40
42
  export type { TableProperties } from './Table/properties';
41
43
  export type { StepperProperties } from './Stepper/properties';
44
+ export type { ToastProperties } from './Toast/properties';
42
45
  export { defaultIconProperties } from './Icon/properties';
43
46
  export { defaultButtonProperties } from './Button/properties';
44
47
  export { defaultModalProperties } from './Modal/properties';
@@ -49,4 +52,5 @@ export { defaultStatusProperties } from './Status/properties';
49
52
  export { defaultListItemProperties } from './ListItem/properties';
50
53
  export { defaultToolbarProperties } from './Toolbar/properties';
51
54
  export { defaultCarouselProperties } from './Carousel/properties';
55
+ export { defaultToastProperties } from './Toast/properties';
52
56
  export { validateInput } from './utils';
package/dist/index.js CHANGED
@@ -20,6 +20,7 @@ export { default as CheckListItem } from './CheckListItem/CheckListItem.svelte';
20
20
  export { default as Table } from './Table/Table.svelte';
21
21
  export { default as Stepper } from './Stepper/Stepper.svelte';
22
22
  export { default as Step } from './Stepper/Step.svelte';
23
+ export { default as Toast } from './Toast/Toast.svelte';
23
24
  export { defaultIconProperties } from './Icon/properties';
24
25
  export { defaultButtonProperties } from './Button/properties';
25
26
  export { defaultModalProperties } from './Modal/properties';
@@ -30,4 +31,5 @@ export { defaultStatusProperties } from './Status/properties';
30
31
  export { defaultListItemProperties } from './ListItem/properties';
31
32
  export { defaultToolbarProperties } from './Toolbar/properties';
32
33
  export { defaultCarouselProperties } from './Carousel/properties';
34
+ export { defaultToastProperties } from './Toast/properties';
33
35
  export { validateInput } from './utils';
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.6.0",
3
+ "version": "1.8.0",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run package",