mirror of
https://github.com/SomboChea/ui
synced 2026-01-17 00:25:50 +07:00
fix: typography Component - Introduced ForwardRef (#179)
* refactor: introduced forwardref * refacttor: updated ref's * fix: fixed func's name * fix: fixed snapshots * fix: updated snap
This commit is contained in:
committed by
Juan Picado @jotadeveloper
parent
82d7107de7
commit
a8deeb9b9d
19
src/muiComponents/Heading/Heading.tsx
Normal file
19
src/muiComponents/Heading/Heading.tsx
Normal file
@@ -0,0 +1,19 @@
|
||||
import React, { forwardRef } from 'react';
|
||||
import { default as MaterialUITypography, TypographyProps } from '@material-ui/core/Typography';
|
||||
|
||||
type HeadingType = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
|
||||
type HeadingRef = HeadingType;
|
||||
|
||||
interface Props extends Omit<TypographyProps, 'variant'> {
|
||||
variant?: HeadingType;
|
||||
}
|
||||
|
||||
const Heading = forwardRef<HeadingRef, Props>(function Heading(props, ref) {
|
||||
return <MaterialUITypography {...props} ref={ref} />;
|
||||
});
|
||||
|
||||
Heading.defaultProps = {
|
||||
variant: 'h6',
|
||||
};
|
||||
|
||||
export default Heading;
|
||||
1
src/muiComponents/Heading/index.ts
Normal file
1
src/muiComponents/Heading/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { default } from './Heading';
|
||||
20
src/muiComponents/Text/Text.tsx
Normal file
20
src/muiComponents/Text/Text.tsx
Normal file
@@ -0,0 +1,20 @@
|
||||
import React, { forwardRef } from 'react';
|
||||
import { default as MaterialUITypography, TypographyProps } from '@material-ui/core/Typography';
|
||||
|
||||
type TextType = 'subtitle1' | 'subtitle2' | 'body1' | 'body2';
|
||||
type TextRef = keyof HTMLElementTagNameMap;
|
||||
|
||||
interface Props extends Omit<TypographyProps, 'variant'> {
|
||||
variant?: TextType;
|
||||
}
|
||||
|
||||
// The reference is already from type of the Component, so the any below is not a problem
|
||||
const Text = forwardRef<TextRef, Props>(function Text(props, ref) {
|
||||
return <MaterialUITypography {...props} ref={ref} />;
|
||||
});
|
||||
|
||||
Text.defaultProps = {
|
||||
variant: 'subtitle1',
|
||||
};
|
||||
|
||||
export default Text;
|
||||
1
src/muiComponents/Text/index.ts
Normal file
1
src/muiComponents/Text/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { default } from './Text';
|
||||
Reference in New Issue
Block a user