Skip to content

Instantly share code, notes, and snippets.

View horaciosystem's full-sized avatar
🏠
Working from home

Horacio Alexandre Fernandes horaciosystem

🏠
Working from home
View GitHub Profile
const DefaultRenderAnimationOutput = ({name, count}) => {
return (
<>
<span className="RenderAnimation-name">{name} </span>
<span className="RenderAnimation-count">{count}</span>
</>
);
};
function useRenderAnimation(
@horaciosystem
horaciosystem / Table.js
Created June 3, 2022 16:18
Implementation idea for Table components
//Configuration object that can be used to build the table:
const trackRowSchema = [
{
field: 'expand-column',
renderValue: (value) => <Button aria-label="expand-icon"><icon /></Button>,
},
{
field: 'name',
renderValue: (value) => <FancyLabel>{value.name}</FancyLabel>,
},
import clsx from 'clsx';
import { useEffect, useState } from 'react';
import { Input } from 'reakit';
import { BehaviorSubject } from 'rxjs';
import {
debounceTime,
map,
filter,
distinctUntilChanged,
} from 'rxjs/operators';
@horaciosystem
horaciosystem / machine.js
Last active March 30, 2021 18:33
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@horaciosystem
horaciosystem / Layout.js
Last active January 27, 2021 21:32
Sidebar [react, reakit, tailwindcss, postcss, postcss-nested]
import {
useDialogState,
Dialog,
DialogDisclosure,
DialogBackdrop,
} from "reakit/Dialog"
import styles from "./Layout.module.css"
function Layout({ children }) {
const dialog = useDialogState({ animated: true })
import Vue from 'vue'
export function createWatchersForDependentFields({
dependentFields,
form,
vm
}) {
return dependentFields.map(it => {
console.log('watcher for', `form.${it.field}`)
return vm.$watch(
@horaciosystem
horaciosystem / createAsyncAction.js
Created May 2, 2019 14:47
A Vuex helper to generate async actions with same shape and less boilerplate.
export default function createAsyncAction({
key,
methodName,
handler,
initialState = null,
stateUpdater = ({ currentData }) => currentData
}) {
let [setLoading, setError, setData] = [
`${key}SetLoading`,
`${key}SetError`,
@horaciosystem
horaciosystem / flatten.js
Created November 20, 2018 23:41
A Javascript function to flatten the provided array elements into a single array
function flatten(input) {
return input.reduce((acc, current) => {
return acc.concat(Array.isArray(current) ? flatten(current) : current)
}, [])
}
/**
* Tests
import React, { Component, createContext } from "react"
import { differenceBy } from "lodash/fp"
const { Provider, Consumer: MultiSelectConsumer } = createContext({})
export function toggleItemUpdater(item) {
return ({ items: currentStateItems }) => {
const hasItem = currentStateItems.some(it => it.id === item.id)
if (hasItem) {
return { items: currentStateItems.filter(it => it.id !== item.id) }
@horaciosystem
horaciosystem / Grid.js
Last active October 7, 2018 01:54
React Grid component to render a specific amount of lines with cross screen width capability
import { withSize } from "react-sizeme"
import { take } from "lodash/fp"
import styled from "styled-components"
const CONTAINER_SIDE_PADDING = 20
const CONTAINER_TOTAL_PADDING = CONTAINER_SIDE_PADDING * 2
const ListContainer = styled.div`
display: flex;
flex-wrap: ${({ isMultiLine }) => (isMultiLine ? "wrap" : "nowrap")};