Skip to content

Commit 64318fd

Browse files
authored
export useWindowSize and add forwardRef to hero children (#456)
1 parent e9d130c commit 64318fd

File tree

4 files changed

+53
-17
lines changed

4 files changed

+53
-17
lines changed

.changeset/export-windowsize-hook.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@primer/react-brand': patch
3+
---
4+
5+
Added hook for `useWindowSize` to the library exports.
6+
7+
Usage example:
8+
9+
```js
10+
import {useWindowSize} from '@primer/react-brand'
11+
```
12+
13+
```jsx
14+
const {width, height, isXSmall, isSmall, isMedium, isLarge, isXLarge, isXXLarge, currentBreakpointSize} =
15+
useWindowSize()
16+
```

.changeset/fix-hero-refs.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/react-brand': patch
3+
---
4+
5+
Enabled `forwardRef` on `Hero.Description`, `Hero.Label` and `Hero.Image`.

packages/react/src/Hero/Hero.tsx

+29-17
Original file line numberDiff line numberDiff line change
@@ -104,32 +104,44 @@ type HeroDescriptionProps = {
104104
weight?: TextWeightVariants | ResponsiveWeightMap
105105
} & BaseProps<HTMLParagraphElement>
106106

107-
function HeroDescription({size = '200', weight, children}: PropsWithChildren<HeroDescriptionProps>) {
108-
return (
109-
<Text className={styles['Hero-description']} as="p" size={size} weight={weight}>
110-
{children}
111-
</Text>
112-
)
113-
}
107+
const HeroDescription = forwardRef<HTMLParagraphElement, PropsWithChildren<HeroDescriptionProps>>(
108+
({size = '200', weight, children}: PropsWithChildren<HeroDescriptionProps>, ref) => {
109+
return (
110+
<Text ref={ref} className={styles['Hero-description']} as="p" size={size} weight={weight}>
111+
{children}
112+
</Text>
113+
)
114+
},
115+
)
114116

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

120-
function HeroImage({position = 'block-end', className, ...rest}: PropsWithChildren<HeroImageProps>) {
121-
return <Image className={clsx(styles['Hero-image'], styles[`Hero-image--pos-${position}`], className)} {...rest} />
122-
}
122+
const HeroImage = forwardRef<HTMLImageElement, HeroImageProps>(
123+
({position = 'block-end', className, ...rest}: PropsWithChildren<HeroImageProps>, ref) => {
124+
return (
125+
<Image
126+
ref={ref}
127+
className={clsx(styles['Hero-image'], styles[`Hero-image--pos-${position}`], className)}
128+
{...rest}
129+
/>
130+
)
131+
},
132+
)
123133

124134
type HeroLabelProps = LabelProps & BaseProps<HTMLSpanElement>
125135

126-
function HeroLabel({children, ...rest}: PropsWithChildren<HeroLabelProps>) {
127-
return (
128-
<Label className={styles['Hero-label']} {...rest}>
129-
{children}
130-
</Label>
131-
)
132-
}
136+
const HeroLabel = forwardRef<HTMLSpanElement, HeroLabelProps>(
137+
({children, ...rest}: PropsWithChildren<HeroLabelProps>, ref) => {
138+
return (
139+
<Label ref={ref} className={styles['Hero-label']} {...rest}>
140+
{children}
141+
</Label>
142+
)
143+
},
144+
)
133145

134146
type RestrictedPolymorphism =
135147
| (BaseProps<HTMLAnchorElement> & {as?: 'a'})

packages/react/src/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,6 @@ export * from './VideoPlayer'
3636
export * from './LogoSuite'
3737
export * from './Timeline'
3838
export * from './Bento'
39+
40+
// hooks
41+
export * from './hooks/useWindowSize'

0 commit comments

Comments
 (0)