import { useRef } from "react";
const Item = ({ element, renderIn }) => {
const node = useRef(null);
const chooseThis = (event) => {
renderIn.current.appendChild(node.current);
};
return (
<li onClick={chooseThis}>
<h1 ref={node}>{element}</h1>
</li>
);
};
const List = ({ elements, renderIn }) => (
<ul>
{elements.map((element) => (
<Item element={element} renderIn={renderIn} />
))}
</ul>
);
const App = () => {
const elements = ["one", "two", "three"];
const renderIn = useRef(null);
return (
<>
<h1>
Chosen one: <div style={{ color: "red" }} ref={renderIn}></div>
</h1>
<List elements={elements} renderIn={renderIn} />
</>
);
};
export default App;
import { useRef, useEffect } from "react";
const Item = ({ element, pushNode }) => {
const node = useRef(null);
useEffect(() => {
pushNode(node);
}, [node]);
return <li ref={node}>{element}</li>;
};
const List = ({ elements, pushNode }) => {
return (
<ul>
{elements.map((element) => (
<Item element={element} pushNode={pushNode} />
))}
</ul>
);
};
const App = () => {
const elements = ["one", "two", "three"];
const nodes = [];
const pushNode = (node) => nodes.push(node);
const paintRed = (event) => {
nodes.forEach((node) => {
node.current.style.color = "red";
});
};
return (
<>
<List elements={elements} pushNode={pushNode} />
<button onClick={paintRed}>Paint it red</button>
</>
);
};
export default App;
const TopNavigation: FC = () => {
const { opened, setOpened } = useData()
const { state: cityState } = useCityState()
const { dispatch } = useNavigationDispatch()
const { state: navigationState } = useNavigationState()
const navRef = useRef(null)
useEffect(() => {
dispatch({ type: 'setTopNavHeight', payload: { topNavHeight: navRef.current.offsetHeight } })
}, [])
return (
<Navigation
size='tiny'
fixed
dispatch={dispatch}
transparent={navigationState.transparent}
borderBottom='white'
backgroundColor={navigationState.transparent ? 'transparent' : 'slightlyGray'}
>
<Layout justifyContent='center'>
<Box
maxWidth={['90%', '90%', '1200px']}
width='100%'
height='48px'
ref={navRef}
alignSelf='center'
alignItems='center'
>
<CityPinIcon
color={navigationState.transparent ? 'white' : ''}
width='10px'
height='13px'
/>
<Layout flexBasis='8px' />
<Text
fontSize='small'
lineHeight='normal'
color={navigationState.transparent ? 'white' : 'dustyGray'}
cursor='pointer'
onClick={() => setOpened(true)}
>
{cityState.city.name}
</Text>
<Layout flexGrow={1} />
<TopBarList />
</Box>
</Layout>
<CityModal onClose={() => setOpened(false)} opened={opened} />
</Navigation>
)
}
export default TopNavigation
import React from 'react'
import Helmet from 'react-helmet'
import { useIntl } from 'react-intl'
import messages from './messages'
export const Seo = () => {
const intl = useIntl()
const title = intl.formatMessage(messages.title)
const description = intl.formatMessage(messages.description)
return (
<Helmet
htmlAttributes={{ lang: intl.locale }}
title={title}
titleTemplate={`%s | ${title}`}
meta={[
{
name: 'description',
content: description,
},
{
property: 'og:title',
content: title,
},
{
property: 'og:description',
content: description,
},
{
property: 'og:type',
content: 'website',
},
{
name: 'twitter:card',
content: 'summary',
},
{
name: 'twitter:title',
content: title,
},
{
name: 'twitter:description',
content: description,
},
]}
/>
)
}
import { Router, Route, IndexRoute, Redirect, IndexRedirect } from 'react-router'
import React from 'react';
export default (
<Router>
<Route path="/">
<IndexRoute/>
<Route path="test" />
<Route path="posts(/:page)" />
<Route path="article/:hrefTitle" />
<Route path="tags/:tagName" />
<Route path="tags/pages/(:page)" />
<Route path="archive(/:searchKey)" />
<Redirect path="*" to="/" />
</Route>
</Router>
)
import React, { useState, useRef } from 'react'
import { withYMaps } from 'react-yandex-maps'
import { Column, Layout } from '@ui/layout'
import { ContentLight } from '@ui/dropdown'
import { Input } from '@ui/input'
import styled from '@emotion/styled'
import OnOutsideClick from '@ui/layer/src/OnOutsideClick'
import Dropdown from './Dropdown'
import SuggestView from './SuggestView'
import { update, change, select } from './handlers'
import { SuggestProps } from './types'
const Wrapper = styled('div')({
position: 'relative',
width: '100%',
})
const Suggest = ({
color,
disabled,
id,
readOnly,
placeholder,
value,
ymaps,
onChange,
onSuggest,
}: SuggestProps) => {
const [items, setItems] = useState([])
const [toggle, setToggle] = useState(false)
const suggestRef = useRef()
const onUpdate = update(ymaps, setItems)
const content = []
content.push(
<Input
id={id}
key='smart-input'
disabled={disabled}
value={value}
onChange={
disabled ? null : targetValue => change(targetValue, onUpdate, onChange)
}
color={color}
readOnly={readOnly}
placeholder={placeholder}
onClick={() => setToggle(true)}
/>,
)
if (
toggle &&
items.length > 0 &&
!(items[0] !== value && items.length === 1)
) {
content.push(
<OnOutsideClick
key='smart-suggest'
target={suggestRef.current}
onOutsideClick={() => setToggle(false)}
>
<Dropdown>
<ContentLight borderRadius='s' width='large' noPopup>
<Column>
<Layout basis='12px' />
{items.map(s => (
<SuggestView
key={Math.random()}
onClick={() =>
select(s.value, onSuggest, onUpdate, onChange, setToggle)
}
>
{s.displayName}
</SuggestView>
))}
<Layout basis='12px' />
</Column>
</ContentLight>
</Dropdown>
</OnOutsideClick>,
)
}
return <Wrapper ref={suggestRef}>{content}</Wrapper>
}
const map = {};
Window.addEventListener = jest.genMockFn().mockImpl((event, cb) => {
map[event] = cb;
});
map.event(...args);
import { mount } from 'enzyme';
...
describe('Editor', function () {
it('dispatch COMMAND_SAVE when command+s key pressesd', function () {
const dispatchSpy = sinon.spy();
dispatchSpy.withArgs(COMMAND_SAVE);
// 1. use `mount` API for Full DOM Rendering
const wrapper = mount(<Editor dispatch={dispatchSpy} />);
// 2. find a DOM element with '.public-DraftEditor-content' classname
const ed = wrapper.find('.public-DraftEditor-content');
// 3. dispatch the 'keyDown' event with `simulate` API
ed.simulate('keyDown', {
keyCode: KeyCode.KEY_S,
metaKey: false, // is IS_OSX=true, this should be true
ctrlKey: true,
altKey: false,
});
assert.equal(dispatchSpy.calledOnce, true);
assert.equal(dispatchSpy.withArgs(COMMAND_SAVE).calledOnce, true);
});
});
class ScrollToTop extends Component {
onClick = () => {
if (this.element && this.element.parentNode) {
scrollIntoView(this.element.parentNode.parentNode, {
time: 500,
align: {
top: 0.1,
},
})
}
}
onSetRef = (element) => {
this.element = element
}
render() {
const { intl } = this.props
return (
<div
ref={this.onSetRef}
style={{ width: '100%' }}
>
<Layer
align='mc-mc'
constraints={[{
to: 'window',
attachment: 'none',
pin: ['top'],
}]}
classes={{
pinned: styles(),
}}
>
<div style={{ display: 'none', marginTop: 60, paddingRight: 40, paddingBottom: 20 }}>
<Text color='blue400'>
↑
</Text>
<Space />
<Link onClick={this.onClick}>
<Text color='blue400'>
{intl.formatMessage(messages.up)}
</Text>
</Link>
</div>
</Layer>
</div>
)
}
}
this.setState({welcome: "Привет Андрей"});
this.state.welcome = "Привет Андрей";
const info = [
{
title: 'Сделать уроки',
description: 'Нужно сделать математику и русский язык',
importance: 'Важно',
done: '12.12.2017',
deadline: '14.12.2017'
}
],
const newObject={}
info.push(newObject)