πŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more β†’
Socket
DemoInstallSign in
Socket

nc-one-react-helpers

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nc-one-react-helpers

Developments that will simplify the life of a React developer

1.0.22
latest
Source
npm
Version published
Weekly downloads
2
-60%
Maintainers
1
Weekly downloads
Β 
Created
Source

nc-one-react-helpers

Developments of the company's front-end developers NC1

npm i nc-one-react-helpers or yarn add nc-one-react-helpers

Documentation in English:

1. Components:

1.1. DateTimePicker:

Import:

import { DateTimePicker } from 'nc-one-react-helpers'

Example of use:

<DateTimePicker
	date={new Date()}
	onDateTimeChange={(date) => console.log(date)}
	getDateTimeString={(date) => console.log(date)}
	format='MMMM DD, YYYY - hh:mm'
/>

Interface:

interface DateTimePickerProps extends ITextFieldProps {
	date?: Date
	stringDate?: string
	format?: string
	withIcon?: boolean
	onDateTimeChange?: (date?: Date) => void
	getDateTimeString?: (date?: string) => void
	CalendarStrings?: ICalendarStrings
}
NameTypeDefault valueDescription
datedateundefineddate and time to be recorded and selected automatically
stringDatestringundefineddate and time which will be written and selected automatically as a string (string must be in the same format as format)
formatstring"MM.DD.YYYY, hh:mma"format of the string in which the date and time will be displayed and output more here
withIconbooleantruewhether the time date icon will be shown
onDateTimeChange(date?: Date) => voidundefinedDo something with the date time every time it changes
getDateTimeStringICalendarStringsinitialCalendarStringsthe way the calendar lines will be displayed

DateTimePickerProps is inherited from ITextFieldProps, so all TextField props will work fine!

2. Hooks:

2.1. useMediaQuery:

Import:.

import { useMediaQuery } from 'nc-one-react-helpers'

Example of use:

const matches = useMediaQuery('(min-width: 800px)')

if (matches) return <>Screen width greater than 800px</>
else return <>Screen width 800px or less</>

Type:

type useMediaQuery = (query: string) => boolean

Takes the string as in css @usemedia and returns true if the screen width satisfies the condition or false otherwise.

3. Various auxiliary elements:

3.1. functions:

3.1.1. UTCHoursPlus:

Import:.

import { UTCHoursPlus } from 'nc-one-react-helpers'

Example usage:

export const Time: React.FC = () => {
    const [time, setTime] = useState('')

    setTimeout(() => setTime(`${UTCHoursPlus(1)}:${new Date().getUTCMinutes()}:${new Date().getUTCSeconds()}`), 1000)

    return <>Storage time: {time} (UTC+01:00)</>
}

type:

type UTCHoursPlus = (plus: number) => number

Accepts how much to increase the current time and returns UTC clock+input parameter

3.1.2:

Import:

import { sleep } from 'nc-one-react-helpers'

Example of use:

onSubmit={async (values) => {
     setProgressIndicator(true); // show spinner

    try {
        sleep(500) //wait 500 milliseconds
        // mimic a request to the server
    } catch (e) {
        console.log(e)
    } finally {
        setProgressIndicator(false) // hide the spinner
    }
}}

Type:

type sleep = (ms: number) => Promise<unknown>

Wait for the entered number of milliseconds, and then execute the code below

3.2. Validations:

Import:

import { required, invalidEmail, invalidPassword, matchPassword, positiveNumber } from 'nc-one-react-helpers'

Type:

type required = (value: string, text?: string | undefined) => string | undefined

type invalidEmail = (value: string, text?: string | undefined) => string | undefined

type invalidPassword = (value: string, text?: string | undefined) => string | undefined

type matchPassword = (password: string, rePassword: string, text?: string | undefined) => string | undefined

type positiveNumber = (value: number, text?: string | undefined) => string | undefined

Example of use:

