Skip to content

Commit

Permalink
Stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Raathigesh committed Nov 11, 2018
1 parent bc7068a commit 3a64852
Show file tree
Hide file tree
Showing 10 changed files with 296 additions and 99 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,26 @@ Retoggle is a dev utility for your demos, presentations and debugging use-cases
- 🎨 Themeable components
- 🎁 Extensible. Write your custom toggles.

### Show me ths code

```javascript
import React, { useState } from "react";
import { Inspector, useLog } from "retoggle";

export default function Demo() {
const [state, setState] = useState({ value: 5 });

// logs your state to inspector
useLog("My state", state);

return (
<div>
<Inspector />
</div>
);
}
```

### Avilable knobs

- 📝 `useLog()` - Keeps track of a variable value
Expand Down
Binary file added docs/Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
112 changes: 112 additions & 0 deletions docs/customKnob.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
---
name: Writting a Custom Knob
menu: Knobs
---
import {useState} from "react";
import { Playground } from "docz";
import useChartKnob from "../example/custom-chart-knob";

### Writting a custom Knob
Retoggle allows you to add your own knows to the Inspector with a simple API.

- A component to render in the inspector panel
- A custom hook to manage state

### The API

```javascript
import { setKnob, removeKnob, addKnobRenderer } from "retoggle";
```

- `addKnobRenderer(type, Component)` - Registers a knob renderer with the store.
- `type`: Knob type. This is a string. Should be unqiue.
- `Component`: The component constructor.

- `setKnob(props)` - You would call this method to update your knob. The following are required props.
- `name`: The name of your knob.
- `type`: Type of the knob.

- `removeKnob(name)` - You would call this method remove your knob from the inspector.
- `name`: The name of your knob.


### A walkthough of the custom knob sample

