83d8035dc2
* root + server * frontend * frontend-2 * dui3 * dui3 * tailwind theme * ui-components * preview service * viewer * viewer-sandbox * fileimport-service * webhook service * objectloader * shared * ui-components-nuxt * WIP full config * WIP full linter * eslint projectwide util * minor fix * removing redundant ci * clean up test errors * fixed prettier formatting * CI improvements * TSC lint fix * 'buildBatch' needs to be async since some batch types (like Text) require it. Removed a disabled liniting rule from ObjLoader * removed unnecessary void --------- Co-authored-by: AlexandruPopovici <alexandrupopoviciioan@gmail.com>
52 lines
1.7 KiB
TypeScript
52 lines
1.7 KiB
TypeScript
import { ensureError } from '@speckle/shared'
|
|
import { useClipboard as coreUseClipboard, useBreakpoints } from '@vueuse/core'
|
|
import { ToastNotificationType, useGlobalToast } from '~~/lib/common/composables/toast'
|
|
import { TailwindBreakpoints } from '~~/lib/common/helpers/tailwind'
|
|
/**
|
|
* A wrapper over vueuse's useClipboard that also triggers toast notifications
|
|
*/
|
|
export const useClipboard = () => {
|
|
// non-legacy doesn't seem to work in dev environments
|
|
const { copy } = coreUseClipboard({ legacy: true })
|
|
const { triggerNotification } = useGlobalToast()
|
|
|
|
return {
|
|
copy: async (
|
|
text: string,
|
|
options?: Partial<{
|
|
successMessage?: string
|
|
failureMessage?: string
|
|
}>
|
|
) => {
|
|
const successMessage = options?.successMessage || 'Value copied to clipboard'
|
|
const failureMessage =
|
|
options?.failureMessage || 'Failed to copy value to clipboard'
|
|
|
|
try {
|
|
await copy(text)
|
|
triggerNotification({
|
|
type: ToastNotificationType.Info,
|
|
title: successMessage
|
|
})
|
|
} catch (e) {
|
|
triggerNotification({
|
|
type: ToastNotificationType.Danger,
|
|
title: failureMessage,
|
|
description: ensureError(e).message
|
|
})
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
export const useIsSmallerOrEqualThanBreakpoint = () => {
|
|
const breakpoints = useBreakpoints(TailwindBreakpoints)
|
|
return {
|
|
isSmallerOrEqualSm: breakpoints.smallerOrEqual('sm'),
|
|
isSmallerOrEqualMd: breakpoints.smallerOrEqual('md'),
|
|
isSmallerOrEqualLg: breakpoints.smallerOrEqual('lg'),
|
|
isSmallerOrEqualXl: breakpoints.smallerOrEqual('xl'),
|
|
isSmallerOrEqual2xl: breakpoints.smallerOrEqual('2xl')
|
|
}
|
|
}
|