Skip to content

Instantly share code, notes, and snippets.

View yoavniran's full-sized avatar
📖
Writing. Code & Prose

Yoav Niran yoavniran

📖
Writing. Code & Prose
View GitHub Profile
@yoavniran
yoavniran / chart.css
Created October 12, 2014 06:44
d3 bar chart with rising bars transition
.myChart text {
fill: white;
font: 10px sans-serif;
text-anchor: end;
}
.axis text {
fill: black;
}
@yoavniran
yoavniran / Image.js
Last active September 9, 2019 15:42
utility to generate breakpoints with cloudinary
import {getResponsiveAttributes} from "../getResponsiveAttributes";
const Image = ({publidId}) => {
const transformation = [{
quality: "auto",
fetchFormat: "auto",
dpr: 2,
},];
@yoavniran
yoavniran / RTLMarkdownWidget.js
Created July 25, 2019 10:51
right-to-left markdown widget for netlify-cms
import React from "react";
import NetlifyCmsWidgetMarkdown from "netlify-cms-widget-markdown";
const name = "rtlmarkdown";
const PreviewComponent = NetlifyCmsWidgetMarkdown.previewComponent;
const OrgControlComponent = NetlifyCmsWidgetMarkdown.controlComponent;
const ControlComponent = React.forwardRef((props, ref) => {
return <div dir="rtl">
@yoavniran
yoavniran / gatsby-netlify-form.js
Last active March 2, 2020 21:49
a gatsby-netlify contact form example
import React, { useContext, useState, } from "react";
import { navigate } from "gatsby";
import styled from "styled-components";
import { Box, Button } from "grommet";
import ReCaptcha from "react-google-recaptcha";
import { NotificationContext } from "../Notifications/NotificationProvider";
const isDev = process.env.NODE_ENV === "development";
const onRegisterSuccess = (navUrl) => {
@yoavniran
yoavniran / simple.jsx
Created May 3, 2020 21:34
React-Uploady - Simple
import React from "react";
import Uploady from "@rpldy/uploady";
import UploadButton from "@rpldy/upload-button";
const MyApp = () => (
<Uploady destination={{url: "https://my-server.com/upload"}}>
<UploadButton/>
</Uploady>
);
@yoavniran
yoavniran / node-remove-dir.js
Last active May 13, 2020 15:58
Node async & recursive dir remove
"use strict";
var path = require("path"),
fs = require("fs");
module.exports = (function(){
/**
* recursively remove the fs structure starting from (and including) the path given in dirToRemove
* @param dirToRemove
* the path to remove
@yoavniran
yoavniran / App.jsx
Created May 21, 2020 21:31
React-Uploady preview with progress demo - app.jsx
import Uploady from "@rpldy/uploady";
import UploadWithProgressPreview from "./UploadWithProgressPreview";
const App = > () {
return (
<Uploady
destination={{ url: "[upload-url]" }}
>
<div className="App">
<h1>Hello React Uploady</h1>
@yoavniran
yoavniran / UploadWithProgressPreview.jsx
Created May 21, 2020 21:35
React-Uploady preview with progress demo - UploadWithProgressPreview.jsx
import UploadButton from "@rpldy/upload-button";
import UploadPreview from "@rpldy/upload-preview";
import CustomImagePreview from "./CustomImagePreview";
const UploadWithProgressPreview = () => {
const getPreviewProps = useCallback(item => ({ id: item.id }), []);
return (
<>
<UploadButton>Upload Files</UploadButton>
@yoavniran
yoavniran / customHookTestHelper.js
Last active June 3, 2020 12:54
helper to test custom hook (especially if it's using useEffect) with React, Jest & Enzyme
import React from "react";
import { isFunction } from "lodash";
import { mount } from "enzyme";
export default (hook, props) => {
let wrapper, hookResult, hookParams, error;
if (isFunction(props)) {
hookParams = props;
props = {};
@yoavniran
yoavniran / UploadWithCrop.jsx
Last active July 8, 2020 15:54
UploadWithCrop.jsx - react-uploady demo
import Uploady from "@rpldy/uploady";
import UploadButton from "@rpldy/upload-button";
import UploadPreview from "@rpldy/upload-preview";
export default function UploadWithCrop() {
const previewMethodsRef = useRef();
return (
<Uploady
destination={{ url: "[upload-url]" }}