Skip to content

Instantly share code, notes, and snippets.

var version=function(){"use strict";return(t=new Date,e="month")=>{let n=new Date(t.getFullYear(),t.getMonth(),"month"===e?1:t.getDate());const a="month"===e?42:7,o=[];for(let e=0;e<a;e++){if(0===e){const t=n.getDay();n.setDate(n.getDate()-t)}else n.setDate(n.getDate()+1);let a={isCurrentMonth:n.getMonth()===t.getMonth(),date:new Date(n),year:n.getYear(),month:n.getMonth(),day:n.getDate(),isToday:n===t,events:[]};o.push(a)}return o}}();
export default function ProgressBar() {
return (
<div className='w-full'>
<div className='h-1.5 w-full bg-pink-100 overflow-hidden'>
<div className='animate-progress w-full h-full bg-pink-500 origin-left-right'></div>
</div>
</div>
);
}
'use client';
/* eslint-disable react-hooks/rules-of-hooks, react-hooks/exhaustive-deps */
import * as React from 'react';
export default function useControlled({ controlled, default: defaultProp, name, state = 'value' }) {
// isControlled is ignored in the hook dependency lists as it should never change.
const { current: isControlled } = React.useRef(controlled !== undefined);
const [valueState, setValue] = React.useState(defaultProp);
const value = isControlled ? controlled : valueState;
'use client';
import useControlled from './useControlled';
export default function usePagination(props = {}) {
// keep default values in sync with @default tags in Pagination.propTypes
const {
boundaryCount = 1,
componentName = 'usePagination',
count = 1,
defaultPage = 1,
@sprobejames
sprobejames / useCalendar.jsx
Last active April 30, 2024 03:15
Simple React Hook to Generate Dates for Calendar.
import { useMemo } from 'react';
import dayjs from 'dayjs';
import weekday from 'dayjs/plugin/weekday';
dayjs.extend(weekday);
export default function useCalendar(date = new Date(), range = 'month') {
const dates = useMemo(() => {
let startDate = range === 'month' ? dayjs(date).startOf('month') : dayjs(date);
let days = range === 'month' ? 42 : 7;
const date = new Date(2024, 03, 25);
console.log(date.toLocaleString());
const range = 'month';
/** using native date **/
const generateDates = (date, range = 'month', splitIntoWeeks = true) => {
// the first day of the month
let startDate = new Date(
date.getFullYear(),
date.getMonth(),
@sprobejames
sprobejames / customCalendar.js
Created April 25, 2024 00:54 — forked from aibrahim3546/customCalendar.js
Gist containing code for creating custom calendar in react using hooks.
import React, { useState, useEffect } from 'react';
import styled from 'styled-components'
const { datesGenerator } = require('dates-generator');
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
const days = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
const Container = styled.div`
width: 300px;
border: 1px solid black;
@sprobejames
sprobejames / Bank.php
Created April 17, 2024 06:35
Encrypting Model data.
<?php
class Bank extends Model
{
use Encryptable;
protected $encryptable = [
'account_number',
];
}
const range = (start, end) => {
const length = end - start;
return Array.from({ length }, (_, i) => start + i);
}
@sprobejames
sprobejames / useCountdown.jsx
Last active June 11, 2024 00:51
Reusable Countdown Hook for React
import { useEffect, useState, useRef } from 'react';
const useCountdown = (targetDate) => {
const countDownDate = new Date(targetDate).getTime();
const [countDown, setCountDown] = useState(
countDownDate - new Date().getTime()
);
const timerRef = useRef(null);