@kiwicom/orbit-components
Version:
Orbit-components is a React component library which provides developers with the easiest possible way of building Kiwi.com’s products.
60 lines (57 loc) • 1.86 kB
JavaScript
import * as React from "react";
import styled from "styled-components";
import KEY_CODE_MAP from "../common/keyMaps";
import defaultTheme from "../defaultTheme";
const StyledNavigation = styled.nav.withConfig({
displayName: "SkipLink__StyledNavigation",
componentId: "sc-dytgum-0"
})([""]);
const StyledLink = styled.a.withConfig({
displayName: "SkipLink__StyledLink",
componentId: "sc-dytgum-1"
})(["border:0;clip:rect(0 0 0 0);height:1px;margin:-1px;overflow:hidden;padding:0;position:absolute;width:1px;font-family:", ";text-decoration:", ";font-size:", ";border-radius:", ";color:", ";&:focus{top:1rem;left:1rem;clip:auto;height:auto;width:auto;margin:0;overflow:visible;padding:", ";background-color:", ";z-index:", ";}"], ({
theme
}) => theme.orbit.fontFamily, ({
theme
}) => theme.orbit.textDecorationTextLinkPrimary, ({
theme
}) => theme.orbit.fontSizeTextLarge, ({
theme
}) => theme.orbit.borderRadiusNormal, ({
theme
}) => theme.orbit.paletteInkNormal, ({
theme
}) => theme.orbit.spaceMedium, ({
theme
}) => theme.orbit.paletteWhite, ({
theme
}) => theme.orbit.zIndexOnTheTop); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
StyledLink.defaultProps = {
theme: defaultTheme
};
const SkipLink = ({
links,
buttonLabel
}) => {
return /*#__PURE__*/React.createElement(StyledNavigation, {
"aria-label": buttonLabel
}, links && links.map(({
href,
name,
onClick
}, index) => {
return /*#__PURE__*/React.createElement(StyledLink, {
key: encodeURIComponent(name + index),
href: href,
tabIndex: onClick && "0",
role: href ? "link" : "button",
onClick: onClick,
onKeyDown: ev => {
if (ev.keyCode === KEY_CODE_MAP.ENTER && onClick) {
onClick();
}
}
}, name);
}));
};
export default SkipLink;