Skip to content

Instantly share code, notes, and snippets.

@Aberratio
Aberratio / MyComponent.tsx
Last active July 7, 2023 11:34
useOutsideClick
import React, { useRef } from 'react';
import { useOutsideClick } from './useOutsideClick';
export const MyComponent = () => {
const ref1 = useRef(null);
const ref2 = useRef(null);
const handleOutsideClick = () => {
// Place your code to be executed when clicked outside the elements
};
@Aberratio
Aberratio / regex.md
Last active February 8, 2023 14:20
JavaScript regex

Example regexes

URL

^(https?:\\/\\/)?(www\\.)?([\\da-z\\.-]+)\\.([a-z\\.]{2,6})([\\/\\w \\.-]*)*\\/?$

E-mail

^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$
@Aberratio
Aberratio / ChildObjectView.js
Last active October 27, 2022 04:30
[Sanity.io v2] Dynamically changes the icons assigned to the icons selected in the childObject answers array depending on the type of the selected childObject and the showCorrectnes state of the parent object.
import React from 'react';
import { withDocument } from 'part:@sanity/form-builder';
const ChildObjectView = (props) => {
const PARENT_ICON = {
correct: '✅',
incorrect: '❌',
neutral: '🔵',
};
@Aberratio
Aberratio / BlogItemPreview.tsx
Last active December 27, 2023 16:19
An example of using quards in React.
import React from "react";
import { BlogItem, isLongPostBody } from "./types";
const BlogItemPreview = (blogItem: BlogItem) => {
const { body, author, title } = blogItem;
const image = isLongPostBody(body) && body.image;
const previewText = isLongPostBody(body) ? body.lead : body.summary;
return (
@Aberratio
Aberratio / README.md
Created September 13, 2022 05:12
[Sanity.io v2] Sort and filter elements in an array of references

The code allows for arbitrary sorting and filtering of elements in an array of references in Sanity.io.

Supports Sanity.io version v2.

In the example given an array of references for two types, but you can limit it to one type or extend it as desired.

In the fetchElement() function, you can use a custom query so as to get the required elements.

@Aberratio
Aberratio / CSS Grid.md
Last active October 15, 2022 06:52
Play with grid

CSS Grid is a two-dimensional grid-based layout.

When to use CSS Grid?

  • user interfaces;
  • overall layout on website.

How does it work?

Grid container contains grid items, which are its direct children.

image

@Aberratio
Aberratio / README.md
Last active September 13, 2022 05:15
[Sanity.io v2] with Schedule plugin

Read about the plugin here.

Instalation

sanity install @sanity/scheduled-publishing

Simply installing the plugin adds the ability to schedule the publication of all documents over time from the drop-down list level next to the "Publish" button. The snippets below show the customization options for this.

Three use cases were implemented:

  1. Change Publish button to Schedule for all documents that are type1 and type2