function filterByMinMax(arr, [ min, max ], key = n => n) {
const getVal = key instanceof Function ? key : n => n[key];
return arr.filter(n => {
const val = getVal(n);
return (min == null || min <= val) && (max == null || val <= max);
});
}
const d1 = filterByMinMax(chartPoints, [ new Date('2019-02-19') ], n => new Date(n.date));
const d2 = filterByMinMax(chartPoints, [ , '2019-01-23' ], n => n.date);
const d3 = filterByMinMax(chartPoints, [ '2019-02-12', '2019-02-26' ], 'date');
const Gradient = ({ data, areaGenerator, height }) => {
const ref = useRef(null);
useEffect(() => {
if (ref.current) {
d3.select(ref.current)
.append('linearGradient')
.attr('id', 'area-gradient')
.attr('gradientUnits', 'userSpaceOnUse')
.attr('x1', 0)
.attr('y1', 0)
.attr('x2', 0)
.attr('y2', height)
.selectAll('stop')
.data([
{ offset: '0%', color: 'rgba(101, 60, 173, 0)' },
{ offset: '100%', color: 'rgba(101, 60, 173, 0.2)' }
])
.enter()
.append('stop')
.attr('offset', d => d.offset)
.attr('stop-color', d => d.color);
d3.select(ref.current).append('path').attr('class', 'area');
}
}, [ ref.current ]);
useEffect(() => {
if (ref.current) {
d3.select(ref.current)
.select('.area')
.datum(data)
.transition()
.duration(1000)
.attr('d', areaGenerator);
}
}, [ ref.current, data ]);
return <g className="gradient-generator" ref={ref} />;
};
$(document).on('input', '.editor', function() {
const content = $('.editor')
.get()
.map(n => `\n <li>${$(n).html()}</li>`)
.join('');
$('textarea').val(`<ul>${content}\n</ul>`);
});
str.replace(/.{4}(?!$)/g, '$&-')
// или
str.match(/.{1,4}/g).join('-')
// или
str.split(/(?<=^(?:.{4})+)/).reduce((acc, n) => acc + (acc && '-') + n, '')
// или
''.concat(...[...str].map((n, i) => !i || i % 4 ? n : `-${n}`))
// или
Array.from(
{ length: Math.ceil(str.length / 4) },
(n, i) => str.slice(i * 4, (i + 1) * 4)
).join`-`
const items = document.querySelectorAll('.yourself-item__title');
const height = `${Math.max(...Array.from(items, n => n.clientHeight))}px`;
items.forEach(n => n.style.height = height);
.accordion__grandchild__item
, а переключаете видимость у родительских элементов - .accordion__grandchild__group
. Надо как-то устранить это печальное несоответствие. v-model
. flex-direction: column;
justify-content: space-around;
$('select').change(function() {
const v = this.value;
$('.sum').text($(`.element${v === '*' ? '' : `.${v}`}`).length);
});
document.querySelector('select').addEventListener('change', e => {
const v = e.target.value;
const s = '.element' + (v === '*' ? '' : '.' + v);
document.querySelector('.sum').textContent = document.querySelectorAll(s).length;
});
<select data-prop="type">
<option hidden></option>
<option value="type1">hello, world!!</option>
<option value="type2">fuck the world</option>
<option value="type3">fuck everything</option>
</select>
<br>
<input placeholder="name1" data-prop="name">
<input placeholder="name2" data-prop="name">
<input placeholder="name3" data-prop="name">
<br>
<input placeholder="url1" data-prop="url">
<input placeholder="url2" data-prop="url">
<input placeholder="url3" data-prop="url">
<br>
<input class="value" disabled>
<input class="value" disabled>
<input class="value" disabled>
const getValues = prop =>
Array.from(document.querySelectorAll(`[data-prop="${prop}"]`), n => n.value);
document.addEventListener('input', e => {
if (!e.target.dataset.prop) {
return;
}
const type = getValues('type')[0];
const names = getValues('name');
const urls = getValues('url');
document.querySelectorAll('.value').forEach((n, i) => {
n.name = n.value = `xxx[${type}][${names[i]}][${urls[i]}]`;
});
});