Skip to content

Instantly share code, notes, and snippets.

View yansusanto's full-sized avatar
:octocat:
Hustling

Yan Susanto yansusanto

:octocat:
Hustling
View GitHub Profile
@yansusanto
yansusanto / bootstrap
Created September 23, 2023 06:45
Bootstrap 5.3 Variables
// Variables
//
// Variables should follow the `$component-state-property-size` formula for
// consistent naming. Ex: $nav-link-disabled-color and $modal-content-box-shadow-xs.
// Color system
// scss-docs-start gray-color-variables
$white: #fff !default;
$gray-100: #f8f9fa !default;
@yansusanto
yansusanto / onScroll
Last active September 10, 2023 08:52
On scroll effect based on the percentage of viewport height
const [inView, setInView] = React.useState(false);
React.useEffect(() => {
const handleScroll = () => {
const scrollThresholdVH = 30;
if (window.scrollY > (window.innerHeight * scrollThresholdVH) / 100) {
setInView(true);
} else {
setInView(false);
const data = [
{
name: 'Cluster 1',
value: 210,
},
{
name: 'Cluster 2',
value: 30,
},
{
const randomString = () => Math.random().toString(36).slice(2);
import React, { Component } from 'react';
import { StyleSheet, View, Animated, Easing, Text, Image, AppState } from 'react-native';
import PropTypes from 'prop-types';
import { RNCamera } from 'react-native-camera';
const defaultRectStyle = { height: 300, width: 300, borderWidth: 0, borderColor: '#000000', marginBottom: 0 };
const defaultCornerStyle = { height: 32, width: 32, borderWidth: 3, borderColor: '#1dbc60' };
const defaultScanBarStyle = { marginHorizontal: 8, borderRadius: 2, backgroundColor: '#1dbc60' };
const defaultHintTextStyle = { color: '#aaa', fontSize: 14, backgroundColor: 'transparent', marginTop: 32 };

Install bootstrap

npm install react-bootstrap bootstrap

Install Sass

npm install node-sass gatsby-plugin-sass

Set up Bootstrap scss

  • Download source files from getbootstrap.com and copy the scss directory to src/scss/bootstrap
  • Configure gatsby-plugin-sass, specifying the bootstrap scss directory created in porevious step:
@yansusanto
yansusanto / ScrollTo()
Last active July 25, 2020 04:15
Smooth scrolling in Vanilla JS
document.querySelectorAll('a[href^="#"]').forEach((anchor) => {
anchor.addEventListener("click", (e) => {
e.preventDefault();
document.querySelector(anchor.getAttribute("href"))
.scrollIntoView({
behavior: "smooth",
block: "start",
});
});
});
@yansusanto
yansusanto / new Date();
Last active July 22, 2020 13:34
Set a date 12 months in the future
const oneYearLater = new Date(
new Date().getFullYear(),
new Date().getMonth() + 12,
new Date().getDate()
);
let launchDate = oneYearLater;
import { useState, useLayoutEffect } from 'react';
export const useWindowWidth = () => {
const [windowWidth, setWindowWidth] = useState(window.innerWidth);
const handleWindowResize = () => {
setWindowWidth(window.innerWidth);
};
useLayoutEffect(() => {