Skip to content

Instantly share code, notes, and snippets.

@tonysaffo
tonysaffo / UserInfo.jsx
Created February 21, 2019 15:46
UserInfo component with detection of outside clicking
import React, { Component } from 'react'
import { Link } from 'react-router-dom'
import { connect } from 'react-redux'
import './userInfo.scss'
class UserInfo extends Component {
constructor(props) {
super(props);
this.setWrapperRef = this.setWrapperRef.bind(this);
@tonysaffo
tonysaffo / calendarChunkWithMoment.js
Created February 7, 2019 11:47
Chunk for creating calendar with moment js and react
updateDates = () => {
const date = this.state.currentDate.startOf('month')
const delta = Math.abs(1-date.day())
let daysInMonth = date.daysInMonth() + delta
date.subtract(delta+1, 'd')
const arrayOfDays = []
while(daysInMonth > 0){
let dateNew = Moment(date.add(1, 'd'))
arrayOfDays.push(dateNew)
daysInMonth-=1
const regExp = /^(\+7)[\s]\([0-9]{3}\)[\s][0-9]{3}\-[0-9]{2}\-[0-9]{2}/;
@tonysaffo
tonysaffo / imaskinput.js
Created January 24, 2019 14:15
Phone Mask React
<IMaskInput
name='phone'
mask='+{7} (000) 000-00-00'
radix="."
value={this.state.phone}
unmask="true" // true|false|'typed'
onAccept={
// depending on prop above first argument is
// `value` if `unmask=false`,
// `unmaskedValue` if `unmask=true`,
downloadHt = (e) => {
const { token, setToken, taskId } = this.props
const el = e.target
this.ApiService.downloadHt(token, setToken, taskId, this.state.export)
.then(r => {
if(r === 'error'){
el.innerHTML = 'Произошла ошибка'
setTimeout(() => {
el.innerHTML = 'Распечатать'
return
@tonysaffo
tonysaffo / usingMoment.js
Created December 12, 2018 10:57
Use moment.js in react
import React, {Component} from 'react'
import Moment from 'moment/min/moment-with-locales'
import './Infoblock.css'
export default class Infoblock extends Component{
state = {
_isNumber = (n) => {
return !isNaN(parseFloat(n)) && isFinite(n);
}
adaptPhone = (val) => {
const deleteLastChar = (val) =>{
val = val.substring(0, val.length - 1);
if(val[0] != '+'){
val = '+7'+val;
}
function validatePhoneInput(selector){
$(document).delegate(selector, "keyup", function(e){
function isNumber(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
function deleteLastChar(val){
val = val.substring(0, val.length - 1);
if(val[0] != '+'){
$(document).delegate('.courses-module.my .typical-course-card', "click", function(e){
clearAll();
if (!History.enabled) {
return;
}
e.preventDefault();
@tonysaffo
tonysaffo / snippets.cson
Created November 16, 2018 16:52
Atom js snippets
'.source.js':
'anonymous function':
'prefix': 'f'
'body': 'function(){$1}'
'jquery click function':
'prefix': 'c'
'body': """
.click(function(){
${1}
});