Skip to content

Instantly share code, notes, and snippets.

View fResult's full-sized avatar

Sila Setthakan-anan fResult

View GitHub Profile
@fResult
fResult / index.html
Last active July 28, 2020 11:19
CSS Positioning
<!DOCTYPE html>
<html>
<head>
<style>
body {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
@fResult
fResult / UploadFile.js
Last active October 3, 2020 11:53
FileUpload page
import React from 'react';
import { CancelToken } from 'axios'
const FileUpload = () => {
const [fileList, setFileList] = useState([]) // List of File instance
const [sizeAmount, setSizeAmount] = useState('') // sum files size (such as '444.44 MB' or '2.15 GB')
const [uploadedSize, setUploadedSize] = useState('') // sum uploaded (such as '444.44 MB' or '2.15 GB')
const [fileCount, setFileCount] = useState(0)
const [progress, setProgress] = useState(0) // sum uploaded (percent)
const [prevLoaded, setPrevLoaded] = useState(0) // previous progressEvent.loaded
import { useState, useEffect, useCallback } from 'react'
export default (asyncFunction, immediate = true) => {
const [isLoading, setIsLoading] = useState(false)
const [value, setValue] = useState(null)
const [error, setError] = useState(null)
const execute = useCallback(
async (params = {}, config = {}) => {
setIsLoading(true)
import axios from 'axios'
export default axios.create({
baseURL: 'http://localhost:3002',
headers: { 'Content-Type': 'application/json' }
})
import axios from './Axios'
export const uploadFiles = async (params = {}, config = {}) => {
return await axios.post('/upload', params, config)
}
@fResult
fResult / package.json
Last active January 14, 2021 06:55
Use craco instead react-scripts
{
/* ตัด code บางส่วนออก เพื่อความกระชับ */
"scripts": {
"start": "craco start",
"build": "craco build",
"test": "craco test",
"eject": "react-scripts eject"
},
/* ตัด code บางส่วนออก เพื่อความกระชับ */
}
@fResult
fResult / craco.config.js
Last active January 14, 2021 08:23
Create craco.config.js and config postcss
const tailwind = require('tailwindcss')
const postcss = require('autoprefixer')
module.exports = {
style: {
postcss: {
plugins: [tailwind(), postcss()]
}
}
}
@fResult
fResult / tailwind.config.js
Created January 14, 2021 09:08
Config Darkmode for TailwindCSS
module.exports = {
purge: ['./src/**/*.{js,jsx,ts,tsx}', './public/index.html'],
darkMode: 'class',
theme: {
extend: {
colors: {
dark: {
elem: '#2B3945',
bg: '#202C37',
text: '#FFFFFF'
@fResult
fResult / src\ThemeProvider.tsx
Created January 14, 2021 10:23
Create ThemeContext provider in `src` folder
import React, { useState, useEffect } from 'react'
function getInitialTheme(): string {
if (typeof window !== 'undefined' && window.localStorage) {
const storedPrefs = window.localStorage.getItem('theme')
if (typeof storedPrefs === 'string') {
return storedPrefs
}
const userMedia = window.matchMedia('(prefers-color-scheme: dark)')
@fResult
fResult / src\App.tsx
Created January 14, 2021 11:23
Change your code in App.tsx file
import React, { useContext } from 'react';
import './App.css';
import { ThemeContext } from './ThemeProvider';
function App() {
const { theme, setTheme } = useContext(ThemeContext)
const isDark = theme === 'dark'
return (
<div className="bg-light-bg dark:bg-dark-bg text-light-text dark:text-dark-text h-screen flex flex-col justify-center items-center">