|
1 | 1 | import React, {type ForwardedRef} from 'react' |
2 | 2 | import {clsx} from 'clsx' |
3 | | -import styled from 'styled-components' |
4 | | -import {get} from '../constants' |
5 | 3 | import type {SxProp} from '../sx' |
6 | | -import sx from '../sx' |
7 | | -import {useFeatureFlag} from '../FeatureFlags' |
8 | | -import Box from '../Box' |
9 | 4 | import classes from './BranchName.module.css' |
10 | | - |
11 | | -const StyledBranchName = styled.a<SxProp>` |
12 | | - display: inline-block; |
13 | | - padding: 2px 6px; |
14 | | - font-size: var(--text-body-size-small, ${get('fontSizes.0')}); |
15 | | - font-family: var(--fontStack-monospace, ${get('fonts.mono')}); |
16 | | - color: var(--fgColor-link, ${get('colors.accent.fg')}); |
17 | | - background-color: var(--bgColor-accent-muted, ${get('colors.accent.subtle')}); |
18 | | - border-radius: var(--borderRadius-medium, ${get('radii.2')}); |
19 | | - text-decoration: none; |
20 | | - &:is(:not(a)) { |
21 | | - color: var(--fgColor-muted); |
22 | | - } |
23 | | - ${sx}; |
24 | | -` |
| 5 | +import {toggleSxComponent} from '../internal/utils/toggleSxComponent' |
25 | 6 |
|
26 | 7 | type BranchNameProps<As extends React.ElementType> = { |
27 | 8 | as?: As |
28 | 9 | } & DistributiveOmit<React.ComponentPropsWithRef<React.ElementType extends As ? 'a' : As>, 'as'> & |
| 10 | + Omit<SxProp, 'sx'> & |
29 | 11 | SxProp |
30 | 12 |
|
| 13 | +const BaseComponent = toggleSxComponent('div') as React.ComponentType< |
| 14 | + React.PropsWithChildren<BranchNameProps<React.ElementType> & React.RefAttributes<HTMLElement>> |
| 15 | +> |
| 16 | + |
31 | 17 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
32 | 18 | function BranchName<As extends React.ElementType>(props: BranchNameProps<As>, ref: ForwardedRef<any>) { |
33 | | - const {as: BaseComponent = 'a', className, children, sx, ...rest} = props |
34 | | - const enabled = useFeatureFlag('primer_react_css_modules_ga') |
35 | | - |
36 | | - if (enabled) { |
37 | | - if (sx) { |
38 | | - return ( |
39 | | - <Box {...rest} ref={ref} as={BaseComponent} className={clsx(className, classes.BranchName)} sx={sx}> |
40 | | - {children} |
41 | | - </Box> |
42 | | - ) |
43 | | - } |
44 | | - |
45 | | - return ( |
46 | | - <BaseComponent {...rest} ref={ref} className={clsx(className, classes.BranchName)}> |
47 | | - {children} |
48 | | - </BaseComponent> |
49 | | - ) |
50 | | - } |
51 | | - |
| 19 | + const {as: Component = 'a', className, children, ...rest} = props |
52 | 20 | return ( |
53 | | - <StyledBranchName {...rest} as={BaseComponent} ref={ref} className={className} sx={sx}> |
| 21 | + <BaseComponent as={Component} {...rest} ref={ref} className={clsx(className, classes.BranchName)}> |
54 | 22 | {children} |
55 | | - </StyledBranchName> |
| 23 | + </BaseComponent> |
56 | 24 | ) |
57 | 25 | } |
58 | 26 |
|
|
0 commit comments