aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/design-system/src/components
diff options
context:
space:
mode:
authorViktor Vorona <viktor.vorona@sonarsource.com>2024-08-09 19:20:24 +0200
committersonartech <sonartech@sonarsource.com>2024-08-26 20:03:06 +0000
commit497b7e3d8826e495865b36860ead63a2a4a5b69b (patch)
treee541f74f9383481645d4db68393726cf57d35174 /server/sonar-web/design-system/src/components
parent72492e32e0eadc5ded27b0bf4a4bfb98665dbcc9 (diff)
downloadsonarqube-497b7e3d8826e495865b36860ead63a2a4a5b69b.tar.gz
sonarqube-497b7e3d8826e495865b36860ead63a2a4a5b69b.zip
SONAR-22717 Change in calculation badge in projects list
Diffstat (limited to 'server/sonar-web/design-system/src/components')
-rw-r--r--server/sonar-web/design-system/src/components/Pill.tsx56
1 files changed, 41 insertions, 15 deletions
diff --git a/server/sonar-web/design-system/src/components/Pill.tsx b/server/sonar-web/design-system/src/components/Pill.tsx
index 79d68589126..acd24669bda 100644
--- a/server/sonar-web/design-system/src/components/Pill.tsx
+++ b/server/sonar-web/design-system/src/components/Pill.tsx
@@ -17,8 +17,9 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+import { css } from '@emotion/react';
import styled from '@emotion/styled';
-import { ReactNode } from 'react';
+import { forwardRef, ReactNode } from 'react';
import tw from 'twin.macro';
import { themeColor, themeContrast } from '../helpers/theme';
import { ThemeColors } from '../types/theme';
@@ -43,34 +44,59 @@ interface PillProps {
['aria-label']?: string;
children: ReactNode;
className?: string;
+ onClick?: () => void;
variant: PillVariant;
}
-export function Pill({ children, variant, ...rest }: Readonly<PillProps>) {
- return (
- <StyledPill variant={variant} {...rest}>
- {children}
- </StyledPill>
- );
-}
+// eslint-disable-next-line react/display-name
+export const Pill = forwardRef<HTMLButtonElement, Readonly<PillProps>>(
+ ({ children, variant, onClick, ...rest }, ref) => {
+ return onClick ? (
+ <StyledPillButton onClick={onClick} ref={ref} variant={variant} {...rest}>
+ {children}
+ </StyledPillButton>
+ ) : (
+ <StyledPill ref={ref} variant={variant} {...rest}>
+ {children}
+ </StyledPill>
+ );
+ },
+);
-const StyledPill = styled.span<{
- variant: PillVariant;
-}>`
+const reusedStyles = css`
${tw`sw-body-xs`};
${tw`sw-w-fit`};
${tw`sw-inline-block`};
${tw`sw-whitespace-nowrap`};
${tw`sw-px-[8px] sw-py-[2px]`};
${tw`sw-rounded-pill`};
+ border-width: 1px;
+
+ &:empty {
+ ${tw`sw-hidden`}
+ }
+`;
+
+const StyledPill = styled.span<{
+ variant: PillVariant;
+}>`
+ ${reusedStyles};
background-color: ${({ variant }) => themeColor(variantThemeColors[variant])};
color: ${({ variant }) => themeContrast(variantThemeColors[variant])};
border-style: ${({ variant }) => (variant === 'accent' ? 'hidden' : 'solid')};
border-color: ${({ variant }) => themeColor(variantThemeBorderColors[variant])};
- border-width: 1px;
+`;
- &:empty {
- ${tw`sw-hidden`}
- }
+const StyledPillButton = styled.button<{
+ variant: PillVariant;
+}>`
+ ${reusedStyles};
+
+ background-color: ${({ variant }) => themeColor(variantThemeColors[variant])};
+ color: ${({ variant }) => themeContrast(variantThemeColors[variant])};
+ border-style: ${({ variant }) => (variant === 'accent' ? 'hidden' : 'solid')};
+ border-color: ${({ variant }) => themeColor(variantThemeBorderColors[variant])};
+
+ cursor: pointer;
`;