@navinc/base-react-components
Version:
Nav's Pattern Library
49 lines (48 loc) • 2.42 kB
JavaScript
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
import { jsx as _jsx } from "react/jsx-runtime";
import styled from 'styled-components';
import { StyledButton } from './button';
import Icon from './icon';
import isRebrand from './is-rebrand';
const getIconName = (name) => {
const nameArr = name.split('/');
return nameArr[nameArr.length - 1];
};
const StyleOverrideButton = styled(StyledButton).withConfig({ displayName: "brc-sc-StyleOverrideButton", componentId: "brc-sc-1ixmm94" }) `
padding: 0;
height: ${({ variation }) => (variation === 'buttonLink' ? '24px' : '32px')};
width: ${({ variation }) => (variation === 'buttonLink' ? '24px' : '32px')};
display: flex;
align-items: center;
justify-content: center;
line-height: 0;
border-radius: ${({ variation }) => (variation === 'buttonLink' ? '2px' : '50%')};
${({ variation, theme }) => {
if (variation === 'buttonLink') {
return `
&:focus {
box-shadow: ${isRebrand(theme) ? `0 0 0 4px ${theme.navStatusPositive500}` : `0 0 0 3px ${theme.navPrimary700}`};
}
`;
}
return ``;
}}
`;
/** Pass all event handler props to a wrapper button to avoid rerendering the icon and causing flicker */
const IconButton = (_a) => {
var { variation = 'buttonLink', buttonAriaLabel, className, name, color, size } = _a, props = __rest(_a, ["variation", "buttonAriaLabel", "className", "name", "color", "size"]);
return (_jsx(StyleOverrideButton, Object.assign({ className: className, variation: variation, "data-testid": "icon-button", "aria-label": buttonAriaLabel || `${getIconName(name)} icon button` }, props, { children: _jsx(Icon, { name: name, color: color, size: size }) })));
};
export const InteractiveIcon = styled(IconButton).withConfig({ displayName: "brc-sc-InteractiveIcon", componentId: "brc-sc-1chnnt7" }) ``;
export default styled(IconButton).withConfig({ componentId: "brc-sc-1n24590" }) ``;
//# sourceMappingURL=icon-button.js.map