Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(PointerBox): Convert PointerBox to CSS modules behind team feature flag #5328

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/react/src/PointerBox/PointerBox.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.PointerBox {
position: relative;
border: 1px solid var(--borderColor-default);
border-radius: var(--borderRadius-medium);
}
45 changes: 44 additions & 1 deletion packages/react/src/PointerBox/PointerBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import type {CaretProps} from '../Caret'
import Caret from '../Caret'
import {get} from '../constants'
import type {SxProp} from '../sx'
import {useFeatureFlag} from '../FeatureFlags'
import classes from './PointerBox.module.css'
import {clsx} from 'clsx'

const CSS_MODULES_FEATURE_FLAG = 'primer_react_css_modules_team'

// FIXME: Make this work with BetterStyledSystem types
type MutatedSxProps = {
Expand All @@ -21,13 +26,14 @@ export type PointerBoxProps = {
bg?: CaretProps['bg']
borderColor?: CaretProps['borderColor']
border?: CaretProps['borderWidth']
className?: string
} & BoxProps &
MutatedSxProps

function PointerBox(props: PointerBoxProps) {
// don't destructure these, just grab them
const themeContext = React.useContext(ThemeContext)
const {bg, border, borderColor, theme: themeProp, sx} = props
const {bg, border, borderColor, theme: themeProp, sx, className} = props
const {caret, children, ...boxProps} = props
const {bg: sxBg, backgroundColor, ...sxRest} = sx || {}
const theme = themeProp || themeContext
Expand All @@ -42,6 +48,43 @@ function PointerBox(props: PointerBoxProps) {
}

const defaultBoxProps = {borderWidth: '1px', borderStyle: 'solid', borderColor: 'border.default', borderRadius: 2}
const enabled = useFeatureFlag(CSS_MODULES_FEATURE_FLAG)

if (enabled) {
const styles: {[key: string]: string} = {}
if (customBackground) {
const pointerBoxBg = `var(--bgColor-${customBackground})`
styles['background-color'] = pointerBoxBg
styles['background-image'] =
`linear-gradient(${pointerBoxBg}, ${pointerBoxBg}), linear-gradient(var(--bgColor-default), var(--bgColor-default))`
}

if (sx) {
return (
<Box
{...boxProps}
className={clsx(className, {[classes.PointerBox]: enabled})}
sx={{
...sxRest,
'--custom-bg': get(`colors.accent.emphasis`)({theme}),
backgroundImage: customBackground
? `linear-gradient(var(--custom-bg), var(--custom-bg)), linear-gradient(var(--bgColor-default), var(--bgColor-default))`
: undefined,
position: 'relative',
}}
>
{children}
<Caret {...caretProps} />
</Box>
)
}
return (
<div {...boxProps} className={clsx(className, {[classes.PointerBox]: enabled})} style={styles}>
{children}
<Caret {...caretProps} />
</div>
)
}

return (
<Box
Expand Down
Loading