noph-ui 0.29.5 → 0.30.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.
@@ -2,7 +2,6 @@
2
2
  import IconButton from '../button/IconButton.svelte'
3
3
  import CloseIcon from '../icons/CloseIcon.svelte'
4
4
  import Ripple from '../ripple/Ripple.svelte'
5
- import { onMount } from 'svelte'
6
5
  import type { InputChipProps } from './types.ts'
7
6
 
8
7
  let {
@@ -19,26 +18,6 @@
19
18
  }: InputChipProps = $props()
20
19
 
21
20
  let chipLabel: HTMLDivElement | undefined = $state()
22
- let visible = $state(false)
23
-
24
- onMount(() => {
25
- const observer = new IntersectionObserver((entries) => {
26
- entries.forEach((entry) => {
27
- if (entry.isIntersecting) {
28
- visible = true
29
- observer.disconnect()
30
- }
31
- })
32
- })
33
-
34
- if (element) {
35
- observer.observe(element)
36
- }
37
-
38
- return () => {
39
- observer.disconnect()
40
- }
41
- })
42
21
  </script>
43
22
 
44
23
  <div
@@ -55,44 +34,37 @@
55
34
  attributes.class,
56
35
  ]}
57
36
  >
58
- {#if visible}
59
- <div bind:this={chipLabel} class={['np-input-chip-label']}>
60
- {#if icon}
61
- <div class="np-chip-icon">
62
- {@render icon()}
63
- </div>
64
- {/if}
65
- <div class="np-chip-label">{label || value}</div>
66
- <input type="hidden" {value} {name} {disabled} />
67
- </div>
68
- {#if !disabled}
69
- <Ripple forElement={chipLabel} />
37
+ <div bind:this={chipLabel} class={['np-input-chip-label']}>
38
+ {#if icon}
39
+ <div class="np-chip-icon">
40
+ {@render icon()}
41
+ </div>
70
42
  {/if}
71
- <IconButton
72
- {disabled}
73
- type="button"
74
- size="xs"
75
- --np-icon-button-icon-size="1.125rem"
76
- aria-label={ariaLabelRemove}
77
- onclick={(
78
- event: MouseEvent & {
79
- currentTarget: EventTarget & HTMLButtonElement
80
- },
81
- ) => {
82
- if (element === undefined) {
83
- return
84
- }
85
- onremove?.(event)
86
- }}
87
- >
88
- <CloseIcon />
89
- </IconButton>
90
- {:else}
91
- <div class="np-skeleton">
92
- {label}
93
- <input type="hidden" {value} {name} {disabled} />
94
- </div>
43
+ <div class="np-chip-label">{label || value}</div>
44
+ <input type="hidden" {value} {name} {disabled} />
45
+ </div>
46
+ {#if !disabled}
47
+ <Ripple forElement={chipLabel} />
95
48
  {/if}
49
+ <IconButton
50
+ {disabled}
51
+ type="button"
52
+ size="xs"
53
+ --np-icon-button-icon-size="1.125rem"
54
+ aria-label={ariaLabelRemove}
55
+ onclick={(
56
+ event: MouseEvent & {
57
+ currentTarget: EventTarget & HTMLButtonElement
58
+ },
59
+ ) => {
60
+ if (element === undefined) {
61
+ return
62
+ }
63
+ onremove?.(event)
64
+ }}
65
+ >
66
+ <CloseIcon />
67
+ </IconButton>
96
68
  </div>
97
69
 
98
70
  <style>
@@ -1,8 +1,8 @@
1
1
  <script lang="ts">
2
2
  import Ripple from '../ripple/Ripple.svelte'
3
+ import { onMount } from 'svelte'
3
4
  import type { FocusEventHandler } from 'svelte/elements'
4
5
  import type { ItemProps } from './types.ts'
5
- import { onMount } from 'svelte'
6
6
 
7
7
  let {
8
8
  selected = false,
@@ -14,14 +14,18 @@
14
14
  onfocus,
15
15
  onblur,
16
16
  softFocus = false,
17
+ lazy = false,
17
18
  ...attributes
18
19
  }: ItemProps = $props()
19
20
 
20
21
  let focused = $derived(softFocus)
21
- let visible = $state(false)
22
+ let visible = $state(!lazy)
22
23
  let element: HTMLButtonElement | HTMLAnchorElement | HTMLDivElement | undefined = $state()
23
24
  let observer: IntersectionObserver | undefined
24
25
  onMount(() => {
26
+ if (!lazy) {
27
+ return
28
+ }
25
29
  observer = new IntersectionObserver((entries) => {
26
30
  entries.forEach((entry) => {
27
31
  if (entry.isIntersecting) {
@@ -34,7 +38,7 @@
34
38
  return () => observer?.disconnect()
35
39
  })
36
40
  $effect(() => {
37
- if (element) {
41
+ if (element && lazy) {
38
42
  observer?.observe(element)
39
43
  }
40
44
  })
@@ -7,6 +7,7 @@ interface ButtonProps extends HTMLButtonAttributes {
7
7
  variant: 'button';
8
8
  supportingText?: Snippet;
9
9
  softFocus?: boolean;
10
+ lazy?: boolean;
10
11
  }
11
12
  interface AnchorProps extends HTMLAnchorAttributes {
12
13
  selected?: boolean;
@@ -16,6 +17,7 @@ interface AnchorProps extends HTMLAnchorAttributes {
16
17
  variant: 'link';
17
18
  supportingText?: Snippet;
18
19
  softFocus?: boolean;
20
+ lazy?: boolean;
19
21
  }
20
22
  interface TextProps extends HTMLAttributes<HTMLDivElement> {
21
23
  selected?: boolean;
@@ -25,6 +27,7 @@ interface TextProps extends HTMLAttributes<HTMLDivElement> {
25
27
  variant?: 'text';
26
28
  supportingText?: Snippet;
27
29
  softFocus?: boolean;
30
+ lazy?: boolean;
28
31
  }
29
32
  export type ItemProps = ButtonProps | AnchorProps | TextProps;
30
33
  export type ListItemProps = ButtonProps | AnchorProps | TextProps;
@@ -1,5 +1,5 @@
1
1
  import type { Snippet } from 'svelte';
2
- import type { HTMLAttributes, HTMLAnchorAttributes, HTMLButtonAttributes } from 'svelte/elements';
2
+ import type { HTMLAnchorAttributes, HTMLAttributes, HTMLButtonAttributes } from 'svelte/elements';
3
3
  export interface MenuProps extends HTMLAttributes<HTMLDivElement> {
4
4
  children: Snippet;
5
5
  anchor?: HTMLElement | undefined;
@@ -13,6 +13,7 @@ interface ButtonProps extends HTMLButtonAttributes {
13
13
  start?: Snippet;
14
14
  end?: Snippet;
15
15
  supportingText?: Snippet;
16
+ lazy?: boolean;
16
17
  }
17
18
  interface AnchorProps extends HTMLAnchorAttributes {
18
19
  selected?: boolean;
@@ -20,6 +21,7 @@ interface AnchorProps extends HTMLAnchorAttributes {
20
21
  end?: Snippet;
21
22
  disabled?: boolean;
22
23
  supportingText?: Snippet;
24
+ lazy?: boolean;
23
25
  }
24
26
  export type MenuItemProps = ButtonProps | AnchorProps;
25
27
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "noph-ui",
3
- "version": "0.29.5",
3
+ "version": "0.30.0",
4
4
  "license": "MIT",
5
5
  "homepage": "https://noph.dev",
6
6
  "repository": {