validate={({ email, position, password, repassword }) => {
    if (
        !required(email) &&
        !invalidEmail(email) &&
        !required(position) &&
        !positiveNumber(position) &&
        !required(password) &&
        !invalidPassword(password) &&
        !& required(repassword) &&
        !!invalidPassword(repassword) &&
        !!matchPassword(password, repassword)
    ) return {};

    return {
        email: required(email) || invalidEmail(email),
        position: required(position) || positiveNumber(position),
        password: required(password) || invalidPassword(password),
        repassword: required(repassword) || invalidPassword(repassword) || matchPassword(password, repassword)
    };
}}
  • required - Accepts value and returns error text if value is empty or undefined otherwise.
  • invalidEmail - Accepts value and returns error text if value is not a valid email address or undefined otherwise.
  • invalidPassword - Accepts value and returns error text if value fails validation check (too simple) or undefined otherwise.

password validation: minimum 8 characters, minimum 1 Latin letter A-Za-z, minimum 1 digit 0-9

  • matchPassword - Accepts password and rePassword and returns error text if passwords do not match or undefined otherwise.
  • positiveNumber - Accepts a number and returns an error text if it is negative or undefined otherwise.

text - Optional parameter for all validations. It determines what the error message will be. If it is not specified, the default (in Polish) message will be displayed

=====================================

nc-one-react-helpers

Наработки front-end Ρ€Π°Π·Π°Ρ€Π°Π±ΠΎΡ‚Ρ‡ΠΈΠΊΠΎΠ² ΠΊΠΎΠΌΠΏΠ°Π½ΠΈΠΈ NC1

npm i nc-one-react-helpers ΠΈΠ»ΠΈ yarn add nc-one-react-helpers

ДокумСнтация Π½Π° Русском:

1. ΠšΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Ρ‹:

1.1. DateTimePicker:

Π˜ΠΌΠΏΠΎΡ€Ρ‚:

import { DateTimePicker } from 'nc-one-react-helpers'

ΠŸΡ€ΠΈΠΌΠ΅Ρ€ использования:

<DateTimePicker
	date={new Date()}
	onDateTimeChange={(date) => console.log(date)}
	getDateTimeString={(date) => console.log(date)}
	format='MMMM DD, YYYY - hh:mm'
/>

Π˜Π½Ρ‚Π΅Ρ€Ρ„Π΅ΠΉΡ:

interface DateTimePickerProps extends ITextFieldProps {
	date?: Date
	stringDate?: string
	format?: string
	withIcon?: boolean
	onDateTimeChange?: (date?: Date) => void
	getDateTimeString?: (date?: string) => void
	CalendarStrings?: ICalendarStrings
}
НазваниСВипДСфолтноС Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ΠžΠΏΠΈΡΠ°Π½ΠΈΠ΅
dateDateundefinedΠ”Π°Ρ‚Π° ΠΈ врСмя ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ Π±ΡƒΠ΄ΡƒΡ‚ записаны ΠΈ Π²Ρ‹Π±Ρ€Π°Π½Ρ‹ автоматичСски
stringDatestringundefinedΠ”Π°Ρ‚Π° ΠΈ врСмя ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ Π±ΡƒΠ΄ΡƒΡ‚ записаны ΠΈ Π²Ρ‹Π±Ρ€Π°Π½Ρ‹ автоматичСски Π² Π²ΠΈΠ΄Π΅ строки (строка Π΄ΠΎΠ»ΠΆΠ½Π° Π±Ρ‹Ρ‚ΡŒ Π² Ρ‚Π°ΠΊΠΎΠΌ ΠΆΠ΅ Ρ„ΠΎΡ€ΠΌΠ°Ρ‚Π΅ Ρ‡Ρ‚ΠΎ ΠΈ format)
formatstring"MM.DD.YYYY, hh:mma"Π€ΠΎΡ€ΠΌΠ°Ρ‚ строки Π² ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠΌ Π±ΡƒΠ΄Π΅Ρ‚ ΠΎΡ‚ΠΎΠ±Ρ€Π°ΠΆΠ°Ρ‚ΡŒΡΡ ΠΈ Π²Ρ‹Π²ΠΎΠ΄ΠΈΡ‚ΡŒΡΡ Π΄Π°Ρ‚Π° врСмя ΠΏΠΎΠ΄Ρ€ΠΎΠ±Π½Π΅Π΅ здСсь
withIconbooleantrueΠ‘ΡƒΠ΄Π΅Ρ‚ Π»ΠΈ ΠΏΠΎΠΊΠ°Π·Ρ‹Π²Π°Ρ‚ΡŒΡΡ ΠΈΠΊΠΎΠ½ΠΊΠ° Π΄Π°Ρ‚Ρ‹ Π²Ρ€Π΅ΠΌΠ΅Π½ΠΈ
onDateTimeChange(date?: Date) => voidundefinedΠ”Π΅Π»Π°Ρ‚ΡŒ Ρ‡Ρ‚ΠΎ-Ρ‚ΠΎ с Π΄Π°Ρ‚ΠΎΠΉ Π²Ρ€Π΅ΠΌΠ΅Π½Π΅ΠΌ ΠΏΡ€ΠΈ ΠΊΠ°ΠΆΠ΄ΠΎΠΌ ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΠΈ
getDateTimeStringICalendarStringsinitialCalendarStringsΠ’ΠΎ ΠΊΠ°ΠΊ Π±ΡƒΠ΄ΡƒΡ‚ ΠΎΡ‚ΠΎΠ±Ρ€Π°ΠΆΠ°Ρ‚ΡŒΡΡ строки калСндаря

