uisv 0.0.18 → 0.0.20

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.
@@ -5,8 +5,10 @@
5
5
  // import { FORM_LOADING_CONTEXT_KEY } from '../utils/keys.js';
6
6
  import { isSnippet } from '../index.js';
7
7
  import { tv } from 'tailwind-variants';
8
+ import type { SvelteHTMLElements } from 'svelte/elements';
9
+ import { Button } from 'bits-ui';
8
10
 
9
- export type ButtonProps = {
11
+ export type ButtonProps = SvelteHTMLElements['button'] & {
10
12
  /** The underlying DOM element being rendered. You can bind to this to get a reference to the element. */
11
13
  ref?: HTMLButtonElement | HTMLAnchorElement;
12
14
  /** Where to display the linked URL, as the name for a browsing context. */
@@ -47,7 +49,6 @@
47
49
  block?: boolean;
48
50
  /** Set loading state automatically based on the `@click` promise state */
49
51
  loadingauto?: boolean;
50
- onclick?: (event: MouseEvent) => void | Promise<void>;
51
52
  ui?: {
52
53
  base?: ClassNameValue;
53
54
  icon?: ClassNameValue;
@@ -73,7 +74,7 @@
73
74
  block,
74
75
  label,
75
76
  loadingauto,
76
- onclick,
77
+ onclick = () => {},
77
78
  ui = {},
78
79
  disabled,
79
80
  href,
@@ -84,6 +85,7 @@
84
85
  type,
85
86
  trailingicon,
86
87
  leadingicon,
88
+ ...rest
87
89
  }: ButtonProps = $props();
88
90
 
89
91
  let internal_loading = $state(false);
@@ -143,7 +145,7 @@
143
145
  {
144
146
  color: 'surface',
145
147
  variant: 'solid',
146
- class: 'bg-surface-inverted text-inverted hover:bg-toned',
148
+ class: 'bg-surface-inverted text-hightlighted hover:bg-toned',
147
149
  },
148
150
  {
149
151
  color: 'info',
@@ -170,148 +172,136 @@
170
172
  color: 'primary',
171
173
  variant: 'outline',
172
174
  class: {
173
- base: [
174
- 'border-primary/50 text-primary-500 hover:bg-primary-50',
175
- 'dark:hover:bg-primary-950',
176
- ],
175
+ base: 'border-primary/50 text-primary-500 hover:bg-primary/10',
177
176
  },
178
177
  },
179
178
  {
180
179
  color: 'surface',
181
180
  variant: 'outline',
182
181
  class: {
183
- base: [
184
- 'border-surface-accented text-surface-inverted hover:bg-surface/10',
185
- 'dark:hover:bg-surface-800',
186
- ],
182
+ base: 'border-surface-hightlighted text-surface-inverted hover:bg-surface/10',
187
183
  },
188
184
  },
189
185
  {
190
186
  color: 'info',
191
187
  variant: 'outline',
192
188
  class: {
193
- base: ['border-info/50 text-info-500 hover:bg-info/10', 'dark:hover:bg-info-950'],
189
+ base: 'border-info/50 text-info-500 hover:bg-info/10',
194
190
  },
195
191
  },
196
192
  {
197
193
  color: 'success',
198
194
  variant: 'outline',
199
195
  class: {
200
- base: [
201
- 'border-success/50 text-success-500 hover:bg-success/10',
202
- 'dark:hover:bg-success-950',
203
- ],
196
+ base: 'border-success/50 text-success-500 hover:bg-success/10',
204
197
  },
205
198
  },
206
199
  {
207
200
  color: 'error',
208
201
  variant: 'outline',
209
202
  class: {
210
- base: ['border-error/50 text-error-500 hover:bg-error/10', 'dark:hover:bg-error-950'],
203
+ base: 'border-error/50 text-error-500 hover:bg-error/10',
211
204
  },
212
205
  },
213
206
  {
214
207
  color: 'warning',
215
208
  variant: 'outline',
216
209
  class: {
217
- base: [
218
- 'border-warning/50 text-warning-500 hover:bg-warning/10',
219
- 'dark:hover:bg-warning-950',
220
- ],
210
+ base: 'border-warning/50 text-warning-500 hover:bg-warning/10',
221
211
  },
222
212
  },
223
213
 
224
214
  {
225
215
  color: 'primary',
226
216
  variant: 'soft',
227
- class: 'bg-primary-50 text-primary-500 hover:bg-primary-100',
217
+ class: 'bg-primary/10 text-primary-500 hover:bg-primary/15',
228
218
  },
229
219
  {
230
220
  color: 'surface',
231
221
  variant: 'soft',
232
- class: 'bg-surface-100 text-surface-800 hover:bg-surface-200',
222
+ class: 'bg-surface/10 text-hightlighted hover:bg-surface/15',
233
223
  },
234
224
  {
235
225
  color: 'info',
236
226
  variant: 'soft',
237
- class: 'bg-info-100 text-info-500 hover:bg-info-50',
227
+ class: 'bg-info/10 text-info-500 hover:bg-info/15',
238
228
  },
239
229
  {
240
230
  color: 'success',
241
231
  variant: 'soft',
242
- class: 'bg-success-100 text-success-500 hover:bg-success-50',
232
+ class: 'bg-success/10 text-success-500 hover:bg-success/15',
243
233
  },
244
234
  {
245
235
  color: 'error',
246
236
  variant: 'soft',
247
- class: 'bg-error-100 text-error-500 hover:bg-error-50',
237
+ class: 'bg-error/10 text-error-500 hover:bg-error/15',
248
238
  },
249
239
  {
250
240
  color: 'warning',
251
241
  variant: 'soft',
252
- class: 'bg-warning-100 text-warning-500 hover:bg-warning-50',
242
+ class: 'bg-warning/10 text-warning-500 hover:bg-warning/15',
253
243
  },
254
244
 
255
245
  {
256
246
  color: 'primary',
257
247
  variant: 'subtle',
258
- class: 'bg-primary-50 text-primary-500 border-primary-200 hover:bg-primary-100',
248
+ class: 'bg-primary/10 text-primary-500 border-primary/25 hover:bg-primary/15',
259
249
  },
260
250
  {
261
251
  color: 'surface',
262
252
  variant: 'subtle',
263
- class: 'bg-surface-50 text-surface-800 border-surface-300 hover:bg-surface-100',
253
+ class: 'bg-surface/10 text-hightlighted border-surface/25 hover:bg-surface/15',
264
254
  },
265
255
  {
266
256
  color: 'info',
267
257
  variant: 'subtle',
268
- class: 'bg-info-50 text-info-600 border-info-200 hover:bg-info-100',
258
+ class: 'bg-info/10 text-info-600 border-info/25 hover:bg-info/15',
269
259
  },
270
260
  {
271
261
  color: 'success',
272
262
  variant: 'subtle',
273
- class: 'bg-success-100 text-success-600 border-success-300 hover:bg-success-100',
263
+ class: 'bg-success/10 text-success-600 border-success/25 hover:bg-success/15',
274
264
  },
275
265
  {
276
266
  color: 'error',
277
267
  variant: 'subtle',
278
- class: 'bg-error-50 text-error-600 border-error-200 hover:bg-error-100',
268
+ class: 'bg-error/10 text-error-600 border-error/25 hover:bg-error/15',
279
269
  },
280
270
  {
281
271
  color: 'warning',
282
272
  variant: 'subtle',
283
- class: 'bg-warning-50 text-warning-600 border-warning-300 hover:bg-warning-100',
273
+ class: 'bg-warning/10 text-warning-600 border-warning/25 hover:bg-warning/15',
284
274
  },
285
275
 
286
276
  {
287
277
  color: 'primary',
288
278
  variant: 'ghost',
289
- class: 'text-primary-500 hover:bg-primary-100',
279
+ class: 'text-primary-500 hover:bg-primary/15',
290
280
  },
291
281
  {
292
282
  color: 'surface',
293
283
  variant: 'ghost',
294
- class: 'text-surface-inverted hover:bg-surface-elevated',
284
+ class: 'text-highlighted hover:bg-surface/15',
295
285
  },
296
286
  {
297
287
  color: 'info',
298
288
  variant: 'ghost',
299
- class: 'text-info-600 hover:bg-info-100',
289
+ class: 'text-info-600 hover:bg-info/15',
300
290
  },
301
291
  {
302
292
  color: 'success',
303
293
  variant: 'ghost',
304
- class: 'text-success-600 hover:bg-success-100',
294
+ class: 'text-success-600 hover:bg-success/15',
305
295
  },
306
296
  {
307
297
  color: 'error',
308
298
  variant: 'ghost',
309
- class: 'text-error-600 hover:bg-error-100',
299
+ class: 'text-error-600 hover:bg-error/15',
310
300
  },
311
301
  {
312
302
  color: 'warning',
313
303
  variant: 'ghost',
314
- class: 'text-warning-600 hover:bg-warning-100',
304
+ class: 'text-warning-600 hover:bg-warning/15',
315
305
  },
316
306
 
317
307
  {
@@ -350,41 +340,36 @@
350
340
 
351
341
  const only_icon = $derived(!(children || label) && !!icon);
352
342
 
353
- async function onClickWrapper(event: MouseEvent) {
343
+ async function onClickWrapper(
344
+ e: MouseEvent & { currentTarget: EventTarget & HTMLButtonElement },
345
+ ) {
354
346
  if (!onclick) return;
355
347
  internal_loading = true;
356
348
 
357
- await onclick(event);
349
+ await onclick(e);
358
350
 
359
351
  internal_loading = false;
360
352
  }
361
- </script>
362
353
 
363
- {#if href}
364
- <a
365
- {href}
366
- {target}
367
- class={variants.base({
368
- class: [only_icon ? 'px-0 aspect-square justify-center' : '', 'cursor-pointer', ui.base],
369
- })}
370
- onclick={onClickWrapper}
371
- >
372
- {@render Content()}
373
- </a>
374
- {:else}
375
- <button
376
- {type}
377
- disabled={disabled || is_loading}
378
- class={variants.base({
379
- class: [only_icon ? 'px-0 aspect-square justify-center' : '', ui.base],
380
- })}
381
- onclick={onClickWrapper}
382
- >
383
- {@render Content()}
384
- </button>
385
- {/if}
354
+ $inspect(children, label, !!icon);
355
+ </script>
386
356
 
387
- {#snippet Content()}
357
+ <svelte:element
358
+ this={href ? 'a' : 'button'}
359
+ data-button-root
360
+ type={href ? undefined : type}
361
+ href={href && !disabled ? href : undefined}
362
+ disabled={disabled || is_loading}
363
+ aria-disabled={href ? disabled : undefined}
364
+ role={href && disabled ? 'link' : undefined}
365
+ tabindex={href && disabled ? -1 : 0}
366
+ bind:this={ref}
367
+ class={variants.base({
368
+ class: [only_icon && 'px-0 aspect-square justify-center', href && 'cursor-pointer', ui.base],
369
+ })}
370
+ onclick={onClickWrapper}
371
+ {...rest}
372
+ >
388
373
  {#if iconposition === 'left' || leadingicon}
389
374
  {@render Icon(is_loading ? loadingicon : leadingicon || icon, ui.leadingicon)}
390
375
  {/if}
@@ -398,7 +383,7 @@
398
383
  {#if iconposition !== 'left' || trailingicon}
399
384
  {@render Icon(trailingicon || icon, ui.trailingicon)}
400
385
  {/if}
401
- {/snippet}
386
+ </svelte:element>
402
387
 
403
388
  {#snippet Icon(IconProp?: string | Snippet | Component, classvalue?: ClassNameValue)}
404
389
  {#if typeof IconProp === 'string'}
@@ -1,7 +1,9 @@
1
1
  import { type Component, type Snippet } from 'svelte';
2
2
  import { type PropColor, type PropVariant } from '../index.js';
3
3
  import type { ClassNameValue } from 'tailwind-merge';
4
- export type ButtonProps = {
4
+ import type { SvelteHTMLElements } from 'svelte/elements';
5
+ import { Button } from 'bits-ui';
6
+ export type ButtonProps = SvelteHTMLElements['button'] & {
5
7
  /** The underlying DOM element being rendered. You can bind to this to get a reference to the element. */
6
8
  ref?: HTMLButtonElement | HTMLAnchorElement;
7
9
  /** Where to display the linked URL, as the name for a browsing context. */
@@ -39,7 +41,6 @@ export type ButtonProps = {
39
41
  block?: boolean;
40
42
  /** Set loading state automatically based on the `@click` promise state */
41
43
  loadingauto?: boolean;
42
- onclick?: (event: MouseEvent) => void | Promise<void>;
43
44
  ui?: {
44
45
  base?: ClassNameValue;
45
46
  icon?: ClassNameValue;
@@ -26,7 +26,6 @@
26
26
  .replaceAll('"', '\"')
27
27
  .replace('<', '%3C')
28
28
  .replace('>', '%3E')}');
29
- display: inline-block;
30
29
  width: 1em;
31
30
  height: 1em;
32
31
  background-color: currentColor;
@@ -47,6 +46,8 @@
47
46
  },
48
47
  );
49
48
 
49
+ $inspect(isComponent(name), name);
50
+
50
51
  useStyle(() => css_style);
51
52
  </script>
52
53
 
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './components/index.js';
2
2
  export * from './utilities.svelte.js';
3
3
  export * from './types.js';
4
+ export { ModeWatcher } from 'mode-watcher';
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './components/index.js';
2
2
  export * from './utilities.svelte.js';
3
3
  export * from './types.js';
4
+ export { ModeWatcher } from 'mode-watcher';
package/dist/mode.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from 'mode-watcher';
package/dist/mode.js ADDED
@@ -0,0 +1 @@
1
+ export * from 'mode-watcher';
@@ -5,6 +5,8 @@ import { extract, useMutationObserver, useResizeObserver, } from 'runed';
5
5
  * @returns true if the value is a component, false otherwise
6
6
  */
7
7
  export function isComponent(v) {
8
+ if (typeof document !== 'undefined')
9
+ return typeof v === 'function';
8
10
  return typeof v === 'function' && 'render' in v;
9
11
  }
10
12
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "uisv",
3
- "version": "0.0.18",
3
+ "version": "0.0.20",
4
4
  "description": "ui library for the rest of us",
5
5
  "license": "MIT",
6
6
  "repository": "ui-sv/uisv",
@@ -44,6 +44,11 @@
44
44
  "types": "./dist/date.d.ts",
45
45
  "svelte": "./dist/date.js",
46
46
  "default": "./dist/date.js"
47
+ },
48
+ "./mode": {
49
+ "types": "./dist/mode.d.ts",
50
+ "svelte": "./dist/mode.js",
51
+ "default": "./dist/mode.js"
47
52
  }
48
53
  },
49
54
  "peerDependencies": {
@@ -78,7 +83,7 @@
78
83
  "dependencies": {
79
84
  "@internationalized/date": "^3.11.0",
80
85
  "@unocss/preset-web-fonts": "^66.6.0",
81
- "bits-ui": "^2.16.2",
86
+ "bits-ui": "^2.16.5",
82
87
  "colortranslator": "^5.0.0",
83
88
  "defu": "^6.1.4",
84
89
  "maska": "^3.2.0",