diff --git a/.changeset/gentle-apes-do.md b/.changeset/gentle-apes-do.md new file mode 100644 index 00000000000..4ceb2ac641d --- /dev/null +++ b/.changeset/gentle-apes-do.md @@ -0,0 +1,5 @@ +--- +"@primer/react": minor +--- + +Convert KeybindingHint to CSS modules behind feature flag diff --git a/packages/react/src/KeybindingHint/KeybindingHint.module.css b/packages/react/src/KeybindingHint/KeybindingHint.module.css new file mode 100644 index 00000000000..980830b0e8f --- /dev/null +++ b/packages/react/src/KeybindingHint/KeybindingHint.module.css @@ -0,0 +1,15 @@ +.KeybindingHint { + position: relative; + padding: 0; + overflow: visible; + font-family: inherit; + font-size: inherit; + /* stylelint-disable-next-line primer/typography */ + line-height: unset; + color: inherit; + white-space: nowrap; + vertical-align: baseline; + background: none; + border: none; + box-shadow: none; +} diff --git a/packages/react/src/KeybindingHint/KeybindingHint.tsx b/packages/react/src/KeybindingHint/KeybindingHint.tsx index 82338b748ca..4b7a820aada 100644 --- a/packages/react/src/KeybindingHint/KeybindingHint.tsx +++ b/packages/react/src/KeybindingHint/KeybindingHint.tsx @@ -3,34 +3,48 @@ import {memo} from 'react' import Text from '../Text' import type {KeybindingHintProps} from './props' import {accessibleSequenceString, Sequence} from './components/Sequence' +import {useFeatureFlag} from '../FeatureFlags' + +import classes from './KeybindingHint.module.css' +import {clsx} from 'clsx' /** `kbd` element with style resets. */ -const Kbd = ({children}: {children: ReactNode}) => ( - - {children} - -) +const Kbd = ({children, className}: {children: ReactNode; className?: string}) => { + const enabled = useFeatureFlag('primer_react_css_modules_team') + + return ( + + {children} + + ) +} /** Indicates the presence of an available keybinding. */ // KeybindingHint is a good candidate for memoizing since props will rarely change -export const KeybindingHint = memo((props: KeybindingHintProps) => ( - +export const KeybindingHint = memo(({className, ...props}: KeybindingHintProps) => ( + )) diff --git a/packages/react/src/KeybindingHint/props.ts b/packages/react/src/KeybindingHint/props.ts index 111908a7370..bc384fafd08 100644 --- a/packages/react/src/KeybindingHint/props.ts +++ b/packages/react/src/KeybindingHint/props.ts @@ -31,4 +31,8 @@ export interface KeybindingHintProps { * Control the size of the hint. */ size?: 'small' | 'normal' + /** + * Additional class name to apply to the hint. + */ + className?: string } diff --git a/packages/react/src/__tests__/KeybindingHint.test.tsx b/packages/react/src/__tests__/KeybindingHint.test.tsx index 79281964828..78c113a1b6e 100644 --- a/packages/react/src/__tests__/KeybindingHint.test.tsx +++ b/packages/react/src/__tests__/KeybindingHint.test.tsx @@ -74,6 +74,11 @@ describe('KeybindingHint', () => { expect(el).toBeInTheDocument() expect(el).not.toHaveAttribute('aria-hidden') }) + + it('accepts className prop', () => { + render() + expect(screen.getByTestId('keybinding-hint')).toHaveClass('test-class') + }) }) describe('getAccessibleKeybindingHintString', () => {