Skip to content

Instantly share code, notes, and snippets.

node_modules/
  @myapp/
    buttons/index.js <-- final button with all components, even if you're using only 1 of them
    icons/index.js <-- final bundle with all icons, even the ones you're not using
@willmendesneto
willmendesneto / download-file-sync.js
Last active April 9, 2021 04:46
Dowload file sync. Alternative option for `window.open`, but running download file in sync
/**
* Usage
* downloadFileSync('file-url', {name: 'filename', iframeName: 'my-amazing-iframe-name' })
*/
const downloadFileSync = (
url: string,
filename?: string;
) => {
const iframeName = options?.iframeName ?? 'reusable-iframe';
const link = document.createElement('a');
@willmendesneto
willmendesneto / css-in-js-breakpoints.js
Created March 20, 2021 05:45
Helper for CSS-In-JS Media Query integration on Components
/**
* Helper for CSS-In-JS Media Query integration on Components
*
* Usage:
* // It's using `styled-components` package, but it can be used in any CSS-IN-JS package solution
*
* import styled from 'styled-components';
*.
*. const MyDiv = styled.div`
display: inline-block;
@willmendesneto
willmendesneto / lambda-function.js
Last active October 31, 2020 04:44
AWS Lambda Recursive HTTP File Upload using NodeJS
const aws = require('aws-sdk');
const { writeFileSync, statSync, createReadStream } = require('fs');
const fetch = require('node-fetch');
const FormData = require('form-data');
exports.handler = async (event, context) => {
const { numberOfCalls = 0, url } = event;
const lambda = new aws.Lambda();
@willmendesneto
willmendesneto / dark-mode-via-css-media-query-classes-and-scheme-listener-and-event-listener-optimized-by-devicevia-javascript.js
Created July 5, 2020 20:27
dark-mode via css media query classes and scheme listener and event listener optimized by device via javascript
function toggleSiteTheme(e) {
const html = document.getElementsByTagName("html");
const className = html[0].classList.value;
/** Gets the target by checking if it was triggered by clicking on the switch or if via OS configuration changes */
const target =
e && e.target ? e.target : document.getElementById("theme-switch");
const isLightMode = target.className === "" || className === "light-mode";
@willmendesneto
willmendesneto / dark-mode-via-css-media-query-classes-and-scheme-listener-via-javascript.js
Last active July 5, 2020 20:21
dark-mode via css media query classes and scheme listener via javascript
function toggleSiteTheme(e) {
var html = document.getElementsByTagName("html");
var className = html[0].classList.value;
/** Gets the target by checking if it was triggered by
clicking on the switch or if via OS configuration changes */
var target = document.getElementById("theme-switch");
var isLightMode = target.className === "" || className === "light-mode";
/** Adds the class into our HTML to determine if it will be light or dark mode */
@willmendesneto
willmendesneto / dark-mode-via-css-media-query-and-classes-via-javascript.js
Last active July 5, 2020 20:21
dark-mode via css media query and classes via javascript
function toggleSiteTheme(e) {
var html = document.getElementsByTagName("html");
var className = html[0].classList.value;
/** Gets the target by checking if it was triggered by
clicking on the switch or if via OS configuration changes */
var target = document.getElementById("theme-switch");
var isLightMode = target.className === "" || className === "light-mode";
/** Adds the class into our HTML to determine if it will be light or dark mode */
<!-- Adding dark-mode switch toggle in your page -->
<div class="switch-toggle">
<input type="checkbox" id="switch-checkbox" />
<label for="switch" id="theme-switch"
>Enable/disable Dark Mode Theme</label
>
</div>
@willmendesneto
willmendesneto / dark-mode-via-css-media-query-and-classes-via-javascript.css
Last active July 5, 2020 19:57
dark-mode via css media query and classes via javascript
/** Common CSS */
html {
background: #FFFFFF;
}
html.dark-mode {
filter: invert(100%);
}
@willmendesneto
willmendesneto / dark-mode-via-css-media-query.css
Last active July 5, 2020 18:55
dark-mode via css media query
html {
background: #FFFFFF;
}
// Detect if the user has requested the system
// use a light or dark color theme.
// More details about `prefers-color-scheme` in https://web.dev/prefers-color-scheme/
@media (prefers-color-scheme: "dark") {
html {
filter: invert(100%);