Skip to content

Instantly share code, notes, and snippets.

@Mood-al
Mood-al / +page.svelte
Created December 20, 2022 00:57
svelte-tabs-scrollable usage
<script>
// @ts-nocheck
import Tabs from '$lib/Tabs.svelte';
import Tab from '$lib/Tab.svelte';
let isRTL = false;
const onClick = () => {
isRTL = !isRTL;
};
const onInputBlur = (e) => {
setFocussed(false);
if (e.target.value === "" && locale === "ar") {
setDir("rtl");
return;
}
locale === "ar" ? setDir("rtl") : setDir("ltr");
};
const onInputFocus = (e) => {
setFocussed(true);
if (e.target.value === "" && locale === "ar") {
setDir("rtl");
return;
}
isRTL(e.target.value) ? setDir("rtl") : setDir("ltr");
};
//code from this repo https://github.com/kavirajk/isRTL/blob/master/isRTL.js
let reRTL, rtlChars;
rtlChars = [
/* arabic ranges*/
"\u0600-\u06FF",
"\u0750-\u077F",
"\uFB50-\uFDFF",
"\uFE70-\uFEFF",
useEffect(() => {
if (value === "" && locale === "ar") {
setDir("rtl");
return;
}
/* The above code is setting the direction of the text to right to left if the user is focussed on
the text box. */
if (focussed) {
isRTL(value) ? setDir("rtl") : setDir("ltr");
}
@Mood-al
Mood-al / useInputDirectionDetector.js
Last active March 15, 2023 22:49
a react custom hook that detects the direction of an input based on its value
import { useEffect, useState } from "react";
import { isRTL } from "../utils/isRTL";
const useInputDirectionDetector = (value, locale) => {
const [dir, setDir] = useState();
const [focussed, setFocussed] = useState(false);
/* If the user is typing and the language is Arabic, then set the direction to
right-to-left. */
import { useEffect, useState } from "react";
import { isRTL } from "../utils/isRTL";
const useInputValueLangaugeDetector = (value, locale) => {
const [dir, setDir] = useState();
const [focussed, setFocussed] = useState(false);
/* If the user is typing and the language is Arabic, then set the direction to
right-to-left. */
import { useEffect, useState } from "react";
import { isRTL } from "../utils/isRTL";
const useInputValueLangaugeDetector = (value, locale) => {
const [dir, setDir] = useState();
const [focussed, setFocussed] = useState(false);
/* If the user is typing and the language is Arabic, then set the direction to
right-to-left. */
@Mood-al
Mood-al / gist:5e0e2cdc23641caf37fed381d6bfb611
Created October 2, 2022 20:12
useInputValueLangaugeDetector.js
import { useEffect, useState } from "react";
import { isRTL } from "../utils/isRTL";
const useInputValueLangaugeDetector = (value, locale) => {
const [dir, setDir] = useState();
const [focussed, setFocussed] = useState(false);
/* If the user is typing and the language is Arabic, then set the direction to
right-to-left. */
export const donateRoutes = {
medical_support: {
constant: "sections_medical_support",
sections: [
{
main_section_name: "medical_support",
section_name: "medical-cases",
title_constant_name: "medical_cases_title",
description_constant_name: "medical_cases_description",
route_url: "medical-cases",