@marianmeres/stuic 1.55.0 → 1.57.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.
@@ -9,8 +9,19 @@ import {
9
9
  validate as validateAction,
10
10
  Thc
11
11
  } from "../../index.js";
12
+ const _emptyClasses = () => ({
13
+ box: "",
14
+ wrap: "",
15
+ label: "",
16
+ input: "",
17
+ invalid: "",
18
+ validationMessage: "",
19
+ description: "",
20
+ below: "",
21
+ asterix: ""
22
+ });
12
23
  const _PRESET = {
13
- box: "mb-4",
24
+ box: "mb-4 grid",
14
25
  wrap: `
15
26
  rounded-md border border-gray-300
16
27
  bg-gray-100
@@ -48,8 +59,12 @@ const _PRESET_BY_SIZE = {
48
59
  }
49
60
  };
50
61
  export class FieldConfig {
51
- static class = {};
52
- static classBySize = {};
62
+ static class = _emptyClasses();
63
+ static classBySize = {
64
+ sm: _emptyClasses(),
65
+ md: _emptyClasses(),
66
+ lg: _emptyClasses()
67
+ };
53
68
  }
54
69
  </script>
55
70
 
@@ -81,6 +96,8 @@ export let pattern = void 0;
81
96
  export let step = void 0;
82
97
  export let useTrim = true;
83
98
  export let textareaAutoEnlarge = true;
99
+ export let labelLeft = false;
100
+ export let labelLeftWidth = "normal";
84
101
  export let validate = void 0;
85
102
  export let showAsterixOnRequired = true;
86
103
  let validation;
@@ -127,8 +144,17 @@ $:
127
144
  _belowClass = twMerge(_collectClasses("below"));
128
145
  </script>
129
146
 
130
- <div class={_boxClass}>
131
- <div class="flex items-end px-2 mb-1">
147
+ <div
148
+ class={_boxClass}
149
+ class:grid-cols-4={labelLeft && labelLeftWidth === 'normal'}
150
+ class:grid-cols-3={labelLeft && labelLeftWidth === 'wide'}
151
+ >
152
+ <div
153
+ class="flex px-2 mb-1"
154
+ class:items-end={!labelLeft}
155
+ class:items-start={labelLeft}
156
+ class:mt-1={labelLeft}
157
+ >
132
158
  {#if label || $$slots.label}
133
159
  <label for={id} class={_labelClass} class:required>
134
160
  {#if $$slots.label}
@@ -140,73 +166,82 @@ $:
140
166
  {/if}
141
167
  <slot name="right_of_label" />
142
168
  </div>
143
- <div class={_wrapClass} class:cursor-not-allowed={disabled} class:opacity-50={disabled}>
144
- <div class="flex items-center">
145
- <slot name="input_before" {id} />
146
- {#if type === 'textarea'}
147
- <textarea
148
- bind:value
149
- bind:this={_inputEl}
150
- {id}
151
- class={_inputClass}
152
- class:cursor-not-allowed={disabled}
153
- {name}
154
- {disabled}
155
- {readonly}
156
- {required}
157
- {autofocus}
158
- {tabindex}
159
- use:trim={useTrim}
160
- use:validateAction={validate
161
- ? { ...(validate === true ? {} : validate), setValidationResult }
162
- : undefined}
163
- use:autogrow={{ allowed: textareaAutoEnlarge }}
164
- {...$$restProps}
165
- />
166
- {:else}
167
- <input
168
- bind:value
169
- bind:this={_inputEl}
170
- use:setType={type}
171
- {id}
172
- class={_inputClass}
173
- class:cursor-not-allowed={disabled}
174
- {name}
175
- {placeholder}
176
- {disabled}
177
- {readonly}
178
- {required}
179
- {autofocus}
180
- {autocomplete}
181
- {tabindex}
182
- {minlength}
183
- {maxlength}
184
- {min}
185
- {max}
186
- {pattern}
187
- {step}
188
- use:trim={useTrim}
189
- use:validateAction={validate
190
- ? { ...(validate === true ? {} : validate), setValidationResult }
191
- : undefined}
192
- {...$$restProps}
193
- />
194
- {/if}
195
- <slot name="input_after" {id} />
169
+ <div
170
+ class:col-span-3={labelLeft && labelLeftWidth === 'normal'}
171
+ class:col-span-2={labelLeft && labelLeftWidth === 'wide'}
172
+ >
173
+ <div
174
+ class={_wrapClass}
175
+ class:cursor-not-allowed={disabled}
176
+ class:opacity-50={disabled}
177
+ >
178
+ <div class="flex items-center">
179
+ <slot name="input_before" {id} />
180
+ {#if type === 'textarea'}
181
+ <textarea
182
+ bind:value
183
+ bind:this={_inputEl}
184
+ {id}
185
+ class={_inputClass}
186
+ class:cursor-not-allowed={disabled}
187
+ {name}
188
+ {disabled}
189
+ {readonly}
190
+ {required}
191
+ {autofocus}
192
+ {tabindex}
193
+ use:trim={useTrim}
194
+ use:validateAction={validate
195
+ ? { ...(validate === true ? {} : validate), setValidationResult }
196
+ : undefined}
197
+ use:autogrow={{ allowed: textareaAutoEnlarge }}
198
+ {...$$restProps}
199
+ />
200
+ {:else}
201
+ <input
202
+ bind:value
203
+ bind:this={_inputEl}
204
+ use:setType={type}
205
+ {id}
206
+ class={_inputClass}
207
+ class:cursor-not-allowed={disabled}
208
+ {name}
209
+ {placeholder}
210
+ {disabled}
211
+ {readonly}
212
+ {required}
213
+ {autofocus}
214
+ {autocomplete}
215
+ {tabindex}
216
+ {minlength}
217
+ {maxlength}
218
+ {min}
219
+ {max}
220
+ {pattern}
221
+ {step}
222
+ use:trim={useTrim}
223
+ use:validateAction={validate
224
+ ? { ...(validate === true ? {} : validate), setValidationResult }
225
+ : undefined}
226
+ {...$$restProps}
227
+ />
228
+ {/if}
229
+ <slot name="input_after" {id} />
230
+ </div>
231
+ <slot name="input_below" {id} />
196
232
  </div>
197
- <slot name="input_below" {id} />
233
+ {#if validation && !validation?.valid}
234
+ <div transition:slide={{ duration: 150 }} class={_validationMessageClass}>
235
+ {@html validation.message}
236
+ </div>
237
+ {/if}
238
+ {#if description}
239
+ <div class={_descriptionClass}>
240
+ <Thc thc={description} forceAsHtml />
241
+ </div>
242
+ {/if}
243
+ {#if $$slots.below}
244
+ <div class={_belowClass}><slot name="below" {id} /></div>
245
+ {/if}
198
246
  </div>
199
- {#if validation && !validation?.valid}
200
- <div transition:slide={{ duration: 150 }} class={_validationMessageClass}>
201
- {@html validation.message}
202
- </div>
203
- {/if}
204
- {#if description}
205
- <div class={_descriptionClass}>
206
- <Thc thc={description} forceAsHtml />
207
- </div>
208
- {/if}
209
- {#if $$slots.below}
210
- <div class={_belowClass}><slot name="below" {id} /></div>
211
- {/if}
212
247
  </div>
@@ -47,6 +47,8 @@ declare const __propDef: {
47
47
  step?: number | undefined;
48
48
  useTrim?: boolean | undefined;
49
49
  textareaAutoEnlarge?: boolean | undefined;
50
+ labelLeft?: boolean | undefined;
51
+ labelLeftWidth?: "normal" | "wide" | undefined;
50
52
  validate?: ValidateOptions | true | undefined;
51
53
  showAsterixOnRequired?: boolean | undefined;
52
54
  };
@@ -5,6 +5,14 @@ import {
5
5
  Thc,
6
6
  validate as validateAction
7
7
  } from "../../index.js";
8
+ const _emptyClasses = () => ({
9
+ box: "",
10
+ label: "",
11
+ input: "",
12
+ invalid: "",
13
+ validationMessage: "",
14
+ description: ""
15
+ });
8
16
  const _PRESET = {
9
17
  box: "flex items-start mb-4",
10
18
  label: "block w-full",
@@ -31,8 +39,12 @@ const _PRESET_BY_SIZE = {
31
39
  lg: { label: "text-base font-bold" }
32
40
  };
33
41
  export class FieldCheckboxConfig {
34
- static class;
35
- static classBySize;
42
+ static class = _emptyClasses();
43
+ static classBySize = {
44
+ sm: _emptyClasses(),
45
+ md: _emptyClasses(),
46
+ lg: _emptyClasses()
47
+ };
36
48
  }
37
49
  </script>
38
50
 
@@ -2,9 +2,22 @@
2
2
  import { twMerge } from "tailwind-merge";
3
3
  import { getId } from "../../index.js";
4
4
  import XFieldRadioInternal from "./XFieldRadioInternal.svelte";
5
+ const _emptyClasses = () => ({
6
+ group: "",
7
+ box: "",
8
+ label: "",
9
+ input: "",
10
+ invalid: "",
11
+ validationMessage: "",
12
+ description: ""
13
+ });
5
14
  export class FieldRadiosConfig {
6
- static class;
7
- static classBySize;
15
+ static class = _emptyClasses();
16
+ static classBySize = {
17
+ sm: _emptyClasses(),
18
+ md: _emptyClasses(),
19
+ lg: _emptyClasses()
20
+ };
8
21
  }
9
22
  </script>
10
23
 
@@ -6,8 +6,19 @@ import {
6
6
  Thc,
7
7
  validate as validateAction
8
8
  } from "../../index.js";
9
+ const _emptyClasses = () => ({
10
+ box: "",
11
+ wrap: "",
12
+ label: "",
13
+ input: "",
14
+ invalid: "",
15
+ validationMessage: "",
16
+ description: "",
17
+ below: "",
18
+ asterix: ""
19
+ });
9
20
  const _PRESET = {
10
- box: "mb-4",
21
+ box: "mb-4 grid",
11
22
  wrap: `
12
23
  flex items-center
13
24
  rounded-md border border-gray-300
@@ -45,8 +56,12 @@ const _PRESET_BY_SIZE = {
45
56
  }
46
57
  };
