Skip to content

Instantly share code, notes, and snippets.

const loading$ = fromEvent(form, 'submit').pipe( exhaustMap(() => { const data$ = fetchData().pipe(shareReplay(1));

const showLoading$ = of(true).pipe(
  delay(+showLoadingAfterField.value),
  tap(() => showLoading(true)),
);

const hideLoading$ = timer(+showLoadingForAtLeastField.value).pipe(first());

@Vital99878
Vital99878 / loading-state$.md
Created April 5, 2023 08:21
logic for loader with delay

const loading$ = fromEvent(form, 'submit').pipe( exhaustMap(() => { const data$ = fetchData().pipe(shareReplay(1));

const showLoading$ = of(true).pipe(
  delay(+showLoadingAfterField.value),
  tap(() => showLoading(true)),
);

const hideLoading$ = timer(+showLoadingForAtLeastField.value).pipe(first());

@Vital99878
Vital99878 / useBooleanState.tsx
Created January 27, 2023 14:45
Хук для state типа boolean
import { useState } from "react";
export default function useBooleanState(initial?: boolean) {
const [state, setState] = useState(Boolean(initial));
const toggler = {
setToTrue: () => setState(true),
setToFalse: () => setState(false),
}
@Vital99878
Vital99878 / pkcs10Generator.js
Created November 21, 2022 10:25 — forked from tcd93/pkcs10Generator.js
Simple way to generate certificate signing request (CSR) with X.509 using Javascript
import * as asn1js from 'asn1js';
import { getCrypto, getAlgorithmParameters, CertificationRequest, AttributeTypeAndValue } from 'pkijs/build'
import { arrayBufferToString, toBase64 } from 'pvutils';
//https://github.com/PeculiarVentures/PKI.js/blob/31c10e9bb879cac59d710102adf4fd7bd61cd66c/src/CryptoEngine.js#L1300
const hashAlg = 'SHA-256'
const signAlg = 'ECDSA'
/**
* @example
* createPKCS10({ enrollmentID: 'user1', organizationUnit: 'Marketing', organization: 'Farmer Market', state: 'M', country: 'V' })
import React, { useEffect, useState } from 'react';
/**
* @description вычисляет element.current.scrollWidth > element.current.clientWidth
* при каждом появлении HTMLElement на странице
* и при resize страницы
* @return Boolean (element.current.scrollWidth > element.current.clientWidth)
*/
export const useOverflow = (element: React.RefObject<HTMLElement>): boolean => {
@Vital99878
Vital99878 / Select.scss
Created September 13, 2022 07:08
Custom Select style
.select {
--padding: .8em 1em;
position: relative;
font-size: 1.2rem;
font-family: 'sans-serif', sans-serif;
display: inline-block;
color: var(--clr-select-option-text)
}
.select__buttonWrapper {
@Vital99878
Vital99878 / Select.tsx
Created September 13, 2022 07:07
FC Custom Select
import React, { useRef, useState } from 'react';
import clsx from 'clsx';
import './Select.scss';
import { useClickOutside } from '../../hooks/useClickOutside';
const Arrow = ({ className }: { className: string }) => {
return (
<svg
width="12"
height="8"
@Vital99878
Vital99878 / LinkAsButton.tsx
Created September 12, 2022 09:03
Link As Button
import React, { PropsWithChildren } from 'react';
import { Link } from 'react-router-dom';
import clsx from 'clsx';
import { LinkAsButtonProps as Props } from '../types/LinkAsButtonProps';
import './LinkAsButton.scss';
export default function LinkAsButton(props: PropsWithChildren<Props>) {
const { primary, secondary, transparent, disabled, className, children, onClick, hasPlus, ...other } = props;
function handleClick(evt: React.MouseEvent<HTMLAnchorElement, MouseEvent>) {
@Vital99878
Vital99878 / LinkAsButton.scss
Created September 11, 2022 08:31
Link variant style
.asButton {
font-size: 1.4rem;
min-width: max-content;
padding: 0.4em 1.5em;
border-radius: 6px;
display: grid;
place-items: center;
border: 1.2px solid transparent; // бордер у всех один, чтобы разные виды сылок по высоте были одинаковые
outline: none;
text-align: center;
@Vital99878
Vital99878 / Button.scss
Created September 11, 2022 08:31
button variant style
.btn {
font-size: 1.4rem;
min-width: max-content;
padding: 0.4em 1.5em;
border-radius: 6px;
display: grid;
place-items: center;
border: 1.2px solid transparent; // бордер у всех один, чтобы разные виды кнопок по высоте были одинаковые
outline: none;
text-align: center;