This example knob implementation can be found in [src/example/custom-chart-knob](https://github.com/Raathigesh/storyhooks/blob/master/src/example/custom-chart-knob/index.ts).

#### The Component of the Knob
The props of this components are passed by your from your custom hook

```javascript
import React from "react";
import styled from "styled-components";
import { Activity } from "react-feather";
import { Sparklines, SparklinesLine, SparklinesSpots } from "react-sparklines";
import { KnobFrame } from "retoggle";

const Container = styled.div`
display: flex;
width: 100%;
margin-top: 5px;
svg {
width: 100%;
height: 50px;
}
`;

export default function Chart({ data }) {
return (
<KnobFrame
label="This is a custom knob"
direction="column"
icon={<Activity size={11} />}
>
<Container>
<Sparklines data={data} limit={20}>
<SparklinesLine color="#1c8cdc" />
<SparklinesSpots />
</Sparklines>
</Container>
</KnobFrame>
);
}

```

#### The custom hook
```javascript
import { useState, useEffect } from "react";
import { setKnob, removeKnob, addKnobRenderer } from "retoggle";
import Component from "./component";

const KnobType = "chart";
addKnobRenderer(KnobType, Component);

export default function useChartKnob(name: string, value: any) {
const [data, setData] = useState([]);

useEffect(
() => {
const randomNumber = Math.floor(Math.random() * 6) + 1;
setData([...data, randomNumber]);

setKnob({
name,
type: KnobType,
data
});
},
[value]
);

useEffect(() => {
return () => removeKnob(name);
}, []);
}

```




64 changes: 64 additions & 0 deletions docs/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
name: Getting started
route: /
---
import {Playground} from 'docz';
import image from './Retoggle.png'
import App from '../src/example/app.tsx';

## Retoggle
<Playground>
{() => {
return <App />
}}
</Playground>

[![Build Status](https://travis-ci.org/Raathigesh/storyhooks.svg?branch=master)](https://travis-ci.org/Raathigesh/storyhooks)

Retoggle is a dev utility for your demos, presentations and debugging use-cases inspired by [ideas from Dan Abramov](https://twitter.com/dan_abramov/status/1058834904207761409).

- 🎉 A wide range of toggles
- 💡 Frictionless integration
- 🎨 Themeable components
- 🎁 Extensible. Write your custom toggles.

### Take it for a spin



### Avilable knobs

- 📝 `useLog()` - Keeps track of a variable value
- 🅰 `useTextKnob()` - Shows a text box
- 1️⃣ `useNumberKnob()` - Shows a number box
- ✅️ `useBooleanKnob()` - Shows a check box
- 🎚 `useRangeKnob()` - Shows a slider
- 🎛 `useRangesKnob()` - Shows multiple sliders
- 🎏 `useSelectKnob()` - Shows a select box
-`useObjectKnob()` - Shows an object editor
- 🎨 `useColorKnob()` - Shows a color picker
-`useTimemachine()` - Shows a slider and tracks the state of a given variable and allows to travel back in time

#### 📚 [API Docs with live preview available here.](https://storyhooks.debuggable.io)



## Contribute

### Preparing dev environment

- `yarn install` to install dev dependencies

### Running and building the library

- `yarn start` will start the dev server and expose the sample app
- `yarn build` will output the build artifact to `./lib` folder

### Docs

- `docz:dev` will start the docz developement server
- `docz:build` will build the docs

## License

MIT
32 changes: 32 additions & 0 deletions docs/useBooleanKnob.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
name: useBooleanKnob
menu: Knobs
---
import {useState} from "react";
import { Playground } from "docz";
import { Inspector, useBooleanKnob } from "../src/lib";

### useBooleanKnob(label, value)

A color picker which let you pic a color

- `label` - A label for the color picker
- `value` - A boolean value as initial value


#### Usage
```javascript
import { useBooleanKnob } from "retoggle";
```
<Playground>
{() => {
const [value, setValue] = useBooleanKnob("Boolean", true);

return (
<React.Fragment>
<Inspector usePortal={false} />
{value.toString()}
</React.Fragment>
)
}}
</Playground>
2 changes: 1 addition & 1 deletion doczrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default {
},
logo: {
src:
"https://raw.githubusercontent.com/Raathigesh/storyhooks/master/docs/Retoggle.png",
"https://raw.githubusercontent.com/Raathigesh/storyhooks/master/docs/Logo.png",
width: 200
},
styles: {
Expand Down
25 changes: 13 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,21 @@
"not op_mini all"
],
"devDependencies": {
"@smooth-ui/core-sc": "^7.0.4",
"@types/styled-components": "^4.0.3",
"babel-jest": "^23.6.0",
"react-color": "^2.14.1",
"react-compound-slider": "^0.16.2",
"react-feather": "^1.1.4",
"react-json-view": "^1.19.1",
"react-kawaii": "^0.6.0",
"react-popper": "^1.3.0",
"react-sparklines": "^1.7.0",
"styled-components": "^4.0.3",
"typeface-nunito": "^0.0.54",
"@babel/core": "^7.1.2",
"@babel/plugin-proposal-class-properties": "^7.1.0",
"@babel/plugin-proposal-decorators": "^7.1.2",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0",
"@babel/preset-env": "^7.1.0",
"@babel/preset-react": "^7.0.0",
"@babel/preset-typescript": "^7.1.0",
"@smooth-ui/core-sc": "^7.0.4",
"@types/jest": "^23.3.9",
"@types/react": "^16.4.18",
"@types/react-dom": "^16.0.9",
"@types/styled-components": "^4.0.3",
"@types/webpack": "^4.4.17",
"babel-core": "7.0.0-bridge.0",
"babel-jest": "^23.6.0",
"babel-loader": "^8.0.4",
"babel-plugin-external-helpers": "^6.22.0",
"babel-preset-env": "^1.7.0",
Expand All @@ -52,14 +43,24 @@
"cross-env": "^5.2.0",
"css-loader": "^1.0.1",
"docz": "^0.12.9",
"file-loader": "^2.0.0",
"html-webpack-plugin": "^3.2.0",
"html-webpack-template": "^6.2.0",
"jest": "^23.6.0",
"react": "^16.7.0-alpha.0",
"react-color": "^2.14.1",
"react-compound-slider": "^0.16.2",
"react-dom": "16.7.0-alpha.0",
"react-feather": "^1.1.4",
"react-json-view": "^1.19.1",
"react-kawaii": "^0.6.0",
"react-popper": "^1.3.0",
"react-sparklines": "^1.7.0",
"react-testing-library": "^5.2.3",
"rimraf": "^2.6.2",
"style-loader": "^0.23.1",
"styled-components": "^4.0.3",
"typeface-nunito": "^0.0.54",
"typescript": "^3.1.6",
"url-loader": "^1.1.2",
"webpack": "^4.24.0",
Expand Down
60 changes: 53 additions & 7 deletions src/example/app.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,66 @@
import React from "react";
import styled from "styled-components";
import { Inspector } from "../lib";
import Icon from "./icon";
import { Ghost } from "react-kawaii";
import {
Inspector,
useLog,
useBooleanKnob,
useNumberKnob,
useRangeKnob,
useSelectKnob,
useTimemachine,
useColorKnob,
useObjectKnob
} from "../lib";
import useChartKnob from "./custom-chart-knob";

const Container = styled.div`
background-color: #3356d0;
flex-direction: column;
display: flex;
justify-content: center;
padding: 15px;
margin: 5px;
border-radius: 5px;
width: 400px;
height: 400px;
align-items: center;
height: 97vh;
justify-content: center;
box-shadow: rgba(195, 22, 22, 0.03) 0px 0px 5px,
rgba(63, 81, 181, 0.55) 10px 13px 47px;
`;

export default function App() {
export default function Icon() {
const [visibility] = useBooleanKnob("Icon Visibility", true);

useLog("Visibility", {
visibility
});

const [borderWidth] = useNumberKnob("Border Width");
const [rangeKnobValue] = useRangeKnob("Ghost Size", {
initialValue: 240,
min: 0,
max: 500
});
const [mood] = useSelectKnob(
"Mood",
["sad", "shocked", "happy", "blissful", "lovestruck", "excited"],
"blissful"
);
const [colorValue] = useColorKnob("Color", "wheat");
const [obj, setObj] = useObjectKnob("Object", {});
const timemachineValue = useTimemachine("Textbox timemachine", colorValue);
useChartKnob("Chart", timemachineValue);

return (
<Container>
<Container
style={{ borderWidth, borderStyle: "solid", borderColor: "white" }}
>
<Inspector />
<Icon />
{visibility && (
<Ghost size={rangeKnobValue} mood={mood} color={timemachineValue} />
)}
</Container>
);
}
2 changes: 1 addition & 1 deletion src/example/custom-chart-knob/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Component from "./component";

addKnobRenderer("chart", Component);

export default function useChartKnob(name, value) {
export default function useChartKnob(name: string, value: any) {
const [data, setData] = useState([]);

useEffect(
Expand Down
Loading

0 comments on commit 3a64852

Please sign in to comment.