noph-ui 0.4.2 → 0.4.4
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.
package/dist/menu/Menu.svelte
CHANGED
|
@@ -2,7 +2,14 @@
|
|
|
2
2
|
import { generateUUIDv4 } from '../utils.js'
|
|
3
3
|
import type { MenuProps } from './types.ts'
|
|
4
4
|
|
|
5
|
-
let {
|
|
5
|
+
let {
|
|
6
|
+
anchor,
|
|
7
|
+
children,
|
|
8
|
+
element = $bindable(),
|
|
9
|
+
showPopover = $bindable(),
|
|
10
|
+
hidePopover = $bindable(),
|
|
11
|
+
...attributes
|
|
12
|
+
}: MenuProps = $props()
|
|
6
13
|
|
|
7
14
|
let clientWidth = $state(0)
|
|
8
15
|
let clientHeight = $state(0)
|
|
@@ -10,30 +17,38 @@
|
|
|
10
17
|
let innerWidth = $state(0)
|
|
11
18
|
let scrollY = $state(0)
|
|
12
19
|
let scrollX = $state(0)
|
|
13
|
-
let popoverElement: HTMLDivElement | undefined = $state()
|
|
14
20
|
let anchorId = anchor?.style.getPropertyValue('anchor-name')
|
|
21
|
+
|
|
22
|
+
showPopover = () => {
|
|
23
|
+
element?.showPopover()
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
hidePopover = () => {
|
|
27
|
+
element?.hidePopover()
|
|
28
|
+
}
|
|
29
|
+
|
|
15
30
|
const refreshValues = () => {
|
|
16
|
-
if (
|
|
31
|
+
if (element && anchor && !('anchorName' in document.documentElement.style)) {
|
|
17
32
|
const anchorRect = anchor.getBoundingClientRect()
|
|
18
33
|
if (anchorRect.bottom + clientHeight > innerHeight && anchorRect.top - clientHeight > 0) {
|
|
19
|
-
|
|
34
|
+
element.style.top = `${anchorRect.top - clientHeight - 2}px`
|
|
20
35
|
} else {
|
|
21
|
-
|
|
36
|
+
element.style.top = `${anchorRect.bottom + 2}px`
|
|
22
37
|
}
|
|
23
38
|
const left = anchorRect.left + anchorRect.width / 2 - clientWidth / 2
|
|
24
39
|
if (left > innerWidth - clientWidth) {
|
|
25
|
-
|
|
40
|
+
element.style.left = `${innerWidth - clientWidth - 8}px`
|
|
26
41
|
} else if (left < 8) {
|
|
27
|
-
|
|
42
|
+
element.style.left = '8px'
|
|
28
43
|
} else {
|
|
29
|
-
|
|
44
|
+
element.style.left = `${anchorRect.left + anchorRect.width / 2 - clientWidth / 2}px`
|
|
30
45
|
}
|
|
31
46
|
}
|
|
32
47
|
}
|
|
33
48
|
$effect(refreshValues)
|
|
34
49
|
|
|
35
50
|
$effect(() => {
|
|
36
|
-
if (anchor &&
|
|
51
|
+
if (anchor && element) {
|
|
37
52
|
if (!('anchorName' in document.documentElement.style)) {
|
|
38
53
|
anchor.addEventListener('click', () => {
|
|
39
54
|
refreshValues()
|
|
@@ -47,7 +62,7 @@
|
|
|
47
62
|
)
|
|
48
63
|
} else if (!anchorId) {
|
|
49
64
|
const generatedId = `--${generateUUIDv4()}`
|
|
50
|
-
|
|
65
|
+
element.style.setProperty('position-anchor', generatedId)
|
|
51
66
|
anchor.style.setProperty('anchor-name', generatedId)
|
|
52
67
|
}
|
|
53
68
|
}
|
|
@@ -63,7 +78,7 @@
|
|
|
63
78
|
/>
|
|
64
79
|
|
|
65
80
|
<div
|
|
66
|
-
bind:this={
|
|
81
|
+
bind:this={element}
|
|
67
82
|
bind:clientWidth
|
|
68
83
|
bind:clientHeight
|
|
69
84
|
{...attributes}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { MenuProps } from './types.ts';
|
|
2
|
-
declare const Menu: import("svelte").Component<MenuProps, {}, "">;
|
|
2
|
+
declare const Menu: import("svelte").Component<MenuProps, {}, "element" | "showPopover" | "hidePopover">;
|
|
3
3
|
type Menu = ReturnType<typeof Menu>;
|
|
4
4
|
export default Menu;
|
package/dist/menu/types.d.ts
CHANGED
|
@@ -3,6 +3,9 @@ import type { HTMLAttributes, HTMLAnchorAttributes, HTMLButtonAttributes } from
|
|
|
3
3
|
export interface MenuProps extends HTMLAttributes<HTMLDivElement> {
|
|
4
4
|
children: Snippet;
|
|
5
5
|
anchor?: HTMLElement | undefined;
|
|
6
|
+
showPopover?: () => void;
|
|
7
|
+
hidePopover?: () => void;
|
|
8
|
+
element?: HTMLDivElement;
|
|
6
9
|
}
|
|
7
10
|
interface ButtonProps extends HTMLButtonAttributes {
|
|
8
11
|
selected?: boolean;
|
|
@@ -21,14 +21,15 @@
|
|
|
21
21
|
}: TextFieldProps = $props()
|
|
22
22
|
|
|
23
23
|
let errorTextRaw = $state(errorText)
|
|
24
|
+
let textElement: HTMLInputElement | HTMLTextAreaElement | undefined = $state()
|
|
24
25
|
|
|
25
26
|
$effect(() => {
|
|
26
|
-
if (
|
|
27
|
-
|
|
27
|
+
if (textElement) {
|
|
28
|
+
textElement.form?.addEventListener('reset', () => {
|
|
28
29
|
error = false
|
|
29
30
|
value = ''
|
|
30
31
|
})
|
|
31
|
-
|
|
32
|
+
textElement.addEventListener('invalid', (event) => {
|
|
32
33
|
event.preventDefault()
|
|
33
34
|
const { currentTarget } = event as Event & {
|
|
34
35
|
currentTarget: HTMLInputElement | HTMLTextAreaElement
|
|
@@ -42,7 +43,7 @@
|
|
|
42
43
|
}
|
|
43
44
|
})
|
|
44
45
|
|
|
45
|
-
|
|
46
|
+
textElement.addEventListener('change', (event) => {
|
|
46
47
|
const { currentTarget } = event as Event & {
|
|
47
48
|
currentTarget: HTMLInputElement | HTMLTextAreaElement
|
|
48
49
|
}
|
|
@@ -64,11 +65,12 @@
|
|
|
64
65
|
? '--top-space:1rem;--bottom-space:1rem'
|
|
65
66
|
: '') + style}
|
|
66
67
|
class="text-field"
|
|
68
|
+
bind:this={element}
|
|
67
69
|
onclick={() => {
|
|
68
70
|
if (attributes.disabled) {
|
|
69
71
|
return
|
|
70
72
|
}
|
|
71
|
-
|
|
73
|
+
textElement?.focus()
|
|
72
74
|
}}
|
|
73
75
|
>
|
|
74
76
|
<div
|
|
@@ -117,7 +119,7 @@
|
|
|
117
119
|
<textarea
|
|
118
120
|
{...attributes}
|
|
119
121
|
bind:value
|
|
120
|
-
bind:this={
|
|
122
|
+
bind:this={textElement}
|
|
121
123
|
class="input"
|
|
122
124
|
aria-label={label}
|
|
123
125
|
{placeholder}
|
|
@@ -133,7 +135,7 @@
|
|
|
133
135
|
<input
|
|
134
136
|
{...attributes}
|
|
135
137
|
bind:value
|
|
136
|
-
bind:this={
|
|
138
|
+
bind:this={textElement}
|
|
137
139
|
class="input"
|
|
138
140
|
{placeholder}
|
|
139
141
|
aria-label={label}
|
|
@@ -12,7 +12,7 @@ export interface InputFieldProps extends Omit<HTMLInputAttributes, 'class'> {
|
|
|
12
12
|
start?: Snippet;
|
|
13
13
|
end?: Snippet;
|
|
14
14
|
noAsterisk?: boolean;
|
|
15
|
-
element?:
|
|
15
|
+
element?: HTMLSpanElement;
|
|
16
16
|
}
|
|
17
17
|
export interface TextAreaFieldProps extends Omit<HTMLTextareaAttributes, 'class'> {
|
|
18
18
|
label?: string;
|
|
@@ -26,6 +26,6 @@ export interface TextAreaFieldProps extends Omit<HTMLTextareaAttributes, 'class'
|
|
|
26
26
|
start?: Snippet;
|
|
27
27
|
end?: Snippet;
|
|
28
28
|
noAsterisk?: boolean;
|
|
29
|
-
element?:
|
|
29
|
+
element?: HTMLSpanElement;
|
|
30
30
|
}
|
|
31
31
|
export type TextFieldProps = InputFieldProps | TextAreaFieldProps;
|
package/package.json
CHANGED
|
@@ -1,93 +1,92 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
2
|
+
"name": "noph-ui",
|
|
3
|
+
"version": "0.4.4",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"homepage": "https://noph.dev",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/cnolte/noph-ui"
|
|
9
|
+
},
|
|
10
|
+
"author": {
|
|
11
|
+
"name": "cnolte"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"svelte",
|
|
15
|
+
"svelte 5",
|
|
16
|
+
"material",
|
|
17
|
+
"material 3",
|
|
18
|
+
"material you",
|
|
19
|
+
"m3",
|
|
20
|
+
"ui",
|
|
21
|
+
"frontend",
|
|
22
|
+
"design-system",
|
|
23
|
+
"ui-library",
|
|
24
|
+
"theming"
|
|
25
|
+
],
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"svelte": "./dist/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./icons": {
|
|
32
|
+
"types": "./dist/icons/index.d.ts",
|
|
33
|
+
"svelte": "./dist/icons/index.js"
|
|
34
|
+
},
|
|
35
|
+
"./types": {
|
|
36
|
+
"types": "./dist/types.d.ts"
|
|
37
|
+
},
|
|
38
|
+
"./defaultTheme": {
|
|
39
|
+
"import": "./dist/themes/defaultTheme.css",
|
|
40
|
+
"require": "./dist/themes/defaultTheme.css"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"sideEffects": [
|
|
44
|
+
"**/*.css"
|
|
45
|
+
],
|
|
46
|
+
"files": [
|
|
47
|
+
"dist",
|
|
48
|
+
"!dist/**/*.test.*",
|
|
49
|
+
"!dist/**/*.spec.*"
|
|
50
|
+
],
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"svelte": "^5.0.0"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@material/material-color-utilities": "^0.3.0",
|
|
56
|
+
"@playwright/test": "^1.49.1",
|
|
57
|
+
"@sveltejs/adapter-vercel": "^5.5.2",
|
|
58
|
+
"@sveltejs/kit": "^2.12.1",
|
|
59
|
+
"@sveltejs/package": "^2.3.7",
|
|
60
|
+
"@sveltejs/vite-plugin-svelte": "^5.0.2",
|
|
61
|
+
"@types/eslint": "^9.6.1",
|
|
62
|
+
"eslint": "^9.17.0",
|
|
63
|
+
"eslint-config-prettier": "^9.1.0",
|
|
64
|
+
"eslint-plugin-svelte": "^2.46.1",
|
|
65
|
+
"globals": "^15.13.0",
|
|
66
|
+
"prettier": "^3.4.2",
|
|
67
|
+
"prettier-plugin-svelte": "^3.3.2",
|
|
68
|
+
"publint": "^0.2.12",
|
|
69
|
+
"svelte": "^5.14.1",
|
|
70
|
+
"svelte-check": "^4.1.1",
|
|
71
|
+
"typescript": "^5.7.2",
|
|
72
|
+
"typescript-eslint": "^8.18.1",
|
|
73
|
+
"vite": "^6.0.3",
|
|
74
|
+
"vitest": "^2.1.8"
|
|
75
|
+
},
|
|
76
|
+
"svelte": "./dist/index.js",
|
|
77
|
+
"types": "./dist/index.d.ts",
|
|
78
|
+
"type": "module",
|
|
79
|
+
"scripts": {
|
|
80
|
+
"dev": "vite dev",
|
|
81
|
+
"build": "vite build && npm run package",
|
|
82
|
+
"preview": "vite preview",
|
|
83
|
+
"package": "svelte-kit sync && svelte-package && publint",
|
|
84
|
+
"test": "npm run test:integration && npm run test:unit",
|
|
85
|
+
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
|
86
|
+
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
|
87
|
+
"lint": "prettier --check . && eslint .",
|
|
88
|
+
"format": "prettier --write .",
|
|
89
|
+
"test:integration": "playwright test",
|
|
90
|
+
"test:unit": "vitest"
|
|
91
|
+
}
|
|
92
|
+
}
|