DateTimePickerProps наслСдуСтся ΠΎΡ‚ ITextFieldProps, поэтому всС пропсы TextField Π±ΡƒΠ΄ΡƒΡ‚ прСкрасно Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ!

2. Π₯ΡƒΠΊΠΈ:

2.1. useMediaQuery:

Π˜ΠΌΠΏΠΎΡ€Ρ‚:

import { useMediaQuery } from 'nc-one-react-helpers'

ΠŸΡ€ΠΈΠΌΠ΅Ρ€ использования:

const matches = useMediaQuery('(min-width: 800px)')

if (matches) return <>Π¨ΠΈΡ€ΠΈΠ½Π° экрана большС 800px</>
else return <>Π¨ΠΈΡ€ΠΈΠ½Π° экрана 800px ΠΈΠ»ΠΈ мСньшС</>

Π’ΠΈΠΏ:

type useMediaQuery = (query: string) => boolean

ΠŸΡ€ΠΈΠ½ΠΈΠΌΠ°Π΅Ρ‚ строку ΠΊΠ°ΠΊ Π² css @usemedia ΠΈ Π²ΠΎΠ·Π²Ρ€Π°Ρ‰Π°Π΅Ρ‚ true Π² случаС Ссли ΡˆΠΈΡ€ΠΈΠ½Π° экрана удовлСтворяСт условиС ΠΈΠ»ΠΈ false Π² ΠΏΡ€ΠΎΡ‚ΠΈΠ²Π½ΠΎΠΌ случаС.

3. Π Π°Π·Π»ΠΈΡ‡Π½Ρ‹Π΅ Π²ΡΠΏΠΎΠΌΠΎΠ³Π°Ρ‚Π΅Π»ΡŒΠ½Ρ‹Π΅ элСмСнты:

3.1. Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ:

3.1.1. UTCHoursPlus:

Π˜ΠΌΠΏΠΎΡ€Ρ‚:

import { UTCHoursPlus } from 'nc-one-react-helpers'

ΠŸΡ€ΠΈΠΌΠ΅Ρ€ использования:

export const Time: React.FC = () => {
    const [time, setTime] = useState('')

    setTimeout(() => setTime(`${UTCHoursPlus(1)}:${new Date().getUTCMinutes()}:${new Date().getUTCSeconds()}`), 1000)

    return <>Storage time: {time} (UTC+01:00)</>
}

Π’ΠΈΠΏ:

type UTCHoursPlus = (plus: number) => number

