Socket
Book a DemoInstallSign in
Socket

kubefont

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kubefont

A React + Three.js component showing text and cubes

latest
Source
npmnpm
Version
0.1.1
Version published
Maintainers
1
Created
Source

Kubefont

Example image

A simple React component (written in Typescript) using Three.js to show a text and a number of random-positioned cubes. It exploits the normal hover event to move the camera while on desktop, and the gyroscope on mobile devices.

This is an experiment I made to test the integration between React and Three.js. It is not remotely tested enough or fit for a production environment.

Live example here!

Usage

Install the component using your favourite package manager:

# npm
npm install kubefont

# yarn
yarn add kubefont

Then use it as simple as:

import React from 'react';
import Kubefont from 'kubefont';

const App = () => (
  <div style={{ width: '100vw', height: '100vh' }}>
    <Kubefont text="Hello World" textFontUrl="/font.json" />
  </div>
);

The textFontUrl prop takes the path to your JSON font. This font must be served as a static file from your app. To create a JSON font you can use Facetype.js.

This component takes the same size of its parent container.

API

These are the props accepted by the Kubefont component:

Prop nameTypeDescriptionRequiredDefault
textStringThe string to displayYes-
textFontUrlStringThe path to the JSON font file (served statically from the webserver)Yes-
textColorStringThe text color in HEXNo"#dddddd"
cameraDistanceNumberThe text distance from the cameraNo400
cubesColorStringThe cubes color in HEXNo"#dddddd"
particlesNumberNumberThe number of cubes to displayNo50
scatteringNumberThe cubes' scattering levelNo1.5
backgroundColorStringThe environment background color in HEXNo"#000000"
useGyroscopeBooleanWhether to use the gyroscope or the hover eventNofalse
GyroscopeRequestComponentFunctionTakes a function as a parameter and return a new React node (see below)No-

Gyroscope

To use the gyroscope you HAVE to set this prop!

This component supports the DeviceOrientationEvent (W3C Documentation). In iOS13 you have to ask for permission to use the gyroscope and this permission must be granted "manually" (E.g. from a onClick event) from the user. To handle this particular case this component supports the GyroscopeRequestComponent prop, which takes a function as the only parameter and return a new React node. This new React node will be added over the Three.js canvas (you can even position it absolute) and triggering the passed function from there will try to obtain the permission.

import React from 'react';
import Kubefont from 'kubefont';

const App = () => (
  <div style={{ width: '100vw', height: '100vh' }}>
    <Kubefont
      text="Hello World"
      textFontUrl="/font.json"
      useGyroscope={true}
      GyroscopeRequestComponent={request => (
        <a onClick={request} style={{ color: '#ffffff' }}>
          Enable Gyroscope
        </a>
      )}
    />
  </div>
);

Keywords

react

FAQs

Package last updated on 22 Feb 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts