matthewhudson / current-device

📱 The easiest way to write conditional CSS and/or JavaScript based on device operating system (iOS, Android, Blackberry, Windows, Firefox OS, MeeGo), orientation (Portrait vs. Landscape), and type (Tablet vs. Mobile).
https://matthewhudson.github.io/current-device/
MIT License
3.95k stars 586 forks source link

Typescript #181

Closed PeterKottas closed 5 years ago

PeterKottas commented 5 years ago

I needed typescript def for my project so I created them. No rocket science but it might save somebody 15 minutes to copy it from the docs.

declare module 'current-device' {
  import * as React from 'react';
  export interface CurrentDeviceInterface {
    mobile: () => boolean;
    tablet: () => boolean;
    desktop: () => boolean;
    ios: () => boolean;
    ipad: () => boolean;
    iphone: () => boolean;
    ipod: () => boolean;
    android: () => boolean;
    androidPhone: () => boolean;
    androidTablet: () => boolean;
    blackberry: () => boolean;
    blackberryPhone: () => boolean;
    blackberryTablet: () => boolean;
    windows: () => boolean;
    windowsPhone: () => boolean;
    windowsTablet: () => boolean;
    fxos: () => boolean;
    fxosPhone: () => boolean;
    fxosTablet: () => boolean;
    meego: () => boolean;
    television: () => boolean;

    // Orientation
    landscape: () => boolean;
    portrait: () => boolean;
    onChangeOrientation: (newOrientation: DeviceOrientation) => void;

    // Utility
    noConflict: (currentDevice: CurrentDeviceInterface) => void;

    // Properties
    type: DeviceType;
    orientation: DeviceOrientation;
    os: DeviceOs;
  }

  export type DeviceType = 'mobile' | 'tablet' | 'desktop' | 'unknown';
  export type DeviceOrientation = 'landscape' | 'portrait' | 'unknown';
  export type DeviceOs =
    | 'ios'
    | 'iphone'
    | 'ipad'
    | 'ipod'
    | 'android'
    | 'blackberry'
    | 'windows'
    | 'fxos'
    | 'meego'
    | 'television'
    | 'unknown';

  let instance: CurrentDeviceInterface;
  export default instance;
}

P.s.: Feel free to add these to the lib, I just didn't have time to do a proper PR. (Sometimes people are reluctant to add it to the lib anyways so this felt like best way to share)

matthewhudson commented 5 years ago

Thanks @PeterKottas! I don't have much TypeScript experience, so even a rough PR in need of cleanup would be much appreciated.

LeeKatz1 commented 5 years ago

Hi @matthewhudson , I opened a PR for this issue with @PeterKottas 's typescript definition file . https://github.com/matthewhudson/current-device/pull/204