UNPKG

@navinc/base-react-components

Version:
49 lines (48 loc) 2.33 kB
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 { forwardRef } from 'react'; 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: 0 0 0 4px ${theme.navStatusPositive500}; } `; } return ``; }} `; /** Pass all event handler props to a wrapper button to avoid rerendering the icon and causing flicker */ const _IconButton = forwardRef((_a, ref) => { 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, { ref: ref, children: _jsx(Icon, { name: name, color: color, size: size }) }))); }); export const IconButton = styled(_IconButton).withConfig({ displayName: "brc-sc-IconButton", componentId: "brc-sc-14dxz09" }) ``; export const InteractiveIcon = IconButton; //# sourceMappingURL=icon-button.js.map