Skip to content

Commit 25fca4f

Browse files
committed
🏷️ Add types for utilities
1 parent 63ce582 commit 25fca4f

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"react.d.ts",
4444
"react.js",
4545
"index.js",
46+
"index.d.ts",
4647
"README.md",
4748
"LICENSE"
4849
],

scripts/build.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,6 @@ fs.writeFileSync('dist/astro.d.ts', buildTypes('astro'))
5656
fs.writeFileSync('dist/svelte.d.ts', buildTypes('svelte'))
5757
fs.writeFileSync('dist/react.d.ts', buildTypes('react'))
5858
fs.writeFileSync('dist/icons.d.ts', buildTypes('icons'))
59+
fs.writeFileSync('dist/index.d.ts', buildTypes('utils'))
5960

6061
console.log('✅ Package built')

scripts/buildTypes.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,80 @@ const buildTypes = type => {
9393
}
9494
`)
9595
}
96+
97+
if (type === 'utils') {
98+
return format(`
99+
type PopoverPosition = 'top'
100+
| 'top-start'
101+
| 'top-end'
102+
| 'left'
103+
| 'left-start'
104+
| 'left-end'
105+
| 'right'
106+
| 'right-start'
107+
| 'right-end'
108+
| 'bottom'
109+
| 'bottom-start'
110+
| 'bottom-end'
111+
112+
type Popover = {
113+
trigger: string
114+
popover: string
115+
position?: PopoverPosition
116+
offset?: number
117+
closeOnBlur?: boolean
118+
}
119+
120+
type Toast = {
121+
element: string
122+
timeout?: number
123+
title?: string
124+
content?: string
125+
theme?: 'info' | 'success' | 'warning' | 'alert' | null
126+
position?: 'bottom-left'
127+
| 'top-left'
128+
| 'top-right'
129+
| 'bottom-full'
130+
| 'top-full'
131+
}
132+
133+
declare module 'webcoreui' {
134+
export const classNames = (classes: any[]) => string
135+
136+
export const setCookie = (name: string, value: string, days: number) => {}
137+
export const getCookie = (name: string) => string | null
138+
export const removeCookie = (name: string) => {}
139+
140+
export const debounce = (fn: any, waitFor: number) => any
141+
142+
export const dispatch = (event: string, detail: any) => {}
143+
export const listen = (event: string, callback: (e: any) => any) => {
144+
remove()
145+
}
146+
147+
export const clamp = (num: number, min: number, max: number) => number
148+
export const lerp = (start: number, end: number, value: number) => number
149+
export const invlerp = (start: number, end: number, value: number) => number
150+
export const interpolate = (
151+
value: number,
152+
input: [start: number, end: number],
153+
output: [start: number, end: number],
154+
) => number
155+
156+
export const modal = (selector: string) => {}
157+
export const closeModal = (selector: string) => {}
158+
159+
export const popover = (config: Popover) => {
160+
remove()
161+
}
162+
export const closePopover = (selector: string) => {}
163+
164+
export const setDefaultTimeout = (time: number) => number
165+
export const toast = (config: Toast | string) => {}
166+
export const hideToast = (element: string) => {}
167+
}
168+
`)
169+
}
96170
}
97171

98172
export default buildTypes

0 commit comments

Comments
 (0)