Skip to content

Instantly share code, notes, and snippets.

View CyberAP's full-sized avatar
🔴

Stanislav Lashmanov CyberAP

🔴
View GitHub Profile
@CyberAP
CyberAP / parseStringIntoChunks.js
Created March 10, 2021 00:31
Convert html-like translation strings into scoped-slot-compatible chunks
/*
* "foo<bar>baz</bar>qux" => ['foo', ['bar', 'baz'], 'qux']
* "<bar/>" => [['bar', '']]
* */
function parseStringIntoChunks(string) {
const chunks = [];
let buffer = '';
let currentTag = '';
let currentTagContent = '';
@CyberAP
CyberAP / bem.js
Last active December 28, 2020 07:52
Generate bem classes in runtime
// Usage:
// bem('class-name', { foo: 'bar', baz: true }) → ['class-name--foo-bar', 'class-name--baz']
export const bem = (baseClass, mods) => {
const keys = Object.keys(mods);
const res = [];
keys.forEach(key => {
const param = mods[key];
if (!param) return;
if (Array.isArray(param)) {
@CyberAP
CyberAP / OuterClick.vue
Created June 8, 2020 15:04
Handle clicks outside an element, done via Vue component
<template>
<div class="outer-click" ref="root">
<slot />
</div>
</template>
<script>
export default {
name: 'OuterClick',
props: {
@CyberAP
CyberAP / TransitionExpand.vue
Last active February 12, 2023 01:06
Transition height change in Vue
<template>
<div
class="transition-expand"
ref="container"
:style="style"
>
<transition
name="transition-fade"
@enter="enter"
import Vue from 'vue';
import getScrollbarWidth from "@modules/utils/getScrollbarWidth.js";
import { getDocument, getWindow } from "@modules/utils/dom.js";
const window = getWindow();
const document = getDocument();
const mobileWidth = parseInt(
window
.getComputedStyle(document.documentElement)