Git Product home page Git Product logo

nova.js's People

Contributors

aletid5 avatar alnavarrop99 avatar bryandms avatar dalessandro07 avatar dlcastillop avatar drbarzaga avatar francobuceta avatar josealbdr avatar tedesco8 avatar uvee-dev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

nova.js's Issues

New hook to detect if the device is touch-enabled

Description

Currently, Nova.js lacks a hook to detect whether the device is touch-enabled or not. This could be useful for adapting the user interface or application behavior based on the device type.

Proposed new feature

I propose adding a new hook called useIsTouchDevice to detect if the device is touch-enabled. This hook will utilize standard methods to determine this condition.

Network state hook

React Hook to detect the current network connection status through the online and offline events.

Hook to download a file

Description

I propose creating a hook that allows downloading a file. This hook could provide the error (if there is one), a download indicator and the function that downloads the file, which could receive the url of the file and the name that the file will have once downloaded.

Example

import { useDownloadFile } from './hooks/useDownloadFile'

const App = () => {
  const { error, isDownloading, downloadFile } = useDownloadFile()
  
  const onClickButton = () => {
    downloadFile('react.svg', 'https://www.svgrepo.com/show/452092/react.svg')
  }

  return (
    <div>
      <button disabled={isDownloading} onClick={onClickButton}>
        {isDownloading ? 'Downloading...' : 'Download file'}
      </button>

      {error && <p>Could not download file</p>}
    </div>
  )
}

export default App

If this suggestion is accepted, I would like to implement it. Additionally, I'm open to suggestions and feedback to improve the proposal.

Fix typo on useIsTouchDevice hook

From

setIsTouchDevice(
    'ontouchstart' in window ||
    navigator.maxTouchPoints > 0 ||
    navigator.msMaxTouchPoints > 0
);

to

setIsTouchDevice(
    'ontouchstart' in window ||
    navigator.maxTouchPoints > 0 ||
    navigator.maxTouchPoints > 0
);

Current Color Scheme Hook

Detect changes in the current color preference through Match Media and the classes defined in the root.

Share via navigator hook

Proposed new hook

I propose to add a new hook called useNavigatorShare, to share content (text, url, files) using the navigator.share api. With error validation and in a simpler way.

Content of .ts hook

interface IShareData {
  title: string
  text: string
  url?: string
  files?: File[]
}

const errorMessages: Record<string, string> = {
  NotAllowedError: 'Permiso para compartir denegado.',
  AbortError: 'La acción de compartir fue abortada.',
  NotSupportedError: 'Tu navegador no soporta la función de compartir.',
  TypeError: 'Error al compartir: tipo de dato incorrecto.'
}

function checkPermission (files?: File[]) {
  if (!navigator.canShare) {
    throw new Error('Tu navegador no soporta la función de compartir.')
  }

  if (!navigator.canShare({ files } ?? { files: [new File([], '')] })) {
    throw new Error(`Tu navegador no permite compartir ${files ? 'este tipo de ' : ''} archivos.`)
  }
}

function surroundTryCatch (fn: (data: IShareData) => void | Promise<void>) {
  return async (data: IShareData) => {
    try {
      await fn(data)
    } catch (error: unknown) {
      if ((error as Error).name in errorMessages) {
        const message = `Error al compartir: ${errorMessages[(error as Error).name]}`
        console.error(message)
      } else {
        throw error
      }
    }
  }
}

export const useNavigatorShare = () => {
  async function shareInNavigator (data: IShareData) {
    if (data.files) checkPermission(data.files)

    await navigator.share({
      title: data.title,
      text: data.text ?? '',
      url: data.url ?? '',
      files: data.files ?? []
    })
  }

  return {
    shareInNavigator: surroundTryCatch(shareInNavigator),
  }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.