@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.
45 lines (44 loc) • 1.69 kB
JavaScript
"use client";
import * as React from "react";
import styled, { css } from "styled-components";
import KEY_CODE_MAP from "../common/keyMaps";
import defaultTheme from "../defaultTheme";
const StyledNavigation = styled.nav.withConfig({
displayName: "SkipLink__StyledNavigation",
componentId: "sc-1atjx4h-0"
})([""]);
const StyledLink = styled.a.withConfig({
displayName: "SkipLink__StyledLink",
componentId: "sc-1atjx4h-1"
})(["", ""], ({
theme
}) => css(["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.orbit.fontFamily, theme.orbit.textDecorationTextLinkPrimary, theme.orbit.fontSizeTextLarge, theme.orbit.borderRadiusNormal, theme.orbit.paletteInkDark, theme.orbit.spaceMedium, theme.orbit.paletteWhite, theme.orbit.zIndexOnTheTop));
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(ev);
}
}
}, name);
}));
};
export default SkipLink;