ΠŸΡ€ΠΈΠ½ΠΈΠΌΠ°Π΅Ρ‚ Ρ‚ΠΎ насколько ΡƒΠ²Π΅Π»ΠΈΡ‡ΠΈΡ‚ΡŒ Ρ‚Π΅ΠΊΡƒΡ‰Π΅Π΅ врСмя ΠΈ Π²ΠΎΠ·Π²Ρ€Π°Ρ‰Π°Π΅Ρ‚ часы UTC+Π²Π²Ρ‘Π΄Ρ‹ΠΉ ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€

3.1.2. sleep:

Π˜ΠΌΠΏΠΎΡ€Ρ‚:

import { sleep } from 'nc-one-react-helpers'

ΠŸΡ€ΠΈΠΌΠ΅Ρ€ использования:

onSubmit={async (values) => {
     setProgressIndicator(true);  // ΠΏΠΎΠΊΠ°Π·Π°Ρ‚ΡŒ спиннСр

    try {
        sleep(500) // ΠΏΠΎΠ΄ΠΎΠΆΠ΄Π°Ρ‚ΡŒ 500 миллисСкунд
        // ΡΠ΄Π΅Π»Π°Ρ‚ΡŒ ΠΈΠΌΠΈΡ‚Π°Ρ†ΠΈΡŽ запроса Π½Π° сСрвСр
    } catch (e) {
        console.log(e)
    } finally {
        setProgressIndicator(false) // ΡΠΊΡ€Ρ‹Ρ‚ΡŒ спиннСр
    }
}}

Π’ΠΈΠΏ:

type sleep = (ms: number) => Promise<unknown>

ΠŸΠΎΠ΄ΠΎΠΆΠ΄Π°Ρ‚ΡŒ Π²Π²Π΅Π΄Ρ‘Π½Π½ΠΎΠ΅ количСство милисСкунд, ΠΈ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ ΠΏΠΎΡ‚ΠΎΠΌ Π²Ρ‹ΠΏΠΎΠ»Π½ΠΈΡ‚ΡŒ ΠΊΠΎΠ΄ Π½ΠΈΠΆΠ΅

3.2. Π’Π°Π»ΠΈΠ΄Π°Ρ†ΠΈΠΈ:

Π˜ΠΌΠΏΠΎΡ€Ρ‚:

import { required, invalidEmail, invalidPassword, matchPassword, positiveNumber } from 'nc-one-react-helpers'

Π’ΠΈΠΏΡ‹:

type required = (value: string, text?: string | undefined) => string | undefined

type invalidEmail = (value: string, text?: string | undefined) => string | undefined

type invalidPassword = (value: string, text?: string | undefined) => string | undefined

type matchPassword = (password: string, rePassword: string, text?: string | undefined) => string | undefined

type positiveNumber = (value: number, text?: string | undefined) => string | undefined

ΠŸΡ€ΠΈΠΌΠ΅Ρ€ использования:

