setValue(value === e.target.value);value ===.setValue(Math.min(max, Math.max(min, e.target.value)));Хотел реализовать тоже самое с двойным range слайдером и оказалось несколько сложнее.
function sum(...v1) {
const s = v1.reduce((acc, n) => acc + n, 0);
const f = (...v2) => v2.length ? sum(...v2, s) : s;
return v1.length ? f : s;
}
{cats.map((cat, index) => (
<li key={cat.description} className="catsItem">
<img src={catsImg[index]} alt=""/>
...
const selector = '.text';
const regex = /@(\w+)/g;
const replacement = '<a href="https://site.com/$1">$&</a>';
const replace = str => str.replace(regex, replacement);$(selector).html((i, html) => replace(html));
// или
document.querySelectorAll(selector).forEach(n => {
n.innerHTML = replace(n.innerText);
});
lower = next((n for n in reversed(lst) if n <= num), float('-inf'))
upper = next((n for n in lst if n >= num), float('inf'))
print([ lower, upper ])
() => перед openLightboxOnSlide(key) (кстати, а какого хрена переменная, содержащая индекс, названа key?).null, или -1) - это будет означать, что показывать ничего не надо:const [ lightIndex, setLightIndex ] = useState(null);<img onClick={() => setLightIndex(key)} /><ReactBnbGallery
photos={photos}
show={lightIndex !== null}
activePhotoIndex={lightIndex}
onClose={() => setLightIndex(null)}
/>
return [...el].map((n) => new Select(n));Select на this.constructor.
const checkedTexts = (el, selector) =>
Array.from(el.querySelectorAll(`${selector}:checked`), n => n.parentNode.innerText);
const propertyText = (el, selector) =>
el.querySelector(selector).innerText.split(': ')[1];
document.querySelector('.container-filter').addEventListener('input', function() {
const maxPrice = parseInt(this.querySelector('.range').value);
const brands = checkedTexts(this, '.input');
const years = checkedTexts(this, '.input-date');
document.querySelectorAll('.device .laptop').forEach(n => {
const price = parseInt(propertyText(n, '.laptop-price'));
const brand = propertyText(n, '.laptop-name');
const year = propertyText(n, '.laptop-year');
n.style.display = (
(maxPrice >= price) &&
(!brands.length || brands.includes(brand)) &&
(!years.length || years.includes(year))
)
? 'block'
: 'none';
});
});
const newStr = str
.split(' ')
.map(function([...word]) {
const sorted = word.filter(this).sort((a, b) => b.localeCompare(a));
return word.map(n => this(n) ? sorted.pop() : n).join('');
}, RegExp.prototype.test.bind(/[a-z]/i))
.join(' ');
str.replace(/(\d{2})(\d{2})/, '$1.$2.')
// или
str.replace(/(?=\d{4}$|\d{6}$)/g, '.')
// или
str.match(/(..)(..)(.+)/).slice(1).join('.')
// или
[ 0, 2, 4 ].map((n, i, a) => str.slice(n, a[i + 1])).join`.`
// или
[...str].reduce((acc, n, i) => acc + n + ([ ,'.',,'.' ][i] || ''))
// или
''.concat(...Array.from(str, (n, i) => '24'.includes(i) ? `.${n}` : n))
on: {
breakpoint() {
this.el.classList.toggle('класс', this.slides.length < this.params.slidesPerView);
},
},
ref={ref} элементу, который собираетесь скрывать.
const buttons = document.querySelector('.content');
const blocks = document.querySelector('.wrap');
const key = 'block';
const attr = `data-${key}`;
const attrSelector = `[${attr}]`;buttons.addEventListener('click', e => {
const button = e.target.closest(attrSelector);
if (button) {
const value = button.dataset[key];
console.log(blocks.querySelectorAll(`[${attr}="${value}"]`).length);
}
});const onClick = ({ currentTarget: { attributes: { [attr]: { value } } } }) =>
console.log(Array.prototype.reduce.call(
blocks.children,
(acc, n) => acc + (n.getAttribute(attr) === value),
0
));
for (const n of buttons.children) {
n.addEventListener('click', onClick);
}
Не могу закрыть поп-ап
dialog: [],dialog[index]= falseПри нажатии на кнопку, при выборе 3 изображения на превью открывается всегда первое.
data: () => ({
slide: null,
dialog: false,
...
}),
methods: {
openDialog(slideIndex) {
this.slide = slideIndex;
this.dialog = true;
},
...
},v-row
v-col(v-for="(n, i) in pictures")
v-item
v-img(height="100", width="100", :src="n", @click="openDialog(i)")
v-col(hidden="")
v-dialog(v-model="dialog")
v-carousel(v-model="slide")
v-carousel-item(v-for="n in pictures")
v-img(:src="n")
v-btn(@click="dialog = false") close dialog