-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: migration_v6.md - Добавил блок "Содержание". Для это в Styleguide добавил возможность навигироваться по заголовкам. - Отформатировал текста. - Изменил структуру. * fix(migration_v6.md): add link to "Интеграция с VK Mini Apps" * chore: fix typo * chore: fix typo x2 * fix(migration_v6.md): fix some headers --------- Co-authored-by: Victoria Zhizhonkova <indarklight@gmail.com>
- Loading branch information
1 parent
22216cf
commit 408f22b
Showing
8 changed files
with
492 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,46 @@ | ||
import * as React from 'react'; | ||
import { Link } from '@vkui'; | ||
import { generateIdByReactNode } from '../../utils'; | ||
|
||
export const LinkRenderer = ({ href: _href, ...restProps }) => { | ||
const href = _href?.replace('https://vkcom.github.io/VKUI/', ''); | ||
const resolveHref = (hrefProp, children) => { | ||
if (hrefProp) { | ||
if (hrefProp === '{{anchor}}') { | ||
const id = generateIdByReactNode(children); | ||
return { | ||
scrollTo() { | ||
const el = document.getElementById(id); | ||
if (el) { | ||
window.scrollTo({ behavior: 'smooth', top: el.offsetTop }); | ||
} | ||
}, | ||
native: undefined, | ||
}; | ||
} | ||
|
||
return <Link href={href} {...restProps} />; | ||
return { | ||
scrollTo: null, | ||
native: hrefProp.replace('https://vkcom.github.io/VKUI/', ''), | ||
}; | ||
} | ||
}; | ||
|
||
export const LinkRenderer = ({ href: hrefProp, onClick, children, ...restProps }) => { | ||
const href = resolveHref(hrefProp, children); | ||
|
||
const handleClick = (event) => { | ||
if (onClick) { | ||
onClick(event); | ||
} | ||
if (href.scrollTo !== null) { | ||
href.scrollTo(); | ||
} | ||
}; | ||
|
||
return ( | ||
<Link href={href.native} onClick={handleClick} {...restProps}> | ||
{children} | ||
</Link> | ||
); | ||
}; | ||
|
||
export default LinkRenderer; |
Oops, something went wrong.