Skip to content

Instantly share code, notes, and snippets.

View JoshK2's full-sized avatar
:electron:
Focusing

Josh Kuttler JoshK2

:electron:
Focusing
View GitHub Profile
@JoshK2
JoshK2 / crcl-button.stories.js
Last active October 24, 2019 15:47
Create React typescript components library - button stories file
import React from 'react';
import { action } from '@storybook/addon-actions';
import Button from './';
export default {
title: 'Button',
};
export const text = () => <Button text="Hello Button" onClick={action('clicked')} />;
@JoshK2
JoshK2 / crcl-package2.json
Created September 5, 2019 15:29
Create React typescript components library - package.json after installing storybook
{
"name": "my-own-components-library",
"version": "0.1.0",
"private": false,
"dependencies": {},
"peerDependencies": {
"react": "^16.9.0",
"react-dom": "^16.9.0"
},
"devDependencies": {
@JoshK2
JoshK2 / crcl-stories.js
Last active October 24, 2019 15:38
Create React typescript components library - Storybook - stories file examples
import React from 'react';
import { action } from '@storybook/addon-actions';
import Button from '../src/components/Button';
export default {
title: 'Button',
};
export const text = () => <Button text="Hello Button" onClick={action('clicked')} />;
@JoshK2
JoshK2 / crcl-button.scss
Last active September 5, 2019 13:19
Create React typescript components library - simple button style
button {
width: auto;
height: auto;
padding: 4px 8px;
background-color: white;
border: 2px solid #f9a2b1;
border-radius: 3px;
font-size: 16px;
cursor: pointer;
color: black;
@JoshK2
JoshK2 / crcl-button.tsx
Last active September 28, 2021 08:29
Create React typescript components library - simple button
import React, { Component } from 'react'
import './button.scss'
type State = {}
type Props = {
text?: string,
disable?: boolean,
className?: string,
onClick: Function
}
@JoshK2
JoshK2 / circle-loader.css
Created September 3, 2019 15:23
React spinner example - circle loader style
.lds-circle {
display: inline-block;
margin: 8px;
border-radius: 50%;
animation: lds-circle 2.4s cubic-bezier(0, 0.2, 0.8, 1) infinite;
}
@keyframes lds-circle {
0%, 100% {
animation-timing-function: cubic-bezier(0.5, 0, 1, 0.5);
}
@JoshK2
JoshK2 / circle-spinner.js
Created September 3, 2019 15:18
React spinner example - circle loader
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import './style.css'
export default class Circle extends Component {
render() {
const { color, size } = this.props;
return <div className="lds-circle" style={{ background: color, width: size, height: size }}></div>
}
}
@JoshK2
JoshK2 / react-spinner.js
Last active July 12, 2021 12:09
Using loading animation/react spinner - https://github.com/JoshK2/react-spinners-css
import React, { Component } from 'react';
import Facebook from '@bit/joshk.react-spinners-css.facebook';
class App extends Component {
state = {
data: []
}
componentDidMount(){
setTimeout(() => { this.setState({ data: ['Mercedes', 'Jaguar', 'Volvo', 'BMW'] }) }, 5000);
@JoshK2
JoshK2 / winner-calc.ts
Created May 19, 2019 15:54
Check winner horizontal, vertical and diagonal in 2D array
/**
* @description
* check winner horizontal, vertical and diagonal
* @param {Array.<string[]>} matrix 2d array with X and O
* @param {number} rowsNum number of rows
* @param {number} colsNum number of columns
* @param {number} numToWin the number of matching to win
* @param {number} lastRow the row number of the square player click
* @param {number} lastCol the column number of the square player click
* @returns {string} return the winner, X or O or '' if no one win.
@JoshK2
JoshK2 / have-empty-cell.ts
Created May 19, 2019 15:44
Check if 2d array have an empty cell
/**
* @description
* check if 2d array have an empty cell
* @param {{Array.<string[]>}} matrix 2d array
* @param {number} rowsNum number of rows
* @param {number} colsNum number of columns
* @returns {boolean} return true if empty cell was found, and false if not.
* @example
* import haveEmptyCell from '@bit/joshk.tic-tac-toe-game.utils.have-empty-cell';
*