validate={({ email, position, password, repassword }) => {
    if (
        !required(email) &&
        !invalidEmail(email) &&
        !required(position) &&
        !positiveNumber(position) &&
        !required(password) &&
        !invalidPassword(password) &&
        !required(repassword) &&
        !invalidPassword(repassword) &&
        !matchPassword(password, repassword)
    ) return {};

    return {
        email: required(email) || invalidEmail(email),
        position: required(position) || positiveNumber(position),
        password: required(password) || invalidPassword(password),
        repassword: required(repassword) || invalidPassword(repassword) || matchPassword(password, repassword)
    };
}}
  • required - ΠŸΡ€ΠΈΠ½ΠΈΠΌΠ°Π΅Ρ‚ value ΠΈ Π²ΠΎΠ·Π²Ρ€Π°Ρ‰Π°Π΅Ρ‚ тСкст ошибки Π² случаС Ссли value пустой ΠΈΠ»ΠΈ undefined Π² ΠΏΡ€ΠΎΡ‚ΠΈΠ²Π½ΠΎΠΌ случаС.
  • invalidEmail - ΠŸΡ€ΠΈΠ½ΠΈΠΌΠ°Π΅Ρ‚ value ΠΈ Π²ΠΎΠ·Π²Ρ€Π°Ρ‰Π°Π΅Ρ‚ тСкст ошибки Π² случаС Ссли value Π½Π΅ являСтся Π²Π°Π»ΠΈΠ΄Π½Ρ‹ΠΌ ΠΏΠΎΡ‡Ρ‚ΠΎΠ²Ρ‹ΠΌ адрСсом (email) ΠΈΠ»ΠΈ undefined Π² ΠΏΡ€ΠΎΡ‚ΠΈΠ²Π½ΠΎΠΌ случаС.
  • invalidPassword - ΠŸΡ€ΠΈΠ½ΠΈΠΌΠ°Π΅Ρ‚ value ΠΈ Π²ΠΎΠ·Π²Ρ€Π°Ρ‰Π°Π΅Ρ‚ тСкст ошибки Π² случаС Ссли value Π½Π΅ ΠΏΡ€ΠΎΡ…ΠΎΠ΄ΠΈΡ‚ ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΊΡƒ Π²Π°Π»ΠΈΠ΄Π°Ρ†ΠΈΠΈ (слишком простой) ΠΈΠ»ΠΈ undefined Π² ΠΏΡ€ΠΎΡ‚ΠΈΠ²Π½ΠΎΠΌ случаС.

валидация пароля: ΠΌΠΈΠ½ΠΈΠΌΡƒΠΌ 8 символов, ΠΌΠΈΠ½ΠΈΠΌΡƒΠΌ 1 латинская Π±ΡƒΠΊΠ²Π° A-Za-z, ΠΌΠΈΠ½ΠΈΠΌΡƒΠΌ 1 Ρ†ΠΈΡ„Ρ€Π° 0-9

  • matchPassword - ΠŸΡ€ΠΈΠ½ΠΈΠΌΠ°Π΅Ρ‚ password ΠΈ rePassword ΠΈ Π²ΠΎΠ·Π²Ρ€Π°Ρ‰Π°Π΅Ρ‚ тСкст ошибки Π² случаС Ссли ΠΏΠ°Ρ€ΠΎΠ»ΠΈ Π½Π΅ ΡΠΎΠ²ΠΏΠ°Π΄Π°ΡŽΡ‚ ΠΈΠ»ΠΈ undefined Π² ΠΏΡ€ΠΎΡ‚ΠΈΠ²Π½ΠΎΠΌ случаС.
  • positiveNumber - ΠŸΡ€ΠΈΠ½ΠΈΠΌΠ°Π΅Ρ‚ число ΠΈ Π²ΠΎΠ·Π²Ρ€Π°Ρ‰Π°Π΅Ρ‚ тСкст ошибки Π² случаС Ссли ΠΎΠ½ΠΎ ΠΎΡ‚Ρ€ΠΈΡ†Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎΠ΅ ΠΈΠ»ΠΈ undefined Π² ΠΏΡ€ΠΎΡ‚ΠΈΠ²Π½ΠΎΠΌ случаС.

text - ΠΠ΅ΠΎΠ±ΡΠ·Π°Ρ‚Π΅Π»ΡŒΠ½Ρ‹ΠΉ ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€ всСх Π²Π°Π»ΠΈΠ΄Π°Ρ†ΠΈΠΉ. Он ΠΎΡ‚Π²Π΅Ρ‡Π°Π΅Ρ‚ Π·Π° Ρ‚ΠΎ ΠΊΠ°ΠΊΠΈΠΌ Π±ΡƒΠ΄Π΅Ρ‚ сообщСниС ΠΎΠ± ошибкС. Если ΠΎΠ½ Π½Π΅ ΡƒΠΊΠ°Π·Π°Π½ Π±ΡƒΠ΄Π΅Ρ‚ Π²Ρ‹Π²Π΅Π΄Π΅Π½ΠΎ сообщСниС ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ (Π½Π° Польском)

Keywords

DateTimePicker

FAQs

Package last updated on 21 May 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts