Skip to content

Instantly share code, notes, and snippets.

View segunadebayo's full-sized avatar
😃

Segun Adebayo segunadebayo

😃
View GitHub Profile
@segunadebayo
segunadebayo / badge.ts
Last active August 30, 2022 17:13
test
import {
cssVar,
defineStyle,
defineStyleConfig,
} from "@chakra-ui/styled-system"
import { transparentize } from "@chakra-ui/theme-tools"
const baseStyle = defineStyle({
px: 1,
textTransform: "uppercase",
import { createMachine } from "@ui-machines/core"
import { useMachine } from "@ui-machines/react"
type State = {
value: "idle" | "ticking" | "paused"
}
type Context = {
value: number
laps: number[]
const getAllFocusableElements = (parent) => Array.from(parent.querySelectorAll('*')).filter(elm => elm.tabIndex > -1).sort((a,b) => a.tabIndex > b.tabIndex ? 1 : a.tabIndex < b.tabIndex ? -1 : 0);
@segunadebayo
segunadebayo / use-effect-ref.ts
Created October 6, 2021 11:22
use-effect-ref
import {useRef, useCallback} from 'react';
export type EffectRef<E extends HTMLElement = HTMLElement> = (element: E | null) => void;
export type RefCallback<E extends HTMLElement = HTMLElement> = (element: E) => (() => void) | void;
// eslint-disable-next-line @typescript-eslint/no-empty-function
const noop = () => {};
export function useEffectRef<E extends HTMLElement = HTMLElement>(callback: RefCallback<E>): EffectRef<E> {
@segunadebayo
segunadebayo / ideas.md
Last active October 2, 2021 13:00
Ideas for Static CSS Generation of JSX Style Props
// Button.js => Button.css
import { chakra } from "@chakra-ui/magic";
import "@chakra-ui/css/Button.css";

<chakra.button mb="2" mt="2" _hover={{ bg: "red.200", _focus: {} }} />;

<button css={{mb: "2", mt="2", _hover: { bg: "red.200", _focus: {} }} />

const result = interpret(
@segunadebayo
segunadebayo / results.json
Created June 28, 2021 21:57 — forked from steveruizok/results.json
result of figma api request
{
"document": {
"id": "0:0",
"name": "Document",
"type": "DOCUMENT",
"children": [
{
"id": "0:1",
"name": "Page 1",
"type": "CANVAS",
@segunadebayo
segunadebayo / getComponents.js
Created June 28, 2021 21:52 — forked from steveruizok/getComponents.js
Get components and styles (as full nodes) from a Figma file.
async function getComponents(fileKey, token) {
// Get file
const file = await fetch(`https://api.figma.com/v1/files/${fileKey}`, {
headers: { "X-Figma-Token": token }
}).then((r) => r.json())
if (file.err === undefined) {
// Get style ids
const styleIds = Object.keys(file.styles)
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
const menuMachine = Machine(
{
id: "menu-machine",
initial: "idle",
context: {
activeDescendantId: null,
menuId: "",
buttonId: "",
onSelect: () => {}
},
export interface PaginationOptions {
total: number;
current: number;
noOfSiblings?: number;
}
export function pagination(options: PaginationOptions) {
const { total, noOfSiblings, current } = validate(options);
const max = 2 * noOfSiblings + 5;