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

Add lib export for useWindowSize and add forwardRef to hero children #456

Merged
merged 1 commit into from
Oct 10, 2023
Merged
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
16 changes: 16 additions & 0 deletions .changeset/export-windowsize-hook.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
'@primer/react-brand': patch
---

Added hook for `useWindowSize` to the library exports.

Usage example:

```js
import {useWindowSize} from '@primer/react-brand'
```

```jsx
const {width, height, isXSmall, isSmall, isMedium, isLarge, isXLarge, isXXLarge, currentBreakpointSize} =
useWindowSize()
```
5 changes: 5 additions & 0 deletions .changeset/fix-hero-refs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react-brand': patch
---

Enabled `forwardRef` on `Hero.Description`, `Hero.Label` and `Hero.Image`.
46 changes: 29 additions & 17 deletions packages/react/src/Hero/Hero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,32 +104,44 @@ type HeroDescriptionProps = {
weight?: TextWeightVariants | ResponsiveWeightMap
} & BaseProps<HTMLParagraphElement>

function HeroDescription({size = '200', weight, children}: PropsWithChildren<HeroDescriptionProps>) {
return (
<Text className={styles['Hero-description']} as="p" size={size} weight={weight}>
{children}
</Text>
)
}
const HeroDescription = forwardRef<HTMLParagraphElement, PropsWithChildren<HeroDescriptionProps>>(
({size = '200', weight, children}: PropsWithChildren<HeroDescriptionProps>, ref) => {
return (
<Text ref={ref} className={styles['Hero-description']} as="p" size={size} weight={weight}>
{children}
</Text>
)
},
)

type HeroImageProps = {
position?: 'inline-end' | 'block-end'
} & ImageProps &
BaseProps<HTMLImageElement>

function HeroImage({position = 'block-end', className, ...rest}: PropsWithChildren<HeroImageProps>) {
return <Image className={clsx(styles['Hero-image'], styles[`Hero-image--pos-${position}`], className)} {...rest} />
}
const HeroImage = forwardRef<HTMLImageElement, HeroImageProps>(
({position = 'block-end', className, ...rest}: PropsWithChildren<HeroImageProps>, ref) => {
return (
<Image
ref={ref}
className={clsx(styles['Hero-image'], styles[`Hero-image--pos-${position}`], className)}
{...rest}
/>
)
},
)

type HeroLabelProps = LabelProps & BaseProps<HTMLSpanElement>

function HeroLabel({children, ...rest}: PropsWithChildren<HeroLabelProps>) {
return (
<Label className={styles['Hero-label']} {...rest}>
{children}
</Label>
)
}
const HeroLabel = forwardRef<HTMLSpanElement, HeroLabelProps>(
({children, ...rest}: PropsWithChildren<HeroLabelProps>, ref) => {
return (
<Label ref={ref} className={styles['Hero-label']} {...rest}>
{children}
</Label>
)
},
)

type RestrictedPolymorphism =
| (BaseProps<HTMLAnchorElement> & {as?: 'a'})
Expand Down
3 changes: 3 additions & 0 deletions packages/react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,6 @@ export * from './VideoPlayer'
export * from './LogoSuite'
export * from './Timeline'
export * from './Bento'

// hooks
export * from './hooks/useWindowSize'