47
58
  export class FieldSelectConfig {
48
- static class = {};
49
- static classBySize = {};
59
+ static class = _emptyClasses();
60
+ static classBySize = {
61
+ sm: _emptyClasses(),
62
+ md: _emptyClasses(),
63
+ lg: _emptyClasses()
64
+ };
50
65
  }
51
66
  </script>
52
67
 
@@ -67,6 +82,8 @@ export let required = false;
67
82
  export let autofocus = void 0;
68
83
  export let validate = void 0;
69
84
  export let showAsterixOnRequired = true;
85
+ export let labelLeft = false;
86
+ export let labelLeftWidth = "normal";
70
87
  let validation;
71
88
  const setValidationResult = (res) => validation = res;
72
89
  let _options = [];
@@ -119,8 +136,17 @@ $:
119
136
  _belowClass = twMerge(_collectClasses("below"));
120
137
  </script>
121
138
 
122
- <div class={_boxClass}>
123
- <div class="flex items-end px-2 mb-1">
139
+ <div
140
+ class={_boxClass}
141
+ class:grid-cols-4={labelLeft && labelLeftWidth === 'normal'}
142
+ class:grid-cols-3={labelLeft && labelLeftWidth === 'wide'}
143
+ >
144
+ <div
145
+ class="flex px-2"
146
+ class:items-end={!labelLeft}
147
+ class:items-start={labelLeft}
148
+ class:mt-1={labelLeft}
149
+ >
124
150
  {#if label || $$slots.label}
125
151
  <label for={id} class={_labelClass}>
126
152
  {#if $$slots.label}
@@ -132,39 +158,49 @@ $:
132
158
  {/if}
133
159
  <slot name="right_of_label" />
134
160
  </div>
135
- <div class={_wrapClass} class:cursor-not-allowed={disabled} class:opacity-50={disabled}>
136
- <slot name="input_before" {id} />
137
- <select
138
- class={_inputClass}
139
- bind:value
140
- bind:this={_inputEl}
141
- {disabled}
142
- {required}
143
- {tabindex}
144
- {autofocus}
145
- {name}
146
- use:validateAction={validate
147
- ? { ...(validate === true ? {} : validate), setValidationResult }
148
- : undefined}
161
+ <div
162
+ class:col-span-3={labelLeft && labelLeftWidth === 'normal'}
163
+ class:col-span-2={labelLeft && labelLeftWidth === 'wide'}
164
+ >
165
+ <div
166
+ class={_wrapClass}
167
+ class:cursor-not-allowed={disabled}
168
+ class:opacity-50={disabled}
149
169
  >
150
- {#each _options as o, i}
151
- <option value={o.value}>{o.label}</option>
152
- {/each}
153
- </select>
170
+ <slot name="input_before" {id} />
171
+ <select
172
+ class={_inputClass}
173
+ bind:value
174
+ bind:this={_inputEl}
175
+ {id}
176
+ {disabled}
177
+ {required}
178
+ {tabindex}
179
+ {autofocus}
180
+ {name}
181
+ use:validateAction={validate
182
+ ? { ...(validate === true ? {} : validate), setValidationResult }
183
+ : undefined}
184
+ >
185
+ {#each _options as o, i}
186
+ <option value={o.value}>{o.label}</option>
187
+ {/each}
188
+ </select>
154
189
 
155
- <slot name="input_after" {id} />
156
- </div>
157
- {#if validation && !validation?.valid}
158
- <div transition:slide={{ duration: 150 }} class={_validationMessageClass}>
159
- {@html validation.message}
160
- </div>
161
- {/if}
162
- {#if description}
163
- <div class={_descriptionClass}>
164
- <Thc thc={description} forceAsHtml />
190
+ <slot name="input_after" {id} />
165
191
  </div>
166
- {/if}
167
- {#if $$slots.below}
168
- <div class={_belowClass}><slot name="below" {id} /></div>
169
- {/if}
192
+ {#if validation && !validation?.valid}
193
+ <div transition:slide={{ duration: 150 }} class={_validationMessageClass}>
194
+ {@html validation.message}
195
+ </div>
196
+ {/if}
197
+ {#if description}
198
+ <div class={_descriptionClass}>
199
+ <Thc thc={description} forceAsHtml />
200
+ </div>
201
+ {/if}
202
+ {#if $$slots.below}
203
+ <div class={_belowClass}><slot name="below" {id} /></div>
204
+ {/if}
205
+ </div>
170
206
  </div>
@@ -40,6 +40,8 @@ declare const __propDef: {
40
40
  autofocus?: true | undefined;
41
41
  validate?: ValidateOptions | true | undefined;
42
42
  showAsterixOnRequired?: boolean | undefined;
43
+ labelLeft?: boolean | undefined;
44
+ labelLeftWidth?: "normal" | "wide" | undefined;
43
45
  };
44
46
  events: {
45
47
  [evt: string]: CustomEvent<any>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marianmeres/stuic",
3
- "version": "1.55.0",
3
+ "version": "1.57.0",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run package && node ./scripts/date.js",