This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
type Item struct { | |
Name string | |
Price float64 | |
discount float64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
```go | |
package main | |
import ( | |
"fmt" | |
) | |
type Item struct { | |
Name string | |
Price float64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
void swap(int * array, int index1, int index2) { | |
int temp = array[index1]; | |
array[index1] = array[index2]; | |
array[index2] = temp; | |
} | |
bool willMoveNext(int number, int nextNumber) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"extends": [ | |
"next", | |
"eslint:recommended", | |
"next/core-web-vitals", | |
"eslint:recommended", | |
"plugin:@typescript-eslint/recommended", | |
"plugin:prettier/recommended" | |
], | |
"parser": "@typescript-eslint/parser", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import {useSetThemeRelatedToSystem } | |
export default App = () => { | |
const {theme} = useSetThemeRelatedToSystem(); | |
return <div> {theme ? theme : "getting system theme" } </div> | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const setThemeRelatedToSystem = () => { | |
// ... rest of the function's code | |
} | |
// Plain JS | |
document.addEventListener("DOMContentLoad", () => { | |
setThemeRelatedToSystem(); | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const watchSystemTheme = (cb) => { // I will use callback for that | |
// Addlistener to matchmedia for light and dark mode | |
window.matchMedia("(prefers-color-scheme: dark)").addListener(e => { | |
e.matches && cb("dark"); // If it is dark we called the defined callback with dark argument | |
}) | |
window.matchMedia("(prefers-color-scheme: light)").addListener(e => { | |
e.matches && cb("light"); // Else If it is dark we called the defined callback with light argument | |
}) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const setTheme = (theme) => { | |
const rootElement = document.querySelector("html"); | |
// Set <html daa-theme="theme"> to change children styles | |
rootElement.setQuery("data-theme", theme); | |
} |
NewerOlder