All Projects → Jesperpaulsen → sanity-mobile-preview

Jesperpaulsen / sanity-mobile-preview

Licence: MIT license
An NPM package written in React used to preview mobile devices. Especially helpful when used in combination with a CMS like sanity.

Programming Languages

typescript
32286 projects
CSS
56736 projects
HTML
75241 projects

Projects that are alternatives of or similar to sanity-mobile-preview

ck-env
CK repository with components and automation actions to enable portable workflows across diverse platforms including Linux, Windows, MacOS and Android. It includes software detection plugins and meta packages (code, data sets, models, scripts, etc) with the possibility of multiple versions to co-exist in a user or system environment:
Stars: ✭ 67 (+252.63%)
Mutual labels:  mobile-devices
sneyder.dev
📌 My personal website.
Stars: ✭ 26 (+36.84%)
Mutual labels:  sanity
sanity-portfolio-studio
A Sanity.io instance that powers a Gatsby portfolio site. Watch it get built live:
Stars: ✭ 14 (-26.32%)
Mutual labels:  sanity
sanity-template-commercelayer
A multi-country ecommerce template built with Commerce Layer, Next.js, Sanity studio, and deployed to Netlify.
Stars: ✭ 76 (+300%)
Mutual labels:  sanity-studio
ck-crowd-scenarios
Public scenarios to crowdsource experiments (such as DNN crowd-benchmarking and crowd-tuning) using Collective Knowledge Framework across diverse mobile devices provided by volunteers. Results are continuously aggregated at the open repository of knowledge:
Stars: ✭ 22 (+15.79%)
Mutual labels:  mobile-devices
snio.dev
The source code of my personal portfolio available on: https://snio.dev.
Stars: ✭ 35 (+84.21%)
Mutual labels:  sanity-studio
crowdsource-experiments-using-android-devices
Android application to participate in experiment crowdsourcing (such as workload crowd-benchmarking and crowd-tuning) using Collective Knowledge Framework and open repositories of knowledge:
Stars: ✭ 23 (+21.05%)
Mutual labels:  mobile-devices
sanity-linq
Strongly-typed .Net Client for Sanity
Stars: ✭ 36 (+89.47%)
Mutual labels:  sanity
React-Commenting-System
Commenting System built with NextJS and Sanity
Stars: ✭ 28 (+47.37%)
Mutual labels:  sanity
startup-starter-kit
The Structured Content Startup Starter Kit
Stars: ✭ 42 (+121.05%)
Mutual labels:  sanity
exo
EXO, the empathy-first framework for an accessible world.
Stars: ✭ 75 (+294.74%)
Mutual labels:  sanity
how-to-css
howtocss.dev
Stars: ✭ 48 (+152.63%)
Mutual labels:  sanity
svelte-portable-text
Svelte component for rendering block content
Stars: ✭ 30 (+57.89%)
Mutual labels:  sanity
crowdsource-video-experiments-on-android
Crowdsourcing video experiments (such as collaborative benchmarking and optimization of DNN algorithms) using Collective Knowledge Framework across diverse Android devices provided by volunteers. Results are continuously aggregated in the open repository:
Stars: ✭ 29 (+52.63%)
Mutual labels:  mobile-devices
sanity-super-pane
The Sanity Desk Tool Pane with Super Powers
Stars: ✭ 90 (+373.68%)
Mutual labels:  sanity-studio
pytorch-peleenet
PeleeNet in PyTorch
Stars: ✭ 37 (+94.74%)
Mutual labels:  mobile-devices
sanity-blocks-vue-component
Vue component for rendering block content from Sanity
Stars: ✭ 67 (+252.63%)
Mutual labels:  sanity
nuxt-sanity
Easily integrate Sanity in your Nuxt.js project.
Stars: ✭ 14 (-26.32%)
Mutual labels:  sanity
sanity-codegen
Generate TypeScript types from your Sanity.io schemas
Stars: ✭ 181 (+852.63%)
Mutual labels:  sanity
sanity-gatsby-portfolio
A Gatsby portfolio site powered by Sanity.io. Watch it get built live:
Stars: ✭ 16 (-15.79%)
Mutual labels:  sanity

sanity-mobile-preview

An NPM package written in React used to preview mobile devices. Especially helpful when used in combination with a CMS like sanity.

NPM JavaScript Style Guide

DEMO

Demo picture

Install

npm install --save sanity-mobile-preview

Usage

import SanityMobilePreview from 'sanity-mobile-preview'
import 'sanity-mobile-preview/dist/index.css?raw'

const Example = () => {
  return <SanityMobilePreview />
}

How to set up preview with Sanity

In order to set up mobile preview with Sanity, you first need to create a new view.

For simplicity, we will copy the predefined preview from IframePreview.js to a file called IframeMobilePreview.js

Add imports:

import SanityMobilePreview from 'sanity-mobile-preview'
import 'sanity-mobile-preview/dist/index.css?raw'

At line 47, replace

return (
  <div className={styles.componentWrapper}>
    <div className={styles.iframeContainer}>
      <iframe src={url} frameBorder={'0'} />
    </div>
  </div>
)

with

return (
  <div className={styles.componentWrapper}>
    <SanityMobilePreview>
      <div className={styles.iframeContainer}>
        <iframe src={url} frameBorder={'0'} />
      </div>
    </SanityMobilePreview>
  </div>
)

Then go to deskStructure.js.

Under getDefaultDocumentNode add the next snippet to the Schemes you want to add mobile preview to:

    S.view
        .component(IframeMobilePreview)
        .title('Mobile preview')
        .options({previewURL})
    ])

You should now be able to preview your website with a mobile view.

Customization

The SanityMobilePreview takes five optional arguments:

Argument Values Default
allowedDevices An array of MobileDevices. This will be the devices that are selectable in the dropdown menu. All devices
preSelectedDevice A MobileDevice. The default device to be selected. 'iphone-x'
preSelectedColor A device color. The default device color to selected. 'black
showMenu A boolean. Controls the visibility of the dropdowns. true
preSelectedLandscape A boolean. The default orientation of the devices false

If you have specified a preSelectedDevice that is not specified in allowedDevices, it will default to the first device in allowedDevices.

If you have specified a preSelectedColor that is not applicable to the preSelectedDevice, the preSelectedColor will default to black.

Example

This example will load a silver iPad mini as default, and only allows iPhone X and iPad to be selected:

const App = () => {
  return (
    <MobileDevicePreview
      preSelectedDevice={'ipad'}
      preSelectedColor={'silver'}
      allowedDevices={['ipad', 'iphone-x']}
    >
      <div> This is a demo 🤠</div>
    </MobileDevicePreview>
  )
}

Types

MobileDevices = 'iphone-x' | 'note8' | 'iphone8' | 'iphone8plus' | 'iphone5s' | 'ipad' | 'nexus5'

MobileDeviceColors = 'silver' | 'black' | 'gold'

Devices

The different devices are:

DeviceId Readable name Colors
iphone-x iPhone X black
note8 Note 8 black
iphone8 iPhone 8 black, silver, gold
iphone8plus iPhone 8 Plus black, silver, gold
iphone5s iPhone 5s black, silver, gold
ipad iPad mini black, silver
nexus5 Nexus 5 black

Credit

Marvel Devices
create-react-library

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].