Skip to content

Instantly share code, notes, and snippets.

View andreich-tut's full-sized avatar
🚲
in dev <3

Ilya Polyakov andreich-tut

🚲
in dev <3
  • Samara
View GitHub Profile
@andreich-tut
andreich-tut / ViewportProvider.tsx
Last active February 2, 2024 13:31
ViewportProvider
const viewportConfig = {
isDesktop: '(min-width: 1280px)',
isDesktopSm: '(max-width: 1279px)',
isTablet: '(max-width: 1023px)',
isMobileLg: '(max-width: 767px)',
isMobileMd: '(max-width: 639px)',
};
// ==============================================================
@andreich-tut
andreich-tut / useClickOutside.ts
Last active August 16, 2022 11:37
useClickOutside
import { MutableRefObject, useCallback, useEffect } from 'react';
const useClickOutside = (
target: MutableRefObject<null | HTMLElement>,
handler: () => void,
exceptions: MutableRefObject<null | HTMLElement>[] = [],
) => {
const handleClickOutside = useCallback((e: MouseEvent) => {
const clickTarget = e.target as HTMLElement;
const hasInterceptionWithTarget = target.current?.contains(clickTarget);
@andreich-tut
andreich-tut / getStaticPath.ts
Last active February 28, 2022 12:40
getStaticPath.ts
/**
* The function handles the url depending on whether the path is absolute or relative
* @param url – required url
* @param withHost – inject host name to make an absolute url (with protocol and domain)
* @param lang – language used by client to inject correct host into url
* @returns string
*/
const getStaticPath = (
url: string,
withHost: boolean = false,
// use: declOfNum(count, ["Город", "Города", "Городов"]);
const declOfNum = (number, titles) => {
const cases = [2, 0, 1, 1, 1, 2];
return titles[(number % 100 > 4 && number % 100 < 20) ? 2 : cases[(number % 10 < 5) ? number % 10 : 5]];
};
export default declOfNum;
@andreich-tut
andreich-tut / ModalUsage.js
Created September 16, 2020 09:36
modal usage
import React from 'react';
import Button from '@/components/ui/Button';
import Modal from '@/components/ui/Modal';
import {operation} from '@/store/Operations/Operaion';
const ModalAddOperation = ({operation, modalVisibility, setModalVisibility, sendCallback}) => {
const makeOperation = () => operation().then(() => {
sendCallback();
setModalVisibility(false);
});
@andreich-tut
andreich-tut / Sidebar.js
Created September 16, 2020 09:19
WithOuterClick usage
import React from 'react';
import WithOuterClick from '@/components/ui/WithOuterClick';
import SidebarContainer from '@/components/ui/sidebar/SidebarContainer';
const Sidebar = ({content}) => {
const [visibility, setVisibility] = useState(false);
const showSidebar = () => setVisibility(!visibility);
return (
<WithOuterClick handler={() => setVisibility(false)}>
@andreich-tut
andreich-tut / Modal.js
Created September 16, 2020 09:15
simple react modal
import PropTypes from 'prop-types';
import React, {useRef} from 'react';
import ReactDOM from 'react-dom';
import styled from 'styled-components';
const Overlay = styled.div`
position: fixed;
top: 0;
left: 0;
width: 100%;
@andreich-tut
andreich-tut / WithOuterClick.js
Created September 16, 2020 09:10
WithOuterClick.js
import PropTypes from 'prop-types';
import React, {
Children,
cloneElement,
isValidElement,
useEffect,
useRef
} from 'react';
const WithOuterClick = ({children, handler}) => {
@andreich-tut
andreich-tut / serverManager.js
Created April 8, 2020 08:02
example of server manager
import Axios from 'axios';
export default class ServerManager {
constructor(ServiceProvider) {
this._serviceProvider = ServiceProvider;
this._csrfTokenContainer = document.head.querySelector('meta[name="csrf-token"]');
this._httpClient = this._makeHttpClientInstance();
}
$message = 'Hello "User"! <script>window.location.href = \'https://yandex.ru\';</script> Down angled quote (« and ») in HTML [duplicate]';
echo str_replace(
["&quot;", "&amp;", "&laquo;", "&raquo;"],
["\"", "&", "«", "»"],
htmlentities($message)
);